Make WordPress Core


Ignore:
Timestamp:
04/06/2012 08:47:24 PM (14 years ago)
Author:
ryan
Message:

Make choosing a header image from the media library play nicely with file replication plugins that do not guarantee images will be retained in the local filesystem.

  • When passing an attachment ID to wp_crop_image(), use load_image_to_edit() to fetch the image via a url fopen when the image does not exist in the filesystem.
  • Move load_image_to_edit() to wp-admin/includes/image.php so that it is always available for admin pages loads.
  • Fallback to the height and width stored in the attachment meta when the image no longer exists in the filesystem.

see #19840

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/custom-header.php

    r20358 r20384  
    701701        }
    702702
    703         list($width, $height, $type, $attr) = getimagesize( $file );
     703        if ( file_exists( $file ) ) {
     704            list( $width, $height, $type, $attr ) = getimagesize( $file );
     705        } else {
     706            $data = wp_get_attachment_metadata( $id );
     707            $height = $data[ 'height' ];
     708            $width = $data[ 'width' ];
     709            unset( $data );
     710        }
    704711
    705712        $max_width = 0;
     
    717724        {
    718725            // Add the meta-data
    719             wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
     726            if ( file_exists( $file ) )
     727                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    720728            update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
    721729
     
    725733        } elseif ( $width > $max_width ) {
    726734            $oitar = $width / $max_width;
    727             $image = wp_crop_image($file, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
     735            $image = wp_crop_image($id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
    728736            if ( is_wp_error( $image ) )
    729737                wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
Note: See TracChangeset for help on using the changeset viewer.