Ticket #17240: 17240.diff
File 17240.diff, 6.9 KB (added by , 14 years ago) |
---|
-
wp-includes/theme.php
1427 1427 */ 1428 1428 function get_header_image() { 1429 1429 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1430 1431 1430 $url = get_theme_mod( 'header_image', $default ); 1432 1431 1432 if ( is_random_header_image() ) { 1433 $url = get_random_header_image(); 1434 } 1435 1433 1436 if ( is_ssl() ) 1434 1437 $url = str_replace( 'http://', 'https://', $url ); 1435 1438 else … … 1439 1442 } 1440 1443 1441 1444 /** 1445 * Get random header image from registered images in theme. 1446 * 1447 * @since 3.2 1448 * 1449 * @return string Path to header image 1450 */ 1451 function get_random_header_image() { 1452 global $_wp_default_headers; 1453 $header_url = ''; 1454 1455 $uploaded_headers = get_uploaded_header_images(); 1456 1457 if ( empty( $_wp_default_headers ) && empty( $uploaded_headers ) ) 1458 return $header_url; 1459 1460 $headers = array_merge( $_wp_default_headers, $uploaded_headers); 1461 1462 $random_image = array_rand( $headers ); 1463 $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1464 1465 return $header_url; 1466 } 1467 1468 /** 1469 * Check if random header image is in use. 1470 * 1471 * Always true if user expressly chooses the option in Appearance > Header. 1472 * Also true if theme has multiple header images registered and no specific header image is chosen. 1473 * 1474 * @since 3.2 1475 * @uses HEADER_IMAGE 1476 * 1477 * @return boolean 1478 */ 1479 function is_random_header_image() { 1480 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1481 $header_image_mod = get_theme_mod( 'header_image', $default ); 1482 1483 if ( 'random-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) 1484 return true; 1485 1486 return false; 1487 } 1488 1489 /** 1442 1490 * Display header image path. 1443 1491 * 1444 1492 * @since 2.1.0 … … 1448 1496 } 1449 1497 1450 1498 /** 1499 * Get the header images uploaded for the current theme. 1500 * 1501 * @since 3.2.0 1502 * 1503 * @return array 1504 */ 1505 function get_uploaded_header_images() { 1506 $header_images = array(); 1507 1508 // @todo caching 1509 $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); 1510 1511 if ( empty( $headers ) ) 1512 return array(); 1513 1514 foreach ( (array) $headers as $header ) { 1515 $url = $header->guid; 1516 $header = basename($url); 1517 $header_images[$header] = array(); 1518 $header_images[$header]['url'] = $url; 1519 $header_images[$header]['thumbnail_url'] = $url; 1520 $header_images[$header]['uploaded'] = true; 1521 } 1522 1523 return $header_images; 1524 } 1525 1526 /** 1451 1527 * Add callbacks for image header display. 1452 1528 * 1453 1529 * The parameter $header_callback callback will be required to display the -
wp-admin/custom-header.php
42 42 */ 43 43 var $default_headers = array(); 44 44 45 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 55 /** 46 56 * Holds the page menu hook. 47 57 * 48 58 * @var string … … 199 209 } 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 214 $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'])); 215 if ( 'random-image' == $_POST['default-header'] ) 216 set_theme_mod( 'header_image', 'random-image' ); 217 if ( isset( $this->default_headers[$_POST['default-header']] ) ) 218 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 207 219 } 208 220 } 209 221 … … 226 238 $this->default_headers[$header]['url'] = sprintf( $this->default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 227 239 $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 228 240 } 241 242 $this->default_headers = array_merge( get_uploaded_header_images(), $this->default_headers ); 229 243 } 230 244 231 245 /** 232 246 * Display UI for selecting one of several default headers. 233 247 * 248 * Show the random image option if this theme has multiple header images. 249 * Random image option is on by default if no header has been set. 250 * 234 251 * @since 3.0.0 235 252 */ 236 253 function show_default_header_selector() { … … 238 255 foreach ( $this->default_headers as $header_key => $header ) { 239 256 $header_thumbnail = $header['thumbnail_url']; 240 257 $header_url = $header['url']; 241 $header_desc = $header['description'];258 $header_desc = empty( $header['description'] ) ? '' : $header['description']; 242 259 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>'; 260 echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />'; 261 $width = ''; 262 if ( !empty( $header['uploaded'] ) ) 263 $width = ' width="230"'; 264 echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>'; 245 265 echo '</div>'; 246 266 } 267 if ( 0 < count( $this->default_headers ) ) { 268 echo '<div class="default-header">'; 269 echo '<label><input name="default-header" type="radio" value="random-image"' . checked( is_random_header_image(), true, false ) . ' />'; 270 echo __( '<strong>Random:</strong> Show a different image on each page.' ); 271 echo '</label>'; 272 echo '</div>'; 273 } 247 274 echo '<div class="clear"></div></div>'; 248 275 } 249 276 … … 496 523 </tr> 497 524 <?php endif; 498 525 499 if ( get_header_image() ) : ?>526 if ( get_header_image() && !is_random_header_image() ) : ?> 500 527 <tr valign="top"> 501 528 <th scope="row"><?php _e( 'Remove Image' ); ?></th> 502 529 <td> … … 506 533 </tr> 507 534 <?php endif; 508 535 509 if ( defined( 'HEADER_IMAGE' ) ) : ?>536 if ( defined( 'HEADER_IMAGE' ) && !is_random_header_image() ) : ?> 510 537 <tr valign="top"> 511 538 <th scope="row"><?php _e( 'Reset Image' ); ?></th> 512 539 <td> … … 693 720 // Update the attachment 694 721 wp_insert_attachment($object, $cropped); 695 722 wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); 723 update_post_meta( $_POST['attachment_id'], '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); 696 724 697 725 set_theme_mod('header_image', $url); 698 726