Changeset 33154 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 07/10/2015 09:32:23 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r32965 r33154 3053 3053 $GLOBALS['wp_press_this']->add_category(); 3054 3054 } 3055 3056 /** 3057 * AJAX handler for cropping an image. 3058 * 3059 * @since 4.3.0 3060 * 3061 * @global WP_Site_Icon $wp_site_icon 3062 */ 3063 function wp_ajax_crop_image() { 3064 $attachment_id = absint( $_POST['id'] ); 3065 3066 check_ajax_referer( 'image_editor-' . $attachment_id, 'nonce' ); 3067 if ( ! current_user_can( 'customize' ) ) { 3068 wp_send_json_error(); 3069 } 3070 3071 $context = str_replace( '_', '-', $_POST['context'] ); 3072 $data = array_map( 'absint', $_POST['cropDetails'] ); 3073 $cropped = wp_crop_image( $attachment_id, $data['x1'], $data['y1'], $data['width'], $data['height'], $data['dst_width'], $data['dst_height'] ); 3074 3075 if ( ! $cropped || is_wp_error( $cropped ) ) { 3076 wp_send_json_error( array( 'message' => __( 'Image could not be processed.' ) ) ); 3077 } 3078 3079 switch ( $context ) { 3080 case 'site-icon': 3081 require_once ABSPATH . '/wp-admin/includes/class-wp-site-icon.php'; 3082 global $wp_site_icon; 3083 3084 /** This filter is documented in wp-admin/custom-header.php */ 3085 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 3086 $object = $wp_site_icon->create_attachment_object( $cropped, $attachment_id ); 3087 unset( $object['ID'] ); 3088 3089 // Update the attachment. 3090 add_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) ); 3091 $attachment_id = $wp_site_icon->insert_attachment( $object, $cropped ); 3092 remove_filter( 'intermediate_image_sizes_advanced', array( $wp_site_icon, 'additional_sizes' ) ); 3093 3094 // Additional sizes in wp_prepare_attachment_for_js(). 3095 add_filter( 'image_size_names_choose', array( $wp_site_icon, 'additional_sizes' ) ); 3096 break; 3097 3098 default: 3099 3100 /** 3101 * Filters the attachment id for a cropped image. 3102 * 3103 * @since 4.3.0 3104 * 3105 * @param int $attachment_id The ID of the cropped image. 3106 * @param string $context The feature requesting the cropped image. 3107 */ 3108 $attachment_id = apply_filters( 'wp_ajax_cropped_attachment_id', 0, $context ); 3109 3110 if ( ! $attachment_id ) { 3111 wp_send_json_error(); 3112 } 3113 } 3114 3115 wp_send_json_success( wp_prepare_attachment_for_js( $attachment_id ) ); 3116 }
Note: See TracChangeset
for help on using the changeset viewer.