Ticket #13231: refactoring_custom_header.7.2.patch
File refactoring_custom_header.7.2.patch, 32.2 KB (added by , 15 years ago) |
---|
-
wp-admin/css/wp-admin.dev.css
3697 3697 } 3698 3698 3699 3699 /* Custom Header */ 3700 .appearance_page_custom-header #headimg img { 3701 width: 100%; 3702 } 3700 3703 3701 table#available-headers td { 3702 padding: 0 20px 10px 0; 3704 .appearance_page_custom-header #headimg h1 { 3705 font-family: 'Trebuchet MS', 'Lucida Grande', Verdana,Arial, Sans-Serif; 3706 font-size: 18px; 3707 font-weight: bold; 3708 margin: 0; 3709 padding-top: 5%; 3710 text-align: center; 3703 3711 } 3704 table#available-headers label input { 3705 margin-right: 8px; 3712 3713 .appearance_page_custom-header #headimg #desc { 3714 font-family: 'Lucida Grande', Verdana, Arial, Sans-Serif; 3715 font-size: 10px; 3716 text-align: center; 3706 3717 } 3707 table#available-headers label img { 3718 3719 .appearance_page_custom-header #upload-form p label { 3720 font-size: 11px; 3721 } 3722 3723 .appearance_page_custom-header #available-headers .default-header { 3724 float: left; 3725 margin: 0 20px 20px 0; 3726 } 3727 3728 .appearance_page_custom-header #available-headers label input { 3729 margin-right: 10px; 3730 } 3731 3732 .appearance_page_custom-header #available-headers label img { 3708 3733 vertical-align: middle; 3709 3734 } 3710 3735 -
wp-admin/custom-header.php
50 50 * @param callback $admin_image_div_callback Optional custom image div output callback. 51 51 * @return Custom_Image_Header 52 52 */ 53 function Custom_Image_Header( $admin_header_callback, $admin_image_div_callback = '') {53 function Custom_Image_Header( $admin_header_callback, $admin_image_div_callback = '' ) { 54 54 $this->admin_header_callback = $admin_header_callback; 55 55 $this->admin_image_div_callback = $admin_image_div_callback; 56 56 } … … 61 61 * @since 2.1.0 62 62 */ 63 63 function init() { 64 if ( ! current_user_can( 'edit_theme_options') )64 if ( ! current_user_can( 'edit_theme_options' ) ) 65 65 return; 66 66 67 $page = add_theme_page( __('Header'), __('Header'), 'edit_theme_options', 'custom-header', array(&$this, 'admin_page'));67 $page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( &$this, 'admin_page' ) ); 68 68 69 add_action( "admin_print_scripts-$page", array(&$this, 'js_includes'));70 add_action( "admin_print_styles-$page", array(&$this, 'css_includes'));71 add_action( "admin_head-$page", array(&$this, 'take_action'), 50);72 add_action( "admin_head-$page", array(&$this, 'js'), 50);73 add_action( "admin_head-$page", $this->admin_header_callback, 51);69 add_action( "admin_print_scripts-$page", array( &$this, 'js_includes' ) ); 70 add_action( "admin_print_styles-$page", array( &$this, 'css_includes' ) ); 71 add_action( "admin_head-$page", array( &$this, 'take_action' ), 50); 72 add_action( "admin_head-$page", array( &$this, 'js' ), 50 ); 73 add_action( "admin_head-$page", $this->admin_header_callback, 51 ); 74 74 } 75 75 76 76 /** … … 99 99 function js_includes() { 100 100 $step = $this->step(); 101 101 102 if ( 1 == $step)103 wp_enqueue_script( 'farbtastic');102 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 103 wp_enqueue_script( 'farbtastic' ); 104 104 elseif ( 2 == $step ) 105 wp_enqueue_script( 'jcrop');105 wp_enqueue_script( 'imgareaselect' ); 106 106 } 107 107 108 108 /** … … 113 113 function css_includes() { 114 114 $step = $this->step(); 115 115 116 if ( 1 == $step)117 wp_enqueue_style( 'farbtastic');116 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 117 wp_enqueue_style( 'farbtastic' ); 118 118 elseif ( 2 == $step ) 119 wp_enqueue_style( 'jcrop');119 wp_enqueue_style( 'imgareaselect' ); 120 120 } 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; 130 131 return true; 132 } 121 133 122 134 /** 123 135 * Execute custom header modification. … … 125 137 * @since 2.6.0 126 138 */ 127 139 function take_action() { 128 if ( ! current_user_can( 'edit_theme_options') )140 if ( ! current_user_can( 'edit_theme_options' ) ) 129 141 return; 142 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 } 130 165 131 if ( isset( $_POST['textcolor'] ) ) { 132 check_admin_referer('custom-header'); 133 if ( 'blank' == $_POST['textcolor'] ) { 134 set_theme_mod('header_textcolor', 'blank'); 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' ); 135 171 } else { 136 $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['textcolor']);172 $color = preg_replace( '/[^0-9a-fA-F]/', '', $_POST['text-color'] ); 137 173 if ( strlen($color) == 6 || strlen($color) == 3 ) 138 set_theme_mod( 'header_textcolor', $color);174 set_theme_mod( 'header_textcolor', $color ); 139 175 } 140 176 } 141 177 142 if ( isset($_POST['resetheader']) ) { 143 check_admin_referer('custom-header'); 144 remove_theme_mods(); 178 if ( isset( $_POST['default-header'] ) ) { 179 check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' ); 180 $this->process_default_headers(); 181 if ( isset( $this->default_headers[$_POST['default-header']] ) ) 182 set_theme_mod( 'header_image', esc_url( $this->default_headers[$_POST['default-header']]['url'] ) ); 145 183 } 146 184 147 if ( isset($_POST['default-header']) ) {148 check_admin_referer('custom-header');149 $this->process_default_headers();150 if ( isset($this->default_headers[$_POST['default-header']]) )151 set_theme_mod('header_image', esc_url($this->default_headers[$_POST['default-header']]['url']));152 }153 185 } 154 186 155 187 /** … … 160 192 function process_default_headers() { 161 193 global $_wp_default_headers; 162 194 163 if ( ! empty($this->headers) )195 if ( ! empty( $this->headers ) ) 164 196 return; 165 197 166 if ( ! isset($_wp_default_headers) )198 if ( ! isset( $_wp_default_headers ) ) 167 199 return; 168 200 169 201 $this->default_headers = $_wp_default_headers; … … 179 211 * @since 3.0.0 180 212 */ 181 213 function show_default_header_selector() { 182 echo '< table id="available-headers" cellspacing="0" cellpadding="0">';214 echo '<div id="available-headers">'; 183 215 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 } 216 foreach ( $this->default_headers as $header_key => $header ) { 217 $header_thumbnail = $header['thumbnail_url']; 218 $header_url = $header['url']; 219 $header_desc = $header['description']; 220 echo '<div class="default-header">'; 221 echo '<label><input name="default-header" type="radio" value="' . esc_attr($header_key) . '" ' . checked($header_url, get_theme_mod( 'header_image' ), false) . ' />'; 222 echo '<img src="' . $header_thumbnail . '" alt="' . esc_attr($header_desc) .'" title="' . esc_attr($header_desc) .'" /></label>'; 223 echo '</div>'; 191 224 } 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>'; 225 226 echo '<div class="clear"></div></div>'; 215 227 } 216 228 217 229 /** … … 221 233 */ 222 234 function js() { 223 235 $step = $this->step(); 224 if ( 1 == $step)236 if ( ( 1 == $step || 3 == $step ) && $this->header_text() ) 225 237 $this->js_1(); 226 238 elseif ( 2 == $step ) 227 239 $this->js_2(); 228 240 } 229 241 230 242 /** 231 * Display Javascript based on Step 1 .243 * Display Javascript based on Step 1 and 3. 232 244 * 233 245 * @since 2.6.0 234 246 */ 235 247 function js_1() { ?> 236 248 <script type="text/javascript"> 237 var buttons = ['#name', '#desc', '#pickcolor', '#defaultcolor']; 249 /* <![CDATA[ */ 250 var text_objects = ['#name', '#desc', '#text-color-row']; 238 251 var farbtastic; 252 var default_color = '#<?php echo HEADER_TEXTCOLOR; ?>'; 253 var old_color = null; 239 254 240 255 function pickColor(color) { 241 256 jQuery('#name').css('color', color); 242 257 jQuery('#desc').css('color', color); 243 jQuery('#text color').val(color);258 jQuery('#text-color').val(color); 244 259 farbtastic.setColor(color); 245 260 } 261 262 function toggle_text(s) { 263 if (jQuery(s).attr('id') == 'showtext' && jQuery('#text-color').val() != 'blank') 264 return; 265 266 if (jQuery(s).attr('id') == 'hidetext' && jQuery('#text-color').val() == 'blank') 267 return; 246 268 269 if (jQuery('#text-color').val() == 'blank') { 270 //Show text 271 if (old_color == '#blank') 272 old_color = default_color; 273 274 jQuery( text_objects.toString() ).show(); 275 jQuery('#text-color').val(old_color); 276 jQuery('#name').css('color', old_color); 277 jQuery('#desc').css('color', old_color); 278 pickColor(old_color); 279 } else { 280 //Hide text 281 jQuery( text_objects.toString() ).hide(); 282 old_color = jQuery('#text-color').val(); 283 jQuery('#text-color').val('blank'); 284 } 285 } 286 247 287 jQuery(document).ready(function() { 248 288 jQuery('#pickcolor').click(function() { 249 jQuery('#color PickerDiv').show();289 jQuery('#color-picker').show(); 250 290 }); 251 291 252 jQuery(' #hidetext').click(function() {253 toggle_text( );292 jQuery('input[name="hidetext"]').click(function() { 293 toggle_text(this); 254 294 }); 295 296 jQuery('#defaultcolor').click(function() { 297 pickColor(default_color); 298 jQuery('#text-color').val(default_color) 299 }); 300 301 jQuery('#text-color').keyup(function() { 302 var _hex = jQuery('#text-color').val(); 303 var hex = _hex; 304 if ( hex[0] != '#' ) 305 hex = '#' + hex; 306 hex = hex.replace(/[^#a-fA-F0-9]+/, ''); 307 if ( hex != _hex ) 308 jQuery('#text-color').val(hex); 309 if ( hex.length == 4 || hex.length == 7 ) 310 pickColor( hex ); 311 }); 312 313 jQuery(document).mousedown(function(){ 314 jQuery('#color-picker').each( function() { 315 var display = jQuery(this).css('display'); 316 if (display == 'block') 317 jQuery(this).fadeOut(2); 318 }); 319 }); 255 320 256 farbtastic = jQuery.farbtastic('#color PickerDiv', function(color) { pickColor(color); });321 farbtastic = jQuery.farbtastic('#color-picker', function(color) { pickColor(color); }); 257 322 pickColor('#<?php echo get_theme_mod('header_textcolor', HEADER_TEXTCOLOR); ?>'); 258 323 259 <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR) ) { ?>324 <?php if ( 'blank' == get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) { ?> 260 325 toggle_text(); 261 326 <?php } ?> 262 });263 264 jQuery(document).mousedown(function(){265 // Make the picker disappear, since we're using it in an independant div266 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 }284 327 }); 285 }286 328 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 } 329 </script> 301 330 302 303 304 </script>305 331 <?php 306 332 } 307 333 … … 312 338 */ 313 339 function js_2() { ?> 314 340 <script type="text/javascript"> 341 /* <![CDATA[ */ 315 342 function onEndCrop( coords ) { 316 343 jQuery( '#x1' ).val(coords.x); 317 344 jQuery( '#y1' ).val(coords.y); 318 jQuery( '#x2' ).val(coords.x2); 319 jQuery( '#y2' ).val(coords.y2); 320 jQuery( '#width' ).val(coords.w); 321 jQuery( '#height' ).val(coords.h); 345 jQuery('#width').val(coords.w); 346 jQuery('#height').val(coords.h); 322 347 } 323 348 324 // with a supplied ratio325 349 jQuery(document).ready(function() { 326 350 var xinit = <?php echo HEADER_IMAGE_WIDTH; ?>; 327 351 var yinit = <?php echo HEADER_IMAGE_HEIGHT; ?>; 328 var ratio = xinit /yinit;352 var ratio = xinit + ':' + yinit; 329 353 var ximg = jQuery('#upload').width(); 330 354 var yimg = jQuery('#upload').height(); 331 355 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({ 356 jQuery('#upload').imgAreaSelect({ 357 handles: true, 358 keys: true, 351 359 aspectRatio: ratio, 352 setSelect: [ 0, 0, xinit, yinit ], 353 onSelect: onEndCrop 360 maxHeight: <?php echo HEADER_IMAGE_HEIGHT; ?>, 361 maxWidth: <?php echo HEADER_IMAGE_WIDTH; ?>, 362 onSelectChange: function(img, c) { 363 jQuery('#x1').val(c.x1); 364 jQuery('#y1').val(c.y1); 365 jQuery('#width').val(c.width); 366 jQuery('#height').val(c.height); 367 }, 354 368 }); 355 369 }); 370 /* ]]> */ 356 371 </script> 357 372 <?php 358 373 } … … 368 383 369 384 <div class="wrap"> 370 385 <?php screen_icon(); ?> 371 <h2><?php _e( 'Your Header Image'); ?></h2>386 <h2><?php _e( 'Custom Header' ); ?></h2> 372 387 373 <?php 374 if ( isset($_GET['updated']) && $_GET['updated'] ) { ?> 388 <?php if ( ! empty( $this->updated ) ) { ?> 375 389 <div id="message" class="updated"> 376 390 <p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p> 377 391 </div> 378 <?php } 392 <?php } ?> 379 393 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 394 <h3><?php _e( 'Header Image' ) ?></h3> 395 <table class="form-table"> 396 <tbody> 384 397 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 } ?> 398 <?php if ( get_header_image() ) : ?> 399 <tr valign="top"> 400 <th scope="row"><?php _e( 'Current Header' ); ?></th> 401 <td > 402 <?php if ( $this->admin_image_div_callback ) { 403 call_user_func( $this->admin_image_div_callback ); 404 } else { 405 ?> 406 <div id="headimg" style="max-width:<?php echo HEADER_IMAGE_WIDTH; ?>px;"> 407 <img id="image" src="<?php esc_url ( header_image() ) ?>" alt="" /> 408 <?php 409 if ( 'blank' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || '' == get_theme_mod('header_textcolor', HEADER_TEXTCOLOR) || ! $this->header_text() ) 410 $style = ' style="display:none;"'; 411 else 412 $style = ' style="color:#' . get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) . ';"'; 413 ?> 414 <h1 id="name"<?php echo $style; ?>><?php bloginfo( 'name' ); ?></h1> 415 <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div> 416 </div> 417 <?php } ?> 418 </td> 419 </tr> 420 <?php endif; ?> 394 421 395 <?php if ( !defined( 'NO_HEADER_TEXT' ) ) { ?> 396 <form method="post" action="<?php echo admin_url('themes.php?page=custom-header&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 } ?> 422 <tr valign="top"> 423 <th scope="row"><?php _e( 'Upload Image' ); ?></th> 424 <td> 425 <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 /> 426 <?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> 427 <form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>"> 428 <p> 429 <label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br /> 430 <input type="file" id="upload" name="import" /> 431 <input type="hidden" name="action" value="save" /> 432 <?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ) ?> 433 <input type="submit" class="button" value="<?php esc_attr_e( 'Upload' ); ?>" /> 434 </p> 435 </form> 436 </td> 437 </tr> 438 </tbody> 439 </table> 440 <form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?>"> 441 <table class="form-table"> 442 <tbody> 443 <?php if ( ! empty( $this->default_headers ) ) : ?> 444 <tr valign="top"> 445 <th scope="row"><?php _e( 'Default Images' ); ?></th> 446 <td> 447 <p><?php _e( 'If you didn‘t want to upload your own image, you can use one of these cool headers.' ) ?></p> 448 <?php 449 $this->show_default_header_selector(); 450 ?> 451 </td> 452 </tr> 453 <?php endif; 402 454 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&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> 455 if ( get_header_image() ) : ?> 456 <tr valign="top"> 457 <th scope="row"><?php _e( 'Remove Image' ); ?></th> 458 <td> 459 <p><?php _e( 'This will remove the header image. You will not be able to retrieve any customizations.' ) ?></p> 460 <input type="submit" class="button" name="removeheader" value="<?php esc_attr_e( 'Remove Header Image' ); ?>" /> 461 </td> 462 </tr> 463 <?php endif; 464 465 if ( defined( 'HEADER_IMAGE' ) ) : ?> 466 <tr valign="top"> 467 <th scope="row"><?php _e( 'Reset Image' ); ?></th> 468 <td> 469 <p><?php _e( 'This will restore the original header image. You will not be able to retrieve any customizations.' ) ?></p> 470 <input type="submit" class="button" name="resetheader" value="<?php esc_attr_e( 'Restore Original Header Image' ); ?>" /> 471 </td> 472 </tr> 473 <?php endif; ?> 474 </tbody> 475 </table> 418 476 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> 477 <?php if ( $this->header_text() ) : ?> 478 <h3><?php _e( 'Header Text' ) ?></h3> 479 <table class="form-table"> 480 <tbody> 481 <tr valign="top" class="hide-if-no-js"> 482 <th scope="row"><?php _e( 'Display Text' ); ?></th> 483 <td> 484 <p> 485 <?php $hidetext = get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ); ?> 486 <label><input type="radio" value="1" name="hidetext" id="hidetext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? true : false ); ?> /> <?php _e( 'No' ); ?></label> 487 <label><input type="radio" value="0" name="hidetext" id="showtext"<?php checked( ( 'blank' == $hidetext || empty( $hidetext ) ) ? false : true ); ?> /> <?php _e( 'Yes' ); ?></label> 488 </p> 489 </td> 490 </tr> 427 491 428 </div> 492 <tr valign="top" id="text-color-row"> 493 <th scope="row"><?php _e( 'Text Color' ); ?></th> 494 <td> 495 <p> 496 <input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_mod( 'header_textcolor', HEADER_TEXTCOLOR ) ); ?>" /> 497 <span class="description hide-if-js"><?php _e( 'If you want to hide header text, add <strong>#blank</strong> as text color.' );?></span> 498 <input type="button" class="button hide-if-no-js" value="<?php esc_attr_e( 'Select a Color' ); ?>" id="pickcolor" /> 499 </p> 500 <div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div> 501 </td> 502 </tr> 429 503 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 } ?> 504 <?php if ( defined( 'HEADER_TEXTCOLOR' ) && get_theme_mod( 'header_textcolor' ) ) { ?> 505 <tr valign="top"> 506 <th scope="row"><?php _e( 'Reset Text Color' ); ?></th> 507 <td> 508 <p><?php _e( 'This will restore the original header text color. You will not be able to retrieve any customizations.' ) ?></p> 509 <input type="submit" class="button" name="resettext" value="<?php esc_attr_e( 'Restore Original Header Text Color' ); ?>" /> 510 </td> 511 </tr> 512 <?php } ?> 513 514 </tbody> 515 </table> 516 <?php endif; 517 518 wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 519 <p class="submit"><input type="submit" class="button-primary" name="save-header-options" value="<?php esc_attr_e( 'Save Changes' ); ?>" /></p> 449 520 </form> 450 521 </div> 451 <?php endif;452 522 453 523 <?php } 454 524 455 525 /** 456 526 * Display second step of custom header image page. … … 458 528 * @since 2.1.0 459 529 */ 460 530 function step_2() { 461 check_admin_referer('custom-header'); 462 $overrides = array('test_form' => false); 463 $file = wp_handle_upload($_FILES['import'], $overrides); 531 check_admin_referer( 'custom-header-upload', '_wpnonce-custom-header-upload' ); 464 532 465 if ( isset($file['error']) )466 die( $file['error']);533 $overrides = array( 'test_form' => false ); 534 $file = wp_handle_upload( $_FILES['import'], $overrides ); 467 535 536 if ( isset( $file['error'] ) ) 537 wp_die( $file['error'], __( 'Image Upload Error' ) ); 538 468 539 $url = $file['url']; 469 540 $type = $file['type']; 470 541 $file = $file['file']; … … 472 543 473 544 // Construct the object array 474 545 $object = array( 475 'post_title' => $filename, 476 'post_content' => $url, 477 'post_mime_type' => $type, 478 'guid' => $url); 546 'post_title' => $filename, 547 'post_content' => __( 'This is your header image, if you delete it, you will lost your header image.' ), 548 'post_mime_type' => $type, 549 'guid' => $url 550 ); 479 551 480 552 // Save the data 481 $id = wp_insert_attachment( $object, $file);553 $id = wp_insert_attachment( $object, $file ); 482 554 483 list( $width, $height, $type, $attr) = getimagesize( $file );555 list( $width, $height, $type, $attr) = getimagesize( $file ); 484 556 485 557 if ( $width == HEADER_IMAGE_WIDTH && $height == HEADER_IMAGE_HEIGHT ) { 486 558 // Add the meta-data 487 559 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); 488 560 489 set_theme_mod( 'header_image', esc_url($url));490 do_action( 'wp_create_file_in_uploads', $file, $id); // For replication561 set_theme_mod( 'header_image', esc_url( $url ) ); 562 do_action( 'wp_create_file_in_uploads', $file, $id ); // For replication 491 563 return $this->finished(); 492 564 } elseif ( $width > HEADER_IMAGE_WIDTH ) { 493 565 $oitar = $width / HEADER_IMAGE_WIDTH; 494 $image = wp_crop_image( $file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));566 $image = wp_crop_image( $file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace( basename( $file ), 'midsize-'.basename( $file ), $file ) ); 495 567 if ( is_wp_error( $image ) ) 496 568 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 497 569 498 $image = apply_filters( 'wp_create_file_in_uploads', $image, $id); // For replication570 $image = apply_filters( 'wp_create_file_in_uploads', $image, $id ); // For replication 499 571 500 $url = str_replace( basename($url), basename($image), $url);572 $url = str_replace( basename( $url ), basename( $image ), $url ); 501 573 $width = $width / $oitar; 502 574 $height = $height / $oitar; 503 575 } else { … … 506 578 ?> 507 579 508 580 <div class="wrap"> 581 <?php screen_icon(); ?> 582 <h2><?php _e( 'Crop Header Image' ); ?></h2> 509 583 510 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 3)) ?>"> 584 <form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 3 ) ); ?>"> 585 <p class="hide-if-no-js"><?php _e( 'Choose the part of the image you want to use as your header.' ); ?></p> 586 <p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.' ); ?></strong></p> 587 <p><?php printf( __( 'Images smaller then <strong>%1$d x %2$d pixels</strong> will be zoomed.' ), HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); ?></p> 588 <div id="crop_image" style="position: relative"> 589 <img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" /> 590 </div> 511 591 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> 516 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 592 <input type="hidden" name="x1" id="x1" value="0"/> 593 <input type="hidden" name="y1" id="y1" value="0"/> 594 <input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/> 595 <input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/> 596 <input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $id ); ?>" /> 597 <input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" /> 598 <?php wp_nonce_field( 'custom-header-crop-image' ) ?> 599 <p class="submit"><input type="submit" value="<?php esc_attr_e( 'Crop Header' ); ?>" /></p> 530 600 </form> 531 601 </div> 532 602 <?php … … 538 608 * @since 2.1.0 539 609 */ 540 610 function step_3() { 541 check_admin_referer('custom-header'); 611 check_admin_referer( 'custom-header-crop-image' ); 612 542 613 if ( $_POST['oitar'] > 1 ) { 543 614 $_POST['x1'] = $_POST['x1'] * $_POST['oitar']; 544 615 $_POST['y1'] = $_POST['y1'] * $_POST['oitar']; … … 548 619 549 620 $original = get_attached_file( $_POST['attachment_id'] ); 550 621 551 $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); 622 // Crop the image 623 $cropped = wp_crop_image( $_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT ); 552 624 if ( is_wp_error( $cropped ) ) 553 wp_die( __( 'Image could not be processed. 625 wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); 554 626 555 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication627 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $_POST['attachment_id'] ); // For replication 556 628 557 $parent = get_post( $_POST['attachment_id']);629 $parent = get_post( $_POST['attachment_id'] ); 558 630 $parent_url = $parent->guid; 559 $url = str_replace( basename($parent_url), basename($cropped), $parent_url);631 $url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url ); 560 632 561 633 // Construct the object array 562 634 $object = array( 563 635 'ID' => $_POST['attachment_id'], 564 'post_title' => basename( $cropped),565 'post_content' => $url,636 'post_title' => basename( $cropped ), 637 'post_content' => __( 'This is your header image, if you delete it, you will lost your header image.' ), 566 638 'post_mime_type' => 'image/jpeg', 567 639 'guid' => $url 568 640 ); … … 571 643 wp_insert_attachment($object, $cropped); 572 644 wp_update_attachment_metadata( $_POST['attachment_id'], wp_generate_attachment_metadata( $_POST['attachment_id'], $cropped ) ); 573 645 574 set_theme_mod( 'header_image', $url);646 set_theme_mod( 'header_image', $url ); 575 647 576 648 // cleanup 577 $medium = str_replace( basename($original), 'midsize-'.basename($original), $original);649 $medium = str_replace( basename( $original ), 'midsize-'.basename( $original ), $original ); 578 650 @unlink( apply_filters( 'wp_delete_file', $medium ) ); 579 651 @unlink( apply_filters( 'wp_delete_file', $original ) ); 580 652 … … 587 659 * @since 2.1.0 588 660 */ 589 661 function finished() { 590 $ _GET['updated'] = 1;591 662 $this->updated = true; 663 $this->step_1(); 592 664 } 593 665 594 666 /** … … 597 669 * @since 2.1.0 598 670 */ 599 671 function admin_page() { 600 if ( ! current_user_can('edit_theme_options') ) 601 wp_die(__('You do not have permission to customize headers.')); 672 if ( ! current_user_can( 'edit_theme_options' ) ) 673 wp_die( __( 'You do not have permission to customize headers.' ) ); 674 602 675 $step = $this->step(); 603 676 if ( 1 == $step ) 604 677 $this->step_1(); -
wp-content/themes/twentyten/functions.php
187 187 function twentyten_admin_header_style() { 188 188 ?> 189 189 <style type="text/css"> 190 #headimg { 191 height: <?php echo HEADER_IMAGE_HEIGHT; ?>px; 192 width: <?php echo HEADER_IMAGE_WIDTH; ?>px; 190 /* Shows the same border as on front page */ 191 .appearance_page_custom-header #headimg { 192 border-bottom: 1px solid #000000; 193 border-top: 4px solid #000000; 193 194 } 194 #headimg h1, #headimg #desc {195 display: none;196 }197 195 </style> 198 196 <?php 199 197 }