diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index cc7cf12291..73f42589e4 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 '
'; + $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 ' | '; + } + echo '
Visit your site to see how it looks.'), home_url()); ?>
@@ -293,6 +364,9 @@ class Custom_Image_Header {%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 99f13a1444..f6669312c4 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 ba4dd17fda..2ac97c4430 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. *