Yoast\WP\SEO\Images\Application
Image_Content_Extractor::gather_images_wp
Gathers all images from content with WP's WP_HTML_Tag_Processor() and returns them along with their IDs, if possible.
Метод класса: Image_Content_Extractor{}
Хуки из метода
Возвращает
int[]. An associated array of image IDs, keyed by their URL.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->gather_images_wp( $content );
- $content(строка) (обязательный)
- The content.
Код Image_Content_Extractor::gather_images_wp() Image Content Extractor::gather images wp Yoast 26.5
protected function gather_images_wp( $content ) {
$processor = new WP_HTML_Tag_Processor( $content );
$images = [];
$query = [
'tag_name' => 'img',
];
/**
* Filter 'wpseo_image_attribute_containing_id' - Allows filtering what attribute will be used to extract image IDs from.
*
* Defaults to "class", which is where WP natively stores the image IDs, in a `wp-image-<ID>` format.
*
* @api string The attribute to be used to extract image IDs from.
*/
$attribute = \apply_filters( 'wpseo_image_attribute_containing_id', 'class' );
while ( $processor->next_tag( $query ) ) {
$src_raw = $processor->get_attribute( 'src' );
if ( ! $src_raw ) {
continue;
}
$src = \htmlentities( $src_raw, ( \ENT_QUOTES | \ENT_SUBSTITUTE | \ENT_HTML401 ), \get_bloginfo( 'charset' ) );
$classes = $processor->get_attribute( $attribute );
$id = $this->extract_id_of_classes( $classes );
$images[ $src ] = $id;
}
return $images;
}