Make WordPress Core

Changeset 20983


Ignore:
Timestamp:
06/04/2012 02:43:19 PM (12 years ago)
Author:
ryan
Message:

Back compat for bundled themes. Props nacin, SergeyBiryukov, kobenland. fixes #20768

Location:
trunk/wp-content/themes
Files:
5 edited

Legend:

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

    r20973 r20983  
    115115
    116116    // Add support for custom headers.
    117     add_theme_support( 'custom-header', array(
     117    $custom_header_support = array(
    118118        // The default header text color.
    119119        'default-text-color' => '000',
     
    131131        // Callback used to display the header preview in the admin.
    132132        'admin-preview-callback' => 'twentyeleven_admin_header_image',
    133     ) );
     133    );
     134   
     135    add_theme_support( 'custom-header', $custom_header_support );
     136
     137    if ( ! function_exists( 'get_custom_header' ) ) {
     138        // This is all for compatibility with versions of WordPress prior to 3.4.
     139        define( 'HEADER_TEXTCOLOR', $custom_header_support['default-text-color'] );
     140        define( 'HEADER_IMAGE', '' );
     141        define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
     142        define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
     143        add_custom_image_header( $custom_header_support['wp-head-callback'], $custom_header_support['admin-head-callback'], $custom_header_support['admin-preview-callback'] );
     144        add_custom_background();
     145    }
    134146
    135147    // We'll be using post thumbnails for custom header images on posts and pages.
    136148    // We want them to be the size of the header image that we just defined
    137149    // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
    138     set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
     150    set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
    139151
    140152    // Add Twenty Eleven's custom image sizes.
    141153    // Used for large feature (header) images.
    142     add_image_size( 'large-feature', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
     154    add_image_size( 'large-feature', $custom_header_support['width'], $custom_header_support['height'], true );
    143155    // Used for featured posts if a large-feature doesn't exist.
    144156    add_image_size( 'small-feature', 500, 300 );
     
    208220
    209221    // If no custom options for text are set, let's bail.
    210     if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
     222    if ( $text_color == HEADER_TEXTCOLOR )
    211223        return;
     224       
    212225    // If we get this far, we have custom styles. Let's do this.
    213226    ?>
     
    270283    <?php
    271284        // If the user has set a custom color for the text use that
    272         if ( get_header_textcolor() != get_theme_support( 'custom-header', 'default-text-color' ) ) :
     285        if ( get_header_textcolor() != HEADER_TEXTCOLOR ) :
    273286    ?>
    274287        #site-title a,
  • trunk/wp-content/themes/twentyeleven/header.php

    r20470 r20983  
    8080                $header_image = get_header_image();
    8181                if ( $header_image ) :
    82                     $header_image_width  = get_custom_header()->width;
    83             ?>
     82                    // Compatibility with versions of WordPress prior to 3.4.
     83                    if ( function_exists( 'get_custom_header' ) ) {
     84                        // We need to figure out what the minimum width should be for our featured image.
     85                        // This result would be the suggested width if the theme were to implement flexible widths.
     86                        $header_image_width = get_theme_support( 'custom-header', 'width' );
     87                    } else {
     88                        $header_image_width = HEADER_IMAGE_WIDTH;
     89                    }
     90                    ?>
    8491            <a href="<?php echo esc_url( home_url( '/' ) ); ?>">
    8592                <?php
     
    9198                        // Houston, we have a new header image!
    9299                        echo get_the_post_thumbnail( $post->ID, 'post-thumbnail' );
    93                     else : ?>
    94                     <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" />
     100                    else :
     101                        // Compatibility with versions of WordPress prior to 3.4.
     102                        if ( function_exists( 'get_custom_header' ) ) {
     103                            $header_image_width  = get_custom_header()->width;
     104                            $header_image_height = get_custom_header()->height;
     105                        } else {
     106                            $header_image_width  = HEADER_IMAGE_WIDTH;
     107                            $header_image_height = HEADER_IMAGE_HEIGHT;
     108                        }
     109                        ?>
     110                    <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    95111                <?php endif; // end check for featured image or standard header ?>
    96112            </a>
  • trunk/wp-content/themes/twentyeleven/showcase.php

    r20226 r20983  
    6767                    $counter_slider = 0;
    6868
    69                     $header_image_width  = get_theme_support( 'custom-header', 'width' );
    70                     ?>
     69                    // Compatibility with versions of WordPress prior to 3.4.
     70                    if ( function_exists( 'get_custom_header' ) )
     71                        $header_image_width = get_theme_support( 'custom-header', 'width' );
     72                    else
     73                        $header_image_width = HEADER_IMAGE_WIDTH;
     74                ?>
    7175
    7276                <div class="featured-posts">
  • trunk/wp-content/themes/twentyten/functions.php

    r20973 r20983  
    102102    // The custom header business starts here.
    103103
    104     add_theme_support( 'custom-header', array(
     104    $custom_header_support = array(
    105105        // The default image to use.
    106106        // The %s is a placeholder for the theme template directory URI.
     
    115115        // Callback for styling the header preview in the admin.
    116116        'admin-head-callback' => 'twentyten_admin_header_style',
    117     ) );
     117    );
     118   
     119    add_theme_support( 'custom-header', $custom_header_support );
     120   
     121    if ( ! function_exists( 'get_custom_header' ) ) {
     122        // This is all for compatibility with versions of WordPress prior to 3.4.
     123        define( 'HEADER_TEXTCOLOR', '' );
     124        define( 'NO_HEADER_TEXT', true );
     125        define( 'HEADER_IMAGE', $custom_header_support['default-image'] );
     126        define( 'HEADER_IMAGE_WIDTH', $custom_header_support['width'] );
     127        define( 'HEADER_IMAGE_HEIGHT', $custom_header_support['height'] );
     128        add_custom_image_header( '', $custom_header_support['admin-head-callback'] );
     129        add_custom_background();
     130    }
    118131
    119132    // We'll be using post thumbnails for custom header images on posts and pages.
    120133    // We want them to be 940 pixels wide by 198 pixels tall.
    121134    // Larger images will be auto-cropped to fit, smaller ones will be ignored. See header.php.
    122     set_post_thumbnail_size( get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ), true );
     135    set_post_thumbnail_size( $custom_header_support['width'], $custom_header_support['height'], true );
    123136
    124137    // ... and thus ends the custom header business.
  • trunk/wp-content/themes/twentyten/header.php

    r20474 r20983  
    6767
    6868                <?php
     69                    // Compatibility with versions of WordPress prior to 3.4.
     70                    if ( function_exists( 'get_custom_header' ) ) {
     71                        // We need to figure out what the minimum width should be for our featured image.
     72                        // This result would be the suggested width if the theme were to implement flexible widths.
     73                        $header_image_width = get_theme_support( 'custom-header', 'width' );
     74                    } else {
     75                        $header_image_width = HEADER_IMAGE_WIDTH;
     76                    }
     77
    6978                    // Check if this is a post or page, if it has a thumbnail, and if it's a big one
    7079                    if ( is_singular() && current_theme_supports( 'post-thumbnails' ) &&
    7180                            has_post_thumbnail( $post->ID ) &&
    7281                            ( /* $src, $width, $height */ $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'post-thumbnail' ) ) &&
    73                             $image[1] >= get_theme_support( 'custom-header', 'width' ) ) :
     82                            $image[1] >= $header_image_width ) :
    7483                        // Houston, we have a new header image!
    7584                        echo get_the_post_thumbnail( $post->ID );
    76                     elseif ( get_header_image() ) :
     85                    elseif ( get_header_image() ) :
     86                        // Compatibility with versions of WordPress prior to 3.4.
    7787                        if ( function_exists( 'get_custom_header' ) ) {
    78                             $header_width  = get_custom_header()->width;
    79                             $header_height = get_custom_header()->height;
     88                            $header_image_width  = get_custom_header()->width;
     89                            $header_image_height = get_custom_header()->height;
    8090                        } else {
    81                             $header_height = $header_width = '';
     91                            $header_image_width  = HEADER_IMAGE_WIDTH;
     92                            $header_image_height = HEADER_IMAGE_HEIGHT;
    8293                        }
    83                         ?>
    84                         <img src="<?php header_image(); ?>" width="<?php echo $header_width; ?>" height="<?php echo $header_height; ?>" alt="" />
     94                    ?>
     95                        <img src="<?php header_image(); ?>" width="<?php echo $header_image_width; ?>" height="<?php echo $header_image_height; ?>" alt="" />
    8596                    <?php endif; ?>
    8697            </div><!-- #branding -->
Note: See TracChangeset for help on using the changeset viewer.