Site Icon: Create custom sizes for images that don't need cropping.

This will duplicate an image that doesn't need cropping once and will skip
creating new images and custom sizes if the selected image has the `site-icon`
context.

Fixes #33011.


git-svn-id: https://develop.svn.wordpress.org/trunk@33356 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Konstantin Obenland 2015-07-22 02:29:57 +00:00
parent 7845150324
commit 2533d76203
2 changed files with 44 additions and 1 deletions

View File

@ -3080,6 +3080,17 @@ function wp_ajax_crop_image() {
require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php';
global $wp_site_icon;
// Skip creating a new attachment if the attachment is a Site Icon.
if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) {
// Delete the temporary cropped file, we don't need it.
wp_delete_file( $cropped );
// Additional sizes in wp_prepare_attachment_for_js().
add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
break;
}
/** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
$object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );

View File

@ -2075,6 +2075,38 @@
this.frame.on( 'skippedcrop', this.onSkippedCrop, this );
},
/**
* After an image is selected in the media modal, switch to the cropper
* state if the image isn't the right size.
*/
onSelect: function() {
var attachment = this.frame.state().get( 'selection' ).first().toJSON(),
controller = this;
if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) {
wp.ajax.post( 'crop-image', {
nonce: attachment.nonces.edit,
id: attachment.id,
context: 'site-icon',
cropDetails: {
x1: 0,
y1: 0,
width: this.params.width,
height: this.params.height,
dst_width: this.params.width,
dst_height: this.params.height
}
} ).done( function( croppedImage ) {
controller.setImageFromAttachment( croppedImage );
controller.frame.close();
} ).fail( function() {
controller.trigger('content:error:crop');
} );
} else {
this.frame.setState( 'cropper' );
}
},
/**
* Updates the setting and re-renders the control UI.
*
@ -2090,7 +2122,7 @@
// Update the icon in-browser.
$( 'link[rel="icon"]' ).attr( 'href', icon.url );
$( 'link[sizes="32x32"]' ).attr( 'href', icon.url );
},
/**