Skip to content

Instantly share code, notes, and snippets.

@markoheijnen
Created December 20, 2012 22:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markoheijnen/4349227 to your computer and use it in GitHub Desktop.
Save markoheijnen/4349227 to your computer and use it in GitHub Desktop.
Hotfixing bug in wp_save_image() in WordPress 3.5
<?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