Created
December 20, 2012 22:41
-
-
Save markoheijnen/4349227 to your computer and use it in GitHub Desktop.
Hotfixing bug in wp_save_image() in WordPress 3.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action( 'wp_ajax_image-editor', 'fix_wp_ajax_image_editor', 0 ); | |
function fix_wp_ajax_image_editor() { | |
$attachment_id = intval( $_POST['postid'] ); | |
if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) | |
wp_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' : | |
$old_meta = wp_get_attachment_metadata( $attachment_id ); | |
$msg = wp_save_image( $attachment_id ); | |
$msg = json_encode( $msg ); | |
break; | |
case 'scale' : | |
$old_meta = wp_get_attachment_metadata( $attachment_id ); | |
$msg = wp_save_image( $attachment_id ); | |
break; | |
case 'restore' : | |
$msg = wp_restore_image( $attachment_id ); | |
break; | |
} | |
if( isset( $old_meta ) ) { | |
$new_meta = wp_get_attachment_metadata( $attachment_id ); | |
$new_meta['sizes'] = array_merge( $old_meta['sizes'], $new_meta['sizes'] ); | |
wp_update_attachment_metadata( $attachment_id, $new_meta ); | |
if( 'save' == $_POST['do'] ) | |
wp_die( $msg ); | |
} | |
wp_image_editor( $attachment_id, $msg ); | |
wp_die(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment