WordPress.org

Make WordPress Core

Changeset 20222


Ignore:
Timestamp:
03/20/2012 08:37:53 PM (6 years ago)
Author:
nacin
Message:

Update twentyeleven/functions.php to use the new add_theme_support() calls for backgrounds and headers. props sabreuse for initial patch. see #20265. see #20249.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/twentyeleven/functions.php

    r19582 r20222  
    104104    add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) );
    105105
    106     // Add support for custom backgrounds
    107     add_custom_background();
     106    // Add support for custom backgrounds.
     107    add_theme_support( 'custom-background' );
    108108
    109109    // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
    110110    add_theme_support( 'post-thumbnails' );
    111111
    112     // The next four constants set how Twenty Eleven supports custom headers.
    113 
    114     // The default header text color
    115     define( 'HEADER_TEXTCOLOR', '000' );
    116 
    117     // By leaving empty, we allow for random image rotation.
    118     define( 'HEADER_IMAGE', '' );
    119 
    120     // The height and width of your custom header.
    121     // Add a filter to twentyeleven_header_image_width and twentyeleven_header_image_height to change these values.
    122     define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyeleven_header_image_width', 1000 ) );
    123     define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyeleven_header_image_height', 288 ) );
     112    // Add support for custom headers.
     113    add_theme_support( 'custom-header', array(
     114        // The default header text color.
     115        'default-text-color' => '000',
     116        // The height and width of our custom header.
     117        'width' => apply_filters( 'twentyeleven_header_image_width', 1000 ),
     118        'height' => apply_filters( 'twentyeleven_header_image_height', 288 ),
     119        // Random image rotation by default.
     120        'random-default' => true,
     121        // Callback for styling the header.
     122        'callback' => 'twentyeleven_header_style',
     123        // Callback for styling the header preview in the admin.
     124        'admin-header-callback' => 'twentyeleven_admin_header_style',
     125        // Callback used to display the header preview in the admin.
     126        'admin-image-div-callback' => 'twentyeleven_admin_header_image',
     127    ) );
    124128
    125129    // We'll be using post thumbnails for custom header images on posts and pages.
    126130    // We want them to be the size of the header image that we just defined
    127131    // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
    128     set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true );
    129 
    130     // Add Twenty Eleven's custom image sizes
    131     add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
    132     add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
    133 
    134     // Turn on random header image rotation by default.
    135     add_theme_support( 'custom-header', array( 'random-default' => true ) );
    136 
    137     // Add a way for the custom header to be styled in the admin panel that controls
    138     // custom headers. See twentyeleven_admin_header_style(), below.
    139     add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' );
    140 
    141     // ... and thus ends the changeable header business.
     132    set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
     133
     134    // Add Twenty Eleven's custom image sizes.
     135    // Used for large feature (header) images.
     136    add_image_size( 'large-feature', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
     137    // Used for featured posts if a large-feature doesn't exist.
     138    add_image_size( 'small-feature', 500, 300 );
    142139
    143140    // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
     
    202199 */
    203200function twentyeleven_header_style() {
    204 
    205     // If no custom options for text are set, let's bail
    206     // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
    207     if ( HEADER_TEXTCOLOR == get_header_textcolor() )
     201    $text_color = get_header_textcolor();
     202
     203    // If no custom options for text are set, let's bail.
     204    if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
    208205        return;
    209206    // If we get this far, we have custom styles. Let's do this.
     
    212209    <?php
    213210        // Has the text been hidden?
    214         if ( 'blank' == get_header_textcolor() ) :
     211        if ( 'blank' == $text_color ) :
    215212    ?>
    216213        #site-title,
     
    226223        #site-title a,
    227224        #site-description {
    228             color: #<?php echo get_header_textcolor(); ?> !important;
     225            color: #<?php echo $text_color; ?> !important;
    229226        }
    230227    <?php endif; ?>
     
    267264    <?php
    268265        // If the user has set a custom color for the text use that
    269         if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
     266        if ( get_header_textcolor() != get_theme_support( 'custom-header', 'default-text-color' ) ) :
    270267    ?>
    271268        #site-title a,
     
    295292    <div id="headimg">
    296293        <?php
    297         if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
    298             $style = ' style="display:none;"';
     294        $color = get_header_textcolor();
     295        $image = get_header_image();
     296        if ( $color && $color != 'blank' )
     297            $style = ' style="color:#' . $color . '"';
    299298        else
    300             $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
     299            $style = ' style="display:none"';
    301300        ?>
    302301        <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
    303302        <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
    304         <?php $header_image = get_header_image();
    305         if ( ! empty( $header_image ) ) : ?>
    306             <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
     303        <?php if ( $image ) : ?>
     304            <img src="<?php echo esc_url( $image ); ?>" alt="" />
    307305        <?php endif; ?>
    308306    </div>
Note: See TracChangeset for help on using the changeset viewer.