WordPress.org

Make WordPress Core

Ticket #20265: 20265.diff

File 20265.diff, 8.6 KB (added by sabreuse, 6 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' => true,
     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( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true ); // Used for large feature (header) images
    132117        add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
    133118
     119        // Add support for custom headers
    134120        // Turn on random header image rotation by default.
    135         add_theme_support( 'custom-header', array( 'random-default' => true ) );
     121        add_theme_support( 'custom-header', array(
     122                'default-image' => '',
     123                'random-default' => false,
     124                'width' => 1000,
     125                'height' => 288,
     126                'default-text-color' => '000',
     127                'callback' => 'twentyeleven_header_style',
     128                'admin-header-callback' => 'twentyeleven_admin_header_style',
     129                'admin-image-div-callback' => 'twentyeleven_admin_header_image',
     130        ) );
    136131
    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 
    141132        // ... and thus ends the changeable header business.
    142133
    143134        // Default custom headers packaged with the theme. %s is a placeholder for the theme template directory URI.
     
    203194function twentyeleven_header_style() {
    204195
    205196        // 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() )
     197        // get_header_textcolor() options: get_theme_support( 'custom-header', 'default-text-color' ) is default, hide text (returns 'blank') or any hex value
     198        if ( get_theme_support( 'custom-header', 'default-text-color' ) == get_header_textcolor() )
    208199                return;
    209200        // If we get this far, we have custom styles. Let's do this.
    210201        ?>
     
    237228/**
    238229 * Styles the header image displayed on the Appearance > Header admin panel.
    239230 *
    240  * Referenced via add_custom_image_header() in twentyeleven_setup().
     231 * Referenced via add_theme_support() in twentyeleven_setup().
    241232 *
    242233 * @since Twenty Eleven 1.0
    243234 */
     
    266257        }
    267258        <?php
    268259                // If the user has set a custom color for the text use that
    269                 if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
     260                if ( get_header_textcolor() != get_theme_support( 'custom-header', 'default-text-color' ) ) :
    270261        ?>
    271262                #site-title a,
    272263                #site-description {
     
    287278/**
    288279 * Custom header image markup displayed on the Appearance > Header admin panel.
    289280 *
    290  * Referenced via add_custom_image_header() in twentyeleven_setup().
     281 * Referenced via add_theme_support() in twentyeleven_setup().
    291282 *
    292283 * @since Twenty Eleven 1.0
    293284 */
    294285function twentyeleven_admin_header_image() { ?>
    295286        <div id="headimg">
    296287                <?php
    297                 if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) )
     288                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' ) ) )
    298289                        $style = ' style="display:none;"';
    299290                else
    300                         $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
     291                        $style = ' style="color:#' . get_theme_mod( 'header_textcolor', get_theme_support( 'custom-header', 'default-text-color' ) ) . ';"';
    301292                ?>
    302293                <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
    303294                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>