Ticket #17242: 17242.8.diff
File 17242.8.diff, 10.2 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() {1467 global $_wp_default_headers;1468 1466 1467 function get_random_header_data() { 1468 global $_wp_default_headers, $_wp_random_header; 1469 1469 1470 $header_image_mod = get_theme_mod( 'header_image', '' ); 1470 1471 $headers = array(); 1471 1472 … … 1484 1485 if ( empty( $headers ) ) 1485 1486 return ''; 1486 1487 1487 $random_image = array_rand( $headers ); 1488 $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1488 $_wp_random_header = $headers[ array_rand( $headers ) ]; 1489 1489 1490 return $header_url; 1490 $_wp_random_header['url'] = sprintf( $_wp_random_header['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1491 $_wp_random_header['thumbnail_url'] = sprintf( $_wp_random_header['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1492 1493 return $_wp_random_header; 1491 1494 } 1492 1495 1493 1496 /** 1497 * Get random header image url from registered images in theme. 1498 * 1499 * @since 3.2.0 1500 * 1501 * @return string Path to header image 1502 */ 1503 1504 function get_random_header_image() { 1505 $random_image = get_random_header_data(); 1506 return $random_image['url']; 1507 } 1508 1509 /** 1494 1510 * Check if random header image is in use. 1495 1511 * 1496 1512 * Always true if user expressly chooses the option in Appearance > Header. … … 1547 1563 1548 1564 foreach ( (array) $headers as $header ) { 1549 1565 $url = esc_url_raw( $header->guid ); 1566 $header_data = wp_get_attachment_metadata( $header->ID ); 1550 1567 $header = basename($url); 1551 1568 $header_images[$header] = array(); 1552 1569 $header_images[$header]['url'] = $url; 1553 1570 $header_images[$header]['thumbnail_url'] = $url; 1554 1571 $header_images[$header]['uploaded'] = true; 1572 $header_images[$header]['width'] = $header_data['width']; 1573 $header_images[$header]['height'] = $header_data['height']; 1555 1574 } 1556 1575 1557 1576 return $header_images; 1558 1577 } 1559 1578 1560 1579 /** 1580 * Get the header image width. 1581 * 1582 * @since 3.4.0 1583 * 1584 * @return int 1585 */ 1586 function get_header_image_width() { 1587 if ( is_random_header_image() ) { 1588 global $_wp_random_header; 1589 return empty( $_wp_random_header['width'] )? HEADER_IMAGE_WIDTH : $_wp_random_header['width']; 1590 } 1591 1592 return get_theme_mod( 'header_image_width', HEADER_IMAGE_WIDTH ); 1593 } 1594 1595 /** 1596 * Get the header image height. 1597 * 1598 * @since 3.4.0 1599 * 1600 * @return int 1601 */ 1602 function get_header_image_height() { 1603 if ( is_random_header_image() ) { 1604 global $_wp_random_header; 1605 return empty( $_wp_random_header['height'] )? HEADER_IMAGE_HEIGHT : $_wp_random_header['height']; 1606 } 1607 1608 return get_theme_mod( 'header_image_height', HEADER_IMAGE_HEIGHT ); 1609 } 1610 1611 /** 1561 1612 * Add callbacks for image header display. 1562 1613 * 1563 1614 * The parameter $header_callback callback will be required to display the -
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 $width = empty( $default_data['width'] )? HEADER_IMAGE_WIDTH : $default_data['width']; 202 $height = empty( $default_data['height'] )? HEADER_IMAGE_HEIGHT : $default_data['height']; 203 set_theme_mod( 'header_image_width', $width ); 204 set_theme_mod( 'header_image_height', $height ); 192 205 return; 193 206 } 194 207 … … 225 238 } else { 226 239 $this->process_default_headers(); 227 240 $uploaded = get_uploaded_header_images(); 228 if ( isset( $uploaded[$_POST['default-header']] ) ) 241 if ( isset( $uploaded[$_POST['default-header']] ) ) { 229 242 set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) ); 230 elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) 243 set_theme_mod( 'header_image_width', $uploaded[$_POST['default-header']]['width'] ); 244 set_theme_mod( 'header_image_height', $uploaded[$_POST['default-header']]['height'] ); 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 $width = empty( $this->default_headers[$_POST['default-header']]['width'] )? HEADER_IMAGE_WIDTH : $this->default_headers[$_POST['default-header']]['width']; 248 $height = empty( $this->default_headers[$_POST['default-header']]['height'] )? HEADER_IMAGE_HEIGHT : $this->default_headers[$_POST['default-header']]['height']; 249 set_theme_mod( 'header_image_width', $width ); 250 set_theme_mod( 'header_image_height', $height ); 251 } 232 252 } 233 253 } 234 254 } … … 438 458 jQuery('img#upload').imgAreaSelect({ 439 459 handles: true, 440 460 keys: true, 441 aspectRatio: xinit + ':' + yinit,442 461 show: true, 443 462 x1: 0, 444 463 y1: 0, 445 464 x2: xinit, 446 465 y2: yinit, 466 <?php 467 $header_support = get_theme_support( 'custom-header' ); 468 if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) { 469 ?> 470 aspectRatio: xinit + ':' + yinit, 447 471 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>, 472 <?php 473 } 474 ?> 448 475 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>, 449 476 onInit: function () { 450 477 jQuery('#width').val(xinit); … … 492 519 call_user_func( $this->admin_image_div_callback ); 493 520 } else { 494 521 ?> 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() ) ?>);">522 <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 523 <?php 497 524 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 498 525 $style = ' style="display:none;"'; … … 510 537 <th scope="row"><?php _e( 'Upload Image' ); ?></th> 511 538 <td> 512 539 <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> 540 <?php 541 $header_support = get_theme_support( 'custom-header' ); 542 if ( ! isset( $header_support[ 0 ] ) || empty( $header_support[ 0 ][ 'flex-height' ] ) || !$header_support[ 0 ][ 'flex-height' ] ) { 543 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); 544 } else { 545 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ), HEADER_IMAGE_WIDTH ); 546 if ( !empty( $header_support[ 0 ][ 'suggested-height' ] ) ) 547 printf( __( ' Suggested height is <strong>%1$d pixels</strong>.' ), absint( $header_support[ 0 ][ 'suggested-height' ] ) ); 548 } 549 ?></p> 514 550 <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>"> 515 551 <p> 516 552 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> … … 662 698 663 699 list($width, $height, $type, $attr) = getimagesize( $file ); 664 700 665 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 701 $header_support = get_theme_support( 'custom-header' ); 702 // If flexible height isn't supported and the image is the exact right size 703 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 704 // Add the meta-data 667 705 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 668 706 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); … … 733 771 $attachment_id = absint( $_POST['attachment_id'] ); 734 772 $original = get_attached_file($attachment_id); 735 773 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 ); 774 $header_support = get_theme_support( 'custom-header' ); 775 if ( isset( $header_support[ 0 ] ) && !empty( $header_support[ 0 ][ 'flex-height' ] ) ) 776 $dst_height = (int) $_POST['height'] * ( HEADER_IMAGE_WIDTH / $_POST['width'] ); 777 else 778 $dst_height = HEADER_IMAGE_HEIGHT; 779 780 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, $dst_height ); 737 781 if ( is_wp_error( $cropped ) ) 738 782 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 739 783 … … 759 803 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 760 804 761 805 set_theme_mod('header_image', $url); 806 set_theme_mod( 'header_image_width', (int) $_POST['width'] ); 807 set_theme_mod( 'header_image_height', $dst_height ); 762 808 763 809 // cleanup 764 810 $medium = str_replace(basename($original), 'midsize-'.basename($original), $original); -
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