wp/wp-admin/custom-header.php
author ymh <ymh.work@gmail.com>
Thu, 07 Nov 2013 00:08:07 +0000
changeset 1 f6eb5a861d2f
parent 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
remove unnessary files. Make timthumb work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * The custom header image script.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 * The custom header image class.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
class Custom_Image_Header {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	 * Callback for administration header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
	 * @var callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
	var $admin_header_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 * Callback for header div.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @var callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	var $admin_image_div_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * Holds default headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	var $default_headers = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
	 * Holds custom headers uploaded by the user
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 * @since 3.2.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	var $uploaded_headers = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	 * Holds the page menu hook.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
	 * @var string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
	var $page = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
	 * Constructor - Register administration header callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	 * @param callback $admin_header_callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 * @param callback $admin_image_div_callback Optional custom image div output callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 * @return Custom_Image_Header
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	function __construct($admin_header_callback, $admin_image_div_callback = '') {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
		$this->admin_header_callback = $admin_header_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
		$this->admin_image_div_callback = $admin_image_div_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
		add_action( 'admin_menu', array( $this, 'init' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Set up the hooks for the Custom Header admin page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	function init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
		if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
		$this->page = $page = add_theme_page(__('Header'), __('Header'), 'edit_theme_options', 'custom-header', array($this, 'admin_page'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
		add_action("admin_print_scripts-$page", array($this, 'js_includes'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
		add_action("admin_print_styles-$page", array($this, 'css_includes'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
		add_action("admin_head-$page", array($this, 'help') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		add_action("admin_head-$page", array($this, 'take_action'), 50);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
		add_action("admin_head-$page", array($this, 'js'), 50);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		if ( $this->admin_header_callback )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			add_action("admin_head-$page", $this->admin_header_callback, 51);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
	 * Adds contextual help.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	function help() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
			'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
			'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
				'<p>' . __( 'This screen is used to customize the header section of your theme.') . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
				'<p>' . __( 'You can choose from the theme&#8217;s default header images, or use one of your own. You can also customize how your Site Title and Tagline are displayed.') . '<p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
			'id'      => 'set-header-image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
			'title'   => __('Header Image'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
				'<p>' . __( 'You can set a custom image header for your site. Simply upload the image and crop it, and the new header will go live immediately. Alternatively, you can use an image that has already been uploaded to your Media Library by clicking the &#8220;Choose Image&#8221; button.' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
				'<p>' . __( 'Some themes come with additional header images bundled. If you see multiple images displayed, select the one you&#8217;d like and click the &#8220;Save Changes&#8221; button.' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
				'<p>' . __( 'If your theme has more than one default header image, or you have uploaded more than one custom header image, you have the option of having WordPress display a randomly different image on each page of your site. Click the &#8220;Random&#8221; radio button next to the Uploaded Images or Default Images section to enable this feature.') . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
				'<p>' . __( 'If you don&#8217;t want a header image to be displayed on your site at all, click the &#8220;Remove Header Image&#8221; button at the bottom of the Header Image section of this page. If you want to re-enable the header image later, you just have to select one of the other image options and click &#8220;Save Changes&#8221;.') . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
			'id'      => 'set-header-text',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
			'title'   => __('Header Text'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   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>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
				'<p>' . __( 'Don&#8217;t forget to click &#8220;Save Changes&#8221; when you&#8217;re done!') . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			'<p>' . __( '<a href="http://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			'<p>' . __( '<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
	 * Get the current step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
	 * @return int Current step
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	function step() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		if ( ! isset( $_GET['step'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
		$step = (int) $_GET['step'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
		if ( $step < 1 || 3 < $step ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
			( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
			( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		return $step;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	 * Set up the enqueue for the JavaScript files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	function js_includes() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
		if ( ( 1 == $step || 3 == $step ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
			wp_enqueue_media();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
			wp_enqueue_script( 'custom-header' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
			if ( current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
				wp_enqueue_script( 'wp-color-picker' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
		} elseif ( 2 == $step ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
			wp_enqueue_script('imgareaselect');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	 * Set up the enqueue for the CSS files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	 * @since 2.7
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	function css_includes() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
			wp_enqueue_style( 'wp-color-picker' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
		elseif ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			wp_enqueue_style('imgareaselect');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
	 * Execute custom header modification.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
	function take_action() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
		if ( empty( $_POST ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		if ( isset( $_POST['resetheader'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
			$this->reset_header_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
		if ( isset( $_POST['removeheader'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			$this->remove_header_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
		if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
			set_theme_mod( 'header_textcolor', 'blank' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		} elseif ( isset( $_POST['text-color'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
			$_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			$color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
			if ( strlen($color) == 6 || strlen($color) == 3 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
				set_theme_mod('header_textcolor', $color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
			elseif ( ! $color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
				set_theme_mod( 'header_textcolor', 'blank' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
		if ( isset( $_POST['default-header'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
			$this->set_header_image( $_POST['default-header'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	 * Process the default headers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	function process_default_headers() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		if ( !empty($this->headers) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		if ( !isset($_wp_default_headers) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		$this->default_headers = $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
		$template_directory_uri = get_template_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
		$stylesheet_directory_uri = get_stylesheet_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
		foreach ( array_keys($this->default_headers) as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			$this->default_headers[$header]['url'] =  sprintf( $this->default_headers[$header]['url'], $template_directory_uri, $stylesheet_directory_uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
			$this->default_headers[$header]['thumbnail_url'] =  sprintf( $this->default_headers[$header]['thumbnail_url'], $template_directory_uri, $stylesheet_directory_uri );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	 * Display UI for selecting one of several default headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	 * Show the random image option if this theme has multiple header images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
	 * Random image option is on by default if no header has been set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
	function show_header_selector( $type = 'default' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		if ( 'default' == $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
			$headers = $this->default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
			$headers = get_uploaded_header_images();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
			$type = 'uploaded';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
		if ( 1 < count( $headers ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			echo '<div class="random-header">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
			echo '<label><input name="default-header" type="radio" value="random-' . $type . '-image"' . checked( is_random_header_image( $type ), true, false ) . ' />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			echo __( '<strong>Random:</strong> Show a different image on each page.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
			echo '</label>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
			echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		echo '<div class="available-headers">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
		foreach ( $headers as $header_key => $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
			$header_thumbnail = $header['thumbnail_url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			$header_url = $header['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
			$header_desc = empty( $header['description'] ) ? '' : $header['description'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
			echo '<div class="default-header">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			echo '<label><input name="default-header" type="radio" value="' . esc_attr( $header_key ) . '" ' . checked( $header_url, get_theme_mod( 'header_image' ), false ) . ' />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
			$width = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
			if ( !empty( $header['attachment_id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
				$width = ' width="230"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
			echo '<img src="' . set_url_scheme( $header_thumbnail ) . '" alt="' . esc_attr( $header_desc ) .'" title="' . esc_attr( $header_desc ) . '"' . $width . ' /></label>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
			echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
		echo '<div class="clear"></div></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	 * Execute Javascript depending on step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	function js() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
			$this->js_1();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		elseif ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
			$this->js_2();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
	 * Display Javascript based on Step 1 and 3.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
	function js_1() { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
/* <![CDATA[ */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
(function($){
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	var default_color = '#<?php echo get_theme_support( 'custom-header', 'default-text-color' ); ?>',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
		header_text_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	function pickColor(color) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		$('#name').css('color', color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
		$('#desc').css('color', color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
		$('#text-color').val(color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	function toggle_text() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		var checked = $('#display-header-text').prop('checked'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
			text_color;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
		header_text_fields.toggle( checked );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
		if ( ! checked )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
		text_color = $('#text-color');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
		if ( '' == text_color.val().replace('#', '') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
			text_color.val( default_color );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			pickColor( default_color );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			pickColor( text_color.val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	$(document).ready(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		var text_color = $('#text-color');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
		header_text_fields = $('.displaying-header-text');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
		text_color.wpColorPicker({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
			change: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
				pickColor( text_color.wpColorPicker('color') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			clear: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
				pickColor( '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		$('#display-header-text').click( toggle_text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		<?php if ( ! display_header_text() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
		toggle_text();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
})(jQuery);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
/* ]]> */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
	 * Display Javascript based on Step 2.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
	function js_2() { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
/* <![CDATA[ */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
	function onEndCrop( coords ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		jQuery( '#x1' ).val(coords.x);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		jQuery( '#y1' ).val(coords.y);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
		jQuery( '#width' ).val(coords.w);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		jQuery( '#height' ).val(coords.h);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
	jQuery(document).ready(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
		var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		var ratio = xinit / yinit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		var ximg = jQuery('img#upload').width();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
		var yimg = jQuery('img#upload').height();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
		if ( yimg < yinit || ximg < xinit ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
			if ( ximg / yimg > ratio ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
				yinit = yimg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
				xinit = yinit * ratio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
				xinit = ximg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
				yinit = xinit / ratio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
		jQuery('img#upload').imgAreaSelect({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			handles: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			keys: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
			show: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
			x1: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
			y1: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
			x2: xinit,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			y2: yinit,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
			if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			aspectRatio: xinit + ':' + yinit,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
			if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
			maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
			maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
			onInit: function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
				jQuery('#width').val(xinit);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
				jQuery('#height').val(yinit);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
			onSelectChange: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
				jQuery('#x1').val(c.x1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
				jQuery('#y1').val(c.y1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
				jQuery('#width').val(c.width);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
				jQuery('#height').val(c.height);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
/* ]]> */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	 * Display first step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
	function step_1() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
		$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
<?php screen_icon(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
<h2><?php _e('Custom Header'); ?></h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
<?php if ( ! empty( $this->updated ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
<div id="message" class="updated">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
<p><?php printf( __( 'Header updated. <a href="%s">Visit your site</a> to see how it looks.' ), home_url( '/' ) ); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
<h3><?php _e( 'Header Image' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
<?php if ( get_custom_header() || display_header_text() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
<th scope="row"><?php _e( 'Preview' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
	<?php if ( $this->admin_image_div_callback ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
	  call_user_func( $this->admin_image_div_callback );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
		$custom_header = get_custom_header();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
		$header_image_style = 'background-image:url(' . esc_url( get_header_image() ) . ');';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
		if ( $custom_header->width )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
			$header_image_style .= 'max-width:' . $custom_header->width . 'px;';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
		if ( $custom_header->height )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
			$header_image_style .= 'height:' . $custom_header->height . 'px;';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	<div id="headimg" style="<?php echo $header_image_style; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
		if ( display_header_text() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
			$style = ' style="color:#' . get_header_textcolor() . ';"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
			$style = ' style="display:none;"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
		<h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>"><?php bloginfo( 'name' ); ?></a></h1>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
		<div id="desc" class="displaying-header-text" <?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
<th scope="row"><?php _e( 'Select Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	<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 />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
		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' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	} elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
		if ( ! current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
			printf( __( 'Images should be at least <strong>%1$d pixels</strong> wide.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
	} elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
		if ( ! current_theme_supports( 'custom-header', 'flex-height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
			printf( __( 'Images should be at least <strong>%1$d pixels</strong> tall.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
	if ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		if ( current_theme_supports( 'custom-header', 'width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
			printf( __( 'Suggested width is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
		if ( current_theme_supports( 'custom-header', 'height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
			printf( __( 'Suggested height is <strong>%1$d pixels</strong>.' ) . ' ', get_theme_support( 'custom-header', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
	<form enctype="multipart/form-data" id="upload-form" class="wp-upload-form" method="post" action="<?php echo esc_url( add_query_arg( 'step', 2 ) ) ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		<input type="file" id="upload" name="import" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
		<input type="hidden" name="action" value="save" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		$modal_update_href = esc_url( add_query_arg( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			'page' => 'custom-header',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
			'step' => 2,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
			'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
		), admin_url('themes.php') ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		<a id="choose-from-library-link" class="button"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
			data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
			data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
			data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ) ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	<?php if ( get_uploaded_header_images() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
<th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	<p><?php _e( 'You can choose one of your previously uploaded headers, or show a random one.' ) ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
		$this->show_header_selector( 'uploaded' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
	if ( ! empty( $this->default_headers ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
<th scope="row"><?php _e( 'Default Images' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	<p><?php _e( 'If you don&lsquo;t want to upload your own image, you can use one of these cool headers, or show a random one.' ) ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
<?php else: ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	<p><?php _e( 'You can use one of these cool headers or show a random one on each page.' ) ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		$this->show_header_selector( 'default' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	if ( get_header_image() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
<th scope="row"><?php _e( 'Remove Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
	<p><?php _e( 'This will remove the header image. You will not be able to restore any customizations.' ) ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
	<?php submit_button( __( 'Remove Header Image' ), 'button', 'removeheader', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	$default_image = get_theme_support( 'custom-header', 'default-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
	if ( $default_image && get_header_image() != $default_image ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
<th scope="row"><?php _e( 'Reset Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	<p><?php _e( 'This will restore the original header image. You will not be able to restore any customizations.' ) ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	<?php submit_button( __( 'Restore Original Header Image' ), 'button', 'resetheader', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
<?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
<h3><?php _e( 'Header Text' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
<tr valign="top">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
<th scope="row"><?php _e( 'Header Text' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
	<label><input type="checkbox" name="display-header-text" id="display-header-text"<?php checked( display_header_text() ); ?> /> <?php _e( 'Show header text with your image.' ); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
<tr valign="top" class="displaying-header-text">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
<th scope="row"><?php _e( 'Text Color' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
$header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
$default_color = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
	$default_color = '#' . get_theme_support( 'custom-header', 'default-text-color' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
	$default_color_attr = ' data-default-color="' . esc_attr( $default_color ) . '"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	echo '<input type="text" name="text-color" id="text-color" value="#' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	if ( $default_color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
		echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), $default_color ) . '</span>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
 * Fires just before the submit button in the custom header options form.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
do_action( 'custom_header_options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
<?php submit_button( null, 'primary', 'save-header-options' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
<?php }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
	 * Display second step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
	function step_2() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
		check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
			wp_die( __( 'Cheatin&#8217; uh?' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
		if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
			$attachment_id = absint( $_GET['file'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
			$file = get_attached_file( $attachment_id, true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
			$url = wp_get_attachment_image_src( $attachment_id, 'full');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
			$url = $url[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
		} elseif ( isset( $_POST ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
			extract($this->step_2_manage_upload());
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
		if ( file_exists( $file ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
			list( $width, $height, $type, $attr ) = getimagesize( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
			$data = wp_get_attachment_metadata( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
			$height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
			$width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
			unset( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
		$max_width = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
		// For flex, limit size of image displayed to 1500px unless theme says otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
		if ( current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
			$max_width = 1500;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		if ( current_theme_supports( 'custom-header', 'max-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
			$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
		$max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
		// If flexible height isn't supported and the image is the exact right size
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
		if ( ! current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
			&& $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
		{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
			// Add the meta-data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
			if ( file_exists( $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
				wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
			$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
			 * Fires after the header image is set or an error is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
			 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
			 * @param string $file          Path to the file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
			 * @param int    $attachment_id Attachment ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
			do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
			return $this->finished();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		} elseif ( $width > $max_width ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
			$oitar = $width / $max_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
			$image = wp_crop_image($attachment_id, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
			if ( ! $image || is_wp_error( $image ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
				wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
			/** This filter is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
			$image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
			$url = str_replace(basename($url), basename($image), $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
			$width = $width / $oitar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
			$height = $height / $oitar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
			$oitar = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
<?php screen_icon(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
<h2><?php _e( 'Crop Header Image' ); ?></h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
<form method="post" action="<?php echo esc_url(add_query_arg('step', 3)); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
	<p class="hide-if-no-js"><?php _e('Choose the part of the image you want to use as your header.'); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
	<p class="hide-if-js"><strong><?php _e( 'You need Javascript to choose a part of the image.'); ?></strong></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
	<div id="crop_image" style="position: relative">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
		<img src="<?php echo esc_url( $url ); ?>" id="upload" width="<?php echo $width; ?>" height="<?php echo $height; ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
	<input type="hidden" name="x1" id="x1" value="0"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
	<input type="hidden" name="y1" id="y1" value="0"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
	<input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
	<input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
	<input type="hidden" name="attachment_id" id="attachment_id" value="<?php echo esc_attr( $attachment_id ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
	<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
	<?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
	<input type="hidden" name="create-new-attachment" value="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
	<?php wp_nonce_field( 'custom-header-crop-image' ) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
	<p class="submit">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
	<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
	if ( isset( $oitar ) && 1 == $oitar && ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
		submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	 * Upload the file to be cropped in the second step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	function step_2_manage_upload() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
		$overrides = array('test_form' => false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		$uploaded_file = $_FILES['import'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'], false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
		$file = wp_handle_upload($uploaded_file, $overrides);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
		if ( isset($file['error']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
			wp_die( $file['error'],  __( 'Image Upload Error' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
		$url = $file['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   781
		$type = $file['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
		$file = $file['file'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
		$filename = basename($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
		// Construct the object array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		$object = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
			'post_title'     => $filename,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
			'post_content'   => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
			'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
			'guid'           => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
			'context'        => 'custom-header'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
		// Save the data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   795
		$attachment_id = wp_insert_attachment( $object, $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   799
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
	 * Display third step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
	function step_3() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		check_admin_referer( 'custom-header-crop-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
			wp_die( __( 'Cheatin&#8217; uh?' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
		if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
			wp_die( __( 'Cheatin&#8217; uh?' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
		if ( $_POST['oitar'] > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
			$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
			$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			$_POST['width'] = $_POST['width'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
			$_POST['height'] = $_POST['height'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
		$attachment_id = absint( $_POST['attachment_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
		$original = get_attached_file($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
		$max_width = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
		// For flex, limit size of image displayed to 1500px unless theme says otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
		if ( current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
			$max_width = 1500;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
		if ( current_theme_supports( 'custom-header', 'max-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
			$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
		$max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
		if ( ( current_theme_supports( 'custom-header', 'flex-height' ) && ! current_theme_supports( 'custom-header', 'flex-width' ) ) || $_POST['width'] > $max_width )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
			$dst_height = absint( $_POST['height'] * ( $max_width / $_POST['width'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		elseif ( current_theme_supports( 'custom-header', 'flex-height' ) && current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   836
			$dst_height = absint( $_POST['height'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
			$dst_height = get_theme_support( 'custom-header', 'height' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   839
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
		if ( ( current_theme_supports( 'custom-header', 'flex-width' ) && ! current_theme_supports( 'custom-header', 'flex-height' ) ) || $_POST['width'] > $max_width )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
			$dst_width = absint( $_POST['width'] * ( $max_width / $_POST['width'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
		elseif ( current_theme_supports( 'custom-header', 'flex-width' ) && current_theme_supports( 'custom-header', 'flex-height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
			$dst_width = absint( $_POST['width'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
			$dst_width = get_theme_support( 'custom-header', 'width' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
		if ( empty( $_POST['skip-cropping'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
			$cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
		elseif ( ! empty( $_POST['create-new-attachment'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
			$cropped = _copy_image_file( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   851
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   852
			$cropped = get_attached_file( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   853
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   854
		if ( ! $cropped || is_wp_error( $cropped ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   855
			wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   856
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
		/** This filter is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   859
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
		$parent = get_post($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
		$parent_url = $parent->guid;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
		$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
		$size = @getimagesize( $cropped );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   867
		// Construct the object array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		$object = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
			'ID' => $attachment_id,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
			'post_title' => basename($cropped),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   871
			'post_content' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
			'post_mime_type' => $image_type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
			'guid' => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			'context' => 'custom-header'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		if ( ! empty( $_POST['create-new-attachment'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   877
			unset( $object['ID'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   879
		// Update the attachment
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		$attachment_id = wp_insert_attachment( $object, $cropped );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
		wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $cropped ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   882
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		$width = $dst_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
		$height = $dst_height;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   885
		$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
		// cleanup
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   889
		if ( file_exists( $medium ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
			 * Filter the path of the file to delete.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
			 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
			 * @param string $medium Path to the file to delete.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
			@unlink( apply_filters( 'wp_delete_file', $medium ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   900
		if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
			/** This filter is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
			@unlink( apply_filters( 'wp_delete_file', $original ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   903
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   905
		return $this->finished();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	 * Display last step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
	function finished() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
		$this->step_1();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
	 * Display the page based on the current step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	function admin_page() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
		if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
			wp_die(__('You do not have permission to customize headers.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   927
		if ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
			$this->step_2();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
		elseif ( 3 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
			$this->step_3();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
			$this->step_1();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   936
	 * Unused since 3.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	function attachment_fields_to_edit( $form_fields ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
		return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   943
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   945
	 * Unused since 3.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   947
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   948
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	function filter_upload_tabs( $tabs ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
		return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
	 * Choose a header image, selected from existing uploaded and default headers,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
	 * or provide an array of uploaded header data (either new, or from media library).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
	 * @param mixed $choice Which header image to select. Allows for values of 'random-default-image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
	 * 	for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
	 * 	among the uploaded images; the key of a default image registered for that theme; and
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
	 * 	the key of an image uploaded for that theme (the basename of the URL).
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
	 *  Or an array of arguments: attachment_id, url, width, height. All are required.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
	final public function set_header_image( $choice ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
		if ( is_array( $choice ) || is_object( $choice ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
			$choice = (array) $choice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
			if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
			$choice['url'] = esc_url_raw( $choice['url'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
			$header_image_data = (object) array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
				'attachment_id' => $choice['attachment_id'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
				'url'           => $choice['url'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
				'thumbnail_url' => $choice['url'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
				'height'        => $choice['height'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
				'width'         => $choice['width'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
			update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
			set_theme_mod( 'header_image', $choice['url'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
			set_theme_mod( 'header_image_data', $header_image_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
		if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
			set_theme_mod( 'header_image', $choice );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
			remove_theme_mod( 'header_image_data' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		$uploaded = get_uploaded_header_images();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
		if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
			$header_image_data = $uploaded[ $choice ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
			$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
			if ( isset( $this->default_headers[ $choice ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
				$header_image_data = $this->default_headers[ $choice ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
		set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
		set_theme_mod( 'header_image_data', $header_image_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	 * Remove a header image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	final public function remove_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
		return $this->set_header_image( 'remove-header' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
	 * Reset a header image to the default image for the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
	 * This method does not do anything if the theme does not have a default header image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	final public function reset_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
		$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		$default = get_theme_support( 'custom-header', 'default-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
		if ( ! $default )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
			return $this->remove_header_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
		$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
		$default_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
		foreach ( $this->default_headers as $header => $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
			if ( $details['url'] == $default ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
				$default_data = $details;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1038
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1042
		set_theme_mod( 'header_image', $default );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
		set_theme_mod( 'header_image_data', (object) $default_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
}