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:
parent
20aad6b5c5
commit
d21f6799a6
|
@ -1187,6 +1187,11 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
$attachment_id = wp_insert_attachment( $object, $cropped );
|
$attachment_id = wp_insert_attachment( $object, $cropped );
|
||||||
$metadata = wp_generate_attachment_metadata( $attachment_id, $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.
|
* 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.
|
* @param array $metadata Attachment metadata.
|
||||||
*/
|
*/
|
||||||
$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
|
$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
|
||||||
wp_update_attachment_metadata( $attachment_id, $metadata );
|
|
||||||
|
|
||||||
if ( $parent_id ) {
|
wp_update_attachment_metadata( $attachment_id, $metadata );
|
||||||
$meta = add_post_meta( $attachment_id, '_wp_attachment_parent', $parent_id, true );
|
|
||||||
}
|
|
||||||
|
|
||||||
return $attachment_id;
|
return $attachment_id;
|
||||||
}
|
}
|
||||||
|
|
|
@ -953,6 +953,9 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar
|
||||||
}) );
|
}) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this._filterContext();
|
||||||
|
this.get('library').on( 'add', this._filterContext, this );
|
||||||
|
|
||||||
this.resetDisplays();
|
this.resetDisplays();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1152,6 +1155,19 @@ Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar
|
||||||
if ( view && view.get( mode ) ) {
|
if ( view && view.get( mode ) ) {
|
||||||
setUserSetting( 'libraryContent', mode );
|
setUserSetting( 'libraryContent', mode );
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter out contextually created attachments (e.g. headers, logos, etc.)
|
||||||
|
*
|
||||||
|
* @since 4.9.0
|
||||||
|
*/
|
||||||
|
_filterContext: function() {
|
||||||
|
var library = this.get('library');
|
||||||
|
|
||||||
|
library.set( library.filter( function( item ) {
|
||||||
|
return item.get('context') === '';
|
||||||
|
} ) );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -3159,6 +3159,9 @@ function wp_prepare_attachment_for_js( $attachment ) {
|
||||||
$response['filesizeHumanReadable'] = size_format( $bytes );
|
$response['filesizeHumanReadable'] = size_format( $bytes );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$context = get_post_meta( $attachment->ID, '_wp_attachment_context', true );
|
||||||
|
$response['context'] = ( $context ) ? $context : '';
|
||||||
|
|
||||||
if ( current_user_can( 'edit_post', $attachment->ID ) ) {
|
if ( current_user_can( 'edit_post', $attachment->ID ) ) {
|
||||||
$response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
|
$response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
|
||||||
$response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID );
|
$response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID );
|
||||||
|
|
|
@ -1214,7 +1214,7 @@ function get_uploaded_header_images() {
|
||||||
$header_images[$header_index]['url'] = $url;
|
$header_images[$header_index]['url'] = $url;
|
||||||
$header_images[$header_index]['thumbnail_url'] = $url;
|
$header_images[$header_index]['thumbnail_url'] = $url;
|
||||||
$header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
|
$header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
|
||||||
$header_images[$header_index]['attachment_parent'] = (int) get_post_meta( $header->ID, '_wp_attachment_parent', true );
|
$header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : '';
|
||||||
|
|
||||||
if ( isset( $header_data['width'] ) )
|
if ( isset( $header_data['width'] ) )
|
||||||
$header_images[$header_index]['width'] = $header_data['width'];
|
$header_images[$header_index]['width'] = $header_data['width'];
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.9-beta2-41936';
|
$wp_version = '4.9-beta2-41937';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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