Yoast\WP\SEO\Images\Application

Image_Content_Extractor::gather_images_wp()protectedYoast 1.0

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() Yoast 24.0

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     = \htmlentities( $processor->get_attribute( 'src' ), ( \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;
}