Check wp_crop_image() for a false return value. Don't delete original image if crop not sucessful. Don't delete the original image when wp_crop_image() returns it untouched. Prevents deletion of header image when no cropping is done to the originally uploaded image. Props SergeyBiryukov, westi. fixes #20657

git-svn-id: https://develop.svn.wordpress.org/trunk@20769 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2012-05-11 16:15:15 +00:00
parent 73586de8bd
commit 9ffc69487f

View File

@ -752,7 +752,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
} elseif ( $width > $max_width ) {
$oitar = $width / $max_width;
$image = wp_crop_image($id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
if ( is_wp_error( $image ) )
if ( ! $image || is_wp_error( $image ) )
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
$image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
@ -868,10 +868,11 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
$dst_width = get_theme_support( 'custom-header', 'width' );
$cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
if ( is_wp_error( $cropped ) )
if ( ! $cropped || is_wp_error( $cropped ) )
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
$is_cropped = ( get_attached_file( $attachment_id ) != $cropped );
$parent = get_post($attachment_id);
$parent_url = $parent->guid;
@ -889,7 +890,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
'guid' => $url,
'context' => 'custom-header'
);
if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] )
if ( ! empty( $_POST['new-attachment'] ) )
unset( $object['ID'] );
// Update the attachment
@ -912,7 +913,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
if ( file_exists( $medium ) )
@unlink( apply_filters( 'wp_delete_file', $medium ) );
if ( empty ( $_POST['new-attachment'] ) )
if ( empty( $_POST['new-attachment'] ) && $is_cropped )
@unlink( apply_filters( 'wp_delete_file', $original ) );
return $this->finished();