Ticket #6008: custom-header.diff

File custom-header.diff, 2.7 KB (added by spikeyslam, 5 years ago)
Line 
1Index: wp-admin/custom-header.php
2===================================================================
3--- wp-admin/custom-header.php  (revision 7038)
4+++ wp-admin/custom-header.php  (working copy)
5@@ -211,6 +211,7 @@
6                die( $file['error'] );
7 
8                $url = $file['url'];
9+               $type = $file['type'];
10                $file = $file['file'];
11                $filename = basename($file);
12 
13@@ -218,7 +219,7 @@
14                $object = array(
15                'post_title' => $filename,
16                'post_content' => $url,
17-               'post_mime_type' => 'import',
18+               'post_mime_type' => $type,
19                'guid' => $url);
20 
21                // Save the data
22@@ -227,6 +228,9 @@
23                list($width, $height, $type, $attr) = getimagesize( $file );
24 
25                if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
26+                       // Add the meta-data
27+                       wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
28+
29                        set_theme_mod('header_image', clean_url($url));
30                        do_action('wp_create_file_in_uploads', $file, $id); // For replication
31                        return $this->finished();
32@@ -279,22 +283,34 @@
33                        $_POST['height'] = $_POST['height'] * $_POST['oitar'];
34                }
35 
36-               $header = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
37-               $header = apply_filters('wp_create_file_in_uploads', $header); // For replication
38+               $original = get_attached_file( $_POST['attachment_id'] );
39 
40+               $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT);
41+               $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
42+
43                $parent = get_post($_POST['attachment_id']);
44-
45                $parent_url = $parent->guid;
46+               $url = str_replace(basename($parent_url), basename($cropped), $parent_url);
47 
48-               $url = str_replace(basename($parent_url), basename($header), $parent_url);
49+               // Construct the object array
50+               $object = array(
51+                       'ID' => $_POST['attachment_id'],
52+                       'post_title' => basename($cropped),
53+                       'post_content' => $url,
54+                       'post_mime_type' => 'image/jpeg',
55+                       'guid' => $url
56+               );
57 
58+               // Update the attachment
59+               wp_insert_attachment($object, $cropped);
60+               wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) );
61+
62                set_theme_mod('header_image', $url);
63 
64                // cleanup
65-               $file = get_attached_file( $_POST['attachment_id'] );
66-               $medium = str_replace(basename($file), 'midsize-'.basename($file), $file);
67+               $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
68                @unlink( apply_filters( 'wp_delete_file', $medium ) );
69-               wp_delete_attachment( $_POST['attachment_id'] );
70+               @unlink( apply_filters( 'wp_delete_file', $original ) );
71 
72                return $this->finished();
73        }