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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@33328 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Konstantin Obenland 2015-07-22 02:30:25 +00:00
parent a0e830d9af
commit 0f61e187b6
4 changed files with 47 additions and 4 deletions

View File

@ -3080,6 +3080,17 @@ function wp_ajax_crop_image() {
require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php'; require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php';
global $wp_site_icon; 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 */ /** This filter is documented in wp-admin/custom-header.php */
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
$object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id ); $object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id );

View File

@ -2075,6 +2075,38 @@
this.frame.on( 'skippedcrop', this.onSkippedCrop, this ); 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. * Updates the setting and re-renders the control UI.
* *
@ -2090,7 +2122,7 @@
// Update the icon in-browser. // Update the icon in-browser.
$( 'link[rel="icon"]' ).attr( 'href', icon.url ); $( 'link[sizes="32x32"]' ).attr( 'href', icon.url );
}, },
/** /**

File diff suppressed because one or more lines are too long

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.3-beta3-33355'; $wp_version = '4.3-beta3-33356';
/** /**
* 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.