Make WordPress Core

Ticket #17242: 17242.5.diff

File 17242.5.diff, 6.5 KB (added by aaroncampbell, 11 years ago)
  • wp-includes/theme.php

     
    15471547
    15481548        foreach ( (array) $headers as $header ) {
    15491549                $url = esc_url_raw( $header->guid );
     1550                $header_data = wp_get_attachment_metadata( $header->ID );
    15501551                $header = basename($url);
    15511552                $header_images[$header] = array();
    15521553                $header_images[$header]['url'] =  $url;
    15531554                $header_images[$header]['thumbnail_url'] =  $url;
    15541555                $header_images[$header]['uploaded'] = true;
     1556                $header_images[$header]['width'] = $header_data['width'];
     1557                $header_images[$header]['height'] = $header_data['height'];
    15551558        }
    15561559
    15571560        return $header_images;
    15581561}
    15591562
     1563function get_header_image_width() {
     1564        return get_theme_mod( 'header_image_width', HEADER_IMAGE_WIDTH );
     1565}
     1566
     1567function get_header_image_height() {
     1568        return get_theme_mod( 'header_image_height', HEADER_IMAGE_HEIGHT );
     1569}
     1570
    15601571/**
    15611572 * Add callbacks for image header display.
    15621573 *
  • wp-admin/custom-header.php

     
    225225                        } else {
    226226                                $this->process_default_headers();
    227227                                $uploaded = get_uploaded_header_images();
    228                                 if ( isset( $uploaded[$_POST['default-header']] ) )
     228                                if ( isset( $uploaded[$_POST['default-header']] ) ) {
    229229                                        set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) );
    230                                 elseif ( isset( $this->default_headers[$_POST['default-header']] ) )
     230                                        set_theme_mod( 'header_image_width', $uploaded[$_POST['default-header']]['width'] );
     231                                        set_theme_mod( 'header_image_height', $uploaded[$_POST['default-header']]['height'] );
     232                                } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) {
    231233                                        set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) );
     234                                        $width = empty( $this->default_headers[$_POST['default-header']]['width'] )? HEADER_IMAGE_WIDTH : $this->default_headers[$_POST['default-header']]['width'];
     235                                        $height = empty( $this->default_headers[$_POST['default-header']]['height'] )? HEADER_IMAGE_HEIGHT : $this->default_headers[$_POST['default-header']]['height'];
     236                                        set_theme_mod( 'header_image_width', $width );
     237                                        set_theme_mod( 'header_image_height', $height );
     238                                }
    232239                        }
    233240                }
    234241        }
     
    438445                jQuery('img#upload').imgAreaSelect({
    439446                        handles: true,
    440447                        keys: true,
    441                         aspectRatio: xinit + ':' + yinit,
    442448                        show: true,
    443449                        x1: 0,
    444450                        y1: 0,
    445451                        x2: xinit,
    446452                        y2: yinit,
     453                        <?php
     454                        $header_support = get_theme_support( 'custom-header' );
     455                        if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
     456                        ?>
     457                        aspectRatio: xinit + ':' + yinit,
    447458                        maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
     459                        <?php
     460                        }
     461                        ?>
    448462                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
    449463                        onInit: function () {
    450464                                jQuery('#width').val(xinit);
     
    492506          call_user_func( $this->admin_image_div_callback );
    493507        } else {
    494508        ?>
    495         <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() ) ?>);">
     509        <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() ) ?>);">
    496510                <?php
    497511                if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
    498512                        $style = ' style="display:none;"';
     
    510524<th scope="row"><?php _e( 'Upload Image' ); ?></th>
    511525<td>
    512526        <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 />
    513         <?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>
     527        <?php
     528        $header_support = get_theme_support( 'custom-header' );
     529        if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
     530                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
     531        } else {
     532                printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH );
     533                if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) )
     534                        printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) );
     535        }
     536        ?></p>
    514537        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
    515538        <p>
    516539                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
     
    662685
    663686                list($width, $height, $type, $attr) = getimagesize( $file );
    664687
    665                 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
     688                $header_support = get_theme_support( 'custom-header' );
     689                // If flexible height isn't supported and the image is the exact right size
     690                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 ) {
    666691                        // Add the meta-data
    667692                        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    668693                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
     
    733758                $attachment_id = absint( $_POST['attachment_id'] );
    734759                $original = get_attached_file($attachment_id);
    735760
    736                 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
     761                $header_support = get_theme_support( 'custom-header' );
     762                if ( isset( $header_support[ 0 ] ) && !empty( $header_support[ 0 ][ 'flex-height' ] ) )
     763                        $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] );
     764                else
     765                        $dst_height = HEADER_IMAGE_HEIGHT;
     766
     767                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height );
    737768                if ( is_wp_error( $cropped ) )
    738769                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
    739770