Customizer: Improve handling of crops in the media library.

This is a follow up on r41732, implementing the following improvements:

* Attachment parent info is now stored in attachment meta rather than a 
separate post meta key.
* Attachments created from contextual crops (e.g. header, logos, etc.) are
filtered out of the media library using a new `_filterContext` method in
`wp.media.controller.Library`.

Props joemcgill, westonruter.
See #21819.

Built from https://develop.svn.wordpress.org/trunk@41937


git-svn-id: http://core.svn.wordpress.org/trunk@41771 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Joe McGill
2017-10-19 04:18:47 +00:00
parent 20aad6b5c5
commit d21f6799a6
6 changed files with 31 additions and 10 deletions

View File

@@ -1187,6 +1187,11 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
$attachment_id = wp_insert_attachment( $object, $cropped );
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
// If this is a crop, save the original attachment ID as metadata.
if ( $parent_id ) {
$metadata['attachment_parent'] = $parent_id;
}
/**
* Filters the header image attachment metadata.
*
@@ -1197,11 +1202,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
* @param array $metadata Attachment metadata.
*/
$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
wp_update_attachment_metadata( $attachment_id, $metadata );
if ( $parent_id ) {
$meta = add_post_meta( $attachment_id, '_wp_attachment_parent', $parent_id, true );
}
wp_update_attachment_metadata( $attachment_id, $metadata );
return $attachment_id;
}