WordPress.org

Make WordPress Core

Changeset 7049


Ignore:
Timestamp:
02/26/08 21:07:15 (7 years ago)
Author:
ryan
Message:

Show custom header images in the media library. Props spikeyslam. fixes #6008

File:
1 edited

Legend:

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

    r6943 r7049  
    212212 
    213213        $url = $file['url']; 
     214        $type = $file['type']; 
    214215        $file = $file['file']; 
    215216        $filename = basename($file); 
     
    219220        'post_title' => $filename, 
    220221        'post_content' => $url, 
    221         'post_mime_type' => 'import', 
     222        'post_mime_type' => $type, 
    222223        'guid' => $url); 
    223224 
     
    228229 
    229230        if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 
     231            // Add the meta-data 
     232            wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 
     233 
    230234            set_theme_mod('header_image', clean_url($url)); 
    231235            do_action('wp_create_file_in_uploads', $file, $id); // For replication 
     
    280284        } 
    281285 
    282         $header = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); 
    283         $header = apply_filters('wp_create_file_in_uploads', $header); // For replication 
     286        $original = get_attached_file( $_POST['attachment_id'] ); 
     287 
     288        $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); 
     289        $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication 
    284290 
    285291        $parent = get_post($_POST['attachment_id']); 
    286  
    287292        $parent_url = $parent->guid; 
    288  
    289         $url = str_replace(basename($parent_url), basename($header), $parent_url); 
     293        $url = str_replace(basename($parent_url), basename($cropped), $parent_url); 
     294 
     295        // Construct the object array 
     296        $object = array( 
     297            'ID' => $_POST['attachment_id'], 
     298            'post_title' => basename($cropped), 
     299            'post_content' => $url, 
     300            'post_mime_type' => 'image/jpeg', 
     301            'guid' => $url 
     302        ); 
     303 
     304        // Update the attachment 
     305        wp_insert_attachment($object, $cropped); 
     306        wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); 
    290307 
    291308        set_theme_mod('header_image', $url); 
    292309 
    293310        // cleanup 
    294         $file = get_attached_file( $_POST['attachment_id'] ); 
    295         $medium = str_replace(basename($file), 'midsize-'.basename($file), $file); 
     311        $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); 
    296312        @unlink( apply_filters( 'wp_delete_file', $medium ) ); 
    297         wp_delete_attachment( $_POST['attachment_id'] ); 
     313        @unlink( apply_filters( 'wp_delete_file', $original ) ); 
    298314 
    299315        return $this->finished(); 
Note: See TracChangeset for help on using the changeset viewer.