Image_Helper::generate_from_attachment_id()publicYoast 1.0

Retrieve data about an image from the database and use it to generate a Schema object.

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

Хуков нет.


Массив. Schema ImageObject array.


$Image_Helper = new Image_Helper();
$Image_Helper->generate_from_attachment_id( $schema_id, $attachment_id, $caption, $add_hash );
$schema_id(строка) (обязательный)
The @id to use for the returned image.
$attachment_id(int) (обязательный)
The attachment to retrieve data from.
The caption string, if there is one.
По умолчанию: ''
Whether a hash will be added as a suffix in the @id.
По умолчанию: false

Код Image_Helper::generate_from_attachment_id() Yoast 22.8

public function generate_from_attachment_id( $schema_id, $attachment_id, $caption = '', $add_hash = false ) {
	$data = $this->generate_object();
	$url  = $this->image->get_attachment_image_url( $attachment_id, 'full' );

	$id_suffix = ( $add_hash ) ? \md5( $url ) : '';

	$data['@id']        = $schema_id . $id_suffix;
	$data['url']        = $url;
	$data['contentUrl'] = $url;
	$data               = $this->add_image_size( $data, $attachment_id );
	$data               = $this->add_caption( $data, $attachment_id, $caption );

	return $data;