Make WordPress Core

Ticket #20657: 20657.3.patch

File 20657.3.patch, 2.9 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/custom-header.php

     
    752752                } elseif ( $width > $max_width ) {
    753753                        $oitar = $width / $max_width;
    754754                        $image = wp_crop_image($id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
    755                         if ( is_wp_error( $image ) )
     755                        if ( ! $image || is_wp_error( $image ) )
    756756                                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
    757757
    758758                        $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
     
    868868                        $dst_width = get_theme_support( 'custom-header', 'width' );
    869869
    870870                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
    871                 if ( is_wp_error( $cropped ) )
     871                if ( ! $cropped || is_wp_error( $cropped ) )
    872872                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
    873873
    874874                $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication
     875                $is_cropped = ( get_attached_file( $attachment_id ) != $cropped );
    875876
    876877                $parent = get_post($attachment_id);
    877878                $parent_url = $parent->guid;
    878                 $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
     879                $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
    879880
    880881                $size = @getimagesize( $cropped );
    881882                $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
     
    889890                        'guid' => $url,
    890891                        'context' => 'custom-header'
    891892                );
    892                 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'] )
    893                         unset($object['ID']);
     893                if ( ! empty( $_POST['new-attachment'] ) )
     894                        unset( $object['ID'] );
    894895
    895896                // Update the attachment
    896897                $attachment_id = wp_insert_attachment( $object, $cropped );
    897898                wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
    898                 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
     899                update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option( 'stylesheet' ) );
    899900
    900901                set_theme_mod('header_image', $url);
    901902
     
    909910                set_theme_mod( 'header_image_data', $header_data );
    910911
    911912                // cleanup
    912                 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
     913                $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
    913914                if ( file_exists( $medium ) )
    914915                        @unlink( apply_filters( 'wp_delete_file', $medium ) );
    915                 if ( empty ( $_POST['new-attachment'] ) )
     916                if ( empty( $_POST['new-attachment'] ) && $is_cropped )
    916917                        @unlink( apply_filters( 'wp_delete_file', $original ) );
    917918
    918919                return $this->finished();