Yoast\WP\SEO\Images\Application
Image_Content_Extractor::gather_images_domdocument
Gathers all images from content with DOMDocument() 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_domdocument( $content );
- $content(строка) (обязательный)
- The content.
Код Image_Content_Extractor::gather_images_domdocument() Image Content Extractor::gather images domdocument Yoast 28.6
protected function gather_images_domdocument( $content ) {
$images = [];
$charset = \get_bloginfo( 'charset' );
/**
* 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' );
\libxml_use_internal_errors( true );
$post_dom = new DOMDocument();
$post_dom->loadHTML( '<?xml encoding="' . $charset . '">' . $content );
\libxml_clear_errors();
foreach ( $post_dom->getElementsByTagName( 'img' ) as $img ) {
$src = \htmlentities( $img->getAttribute( 'src' ), ( \ENT_QUOTES | \ENT_SUBSTITUTE | \ENT_HTML401 ), $charset );
$classes = $img->getAttribute( $attribute );
$id = $this->extract_id_of_classes( $classes );
$images[ $src ] = $id;
}
return $images;
}