mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-25 13:52:59 +02:00
Upload:
- Run the `wp_generate_attachment_metadata` filter at the end in `wp_update_image_subsizes()` when new metadata was generated and additional image sub-sizes were created. - Add another arg in the `wp_generate_attachment_metadata` filter for additional context. - Fix inline docs and ensure the new image meta is always saved before starting post-processing. Fixes #48472 for trunk. Built from https://develop.svn.wordpress.org/trunk@46621 git-svn-id: http://core.svn.wordpress.org/trunk@46418 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e678d5bf28
commit
ed651b17a4
@ -142,20 +142,28 @@ function wp_update_image_subsizes( $attachment_id ) {
|
|||||||
// Previously failed upload?
|
// Previously failed upload?
|
||||||
// If there is an uploaded file, make all sub-sizes and generate all of the attachment meta.
|
// If there is an uploaded file, make all sub-sizes and generate all of the attachment meta.
|
||||||
if ( ! empty( $image_file ) ) {
|
if ( ! empty( $image_file ) ) {
|
||||||
return wp_create_image_subsizes( $image_file, $attachment_id );
|
$image_meta = wp_create_image_subsizes( $image_file, $attachment_id );
|
||||||
} else {
|
} else {
|
||||||
return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) );
|
return new WP_Error( 'invalid_attachment', __( 'The attached file cannot be found.' ) );
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$missing_sizes = wp_get_missing_image_subsizes( $attachment_id );
|
||||||
|
|
||||||
|
if ( empty( $missing_sizes ) ) {
|
||||||
|
return $image_meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This also updates the image meta.
|
||||||
|
$image_meta = _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id );
|
||||||
}
|
}
|
||||||
|
|
||||||
$missing_sizes = wp_get_missing_image_subsizes( $attachment_id );
|
/** This filter is documented in wp-admin/includes/image.php */
|
||||||
|
$image_meta = apply_filters( 'wp_generate_attachment_metadata', $image_meta, $attachment_id, 'update' );
|
||||||
|
|
||||||
if ( empty( $missing_sizes ) ) {
|
// Save the updated metadata.
|
||||||
return $image_meta;
|
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||||
}
|
|
||||||
|
|
||||||
// This also updates the image meta.
|
return $image_meta;
|
||||||
return _wp_make_subsizes( $missing_sizes, $image_file, $image_meta, $attachment_id );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -275,6 +283,9 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
|||||||
$image_meta['image_meta']['orientation'] = 1;
|
$image_meta['image_meta']['orientation'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initial save of the new metadata when the original image was scaled.
|
||||||
|
// At this point the file was uploaded and moved to the uploads directory
|
||||||
|
// but the image sub-sizes haven't been created yet and the `sizes` array is empty.
|
||||||
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||||
} else {
|
} else {
|
||||||
// TODO: log errors.
|
// TODO: log errors.
|
||||||
@ -307,11 +318,15 @@ function wp_create_image_subsizes( $file, $attachment_id ) {
|
|||||||
$image_meta['image_meta']['orientation'] = 1;
|
$image_meta['image_meta']['orientation'] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Initial save of the new metadata when the original image was rotated.
|
||||||
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||||
} else {
|
} else {
|
||||||
// TODO: log errors.
|
// TODO: log errors.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// Initial save of the new metadata when the image was not scaled or rotated.
|
||||||
|
wp_update_attachment_metadata( $attachment_id, $image_meta );
|
||||||
}
|
}
|
||||||
|
|
||||||
$new_sizes = wp_get_registered_image_subsizes();
|
$new_sizes = wp_get_registered_image_subsizes();
|
||||||
@ -578,10 +593,12 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
|||||||
*
|
*
|
||||||
* @since 2.1.0
|
* @since 2.1.0
|
||||||
*
|
*
|
||||||
* @param array $metadata An array of attachment meta data.
|
* @param array $metadata An array of attachment meta data.
|
||||||
* @param int $attachment_id Current attachment ID.
|
* @param int $attachment_id Current attachment ID.
|
||||||
|
* @param string $context Additional context. Can be 'create' when metadata was initially created for new attachment
|
||||||
|
* or 'update' when the metadata was updated.
|
||||||
*/
|
*/
|
||||||
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id );
|
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '5.4-alpha-46620';
|
$wp_version = '5.4-alpha-46621';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user