function wp_ajax_crop_image() { $attachment_id =
absint( $_POST['id'
] );
check_ajax_referer( 'image_editor-' .
$attachment_id, 'nonce'
);
if ( empty( $attachment_id ) || !
current_user_can( 'edit_post',
$attachment_id ) ) { wp_send_json_error();
} $context =
str_replace( '_', '-',
$_POST['context'
] );
$data =
array_map( 'absint',
$_POST['cropDetails'
] );
$cropped =
wp_crop_image( $attachment_id,
$data['x1'
],
$data['y1'
],
$data['width'
],
$data['height'
],
$data['dst_width'
],
$data['dst_height'
] );
if ( !
$cropped ||
is_wp_error( $cropped ) ) { wp_send_json_error( array
( 'message' =>
__( 'Image could not be processed.'
) ) );
} switch ( $context ) { case 'site-icon':
require_once ABSPATH . 'wp-admin/includes/class-wp-site-icon.php';
$wp_site_icon =
new WP_Site_Icon();
// Skip creating a new attachment if the attachment is a Site Icon.