Make WordPress Core


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/theme.php

    r18018 r18268  
    8080function get_stylesheet_uri() {
    8181    $stylesheet_dir_uri = get_stylesheet_directory_uri();
    82     $stylesheet_uri = $stylesheet_dir_uri . "/style.css";
     82    $stylesheet_uri = $stylesheet_dir_uri . '/style.css';
    8383    return apply_filters('stylesheet_uri', $stylesheet_uri, $stylesheet_dir_uri);
    8484}
     
    828828    $templates[] = "category-{$category->slug}.php";
    829829    $templates[] = "category-{$category->term_id}.php";
    830     $templates[] = "category.php";
     830    $templates[] = 'category.php';
    831831
    832832    return get_query_template( 'category', $templates );
     
    852852    $templates[] = "tag-{$tag->slug}.php";
    853853    $templates[] = "tag-{$tag->term_id}.php";
    854     $templates[] = "tag.php";
     854    $templates[] = 'tag.php';
    855855
    856856    return get_query_template( 'tag', $templates );
     
    882882    $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
    883883    $templates[] = "taxonomy-$taxonomy.php";
    884     $templates[] = "taxonomy.php";
     884    $templates[] = 'taxonomy.php';
    885885
    886886    return get_query_template( 'taxonomy', $templates );
     
    964964    if ( $id )
    965965        $templates[] = "page-$id.php";
    966     $templates[] = "page.php";
     966    $templates[] = 'page.php';
    967967
    968968    return get_query_template( 'page', $templates );
     
    14281428function get_header_image() {
    14291429    $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
    1430 
    14311430    $url = get_theme_mod( 'header_image', $default );
     1431
     1432    if ( 'remove-header' == $url )
     1433        return false;
     1434
     1435    if ( is_random_header_image() )
     1436        $url = get_random_header_image();
    14321437
    14331438    if ( is_ssl() )
     
    14401445
    14411446/**
     1447 * Get random header image from registered images in theme.
     1448 *
     1449 * @since 3.2.0
     1450 *
     1451 * @return string Path to header image
     1452 */
     1453function get_random_header_image() {
     1454    global $_wp_default_headers;
     1455
     1456    $header_image_mod = get_theme_mod( 'header_image', '' );
     1457    $headers = array();
     1458
     1459    if ( 'random-uploaded-image' == $header_image_mod )
     1460        $headers = get_uploaded_header_images();
     1461    elseif ( ! empty( $_wp_default_headers ) )
     1462        $headers = $_wp_default_headers;
     1463
     1464    if ( empty( $headers ) )
     1465        return '';
     1466
     1467    $random_image = array_rand( $headers );
     1468    $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
     1469
     1470    return $header_url;
     1471}
     1472
     1473/**
     1474 * Check if random header image is in use.
     1475 *
     1476 * Always true if user expressly chooses the option in Appearance > Header.
     1477 * Also true if theme has multiple header images registered and no specific header image is chosen.
     1478 *
     1479 * @since 3.2.0
     1480 * @uses HEADER_IMAGE
     1481 *
     1482 * @param string $type The random pool to use. any|default|uploaded
     1483 * @return boolean
     1484 */
     1485function is_random_header_image( $type = 'any' ) {
     1486    $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
     1487    $header_image_mod = get_theme_mod( 'header_image', $default );
     1488
     1489    if ( 'any' == $type ) {
     1490        if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) )
     1491            return true;
     1492    } else {
     1493        if ( "random-$type-image" == $header_image_mod )
     1494            return true;
     1495        elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image()  )
     1496            return true;
     1497    }
     1498
     1499    return false;
     1500}
     1501
     1502/**
    14421503 * Display header image path.
    14431504 *
     
    14461507function header_image() {
    14471508    echo get_header_image();
     1509}
     1510
     1511/**
     1512 * Get the header images uploaded for the current theme.
     1513 *
     1514 * @since 3.2.0
     1515 *
     1516 * @return array
     1517 */
     1518function get_uploaded_header_images() {
     1519    $header_images = array();
     1520
     1521    // @todo caching
     1522    $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) );
     1523
     1524    if ( empty( $headers ) )
     1525        return array();
     1526
     1527    foreach ( (array) $headers as $header ) {
     1528        $url = esc_url_raw( $header->guid );
     1529        $header = basename($url);
     1530        $header_images[$header] = array();
     1531        $header_images[$header]['url'] =  $url;
     1532        $header_images[$header]['thumbnail_url'] =  $url;
     1533        $header_images[$header]['uploaded'] = true;
     1534    }
     1535
     1536    return $header_images;
    14481537}
    14491538
Note: See TracChangeset for help on using the changeset viewer.