Ticket #17242: 17242.7.diff

File 17242.7.diff, 8.1 KB (added by aaroncampbell, 16 months ago)
Line 
1Index: wp-includes/theme.php
2===================================================================
3--- wp-includes/theme.php       (revision 19794)
4+++ wp-includes/theme.php       (working copy)
5@@ -1547,16 +1547,27 @@
6 
7        foreach ( (array) $headers as $header ) {
8                $url = esc_url_raw( $header->guid );
9+               $header_data = wp_get_attachment_metadata( $header->ID );
10                $header = basename($url);
11                $header_images[$header] = array();
12                $header_images[$header]['url'] =  $url;
13                $header_images[$header]['thumbnail_url'] =  $url;
14                $header_images[$header]['uploaded'] = true;
15+               $header_images[$header]['width'] = $header_data['width'];
16+               $header_images[$header]['height'] = $header_data['height'];
17        }
18 
19        return $header_images;
20 }
21 
22+function get_header_image_width() {
23+       return get_theme_mod( 'header_image_width', HEADER_IMAGE_WIDTH );
24+}
25+
26+function get_header_image_height() {
27+       return get_theme_mod( 'header_image_height', HEADER_IMAGE_HEIGHT );
28+}
29+
30 /**
31  * Add callbacks for image header display.
32  *
33Index: wp-admin/custom-header.php
34===================================================================
35--- wp-admin/custom-header.php  (revision 19794)
36+++ wp-admin/custom-header.php  (working copy)
37@@ -188,7 +188,20 @@
38 
39                if ( isset( $_POST['resetheader'] ) ) {
40                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
41-                       remove_theme_mod( 'header_image' );
42+                       $this->process_default_headers();
43+                       $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
44+                       $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
45+                       foreach ( $this->default_headers as $header => $details ) {
46+                               if ( $details['url'] == $default ) {
47+                                       $default_data = $details;
48+                                       break;
49+                               }
50+                       }
51+                       set_theme_mod( 'header_image', $default );
52+                       $width = empty( $default_data['width'] )? HEADER_IMAGE_WIDTH : $default_data['width'];
53+                       $height = empty( $default_data['height'] )? HEADER_IMAGE_HEIGHT : $default_data['height'];
54+                       set_theme_mod( 'header_image_width', $width );
55+                       set_theme_mod( 'header_image_height', $height );
56                        return;
57                }
58 
59@@ -225,10 +238,17 @@
60                        } else {
61                                $this->process_default_headers();
62                                $uploaded = get_uploaded_header_images();
63-                               if ( isset( $uploaded[$_POST['default-header']] ) )
64+                               if ( isset( $uploaded[$_POST['default-header']] ) ) {
65                                        set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) );
66-                               elseif ( isset( $this->default_headers[$_POST['default-header']] ) )
67+                                       set_theme_mod( 'header_image_width', $uploaded[$_POST['default-header']]['width'] );
68+                                       set_theme_mod( 'header_image_height', $uploaded[$_POST['default-header']]['height'] );
69+                               } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) {
70                                        set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
71+                                       $width = empty( $this->default_headers[$_POST['default-header']]['width'] )? HEADER_IMAGE_WIDTH : $this->default_headers[$_POST['default-header']]['width'];
72+                                       $height = empty( $this->default_headers[$_POST['default-header']]['height'] )? HEADER_IMAGE_HEIGHT : $this->default_headers[$_POST['default-header']]['height'];
73+                                       set_theme_mod( 'header_image_width', $width );
74+                                       set_theme_mod( 'header_image_height', $height );
75+                               }
76                        }
77                }
78        }
79@@ -438,13 +458,20 @@
80                jQuery('img#upload').imgAreaSelect({
81                        handles: true,
82                        keys: true,
83-                       aspectRatio: xinit + ':' + yinit,
84                        show: true,
85                        x1: 0,
86                        y1: 0,
87                        x2: xinit,
88                        y2: yinit,
89+                       <?php
90+                       $header_support = get_theme_support( 'custom-header' );
91+                       if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
92+                       ?>
93+                       aspectRatio: xinit + ':' + yinit,
94                        maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
95+                       <?php
96+                       }
97+                       ?>
98                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
99                        onInit: function () {
100                                jQuery('#width').val(xinit);
101@@ -492,7 +519,7 @@
102          call_user_func( $this->admin_image_div_callback );
103        } else {
104        ?>
105-       <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);">
106+       <div id="headimg" style="max-width:<?php echo get_header_image_width(); ?>px;height:<?php echo get_header_image_height(); ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);">
107                <?php
108                if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
109                        $style = ' style="display:none;"';
110@@ -510,7 +537,16 @@
111 <th scope="row"><?php _e( 'Upload Image' ); ?></th>
112 <td>
113        <p><?php _e( 'You can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
114-       <?php printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p>
115+       <?php
116+       $header_support = get_theme_support( 'custom-header' );
117+       if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
118+               printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
119+       } else {
120+               printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH );
121+               if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) )
122+                       printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) );
123+       }
124+       ?></p>
125        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
126        <p>
127                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
128@@ -662,7 +698,9 @@
129 
130                list($width, $height, $type, $attr) = getimagesize( $file );
131 
132-               if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
133+               $header_support = get_theme_support( 'custom-header' );
134+               // If flexible height isn't supported and the image is the exact right size
135+               if ( ( !isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !empty( $header_support[ 0 ][ 'flex-height' ] ) ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
136                        // Add the meta-data
137                        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
138                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
139@@ -733,7 +771,13 @@
140                $attachment_id = absint( $_POST['attachment_id'] );
141                $original = get_attached_file($attachment_id);
142 
143-               $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
144+               $header_support = get_theme_support( 'custom-header' );
145+               if ( isset( $header_support[ 0 ] ) && !empty( $header_support[ 0 ][ 'flex-height' ] ) )
146+                       $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] );
147+               else
148+                       $dst_height = HEADER_IMAGE_HEIGHT;
149+
150+               $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height );
151                if ( is_wp_error( $cropped ) )
152                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
153 
154@@ -759,6 +803,8 @@
155                update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
156 
157                set_theme_mod('header_image', $url);
158+               set_theme_mod( 'header_image_width', (int) $_POST['width'] );
159+               set_theme_mod( 'header_image_height', $dst_height );
160 
161                // cleanup
162                $medium = str_replace(basename($original), 'midsize-'.basename($original), $original);
163Index: wp-admin/css/wp-admin.dev.css
164===================================================================
165--- wp-admin/css/wp-admin.dev.css       (revision 19794)
166+++ wp-admin/css/wp-admin.dev.css       (working copy)
167@@ -4494,7 +4494,6 @@
168 
169 .appearance_page_custom-header #headimg {
170        border: 1px solid #DFDFDF;
171-       min-height: 100px;
172        width: 100%;
173 }
174