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