Send user back to main custom header page after cropping and setting image. Add support for a custom image div callback for greather theme flexibility. Props dphiffer. see #11855

git-svn-id: https://develop.svn.wordpress.org/trunk@12890 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2010-01-28 19:00:16 +00:00
parent 22e8867c67
commit 93fc30b2a0
2 changed files with 27 additions and 14 deletions

View File

@ -24,15 +24,26 @@ class Custom_Image_Header {
*/ */
var $admin_header_callback; var $admin_header_callback;
/**
* Callback for header div.
*
* @var callback
* @since unknown
* @access private
*/
var $admin_image_div_callback;
/** /**
* PHP4 Constructor - Register administration header callback. * PHP4 Constructor - Register administration header callback.
* *
* @since unknown * @since unknown
* @param callback $admin_header_callback * @param callback $admin_header_callback
* @param callback $admin_image_div_callback Optional custom image div output callback.
* @return Custom_Image_Header * @return Custom_Image_Header
*/ */
function Custom_Image_Header($admin_header_callback) { function Custom_Image_Header($admin_header_callback, $admin_image_div_callback = '') {
$this->admin_header_callback = $admin_header_callback; $this->admin_header_callback = $admin_header_callback;
$this->admin_image_div_callback = $admin_image_div_callback;
} }
/** /**
@ -267,9 +278,9 @@ class Custom_Image_Header {
* @since unknown * @since unknown
*/ */
function step_1() { function step_1() {
if ( $_GET['updated'] ) { ?> if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
<div id="message" class="updated"> <div id="message" class="updated">
<p><?php _e('Header updated.') ?></p> <p><?php printf(__('Header updated. <a href="%s">Visit your site</a> to see how it looks.'), home_url()); ?></p>
</div> </div>
<?php } ?> <?php } ?>
@ -277,11 +288,18 @@ class Custom_Image_Header {
<?php screen_icon(); ?> <?php screen_icon(); ?>
<h2><?php _e('Your Header Image'); ?></h2> <h2><?php _e('Your Header Image'); ?></h2>
<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
if ( $this->admin_image_div_callback ) {
call_user_func($this->admin_image_div_callback);
} else {
?>
<div id="headimg" style="background-image: url(<?php esc_url(header_image()) ?>);"> <div id="headimg" style="background-image: url(<?php esc_url(header_image()) ?>);">
<h1><a onclick="return false;" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" id="name"><?php bloginfo('name'); ?></a></h1> <h1><a onclick="return false;" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" id="name"><?php bloginfo('name'); ?></a></h1>
<div id="desc"><?php bloginfo('description');?></div> <div id="desc"><?php bloginfo('description');?></div>
</div> </div>
<?php } ?>
<?php if ( !defined( 'NO_HEADER_TEXT' ) ) { ?> <?php if ( !defined( 'NO_HEADER_TEXT' ) ) { ?>
<form method="post" action="<?php echo admin_url('themes.php?page=custom-header&amp;updated=true') ?>"> <form method="post" action="<?php echo admin_url('themes.php?page=custom-header&amp;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" />
@ -455,14 +473,8 @@ class Custom_Image_Header {
* @since unknown * @since unknown
*/ */
function finished() { function finished() {
?> $_GET['updated'] = 1;
<div class="wrap"> $this->step_1();
<h2><?php _e('Header complete!'); ?></h2>
<p><?php _e('Visit your site and you should see the new header now.'); ?></p>
</div>
<?php
} }
/** /**

View File

@ -1298,16 +1298,17 @@ function header_image() {
* @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display. * @uses Custom_Image_Header Sets up for $admin_header_callback for administration panel display.
* *
* @param callback $header_callback Call on 'wp_head' action. * @param callback $header_callback Call on 'wp_head' action.
* @param callback $admin_header_callback Call on administration panels. * @param callback $admin_header_callback Call on custom header administration screen.
* @param callback $admin_image_div_callback Output a custom header image div on the custom header administration screen. Optional.
*/ */
function add_custom_image_header($header_callback, $admin_header_callback) { function add_custom_image_header($header_callback, $admin_header_callback, $admin_image_div_callback = '') {
if ( ! empty($header_callback) ) if ( ! empty($header_callback) )
add_action('wp_head', $header_callback); add_action('wp_head', $header_callback);
if ( ! is_admin() ) if ( ! is_admin() )
return; return;
require_once(ABSPATH . 'wp-admin/custom-header.php'); require_once(ABSPATH . 'wp-admin/custom-header.php');
$GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback); $GLOBALS['custom_image_header'] =& new Custom_Image_Header($admin_header_callback, $admin_image_div_callback);
add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init')); add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init'));
} }