web/wp-admin/custom-header.php
changeset 204 09a1c134465b
parent 194 32102edaa81b
equal deleted inserted replaced
203:f507feede89a 204:09a1c134465b
    91 		add_action("admin_head-$page", array(&$this, 'help') );
    91 		add_action("admin_head-$page", array(&$this, 'help') );
    92 		add_action("admin_head-$page", array(&$this, 'take_action'), 50);
    92 		add_action("admin_head-$page", array(&$this, 'take_action'), 50);
    93 		add_action("admin_head-$page", array(&$this, 'js'), 50);
    93 		add_action("admin_head-$page", array(&$this, 'js'), 50);
    94 		if ( $this->admin_header_callback )
    94 		if ( $this->admin_header_callback )
    95 			add_action("admin_head-$page", $this->admin_header_callback, 51);
    95 			add_action("admin_head-$page", $this->admin_header_callback, 51);
    96 
       
    97 		if ( isset( $_REQUEST['context'] ) && $_REQUEST['context'] == 'custom-header' ) {
       
    98 			add_filter( 'attachment_fields_to_edit', array( $this, 'attachment_fields_to_edit' ), 10, 2 );
       
    99 			add_filter( 'media_upload_tabs', array( $this, 'filter_upload_tabs' ) );
       
   100 			add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
       
   101 		}
       
   102 	}
    96 	}
   103 
    97 
   104 	/**
    98 	/**
   105 	 * Adds contextual help.
    99 	 * Adds contextual help.
   106 	 *
   100 	 *
   128 		get_current_screen()->add_help_tab( array(
   122 		get_current_screen()->add_help_tab( array(
   129 			'id'      => 'set-header-text',
   123 			'id'      => 'set-header-text',
   130 			'title'   => __('Header Text'),
   124 			'title'   => __('Header Text'),
   131 			'content' =>
   125 			'content' =>
   132 				'<p>' . sprintf( __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%1$s">General Settings</a> section.' ), admin_url( 'options-general.php' ) ) . '<p>' .
   126 				'<p>' . sprintf( __( 'For most themes, the header text is your Site Title and Tagline, as defined in the <a href="%1$s">General Settings</a> section.' ), admin_url( 'options-general.php' ) ) . '<p>' .
   133 				'<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by typing in a legitimate HTML hex value (eg: &#8220;#ff0000&#8221; for red) or by clicking &#8220;Select a Color&#8221; and dialing in a color using the color picker.') . '</p>' .
   127 				'<p>' . __( 'In the Header Text section of this page, you can choose whether to display this text or hide it. You can also choose a color for the text by clicking the Select Color button and either typing in a legitimate HTML hex value, e.g. &#8220;#ff0000&#8221; for red, or by choosing a color using the color picker.' ) . '</p>' .
   134 				'<p>' . __( 'Don&#8217;t forget to Save Changes when you&#8217;re done!') . '</p>'
   128 				'<p>' . __( 'Don&#8217;t forget to click &#8220;Save Changes&#8221; when you&#8217;re done!') . '</p>'
   135 		) );
   129 		) );
   136 
   130 
   137 		get_current_screen()->set_help_sidebar(
   131 		get_current_screen()->set_help_sidebar(
   138 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   132 			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
   139 			'<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
   133 			'<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
   169 	 */
   163 	 */
   170 	function js_includes() {
   164 	function js_includes() {
   171 		$step = $this->step();
   165 		$step = $this->step();
   172 
   166 
   173 		if ( ( 1 == $step || 3 == $step ) ) {
   167 		if ( ( 1 == $step || 3 == $step ) ) {
   174 			add_thickbox();
   168 			wp_enqueue_media();
   175 			wp_enqueue_script( 'media-upload' );
       
   176 			wp_enqueue_script( 'custom-header' );
   169 			wp_enqueue_script( 'custom-header' );
   177 			if ( current_theme_supports( 'custom-header', 'header-text' ) )
   170 			if ( current_theme_supports( 'custom-header', 'header-text' ) )
   178 				wp_enqueue_script('farbtastic');
   171 				wp_enqueue_script( 'wp-color-picker' );
   179 		} elseif ( 2 == $step ) {
   172 		} elseif ( 2 == $step ) {
   180 			wp_enqueue_script('imgareaselect');
   173 			wp_enqueue_script('imgareaselect');
   181 		}
   174 		}
   182 	}
   175 	}
   183 
   176 
   188 	 */
   181 	 */
   189 	function css_includes() {
   182 	function css_includes() {
   190 		$step = $this->step();
   183 		$step = $this->step();
   191 
   184 
   192 		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
   185 		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
   193 			wp_enqueue_style('farbtastic');
   186 			wp_enqueue_style( 'wp-color-picker' );
   194 		elseif ( 2 == $step )
   187 		elseif ( 2 == $step )
   195 			wp_enqueue_style('imgareaselect');
   188 			wp_enqueue_style('imgareaselect');
   196 	}
   189 	}
   197 
   190 
   198 	/**
   191 	/**
   210 		$this->updated = true;
   203 		$this->updated = true;
   211 
   204 
   212 		if ( isset( $_POST['resetheader'] ) ) {
   205 		if ( isset( $_POST['resetheader'] ) ) {
   213 			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
   206 			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
   214 			$this->reset_header_image();
   207 			$this->reset_header_image();
   215 			return;
       
   216 		}
       
   217 
       
   218 		if ( isset( $_POST['resettext'] ) ) {
       
   219 			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
       
   220 			remove_theme_mod('header_textcolor');
       
   221 			return;
   208 			return;
   222 		}
   209 		}
   223 
   210 
   224 		if ( isset( $_POST['removeheader'] ) ) {
   211 		if ( isset( $_POST['removeheader'] ) ) {
   225 			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
   212 			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
   330 	 * @since 2.6.0
   317 	 * @since 2.6.0
   331 	 */
   318 	 */
   332 	function js_1() { ?>
   319 	function js_1() { ?>
   333 <script type="text/javascript">
   320 <script type="text/javascript">
   334 /* <![CDATA[ */
   321 /* <![CDATA[ */
   335 var farbtastic;
       
   336 (function($){
   322 (function($){
   337 	var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
   323 	var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
   338 		header_text_fields;
   324 		header_text_fields;
   339 
   325 
   340 	function pickColor(color) {
   326 	function pickColor(color) {
   341 		$('#name').css('color', color);
   327 		$('#name').css('color', color);
   342 		$('#desc').css('color', color);
   328 		$('#desc').css('color', color);
   343 		$('#text-color').val(color);
   329 		$('#text-color').val(color);
   344 		farbtastic.setColor(color);
       
   345 	}
   330 	}
   346 
   331 
   347 	function toggle_text() {
   332 	function toggle_text() {
   348 		var checked = $('#display-header-text').prop('checked'),
   333 		var checked = $('#display-header-text').prop('checked'),
   349 			text_color;
   334 			text_color;
   358 			pickColor( text_color.val() );
   343 			pickColor( text_color.val() );
   359 		}
   344 		}
   360 	}
   345 	}
   361 
   346 
   362 	$(document).ready(function() {
   347 	$(document).ready(function() {
       
   348 		var text_color = $('#text-color');
   363 		header_text_fields = $('.displaying-header-text');
   349 		header_text_fields = $('.displaying-header-text');
   364 		$('#pickcolor').click(function(e) {
   350 		text_color.wpColorPicker({
   365 			e.preventDefault();
   351 			change: function( event, ui ) {
   366 			$('#color-picker').show();
   352 				pickColor( text_color.wpColorPicker('color') );
       
   353 			},
       
   354 			clear: function() {
       
   355 				pickColor( '' );
       
   356 			}
   367 		});
   357 		});
   368 
       
   369 		$('#display-header-text').click( toggle_text );
   358 		$('#display-header-text').click( toggle_text );
   370 
   359 		<?php if ( ! display_header_text() ) : ?>
   371 		$('#defaultcolor').click(function() {
       
   372 			pickColor(default_color);
       
   373 			$('#text-color').val(default_color);
       
   374 		});
       
   375 
       
   376 		$('#text-color').keyup(function() {
       
   377 			var _hex = $('#text-color').val();
       
   378 			var hex = _hex;
       
   379 			if ( hex[0] != '#' )
       
   380 				hex = '#' + hex;
       
   381 			hex = hex.replace(/[^#a-fA-F0-9]+/, '');
       
   382 			if ( hex != _hex )
       
   383 				$('#text-color').val(hex);
       
   384 			if ( hex.length == 4 || hex.length == 7 )
       
   385 				pickColor( hex );
       
   386 		});
       
   387 
       
   388 		$(document).mousedown(function(){
       
   389 			$('#color-picker').each( function() {
       
   390 				var display = $(this).css('display');
       
   391 				if (display == 'block')
       
   392 					$(this).fadeOut(2);
       
   393 			});
       
   394 		});
       
   395 
       
   396 		farbtastic = $.farbtastic('#color-picker', function(color) { pickColor(color); });
       
   397 		<?php if ( display_header_text() ) { ?>
       
   398 		pickColor('#<?php echo get_header_textcolor(); ?>');
       
   399 		<?php } else { ?>
       
   400 		toggle_text();
   360 		toggle_text();
   401 		<?php } ?>
   361 		<?php endif; ?>
   402 	});
   362 	});
   403 })(jQuery);
   363 })(jQuery);
   404 /* ]]> */
   364 /* ]]> */
   405 </script>
   365 </script>
   406 <?php
   366 <?php
   508 <th scope="row"><?php _e( 'Preview' ); ?></th>
   468 <th scope="row"><?php _e( 'Preview' ); ?></th>
   509 <td>
   469 <td>
   510 	<?php if ( $this->admin_image_div_callback ) {
   470 	<?php if ( $this->admin_image_div_callback ) {
   511 	  call_user_func( $this->admin_image_div_callback );
   471 	  call_user_func( $this->admin_image_div_callback );
   512 	} else {
   472 	} else {
       
   473 		$custom_header = get_custom_header();
       
   474 		$header_image_style = 'background-image:url(' . esc_url( get_header_image() ) . ');';
       
   475 		if ( $custom_header->width )
       
   476 			$header_image_style .= 'max-width:' . $custom_header->width . 'px;';
       
   477 		if ( $custom_header->height )
       
   478 			$header_image_style .= 'height:' . $custom_header->height . 'px;';
   513 	?>
   479 	?>
   514 	<div id="headimg" style="background-image:url(<?php esc_url ( header_image() ) ?>);max-width:<?php echo get_custom_header()->width; ?>px;height:<?php echo get_custom_header()->height; ?>px;">
   480 	<div id="headimg" style="<?php echo $header_image_style; ?>">
   515 		<?php
   481 		<?php
   516 		if ( display_header_text() )
   482 		if ( display_header_text() )
   517 			$style = ' style="color:#' . get_header_textcolor() . ';"';
   483 			$style = ' style="color:#' . get_header_textcolor() . ';"';
   518 		else
   484 		else
   519 			$style = ' style="display:none;"';
   485 			$style = ' style="display:none;"';
   526 </tr>
   492 </tr>
   527 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
   493 <?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
   528 <tr valign="top">
   494 <tr valign="top">
   529 <th scope="row"><?php _e( 'Select Image' ); ?></th>
   495 <th scope="row"><?php _e( 'Select Image' ); ?></th>
   530 <td>
   496 <td>
   531 	<p><?php _e( '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 />
   497 	<p><?php _e( 'You can select an image to be shown at the top of your site by uploading from your computer or choosing from your media library. After selecting an image you will be able to crop it.' ); ?><br />
   532 	<?php
   498 	<?php
   533 	if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
   499 	if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
   534 		printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
   500 		printf( __( 'Images of exactly <strong>%1$d &times; %2$d pixels</strong> will be used as-is.' ) . '<br />', get_theme_support( 'custom-header', 'width' ), get_theme_support( 'custom-header', 'height' ) );
   535 	} elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
   501 	} elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
   536 		if ( ! current_theme_supports( 'custom-header', 'flex-width' ) )
   502 		if ( ! current_theme_supports( 'custom-header', 'flex-width' ) )
   544 			printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
   510 			printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
   545 		if ( current_theme_supports( 'custom-header', 'height' ) )
   511 		if ( current_theme_supports( 'custom-header', 'height' ) )
   546 			printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
   512 			printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
   547 	}
   513 	}
   548 	?></p>
   514 	?></p>
   549 	<form enctype="multipart/form-data" id="upload-form" method="post" action="<?php echo esc_attr( add_query_arg( 'step', 2 ) ) ?>">
   515 	<form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ) ?>">
   550 	<p>
   516 	<p>
   551 		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
   517 		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
   552 		<input type="file" id="upload" name="import" />
   518 		<input type="file" id="upload" name="import" />
   553 		<input type="hidden" name="action" value="save" />
   519 		<input type="hidden" name="action" value="save" />
   554 		<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
   520 		<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
   555 		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
   521 		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
   556 	</p>
   522 	</p>
   557 	<?php
   523 	<?php
   558 		$image_library_url = get_upload_iframe_src( 'image', null, 'library' );
   524 		$modal_update_href = esc_url( add_query_arg( array(
   559 		$image_library_url = remove_query_arg( 'TB_iframe', $image_library_url );
   525 			'page' => 'custom-header',
   560 		$image_library_url = add_query_arg( array( 'context' => 'custom-header', 'TB_iframe' => 1 ), $image_library_url );
   526 			'step' => 2,
       
   527 			'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
       
   528 		), admin_url('themes.php') ) );
   561 	?>
   529 	?>
   562 	<p>
   530 	<p>
   563 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   531 		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
   564 		<a id="choose-from-library-link" class="button thickbox" href="<?php echo esc_url( $image_library_url ); ?>"><?php _e( 'Choose Image' ); ?></a>
   532 		<a id="choose-from-library-link" class="button"
       
   533 			data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
       
   534 			data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
       
   535 			data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></a>
   565 	</p>
   536 	</p>
   566 	</form>
   537 	</form>
   567 </td>
   538 </td>
   568 </tr>
   539 </tr>
   569 <?php endif; ?>
   540 <?php endif; ?>
   570 </tbody>
   541 </tbody>
   571 </table>
   542 </table>
   572 
   543 
   573 <form method="post" action="<?php echo esc_attr( add_query_arg( 'step', 1 ) ) ?>">
   544 <form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ) ?>">
   574 <table class="form-table">
   545 <table class="form-table">
   575 <tbody>
   546 <tbody>
   576 	<?php if ( get_uploaded_header_images() ) : ?>
   547 	<?php if ( get_uploaded_header_images() ) : ?>
   577 <tr valign="top">
   548 <tr valign="top">
   578 <th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
   549 <th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
   639 
   610 
   640 <tr valign="top" class="displaying-header-text">
   611 <tr valign="top" class="displaying-header-text">
   641 <th scope="row"><?php _e( 'Text Color' ); ?></th>
   612 <th scope="row"><?php _e( 'Text Color' ); ?></th>
   642 <td>
   613 <td>
   643 	<p>
   614 	<p>
   644 <?php if ( display_header_text() ) : ?>
   615 <?php
   645 		<input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_header_textcolor() ); ?>" />
   616 $header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
   646 <?php else : ?>
   617 $default_color = '';
   647 		<input type="text" name="text-color" id="text-color" value="#<?php echo esc_attr( get_theme_support( 'custom-header', 'default-text-color' ) ); ?>" />
   618 if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
   648 <?php endif; ?>
   619 	$default_color = '#' . get_theme_support( 'custom-header', 'default-text-color' );
   649 		<a href="#" class="hide-if-no-js" id="pickcolor"><?php _e( 'Select a Color' ); ?></a>
   620 	$default_color_attr = ' data-default-color="' . esc_attr( $default_color ) . '"';
       
   621 	echo '<input type="text" name="text-color" id="text-color" value="#' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
       
   622 	if ( $default_color )
       
   623 		echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), $default_color ) . '</span>';
       
   624 }
       
   625 ?>
   650 	</p>
   626 	</p>
   651 	<div id="color-picker" style="z-index: 100; background:#eee; border:1px solid #ccc; position:absolute; display:none;"></div>
       
   652 </td>
   627 </td>
   653 </tr>
   628 </tr>
   654 
       
   655 	<?php if ( current_theme_supports( 'custom-header', 'default-text-color' ) && get_theme_mod( 'header_textcolor' ) ) { ?>
       
   656 <tr valign="top">
       
   657 <th scope="row"><?php _e('Reset Text Color'); ?></th>
       
   658 <td>
       
   659 	<p><?php _e( 'This will restore the original header text. You will not be able to restore any customizations.' ) ?></p>
       
   660 	<?php submit_button( __( 'Restore Original Header Text' ), 'button', 'resettext', false ); ?>
       
   661 </td>
       
   662 </tr>
       
   663 	<?php } ?>
       
   664 
       
   665 </tbody>
   629 </tbody>
   666 </table>
   630 </table>
   667 <?php endif;
   631 <?php endif;
   668 
   632 
   669 do_action( 'custom_header_options' );
   633 do_action( 'custom_header_options' );
   743 
   707 
   744 <div class="wrap">
   708 <div class="wrap">
   745 <?php screen_icon(); ?>
   709 <?php screen_icon(); ?>
   746 <h2><?php _e( 'Crop Header Image' ); ?></h2>
   710 <h2><?php _e( 'Crop Header Image' ); ?></h2>
   747 
   711 
   748 <form method="post" action="<?php echo esc_attr(add_query_arg('step', 3)); ?>">
   712 <form method="post" action="<?php echo esc_url(add_query_arg('step', 3)); ?>">
   749 	<p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
   713 	<p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
   750 	<p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.'); ?></strong></p>
   714 	<p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.'); ?></strong></p>
   751 
   715 
   752 	<div id="crop_image" style="position: relative">
   716 	<div id="crop_image" style="position: relative">
   753 		<img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
   717 		<img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
   765 	<?php wp_nonce_field( 'custom-header-crop-image' ) ?>
   729 	<?php wp_nonce_field( 'custom-header-crop-image' ) ?>
   766 
   730 
   767 	<p class="submit">
   731 	<p class="submit">
   768 	<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
   732 	<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
   769 	<?php
   733 	<?php
   770 	if ( isset( $oitar ) && 1 == $oitar )
   734 	if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
   771 		submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
   735 		submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
   772 	?>
   736 	?>
   773 	</p>
   737 	</p>
   774 </form>
   738 </form>
   775 </div>
   739 </div>
   782 	 *
   746 	 *
   783 	 * @since 3.4.0
   747 	 * @since 3.4.0
   784 	 */
   748 	 */
   785 	function step_2_manage_upload() {
   749 	function step_2_manage_upload() {
   786 		$overrides = array('test_form' => false);
   750 		$overrides = array('test_form' => false);
   787 		$file = wp_handle_upload($_FILES['import'], $overrides);
   751 
       
   752 		$uploaded_file = $_FILES['import'];
       
   753 		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
       
   754 		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
       
   755 			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
       
   756 
       
   757 		$file = wp_handle_upload($uploaded_file, $overrides);
   788 
   758 
   789 		if ( isset($file['error']) )
   759 		if ( isset($file['error']) )
   790 			wp_die( $file['error'],  __( 'Image Upload Error' ) );
   760 			wp_die( $file['error'],  __( 'Image Upload Error' ) );
   791 
   761 
   792 		$url = $file['url'];
   762 		$url = $file['url'];
   815 	 */
   785 	 */
   816 	function step_3() {
   786 	function step_3() {
   817 		check_admin_referer( 'custom-header-crop-image' );
   787 		check_admin_referer( 'custom-header-crop-image' );
   818 
   788 
   819 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
   789 		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
       
   790 			wp_die( __( 'Cheatin&#8217; uh?' ) );
       
   791 
       
   792 		if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
   820 			wp_die( __( 'Cheatin&#8217; uh?' ) );
   793 			wp_die( __( 'Cheatin&#8217; uh?' ) );
   821 
   794 
   822 		if ( $_POST['oitar'] > 1 ) {
   795 		if ( $_POST['oitar'] > 1 ) {
   823 			$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
   796 			$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
   824 			$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
   797 			$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
   928 		else
   901 		else
   929 			$this->step_1();
   902 			$this->step_1();
   930 	}
   903 	}
   931 
   904 
   932 	/**
   905 	/**
   933 	 * Replace default attachment actions with "Set as header" link.
   906 	 * Unused since 3.5.0.
   934 	 *
   907 	 *
   935 	 * @since 3.4.0
   908 	 * @since 3.4.0
   936 	 */
   909 	 */
   937 	function attachment_fields_to_edit( $form_fields, $post ) {
   910 	function attachment_fields_to_edit( $form_fields ) {
   938 		$form_fields = array();
       
   939 		$href = esc_url(add_query_arg(array(
       
   940 			'page' => 'custom-header',
       
   941 			'step' => 2,
       
   942 			'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
       
   943 			'file' => $post->ID
       
   944 		), admin_url('themes.php')));
       
   945 
       
   946 		$form_fields['buttons'] = array( 'tr' => '<tr class="submit"><td></td><td><a data-location="' . $href . '" class="wp-set-header">' . __( 'Set as header' ) . '</a></td></tr>' );
       
   947 		$form_fields['context'] = array( 'input' => 'hidden', 'value' => 'custom-header' );
       
   948 
       
   949 		return $form_fields;
   911 		return $form_fields;
   950 	}
   912 	}
   951 
   913 
   952 	/**
   914 	/**
   953 	 * Leave only "Media Library" tab in the uploader window.
   915 	 * Unused since 3.5.0.
   954 	 *
   916 	 *
   955 	 * @since 3.4.0
   917 	 * @since 3.4.0
   956 	 */
   918 	 */
   957 	function filter_upload_tabs() {
   919 	function filter_upload_tabs( $tabs ) {
   958 		return array( 'library' => __('Media Library') );
   920 		return $tabs;
   959 	}
   921 	}
   960 
   922 
   961 	/**
   923 	/**
   962 	 * Choose a header image, selected from existing uploaded and default headers,
   924 	 * Choose a header image, selected from existing uploaded and default headers,
   963 	 * or provide an array of uploaded header data (either new, or from media library).
   925 	 * or provide an array of uploaded header data (either new, or from media library).