WPSEO_Sitemap_Image_Parser::image_url
Get attached image URL with filters applied. Adapted from core for speed.
Метод класса: WPSEO_Sitemap_Image_Parser{}
Хуки из метода
Возвращает
Строку.
Использование
// private - только в коде основоного (родительского) класса $result = $this->image_url( $post_id );
- $post_id(int) (обязательный)
- ID of the post.
Код WPSEO_Sitemap_Image_Parser::image_url() WPSEO Sitemap Image Parser::image url Yoast 27.3
private function image_url( $post_id ) {
static $uploads;
if ( empty( $uploads ) ) {
$uploads = wp_upload_dir();
}
if ( $uploads['error'] !== false ) {
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 ( strpos( $file, $uploads['basedir'] ) === 0 ) {
$src = str_replace( $uploads['basedir'], $uploads['baseurl'], $file );
}
elseif ( strpos( $file, 'wp-content/uploads' ) !== false ) {
$src = $uploads['baseurl'] . substr( $file, ( strpos( $file, 'wp-content/uploads' ) + 18 ) );
}
else {
// It's a newly uploaded file, therefore $file is relative to the baseurl.
$src = $uploads['baseurl'] . '/' . $file;
}
return apply_filters( 'wp_get_attachment_url', $src, $post_id );
}