Changes from branches/3.1/wp-admin/custom-header.php at r18023 to trunk/wp-admin/custom-header.php at r18298
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-header.php
r18023 r18298 43 43 var $default_headers = array(); 44 44 45 46 /** 47 * Holds custom headers uploaded by the user 48 * 49 * @var array 50 * @since 3.2.0 51 * @access private 52 */ 53 var $uploaded_headers = array(); 54 45 55 /** 46 56 * Holds the page menu hook. … … 53 63 54 64 /** 55 * PHP4Constructor - Register administration header callback.65 * Constructor - Register administration header callback. 56 66 * 57 67 * @since 2.1.0 … … 60 70 * @return Custom_Image_Header 61 71 */ 62 function Custom_Image_Header($admin_header_callback, $admin_image_div_callback = '') {72 function __construct($admin_header_callback, $admin_image_div_callback = '') { 63 73 $this->admin_header_callback = $admin_header_callback; 64 74 $this->admin_image_div_callback = $admin_image_div_callback; … … 94 104 '<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you’d like and click the Save Changes button.' ) . '</p>' . 95 105 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 96 '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_S ubPanel" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .106 '<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' . 97 107 '<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>' ); 98 108 } … … 184 194 if ( isset( $_POST['removeheader'] ) ) { 185 195 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 186 set_theme_mod( 'header_image', ' ' );196 set_theme_mod( 'header_image', 'remove-header' ); 187 197 return; 188 198 } … … 200 210 } 201 211 202 if ( isset( $_POST['default-header']) ) {212 if ( isset( $_POST['default-header'] ) ) { 203 213 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 204 $this->process_default_headers(); 205 if ( isset($this->default_headers[$_POST['default-header']]) ) 206 set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url'])); 214 if ( 'random-default-image' == $_POST['default-header'] ) { 215 set_theme_mod( 'header_image', 'random-default-image' ); 216 } elseif ( 'random-uploaded-image' == $_POST['default-header'] ) { 217 set_theme_mod( 'header_image', 'random-uploaded-image' ); 218 } else { 219 $this->process_default_headers(); 220 $uploaded = get_uploaded_header_images(); 221 if ( isset( $uploaded[$_POST['default-header']] ) ) 222 set_theme_mod( 'header_image', esc_url( $uploaded[$_POST['default-header']]['url'] ) ); 223 elseif ( isset( $this->default_headers[$_POST['default-header']] ) ) 224 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 225 } 207 226 } 208 227 } … … 227 246 $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 228 247 } 248 229 249 } 230 250 … … 232 252 * Display UI for selecting one of several default headers. 233 253 * 254 * Show the random image option if this theme has multiple header images. 255 * Random image option is on by default if no header has been set. 256 * 234 257 * @since 3.0.0 235 258 */ 236 function show_default_header_selector() { 237 echo '<div id="available-headers">'; 238 foreach ( $this->default_headers as $header_key => $header ) { 259 function show_header_selector( $type = 'default' ) { 260 if ( 'default' == $type ) { 261 $headers = $this->default_headers; 262 } else { 263 $headers = get_uploaded_header_images(); 264 $type = 'uploaded'; 265 } 266 267 if ( 1 < count( $headers ) ) { 268 echo '<div class="random-header">'; 269 echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />'; 270 echo __( '<strong>Random:</strong> Show a different image on each page.' ); 271 echo '</label>'; 272 echo '</div>'; 273 } 274 275 echo '<div class="available-headers">'; 276 foreach ( $headers as $header_key => $header ) { 239 277 $header_thumbnail = $header['thumbnail_url']; 240 278 $header_url = $header['url']; 241 $header_desc = $header['description'];279 $header_desc = empty( $header['description'] ) ? '' : $header['description']; 242 280 echo '<div class="default-header">'; 243 echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' />'; 244 echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /></label>'; 281 echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />'; 282 $width = ''; 283 if ( !empty( $header['uploaded'] ) ) 284 $width = ' width="230"'; 285 echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>'; 245 286 echo '</div>'; 246 287 } … … 348 389 toggle_text(); 349 390 <?php } ?> 350 }); 391 }); 392 /* ]]> */ 351 393 </script> 352 394 <?php … … 432 474 <?php } ?> 433 475 434 <h3><?php _e( 'Header Image' ) ?></h3>435 476 <table class="form-table"> 436 477 <tbody> … … 481 522 <table class="form-table"> 482 523 <tbody> 483 <?php if ( ! empty( $this->default_headers ) ) : ?> 524 <?php if ( get_uploaded_header_images() ) : ?> 525 <tr valign="top"> 526 <th scope="row"><?php _e( 'Uploaded Images' ); ?></th> 527 <td> 528 <p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ) ?></p> 529 <?php 530 $this->show_header_selector( 'uploaded' ); 531 ?> 532 </td> 533 </tr> 534 <?php endif; 535 if ( ! empty( $this->default_headers ) ) : ?> 484 536 <tr valign="top"> 485 537 <th scope="row"><?php _e( 'Default Images' ); ?></th> 486 538 <td> 487 539 <?php if ( current_theme_supports( 'custom-header-uploads' ) ) : ?> 488 <p><?php _e( 'If you don‘t want to upload your own image, you can use one of these cool headers .' ) ?></p>540 <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> 489 541 <?php else: ?> 490 <p><?php _e( 'You can use one of these cool headers .' ) ?>542 <p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ) ?></p> 491 543 <?php endif; ?> 492 544 <?php 493 $this->show_ default_header_selector();545 $this->show_header_selector( 'default' ); 494 546 ?> 495 547 </td> 496 548 </tr> 497 549 <?php endif; 498 499 550 if ( get_header_image() ) : ?> 500 551 <tr valign="top"> … … 507 558 <?php endif; 508 559 509 if ( defined( 'HEADER_IMAGE' ) ) : ?>560 if ( defined( 'HEADER_IMAGE' ) && '' != HEADER_IMAGE ) : ?> 510 561 <tr valign="top"> 511 562 <th scope="row"><?php _e( 'Reset Image' ); ?></th> … … 520 571 521 572 <?php if ( $this->header_text() ) : ?> 522 <h3><?php _e( 'Header Text' ) ?></h3>523 573 <table class="form-table"> 524 574 <tbody> … … 607 657 // Add the meta-data 608 658 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 659 update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 609 660 610 661 set_theme_mod('header_image', esc_url($url)); … … 671 722 } 672 723 673 $original = get_attached_file( $_POST['attachment_id'] ); 674 675 $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); 724 $attachment_id = absint( $_POST['attachment_id'] ); 725 $original = get_attached_file($attachment_id); 726 727 $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); 676 728 if ( is_wp_error( $cropped ) ) 677 729 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 678 730 679 $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $ _POST['attachment_id']); // For replication680 681 $parent = get_post($ _POST['attachment_id']);731 $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication 732 733 $parent = get_post($attachment_id); 682 734 $parent_url = $parent->guid; 683 735 $url = str_replace(basename($parent_url), basename($cropped), $parent_url); … … 685 737 // Construct the object array 686 738 $object = array( 687 'ID' => $ _POST['attachment_id'],739 'ID' => $attachment_id, 688 740 'post_title' => basename($cropped), 689 741 'post_content' => $url, … … 695 747 // Update the attachment 696 748 wp_insert_attachment($object, $cropped); 697 wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); 749 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) ); 750 update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 698 751 699 752 set_theme_mod('header_image', $url);
Note: See TracChangeset
for help on using the changeset viewer.