Changeset 17757 for trunk/wp-includes/theme.php
- Timestamp:
- 04/28/2011 11:02:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/theme.php
r17316 r17757 1428 1428 function get_header_image() { 1429 1429 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1430 1431 1430 $url = get_theme_mod( 'header_image', $default ); 1431 1432 if ( is_random_header_image() ) 1433 $url = get_random_header_image(); 1432 1434 1433 1435 if ( is_ssl() ) … … 1440 1442 1441 1443 /** 1444 * Get random header image from registered images in theme. 1445 * 1446 * @since 3.2 1447 * 1448 * @return string Path to header image 1449 */ 1450 function get_random_header_image() { 1451 global $_wp_default_headers; 1452 1453 $header_image_mod = get_theme_mod( 'header_image', '' ); 1454 $headers = array(); 1455 1456 if ( 'random-uploaded-image' == $header_image_mod ) 1457 $headers = get_uploaded_header_images(); 1458 elseif ( ! empty( $_wp_default_headers ) ) 1459 $headers = $_wp_default_headers; 1460 1461 if ( empty( $headers ) ) 1462 return ''; 1463 1464 $random_image = array_rand( $headers ); 1465 $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); 1466 1467 return $header_url; 1468 } 1469 1470 /** 1471 * Check if random header image is in use. 1472 * 1473 * Always true if user expressly chooses the option in Appearance > Header. 1474 * Also true if theme has multiple header images registered and no specific header image is chosen. 1475 * 1476 * @since 3.2 1477 * @uses HEADER_IMAGE 1478 * 1479 * @param string $type The random pool to use. any|default|uploaded 1480 * @return boolean 1481 */ 1482 function is_random_header_image( $type = 'any' ) { 1483 $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : ''; 1484 $header_image_mod = get_theme_mod( 'header_image', $default ); 1485 1486 if ( 'any' == $type ) { 1487 if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) ) 1488 return true; 1489 } else { 1490 if ( "random-$type-image" == $header_image_mod ) 1491 return true; 1492 } 1493 1494 return false; 1495 } 1496 1497 /** 1442 1498 * Display header image path. 1443 1499 * … … 1446 1502 function header_image() { 1447 1503 echo get_header_image(); 1504 } 1505 1506 /** 1507 * Get the header images uploaded for the current theme. 1508 * 1509 * @since 3.2.0 1510 * 1511 * @return array 1512 */ 1513 function get_uploaded_header_images() { 1514 $header_images = array(); 1515 1516 // @todo caching 1517 $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) ); 1518 1519 if ( empty( $headers ) ) 1520 return array(); 1521 1522 foreach ( (array) $headers as $header ) { 1523 $url = $header->guid; 1524 $header = basename($url); 1525 $header_images[$header] = array(); 1526 $header_images[$header]['url'] = $url; 1527 $header_images[$header]['thumbnail_url'] = $url; 1528 $header_images[$header]['uploaded'] = true; 1529 } 1530 1531 return $header_images; 1448 1532 } 1449 1533
Note: See TracChangeset
for help on using the changeset viewer.