Ticket #17242: 17242.4.diff
File 17242.4.diff, 5.2 KB (added by , 11 years ago) |
---|
-
wp-admin/custom-header.php
173 173 } 174 174 175 175 /** 176 * Get the header height if using a flexible header (should this be in theme.php?) 177 * @since 3.4 178 */ 179 function flex_header_height() { 180 $header_support = get_theme_support( 'custom-header' ); 181 182 if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) { 183 return HEADER_IMAGE_HEIGHT; 184 } else { 185 $header_image = get_header_image(); 186 $header_image_post = get_page_by_title( substr( $header_image, strrpos( $header_image, '/') + 1 ), null, 'attachment' ); 187 $header_image_info = wp_get_attachment_metadata( $header_image_post->ID ); 188 return $header_image_info['height']; 189 } 190 } 191 /** 176 192 * Execute custom header modification. 177 193 * 178 194 * @since 2.6.0 … … 438 454 jQuery('img#upload').imgAreaSelect({ 439 455 handles: true, 440 456 keys: true, 441 aspectRatio: xinit + ':' + yinit,442 457 show: true, 443 458 x1: 0, 444 459 y1: 0, 445 460 x2: xinit, 446 461 y2: yinit, 462 <?php 463 $header_support = get_theme_support( 'custom-header' ); 464 if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) { 465 ?> 466 aspectRatio: xinit + ':' + yinit, 447 467 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>, 468 <?php 469 } 470 ?> 448 471 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>, 449 472 onInit: function () { 450 473 jQuery('#width').val(xinit); … … 490 513 <td > 491 514 <?php if ( $this->admin_image_div_callback ) { 492 515 call_user_func( $this->admin_image_div_callback ); 493 } else { 516 } else { 494 517 ?> 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() ) ?>);"> 518 <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php 519 echo $this->flex_header_height(); ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);"> 496 520 <?php 497 521 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 498 522 $style = ' style="display:none;"'; … … 510 534 <th scope="row"><?php _e( 'Upload Image' ); ?></th> 511 535 <td> 512 536 <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 × %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p> 537 <?php 538 $header_support = get_theme_support( 'custom-header' ); 539 if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || ! $header_support[ 0 ][ 'flex-height' ] ) { 540 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); 541 } else { 542 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH ); 543 if ( ! empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 544 printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) ); 545 } 546 ?></p> 514 547 <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>"> 515 548 <p> 516 549 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> … … 662 695 663 696 list($width, $height, $type, $attr) = getimagesize( $file ); 664 697 665 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 698 $header_support = get_theme_support( 'custom-header' ); 699 // If flexible height isn't supported and the image is the exact right size 700 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 ) { 666 701 // Add the meta-data 667 702 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 668 703 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); … … 733 768 $attachment_id = absint( $_POST['attachment_id'] ); 734 769 $original = get_attached_file($attachment_id); 735 770 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 ); 771 $header_support = get_theme_support( 'custom-header' ); 772 if ( isset( $header_support[ 0 ] ) && ! empty( $header_support[ 0 ][ 'flex-height' ] ) ) 773 $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] ); 774 else 775 $dst_height = HEADER_IMAGE_HEIGHT; 776 777 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height ); 737 778 if ( is_wp_error( $cropped ) ) 738 779 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 739 780