Default header selector, first pass. see #12343
git-svn-id: http://svn.automattic.com/wordpress/trunk@13403 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
e8503ab54a
commit
a8a6d742e1
|
@ -33,6 +33,8 @@ class Custom_Image_Header {
|
||||||
*/
|
*/
|
||||||
var $admin_image_div_callback;
|
var $admin_image_div_callback;
|
||||||
|
|
||||||
|
var $default_headers = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP4 Constructor - Register administration header callback.
|
* PHP4 Constructor - Register administration header callback.
|
||||||
*
|
*
|
||||||
|
@ -133,6 +135,74 @@ class Custom_Image_Header {
|
||||||
check_admin_referer('custom-header');
|
check_admin_referer('custom-header');
|
||||||
remove_theme_mods();
|
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 '<table id="available-headers" cellspacing="0" cellpadding="0">';
|
||||||
|
|
||||||
|
$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 '<tr>';
|
||||||
|
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 '<td class="' . join(' ', $class) . '">';
|
||||||
|
$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 '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_header_image(), false) . ' />';
|
||||||
|
echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" /></label>';
|
||||||
|
echo '</td>';
|
||||||
|
}
|
||||||
|
echo '</tr>';
|
||||||
|
}
|
||||||
|
echo '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -284,6 +354,7 @@ class Custom_Image_Header {
|
||||||
* @since unknown
|
* @since unknown
|
||||||
*/
|
*/
|
||||||
function step_1() {
|
function step_1() {
|
||||||
|
$this->process_default_headers();
|
||||||
if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
|
if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
|
||||||
<div id="message" class="updated">
|
<div id="message" class="updated">
|
||||||
<p><?php printf(__('Header updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p>
|
<p><?php printf(__('Header updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p>
|
||||||
|
@ -293,6 +364,9 @@ class Custom_Image_Header {
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<?php screen_icon(); ?>
|
<?php screen_icon(); ?>
|
||||||
<h2><?php _e('Your Header Image'); ?></h2>
|
<h2><?php _e('Your Header Image'); ?></h2>
|
||||||
|
<?php
|
||||||
|
if ( get_theme_mod('header_image') || empty($this->default_headers) ) :
|
||||||
|
?>
|
||||||
<p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
|
<p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
@ -310,12 +384,23 @@ if ( $this->admin_image_div_callback ) {
|
||||||
<form method="post" action="<?php echo admin_url('themes.php?page=custom-header&updated=true') ?>">
|
<form method="post" action="<?php echo admin_url('themes.php?page=custom-header&updated=true') ?>">
|
||||||
<input type="button" class="button" value="<?php esc_attr_e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
|
<input type="button" class="button" value="<?php esc_attr_e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
|
||||||
<input type="button" class="button" value="<?php esc_attr_e('Select a Text Color'); ?>" id="pickcolor" /><input type="button" class="button" value="<?php esc_attr_e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
|
<input type="button" class="button" value="<?php esc_attr_e('Select a Text Color'); ?>" id="pickcolor" /><input type="button" class="button" value="<?php esc_attr_e('Use Original Color'); ?>" onclick="colorDefault()" id="defaultcolor" />
|
||||||
<?php wp_nonce_field('custom-header') ?>
|
<?php wp_nonce_field('custom-header'); ?>
|
||||||
<input type="hidden" name="textcolor" id="textcolor" value="#<?php esc_attr(header_textcolor()) ?>" /><input name="submit" type="submit" class="button" value="<?php esc_attr_e('Save Changes'); ?>" /></form>
|
<input type="hidden" name="textcolor" id="textcolor" value="#<?php esc_attr(header_textcolor()) ?>" /><input name="submit" type="submit" class="button" value="<?php esc_attr_e('Save Changes'); ?>" /></form>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
<div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
|
<div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
|
||||||
</div>
|
</div>
|
||||||
|
<?php
|
||||||
|
else:
|
||||||
|
echo '<p>' . __('Choose one of these cool headers, or upload your own image below.') . '</p>';
|
||||||
|
echo '<form method="post" action="' . admin_url('themes.php?page=custom-header&updated=true') . '">';
|
||||||
|
wp_nonce_field('custom-header');
|
||||||
|
$this->show_default_header_selector();
|
||||||
|
echo '<input type="submit" class="button" value="' . esc_attr__('Save Your Choice') . '" />';
|
||||||
|
echo '</form>';
|
||||||
|
echo '</div>';
|
||||||
|
endif;
|
||||||
|
?>
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<h2><?php _e('Upload New Header Image'); ?></h2><p><?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?></p>
|
<h2><?php _e('Upload New Header Image'); ?></h2><p><?php _e('Here you can upload a custom header image to be shown at the top of your blog instead of the default one. On the next screen you will be able to crop the image.'); ?></p>
|
||||||
<p><?php printf(__('Images of exactly <strong>%1$d x %2$d pixels</strong> will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?></p>
|
<p><?php printf(__('Images of exactly <strong>%1$d x %2$d pixels</strong> will be used as-is.'), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); ?></p>
|
||||||
|
|
|
@ -9,7 +9,7 @@ function twentyten_init() {
|
||||||
// Your Changeable header business starts here
|
// Your Changeable header business starts here
|
||||||
// No CSS, just IMG call
|
// No CSS, just IMG call
|
||||||
define( 'HEADER_TEXTCOLOR', '');
|
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_WIDTH', apply_filters( 'twentyten_header_image_width', 940 ) );
|
||||||
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
|
define( 'HEADER_IMAGE_HEIGHT', apply_filters( 'twentyten_header_image_height', 198 ) );
|
||||||
define( 'NO_HEADER_TEXT', true );
|
define( 'NO_HEADER_TEXT', true );
|
||||||
|
@ -17,6 +17,15 @@ function twentyten_init() {
|
||||||
add_custom_image_header( '', 'twentyten_admin_header_style' );
|
add_custom_image_header( '', 'twentyten_admin_header_style' );
|
||||||
// and thus ends the changeable header business
|
// 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();
|
add_custom_background();
|
||||||
|
|
||||||
// This theme needs post thumbnails
|
// This theme needs post thumbnails
|
||||||
|
|
|
@ -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'));
|
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.
|
* Retrieve background image for custom background.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue