WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

WC_Regenerate_Images_Request::filter_image_sizes_to_only_missing_thumbnails() public WC 1.0

Filters the list of thumbnail sizes to only include those which have missing files.

Это метод класса: WC_Regenerate_Images_Request{}

Хуков нет.

Возвращает

Массив. An associative array of image sizes.

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

$WC_Regenerate_Images_Request = new WC_Regenerate_Images_Request();
$WC_Regenerate_Images_Request->filter_image_sizes_to_only_missing_thumbnails( $sizes, $metadata, $attachment_id );
$sizes(массив) (обязательный)
An associative array of registered thumbnail image sizes.
$metadata(массив) (обязательный)
An associative array of fullsize image metadata: width, height, file.
$attachment_id(число)
Attachment ID. Only passed from WP 5.0+.
По умолчанию: null

Код WC_Regenerate_Images_Request::filter_image_sizes_to_only_missing_thumbnails() WC 4.5.2

woocommerce/includes/class-wc-regenerate-images-request.php
<?php
public function filter_image_sizes_to_only_missing_thumbnails( $sizes, $metadata, $attachment_id = null ) {
	$attachment_id = is_null( $attachment_id ) ? $this->attachment_id : $attachment_id;

	if ( ! $sizes || ! $attachment_id ) {
		return $sizes;
	}

	$fullsizepath = get_attached_file( $attachment_id );
	$editor       = wp_get_image_editor( $fullsizepath );

	if ( is_wp_error( $editor ) ) {
		return $sizes;
	}

	$metadata = wp_get_attachment_metadata( $attachment_id );

	// This is based on WP_Image_Editor_GD::multi_resize() and others.
	foreach ( $sizes as $size => $size_data ) {
		if ( empty( $metadata['sizes'][ $size ] ) ) {
			continue;
		}
		if ( ! isset( $size_data['width'] ) && ! isset( $size_data['height'] ) ) {
			continue;
		}
		if ( ! isset( $size_data['width'] ) ) {
			$size_data['width'] = null;
		}
		if ( ! isset( $size_data['height'] ) ) {
			$size_data['height'] = null;
		}
		if ( ! isset( $size_data['crop'] ) ) {
			$size_data['crop'] = false;
		}

		$image_sizes = getimagesize( $fullsizepath );
		if ( false === $image_sizes ) {
			continue;
		}
		list( $orig_w, $orig_h ) = $image_sizes;

		$dimensions = image_resize_dimensions( $orig_w, $orig_h, $size_data['width'], $size_data['height'], $size_data['crop'] );

		if ( ! $dimensions || ! is_array( $dimensions ) ) {
			continue;
		}

		$info         = pathinfo( $fullsizepath );
		$ext          = $info['extension'];
		$dst_w        = $dimensions[4];
		$dst_h        = $dimensions[5];
		$suffix       = "{$dst_w}x{$dst_h}";
		$dst_rel_path = str_replace( '.' . $ext, '', $fullsizepath );
		$thumbnail    = "{$dst_rel_path}-{$suffix}.{$ext}";

		if ( $dst_w === $metadata['sizes'][ $size ]['width'] && $dst_h === $metadata['sizes'][ $size ]['height'] && file_exists( $thumbnail ) ) {
			unset( $sizes[ $size ] );
		}
	}

	return $sizes;
}