From a8a6d742e1a0cb69c29fb42c13a1dd889ae6e0fb Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 25 Feb 2010 19:18:44 +0000 Subject: [PATCH] Default header selector, first pass. see #12343 git-svn-id: http://svn.automattic.com/wordpress/trunk@13403 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/custom-header.php | 87 ++++++++++++++++++++++- wp-content/themes/twentyten/functions.php | 11 ++- wp-includes/theme.php | 13 ++++ 3 files changed, 109 insertions(+), 2 deletions(-) diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index cc7cf1229..73f42589e 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -33,6 +33,8 @@ class Custom_Image_Header { */ var $admin_image_div_callback; + var $default_headers = array(); + /** * PHP4 Constructor - Register administration header callback. * @@ -133,6 +135,74 @@ class Custom_Image_Header { check_admin_referer('custom-header'); remove_theme_mods(); } + + if ( isset($_POST['default-header']) ) { + $this->process_default_headers(); + if ( isset($this->default_headers[$_POST['default-header']]) ) + set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url'])); + } + } + + /** + * Process the default headers + * + * @since 3.0.0 + */ + function process_default_headers() { + global $_wp_default_headers; + + if ( !empty($this->headers) ) + return; + + if ( !isset($_wp_default_headers) ) + return; + + $this->default_headers = $_wp_default_headers; + foreach ( array_keys($this->default_headers) as $header ) { + $this->default_headers[$header]['url'] = sprintf( $this->default_headers[$header]['url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); + $this->default_headers[$header]['thumbnail_url'] = sprintf( $this->default_headers[$header]['thumbnail_url'], get_template_directory_uri(), get_stylesheet_directory_uri() ); + } + } + + /** + * Display UI for selecting one of several default headers. + * + * @since 3.0.0 + */ + function show_default_header_selector() { + echo ''; + + $headers = array_keys($this->default_headers); + $table = array(); + $rows = ceil(count($headers) / 3); + for ( $row = 1; $row <= $rows; $row++ ) { + for ( $col = 1; $col <= 3; $col++ ) { + $table[$row][$col] = array_shift($headers); + } + } + + foreach ( $table as $row => $cols ) { + echo ''; + foreach ( $cols as $col => $header_key ) { + if ( !$header_key ) + continue; + $class = array('available-theme'); + if ( $row == 1 ) $class[] = 'top'; + if ( $col == 1 ) $class[] = 'left'; + if ( $row == $rows ) $class[] = 'bottom'; + if ( $col == 3 ) $class[] = 'right'; + if ( !isset($this->headers[$header_key])) + echo ''; + } + echo ''; + } + echo '
'; + $header_thumbnail = $this->default_headers[$header_key]['thumbnail_url']; + $header_url = $this->default_headers[$header_key]['url']; + $header_desc = $this->default_headers[$header_key]['description']; + echo ''; + echo '
'; } /** @@ -284,6 +354,7 @@ class Custom_Image_Header { * @since unknown */ function step_1() { + $this->process_default_headers(); if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>

Visit your site to see how it looks.'), home_url()); ?>

@@ -293,6 +364,9 @@ class Custom_Image_Header {

+default_headers) ) : +?>

admin_image_div_callback ) {
- +
+' . __('Choose one of these cool headers, or upload your own image below.') . '

'; + echo '
'; + wp_nonce_field('custom-header'); + $this->show_default_header_selector(); + echo ''; + echo '
'; + echo '
'; +endif; +?>

%1$d x %2$d pixels will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?>

diff --git a/wp-content/themes/twentyten/functions.php b/wp-content/themes/twentyten/functions.php index 99f13a144..f6669312c 100644 --- a/wp-content/themes/twentyten/functions.php +++ b/wp-content/themes/twentyten/functions.php @@ -9,7 +9,7 @@ function twentyten_init() { // Your Changeable header business starts here // No CSS, just IMG call define( 'HEADER_TEXTCOLOR', ''); - define( 'HEADER_IMAGE', '%s/images/header-1.jpg'); // %s is theme dir uri + define( 'HEADER_IMAGE', '%s/images/headers/forestfloor.jpg'); // %s is theme dir uri define( 'HEADER_IMAGE_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) ); define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) ); define( 'NO_HEADER_TEXT', true ); @@ -17,6 +17,15 @@ function twentyten_init() { add_custom_image_header( '', 'twentyten_admin_header_style' ); // and thus ends the changeable header business + register_default_headers( array('berries' => array('url' => '%s/images/headers/berries.jpg', 'thumbnail_url' => '%s/images/headers/berries-thumbnail.jpg', 'description' => __('Berries')), + 'cherryblossom' => array( 'url' => '%s/images/headers/cherryblossoms.jpg', 'thumbnail_url' => '%s/images/headers/cherryblossoms-thumbnail.jpg', 'description' => __('Cherry Blossoms')), + 'concave' => array('url' => '%s/images/headers/concave.jpg', 'thumbnail_url' => '%s/images/headers/concave-thumbnail.jpg', 'description' => __('Concave')), + 'fern' => array('url' => '%s/images/headers/fern.jpg', 'thumbnail_url' => '%s/images/headers/fern-thumbnail.jpg', 'description' => __('Fern')), + 'forestfloor' => array('url' => '%s/images/headers/forestfloor.jpg', 'thumbnail_url' => '%s/images/headers/forestfloor-thumbnail.jpg', 'description' => __('Forest Floor')), + 'inkwell' => array('url' => '%s/images/headers/inkwell.jpg', 'thumbnail_url' => '%s/images/headers/inkwell-thumbnail.jpg', 'description' => __('Ink Well')), + 'path' => array('url' => '%s/images/headers/path.jpg', 'thumbnail_url' => '%s/images/headers/path-thumbnail.jpg', 'description' => __('Path')), + 'sunset' => array('url' => '%s/images/headers/sunset.jpg', 'thumbnail_url' => '%s/images/headers/sunset-thumbnail.jpg', 'description' => __('Sunset')) ) ); + add_custom_background(); // This theme needs post thumbnails diff --git a/wp-includes/theme.php b/wp-includes/theme.php index ba4dd17fd..2ac97c443 100644 --- a/wp-includes/theme.php +++ b/wp-includes/theme.php @@ -1334,6 +1334,19 @@ function add_custom_image_header($header_callback, $admin_header_callback, $admi add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init')); } +/** + * Register a selection of default headers to be displayed by the custom header admin UI. + * + * @since 3.0.0 + * + * @param array $headers Array of headers keyed by a string id. The ids point to arrays containing 'url', 'thumbnail_url', and 'description' keys. + */ +function register_default_headers( $headers ) { + global $_wp_default_headers; + + $_wp_default_headers = $headers; +} + /** * Retrieve background image for custom background. *