wp/wp-admin/custom-header.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
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
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	public $admin_header_callback;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
	 * Callback for header div.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	 * @var callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	public $admin_image_div_callback;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
	 * Holds default headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
	 * @var array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
	 * @access private
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	public $default_headers = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    44
	 * @var bool
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	private $updated;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
	 * Constructor - Register administration header callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
	 * @param callback $admin_header_callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
	 * @param callback $admin_image_div_callback Optional custom image div output callback.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	public function __construct($admin_header_callback, $admin_image_div_callback = '') {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		$this->admin_header_callback = $admin_header_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		$this->admin_image_div_callback = $admin_image_div_callback;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		add_action( 'admin_menu', array( $this, 'init' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    60
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    61
		add_action( 'customize_save_after',         array( $this, 'customize_set_last_used' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
		add_action( 'wp_ajax_custom-header-crop',   array( $this, 'ajax_header_crop'        ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
		add_action( 'wp_ajax_custom-header-add',    array( $this, 'ajax_header_add'         ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
		add_action( 'wp_ajax_custom-header-remove', array( $this, 'ajax_header_remove'      ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
	 * Set up the hooks for the Custom Header admin page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	public function init() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
		$page = add_theme_page( __( 'Header' ), __( 'Header' ), 'edit_theme_options', 'custom-header', array( $this, 'admin_page' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
		if ( ! $page ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    76
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
		add_action( "admin_print_scripts-$page", array( $this, 'js_includes' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    79
		add_action( "admin_print_styles-$page", array( $this, 'css_includes' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
		add_action( "admin_head-$page", array( $this, 'help' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    81
		add_action( "admin_head-$page", array( $this, 'take_action' ), 50 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    82
		add_action( "admin_head-$page", array( $this, 'js' ), 50 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    83
		if ( $this->admin_header_callback ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
			add_action( "admin_head-$page", $this->admin_header_callback, 51 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
	 * Adds contextual help.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    93
	public function help() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
			'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
			'title'   => __('Overview'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
				'<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
    99
				'<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
   100
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
		get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
			'id'      => 'set-header-image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
			'title'   => __('Header Image'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
			'content' =>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
				'<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
   107
				'<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
   108
				'<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
   109
				'<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
   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-text',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
			'title'   => __('Header Text'),
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>' . 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
   117
				'<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
   118
				'<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
   119
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
		get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
			'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			'<p>' . __( '<a href="https://codex.wordpress.org/Appearance_Header_Screen" target="_blank">Documentation on Custom Header</a>' ) . '</p>' .
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
			'<p>' . __( '<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>' ) . '</p>'
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	 * Get the current step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
	 * @return int Current step
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
	public function step() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
		if ( ! isset( $_GET['step'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
		$step = (int) $_GET['step'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		if ( $step < 1 || 3 < $step ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
			( 2 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce-custom-header-upload'], 'custom-header-upload' ) ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
			( 3 == $step && ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'custom-header-crop-image' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
		)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
			return 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
		return $step;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 * Set up the enqueue for the JavaScript files.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
	public function js_includes() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
		if ( ( 1 == $step || 3 == $step ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
			wp_enqueue_media();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			wp_enqueue_script( 'custom-header' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
			if ( current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
				wp_enqueue_script( 'wp-color-picker' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		} elseif ( 2 == $step ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
			wp_enqueue_script('imgareaselect');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	 * Set up the enqueue for the CSS files
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
	 * @since 2.7.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
	public function css_includes() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
			wp_enqueue_style( 'wp-color-picker' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		elseif ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
			wp_enqueue_style('imgareaselect');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 * Execute custom header modification.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   186
	public function take_action() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
		if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
		if ( empty( $_POST ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
		if ( isset( $_POST['resetheader'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
			$this->reset_header_image();
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
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
		if ( isset( $_POST['removeheader'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
			$this->remove_header_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		if ( isset( $_POST['text-color'] ) && ! isset( $_POST['display-header-text'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			set_theme_mod( 'header_textcolor', 'blank' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		} elseif ( isset( $_POST['text-color'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
			check_admin_referer( 'custom-header-options', '_wpnonce-custom-header-options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
			$_POST['text-color'] = str_replace( '#', '', $_POST['text-color'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
			$color = preg_replace('/[^0-9a-fA-F]/', '', $_POST['text-color']);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
			if ( strlen($color) == 6 || strlen($color) == 3 )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
				set_theme_mod('header_textcolor', $color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			elseif ( ! $color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
				set_theme_mod( 'header_textcolor', 'blank' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
		if ( isset( $_POST['default-header'] ) ) {
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
			$this->set_header_image( $_POST['default-header'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
	 * Process the default headers
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
	public function process_default_headers() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
		global $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
		if ( !isset($_wp_default_headers) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		if ( ! empty( $this->default_headers ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   239
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   240
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   241
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
		$this->default_headers = $_wp_default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		$template_directory_uri = get_template_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
		$stylesheet_directory_uri = get_stylesheet_directory_uri();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		foreach ( array_keys($this->default_headers) as $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			$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
   247
			$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
   248
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
	 * Display UI for selecting one of several default headers.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
	 * Show the random image option if this theme has multiple header images.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
	 * Random image option is on by default if no header has been set.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   259
	public function show_header_selector( $type = 'default' ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		if ( 'default' == $type ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
			$headers = $this->default_headers;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			$headers = get_uploaded_header_images();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
			$type = 'uploaded';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		if ( 1 < count( $headers ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
			echo '<div class="random-header">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
			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
   270
			echo __( '<strong>Random:</strong> Show a different image on each page.' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
			echo '</label>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
			echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		echo '<div class="available-headers">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
		foreach ( $headers as $header_key => $header ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
			$header_thumbnail = $header['thumbnail_url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			$header_url = $header['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
			$header_desc = empty( $header['description'] ) ? '' : $header['description'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
			echo '<div class="default-header">';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
			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
   282
			$width = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
			if ( !empty( $header['attachment_id'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
				$width = ' width="230"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
			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
   286
			echo '</div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
		echo '<div class="clear"></div></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
	 * Execute JavaScript depending on step.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
	public function js() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
		if ( ( 1 == $step || 3 == $step ) && current_theme_supports( 'custom-header', 'header-text' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
			$this->js_1();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
		elseif ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
			$this->js_2();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   305
	 * Display JavaScript based on Step 1 and 3.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   309
	public function js_1() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
		$default_color = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
		if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
			$default_color = get_theme_support( 'custom-header', 'default-text-color' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
			if ( $default_color && false === strpos( $default_color, '#' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
				$default_color = '#' . $default_color;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   317
		?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   318
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
(function($){
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   321
	var default_color = '<?php echo $default_color; ?>',
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
		header_text_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	function pickColor(color) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		$('#name').css('color', color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		$('#desc').css('color', color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
		$('#text-color').val(color);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
	function toggle_text() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		var checked = $('#display-header-text').prop('checked'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
			text_color;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
		header_text_fields.toggle( checked );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
		if ( ! checked )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
		text_color = $('#text-color');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
		if ( '' == text_color.val().replace('#', '') ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
			text_color.val( default_color );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
			pickColor( default_color );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
			pickColor( text_color.val() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	$(document).ready(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
		var text_color = $('#text-color');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
		header_text_fields = $('.displaying-header-text');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
		text_color.wpColorPicker({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
			change: function( event, ui ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
				pickColor( text_color.wpColorPicker('color') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
			clear: function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
				pickColor( '' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
		$('#display-header-text').click( toggle_text );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		<?php if ( ! display_header_text() ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
		toggle_text();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
})(jQuery);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	 * Display JavaScript based on Step 2.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	 * @since 2.6.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   371
	public function js_2() { ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
	function onEndCrop( coords ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
		jQuery( '#x1' ).val(coords.x);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
		jQuery( '#y1' ).val(coords.y);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
		jQuery( '#width' ).val(coords.w);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		jQuery( '#height' ).val(coords.h);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
	jQuery(document).ready(function() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
		var xinit = <?php echo absint( get_theme_support( 'custom-header', 'width' ) ); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
		var yinit = <?php echo absint( get_theme_support( 'custom-header', 'height' ) ); ?>;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
		var ratio = xinit / yinit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
		var ximg = jQuery('img#upload').width();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
		var yimg = jQuery('img#upload').height();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
		if ( yimg < yinit || ximg < xinit ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
			if ( ximg / yimg > ratio ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
				yinit = yimg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
				xinit = yinit * ratio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
				xinit = ximg;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
				yinit = xinit / ratio;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
		jQuery('img#upload').imgAreaSelect({
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
			handles: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
			keys: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
			show: true,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
			x1: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
			y1: 0,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
			x2: xinit,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
			y2: yinit,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
			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
   407
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
			aspectRatio: xinit + ':' + 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
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
			if ( ! current_theme_supports( 'custom-header', 'flex-height' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
			maxHeight: <?php echo get_theme_support( 'custom-header', 'height' ); ?>,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
			if ( ! current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			maxWidth: <?php echo get_theme_support( 'custom-header', 'width' ); ?>,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
			<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
			?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
			onInit: function () {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
				jQuery('#width').val(xinit);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
				jQuery('#height').val(yinit);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
			},
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
			onSelectChange: function(img, c) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
				jQuery('#x1').val(c.x1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
				jQuery('#y1').val(c.y1);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
				jQuery('#width').val(c.width);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
				jQuery('#height').val(c.height);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
		});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
	});
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
<?php
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
	 * Display first step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
	public function step_1() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
		$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
<div class="wrap">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   448
<h2><?php _e( 'Custom Header' ); ?></h2>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   450
<?php if ( current_user_can( 'customize' ) ) { ?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
<div class="notice notice-info hide-if-no-customize">
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
	<p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
		<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
		printf(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   455
			__( 'You can now manage and live-preview Custom Header in the <a href="%1$s">Customizer</a>.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
			admin_url( 'customize.php?autofocus[control]=header_image' )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
		?>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
	</p>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
</div>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   461
<?php } ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
<?php if ( ! empty( $this->updated ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
<div id="message" class="updated">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
<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
   466
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
<h3><?php _e( 'Header Image' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
<?php if ( get_custom_header() || display_header_text() ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
<th scope="row"><?php _e( 'Preview' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
<td>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
	if ( $this->admin_image_div_callback ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
		call_user_func( $this->admin_image_div_callback );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
		$custom_header = get_custom_header();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
		$header_image = get_header_image();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
		if ( $header_image ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
			$header_image_style = 'background-image:url(' . esc_url( $header_image ) . ');';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
		}  else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
			$header_image_style = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
		if ( $custom_header->width )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
			$header_image_style .= 'max-width:' . $custom_header->width . 'px;';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
		if ( $custom_header->height )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
			$header_image_style .= 'height:' . $custom_header->height . 'px;';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
	<div id="headimg" style="<?php echo $header_image_style; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		if ( display_header_text() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
			$style = ' style="color:#' . get_header_textcolor() . ';"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
			$style = ' style="display:none;"';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   503
		<h1><a id="name" class="displaying-header-text" <?php echo $style; ?> onclick="return false;" href="<?php bloginfo('url'); ?>" tabindex="-1"><?php bloginfo( 'name' ); ?></a></h1>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		<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
   505
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   512
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
<th scope="row"><?php _e( 'Select Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	<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
   516
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	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
   518
		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
   519
	} elseif ( current_theme_supports( 'custom-header', 'flex-height' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		if ( ! current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
			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
   522
	} elseif ( current_theme_supports( 'custom-header', 'flex-width' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
		if ( ! current_theme_supports( 'custom-header', 'flex-height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
			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
   525
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
	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
   527
		if ( current_theme_supports( 'custom-header', 'width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
			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
   529
		if ( current_theme_supports( 'custom-header', 'height' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
			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
   531
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
	?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
	<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
   534
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
		<label for="upload"><?php _e( 'Choose an image from your computer:' ); ?></label><br />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
		<input type="file" id="upload" name="import" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
		<input type="hidden" name="action" value="save" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		<?php wp_nonce_field( 'custom-header-upload', '_wpnonce-custom-header-upload' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		<?php submit_button( __( 'Upload' ), 'button', 'submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
		$modal_update_href = esc_url( add_query_arg( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
			'page' => 'custom-header',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
			'step' => 2,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
			'_wpnonce-custom-header-upload' => wp_create_nonce('custom-header-upload'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
		), admin_url('themes.php') ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		<label for="choose-from-library-link"><?php _e( 'Or choose an image from your media library:' ); ?></label><br />
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   550
		<button id="choose-from-library-link" class="button"
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
			data-update-link="<?php echo esc_attr( $modal_update_href ); ?>"
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
			data-choose="<?php esc_attr_e( 'Choose a Custom Header' ); ?>"
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
			data-update="<?php esc_attr_e( 'Set as header' ); ?>"><?php _e( 'Choose Image' ); ?></button>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
<form method="post" action="<?php echo esc_url( add_query_arg( 'step', 1 ) ) ?>">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   563
<?php submit_button( null, 'screen-reader-text', 'save-header-options', false ); ?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
<tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
	<?php if ( get_uploaded_header_images() ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   567
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
<th scope="row"><?php _e( 'Uploaded Images' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	<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
   571
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
		$this->show_header_selector( 'uploaded' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
	if ( ! empty( $this->default_headers ) ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
<th scope="row"><?php _e( 'Default Images' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
<?php if ( current_theme_supports( 'custom-header', 'uploads' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
	<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
   583
<?php else: ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
	<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
   585
<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
		$this->show_header_selector( 'default' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	if ( get_header_image() ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   593
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
<th scope="row"><?php _e( 'Remove Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
	<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
   597
	<?php submit_button( __( 'Remove Header Image' ), 'button', 'removeheader', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
	<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
	$default_image = get_theme_support( 'custom-header', 'default-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
	if ( $default_image && get_header_image() != $default_image ) : ?>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
<th scope="row"><?php _e( 'Reset Image' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	<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
   608
	<?php submit_button( __( 'Restore Original Header Image' ), 'button', 'resetheader', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
<?php if ( current_theme_supports( 'custom-header', 'header-text' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
<h3><?php _e( 'Header Text' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
<table class="form-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
<tbody>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
<tr>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
<th scope="row"><?php _e( 'Header Text' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
	<p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
	<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
   626
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   630
<tr class="displaying-header-text">
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
<th scope="row"><?php _e( 'Text Color' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
<td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
	<p>
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   634
	<?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   635
	$default_color = '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   636
	if ( current_theme_supports( 'custom-header', 'default-text-color' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   637
		$default_color = get_theme_support( 'custom-header', 'default-text-color' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
		if ( $default_color && false === strpos( $default_color, '#' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   639
			$default_color = '#' . $default_color;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   640
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   641
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   642
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   643
	$default_color_attr = $default_color ? ' data-default-color="' . esc_attr( $default_color ) . '"' : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   644
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   645
	$header_textcolor = display_header_text() ? get_header_textcolor() : get_theme_support( 'custom-header', 'default-text-color' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   646
	if ( $header_textcolor && false === strpos( $header_textcolor, '#' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
		$header_textcolor = '#' . $header_textcolor;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   648
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   649
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   650
	echo '<input type="text" name="text-color" id="text-color" value="' . esc_attr( $header_textcolor ) . '"' . $default_color_attr . ' />';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   651
	if ( $default_color ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   652
		echo ' <span class="description hide-if-js">' . sprintf( _x( 'Default: %s', 'color' ), esc_html( $default_color ) ) . '</span>';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   653
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   654
	?>
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
</td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
<?php endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
 * Fires just before the submit button in the custom header options form.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
do_action( 'custom_header_options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
<?php submit_button( null, 'primary', 'save-header-options' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
<?php }
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
	 * Display second step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   682
	public function step_2() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
		check_admin_referer('custom-header-upload', '_wpnonce-custom-header-upload');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   685
			wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		if ( empty( $_POST ) && isset( $_GET['file'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
			$attachment_id = absint( $_GET['file'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
			$file = get_attached_file( $attachment_id, true );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   690
			$url = wp_get_attachment_image_src( $attachment_id, 'full' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
			$url = $url[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
		} elseif ( isset( $_POST ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   693
			$data = $this->step_2_manage_upload();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   694
			$attachment_id = $data['attachment_id'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   695
			$file = $data['file'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   696
			$url = $data['url'];
0
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
		if ( file_exists( $file ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
			list( $width, $height, $type, $attr ) = getimagesize( $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
			$data = wp_get_attachment_metadata( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
			$height = isset( $data[ 'height' ] ) ? $data[ 'height' ] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
			$width = isset( $data[ 'width' ] ) ? $data[ 'width' ] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
			unset( $data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
		$max_width = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		// For flex, limit size of image displayed to 1500px unless theme says otherwise
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
		if ( current_theme_supports( 'custom-header', 'flex-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
			$max_width = 1500;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
		if ( current_theme_supports( 'custom-header', 'max-width' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
			$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
		$max_width = max( $max_width, get_theme_support( 'custom-header', 'width' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
		// 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
   718
		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
   719
			&& $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
   720
		{
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
			// Add the meta-data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
			if ( file_exists( $file ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
				wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $file ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
			$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
			/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
			 * Fires after the header image is set or an error is returned.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
			 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
			 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
			 * @param string $file          Path to the file.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
			 * @param int    $attachment_id Attachment ID.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
			 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
			do_action( 'wp_create_file_in_uploads', $file, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
			return $this->finished();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
		} elseif ( $width > $max_width ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
			$oitar = $width / $max_width;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
			$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
   741
			if ( ! $image || is_wp_error( $image ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
				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
   743
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
			/** This filter is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
			$image = apply_filters( 'wp_create_file_in_uploads', $image, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
			$url = str_replace(basename($url), basename($image), $url);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
			$width = $width / $oitar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
			$height = $height / $oitar;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
			$oitar = 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
<h2><?php _e( 'Crop Header Image' ); ?></h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
<form method="post" action="<?php echo esc_url(add_query_arg('step', 3)); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
	<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
   760
	<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
   761
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	<div id="crop_image" style="position: relative">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
		<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
   764
	</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   766
	<input type="hidden" name="x1" id="x1" value="0"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   767
	<input type="hidden" name="y1" id="y1" value="0"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   768
	<input type="hidden" name="width" id="width" value="<?php echo esc_attr( $width ); ?>"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   769
	<input type="hidden" name="height" id="height" value="<?php echo esc_attr( $height ); ?>"/>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
	<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
   771
	<input type="hidden" name="oitar" id="oitar" value="<?php echo esc_attr( $oitar ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   772
	<?php if ( empty( $_POST ) && isset( $_GET['file'] ) ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   773
	<input type="hidden" name="create-new-attachment" value="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   774
	<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   775
	<?php wp_nonce_field( 'custom-header-crop-image' ) ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   776
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   777
	<p class="submit">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   778
	<?php submit_button( __( 'Crop and Publish' ), 'primary', 'submit', false ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   779
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   780
	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
   781
		submit_button( __( 'Skip Cropping, Publish Image as Is' ), 'secondary', 'skip-cropping', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   782
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   783
	</p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   784
</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   785
</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   786
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   787
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   788
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   789
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   790
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   791
	 * Upload the file to be cropped in the second step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   792
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   793
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   794
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
	public function step_2_manage_upload() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   796
		$overrides = array('test_form' => false);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   797
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   798
		$uploaded_file = $_FILES['import'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
		$wp_filetype = wp_check_filetype_and_ext( $uploaded_file['tmp_name'], $uploaded_file['name'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   800
		if ( ! wp_match_mime_types( 'image', $wp_filetype['type'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   801
			wp_die( __( 'The uploaded file is not a valid image. Please try again.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   802
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   803
		$file = wp_handle_upload($uploaded_file, $overrides);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   804
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   805
		if ( isset($file['error']) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   806
			wp_die( $file['error'],  __( 'Image Upload Error' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   807
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   808
		$url = $file['url'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   809
		$type = $file['type'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   810
		$file = $file['file'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   811
		$filename = basename($file);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   812
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
		// Construct the object array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
		$object = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
			'post_title'     => $filename,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
			'post_content'   => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
			'post_mime_type' => $type,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
			'guid'           => $url,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
			'context'        => 'custom-header'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   820
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   821
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   822
		// Save the data
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
		$attachment_id = wp_insert_attachment( $object, $file );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
		return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   825
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   827
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
	 * Display third step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   829
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   830
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   831
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   832
	public function step_3() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   833
		check_admin_referer( 'custom-header-crop-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   834
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   835
		if ( ! current_theme_supports( 'custom-header', 'uploads' ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
			wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   837
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   838
		if ( ! empty( $_POST['skip-cropping'] ) && ! ( current_theme_supports( 'custom-header', 'flex-height' ) || current_theme_supports( 'custom-header', 'flex-width' ) ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
			wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   840
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   841
		if ( $_POST['oitar'] > 1 ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   842
			$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   843
			$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   844
			$_POST['width'] = $_POST['width'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   845
			$_POST['height'] = $_POST['height'] * $_POST['oitar'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   846
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   847
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   848
		$attachment_id = absint( $_POST['attachment_id'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   849
		$original = get_attached_file($attachment_id);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   850
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   851
		$dimensions = $this->get_header_dimensions( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
			'height' => $_POST['height'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
			'width'  => $_POST['width'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
		$height = $dimensions['dst_height'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
		$width = $dimensions['dst_width'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   857
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   858
		if ( empty( $_POST['skip-cropping'] ) )
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
			$cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $width, $height );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   860
		elseif ( ! empty( $_POST['create-new-attachment'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   861
			$cropped = _copy_image_file( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   862
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   863
			$cropped = get_attached_file( $attachment_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   864
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   865
		if ( ! $cropped || is_wp_error( $cropped ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   866
			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
   867
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   868
		/** This filter is documented in wp-admin/custom-header.php */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   869
		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   870
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
		$object = $this->create_attachment_object( $cropped, $attachment_id );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   872
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   873
		if ( ! empty( $_POST['create-new-attachment'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   874
			unset( $object['ID'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   875
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   876
		// Update the attachment
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
		$attachment_id = $this->insert_attachment( $object, $cropped );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   878
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
		$url = $object['guid'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   880
		$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   881
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
		// Cleanup.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   883
		$medium = str_replace( basename( $original ), 'midsize-' . basename( $original ), $original );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   884
		if ( file_exists( $medium ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
			wp_delete_file( $medium );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   886
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   887
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   888
		if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
			wp_delete_file( $original );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   890
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   891
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
		return $this->finished();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	 * Display last step of custom header image page.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   899
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
	public function finished() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
		$this->updated = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
		$this->step_1();
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
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	 * Display the page based on the current step.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	 * @since 2.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   910
	public function admin_page() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
		if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
			wp_die(__('You do not have permission to customize headers.'));
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   913
		$step = $this->step();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
		if ( 2 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
			$this->step_2();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
		elseif ( 3 == $step )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
			$this->step_3();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
			$this->step_1();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   920
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   921
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   922
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   923
	 * Unused since 3.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   924
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   925
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   926
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
	public function attachment_fields_to_edit( $form_fields ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   928
		return $form_fields;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   929
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   930
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   931
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   932
	 * Unused since 3.5.0.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   933
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   934
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   935
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
	public function filter_upload_tabs( $tabs ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   937
		return $tabs;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   938
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   939
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   940
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   941
	 * Choose a header image, selected from existing uploaded and default headers,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   942
	 * 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
   943
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   944
	 * @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
   945
	 * 	for randomly cycling among the default images; 'random-uploaded-image', for randomly cycling
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   946
	 * 	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
   947
	 * 	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
   948
	 *  Or an array of arguments: attachment_id, url, width, height. All are required.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   949
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   950
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   951
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   952
	final public function set_header_image( $choice ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   953
		if ( is_array( $choice ) || is_object( $choice ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   954
			$choice = (array) $choice;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   955
			if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   956
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   957
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   958
			$choice['url'] = esc_url_raw( $choice['url'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   959
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   960
			$header_image_data = (object) array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   961
				'attachment_id' => $choice['attachment_id'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   962
				'url'           => $choice['url'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   963
				'thumbnail_url' => $choice['url'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   964
				'height'        => $choice['height'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   965
				'width'         => $choice['width'],
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
			update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
			set_theme_mod( 'header_image', $choice['url'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   970
			set_theme_mod( 'header_image_data', $header_image_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   971
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   974
		if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ) ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			set_theme_mod( 'header_image', $choice );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   976
			remove_theme_mod( 'header_image_data' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
			return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   978
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
		$uploaded = get_uploaded_header_images();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
		if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
			$header_image_data = $uploaded[ $choice ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
			$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
			if ( isset( $this->default_headers[ $choice ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   987
				$header_image_data = $this->default_headers[ $choice ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   988
			else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
				return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
		set_theme_mod( 'header_image', esc_url_raw( $header_image_data['url'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
		set_theme_mod( 'header_image_data', $header_image_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
	 * Remove a header image.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1000
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
	final public function remove_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
		return $this->set_header_image( 'remove-header' );
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
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	 * Reset a header image to the default image for the theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	 * 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
  1009
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1011
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1012
	final public function reset_header_image() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1013
		$this->process_default_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
		$default = get_theme_support( 'custom-header', 'default-image' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1016
		if ( ! $default )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			return $this->remove_header_image();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1018
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
		$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1020
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		$default_data = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
		foreach ( $this->default_headers as $header => $details ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
			if ( $details['url'] == $default ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
				$default_data = $details;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1029
		set_theme_mod( 'header_image', $default );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1030
		set_theme_mod( 'header_image_data', (object) $default_data );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1032
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1033
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1034
	 * Calculate width and height based on what the currently selected theme supports.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1035
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1036
	 * @return array dst_height and dst_width of header image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1037
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
	final public function get_header_dimensions( $dimensions ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1039
		$max_width = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1040
		$width = absint( $dimensions['width'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1041
		$height = absint( $dimensions['height'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
		$theme_height = get_theme_support( 'custom-header', 'height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1043
		$theme_width = get_theme_support( 'custom-header', 'width' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1044
		$has_flex_width = current_theme_supports( 'custom-header', 'flex-width' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1045
		$has_flex_height = current_theme_supports( 'custom-header', 'flex-height' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1046
		$has_max_width = current_theme_supports( 'custom-header', 'max-width' ) ;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1047
		$dst = array( 'dst_height' => null, 'dst_width' => null );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1048
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
		// For flex, limit size of image displayed to 1500px unless theme says otherwise
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
		if ( $has_flex_width ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
			$max_width = 1500;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
		if ( $has_max_width ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
			$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
		$max_width = max( $max_width, $theme_width );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
		if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1060
			$dst['dst_height'] = absint( $height * ( $max_width / $width ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
		elseif ( $has_flex_height && $has_flex_width ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
			$dst['dst_height'] = $height;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
		else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
			$dst['dst_height'] = $theme_height;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1069
		if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
			$dst['dst_width'] = absint( $width * ( $max_width / $width ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
		elseif ( $has_flex_width && $has_flex_height ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1073
			$dst['dst_width'] = $width;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1074
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
		else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
			$dst['dst_width'] = $theme_width;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1078
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1079
		return $dst;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1080
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1081
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1083
	 * Create an attachment 'object'.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1084
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1085
	 * @param string $cropped Cropped image URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
	 * @param int $parent_attachment_id Attachment ID of parent image.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
	 * @return array Attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
	final public function create_attachment_object( $cropped, $parent_attachment_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1091
		$parent = get_post( $parent_attachment_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1092
		$parent_url = $parent->guid;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1093
		$url = str_replace( basename( $parent_url ), basename( $cropped ), $parent_url );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
		$size = @getimagesize( $cropped );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1096
		$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
		$object = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1099
			'ID' => $parent_attachment_id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1100
			'post_title' => basename($cropped),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1101
			'post_content' => $url,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1102
			'post_mime_type' => $image_type,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1103
			'guid' => $url,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1104
			'context' => 'custom-header'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1106
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1107
		return $object;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1109
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1111
	 * Insert an attachment and its metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1112
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1113
	 * @param array $object Attachment object.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1114
	 * @param string $cropped Cropped image URL.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1115
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1116
	 * @return int Attachment ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1117
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1118
	final public function insert_attachment( $object, $cropped ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1119
		$attachment_id = wp_insert_attachment( $object, $cropped );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1120
		$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1121
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
		 * Filter the header image attachment metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1123
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
		 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1125
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1126
		 * @see wp_generate_attachment_metadata()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
		 * @param array $metadata Attachment metadata.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1130
		$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
		wp_update_attachment_metadata( $attachment_id, $metadata );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
		return $attachment_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1133
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1134
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1135
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1136
	 * Gets attachment uploaded by Media Manager, crops it, then saves it as a
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1137
	 * new object. Returns JSON-encoded object details.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1138
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
	public function ajax_header_crop() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
		check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
		if ( ! current_user_can( 'edit_theme_options' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
		if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
		$crop_details = $_POST['cropDetails'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
		$dimensions = $this->get_header_dimensions( array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
			'height' => $crop_details['height'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
			'width'  => $crop_details['width'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
		) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1157
		$attachment_id = absint( $_POST['id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1158
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1159
		$cropped = wp_crop_image(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1160
			$attachment_id,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1161
			(int) $crop_details['x1'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1162
			(int) $crop_details['y1'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1163
			(int) $crop_details['width'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1164
			(int) $crop_details['height'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1165
			(int) $dimensions['dst_width'],
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1166
			(int) $dimensions['dst_height']
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1167
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1168
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1169
		if ( ! $cropped || is_wp_error( $cropped ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1170
			wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1171
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1172
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1173
		/** This filter is documented in wp-admin/custom-header.php */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1174
		$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1175
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1176
		$object = $this->create_attachment_object( $cropped, $attachment_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1177
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1178
		unset( $object['ID'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
		$new_attachment_id = $this->insert_attachment( $object, $cropped );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
		$object['attachment_id'] = $new_attachment_id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
		$object['width']         = $dimensions['dst_width'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
		$object['height']        = $dimensions['dst_height'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
		wp_send_json_success( $object );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
	 * Given an attachment ID for a header image, updates its "last used"
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
	 * timestamp to now.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
	 * Triggered when the user tries adds a new header image from the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
	 * Media Manager, even if s/he doesn't save that change.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1195
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
	public function ajax_header_add() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1197
		check_ajax_referer( 'header-add', 'nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1198
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
		if ( ! current_user_can( 'edit_theme_options' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1200
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1202
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1203
		$attachment_id = absint( $_POST['attachment_id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1204
		if ( $attachment_id < 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1205
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1206
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1207
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1208
		$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1209
		update_post_meta( $attachment_id, $key, time() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
		update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
		wp_send_json_success();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
	 * Given an attachment ID for a header image, unsets it as a user-uploaded
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
	 * header image for the current theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
	 * Triggered when the user clicks the overlay "X" button next to each image
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
	 * choice in the Customizer's Header tool.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
	public function ajax_header_remove() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
		check_ajax_referer( 'header-remove', 'nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
		if ( ! current_user_can( 'edit_theme_options' ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1229
		$attachment_id = absint( $_POST['attachment_id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1230
		if ( $attachment_id < 1 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1231
			wp_send_json_error();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1232
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1233
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1234
		$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1235
		delete_post_meta( $attachment_id, $key );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1236
		delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1237
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1238
		wp_send_json_success();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1239
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1240
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1241
	public function customize_set_last_used( $wp_customize ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1242
		$data = $wp_customize->get_setting( 'header_image_data' )->post_value();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1243
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1244
		if ( ! isset( $data['attachment_id'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1245
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1246
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1247
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1248
		$attachment_id = $data['attachment_id'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1249
		$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1250
		update_post_meta( $attachment_id, $key, time() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1251
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1252
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1253
	public function get_default_header_images() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1254
		$this->process_default_headers();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1255
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1256
		// Get the default image if there is one.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1257
		$default = get_theme_support( 'custom-header', 'default-image' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1258
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1259
		if ( ! $default ) { // If not,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1260
			return $this->default_headers; // easy peasy.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1261
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1262
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1263
		$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1264
		$already_has_default = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1265
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1266
		foreach ( $this->default_headers as $k => $h ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1267
			if ( $h['url'] === $default ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1268
				$already_has_default = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1269
				break;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1270
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1271
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1272
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1273
		if ( $already_has_default ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1274
			return $this->default_headers;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1275
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1276
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1277
		// If the one true image isn't included in the default set, prepend it.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1278
		$header_images = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1279
		$header_images['default'] = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1280
			'url'           => $default,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1281
			'thumbnail_url' => $default,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1282
			'description'   => 'Default'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1283
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1284
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1285
		// The rest of the set comes after.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1286
		$header_images = array_merge( $header_images, $this->default_headers );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1287
		return $header_images;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1288
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1289
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1290
	public function get_uploaded_header_images() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1291
		$header_images = get_uploaded_header_images();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1292
		$timestamp_key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1293
		$alt_text_key = '_wp_attachment_image_alt';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1294
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1295
		foreach ( $header_images as &$header_image ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1296
			$header_meta = get_post_meta( $header_image['attachment_id'] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1297
			$header_image['timestamp'] = isset( $header_meta[ $timestamp_key ] ) ? $header_meta[ $timestamp_key ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1298
			$header_image['alt_text'] = isset( $header_meta[ $alt_text_key ] ) ? $header_meta[ $alt_text_key ] : '';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1299
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1300
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1301
		return $header_images;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1302
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
}