Changeset 20769
- Timestamp:
- 05/11/2012 04:15:15 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-header.php
r20768 r20769 753 753 $oitar = $width / $max_width; 754 754 $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 ) ) 756 756 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 757 757 … … 869 869 870 870 $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 ) ) 872 872 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 873 873 874 874 $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication 875 $is_cropped = ( get_attached_file( $attachment_id ) != $cropped ); 875 876 876 877 $parent = get_post($attachment_id); 877 878 $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 ); 879 880 880 881 $size = @getimagesize( $cropped ); … … 890 891 'context' => 'custom-header' 891 892 ); 892 if ( isset( $_POST['new-attachment'] ) && $_POST['new-attachment'])893 unset( $object['ID']);893 if ( ! empty( $_POST['new-attachment'] ) ) 894 unset( $object['ID'] ); 894 895 895 896 // Update the attachment 896 897 $attachment_id = wp_insert_attachment( $object, $cropped ); 897 898 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' ) ); 899 900 900 901 set_theme_mod('header_image', $url); … … 910 911 911 912 // cleanup 912 $medium = str_replace( basename($original), 'midsize-'.basename($original), $original);913 $medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original ); 913 914 if ( file_exists( $medium ) ) 914 915 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 915 if ( empty ( $_POST['new-attachment'] ))916 if ( empty( $_POST['new-attachment'] ) && $is_cropped ) 916 917 @unlink( apply_filters( 'wp_delete_file', $original ) ); 917 918
Note: See TracChangeset
for help on using the changeset viewer.