Yoast\WP\SEO\Generators

Open_Graph_Image_Generator::generate()publicYoast 1.0

Retrieves the images for an indexable.

For legacy reasons some plugins might expect we filter a WPSEO_Opengraph_Image object. That might cause type errors. This is why we try/catch our filters.

Метод класса: Open_Graph_Image_Generator{}

Возвращает

Массив. The images.

Использование

$Open_Graph_Image_Generator = new Open_Graph_Image_Generator();
$Open_Graph_Image_Generator->generate( $context );
$context(Meta_Tags_Context) (обязательный)
The context.

Код Open_Graph_Image_Generator::generate() Yoast 24.0

public function generate( Meta_Tags_Context $context ) {
	$image_container        = $this->get_image_container();
	$backup_image_container = $this->get_image_container();

	try {
		/**
		 * Filter: wpseo_add_opengraph_images - Allow developers to add images to the Open Graph tags.
		 *
		 * @param Yoast\WP\SEO\Values\Open_Graph\Images $image_container The current object.
		 */
		\apply_filters( 'wpseo_add_opengraph_images', $image_container );
	} catch ( Error $error ) {
		$image_container = $backup_image_container;
	}

	$this->add_from_indexable( $context->indexable, $image_container );
	$backup_image_container = $image_container;

	try {
		/**
		 * Filter: wpseo_add_opengraph_additional_images - Allows to add additional images to the Open Graph tags.
		 *
		 * @param Yoast\WP\SEO\Values\Open_Graph\Images $image_container The current object.
		 */
		\apply_filters( 'wpseo_add_opengraph_additional_images', $image_container );
	} catch ( Error $error ) {
		$image_container = $backup_image_container;
	}

	$this->add_from_templates( $context, $image_container );
	$this->add_from_default( $image_container );

	return $image_container->get_images();
}