Changeset 20212 for trunk/wp-admin/custom-header.php
- Timestamp:
- 03/19/2012 05:12:44 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/wp-admin/custom-header.php (modified) (29 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-header.php
r20211 r20212 72 72 $this->admin_header_callback = $admin_header_callback; 73 73 $this->admin_image_div_callback = $admin_image_div_callback; 74 75 add_action( 'admin_menu', array( $this, 'init' ) ); 74 76 } 75 77 … … 141 143 $step = $this->step(); 142 144 143 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )145 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 144 146 wp_enqueue_script('farbtastic'); 145 147 elseif ( 2 == $step ) … … 155 157 $step = $this->step(); 156 158 157 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )159 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 158 160 wp_enqueue_style('farbtastic'); 159 161 elseif ( 2 == $step ) … … 162 164 163 165 /** 164 * Check if header text is allowed165 *166 * @since 3.0.0167 */168 function header_text() {169 if ( defined( 'NO_HEADER_TEXT' ) && NO_HEADER_TEXT )170 return false;171 172 return true;173 }174 175 /**176 166 * Execute custom header modification. 177 167 * … … 190 180 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 191 181 $this->process_default_headers(); 192 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';182 $default = get_theme_support( 'custom-header', 'default-image' ); 193 183 $default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() ); 194 184 foreach ( $this->default_headers as $header => $details ) { … … 200 190 set_theme_mod( 'header_image', $default ); 201 191 if ( empty( $default_data['width'] ) ) 202 $default_data['width'] = HEADER_IMAGE_WIDTH;192 $default_data['width'] = get_theme_support( 'custom-header', 'width' ); 203 193 if ( empty( $default_data['height'] ) ) 204 $default_data['height'] = HEADER_IMAGE_HEIGHT;194 $default_data['height'] = get_theme_support( 'custom-header', 'height' ); 205 195 set_theme_mod( 'header_image_data', (object) $default_data ); 206 196 return; … … 246 236 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 247 237 if ( empty( $this->default_headers[$_POST['default-header']]['width'] ) ) 248 $this->default_headers[$_POST['default-header']]['width'] = HEADER_IMAGE_WIDTH;238 $this->default_headers[$_POST['default-header']]['width'] = get_theme_support( 'custom-header', 'width' ); 249 239 if ( empty( $this->default_headers[$_POST['default-header']]['height'] ) ) 250 $this->default_headers[$_POST['default-header']]['height'] = HEADER_IMAGE_HEIGHT;240 $this->default_headers[$_POST['default-header']]['height'] = get_theme_support( 'custom-header', 'height' ); 251 241 set_theme_mod( 'header_image_data', (object) $this->default_headers[$_POST['default-header']] ); 252 242 } … … 326 316 function js() { 327 317 $step = $this->step(); 328 if ( ( 1 == $step || 3 == $step ) && $this->header_text() )318 if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) ) 329 319 $this->js_1(); 330 320 elseif ( 2 == $step ) … … 342 332 var text_objects = ['#name', '#desc', '#text-color-row']; 343 333 var farbtastic; 344 var default_color = '#<?php echo HEADER_TEXTCOLOR; ?>';334 var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>'; 345 335 var old_color = null; 346 336 … … 412 402 413 403 farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); }); 414 <?php if ( $color = get_ theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?>404 <?php if ( $color = get_header_textcolor() ) { ?> 415 405 pickColor('#<?php echo $color; ?>'); 416 406 <?php } ?> 417 407 418 <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) { ?>408 <?php if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) ) { ?> 419 409 toggle_text(); 420 410 <?php } ?> … … 441 431 442 432 jQuery(document).ready(function() { 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 ); ?>; 433 var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>; 434 var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>; 454 435 var ratio = xinit / yinit; 455 436 var ximg = jQuery('img#upload').width(); … … 482 463 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) { 483 464 ?> 484 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,465 maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>, 485 466 <?php 486 467 } 487 468 if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) { 488 469 ?> 489 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,470 maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>, 490 471 <?php 491 472 } … … 532 513 <tr valign="top"> 533 514 <th scope="row"><?php _e( 'Preview' ); ?></th> 534 <td >515 <td> 535 516 <?php if ( $this->admin_image_div_callback ) { 536 517 call_user_func( $this->admin_image_div_callback ); 537 518 } else { 538 519 ?> 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;">520 <div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;"> 540 521 <?php 541 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 522 $color = get_header_textcolor(); 523 if ( 'blank' == $color || '' == $color || ! current_theme_supports( 'custom-header', 'header-text' ) ) 542 524 $style = ' style="display:none;"'; 543 525 else 544 $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ). ';"';526 $style = ' style="color:#' . $color . ';"'; 545 527 ?> 546 528 <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1> … … 550 532 </td> 551 533 </tr> 552 <?php if ( current_theme_supports( 'custom-header -uploads' ) ) : ?>534 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?> 553 535 <tr valign="top"> 554 536 <th scope="row"><?php _e( 'Upload Image' ); ?></th> … … 557 539 <?php 558 540 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);541 printf( __( 'Images of exactly <strong>%1$d × %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) ); 560 542 } elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) { 561 543 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);544 printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . ' ', get_theme_support( 'custom-header', 'width' ) ); 563 545 } elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) { 564 546 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);547 printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . ' ', get_theme_support( 'custom-header', 'height' ) ); 566 548 } 567 549 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' ] ) ); 550 if ( current_theme_supports( 'custom-header', 'width' ) ) 551 printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'width' ) ); 552 if ( current_theme_supports( 'custom-header', 'height' ) ) 553 printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) ); 573 554 } 574 555 ?></p> … … 606 587 <th scope="row"><?php _e( 'Default Images' ); ?></th> 607 588 <td> 608 <?php if ( current_theme_supports( 'custom-header -uploads' ) ) : ?>589 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?> 609 590 <p><?php _e( 'If you don‘t want to upload your own image, you can use one of these cool headers, or show a random one.' ) ?></p> 610 591 <?php else: ?> … … 627 608 <?php endif; 628 609 629 if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE) : ?>610 if ( current_theme_supports( 'custom-header', 'default-image' ) ) : ?> 630 611 <tr valign="top"> 631 612 <th scope="row"><?php _e( 'Reset Image' ); ?></th> … … 638 619 </tbody> 639 620 </table> 640 <?php if ( $this->header_text() ) : ?>621 <?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?> 641 622 <table class="form-table"> 642 623 <tbody> … … 645 626 <td> 646 627 <p> 647 <?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?> 648 <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? true : false ); ?> /> <?php _e( 'No' ); ?></label> 649 <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label> 628 <?php 629 $show_text = get_header_textcolor(); 630 if ( 'blank' == $show_text ) 631 $show_text = false; 632 else 633 $show_text = (bool) $show_text; 634 ?> 635 <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ! $show_text ); ?> /> <?php _e( 'No' ); ?></label> 636 <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( $show_text ); ?> /> <?php _e( 'Yes' ); ?></label> 650 637 </p> 651 638 </td> … … 656 643 <td> 657 644 <p> 658 <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_ theme_mod( 'header_textcolor', HEADER_TEXTCOLOR) ); ?>" />645 <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" /> 659 646 <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span> 660 647 <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" /> … … 664 651 </tr> 665 652 666 <?php if ( defined('HEADER_TEXTCOLOR') && get_theme_mod('header_textcolor') ) { ?>653 <?php if ( current_theme_supports( 'custom-header', 'default-text-color' ) && get_theme_mod( 'header_textcolor' ) ) { ?> 667 654 <tr valign="top"> 668 655 <th scope="row"><?php _e('Reset Text Color'); ?></th> … … 695 682 function step_2() { 696 683 check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload'); 697 if ( ! current_theme_supports( 'custom-header -uploads' ) )684 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 698 685 wp_die( __( 'Cheatin’ uh?' ) ); 699 686 … … 723 710 list($width, $height, $type, $attr) = getimagesize( $file ); 724 711 725 $header_support = get_theme_support( 'custom-header' );726 712 $max_width = 0; 727 713 // For flex, limit size of image displayed to 1500px unless theme says otherwise … … 729 715 $max_width = 1500; 730 716 731 if ( !empty( $header_support[ 0 ][ 'max-width' ] ) ) 732 $max_width = max( $max_width, absint( $header_support[ 0 ][ 'max-width' ] ) ); 733 734 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 735 $max_width = max( $max_width, HEADER_IMAGE_WIDTH ); 717 if ( current_theme_supports( 'custom-header', 'max-width' ) ) 718 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); 719 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); 720 736 721 // If flexible height isn't supported and the image is the exact right size 737 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) && $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 722 if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) 723 && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) 724 { 738 725 // Add the meta-data 739 726 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); … … 792 779 */ 793 780 function step_3() { 794 check_admin_referer('custom-header-crop-image'); 795 if ( ! current_theme_supports( 'custom-header-uploads' ) ) 781 check_admin_referer( 'custom-header-crop-image' ); 782 783 if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) 796 784 wp_die( __( 'Cheatin’ uh?' ) ); 797 785 … … 806 794 $original = get_attached_file($attachment_id); 807 795 808 $header_support = get_theme_support( 'custom-header' ); 796 809 797 $max_width = 0; 810 798 // For flex, limit size of image displayed to 1500px unless theme says otherwise … … 812 800 $max_width = 1500; 813 801 814 if ( !empty( $header_support[ 0 ][ 'max-width' ] ) ) 815 $max_width = max( $max_width, absint( $header_support[ 0 ][ 'max-width' ] ) ); 816 817 if ( defined( 'HEADER_IMAGE_WIDTH' ) ) 818 $max_width = max( $max_width, HEADER_IMAGE_WIDTH ); 802 if ( current_theme_supports( 'custom-header', 'max-width' ) ) 803 $max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) ); 804 $max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) ); 819 805 820 806 if ( ( current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) || $_POST['width'] > $max_width ) … … 823 809 $dst_height = absint( $_POST['height'] ); 824 810 else 825 $dst_height = HEADER_IMAGE_HEIGHT;811 $dst_height = get_theme_support( 'custom-header', 'height' ); 826 812 827 813 if ( ( current_theme_supports( 'custom-header', 'flex-width' ) && ! current_theme_supports( 'custom-header', 'flex-height' ) ) || $_POST['width'] > $max_width ) … … 830 816 $dst_width = absint( $_POST['width'] ); 831 817 else 832 $dst_width = HEADER_IMAGE_WIDTH;818 $dst_width = get_theme_support( 'custom-header', 'width' ); 833 819 834 820 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
Note: See TracChangeset
for help on using the changeset viewer.