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



wp_update_image_subsizes ›

Desde5.3.0
Obsoleton/a
wp_update_image_subsizes ( $attachment_id )
Parâmetros:
  • (int) $attachment_id The image attachment post ID.
    Required: Yes
Retorna:
  • (array|WP_Error) The updated image meta data array or WP_Error object if both the image meta and the attached file are missing.
Definido em:
Codex:

If any of the currently registered image sub-sizes are missing, create them and update the image meta data.



Fonte

function wp_update_image_subsizes( $attachment_id ) {
	$image_meta = wp_get_attachment_metadata( $attachment_id );
	$image_file = wp_get_original_image_path( $attachment_id );

	if ( empty( $image_meta ) || ! is_array( $image_meta ) ) {
		// Previously failed upload?
		// If there is an uploaded file, make all sub-sizes and generate all of the attachment meta.
		if ( ! empty( $image_file ) ) {
			return wp_create_image_subsizes( $image_file, $attachment_id );
		} else {
			return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) );
		}
	}

	$missing_sizes = wp_get_missing_image_subsizes( $attachment_id );

	if ( empty( $missing_sizes ) ) {
		return $image_meta;
	}

	// This also updates the image meta.
	return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id );
}