WPSEO_Image_Utils::get_image()public staticYoast 1.0

Find the right version of an image based on size.

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

Хуков нет.

Возвращает

Массив|false. Returns an array with image data on success, false on failure.

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

$result = WPSEO_Image_Utils::get_image( $attachment_id, $size );
$attachment_id(int) (обязательный)
Attachment ID.
$size(строка|массив) (обязательный)
Size name, or array of width and height in pixels (e.g [800,400]).

Код WPSEO_Image_Utils::get_image() Yoast 25.0

public static function get_image( $attachment_id, $size ) {
	$image = false;
	if ( $size === 'full' ) {
		$image = self::get_full_size_image_data( $attachment_id );
	}

	if ( ! $image ) {
		$image = image_get_intermediate_size( $attachment_id, $size );
	}

	if ( ! is_array( $image ) ) {
		$image_src = wp_get_attachment_image_src( $attachment_id, $size );
		if ( is_array( $image_src ) && isset( $image_src[1] ) && isset( $image_src[2] ) ) {
			$image           = [];
			$image['url']    = $image_src[0];
			$image['width']  = $image_src[1];
			$image['height'] = $image_src[2];
			$image['size']   = 'full';
		}
	}

	if ( ! $image ) {
		return false;
	}

	if ( ! isset( $image['size'] ) ) {
		$image['size'] = $size;
	}

	return self::get_data( $image, $attachment_id );
}