WordPress.org

Make WordPress Core

Changeset 33356


Ignore:
Timestamp:
07/22/2015 02:29:57 AM (5 years ago)
Author:
obenland
Message:

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.

Location:
trunk/src/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r33325 r33356  
    30813081            global $wp_site_icon;
    30823082
     3083            // Skip creating a new attachment if the attachment is a Site Icon.
     3084            if ( get_post_meta( $attachment_id, '_wp_attachment_context', true ) == $context ) {
     3085
     3086                // Delete the temporary cropped file, we don't need it.
     3087                wp_delete_file( $cropped );
     3088
     3089                // Additional sizes in wp_prepare_attachment_for_js().
     3090                add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) );
     3091                break;
     3092            }
     3093
    30833094            /** This filter is documented in wp-admin/custom-header.php */
    30843095            $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
  • trunk/src/wp-admin/js/customize-controls.js

    r33333 r33356  
    20772077
    20782078        /**
     2079         * After an image is selected in the media modal, switch to the cropper
     2080         * state if the image isn't the right size.
     2081         */
     2082        onSelect: function() {
     2083            var attachment = this.frame.state().get( 'selection' ).first().toJSON(),
     2084                controller = this;
     2085
     2086            if ( this.params.width === attachment.width && this.params.height === attachment.height && ! this.params.flex_width && ! this.params.flex_height ) {
     2087                wp.ajax.post( 'crop-image', {
     2088                    nonce: attachment.nonces.edit,
     2089                    id: attachment.id,
     2090                    context: 'site-icon',
     2091                    cropDetails: {
     2092                        x1: 0,
     2093                        y1: 0,
     2094                        width: this.params.width,
     2095                        height: this.params.height,
     2096                        dst_width: this.params.width,
     2097                        dst_height: this.params.height
     2098                    }
     2099                } ).done( function( croppedImage ) {
     2100                    controller.setImageFromAttachment( croppedImage );
     2101                    controller.frame.close();
     2102                } ).fail( function() {
     2103                    controller.trigger('content:error:crop');
     2104                } );
     2105            } else {
     2106                this.frame.setState( 'cropper' );
     2107            }
     2108        },
     2109
     2110        /**
    20792111         * Updates the setting and re-renders the control UI.
    20802112         *
     
    20912123
    20922124            // Update the icon in-browser.
    2093             $( 'link[rel="icon"]' ).attr( 'href', icon.url );
     2125            $( 'link[sizes="32x32"]' ).attr( 'href', icon.url );
    20942126        },
    20952127
Note: See TracChangeset for help on using the changeset viewer.