WPSEO_Sitemap_Image_Parser::image_url PHP Method

image_url() private method

Get attached image URL. Adapted from core for speed.
private image_url ( integer $post_id ) : string
$post_id integer ID of the post.
return string
    private function image_url($post_id)
    {
        static $uploads;
        if (empty($uploads)) {
            $uploads = wp_upload_dir();
        }
        if (false !== $uploads['error']) {
            return '';
        }
        $file = get_post_meta($post_id, '_wp_attached_file', true);
        if (empty($file)) {
            return '';
        }
        // Check that the upload base exists in the file location.
        if (0 === strpos($file, $uploads['basedir'])) {
            return str_replace($uploads['basedir'], $uploads['baseurl'], $file);
        }
        // Replace file location with url location.
        if (false !== strpos($file, 'wp-content/uploads')) {
            return $uploads['baseurl'] . substr($file, strpos($file, 'wp-content/uploads') + 18);
        }
        // It's a newly uploaded file, therefore $file is relative to the baseurl.
        return $uploads['baseurl'] . "/{$file}";
    }