Uma área de pesquisa sobre o WordPress para devs e autores do tema



wp_get_missing_image_subsizes ›

Desde5.3.0
Obsoleton/a
wp_get_missing_image_subsizes ( $attachment_id )
Parâmetros:
  • (int) $attachment_id The image attachment post ID.
    Required: Yes
Retorna:
  • (array) An array of the image sub-sizes that are currently defined but don't exist for this image.
Definido em:
Codex:

Compare the existing image sub-sizes (as saved in the attachment meta) to the currently registered image sub-sizes, and return the difference.

Registered sub-sizes that are larger than the image are skipped.



Fonte

function wp_get_missing_image_subsizes( $attachment_id ) {
	if ( ! wp_attachment_is_image( $attachment_id ) ) {
		return array();
	}

	$registered_sizes = wp_get_registered_image_subsizes();
	$image_meta       = wp_get_attachment_metadata( $attachment_id );

	// Meta error?
	if ( empty( $image_meta ) ) {
		return $registered_sizes;
	}

	$full_width     = (int) $image_meta['width'];
	$full_height    = (int) $image_meta['height'];
	$possible_sizes = array();

	// Skip registered sizes that are too large for the uploaded image.
	foreach ( $registered_sizes as $size_name => $size_data ) {
		if ( image_resize_dimensions( $full_width, $full_height, $size_data['width'], $size_data['height'], $size_data['crop'] ) ) {
			$possible_sizes[ $size_name ] = $size_data;
		}
	}

	if ( empty( $image_meta['sizes'] ) ) {
		$image_meta['sizes'] = array();
	}

	// Remove sizes that already exist. Only checks for matching "size names".
	// It is possible that the dimensions for a particular size name have changed.
	// For example the user has changed the values on the Settings -> Media screen.
	// However we keep the old sub-sizes with the previous dimensions
	// as the image may have been used in an older post.
	$missing_sizes = array_diff_key( $possible_sizes, $image_meta['sizes'] );

	/**
	 * Filters the array of missing image sub-sizes for an uploaded image.
	 *
	 * @since 5.3.0
	 *
	 * @param array $missing_sizes Array with the missing image sub-sizes.
	 * @param array $image_meta    The image meta data.
	 * @param int   $attachment_id The image attachment post ID.
	 */
	return apply_filters( 'wp_get_missing_image_subsizes', $missing_sizes, $image_meta, $attachment_id );
}