WPSEO_Sitemap_Image_Parser::get_images()
Get set of image data sets for the given post.
Метод класса: WPSEO_Sitemap_Image_Parser{}
Возвращает
Массив
.
Использование
$WPSEO_Sitemap_Image_Parser = new WPSEO_Sitemap_Image_Parser(); $WPSEO_Sitemap_Image_Parser->get_images( $post );
- $post(объект) (обязательный)
- Post object to get images for.
Код WPSEO_Sitemap_Image_Parser::get_images() WPSEO Sitemap Image Parser::get images Yoast 24.9
public function get_images( $post ) { $images = []; if ( ! is_object( $post ) ) { return $images; } $thumbnail_id = get_post_thumbnail_id( $post->ID ); if ( $thumbnail_id ) { $src = $this->get_absolute_url( $this->image_url( $thumbnail_id ) ); $images[] = $this->get_image_item( $post, $src ); } /** * Filter: 'wpseo_sitemap_content_before_parse_html_images' - Filters the post content * before it is parsed for images. * * @param string $content The raw/unprocessed post content. */ $content = apply_filters( 'wpseo_sitemap_content_before_parse_html_images', $post->post_content ); $unfiltered_images = $this->parse_html_images( $content ); foreach ( $unfiltered_images as $image ) { $images[] = $this->get_image_item( $post, $image['src'] ); } foreach ( $this->parse_galleries( $content, $post->ID ) as $attachment ) { $src = $this->get_absolute_url( $this->image_url( $attachment->ID ) ); $images[] = $this->get_image_item( $post, $src ); } if ( $post->post_type === 'attachment' && wp_attachment_is_image( $post ) ) { $src = $this->get_absolute_url( $this->image_url( $post->ID ) ); $images[] = $this->get_image_item( $post, $src ); } foreach ( $images as $key => $image ) { if ( empty( $image['src'] ) ) { unset( $images[ $key ] ); } } /** * Filter images to be included for the post in XML sitemap. * * @param array $images Array of image items. * @param int $post_id ID of the post. */ $image_list = apply_filters( 'wpseo_sitemap_urlimages', $images, $post->ID ); if ( isset( $image_list ) && is_array( $image_list ) ) { $images = $image_list; } return $images; }