+case 'image-editor':
+ $attachment_id = intval($_POST['postid']);
+ if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
+ die('-1');
+
+ check_ajax_referer( "image_editor-$attachment_id" );
+ include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
+
+ $msg = false;
+ switch ( $_POST['do'] ) {
+ case 'save' :
+ $msg = wp_save_image($attachment_id);
+ $msg = json_encode($msg);
+ die($msg);
+ break;
+ case 'scale' :
+ $msg = wp_save_image($attachment_id);
+ break;
+ case 'restore' :
+ $msg = wp_restore_image($attachment_id);
+ break;
+ }
+
+ wp_image_editor($attachment_id, $msg);
+ die();
+ break;
+case 'set-post-thumbnail':
+ $post_id = intval( $_POST['post_id'] );
+ if ( !current_user_can( 'edit_post', $post_id ) )
+ die( '-1' );
+ $thumbnail_id = intval( $_POST['thumbnail_id'] );
+
+ if ( $thumbnail_id == '-1' ) {
+ delete_post_meta( $post_id, '_thumbnail_id' );
+ die( _wp_post_thumbnail_html() );
+ }
+
+ if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
+ $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'thumbnail' );
+ if ( !empty( $thumbnail_html ) ) {
+ update_post_meta( $post_id, '_thumbnail_id', $thumbnail_id );
+ die( _wp_post_thumbnail_html( $thumbnail_id ) );
+ }
+ }
+ die( '0' );