wp/wp-includes/class-wp-customize-manager.php
author ymh <ymh.work@gmail.com>
Tue, 09 Jun 2015 03:35:32 +0200
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
permissions -rw-r--r--
upgrade wordpress + plugins
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     3
 * WordPress Customize Manager classes
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Customize
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
     9
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    10
/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    11
 * Customize Manager class.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    12
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    13
 * Bootstraps the Customize experience on the server-side.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    14
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    15
 * Sets up the theme-switching process if a theme other than the active one is
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    16
 * being previewed and customized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    17
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
 * Serves as a factory for Customize Controls and Settings, and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
 * instantiates default Customize Controls and Settings.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    20
 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    21
 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    22
 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
final class WP_Customize_Manager {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    24
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
	 * An instance of the theme being previewed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
	 * @var WP_Theme
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    28
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	protected $theme;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    30
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    31
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    32
	 * The directory name of the previously active theme (within the theme_root).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    33
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    34
	 * @var string
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    35
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
	protected $original_stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    39
	 * Whether this is a Customizer pageload.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    40
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    41
	 * @var boolean
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    42
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	protected $previewing = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    45
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    46
	 * Methods and properties deailing with managing widgets in the Customizer.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    47
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    48
	 * @var WP_Customize_Widgets
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    49
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    50
	public $widgets;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    51
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    52
	protected $settings   = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
	protected $containers = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    54
	protected $panels     = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    55
	protected $sections   = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    56
	protected $controls   = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
	protected $nonce_tick;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
	protected $customized;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    62
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    63
	 * Controls that may be rendered from JS templates.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    64
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    65
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    66
	 * @access protected
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    67
	 * @var array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    68
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    69
	protected $registered_control_types = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    70
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    71
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    72
	 * Unsanitized values for Customize Settings parsed from $_POST['customized'].
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    73
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    74
	 * @var array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    75
	 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
	private $_post_values;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
	 * Constructor.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
	public function __construct() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    84
		require_once( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    85
		require_once( ABSPATH . WPINC . '/class-wp-customize-panel.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    86
		require_once( ABSPATH . WPINC . '/class-wp-customize-section.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    87
		require_once( ABSPATH . WPINC . '/class-wp-customize-control.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    88
		require_once( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    90
		$this->widgets = new WP_Customize_Widgets( $this );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
		add_filter( 'wp_die_handler', array( $this, 'wp_die_handler' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    94
		add_action( 'setup_theme', array( $this, 'setup_theme' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    95
		add_action( 'wp_loaded',   array( $this, 'wp_loaded' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
		// Run wp_redirect_status late to make sure we override the status last.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
		add_action( 'wp_redirect_status', array( $this, 'wp_redirect_status' ), 1000 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
		// Do not spawn cron (especially the alternate cron) while running the Customizer.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
		remove_action( 'init', 'wp_cron' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
		// Do not run update checks when rendering the controls.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
		remove_action( 'admin_init', '_maybe_update_core' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
		remove_action( 'admin_init', '_maybe_update_plugins' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
		remove_action( 'admin_init', '_maybe_update_themes' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
		add_action( 'wp_ajax_customize_save',           array( $this, 'save' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   109
		add_action( 'wp_ajax_customize_refresh_nonces', array( $this, 'refresh_nonces' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
		add_action( 'customize_register',                 array( $this, 'register_controls' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
		add_action( 'customize_register',                 array( $this, 'register_dynamic_settings' ), 11 ); // allow code to create settings first
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
		add_action( 'customize_controls_init',            array( $this, 'prepare_controls' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
		add_action( 'customize_controls_enqueue_scripts', array( $this, 'enqueue_control_scripts' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
	 * Return true if it's an AJAX request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
	 * @since 3.4.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
	 * @since 4.2.0 Added `$action` param.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
	 * @access public
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
	 * @param string|null $action Whether the supplied AJAX action is being run.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
	 * @return bool True if it's an AJAX request, false otherwise.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	public function doing_ajax( $action = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
		$doing_ajax = ( defined( 'DOING_AJAX' ) && DOING_AJAX );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   129
		if ( ! $doing_ajax ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   130
			return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   131
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   132
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		if ( ! $action ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   134
			return true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
			/*
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
			 * Note: we can't just use doing_action( "wp_ajax_{$action}" ) because we need
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   138
			 * to check before admin-ajax.php gets to that point.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   139
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
			return isset( $_REQUEST['action'] ) && wp_unslash( $_REQUEST['action'] ) === $action;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   141
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
	 * Custom wp_die wrapper. Returns either the standard message for UI
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
	 * or the AJAX message.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
	 * @param mixed $ajax_message AJAX return
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
	 * @param mixed $message UI message
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
	protected function wp_die( $ajax_message, $message = null ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
		if ( $this->doing_ajax() || isset( $_POST['customized'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
			wp_die( $ajax_message );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   156
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   158
		if ( ! $message ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
			$message = __( 'Cheatin&#8217; uh?' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   160
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
		wp_die( $message );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	 * Return the AJAX wp_die() handler if it's a customized request.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
	public function wp_die_handler() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
		if ( $this->doing_ajax() || isset( $_POST['customized'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
			return '_ajax_wp_die_handler';
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   175
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
		return '_default_wp_die_handler';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
	 * Start preview and customize theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
	 * Check if customize query variable exist. Init filters to filter the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
	public function setup_theme() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		send_origin_headers();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   190
		$doing_ajax_or_is_customized = ( $this->doing_ajax() || isset( $_POST['customized'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   191
		if ( is_admin() && ! $doing_ajax_or_is_customized ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   192
			auth_redirect();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   193
		} elseif ( $doing_ajax_or_is_customized && ! is_user_logged_in() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   194
			$this->wp_die( 0 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   195
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		show_admin_bar( false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   199
		if ( ! current_user_can( 'customize' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
			$this->wp_die( -1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   201
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
		$this->original_stylesheet = get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
		$this->theme = wp_get_theme( isset( $_REQUEST['theme'] ) ? $_REQUEST['theme'] : null );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
		if ( $this->is_theme_active() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
			// Once the theme is loaded, we'll validate it.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
			add_action( 'after_setup_theme', array( $this, 'after_setup_theme' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
		} else {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   211
			// If the requested theme is not the active theme and the user doesn't have the
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   212
			// switch_themes cap, bail.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   213
			if ( ! current_user_can( 'switch_themes' ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
				$this->wp_die( -1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   215
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
			// If the theme has errors while loading, bail.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   218
			if ( $this->theme()->errors() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
				$this->wp_die( -1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   220
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   222
			// If the theme isn't allowed per multisite settings, bail.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   223
			if ( ! $this->theme()->is_allowed() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
				$this->wp_die( -1 );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   225
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		$this->start_previewing_theme();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
	 * Callback to validate a theme once it is loaded
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   236
	public function after_setup_theme() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   237
		$doing_ajax_or_is_customized = ( $this->doing_ajax() || isset( $_SERVER['customized'] ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   238
		if ( ! $doing_ajax_or_is_customized && ! validate_current_theme() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
			wp_redirect( 'themes.php?broken=true' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
			exit;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   245
	 * If the theme to be previewed isn't the active theme, add filter callbacks
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   246
	 * to swap it out at runtime.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
	public function start_previewing_theme() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		// Bail if we're already previewing.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   252
		if ( $this->is_preview() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   254
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		$this->previewing = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
		if ( ! $this->is_theme_active() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
			add_filter( 'template', array( $this, 'get_template' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
			add_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
			add_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   263
			// @link: https://core.trac.wordpress.org/ticket/20027
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
			add_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
			add_filter( 'pre_option_template', array( $this, 'get_template' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
			// Handle custom theme roots.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
			add_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
			add_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
		 * Fires once the Customizer theme preview has started.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		do_action( 'start_previewing_theme', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	 * Stop previewing the selected theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	 * Removes filters to change the current theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
	public function stop_previewing_theme() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
		if ( ! $this->is_preview() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
			return;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   292
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		$this->previewing = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
		if ( ! $this->is_theme_active() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
			remove_filter( 'template', array( $this, 'get_template' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
			remove_filter( 'stylesheet', array( $this, 'get_stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
			remove_filter( 'pre_option_current_theme', array( $this, 'current_theme' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   301
			// @link: https://core.trac.wordpress.org/ticket/20027
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
			remove_filter( 'pre_option_stylesheet', array( $this, 'get_stylesheet' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
			remove_filter( 'pre_option_template', array( $this, 'get_template' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
			// Handle custom theme roots.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
			remove_filter( 'pre_option_stylesheet_root', array( $this, 'get_stylesheet_root' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
			remove_filter( 'pre_option_template_root', array( $this, 'get_template_root' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   310
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   311
		 * Fires once the Customizer theme preview has stopped.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   312
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   313
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   314
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   315
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   316
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
		do_action( 'stop_previewing_theme', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
	 * Get the theme being customized.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
	 * @return WP_Theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
	public function theme() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   328
		if ( ! $this->theme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   329
			$this->theme = wp_get_theme();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   330
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
		return $this->theme;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
	 * Get the registered settings.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	public function settings() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		return $this->settings;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
	 * Get the registered controls.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
	public function controls() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
		return $this->controls;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   357
	 * Get the registered containers.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   358
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   359
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   360
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   361
	 * @return array
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   362
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   363
	public function containers() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   364
		return $this->containers;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   365
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   366
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   367
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
	 * Get the registered sections.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
	 * @return array
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
	public function sections() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
		return $this->sections;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   379
	 * Get the registered panels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   380
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   381
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   382
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   383
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   384
	 * @return array Panels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   385
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   386
	public function panels() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   387
		return $this->panels;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   388
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   389
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   390
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	 * Checks if the current theme is active.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
	 * @return bool
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
	public function is_theme_active() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
		return $this->get_stylesheet() == $this->original_stylesheet;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	 * Register styles/scripts and initialize the preview of each setting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
	public function wp_loaded() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   407
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   408
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   409
		 * Fires once WordPress has loaded, allowing scripts and styles to be initialized.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   410
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   411
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   412
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   413
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   414
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
		do_action( 'customize_register', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
		if ( $this->is_preview() && ! is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
			$this->customize_preview_init();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	 * Prevents AJAX requests from following redirects when previewing a theme
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
	 * by issuing a 200 response instead of a 30x.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
	 * Instead, the JS will sniff out the location header.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	 * @param $status
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
	 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
	public function wp_redirect_status( $status ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
		if ( $this->is_preview() && ! is_admin() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			return 200;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
		return $status;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   440
	 * Parse the incoming $_POST['customized'] JSON data and store the unsanitized
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   441
	 * settings for subsequent post_value() lookups.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   443
	 * @since 4.1.1
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   444
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   445
	 * @return array
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   447
	public function unsanitized_post_values() {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
		if ( ! isset( $this->_post_values ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   449
			if ( isset( $_POST['customized'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
				$this->_post_values = json_decode( wp_unslash( $_POST['customized'] ), true );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   451
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   452
			if ( empty( $this->_post_values ) ) { // if not isset or if JSON error
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   453
				$this->_post_values = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   454
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   456
		if ( empty( $this->_post_values ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   457
			return array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   458
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   459
			return $this->_post_values;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   460
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   464
	 * Return the sanitized value for a given setting from the request's POST data.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   465
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   466
	 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   467
	 * @since 4.1.1 Introduced 'default' parameter.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   468
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   469
	 * @param WP_Customize_Setting $setting A WP_Customize_Setting derived object
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   470
	 * @param mixed $default value returned $setting has no post value (added in 4.2.0).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   471
	 * @return string|mixed $post_value Sanitized value or the $default provided
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   472
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   473
	public function post_value( $setting, $default = null ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   474
		$post_values = $this->unsanitized_post_values();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   475
		if ( array_key_exists( $setting->id, $post_values ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   476
			return $setting->sanitize( $post_values[ $setting->id ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   477
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   478
			return $default;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   479
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   480
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   481
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   482
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   483
	 * Override a setting's (unsanitized) value as found in any incoming $_POST['customized'].
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   484
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   485
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   486
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   487
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   488
	 * @param string $setting_id ID for the WP_Customize_Setting instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   489
	 * @param mixed  $value      Post value.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   490
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   491
	public function set_post_value( $setting_id, $value ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   492
		$this->unsanitized_post_values();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   493
		$this->_post_values[ $setting_id ] = $value;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   494
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   495
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   496
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   497
	 * Print JavaScript settings.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	public function customize_preview_init() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
		$this->nonce_tick = check_ajax_referer( 'preview-customize_' . $this->get_stylesheet(), 'nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
		$this->prepare_controls();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
		wp_enqueue_script( 'customize-preview' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   507
		add_action( 'wp', array( $this, 'customize_preview_override_404_status' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
		add_action( 'wp_head', array( $this, 'customize_preview_base' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		add_action( 'wp_head', array( $this, 'customize_preview_html5' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   510
		add_action( 'wp_head', array( $this, 'customize_preview_loading_style' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		add_action( 'wp_footer', array( $this, 'customize_preview_settings' ), 20 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
		add_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
		add_filter( 'wp_die_handler', array( $this, 'remove_preview_signature' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
		foreach ( $this->settings as $setting ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
			$setting->preview();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   519
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   520
		 * Fires once the Customizer preview has initialized and JavaScript
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   521
		 * settings have been printed.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   522
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   523
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   524
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   525
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   526
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		do_action( 'customize_preview_init', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   531
	 * Prevent sending a 404 status when returning the response for the customize
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   532
	 * preview, since it causes the jQuery AJAX to fail. Send 200 instead.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   533
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   534
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   535
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   536
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   537
	public function customize_preview_override_404_status() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   538
		if ( is_404() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   539
			status_header( 200 );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   540
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   541
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   542
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   543
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	 * Print base element for preview frame.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	public function customize_preview_base() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
		?><base href="<?php echo home_url( '/' ); ?>" /><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   553
	 * Print a workaround to handle HTML5 tags in IE < 9.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
	public function customize_preview_html5() { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
		<!--[if lt IE 9]>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
		<script type="text/javascript">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
			var e = [ 'abbr', 'article', 'aside', 'audio', 'canvas', 'datalist', 'details',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
				'figure', 'footer', 'header', 'hgroup', 'mark', 'menu', 'meter', 'nav',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
				'output', 'progress', 'section', 'time', 'video' ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
			for ( var i = 0; i < e.length; i++ ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
				document.createElement( e[i] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
		</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
		<![endif]--><?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   571
	 * Print CSS for loading indicators for the Customizer preview.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   572
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   573
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   574
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   575
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   576
	public function customize_preview_loading_style() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   577
		?><style>
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   578
			body.wp-customizer-unloading {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   579
				opacity: 0.25;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   580
				cursor: progress !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   581
				-webkit-transition: opacity 0.5s;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   582
				transition: opacity 0.5s;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   583
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   584
			body.wp-customizer-unloading * {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   585
				pointer-events: none !important;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   586
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   587
		</style><?php
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   588
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   589
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   590
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   591
	 * Print JavaScript settings for preview frame.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
	public function customize_preview_settings() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
		$settings = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
			'values'  => array(),
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   598
			'channel' => wp_unslash( $_POST['customize_messenger_channel'] ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   599
			'activePanels' => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   600
			'activeSections' => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   601
			'activeControls' => array(),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   602
			'l10n' => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   603
				'loading'  => __( 'Loading ...' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   604
			),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
		);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
		if ( 2 == $this->nonce_tick ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
			$settings['nonce'] = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
				'save' => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
				'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
			);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
		foreach ( $this->settings as $id => $setting ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
			$settings['values'][ $id ] = $setting->js_value();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
		}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   617
		foreach ( $this->panels as $id => $panel ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   618
			$settings['activePanels'][ $id ] = $panel->active();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   619
			foreach ( $panel->sections as $id => $section ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   620
				$settings['activeSections'][ $id ] = $section->active();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   621
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   622
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   623
		foreach ( $this->sections as $id => $section ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   624
			$settings['activeSections'][ $id ] = $section->active();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   625
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   626
		foreach ( $this->controls as $id => $control ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   627
			$settings['activeControls'][ $id ] = $control->active();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   628
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
		?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
		<script type="text/javascript">
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   632
			var _wpCustomizeSettings = <?php echo wp_json_encode( $settings ); ?>;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
		</script>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
		<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   638
	 * Prints a signature so we can ensure the Customizer was properly executed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
	public function customize_preview_signature() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
		echo 'WP_CUSTOMIZER_SIGNATURE';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   647
	 * Removes the signature in case we experience a case where the Customizer was not properly executed.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
	public function remove_preview_signature( $return = null ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		remove_action( 'shutdown', array( $this, 'customize_preview_signature' ), 1000 );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
		return $return;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
	 * Is it a theme preview?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	 * @return bool True if it's a preview, false if not.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
	public function is_preview() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
		return (bool) $this->previewing;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
	 * Retrieve the template name of the previewed theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
	 * @return string Template name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
	public function get_template() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
		return $this->theme()->get_template();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
	 * Retrieve the stylesheet name of the previewed theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
	 * @return string Stylesheet name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
	public function get_stylesheet() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
		return $this->theme()->get_stylesheet();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
	 * Retrieve the template root of the previewed theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
	 * @return string Theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
	public function get_template_root() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
		return get_raw_theme_root( $this->get_template(), true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
	 * Retrieve the stylesheet root of the previewed theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
	 * @return string Theme root.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
	public function get_stylesheet_root() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
		return get_raw_theme_root( $this->get_stylesheet(), true );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
	 * Filter the current theme and return the name of the previewed theme.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
	 * @param $current_theme {@internal Parameter is not used}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
	 * @return string Theme name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
	public function current_theme( $current_theme ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
		return $this->theme()->display('Name');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   725
	 * Switch the theme and trigger the save() method on each setting.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
	public function save() {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   730
		if ( ! $this->is_preview() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   731
			wp_send_json_error( 'not_preview' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   732
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   734
		$action = 'save-customize_' . $this->get_stylesheet();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   735
		if ( ! check_ajax_referer( $action, 'nonce', false ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   736
			wp_send_json_error( 'invalid_nonce' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   737
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
		// Do we have to switch themes?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
		if ( ! $this->is_theme_active() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
			// Temporarily stop previewing the theme to allow switch_themes()
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
			// to operate properly.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
			$this->stop_previewing_theme();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
			switch_theme( $this->get_stylesheet() );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   745
			update_option( 'theme_switched_via_customizer', true );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
			$this->start_previewing_theme();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   749
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   750
		 * Fires once the theme has switched in the Customizer, but before settings
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   751
		 * have been saved.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   752
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   753
		 * @since 3.4.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   754
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   755
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   756
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
		do_action( 'customize_save', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
		foreach ( $this->settings as $setting ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
			$setting->save();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   763
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   764
		 * Fires after Customize settings have been saved.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   765
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   766
		 * @since 3.6.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   767
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   768
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   769
		 */
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   770
		do_action( 'customize_save_after', $this );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   771
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   772
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   773
		 * Filter response data for a successful customize_save AJAX request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   774
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   775
		 * This filter does not apply if there was a nonce or authentication failure.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   776
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   777
		 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   778
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   779
		 * @param array                $data Additional information passed back to the 'saved'
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   780
		 *                                   event on `wp.customize`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   781
		 * @param WP_Customize_Manager $this WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   782
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   783
		$response = apply_filters( 'customize_save_response', array(), $this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   784
		wp_send_json_success( $response );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   785
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   786
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   787
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   788
	 * Refresh nonces for the current preview.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   789
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   790
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   791
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   792
	public function refresh_nonces() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   793
		if ( ! $this->is_preview() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   794
			wp_send_json_error( 'not_preview' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   795
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   796
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   797
		$nonces = array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   798
			'save'    => wp_create_nonce( 'save-customize_' . $this->get_stylesheet() ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   799
			'preview' => wp_create_nonce( 'preview-customize_' . $this->get_stylesheet() ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   800
		);
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   801
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   802
		/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   803
		 * Filter nonces for a customize_refresh_nonces AJAX request.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   804
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   805
		 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   806
		 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   807
		 * @param array                $nonces Array of refreshed nonces for save and
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   808
		 *                                     preview actions.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   809
		 * @param WP_Customize_Manager $this   WP_Customize_Manager instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   810
		 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   811
		$nonces = apply_filters( 'customize_refresh_nonces', $nonces, $this );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   812
		wp_send_json_success( $nonces );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   813
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   814
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   815
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   816
	 * Add a customize setting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   817
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   818
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   819
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   820
	 * @param WP_Customize_Setting|string $id Customize Setting object, or ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   821
	 * @param array $args                     Setting arguments; passed to WP_Customize_Setting
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   822
	 *                                        constructor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   823
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   824
	public function add_setting( $id, $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   825
		if ( $id instanceof WP_Customize_Setting ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   826
			$setting = $id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   827
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   828
			$setting = new WP_Customize_Setting( $this, $id, $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   829
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   830
		$this->settings[ $setting->id ] = $setting;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   831
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   832
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   833
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   834
	 * Register any dynamically-created settings, such as those from $_POST['customized']
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   835
	 * that have no corresponding setting created.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   836
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   837
	 * This is a mechanism to "wake up" settings that have been dynamically created
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   838
	 * on the frontend and have been sent to WordPress in `$_POST['customized']`. When WP
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   839
	 * loads, the dynamically-created settings then will get created and previewed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   840
	 * even though they are not directly created statically with code.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   841
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   842
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   843
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   844
	 * @param string $setting_ids The setting IDs to add.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   845
	 * @return WP_Customize_Setting The settings added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   846
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   847
	public function add_dynamic_settings( $setting_ids ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   848
		$new_settings = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   849
		foreach ( $setting_ids as $setting_id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   850
			// Skip settings already created
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   851
			if ( $this->get_setting( $setting_id ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   852
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   853
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   854
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   855
			$setting_args = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   856
			$setting_class = 'WP_Customize_Setting';
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   857
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   858
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   859
			 * Filter a dynamic setting's constructor args.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   860
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   861
			 * For a dynamic setting to be registered, this filter must be employed
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   862
			 * to override the default false value with an array of args to pass to
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   863
			 * the WP_Customize_Setting constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   864
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   865
			 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   866
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   867
			 * @param false|array $setting_args The arguments to the WP_Customize_Setting constructor.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   868
			 * @param string      $setting_id   ID for dynamic setting, usually coming from `$_POST['customized']`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   869
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   870
			$setting_args = apply_filters( 'customize_dynamic_setting_args', $setting_args, $setting_id );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   871
			if ( false === $setting_args ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   872
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   873
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   874
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   875
			/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   876
			 * Allow non-statically created settings to be constructed with custom WP_Customize_Setting subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   877
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   878
			 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   879
			 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   880
			 * @param string $setting_class WP_Customize_Setting or a subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   881
			 * @param string $setting_id    ID for dynamic setting, usually coming from `$_POST['customized']`.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   882
			 * @param string $setting_args  WP_Customize_Setting or a subclass.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   883
			 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   884
			$setting_class = apply_filters( 'customize_dynamic_setting_class', $setting_class, $setting_id, $setting_args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   885
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   886
			$setting = new $setting_class( $this, $setting_id, $setting_args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   887
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   888
			$this->add_setting( $setting );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   889
			$new_settings[] = $setting;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   890
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   891
		return $new_settings;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   892
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   893
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   894
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   895
	 * Retrieve a customize setting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   896
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   897
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   898
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   899
	 * @param string $id Customize Setting ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   900
	 * @return WP_Customize_Setting
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   901
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   902
	public function get_setting( $id ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   903
		if ( isset( $this->settings[ $id ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   904
			return $this->settings[ $id ];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   905
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   906
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   907
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   908
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   909
	 * Remove a customize setting.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   910
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   911
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   912
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   913
	 * @param string $id Customize Setting ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   914
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   915
	public function remove_setting( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   916
		unset( $this->settings[ $id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   917
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   918
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   919
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   920
	 * Add a customize panel.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   921
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   922
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   923
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   924
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   925
	 * @param WP_Customize_Panel|string $id   Customize Panel object, or Panel ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   926
	 * @param array                     $args Optional. Panel arguments. Default empty array.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   927
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   928
	public function add_panel( $id, $args = array() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   929
		if ( $id instanceof WP_Customize_Panel ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   930
			$panel = $id;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   931
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   932
			$panel = new WP_Customize_Panel( $this, $id, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   933
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   934
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   935
		$this->panels[ $panel->id ] = $panel;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   936
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   937
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   938
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   939
	 * Retrieve a customize panel.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   940
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   941
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   942
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   943
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   944
	 * @param string $id Panel ID to get.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   945
	 * @return WP_Customize_Panel Requested panel instance.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   946
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   947
	public function get_panel( $id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   948
		if ( isset( $this->panels[ $id ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   949
			return $this->panels[ $id ];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   950
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   951
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   952
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   953
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   954
	 * Remove a customize panel.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   955
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   956
	 * @since 4.0.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   957
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   958
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   959
	 * @param string $id Panel ID to remove.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   960
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   961
	public function remove_panel( $id ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   962
		unset( $this->panels[ $id ] );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   963
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   964
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   965
	/**
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   966
	 * Add a customize section.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   967
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   968
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   969
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   970
	 * @param WP_Customize_Section|string $id   Customize Section object, or Section ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   971
	 * @param array                       $args Section arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   972
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   973
	public function add_section( $id, $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   974
		if ( $id instanceof WP_Customize_Section ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   975
			$section = $id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   976
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   977
			$section = new WP_Customize_Section( $this, $id, $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   978
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   979
		$this->sections[ $section->id ] = $section;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   980
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   981
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   982
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   983
	 * Retrieve a customize section.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   984
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   985
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   986
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   987
	 * @param string $id Section ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   988
	 * @return WP_Customize_Section
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   989
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   990
	public function get_section( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   991
		if ( isset( $this->sections[ $id ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   992
			return $this->sections[ $id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   993
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   994
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   995
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   996
	 * Remove a customize section.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   997
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   998
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   999
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1000
	 * @param string $id Section ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1001
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1002
	public function remove_section( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1003
		unset( $this->sections[ $id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1004
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1005
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1006
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1007
	 * Add a customize control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1008
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1009
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1010
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1011
	 * @param WP_Customize_Control|string $id   Customize Control object, or ID.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1012
	 * @param array                       $args Control arguments; passed to WP_Customize_Control
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1013
	 *                                          constructor.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1014
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1015
	public function add_control( $id, $args = array() ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1016
		if ( $id instanceof WP_Customize_Control ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1017
			$control = $id;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1018
		} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1019
			$control = new WP_Customize_Control( $this, $id, $args );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1020
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1021
		$this->controls[ $control->id ] = $control;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1022
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1023
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1024
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1025
	 * Retrieve a customize control.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1026
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1027
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1028
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1029
	 * @param string $id ID of the control.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1030
	 * @return WP_Customize_Control $control The control object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1031
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1032
	public function get_control( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1033
		if ( isset( $this->controls[ $id ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1034
			return $this->controls[ $id ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1035
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1036
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1037
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1038
	 * Remove a customize control.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1039
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1040
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1041
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1042
	 * @param string $id ID of the control.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1043
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1044
	public function remove_control( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1045
		unset( $this->controls[ $id ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1046
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1047
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1048
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1049
	 * Register a customize control type.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1050
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1051
	 * Registered types are eligible to be rendered via JS and created dynamically.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1052
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1053
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1054
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1055
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1056
	 * @param string $control Name of a custom control which is a subclass of
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1057
	 *                        {@see WP_Customize_Control}.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1058
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1059
	public function register_control_type( $control ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1060
		$this->registered_control_types[] = $control;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1061
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1062
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1063
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1064
	 * Render JS templates for all registered control types.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1065
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1066
	 * @since 4.1.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1067
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1068
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1069
	public function render_control_templates() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1070
		foreach ( $this->registered_control_types as $control_type ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1071
			$control = new $control_type( $this, 'temp', array() );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1072
			$control->print_template();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1073
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1074
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1075
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1076
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1077
	 * Helper function to compare two objects by priority, ensuring sort stability via instance_number.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1078
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1079
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1080
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1081
	 * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $a Object A.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1082
	 * @param WP_Customize_Panel|WP_Customize_Section|WP_Customize_Control $b Object B.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1083
	 * @return int
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1084
	 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1085
	protected function _cmp_priority( $a, $b ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1086
		if ( $a->priority === $b->priority ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1087
			return $a->instance_number - $a->instance_number;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1088
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1089
			return $a->priority - $b->priority;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1090
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1091
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1092
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1093
	/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1094
	 * Prepare panels, sections, and controls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1095
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1096
	 * For each, check if required related components exist,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1097
	 * whether the user has the necessary capabilities,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1098
	 * and sort by priority.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1099
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1100
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1101
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1102
	public function prepare_controls() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1103
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1104
		$controls = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1105
		uasort( $this->controls, array( $this, '_cmp_priority' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1106
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1107
		foreach ( $this->controls as $id => $control ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1108
			if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1109
				continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1110
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1111
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1112
			$this->sections[ $control->section ]->controls[] = $control;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1113
			$controls[ $id ] = $control;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1114
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1115
		$this->controls = $controls;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1116
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1117
		// Prepare sections.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1118
		uasort( $this->sections, array( $this, '_cmp_priority' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1119
		$sections = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1120
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1121
		foreach ( $this->sections as $section ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1122
			if ( ! $section->check_capabilities() || ! $section->controls ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1123
				continue;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1124
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1125
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1126
			usort( $section->controls, array( $this, '_cmp_priority' ) );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1127
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1128
			if ( ! $section->panel ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1129
				// Top-level section.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1130
				$sections[ $section->id ] = $section;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1131
			} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1132
				// This section belongs to a panel.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1133
				if ( isset( $this->panels [ $section->panel ] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1134
					$this->panels[ $section->panel ]->sections[ $section->id ] = $section;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1135
				}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1136
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1137
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1138
		$this->sections = $sections;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1139
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1140
		// Prepare panels.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1141
		uasort( $this->panels, array( $this, '_cmp_priority' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1142
		$panels = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1143
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1144
		foreach ( $this->panels as $panel ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1145
			if ( ! $panel->check_capabilities() || ! $panel->sections ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1146
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1147
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1148
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1149
			uasort( $panel->sections, array( $this, '_cmp_priority' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1150
			$panels[ $panel->id ] = $panel;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1151
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1152
		$this->panels = $panels;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1153
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1154
		// Sort panels and top-level sections together.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1155
		$this->containers = array_merge( $this->panels, $this->sections );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1156
		uasort( $this->containers, array( $this, '_cmp_priority' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1157
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1159
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1160
	 * Enqueue scripts for customize controls.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1161
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1162
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1163
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1164
	public function enqueue_control_scripts() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1165
		foreach ( $this->controls as $control ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1166
			$control->enqueue();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1167
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1168
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1169
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1170
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1171
	 * Register some default controls.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1172
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1173
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1174
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1175
	public function register_controls() {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1176
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1177
		/* Control Types (custom control classes) */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1178
		$this->register_control_type( 'WP_Customize_Color_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1179
		$this->register_control_type( 'WP_Customize_Media_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1180
		$this->register_control_type( 'WP_Customize_Upload_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1181
		$this->register_control_type( 'WP_Customize_Image_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1182
		$this->register_control_type( 'WP_Customize_Background_Image_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1183
		$this->register_control_type( 'WP_Customize_Theme_Control' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1184
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1185
		/* Themes */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1186
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1187
		$this->add_section( new WP_Customize_Themes_Section( $this, 'themes', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1188
			'title'      => $this->theme()->display( 'Name' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1189
			'capability' => 'switch_themes',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1190
			'priority'   => 0,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1191
		) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1192
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1193
		// Themes Setting (unused - the theme is considerably more fundamental to the Customizer experience).
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1194
		$this->add_setting( new WP_Customize_Filter_Setting( $this, 'active_theme', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1195
			'capability' => 'switch_themes',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1196
		) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1197
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1198
		require_once( ABSPATH . 'wp-admin/includes/theme.php' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1199
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1200
		// Theme Controls.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1201
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1202
		// Add a control for the active/original theme.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1203
		if ( ! $this->is_theme_active() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1204
			$themes = wp_prepare_themes_for_js( array( wp_get_theme( $this->original_stylesheet ) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1205
			$active_theme = current( $themes );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1206
			$active_theme['isActiveTheme'] = true;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1207
			$this->add_control( new WP_Customize_Theme_Control( $this, $active_theme['id'], array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1208
				'theme'    => $active_theme,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1209
				'section'  => 'themes',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1210
				'settings' => 'active_theme',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1211
			) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1212
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1213
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1214
		$themes = wp_prepare_themes_for_js();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1215
		foreach ( $themes as $theme ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1216
			if ( $theme['active'] || $theme['id'] === $this->original_stylesheet ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1217
				continue;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1218
			}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1219
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1220
			$theme_id = 'theme_' . $theme['id'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1221
			$theme['isActiveTheme'] = false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1222
			$this->add_control( new WP_Customize_Theme_Control( $this, $theme_id, array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1223
				'theme'    => $theme,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1224
				'section'  => 'themes',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1225
				'settings' => 'active_theme',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1226
			) ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1227
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1228
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1229
		/* Site Title & Tagline */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1231
		$this->add_section( 'title_tagline', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1232
			'title'    => __( 'Site Title & Tagline' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1233
			'priority' => 20,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1234
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1235
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1236
		$this->add_setting( 'blogname', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1237
			'default'    => get_option( 'blogname' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1238
			'type'       => 'option',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1239
			'capability' => 'manage_options',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1240
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1241
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1242
		$this->add_control( 'blogname', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1243
			'label'      => __( 'Site Title' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1244
			'section'    => 'title_tagline',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1245
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1246
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1247
		$this->add_setting( 'blogdescription', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1248
			'default'    => get_option( 'blogdescription' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1249
			'type'       => 'option',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1250
			'capability' => 'manage_options',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1251
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1252
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1253
		$this->add_control( 'blogdescription', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1254
			'label'      => __( 'Tagline' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1255
			'section'    => 'title_tagline',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1256
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1257
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1258
		/* Colors */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1260
		$this->add_section( 'colors', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1261
			'title'          => __( 'Colors' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1262
			'priority'       => 40,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1263
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1264
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1265
		$this->add_setting( 'header_textcolor', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1266
			'theme_supports' => array( 'custom-header', 'header-text' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1267
			'default'        => get_theme_support( 'custom-header', 'default-text-color' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1269
			'sanitize_callback'    => array( $this, '_sanitize_header_textcolor' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1270
			'sanitize_js_callback' => 'maybe_hash_hex_color',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1271
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1272
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1273
		// Input type: checkbox
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1274
		// With custom value
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1275
		$this->add_control( 'display_header_text', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1276
			'settings' => 'header_textcolor',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1277
			'label'    => __( 'Display Header Text' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1278
			'section'  => 'title_tagline',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1279
			'type'     => 'checkbox',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1280
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1281
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1282
		$this->add_control( new WP_Customize_Color_Control( $this, 'header_textcolor', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1283
			'label'   => __( 'Header Text Color' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1284
			'section' => 'colors',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1285
		) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1286
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1287
		// Input type: Color
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1288
		// With sanitize_callback
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1289
		$this->add_setting( 'background_color', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1290
			'default'        => get_theme_support( 'custom-background', 'default-color' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1291
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1292
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1293
			'sanitize_callback'    => 'sanitize_hex_color_no_hash',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1294
			'sanitize_js_callback' => 'maybe_hash_hex_color',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1295
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1296
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1297
		$this->add_control( new WP_Customize_Color_Control( $this, 'background_color', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1298
			'label'   => __( 'Background Color' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1299
			'section' => 'colors',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1300
		) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1301
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1302
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1303
		/* Custom Header */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1304
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1305
		$this->add_section( 'header_image', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1306
			'title'          => __( 'Header Image' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1307
			'theme_supports' => 'custom-header',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1308
			'priority'       => 60,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1309
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1310
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1311
		$this->add_setting( new WP_Customize_Filter_Setting( $this, 'header_image', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1312
			'default'        => get_theme_support( 'custom-header', 'default-image' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1313
			'theme_supports' => 'custom-header',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1314
		) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1316
		$this->add_setting( new WP_Customize_Header_Image_Setting( $this, 'header_image_data', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1317
			// 'default'        => get_theme_support( 'custom-header', 'default-image' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1318
			'theme_supports' => 'custom-header',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1319
		) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1320
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1321
		$this->add_control( new WP_Customize_Header_Image_Control( $this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1322
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1323
		/* Custom Background */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1325
		$this->add_section( 'background_image', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1326
			'title'          => __( 'Background Image' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1327
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1328
			'priority'       => 80,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1329
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1330
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1331
		$this->add_setting( 'background_image', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1332
			'default'        => get_theme_support( 'custom-background', 'default-image' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1333
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1334
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1336
		$this->add_setting( new WP_Customize_Background_Image_Setting( $this, 'background_image_thumb', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1337
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1338
		) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1339
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1340
		$this->add_control( new WP_Customize_Background_Image_Control( $this ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1341
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1342
		$this->add_setting( 'background_repeat', array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1343
			'default'        => get_theme_support( 'custom-background', 'default-repeat' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1344
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1345
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1347
		$this->add_control( 'background_repeat', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1348
			'label'      => __( 'Background Repeat' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1349
			'section'    => 'background_image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1350
			'type'       => 'radio',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1351
			'choices'    => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1352
				'no-repeat'  => __('No Repeat'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1353
				'repeat'     => __('Tile'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1354
				'repeat-x'   => __('Tile Horizontally'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1355
				'repeat-y'   => __('Tile Vertically'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1356
			),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1357
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1359
		$this->add_setting( 'background_position_x', array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1360
			'default'        => get_theme_support( 'custom-background', 'default-position-x' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1361
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1362
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1364
		$this->add_control( 'background_position_x', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1365
			'label'      => __( 'Background Position' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1366
			'section'    => 'background_image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1367
			'type'       => 'radio',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1368
			'choices'    => array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1369
				'left'       => __('Left'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1370
				'center'     => __('Center'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1371
				'right'      => __('Right'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1372
			),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1373
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1374
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1375
		$this->add_setting( 'background_attachment', array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1376
			'default'        => get_theme_support( 'custom-background', 'default-attachment' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1377
			'theme_supports' => 'custom-background',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1378
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1379
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1380
		$this->add_control( 'background_attachment', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1381
			'label'      => __( 'Background Attachment' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1382
			'section'    => 'background_image',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1383
			'type'       => 'radio',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1384
			'choices'    => array(
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1385
				'scroll'     => __('Scroll'),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1386
				'fixed'      => __('Fixed'),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1387
			),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1388
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1389
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1390
		// If the theme is using the default background callback, we can update
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1391
		// the background CSS using postMessage.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1392
		if ( get_theme_support( 'custom-background', 'wp-head-callback' ) === '_custom_background_cb' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1393
			foreach ( array( 'color', 'image', 'position_x', 'repeat', 'attachment' ) as $prop ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1394
				$this->get_setting( 'background_' . $prop )->transport = 'postMessage';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1395
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1396
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1397
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1398
		/* Nav Menus */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1399
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1400
		$locations      = get_registered_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1401
		$menus          = wp_get_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1402
		$num_locations  = count( array_keys( $locations ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1403
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1404
		if ( 1 == $num_locations ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1405
			$description = __( 'Your theme supports one menu. Select which menu you would like to use.' );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1406
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1407
			$description = sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1408
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1409
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1410
		$this->add_section( 'nav', array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1411
			'title'          => __( 'Navigation' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1412
			'theme_supports' => 'menus',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1413
			'priority'       => 100,
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1414
			'description'    => $description . "\n\n" . __( 'You can edit your menu content on the Menus screen in the Appearance section.' ),
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1415
		) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1416
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1417
		if ( $menus ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1418
			$choices = array( '' => __( '&mdash; Select &mdash;' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1419
			foreach ( $menus as $menu ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1420
				$choices[ $menu->term_id ] = wp_html_excerpt( $menu->name, 40, '&hellip;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1421
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1422
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1423
			foreach ( $locations as $location => $description ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1424
				$menu_setting_id = "nav_menu_locations[{$location}]";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1425
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1426
				$this->add_setting( $menu_setting_id, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1427
					'sanitize_callback' => 'absint',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1428
					'theme_supports'    => 'menus',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1429
				) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1430
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1431
				$this->add_control( $menu_setting_id, array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1432
					'label'   => $description,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1433
					'section' => 'nav',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1434
					'type'    => 'select',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1435
					'choices' => $choices,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1436
				) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1437
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1438
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1439
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1440
		/* Static Front Page */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1441
		// #WP19627
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1442
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1443
		// Replicate behavior from options-reading.php and hide front page options if there are no pages
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1444
		if ( get_pages() ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1445
			$this->add_section( 'static_front_page', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1446
				'title'          => __( 'Static Front Page' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1447
			//	'theme_supports' => 'static-front-page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1448
				'priority'       => 120,
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1449
				'description'    => __( 'Your theme supports a static front page.' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1450
			) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1451
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1452
			$this->add_setting( 'show_on_front', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1453
				'default'        => get_option( 'show_on_front' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1454
				'capability'     => 'manage_options',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1455
				'type'           => 'option',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1456
			//	'theme_supports' => 'static-front-page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1457
			) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1458
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1459
			$this->add_control( 'show_on_front', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1460
				'label'   => __( 'Front page displays' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1461
				'section' => 'static_front_page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1462
				'type'    => 'radio',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1463
				'choices' => array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1464
					'posts' => __( 'Your latest posts' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1465
					'page'  => __( 'A static page' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1466
				),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1467
			) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1468
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1469
			$this->add_setting( 'page_on_front', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1470
				'type'       => 'option',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1471
				'capability' => 'manage_options',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1472
			//	'theme_supports' => 'static-front-page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1473
			) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1474
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1475
			$this->add_control( 'page_on_front', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1476
				'label'      => __( 'Front page' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1477
				'section'    => 'static_front_page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1478
				'type'       => 'dropdown-pages',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1479
			) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1480
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1481
			$this->add_setting( 'page_for_posts', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1482
				'type'           => 'option',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1483
				'capability'     => 'manage_options',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1484
			//	'theme_supports' => 'static-front-page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1485
			) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1486
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1487
			$this->add_control( 'page_for_posts', array(
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1488
				'label'      => __( 'Posts page' ),
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1489
				'section'    => 'static_front_page',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1490
				'type'       => 'dropdown-pages',
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1491
			) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1492
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1493
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1494
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1495
	/**
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1496
	 * Add settings from the POST data that were not added with code, e.g. dynamically-created settings for Widgets
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1497
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1498
	 * @since 4.2.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1499
	 * @access public
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1500
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1501
	 * @see add_dynamic_settings()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1502
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1503
	public function register_dynamic_settings() {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1504
		$this->add_dynamic_settings( array_keys( $this->unsanitized_post_values() ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1505
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1506
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1507
	/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1508
	 * Callback for validating the header_textcolor value.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1509
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1510
	 * Accepts 'blank', and otherwise uses sanitize_hex_color_no_hash().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1511
	 * Returns default text color if hex color is empty.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1512
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1513
	 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1514
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1515
	 * @param string $color
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1516
	 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1517
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1518
	public function _sanitize_header_textcolor( $color ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1519
		if ( 'blank' === $color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1520
			return 'blank';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1521
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1522
		$color = sanitize_hex_color_no_hash( $color );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1523
		if ( empty( $color ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1524
			$color = get_theme_support( 'custom-header', 'default-text-color' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1526
		return $color;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1527
	}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1528
}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1529
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1530
/**
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1531
 * Sanitizes a hex color.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1532
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1533
 * Returns either '', a 3 or 6 digit hex color (with #), or null.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
  1534
 * For sanitizing values without a #, see sanitize_hex_color_no_hash().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1535
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1536
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1537
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1538
 * @param string $color
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1539
 * @return string|null
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1540
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1541
function sanitize_hex_color( $color ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1542
	if ( '' === $color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1543
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1544
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1545
	// 3 or 6 hex digits, or the empty string.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1546
	if ( preg_match('|^#([A-Fa-f0-9]{3}){1,2}$|', $color ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1547
		return $color;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1548
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1549
	return null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1550
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1551
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1552
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1553
 * Sanitizes a hex color without a hash. Use sanitize_hex_color() when possible.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1554
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1555
 * Saving hex colors without a hash puts the burden of adding the hash on the
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1556
 * UI, which makes it difficult to use or upgrade to other color types such as
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1557
 * rgba, hsl, rgb, and html color names.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1558
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1559
 * Returns either '', a 3 or 6 digit hex color (without a #), or null.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1560
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1561
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1562
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1563
 * @param string $color
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1564
 * @return string|null
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1565
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1566
function sanitize_hex_color_no_hash( $color ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1567
	$color = ltrim( $color, '#' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1568
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1569
	if ( '' === $color )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1570
		return '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1571
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1572
	return sanitize_hex_color( '#' . $color ) ? $color : null;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1573
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1574
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1575
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1576
 * Ensures that any hex color is properly hashed.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1577
 * Otherwise, returns value untouched.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1578
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1579
 * This method should only be necessary if using sanitize_hex_color_no_hash().
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1580
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1581
 * @since 3.4.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1582
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1583
 * @param string $color
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1584
 * @return string
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1585
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1586
function maybe_hash_hex_color( $color ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1587
	if ( $unhashed = sanitize_hex_color_no_hash( $color ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1588
		return '#' . $unhashed;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1589
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1590
	return $color;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
  1591
}