WordPress.org

Make WordPress Core

Ticket #17242: 17242.3.diff

File 17242.3.diff, 4.3 KB (added by aaroncampbell, 6 years ago)
  • wp-admin/custom-header.php

     
    438438                jQuery('img#upload').imgAreaSelect({
    439439                        handles: true,
    440440                        keys: true,
    441                         aspectRatio: xinit + ':' + yinit,
    442441                        show: true,
    443442                        x1: 0,
    444443                        y1: 0,
    445444                        x2: xinit,
    446445                        y2: yinit,
     446                        <?php
     447                        $header_support = get_theme_support( 'custom-header' );
     448                        if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
     449                        ?>
     450                        aspectRatio: xinit + ':' + yinit,
    447451                        maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
     452                        <?php
     453                        }
     454                        ?>
    448455                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
    449456                        onInit: function () {
    450457                                jQuery('#width').val(xinit);
     
    492499          call_user_func( $this->admin_image_div_callback );
    493500        } else {
    494501        ?>
    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() ) ?>);">
     502        <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;">
     503                <img src="<?php header_image(); ?>" />
    496504                <?php
    497505                if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
    498506                        $style = ' style="display:none;"';
     
    510518<th scope="row"><?php _e( 'Upload Image' ); ?></th>
    511519<td>
    512520        <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>
     521        <?php
     522        $header_support = get_theme_support( 'custom-header' );
     523        if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) {
     524                printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT );
     525        } else {
     526                printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH );
     527                if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) )
     528                        printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) );
     529        }
     530        ?></p>
    514531        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
    515532        <p>
    516533                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
     
    662679
    663680                list($width, $height, $type, $attr) = getimagesize( $file );
    664681
    665                 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) {
     682                $header_support = get_theme_support( 'custom-header' );
     683                // If flexible height isn't supported and the image is the exact right size
     684                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 ) {
    666685                        // Add the meta-data
    667686                        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    668687                        update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) );
     
    733752                $attachment_id = absint( $_POST['attachment_id'] );
    734753                $original = get_attached_file($attachment_id);
    735754
    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 );
     755                $header_support = get_theme_support( 'custom-header' );
     756                if ( isset( $header_support[ 0 ] ) && !empty( $header_support[ 0 ][ 'flex-height' ] ) )
     757                        $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] );
     758                else
     759                        $dst_height = HEADER_IMAGE_HEIGHT;
     760
     761                $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height );
    737762                if ( is_wp_error( $cropped ) )
    738763                        wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
    739764