Make WordPress Core

Changeset 33280


Ignore:
Timestamp:
07/15/2015 07:53:23 PM (10 years ago)
Author:
obenland
Message:

Customize: Provide a default way to save cropped images.

Allows plugins and themes to use WP_Customize_Cropped_Image_Control without
having to define their own way of saving the cropped image.

Props celloexpressions for initial patch.
Fixes #29211.

Location:
trunk/src
Files:
3 edited

Legend:

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

    r33257 r33280  
    30963096
    30973097            /**
     3098             * Fires before a cropped image is saved.
     3099             *
     3100             * Allows to add filters to modify the way a cropped image is saved.
     3101             *
     3102             * @since 4.3.0
     3103             *
     3104             * @param string $context       The Customizer control requesting the cropped image.
     3105             * @param int    $attachment_id The attachment ID of the original image.
     3106             * @param string $cropped       Path to the cropped image file.
     3107             */
     3108            do_action( 'wp_ajax_crop_image_pre_save', $context, $attachment_id, $cropped );
     3109
     3110            /** This filter is documented in wp-admin/custom-header.php */
     3111            $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
     3112
     3113            $parent_url = get_post( $attachment_id )->guid;
     3114            $url        = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
     3115
     3116            $size       = @getimagesize( $cropped );
     3117            $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
     3118
     3119            $object = array(
     3120                'post_title'     => basename( $cropped ),
     3121                'post_content'   => $url,
     3122                'post_mime_type' => $image_type,
     3123                'guid'           => $url,
     3124                'context'        => $context,
     3125            );
     3126
     3127            $attachment_id = wp_insert_attachment( $object, $cropped );
     3128            $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
     3129
     3130            /**
     3131             * Filter the cropped image attachment metadata.
     3132             *
     3133             * @since 4.3.0
     3134             *
     3135             * @see wp_generate_attachment_metadata()
     3136             *
     3137             * @param array $metadata Attachment metadata.
     3138             */
     3139            $metadata = apply_filters( 'wp_ajax_cropped_attachment_metadata', $metadata );
     3140            wp_update_attachment_metadata( $attachment_id, $metadata );
     3141
     3142            /**
    30983143             * Filter the attachment ID for a cropped image.
    30993144             *
    31003145             * @since 4.3.0
    31013146             *
    3102              * @param int    $attachment_id The ID of the cropped image.
    3103              * @param string $context       The feature requesting the cropped image.
     3147             * @param int    $attachment_id The attachment ID of the cropped image.
     3148             * @param string $context       The Customizer control requesting the cropped image.
    31043149             */
    3105             $attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', 0, $context );
    3106 
    3107             if ( ! $attachment_id ) {
    3108                 wp_send_json_error();
    3109             }
     3150            $attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', $attachment_id, $context );
    31103151    }
    31113152
  • trunk/src/wp-includes/class-wp-customize-control.php

    r33216 r33280  
    10061006 * @since 4.3.0
    10071007 *
    1008  * @see WP_Customize_Image_Control
     1008 * @see WP_Customize_Media_Control
    10091009 */
    1010 class WP_Customize_Cropped_Image_Control extends WP_Customize_Image_Control {
     1010class WP_Customize_Cropped_Image_Control extends WP_Customize_Media_Control {
    10111011
    10121012    /**
  • trunk/src/wp-includes/script-loader.php

    r33249 r33280  
    411411    $scripts->add( 'customize-preview',  "/wp-includes/js/customize-preview$suffix.js",  array( 'customize-base' ), false, 1 );
    412412    $scripts->add( 'customize-models',   "/wp-includes/js/customize-models.js", array( 'underscore', 'backbone' ), false, 1 );
    413     $scripts->add( 'customize-views',    "/wp-includes/js/customize-views.js",  array( 'jquery', 'underscore', 'imgareaselect', 'customize-models' ), false, 1 );
     413    $scripts->add( 'customize-views',    "/wp-includes/js/customize-views.js",  array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 );
    414414    $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base' ), false, 1 );
    415415    did_action( 'init' ) && $scripts->localize( 'customize-controls', '_wpCustomizeControlsL10n', array(
Note: See TracChangeset for help on using the changeset viewer.