WPSEO_Image_Utils::get_data()public staticYoast 1.0

Retrieves the image data.

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

Хуки из метода

Возвращает

false|Массив. Array of image data

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

$result = WPSEO_Image_Utils::get_data( $image, $attachment_id );
$image(массив) (обязательный)
Image array with URL and metadata.
$attachment_id(int) (обязательный)
Attachment ID.

Код WPSEO_Image_Utils::get_data() Yoast 22.4

public static function get_data( $image, $attachment_id ) {
	if ( ! is_array( $image ) ) {
		return false;
	}

	// Deals with non-set keys and values being null or false.
	if ( empty( $image['width'] ) || empty( $image['height'] ) ) {
		return false;
	}

	$image['id']     = $attachment_id;
	$image['alt']    = self::get_alt_tag( $attachment_id );
	$image['pixels'] = ( (int) $image['width'] * (int) $image['height'] );

	if ( ! isset( $image['type'] ) ) {
		$image['type'] = get_post_mime_type( $attachment_id );
	}

	/**
	 * Filter: 'wpseo_image_data' - Filter image data.
	 *
	 * Elements with keys not listed in the section will be discarded.
	 *
	 * @param array $image_data {
	 *     Array of image data
	 *
	 *     @type int    id       Image's ID as an attachment.
	 *     @type string alt      Image's alt text.
	 *     @type string path     Image's path.
	 *     @type int    width    Width of image.
	 *     @type int    height   Height of image.
	 *     @type int    pixels   Number of pixels in the image.
	 *     @type string type     Image's MIME type.
	 *     @type string size     Image's size.
	 *     @type string url      Image's URL.
	 *     @type int    filesize The file size in bytes, if already set.
	 * }
	 * @param int   $attachment_id Attachment ID.
	 */
	$image = apply_filters( 'wpseo_image_data', $image, $attachment_id );

	// Keep only the keys we need, and nothing else.
	return array_intersect_key( $image, array_flip( [ 'id', 'alt', 'path', 'width', 'height', 'pixels', 'type', 'size', 'url', 'filesize' ] ) );
}