Created
November 28, 2010 00:08
-
-
Save mikeschinkel/718414 to your computer and use it in GitHub Desktop.
Alternate approach to removing custom image header upload in WP 3.0.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This approach is what Andrew Nacin suggested[1] instead of [2] and requested via email by Steve Wolfson. | |
* Given it's complexity I can't advise te use of [1] and still recomment [2]. See also: [3][4]. | |
* | |
* Author: Mike Schinkel (http://mikeschinkel.com) | |
* | |
* [1] http://lists.automattic.com/pipermail/wp-hackers/2010-November/036172.html | |
* [2] http://lists.automattic.com/pipermail/wp-hackers/2010-November/036170.html | |
* [3] https://gist.github.com/717514 | |
* [4] https://gist.github.com/717515 | |
* | |
*/ | |
require_once(ABSPATH . "wp-admin/custom-header.php"); | |
class Yoursite_Image_Header extends Custom_Image_Header { | |
function __construct($admin_header_callback,$admin_image_div_callback) { | |
parent::__construct($admin_header_callback,$admin_image_div_callback); | |
} | |
static function on_load() { | |
add_action('after_setup_theme',array(__CLASS__,'action_after_setup_theme'),11); | |
} | |
static function action_after_setup_theme() { | |
$custom_image_header = $GLOBALS['custom_image_header']; | |
remove_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init')); | |
$GLOBALS['custom_image_header'] =& new Yoursite_Image_Header( | |
$custom_image_header->admin_header_callback, | |
$custom_image_header->admin_image_div_callback | |
); | |
add_action('admin_menu', array(&$GLOBALS['custom_image_header'], 'init')); | |
} | |
function step_1() { | |
$this->process_default_headers(); | |
?> | |
<div class="wrap"> | |
<?php screen_icon(); ?> | |
<h2><?php _e('Custom Header'); ?></h2> | |
<?php if ( ! empty( $this->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> | |
</div> | |
<?php } ?> | |
<h3><?php _e( 'Header Image' ) ?></h3> | |
<table class="form-table"> | |
<tbody> | |
<tr valign="top"> | |
<th scope="row"><?php _e( 'Preview' ); ?></th> | |
<td > | |
<?php if ( $this->admin_image_div_callback ) { | |
call_user_func( $this->admin_image_div_callback ); | |
} else { | |
?> | |
<div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;height:<?php echo HEADER_IMAGE_HEIGHT; ?>px;background-image:url(<?php esc_url ( header_image() ) ?>);"> | |
<?php | |
if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) | |
$style = ' style="display:none;"'; | |
else | |
$style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; | |
?> | |
<h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1> | |
<div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> | |
</div> | |
<?php } ?> | |
</td> | |
</tr> | |
</tbody> | |
</table> | |
<form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?>"> | |
<table class="form-table"> | |
<tbody> | |
<?php if ( ! empty( $this->default_headers ) ) : ?> | |
<tr valign="top"> | |
<th scope="row"><?php _e( 'Default Images' ); ?></th> | |
<td> | |
<?php | |
$this->show_default_header_selector(); | |
?> | |
</td> | |
</tr> | |
<?php endif; | |
if ( get_header_image() ) : ?> | |
<tr valign="top"> | |
<th scope="row"><?php _e( 'Remove Image' ); ?></th> | |
<td> | |
<p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?></p> | |
<input type="submit" class="button" name="removeheader" value="<?php esc_attr_e( 'Remove Header Image' ); ?>" /> | |
</td> | |
</tr> | |
<?php endif; | |
if ( defined( 'HEADER_IMAGE' ) ) : ?> | |
<tr valign="top"> | |
<th scope="row"><?php _e( 'Reset Image' ); ?></th> | |
<td> | |
<p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></p> | |
<input type="submit" class="button" name="resetheader" value="<?php esc_attr_e( 'Restore Original Header Image' ); ?>" /> | |
</td> | |
</tr> | |
<?php endif; ?> | |
</tbody> | |
</table> | |
<?php if ( $this->header_text() ) : ?> | |
<h3><?php _e( 'Header Text' ) ?></h3> | |
<table class="form-table"> | |
<tbody> | |
<tr valign="top" class="hide-if-no-js"> | |
<th scope="row"><?php _e( 'Display Text' ); ?></th> | |
<td> | |
<p> | |
<?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?> | |
<label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? true : false ); ?> /> <?php _e( 'No' ); ?></label> | |
<label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label> | |
</p> | |
</td> | |
</tr> | |
<tr valign="top" id="text-color-row"> | |
<th scope="row"><?php _e( 'Text Color' ); ?></th> | |
<td> | |
<p> | |
<input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ); ?>" /> | |
<span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span> | |
<input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" /> | |
</p> | |
<div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> | |
</td> | |
</tr> | |
<?php if ( defined('HEADER_TEXTCOLOR') && get_theme_mod('header_textcolor') ) { ?> | |
<tr valign="top"> | |
<th scope="row"><?php _e('Reset Text Color'); ?></th> | |
<td> | |
<p><?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?></p> | |
<input type="submit" class="button" name="resettext" value="<?php esc_attr_e( 'Restore Original Header Text' ); ?>" /> | |
</td> | |
</tr> | |
<?php } ?> | |
</tbody> | |
</table> | |
<?php endif; | |
wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> | |
<p class="submit"><input type="submit" class="button-primary" name="save-header-options" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p> | |
</form> | |
</div> | |
<?php | |
} | |
} | |
Yoursite_Image_Header::on_load(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment