Make WordPress Core


Ignore:
File:
1 edited

Legend:

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

    r18018 r18325  
    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}
     
    397397        // a new theme directory and the theme header is not updated.  Whichever
    398398        // theme is first keeps the name.  Subsequent themes get a suffix applied.
    399         // The Twenty Ten, Default and Classic themes always trump their pretenders.
     399        // The Twenty Eleven, Twenty Ten, Default and Classic themes always trump
     400        // their pretenders.
    400401        if ( isset($wp_themes[$name]) ) {
    401402            $trump_cards = array(
    402                 'classic'   => 'WordPress Classic',
    403                 'default'   => 'WordPress Default',
    404                 'twentyten' => 'Twenty Ten',
     403                'classic'      => 'WordPress Classic',
     404                'default'      => 'WordPress Default',
     405                'twentyten'    => 'Twenty Ten',
     406                'twentyeleven' => 'Twenty Eleven',
    405407            );
    406408            if ( isset( $trump_cards[ $stylesheet ] ) && $name == $trump_cards[ $stylesheet ] ) {
     
    828830    $templates[] = "category-{$category->slug}.php";
    829831    $templates[] = "category-{$category->term_id}.php";
    830     $templates[] = "category.php";
     832    $templates[] = 'category.php';
    831833
    832834    return get_query_template( 'category', $templates );
     
    852854    $templates[] = "tag-{$tag->slug}.php";
    853855    $templates[] = "tag-{$tag->term_id}.php";
    854     $templates[] = "tag.php";
     856    $templates[] = 'tag.php';
    855857
    856858    return get_query_template( 'tag', $templates );
     
    882884    $templates[] = "taxonomy-$taxonomy-{$term->slug}.php";
    883885    $templates[] = "taxonomy-$taxonomy.php";
    884     $templates[] = "taxonomy.php";
     886    $templates[] = 'taxonomy.php';
    885887
    886888    return get_query_template( 'taxonomy', $templates );
     
    964966    if ( $id )
    965967        $templates[] = "page-$id.php";
    966     $templates[] = "page.php";
     968    $templates[] = 'page.php';
    967969
    968970    return get_query_template( 'page', $templates );
     
    14281430function get_header_image() {
    14291431    $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
    1430 
    14311432    $url = get_theme_mod( 'header_image', $default );
     1433
     1434    if ( 'remove-header' == $url )
     1435        return false;
     1436
     1437    if ( is_random_header_image() )
     1438        $url = get_random_header_image();
    14321439
    14331440    if ( is_ssl() )
     
    14401447
    14411448/**
     1449 * Get random header image from registered images in theme.
     1450 *
     1451 * @since 3.2.0
     1452 *
     1453 * @return string Path to header image
     1454 */
     1455function get_random_header_image() {
     1456    global $_wp_default_headers;
     1457
     1458    $header_image_mod = get_theme_mod( 'header_image', '' );
     1459    $headers = array();
     1460
     1461    if ( 'random-uploaded-image' == $header_image_mod )
     1462        $headers = get_uploaded_header_images();
     1463    elseif ( ! empty( $_wp_default_headers ) ) {
     1464        if ( 'random-default-image' == $header_image_mod ) {
     1465            $headers = $_wp_default_headers;
     1466        } else {
     1467            $is_random = get_theme_support( 'custom-header' );
     1468            if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) )
     1469                $headers = $_wp_default_headers;
     1470        }
     1471    }
     1472
     1473    if ( empty( $headers ) )
     1474        return '';
     1475
     1476    $random_image = array_rand( $headers );
     1477    $header_url = sprintf( $headers[$random_image]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() );
     1478
     1479    return $header_url;
     1480}
     1481
     1482/**
     1483 * Check if random header image is in use.
     1484 *
     1485 * Always true if user expressly chooses the option in Appearance > Header.
     1486 * Also true if theme has multiple header images registered, no specific header image
     1487 * is chosen, and theme turns on random headers with add_theme_support().
     1488 *
     1489 * @since 3.2.0
     1490 * @uses HEADER_IMAGE
     1491 *
     1492 * @param string $type The random pool to use. any|default|uploaded
     1493 * @return boolean
     1494 */
     1495function is_random_header_image( $type = 'any' ) {
     1496    $default = defined( 'HEADER_IMAGE' ) ? HEADER_IMAGE : '';
     1497    $header_image_mod = get_theme_mod( 'header_image', $default );
     1498
     1499    if ( 'any' == $type ) {
     1500        if ( 'random-default-image' == $header_image_mod || 'random-uploaded-image' == $header_image_mod || ( '' != get_random_header_image() && empty( $header_image_mod ) ) )
     1501            return true;
     1502    } else {
     1503        if ( "random-$type-image" == $header_image_mod )
     1504            return true;
     1505        elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() )
     1506            return true;
     1507    }
     1508
     1509    return false;
     1510}
     1511
     1512/**
    14421513 * Display header image path.
    14431514 *
     
    14461517function header_image() {
    14471518    echo get_header_image();
     1519}
     1520
     1521/**
     1522 * Get the header images uploaded for the current theme.
     1523 *
     1524 * @since 3.2.0
     1525 *
     1526 * @return array
     1527 */
     1528function get_uploaded_header_images() {
     1529    $header_images = array();
     1530
     1531    // @todo caching
     1532    $headers = get_posts( array( 'post_type' => 'attachment', 'meta_key' => '_wp_attachment_is_custom_header', 'meta_value' => get_option('stylesheet'), 'orderby' => 'none', 'nopaging' => true ) );
     1533
     1534    if ( empty( $headers ) )
     1535        return array();
     1536
     1537    foreach ( (array) $headers as $header ) {
     1538        $url = esc_url_raw( $header->guid );
     1539        $header = basename($url);
     1540        $header_images[$header] = array();
     1541        $header_images[$header]['url'] =  $url;
     1542        $header_images[$header]['thumbnail_url'] =  $url;
     1543        $header_images[$header]['uploaded'] = true;
     1544    }
     1545
     1546    return $header_images;
    14481547}
    14491548
     
    14671566        add_action('wp_head', $header_callback);
    14681567
    1469     add_theme_support( 'custom-header', array( 'callback' => $header_callback ) );
     1568    $support = array( 'callback' => $header_callback );
     1569    $theme_support = get_theme_support( 'custom-header' );
     1570    if ( ! empty( $theme_support ) && is_array( $theme_support[ 0 ] ) )
     1571        $support = array_merge( $theme_support[ 0 ], $support );
     1572    add_theme_support( 'custom-header',  $support );
    14701573    add_theme_support( 'custom-header-uploads' );
    14711574
Note: See TracChangeset for help on using the changeset viewer.