WordPress.org

Make WordPress Core

Ticket #20265: 20265.2.diff

File 20265.2.diff, 8.6 KB (added by sabreuse, 2 years ago)
  • wp-content/themes/twentyten/functions.php

     
    101101        ) ); 
    102102 
    103103        // This theme allows users to set a custom background 
    104         add_custom_background(); 
     104        add_theme_support('custom-background', array('callback' => '')); 
    105105 
    106106        // Your changeable header business starts here 
    107         if ( ! defined( 'HEADER_TEXTCOLOR' ) ) 
    108                 define( 'HEADER_TEXTCOLOR', '' ); 
     107        $header_args = array( 
     108                'random-default' => false, 
     109                'height' => 198, 
     110                'width' => 940, 
     111                'header-text' => false, 
     112                'default-image' => '%s/images/headers/path.jpg', 
     113                'callback' => '', 
     114                'admin-header-callback' => 'twentyten_admin_header_style', 
     115        ); 
     116        add_theme_support( 'custom-header', $header_args ); 
    109117 
    110         // No CSS, just IMG call. The %s is a placeholder for the theme template directory URI. 
    111         if ( ! defined( 'HEADER_IMAGE' ) ) 
    112                 define( 'HEADER_IMAGE', '%s/images/headers/path.jpg' ); 
    113118 
    114         // The height and width of your custom header. You can hook into the theme's own filters to change these values. 
    115         // Add a filter to twentyten_header_image_width and twentyten_header_image_height to change these values. 
    116         define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); 
    117         define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); 
    118  
    119119        // We'll be using post thumbnails for custom header images on posts and pages. 
    120120        // We want them to be 940 pixels wide by 198 pixels tall. 
    121121        // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php. 
    122         set_post_thumbnail_size( HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); 
     122        set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true ); 
    123123 
    124         // Don't support text inside the header image. 
    125         if ( ! defined( 'NO_HEADER_TEXT' ) ) 
    126                 define( 'NO_HEADER_TEXT', true ); 
    127124 
    128         // Add a way for the custom header to be styled in the admin panel that controls 
    129         // custom headers. See twentyten_admin_header_style(), below. 
    130         add_custom_image_header( '', 'twentyten_admin_header_style' ); 
    131  
    132125        // ... and thus ends the changeable header business. 
    133126 
    134127        // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 
  • wp-content/themes/twentyeleven/functions.php

     
    6262 * 
    6363 * @uses load_theme_textdomain() For translation/localization support. 
    6464 * @uses add_editor_style() To style the visual editor. 
    65  * @uses add_theme_support() To add support for post thumbnails, automatic feed links, and Post Formats. 
     65 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, custom backgrounds, and custom image headers, and Post Formats. 
    6666 * @uses register_nav_menus() To add support for navigation menus. 
    67  * @uses add_custom_background() To add support for a custom background. 
    68  * @uses add_custom_image_header() To add support for a custom header. 
    6967 * @uses register_default_headers() To register the default custom header images provided with the theme. 
    7068 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 
    7169 * 
     
    104102        add_theme_support( 'post-formats', array( 'aside', 'link', 'gallery', 'status', 'quote', 'image' ) ); 
    105103 
    106104        // Add support for custom backgrounds 
    107         add_custom_background(); 
     105        add_theme_support('custom-background', array('callback' => '')); 
    108106 
    109107        // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images 
    110108        add_theme_support( 'post-thumbnails' ); 
    111109 
    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 ) ); 
    124  
    125110        // We'll be using post thumbnails for custom header images on posts and pages. 
    126111        // We want them to be the size of the header image that we just defined 
    127112        // 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 ); 
     113        set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true ); 
    129114 
    130115        // 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 
     116        add_image_size(  
     117                'large-feature',  
     118                get_theme_support( 'custom-header', 'width' ),  
     119                get_theme_support( 'custom-header', 'height' ),  
     120                true  
     121        ); // Used for large feature (header) images 
     122         
    132123        add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist 
    133124 
     125        // Add support for custom headers 
    134126        // Turn on random header image rotation by default. 
    135         add_theme_support( 'custom-header', array( 'random-default' => true ) ); 
     127        add_theme_support( 'custom-header', array(  
     128                'default-image' => '', 
     129                'random-default' => true, 
     130                'width' => 1000, 
     131                'height' => 288, 
     132                'default-text-color' => '000', 
     133                'callback' => 'twentyeleven_header_style', 
     134                'admin-header-callback' => 'twentyeleven_admin_header_style', 
     135                'admin-image-div-callback' => 'twentyeleven_admin_header_image', 
     136        ) ); 
    136137 
    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  
    141138        // ... and thus ends the changeable header business. 
    142139 
    143140        // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI. 
     
    203200function twentyeleven_header_style() { 
    204201 
    205202        // 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() ) 
     203        // get_header_textcolor() options: get_theme_support( 'custom-header', 'default-text-color' ) is default, hide text (returns 'blank') or any hex value 
     204        if ( get_theme_support( 'custom-header', 'default-text-color' ) == get_header_textcolor() ) 
    208205                return; 
    209206        // If we get this far, we have custom styles. Let's do this. 
    210207        ?> 
     
    237234/** 
    238235 * Styles the header image displayed on the Appearance > Header admin panel. 
    239236 * 
    240  * Referenced via add_custom_image_header() in twentyeleven_setup(). 
     237 * Referenced via add_theme_support() in twentyeleven_setup(). 
    241238 * 
    242239 * @since Twenty Eleven 1.0 
    243240 */ 
     
    266263        } 
    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, 
    272269                #site-description { 
     
    287284/** 
    288285 * Custom header image markup displayed on the Appearance > Header admin panel. 
    289286 * 
    290  * Referenced via add_custom_image_header() in twentyeleven_setup(). 
     287 * Referenced via add_theme_support() in twentyeleven_setup(). 
    291288 * 
    292289 * @since Twenty Eleven 1.0 
    293290 */ 
    294291function twentyeleven_admin_header_image() { ?> 
    295292        <div id="headimg"> 
    296293                <?php 
    297                 if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ) 
     294                if ( 'blank' == get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ) || '' == get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ) ) 
    298295                        $style = ' style="display:none;"'; 
    299296                else 
    300                         $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; 
     297                        $style = ' style="color:#' . get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ) . ';"'; 
    301298                ?> 
    302299                <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1> 
    303300                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>