Add theme support option for turning on random default headers. fixes #17832

git-svn-id: http://svn.automattic.com/wordpress/trunk@18325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2011-06-22 19:09:23 +00:00
parent bc667be71b
commit 9907923011
2 changed files with 22 additions and 7 deletions

View File

@ -109,12 +109,12 @@ function twentyeleven_setup() {
// This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images // This theme uses Featured Images (also known as post thumbnails) for per-post/per-page Custom Header images
add_theme_support( 'post-thumbnails' ); add_theme_support( 'post-thumbnails' );
// The next four constants set how twentyeleven supports custom headers // The next four constants set how Twenty Eleven supports custom headers.
// The default header text color // The default header text color
define( 'HEADER_TEXTCOLOR', '000' ); define( 'HEADER_TEXTCOLOR', '000' );
// By leaving empty, we default to random image rotation // By leaving empty, we allow for random image rotation.
define( 'HEADER_IMAGE', '' ); define( 'HEADER_IMAGE', '' );
// The height and width of your custom header. // The height and width of your custom header.
@ -131,6 +131,9 @@ function twentyeleven_setup() {
add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images add_image_size( 'large-feature', HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT, true ); // Used for large feature (header) images
add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist add_image_size( 'small-feature', 500, 300 ); // Used for featured posts if a large-feature doesn't exist
// Turn on random header image rotation by default.
add_theme_support( 'custom-header', array( 'random-default' => true ) );
// Add a way for the custom header to be styled in the admin panel that controls // Add a way for the custom header to be styled in the admin panel that controls
// custom headers. See twentyeleven_admin_header_style(), below. // custom headers. See twentyeleven_admin_header_style(), below.
add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' ); add_custom_image_header( 'twentyeleven_header_style', 'twentyeleven_admin_header_style', 'twentyeleven_admin_header_image' );

View File

@ -1460,8 +1460,15 @@ function get_random_header_image() {
if ( 'random-uploaded-image' == $header_image_mod ) if ( 'random-uploaded-image' == $header_image_mod )
$headers = get_uploaded_header_images(); $headers = get_uploaded_header_images();
elseif ( ! empty( $_wp_default_headers ) ) elseif ( ! empty( $_wp_default_headers ) ) {
$headers = $_wp_default_headers; if ( 'random-default-image' == $header_image_mod ) {
$headers = $_wp_default_headers;
} else {
$is_random = get_theme_support( 'custom-header' );
if ( isset( $is_random[ 0 ] ) && !empty( $is_random[ 0 ][ 'random-default' ] ) )
$headers = $_wp_default_headers;
}
}
if ( empty( $headers ) ) if ( empty( $headers ) )
return ''; return '';
@ -1476,7 +1483,8 @@ function get_random_header_image() {
* Check if random header image is in use. * Check if random header image is in use.
* *
* Always true if user expressly chooses the option in Appearance > Header. * Always true if user expressly chooses the option in Appearance > Header.
* Also true if theme has multiple header images registered and no specific header image is chosen. * Also true if theme has multiple header images registered, no specific header image
* is chosen, and theme turns on random headers with add_theme_support().
* *
* @since 3.2.0 * @since 3.2.0
* @uses HEADER_IMAGE * @uses HEADER_IMAGE
@ -1494,7 +1502,7 @@ function is_random_header_image( $type = 'any' ) {
} else { } else {
if ( "random-$type-image" == $header_image_mod ) if ( "random-$type-image" == $header_image_mod )
return true; return true;
elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() ) elseif ( 'default' == $type && empty( $header_image_mod ) && '' != get_random_header_image() )
return true; return true;
} }
@ -1557,7 +1565,11 @@ function add_custom_image_header( $header_callback, $admin_header_callback, $adm
if ( ! empty( $header_callback ) ) if ( ! empty( $header_callback ) )
add_action('wp_head', $header_callback); add_action('wp_head', $header_callback);
add_theme_support( 'custom-header', array( 'callback' => $header_callback ) ); $support = array( 'callback' => $header_callback );
$theme_support = get_theme_support( 'custom-header' );
if ( ! empty( $theme_support ) && is_array( $theme_support[ 0 ] ) )
$support = array_merge( $theme_support[ 0 ], $support );
add_theme_support( 'custom-header', $support );
add_theme_support( 'custom-header-uploads' ); add_theme_support( 'custom-header-uploads' );
if ( ! is_admin() ) if ( ! is_admin() )