Make WordPress Core

Ticket #13231: refactoring_custom_header.9.patch

File refactoring_custom_header.9.patch, 25.1 KB (added by ocean90, 15 years ago)
  • wp-admin/css/wp-admin.dev.css

     
    37043704}
    37053705
    37063706/* Custom Header */
     3707.appearance_page_custom-header #headimg {
     3708        position: relative;
     3709}
    37073710
    3708 table#available-headers td {
    3709         padding: 0 20px 10px 0;
     3711.appearance_page_custom-header #headimg img {
     3712        width: 100%;
     3713
    37103714}
    3711 table#available-headers label input {
    3712         margin-right: 8px;
     3715
     3716.appearance_page_custom-header #headimg h1 {
     3717        font-family: 'Trebuchet MS', 'Lucida Grande', Verdana,Arial, Sans-Serif;
     3718        font-size: 18px;
     3719        font-weight: bold;
     3720        position: absolute;
     3721        text-align: center;
     3722        width: 100%;
    37133723}
    3714 table#available-headers label img {
     3724
     3725.appearance_page_custom-header #headimg #desc {
     3726        font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif;
     3727        font-size: 10px;
     3728        text-align: center;
     3729        position: absolute;
     3730        width: 100%;
     3731        padding-top: 30px;
     3732}
     3733
     3734.appearance_page_custom-header #upload-form p label {
     3735        font-size: 11px;
     3736}
     3737
     3738.appearance_page_custom-header  #available-headers .default-header {
     3739        float: left;
     3740        margin: 0 20px 20px 0;
     3741}
     3742
     3743.appearance_page_custom-header #available-headers label input {
     3744        margin-right: 10px;
     3745}
     3746
     3747.appearance_page_custom-header #available-headers label img {
    37153748        vertical-align: middle;
    37163749}
    37173750
  • wp-admin/custom-header.php

     
    9999        function js_includes() {
    100100                $step = $this->step();
    101101
    102                 if ( 1 == $step )
     102                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
    103103                        wp_enqueue_script('farbtastic');
    104104                elseif ( 2 == $step )
    105                         wp_enqueue_script('jcrop');
     105                        wp_enqueue_script('imgareaselect');
    106106        }
    107107
    108108        /**
     
    113113        function css_includes() {
    114114                $step = $this->step();
    115115
    116                 if ( 1 == $step )
     116                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
    117117                        wp_enqueue_style('farbtastic');
    118118                elseif ( 2 == $step )
    119                         wp_enqueue_style('jcrop');
     119                        wp_enqueue_style('imgareaselect');
    120120        }
     121       
     122        /**
     123         * Check if header text is allowed
     124         *
     125         * @since 3.0.0
     126         */
     127        function header_text() {
     128                if ( defined( 'NO_HEADER_TEXT' ) && NO_HEADER_TEXT )
     129                        return false;
    121130
     131                return true;
     132        }
     133
    122134        /**
    123135         * Execute custom header modification.
    124136         *
     
    128140                if ( ! current_user_can('edit_theme_options') )
    129141                        return;
    130142
    131                 if ( isset( $_POST['textcolor'] ) ) {
    132                         check_admin_referer('custom-header');
    133                         if ( 'blank' == $_POST['textcolor'] ) {
    134                                 set_theme_mod('header_textcolor', 'blank');
     143                if ( empty( $_POST ) )
     144                        return;
     145
     146                $this->updated = true;
     147
     148                if ( isset( $_POST['resetheader'] ) ) {
     149                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     150                        remove_theme_mod( 'header_image' );
     151                        return;
     152                }
     153
     154                if ( isset( $_POST['resettext'] ) ) {
     155                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     156                        remove_theme_mod('header_textcolor');
     157                        return;
     158                }
     159
     160                if ( isset( $_POST['removeheader'] ) ) {
     161                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     162                        set_theme_mod( 'header_image', '' );
     163                        return;
     164                }
     165
     166                if ( isset( $_POST['text-color'] ) ) {
     167                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
     168                        $_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
     169                        if ( 'blank' == $_POST['text-color'] ) {
     170                                set_theme_mod( 'header_textcolor', 'blank' );
    135171                        } else {
    136                                 $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['textcolor']);
     172                                $color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
    137173                                if ( strlen($color) == 6 || strlen($color) == 3 )
    138174                                        set_theme_mod('header_textcolor', $color);
    139175                        }
    140176                }
    141177
    142                 if ( isset($_POST['resetheader']) ) {
    143                         check_admin_referer('custom-header');
    144                         remove_theme_mods();
    145                 }
    146 
    147178                if ( isset($_POST['default-header']) ) {
    148                         check_admin_referer('custom-header');
     179                        check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
    149180                        $this->process_default_headers();
    150181                        if ( isset($this->default_headers[$_POST['default-header']]) )
    151182                                set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));
     
    179210         * @since 3.0.0
    180211         */
    181212        function show_default_header_selector() {
    182                 echo '<table id="available-headers" cellspacing="0" cellpadding="0">';
    183 
    184                 $headers = array_keys($this->default_headers);
    185                 $table = array();
    186                 $rows = ceil(count($headers) / 3);
    187                 for ( $row = 1; $row <= $rows; $row++ ) {
    188                         for ( $col = 1; $col <= 3; $col++ ) {
    189                                 $table[$row][$col] = array_shift($headers);
    190                         }
     213                echo '<div id="available-headers">';
     214                foreach ( $this->default_headers as $header_key => $header ) {
     215                        $header_thumbnail = $header['thumbnail_url'];
     216                        $header_url = $header['url'];
     217                        $header_desc = $header['description'];
     218                        echo '<div class="default-header">';
     219                        echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' />';
     220                        echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /></label>';
     221                        echo '</div>';
    191222                }
    192 
    193                 foreach ( $table as $row => $cols ) {
    194                         echo '<tr>';
    195                         foreach ( $cols as $col => $header_key ) {
    196                                 if ( !$header_key )
    197                                         continue;
    198                                 $class = array('available-header');
    199                                 if ( $row == 1 ) $class[] = 'top';
    200                                 if ( $col == 1 ) $class[] = 'left';
    201                                 if ( $row == $rows ) $class[] = 'bottom';
    202                                 if ( $col == 3 ) $class[] = 'right';
    203                                 if ( !isset($this->headers[$header_key]))
    204                                 echo '<td class="' . join(' ', $class) . '">';
    205                                 $header_thumbnail = $this->default_headers[$header_key]['thumbnail_url'];
    206                                 $header_url = $this->default_headers[$header_key]['url'];
    207                                 $header_desc = $this->default_headers[$header_key]['description'];
    208                                 echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_header_image(), false) . ' />';
    209                                 echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" /></label>';
    210                                 echo  '</td>';
    211                         }
    212                         echo '</tr>';
    213                 }
    214                 echo '</table>';
     223                echo '<div class="clear"></div></div>';
    215224        }
    216225
    217226        /**
     
    221230         */
    222231        function js() {
    223232                $step = $this->step();
    224                 if ( 1 == $step )
     233                if ( ( 1 == $step || 3 == $step ) && $this->header_text() )
    225234                        $this->js_1();
    226235                elseif ( 2 == $step )
    227236                        $this->js_2();
    228237        }
    229238
    230239        /**
    231          * Display Javascript based on Step 1.
     240         * Display Javascript based on Step 1 and 3.
    232241         *
    233242         * @since 2.6.0
    234243         */
    235244        function js_1() { ?>
    236245<script type="text/javascript">
    237         var buttons = ['#name', '#desc', '#pickcolor', '#defaultcolor'];
     246/* <![CDATA[ */
     247        var text_objects = ['#name', '#desc', '#text-color-row'];
    238248        var farbtastic;
     249        var default_color = '#<?php echo HEADER_TEXTCOLOR; ?>';
     250        var old_color = null;
    239251
    240252        function pickColor(color) {
    241253                jQuery('#name').css('color', color);
    242254                jQuery('#desc').css('color', color);
    243                 jQuery('#textcolor').val(color);
     255                jQuery('#text-color').val(color);
    244256                farbtastic.setColor(color);
    245257        }
    246258
     259        function toggle_text(s) {
     260                if (jQuery(s).attr('id') == 'showtext' && jQuery('#text-color').val() != 'blank')
     261                        return;
     262
     263                if (jQuery(s).attr('id') == 'hidetext' && jQuery('#text-color').val() == 'blank')
     264                        return;
     265
     266                if (jQuery('#text-color').val() == 'blank') {
     267                        //Show text
     268                        if (old_color == '#blank')
     269                                old_color = default_color;
     270
     271                        jQuery( text_objects.toString() ).show();
     272                        jQuery('#text-color').val(old_color);
     273                        jQuery('#name').css('color', old_color);
     274                        jQuery('#desc').css('color', old_color);
     275                        pickColor(old_color);
     276                } else {
     277                        //Hide text
     278                        jQuery( text_objects.toString() ).hide();
     279                        old_color = jQuery('#text-color').val();
     280                        jQuery('#text-color').val('blank');
     281                }
     282        }
     283
    247284        jQuery(document).ready(function() {
    248285                jQuery('#pickcolor').click(function() {
    249                         jQuery('#colorPickerDiv').show();
     286                        jQuery('#color-picker').show();
    250287                });
    251288
    252                 jQuery('#hidetext').click(function() {
    253                         toggle_text();
     289                jQuery('input[name="hidetext"]').click(function() {
     290                        toggle_text(this);
    254291                });
    255292
    256                 farbtastic = jQuery.farbtastic('#colorPickerDiv', function(color) { pickColor(color); });
     293                jQuery('#defaultcolor').click(function() {
     294                        pickColor(default_color);
     295                        jQuery('#text-color').val(default_color)
     296                });
     297
     298                jQuery('#text-color').keyup(function() {
     299                        var _hex = jQuery('#text-color').val();
     300                        var hex = _hex;
     301                        if ( hex[0] != '#' )
     302                                hex = '#' + hex;
     303                        hex = hex.replace(/[^#a-fA-F0-9]+/, '');
     304                        if ( hex != _hex )
     305                                jQuery('#text-color').val(hex);
     306                        if ( hex.length == 4 || hex.length == 7 )
     307                                pickColor( hex );
     308                });
     309
     310                jQuery(document).mousedown(function(){
     311                        jQuery('#color-picker').each( function() {
     312                                var display = jQuery(this).css('display');
     313                                if (display == 'block')
     314                                        jQuery(this).fadeOut(2);
     315                        });
     316                });
     317
     318                farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); });
    257319                pickColor('#<?php echo get_theme_mod('header_textcolor', HEADER_TEXTCOLOR); ?>');
    258320
    259                 <?php if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) ) { ?>
     321                <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) { ?>
    260322                toggle_text();
    261323                <?php } ?>
    262         });
    263 
    264         jQuery(document).mousedown(function(){
    265                 // Make the picker disappear, since we're using it in an independant div
    266                 hide_picker();
    267         });
    268 
    269         function colorDefault() {
    270                 pickColor('#<?php echo HEADER_TEXTCOLOR; ?>');
    271         }
    272 
    273         function hide_picker(what) {
    274                 var update = false;
    275                 jQuery('#colorPickerDiv').each(function(){
    276                         var id = jQuery(this).attr('id');
    277                         if (id == what) {
    278                                 return;
    279                         }
    280                         var display = jQuery(this).css('display');
    281                         if (display == 'block') {
    282                                 jQuery(this).fadeOut(2);
    283                         }
    284324                });
    285         }
    286 
    287         function toggle_text(force) {
    288                 if (jQuery('#textcolor').val() == 'blank') {
    289                         //Show text
    290                         jQuery( buttons.toString() ).show();
    291                         jQuery('#textcolor').val('<?php echo HEADER_TEXTCOLOR; ?>');
    292                         jQuery('#hidetext').val('<?php _e('Hide Text'); ?>');
    293                 }
    294                 else {
    295                         //Hide text
    296                         jQuery( buttons.toString() ).hide();
    297                         jQuery('#textcolor').val('blank');
    298                         jQuery('#hidetext').val('<?php _e('Show Text'); ?>');
    299                 }
    300         }
    301 
    302 
    303 
    304325</script>
    305326<?php
    306327        }
     
    312333         */
    313334        function js_2() { ?>
    314335<script type="text/javascript">
     336/* <![CDATA[ */
    315337        function onEndCrop( coords ) {
    316338                jQuery( '#x1' ).val(coords.x);
    317339                jQuery( '#y1' ).val(coords.y);
    318                 jQuery( '#x2' ).val(coords.x2);
    319                 jQuery( '#y2' ).val(coords.y2);
    320340                jQuery( '#width' ).val(coords.w);
    321341                jQuery( '#height' ).val(coords.h);
    322342        }
    323343
    324         // with a supplied ratio
    325344        jQuery(document).ready(function() {
    326345                var xinit = <?php echo HEADER_IMAGE_WIDTH; ?>;
    327346                var yinit = <?php echo HEADER_IMAGE_HEIGHT; ?>;
    328                 var ratio = xinit / yinit;
     347                var ratio = xinit +  ':' + yinit;
    329348                var ximg = jQuery('#upload').width();
    330349                var yimg = jQuery('#upload').height();
    331350
    332                 //set up default values
    333                 jQuery( '#x1' ).val(0);
    334                 jQuery( '#y1' ).val(0);
    335                 jQuery( '#x2' ).val(xinit);
    336                 jQuery( '#y2' ).val(yinit);
    337                 jQuery( '#width' ).val(xinit);
    338                 jQuery( '#height' ).val(yinit);
    339 
    340                 if ( yimg < yinit || ximg < xinit ) {
    341                         if ( ximg / yimg > ratio ) {
    342                                 yinit = yimg;
    343                                 xinit = yinit * ratio;
    344                         } else {
    345                                 xinit = ximg;
    346                                 yinit = xinit / ratio;
    347                         }
    348                 }
    349 
    350                 jQuery('#upload').Jcrop({
     351                jQuery('#upload').imgAreaSelect({
     352                        handles: true,
     353                        keys: true,
    351354                        aspectRatio: ratio,
    352                         setSelect: [ 0, 0, xinit, yinit ],
    353                         onSelect: onEndCrop
     355                        maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>,
     356                        maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>,
     357                        onSelectChange: function(img, c) {
     358                                jQuery('#x1').val(c.x1);
     359                                jQuery('#y1').val(c.y1);
     360                                jQuery('#width').val(c.width);
     361                                jQuery('#height').val(c.height);
     362                        },
    354363                });
    355364        });
     365/* ]]> */
    356366</script>
    357367<?php
    358368        }
     
    364374         */
    365375        function step_1() {
    366376                $this->process_default_headers();
    367  ?>
     377?>
    368378
    369379<div class="wrap">
    370380<?php screen_icon(); ?>
    371 <h2><?php _e('Your Header Image'); ?></h2>
     381<h2><?php _e('Custom Header'); ?></h2>
    372382
    373 <?php
    374 if ( isset($_GET['updated']) && $_GET['updated'] ) { ?>
     383<?php if ( ! empty( $this->updated ) ) { ?>
    375384<div id="message" class="updated">
    376385<p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
    377386</div>
    378 <?php }
     387<?php } ?>
    379388
    380 if ( get_theme_mod('header_image') || empty($this->default_headers) ) :
    381 ?>
    382 <p><?php _e('This is your header image. You can change the text color or upload and crop a new image.'); ?></p>
    383 <?php
     389<h3><?php _e( 'Header Image' ) ?></h3>
     390<table class="form-table">
     391<tbody>
    384392
    385 if ( $this->admin_image_div_callback ) {
    386   call_user_func($this->admin_image_div_callback);
    387 } else {
    388 ?>
    389 <div id="headimg" style="background-image: url(<?php esc_url(header_image()) ?>);">
    390 <h1><a onclick="return false;" href="<?php bloginfo('url'); ?>" title="<?php bloginfo('name'); ?>" id="name"><?php bloginfo('name'); ?></a></h1>
    391 <div id="desc"><?php bloginfo('description');?></div>
    392 </div>
    393 <?php } ?>
     393        <?php if ( get_header_image() ) : ?>
     394<tr valign="top">
     395<th scope="row"><?php _e( 'Current Header' ); ?></th>
     396<td >
     397        <?php if ( $this->admin_image_div_callback ) {
     398          call_user_func( $this->admin_image_div_callback );
     399        } else {
     400        ?>
     401        <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;">
     402                <?php
     403                if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() )
     404                        $style = ' style="display:none;"';
     405                else
     406                        $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"';
     407                ?>
     408                <h1 id="name"<?php echo $style; ?>><?php bloginfo( 'name' ); ?></h1>
     409                <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
     410                <img id="image" src="<?php esc_url ( header_image() ) ?>" alt="" />
     411        </div>
     412        <?php } ?>
     413</td>
     414</tr>
     415        <?php endif; ?>
    394416
    395 <?php if ( !defined( 'NO_HEADER_TEXT' ) ) { ?>
    396 <form method="post" action="<?php echo admin_url('themes.php?page=custom-header&amp;updated=true') ?>">
    397 <input type="button" class="button" value="<?php esc_attr_e('Hide Text'); ?>" onclick="hide_text()" id="hidetext" />
    398 <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" />
    399 <?php wp_nonce_field('custom-header'); ?>
    400 <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>
    401 <?php } ?>
     417<tr valign="top">
     418<th scope="row"><?php _e( 'Upload Image' ); ?></th>
     419<td>
     420        <p><?php _e( 'Here you can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.' ); ?><br />
     421        <?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>
     422        <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
     423        <p>
     424                <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
     425                <input type="file" id="upload" name="import" />
     426                <input type="hidden" name="action" value="save" />
     427                <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?>
     428                <input type="submit" class="button" value="<?php esc_attr_e( 'Upload' ); ?>" />
     429        </p>
     430        </form>
     431</td>
     432</tr>
     433</tbody>
     434</table>
    402435
    403 <div id="colorPickerDiv" style="z-index: 100;background:#eee;border:1px solid #ccc;position:absolute;display:none;"> </div>
    404 </div>
    405 <?php
    406 else:
    407         echo '<p>' . __('Choose one of these cool headers, or upload your own image below.') . '</p>';
    408         echo '<form method="post" action="' . admin_url('themes.php?page=custom-header&amp;updated=true') . '">';
    409         wp_nonce_field('custom-header');
    410         $this->show_default_header_selector();
    411         echo '<input type="submit" class="button" value="' . esc_attr__('Save Changes') . '"  />';
    412         echo '</form>';
    413         echo '</div>';
    414 endif;
    415 ?>
    416 <div class="wrap">
    417 <h3><?php _e('Upload New Header Image'); ?></h3><p><?php _e('Here you can upload a custom header image to be shown at the top of your site instead of the default one. On the next screen you will be able to crop the image.'); ?> <?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>
     436<form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?>">
     437<table class="form-table">
     438<tbody>
     439        <?php if ( ! empty( $this->default_headers ) ) : ?>
     440<tr valign="top">
     441<th scope="row"><?php _e( 'Default Images' ); ?></th>
     442<td>
     443        <p><?php _e( 'If you didn&lsquo;t want to upload your own image, you can use one of these cool headers.' ) ?></p>
     444        <?php
     445                $this->show_default_header_selector();
     446        ?>
     447</td>
     448</tr>
     449        <?php endif;
    418450
    419 <form enctype="multipart/form-data" id="uploadForm" method="post" action="<?php echo esc_attr(add_query_arg('step', 2)) ?>">
    420 <label for="upload"><?php _e('Choose an image from your computer:'); ?></label><br /><input type="file" id="upload" name="import" />
    421 <input type="hidden" name="action" value="save" />
    422 <?php wp_nonce_field('custom-header') ?>
    423 <p class="submit">
    424 <input type="submit" value="<?php esc_attr_e('Upload'); ?>" />
    425 </p>
    426 </form>
     451        if ( get_header_image() ) : ?>
     452<tr valign="top">
     453<th scope="row"><?php _e( 'Remove Image' ); ?></th>
     454<td>
     455        <p><?php _e( 'This will remove the header image. You will not be able to retrieve any customizations.' ) ?></p>
     456        <input type="submit" class="button" name="removeheader" value="<?php esc_attr_e( 'Remove Header Image' ); ?>" />
     457</td>
     458</tr>
     459        <?php endif;
    427460
    428 </div>
     461        if ( defined( 'HEADER_IMAGE' ) ) : ?>
     462<tr valign="top">
     463<th scope="row"><?php _e( 'Reset Image' ); ?></th>
     464<td>
     465        <p><?php _e( 'This will restore the original header image. You will not be able to retrieve any customizations.' ) ?></p>
     466        <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e( 'Restore Original Header Image' ); ?>" />
     467</td>
     468</tr>
     469        <?php endif; ?>
     470</tbody>
     471</table>
    429472
    430                 <?php if ( get_theme_mod('header_image') || get_theme_mod('header_textcolor') ) : ?>
    431 <div class="wrap">
    432 <h3><?php _e('Reset Header Image and Color'); ?></h3>
    433 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 1)) ?>">
    434 <?php
    435 wp_nonce_field('custom-header');
    436 if ( !empty($this->default_headers) ) {
    437 ?>
    438 <p><?php _e('Use one of these cool headers.') ?></p>
    439 <?php
    440         $this->show_default_header_selector();
    441 ?>
    442         <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e('Save Changes'); ?>" />
    443 <?php
    444 } else {
    445 ?>
    446 <p><?php _e('This will restore the original header image and color. You will not be able to retrieve any customizations.') ?></p>
    447 <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e('Restore Original Header'); ?>" />
    448 <?php } ?>
     473        <?php if ( $this->header_text() ) : ?>
     474<h3><?php _e( 'Header Text' ) ?></h3>
     475<table class="form-table">
     476<tbody>
     477<tr valign="top" class="hide-if-no-js">
     478<th scope="row"><?php _e( 'Display Text' ); ?></th>
     479<td>
     480        <p>
     481        <?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?>
     482        <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) )  ? true : false ); ?> /> <?php _e( 'No' ); ?></label>
     483        <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label>
     484        </p>
     485</td>
     486</tr>
     487
     488<tr valign="top" id="text-color-row">
     489<th scope="row"><?php _e( 'Text Color' ); ?></th>
     490<td>
     491        <p>
     492                <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ); ?>" />
     493                <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span>
     494                <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" />
     495        </p>
     496        <div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
     497</td>
     498</tr>
     499
     500        <?php if ( defined('HEADER_TEXTCOLOR') && get_theme_mod('header_textcolor') ) { ?>
     501<tr valign="top">
     502<th scope="row"><?php _e('Reset Text Color'); ?></th>
     503<td>
     504        <p><?php _e( 'This will restore the original header text color. You will not be able to retrieve any customizations.' ) ?></p>
     505        <input type="submit" class="button" name="resettext" value="<?php esc_attr_e( 'Restore Original Header Text Color' ); ?>" />
     506</td>
     507</tr>
     508        <?php } ?>
     509
     510</tbody>
     511</table>
     512        <?php endif;
     513
     514wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
     515<p class="submit"><input type="submit" class="button-primary" name="save-header-options" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p>
    449516</form>
    450517</div>
    451                 <?php endif;
    452518
    453         }
     519<?php }
    454520
    455521        /**
    456522         * Display second step of custom header image page.
     
    458524         * @since 2.1.0
    459525         */
    460526        function step_2() {
    461                 check_admin_referer('custom-header');
    462                 $overrides = array('test_form' => false);
    463                 $file = wp_handle_upload($_FILES['import'], $overrides);
     527                check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' );
     528                $overrides = array( 'test_form' => false );
     529                $file = wp_handle_upload( $_FILES['import'], $overrides );
    464530
    465531                if ( isset($file['error']) )
    466                 die( $file['error'] );
     532                        wp_die( $file['error'],  __( 'Image Upload Error' ) );
    467533
    468534                $url = $file['url'];
    469535                $type = $file['type'];
     
    506572                ?>
    507573
    508574<div class="wrap">
     575<?php screen_icon(); ?>
     576<h2><?php _e( 'Crop Header Image' ); ?></h2>
    509577
    510 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 3)) ?>">
     578<form method="post" action="<?php echo esc_attr(add_query_arg('step', 3)); ?>">
     579        <p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
     580        <p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.'); ?></strong></p>
    511581
    512 <p><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
    513 <div id="testWrap" style="position: relative">
    514 <img src="<?php echo $url; ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
    515 </div>
     582        <div id="crop_image" style="position: relative">
     583                <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
     584        </div>
    516585
    517 <p class="submit">
    518 <input type="hidden" name="x1" id="x1" />
    519 <input type="hidden" name="y1" id="y1" />
    520 <input type="hidden" name="x2" id="x2" />
    521 <input type="hidden" name="y2" id="y2" />
    522 <input type="hidden" name="width" id="width" />
    523 <input type="hidden" name="height" id="height" />
    524 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr($id); ?>" />
    525 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr($oitar); ?>" />
    526 <?php wp_nonce_field('custom-header') ?>
    527 <input type="submit" value="<?php esc_attr_e('Crop Header'); ?>" />
    528 </p>
    529 
     586        <p class="submit">
     587        <input type="hidden" name="x1" id="x1" value="0"/>
     588        <input type="hidden" name="y1" id="y1" value="0"/>
     589        <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
     590        <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/>
     591        <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" />
     592        <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
     593        <?php wp_nonce_field( 'custom-header-crop-image' ) ?>
     594        <input type="submit" value="<?php esc_attr_e( 'Crop Header' ); ?>" />
     595        </p>
    530596</form>
    531597</div>
    532598                <?php
     
    538604         * @since 2.1.0
    539605         */
    540606        function step_3() {
    541                 check_admin_referer('custom-header');
     607                check_admin_referer('custom-header-crop-image');
    542608                if ( $_POST['oitar'] > 1 ) {
    543609                        $_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
    544610                        $_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
     
    587653         * @since 2.1.0
    588654         */
    589655        function finished() {
    590                 $_GET['updated'] = 1;
    591           $this->step_1();
     656                $this->updated = true;
     657                $this->step_1();
    592658        }
    593659
    594660        /**
  • wp-content/themes/twentyten/functions.php

     
    188188function twentyten_admin_header_style() {
    189189?>
    190190<style type="text/css">
    191 #headimg {
    192         height: <?php echo HEADER_IMAGE_HEIGHT; ?>px;
    193         width: <?php echo HEADER_IMAGE_WIDTH; ?>px;
     191/* Shows the same border as on front page */
     192.appearance_page_custom-header #headimg {
     193        border-bottom: 1px solid #000000;
     194        border-top: 4px solid #000000;
    194195}
    195 #headimg h1, #headimg #desc {
    196         display: none;
    197 }
    198196</style>
    199197<?php
    200198}