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: http://core.svn.wordpress.org/trunk@20769 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ae9ce57153
commit
a0f07732d4
|
@ -752,7 +752,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
} elseif ( $width > $max_width ) {
|
} elseif ( $width > $max_width ) {
|
||||||
$oitar = $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));
|
$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' ) );
|
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
|
$image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
|
||||||
|
@ -868,14 +868,15 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
$dst_width = get_theme_support( 'custom-header', 'width' );
|
$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 );
|
$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' ) );
|
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
|
$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 = get_post($attachment_id);
|
||||||
$parent_url = $parent->guid;
|
$parent_url = $parent->guid;
|
||||||
$url = str_replace(basename($parent_url), basename($cropped), $parent_url);
|
$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
|
||||||
|
|
||||||
$size = @getimagesize( $cropped );
|
$size = @getimagesize( $cropped );
|
||||||
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
|
||||||
|
@ -889,13 +890,13 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
'guid' => $url,
|
'guid' => $url,
|
||||||
'context' => 'custom-header'
|
'context' => 'custom-header'
|
||||||
);
|
);
|
||||||
if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] )
|
if ( ! empty( $_POST['new-attachment'] ) )
|
||||||
unset($object['ID']);
|
unset( $object['ID'] );
|
||||||
|
|
||||||
// Update the attachment
|
// Update the attachment
|
||||||
$attachment_id = wp_insert_attachment( $object, $cropped );
|
$attachment_id = wp_insert_attachment( $object, $cropped );
|
||||||
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
|
wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
|
||||||
update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
|
update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option( 'stylesheet' ) );
|
||||||
|
|
||||||
set_theme_mod('header_image', $url);
|
set_theme_mod('header_image', $url);
|
||||||
|
|
||||||
|
@ -909,10 +910,10 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
|
||||||
set_theme_mod( 'header_image_data', $header_data );
|
set_theme_mod( 'header_image_data', $header_data );
|
||||||
|
|
||||||
// cleanup
|
// cleanup
|
||||||
$medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
|
$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
|
||||||
if ( file_exists( $medium ) )
|
if ( file_exists( $medium ) )
|
||||||
@unlink( apply_filters( 'wp_delete_file', $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 ) );
|
@unlink( apply_filters( 'wp_delete_file', $original ) );
|
||||||
|
|
||||||
return $this->finished();
|
return $this->finished();
|
||||||
|
|
Loading…
Reference in New Issue