Ticket #17242: 17242-height-width.2.diff
File 17242-height-width.2.diff, 14.7 KB (added by , 11 years ago) |
---|
-
wp-includes/theme.php
1457 1457 } 1458 1458 1459 1459 /** 1460 * Get random header image from registered images in theme.1460 * Get random header image data from registered images in theme. 1461 1461 * 1462 * @since 3. 2.01462 * @since 3.4.0 1463 1463 * 1464 1464 * @return string Path to header image 1465 1465 */ 1466 function get_random_header_image() { 1466 1467 function get_random_header_data() { 1468 static $_wp_random_header; 1467 1469 global $_wp_default_headers; 1468 1470 1469 $header_image_mod = get_theme_mod( 'header_image', '' ); 1470 $headers = array(); 1471 if ( empty( $_wp_random_header ) ) { 1472 $header_image_mod = get_theme_mod( 'header_image', '' ); 1473 $headers = array(); 1471 1474 1472 if ( 'random-uploaded-image' == $header_image_mod ) 1473 $headers = get_uploaded_header_images(); 1474 elseif ( ! empty( $_wp_default_headers ) ) { 1475 if ( 'random-default-image' == $header_image_mod ) { 1476 $headers = $_wp_default_headers; 1477 } else { 1478 $is_random = get_theme_support( 'custom-header' ); 1479 if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) ) 1475 if ( 'random-uploaded-image' == $header_image_mod ) 1476 $headers = get_uploaded_header_images(); 1477 elseif ( ! empty( $_wp_default_headers ) ) { 1478 if ( 'random-default-image' == $header_image_mod ) { 1480 1479 $headers = $_wp_default_headers; 1480 } else { 1481 $is_random = get_theme_support( 'custom-header' ); 1482 if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) ) 1483 $headers = $_wp_default_headers; 1484 } 1481 1485 } 1482 }1483 1486 1484 if ( empty( $headers ) )1485 return '';1487 if ( empty( $headers ) ) 1488 return stdClass(); 1486 1489 1487 $random_image = array_rand( $headers ); 1488 $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1490 $_wp_random_header = (object) $headers[ array_rand( $headers ) ]; 1489 1491 1490 return $header_url; 1492 $_wp_random_header->url = sprintf( $_wp_random_header->url, get_template_directory_uri(), get_stylesheet_directory_uri() ); 1493 $_wp_random_header->thumbnail_url = sprintf( $_wp_random_header->thumbnail_url, get_template_directory_uri(), get_stylesheet_directory_uri() ); 1494 } 1495 return $_wp_random_header; 1491 1496 } 1492 1497 1493 1498 /** 1499 * Get random header image url from registered images in theme. 1500 * 1501 * @since 3.2.0 1502 * 1503 * @return string Path to header image 1504 */ 1505 1506 function get_random_header_image() { 1507 $random_image = get_random_header_data(); 1508 if ( empty( $random_image->url ) ) 1509 return ''; 1510 return $random_image->url; 1511 } 1512 1513 /** 1494 1514 * Check if random header image is in use. 1495 1515 * 1496 1516 * Always true if user expressly chooses the option in Appearance > Header. … … 1547 1567 1548 1568 foreach ( (array) $headers as $header ) { 1549 1569 $url = esc_url_raw( $header->guid ); 1550 $header = basename($url); 1551 $header_images[$header] = array(); 1552 $header_images[$header]['url'] = $url; 1553 $header_images[$header]['thumbnail_url'] = $url; 1554 $header_images[$header]['uploaded'] = true; 1570 $header_data = wp_get_attachment_metadata( $header->ID ); 1571 $header_index = basename($url); 1572 $header_images[$header_index] = array(); 1573 $header_images[$header_index]['id'] = $header->ID; 1574 $header_images[$header_index]['url'] = $url; 1575 $header_images[$header_index]['thumbnail_url'] = $url; 1576 $header_images[$header_index]['uploaded'] = true; 1577 $header_images[$header_index]['width'] = $header_data['width']; 1578 $header_images[$header_index]['height'] = $header_data['height']; 1555 1579 } 1556 1580 1557 1581 return $header_images; 1558 1582 } 1559 1583 1560 1584 /** 1585 * Get the header image data. 1586 * 1587 * @since 3.4.0 1588 * 1589 * @return object 1590 */ 1591 function get_current_header_data() { 1592 return is_random_header_image()? get_random_header_data() : get_theme_mod( 'header_image_data', (object) array() ); 1593 } 1594 1595 /** 1596 * Get the header image width. 1597 * 1598 * @since 3.4.0 1599 * 1600 * @return int 1601 */ 1602 function get_header_image_width() { 1603 return empty( get_current_header_data()->width )? HEADER_IMAGE_WIDTH : get_current_header_data()->width; 1604 } 1605 1606 /** 1607 * Get the header image height. 1608 * 1609 * @since 3.4.0 1610 * 1611 * @return int 1612 */ 1613 function get_header_image_height() { 1614 return empty( get_current_header_data()->height )? HEADER_IMAGE_HEIGHT : get_current_header_data()->height; 1615 } 1616 1617 /** 1561 1618 * Add callbacks for image header display. 1562 1619 * 1563 1620 * The parameter $header_callback callback will be required to display the … … 1955 2012 $post_format = $args[0]; 1956 2013 return in_array( $post_format, $_wp_theme_features[$feature][0] ); 1957 2014 break; 2015 2016 case 'custom-header': 2017 // specific custom header capabilities can be registered by passing 2018 // an array to add_theme_support() 2019 $header_support = $args[0]; 2020 return in_array( $header_support, $_wp_theme_features[$feature][0] ); 2021 break; 1958 2022 } 1959 2023 1960 2024 return apply_filters('current_theme_supports-' . $feature, true, $args, $_wp_theme_features[$feature]); -
wp-admin/css/wp-admin.dev.css
4494 4494 4495 4495 .appearance_page_custom-header #headimg { 4496 4496 border: 1px solid #DFDFDF; 4497 min-height: 100px;4498 4497 width: 100%; 4499 4498 } 4500 4499 -
wp-admin/custom-header.php
188 188 189 189 if ( isset( $_POST['resetheader'] ) ) { 190 190 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 191 remove_theme_mod( 'header_image' ); 191 $this->process_default_headers(); 192 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 193 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 194 foreach ( $this->default_headers as $header => $details ) { 195 if ( $details['url'] == $default ) { 196 $default_data = $details; 197 break; 198 } 199 } 200 set_theme_mod( 'header_image', $default ); 201 if ( empty( $default_data['width'] ) ) 202 $default_data['width'] = HEADER_IMAGE_WIDTH; 203 if ( empty( $default_data['height'] ) ) 204 $default_data['height'] = HEADER_IMAGE_HEIGHT; 205 set_theme_mod( 'header_image_data', object( $default_data ) ); 192 206 return; 193 207 } 194 208 … … 225 239 } else { 226 240 $this->process_default_headers(); 227 241 $uploaded = get_uploaded_header_images(); 228 if ( isset( $uploaded[$_POST['default-header']] ) ) 242 if ( isset( $uploaded[$_POST['default-header']] ) ) { 229 243 set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) ); 230 elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) 244 set_theme_mod( 'header_image_data', (object) $uploaded[$_POST['default-header']] ); 245 } elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) { 231 246 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 247 if ( empty( $this->default_headers[$_POST['default-header']]['width'] ) ) 248 $this->default_headers[$_POST['default-header']]['width'] = HEADER_IMAGE_WIDTH; 249 if ( empty( $this->default_headers[$_POST['default-header']]['height'] ) ) 250 $this->default_headers[$_POST['default-header']]['height'] = HEADER_IMAGE_HEIGHT; 251 set_theme_mod( 'header_image_data', (object) $this->default_headers[$_POST['default-header']] ); 252 } 232 253 } 233 254 } 234 255 } … … 419 440 } 420 441 421 442 jQuery(document).ready(function() { 422 var xinit = <?php echo HEADER_IMAGE_WIDTH; ?>; 423 var yinit = <?php echo HEADER_IMAGE_HEIGHT; ?>; 443 <?php 444 $xinit = HEADER_IMAGE_WIDTH; 445 $yinit = HEADER_IMAGE_HEIGHT; 446 $header_support = get_theme_support( 'custom-header' ); 447 if ( !empty( $header_support[ 0 ][ 'suggested-width' ] ) ) 448 $xinit = $header_support[ 0 ][ 'suggested-width' ]; 449 if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 450 $yinit = $header_support[ 0 ][ 'suggested-height' ]; 451 ?> 452 var xinit = <?php echo absint( $xinit ); ?>; 453 var yinit = <?php echo absint( $yinit ); ?>; 424 454 var ratio = xinit / yinit; 425 455 var ximg = jQuery('img#upload').width(); 426 456 var yimg = jQuery('img#upload').height(); … … 438 468 jQuery('img#upload').imgAreaSelect({ 439 469 handles: true, 440 470 keys: true, 441 aspectRatio: xinit + ':' + yinit,442 471 show: true, 443 472 x1: 0, 444 473 y1: 0, 445 474 x2: xinit, 446 475 y2: yinit, 476 <?php 477 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 478 ?> 479 aspectRatio: xinit + ':' + yinit, 480 <?php 481 } 482 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { 483 ?> 447 484 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>, 485 <?php 486 } 487 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 488 ?> 448 489 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>, 490 <?php 491 } 492 ?> 449 493 onInit: function () { 450 494 jQuery('#width').val(xinit); 451 495 jQuery('#height').val(yinit); … … 492 536 call_user_func( $this->admin_image_div_callback ); 493 537 } else { 494 538 ?> 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() ) ?>);">539 <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_header_image_width(); ?>px;height:<?php echo get_header_image_height(); ?>px;"> 496 540 <?php 497 541 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 498 542 $style = ' style="display:none;"'; … … 510 554 <th scope="row"><?php _e( 'Upload Image' ); ?></th> 511 555 <td> 512 556 <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> 557 <?php 558 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 559 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); 560 } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { 561 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) 562 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . '<br />', HEADER_IMAGE_WIDTH ); 563 } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { 564 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) 565 printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . '<br />', HEADER_IMAGE_HEIGHT ); 566 } 567 if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) { 568 $header_support = get_theme_support( 'custom-header' ); 569 if ( !empty( $header_support[ 0 ][ 'suggested-width' ] ) ) 570 printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . '<br />', absint( $header_support[ 0 ][ 'suggested-width' ] ) ); 571 if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 572 printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . '<br />', absint( $header_support[ 0 ][ 'suggested-height' ] ) ); 573 } 574 ?></p> 514 575 <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>"> 515 576 <p> 516 577 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> … … 662 723 663 724 list($width, $height, $type, $attr) = getimagesize( $file ); 664 725 665 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 726 $header_support = get_theme_support( 'custom-header' ); 727 // If flexible height isn't supported and the image is the exact right size 728 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 666 729 // Add the meta-data 667 730 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 668 731 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); … … 670 733 set_theme_mod('header_image', esc_url($url)); 671 734 do_action('wp_create_file_in_uploads', $file, $id); // For replication 672 735 return $this->finished(); 673 } elseif ( $width > HEADER_IMAGE_WIDTH ) {736 } elseif ( ! current_theme_supports( 'custom-header', 'flex-width' ) && $width > HEADER_IMAGE_WIDTH ) { 674 737 $oitar = $width / HEADER_IMAGE_WIDTH; 675 738 $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); 676 739 if ( is_wp_error( $image ) ) … … 733 796 $attachment_id = absint( $_POST['attachment_id'] ); 734 797 $original = get_attached_file($attachment_id); 735 798 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 ); 799 if ( current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) 800 $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] ); 801 elseif ( current_theme_supports( 'custom-header', 'flex-height' ) && current_theme_supports( 'custom-header', 'flex-width' ) ) 802 $dst_height = (int) $_POST['height']; 803 else 804 $dst_height = HEADER_IMAGE_HEIGHT; 805 806 if ( current_theme_supports( 'custom-header', 'flex-width' ) && ! current_theme_supports( 'custom-header', 'flex-height' ) ) 807 $dst_width = (int) $_POST['width'] * ( HEADER_IMAGE_WIDTH / $_POST['height'] ); 808 if ( current_theme_supports( 'custom-header', 'flex-width' ) && current_theme_supports( 'custom-header', 'flex-height' ) ) 809 $dst_width = (int) $_POST['width']; 810 else 811 $dst_width = HEADER_IMAGE_HEIGHT; 812 813 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height ); 737 814 if ( is_wp_error( $cropped ) ) 738 815 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 739 816 … … 760 837 761 838 set_theme_mod('header_image', $url); 762 839 840 $header_data = new stdClass(); 841 $header_data->id = $attachment_id; 842 $header_data->url = $url; 843 $header_data->thumbnail_url = $url; 844 $header_data->uploaded = true; 845 $header_data->width = $dst_width; 846 $header_data->height = $dst_height; 847 848 set_theme_mod( 'header_image_data', $header_data ); 849 763 850 // cleanup 764 851 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); 765 852 @unlink( apply_filters( 'wp_delete_file', $medium ) );