wp/wp-includes/class-wp-customize-control.php
changeset 5 5e2f62d02dcd
parent 0 d970ebf37754
child 7 cf61fcea0001
equal deleted inserted replaced
4:346c88efed21 5:5e2f62d02dcd
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Customize Control Class
     3  * WordPress Customize Control classes
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Customize
     6  * @subpackage Customize
     7  * @since 3.4.0
     7  * @since 3.4.0
     8  */
     8  */
       
     9 
       
    10 /**
       
    11  * Customize Control class.
       
    12  *
       
    13  * @since 3.4.0
       
    14  */
     9 class WP_Customize_Control {
    15 class WP_Customize_Control {
       
    16 
       
    17 	/**
       
    18 	 * Incremented with each new class instantiation, then stored in $instance_number.
       
    19 	 *
       
    20 	 * Used when sorting two instances whose priorities are equal.
       
    21 	 *
       
    22 	 * @since 4.1.0
       
    23 	 * @access protected
       
    24 	 * @var int
       
    25 	 */
       
    26 	protected static $instance_count = 0;
       
    27 
       
    28 	/**
       
    29 	 * Order in which this instance was created in relation to other instances.
       
    30 	 *
       
    31 	 * @since 4.1.0
       
    32 	 * @access public
       
    33 	 * @var int
       
    34 	 */
       
    35 	public $instance_number;
       
    36 
    10 	/**
    37 	/**
    11 	 * @access public
    38 	 * @access public
    12 	 * @var WP_Customize_Manager
    39 	 * @var WP_Customize_Manager
    13 	 */
    40 	 */
    14 	public $manager;
    41 	public $manager;
    37 
    64 
    38 	/**
    65 	/**
    39 	 * @access public
    66 	 * @access public
    40 	 * @var int
    67 	 * @var int
    41 	 */
    68 	 */
    42 	public $priority          = 10;
    69 	public $priority = 10;
    43 
    70 
    44 	/**
    71 	/**
    45 	 * @access public
    72 	 * @access public
    46 	 * @var string
    73 	 * @var string
    47 	 */
    74 	 */
    48 	public $section           = '';
    75 	public $section = '';
    49 
    76 
    50 	/**
    77 	/**
    51 	 * @access public
    78 	 * @access public
    52 	 * @var string
    79 	 * @var string
    53 	 */
    80 	 */
    54 	public $label             = '';
    81 	public $label = '';
       
    82 
       
    83 	/**
       
    84 	 * @access public
       
    85 	 * @var string
       
    86 	 */
       
    87 	public $description = '';
    55 
    88 
    56 	/**
    89 	/**
    57 	 * @todo: Remove choices
    90 	 * @todo: Remove choices
    58 	 *
    91 	 *
    59 	 * @access public
    92 	 * @access public
    60 	 * @var array
    93 	 * @var array
    61 	 */
    94 	 */
    62 	public $choices           = array();
    95 	public $choices = array();
    63 
    96 
    64 	/**
    97 	/**
    65 	 * @access public
    98 	 * @access public
    66 	 * @var array
    99 	 * @var array
    67 	 */
   100 	 */
       
   101 	public $input_attrs = array();
       
   102 
       
   103 	/**
       
   104 	 * @deprecated It is better to just call the json() method
       
   105 	 * @access public
       
   106 	 * @var array
       
   107 	 */
    68 	public $json = array();
   108 	public $json = array();
    69 
   109 
    70 	/**
   110 	/**
    71 	 * @access public
   111 	 * @access public
    72 	 * @var string
   112 	 * @var string
    73 	 */
   113 	 */
    74 	public $type = 'text';
   114 	public $type = 'text';
    75 
   115 
       
   116 	/**
       
   117 	 * Callback.
       
   118 	 *
       
   119 	 * @since 4.0.0
       
   120 	 * @access public
       
   121 	 *
       
   122 	 * @see WP_Customize_Control::active()
       
   123 	 *
       
   124 	 * @var callable Callback is called with one argument, the instance of
       
   125 	 *               WP_Customize_Control, and returns bool to indicate whether
       
   126 	 *               the control is active (such as it relates to the URL
       
   127 	 *               currently being previewed).
       
   128 	 */
       
   129 	public $active_callback = '';
    76 
   130 
    77 	/**
   131 	/**
    78 	 * Constructor.
   132 	 * Constructor.
       
   133 	 *
       
   134 	 * Supplied $args override class property defaults.
    79 	 *
   135 	 *
    80 	 * If $args['settings'] is not defined, use the $id as the setting ID.
   136 	 * If $args['settings'] is not defined, use the $id as the setting ID.
    81 	 *
   137 	 *
    82 	 * @since 3.4.0
   138 	 * @since 3.4.0
    83 	 *
   139 	 *
    84 	 * @param WP_Customize_Manager $manager
   140 	 * @param WP_Customize_Manager $manager
    85 	 * @param string $id
   141 	 * @param string $id
    86 	 * @param array $args
   142 	 * @param array $args
    87 	 */
   143 	 */
    88 	function __construct( $manager, $id, $args = array() ) {
   144 	public function __construct( $manager, $id, $args = array() ) {
    89 		$keys = array_keys( get_object_vars( $this ) );
   145 		$keys = array_keys( get_object_vars( $this ) );
    90 		foreach ( $keys as $key ) {
   146 		foreach ( $keys as $key ) {
    91 			if ( isset( $args[ $key ] ) )
   147 			if ( isset( $args[ $key ] ) ) {
    92 				$this->$key = $args[ $key ];
   148 				$this->$key = $args[ $key ];
       
   149 			}
    93 		}
   150 		}
    94 
   151 
    95 		$this->manager = $manager;
   152 		$this->manager = $manager;
    96 		$this->id = $id;
   153 		$this->id = $id;
    97 
   154 		if ( empty( $this->active_callback ) ) {
       
   155 			$this->active_callback = array( $this, 'active_callback' );
       
   156 		}
       
   157 		self::$instance_count += 1;
       
   158 		$this->instance_number = self::$instance_count;
    98 
   159 
    99 		// Process settings.
   160 		// Process settings.
   100 		if ( empty( $this->settings ) )
   161 		if ( empty( $this->settings ) ) {
   101 			$this->settings = $id;
   162 			$this->settings = $id;
       
   163 		}
   102 
   164 
   103 		$settings = array();
   165 		$settings = array();
   104 		if ( is_array( $this->settings ) ) {
   166 		if ( is_array( $this->settings ) ) {
   105 			foreach ( $this->settings as $key => $setting ) {
   167 			foreach ( $this->settings as $key => $setting ) {
   106 				$settings[ $key ] = $this->manager->get_setting( $setting );
   168 				$settings[ $key ] = $this->manager->get_setting( $setting );
   117 	 *
   179 	 *
   118 	 * @since 3.4.0
   180 	 * @since 3.4.0
   119 	 */
   181 	 */
   120 	public function enqueue() {}
   182 	public function enqueue() {}
   121 
   183 
       
   184 	/**
       
   185 	 * Check whether control is active to current Customizer preview.
       
   186 	 *
       
   187 	 * @since 4.0.0
       
   188 	 * @access public
       
   189 	 *
       
   190 	 * @return bool Whether the control is active to the current preview.
       
   191 	 */
       
   192 	final public function active() {
       
   193 		$control = $this;
       
   194 		$active = call_user_func( $this->active_callback, $this );
       
   195 
       
   196 		/**
       
   197 		 * Filter response of WP_Customize_Control::active().
       
   198 		 *
       
   199 		 * @since 4.0.0
       
   200 		 *
       
   201 		 * @param bool                 $active  Whether the Customizer control is active.
       
   202 		 * @param WP_Customize_Control $control WP_Customize_Control instance.
       
   203 		 */
       
   204 		$active = apply_filters( 'customize_control_active', $active, $control );
       
   205 
       
   206 		return $active;
       
   207 	}
       
   208 
       
   209 	/**
       
   210 	 * Default callback used when invoking WP_Customize_Control::active().
       
   211 	 *
       
   212 	 * Subclasses can override this with their specific logic, or they may
       
   213 	 * provide an 'active_callback' argument to the constructor.
       
   214 	 *
       
   215 	 * @since 4.0.0
       
   216 	 * @access public
       
   217 	 *
       
   218 	 * @return bool Always true.
       
   219 	 */
       
   220 	public function active_callback() {
       
   221 		return true;
       
   222 	}
   122 
   223 
   123 	/**
   224 	/**
   124 	 * Fetch a setting's value.
   225 	 * Fetch a setting's value.
   125 	 * Grabs the main setting by default.
   226 	 * Grabs the main setting by default.
   126 	 *
   227 	 *
   127 	 * @since 3.4.0
   228 	 * @since 3.4.0
   128 	 *
   229 	 *
   129 	 * @param string $setting_key
   230 	 * @param string $setting_key
   130 	 * @return mixed The requested setting's value, if the setting exists.
   231 	 * @return mixed The requested setting's value, if the setting exists.
   131 	 */
   232 	 */
   132 	public final function value( $setting_key = 'default' ) {
   233 	final public function value( $setting_key = 'default' ) {
   133 		if ( isset( $this->settings[ $setting_key ] ) )
   234 		if ( isset( $this->settings[ $setting_key ] ) ) {
   134 			return $this->settings[ $setting_key ]->value();
   235 			return $this->settings[ $setting_key ]->value();
       
   236 		}
   135 	}
   237 	}
   136 
   238 
   137 	/**
   239 	/**
   138 	 * Refresh the parameters passed to the JavaScript via JSON.
   240 	 * Refresh the parameters passed to the JavaScript via JSON.
   139 	 *
   241 	 *
   144 		foreach ( $this->settings as $key => $setting ) {
   246 		foreach ( $this->settings as $key => $setting ) {
   145 			$this->json['settings'][ $key ] = $setting->id;
   247 			$this->json['settings'][ $key ] = $setting->id;
   146 		}
   248 		}
   147 
   249 
   148 		$this->json['type'] = $this->type;
   250 		$this->json['type'] = $this->type;
       
   251 		$this->json['priority'] = $this->priority;
       
   252 		$this->json['active'] = $this->active();
       
   253 		$this->json['section'] = $this->section;
       
   254 		$this->json['content'] = $this->get_content();
       
   255 		$this->json['label'] = $this->label;
       
   256 		$this->json['description'] = $this->description;
       
   257 		$this->json['instanceNumber'] = $this->instance_number;
       
   258 	}
       
   259 
       
   260 	/**
       
   261 	 * Get the data to export to the client via JSON.
       
   262 	 *
       
   263 	 * @since 4.1.0
       
   264 	 *
       
   265 	 * @return array Array of parameters passed to the JavaScript.
       
   266 	 */
       
   267 	public function json() {
       
   268 		$this->to_json();
       
   269 		return $this->json;
   149 	}
   270 	}
   150 
   271 
   151 	/**
   272 	/**
   152 	 * Check if the theme supports the control and check user capabilities.
   273 	 * Check if the theme supports the control and check user capabilities.
   153 	 *
   274 	 *
   154 	 * @since 3.4.0
   275 	 * @since 3.4.0
   155 	 *
   276 	 *
   156 	 * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
   277 	 * @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
   157 	 */
   278 	 */
   158 	public final function check_capabilities() {
   279 	final public function check_capabilities() {
   159 		foreach ( $this->settings as $setting ) {
   280 		foreach ( $this->settings as $setting ) {
   160 			if ( ! $setting->check_capabilities() )
   281 			if ( ! $setting->check_capabilities() )
   161 				return false;
   282 				return false;
   162 		}
   283 		}
   163 
   284 
   167 
   288 
   168 		return true;
   289 		return true;
   169 	}
   290 	}
   170 
   291 
   171 	/**
   292 	/**
       
   293 	 * Get the control's content for insertion into the Customizer pane.
       
   294 	 *
       
   295 	 * @since 4.1.0
       
   296 	 *
       
   297 	 * @return string Contents of the control.
       
   298 	 */
       
   299 	final public function get_content() {
       
   300 		ob_start();
       
   301 		$this->maybe_render();
       
   302 		$template = trim( ob_get_contents() );
       
   303 		ob_end_clean();
       
   304 		return $template;
       
   305 	}
       
   306 
       
   307 	/**
   172 	 * Check capabilities and render the control.
   308 	 * Check capabilities and render the control.
   173 	 *
   309 	 *
   174 	 * @since 3.4.0
   310 	 * @since 3.4.0
   175 	 * @uses WP_Customize_Control::render()
   311 	 * @uses WP_Customize_Control::render()
   176 	 */
   312 	 */
   177 	public final function maybe_render() {
   313 	final public function maybe_render() {
   178 		if ( ! $this->check_capabilities() )
   314 		if ( ! $this->check_capabilities() )
   179 			return;
   315 			return;
   180 
   316 
       
   317 		/**
       
   318 		 * Fires just before the current Customizer control is rendered.
       
   319 		 *
       
   320 		 * @since 3.4.0
       
   321 		 *
       
   322 		 * @param WP_Customize_Control $this WP_Customize_Control instance.
       
   323 		 */
   181 		do_action( 'customize_render_control', $this );
   324 		do_action( 'customize_render_control', $this );
       
   325 
       
   326 		/**
       
   327 		 * Fires just before a specific Customizer control is rendered.
       
   328 		 *
       
   329 		 * The dynamic portion of the hook name, `$this->id`, refers to
       
   330 		 * the control ID.
       
   331 		 *
       
   332 		 * @since 3.4.0
       
   333 		 *
       
   334 		 * @param WP_Customize_Control $this {@see WP_Customize_Control} instance.
       
   335 		 */
   182 		do_action( 'customize_render_control_' . $this->id, $this );
   336 		do_action( 'customize_render_control_' . $this->id, $this );
   183 
   337 
   184 		$this->render();
   338 		$this->render();
   185 	}
   339 	}
   186 
   340 
   187 	/**
   341 	/**
   188 	 * Render the control. Renders the control wrapper, then calls $this->render_content().
   342 	 * Renders the control wrapper and calls $this->render_content() for the internals.
   189 	 *
   343 	 *
   190 	 * @since 3.4.0
   344 	 * @since 3.4.0
   191 	 */
   345 	 */
   192 	protected function render() {
   346 	protected function render() {
   193 		$id    = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
   347 		$id    = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
   197 			<?php $this->render_content(); ?>
   351 			<?php $this->render_content(); ?>
   198 		</li><?php
   352 		</li><?php
   199 	}
   353 	}
   200 
   354 
   201 	/**
   355 	/**
   202 	 * Get the data link parameter for a setting.
   356 	 * Get the data link attribute for a setting.
   203 	 *
   357 	 *
   204 	 * @since 3.4.0
   358 	 * @since 3.4.0
   205 	 *
   359 	 *
   206 	 * @param string $setting_key
   360 	 * @param string $setting_key
   207 	 * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
   361 	 * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
   212 
   366 
   213 		return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
   367 		return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
   214 	}
   368 	}
   215 
   369 
   216 	/**
   370 	/**
   217 	 * Render the data link parameter for a setting
   371 	 * Render the data link attribute for the control's input element.
   218 	 *
   372 	 *
   219 	 * @since 3.4.0
   373 	 * @since 3.4.0
   220 	 * @uses WP_Customize_Control::get_link()
   374 	 * @uses WP_Customize_Control::get_link()
   221 	 *
   375 	 *
   222 	 * @param string $setting_key
   376 	 * @param string $setting_key
   224 	public function link( $setting_key = 'default' ) {
   378 	public function link( $setting_key = 'default' ) {
   225 		echo $this->get_link( $setting_key );
   379 		echo $this->get_link( $setting_key );
   226 	}
   380 	}
   227 
   381 
   228 	/**
   382 	/**
       
   383 	 * Render the custom attributes for the control's input element.
       
   384 	 *
       
   385 	 * @since 4.0.0
       
   386 	 * @access public
       
   387 	 */
       
   388 	public function input_attrs() {
       
   389 		foreach( $this->input_attrs as $attr => $value ) {
       
   390 			echo $attr . '="' . esc_attr( $value ) . '" ';
       
   391 		}
       
   392 	}
       
   393 
       
   394 	/**
   229 	 * Render the control's content.
   395 	 * Render the control's content.
   230 	 *
   396 	 *
   231 	 * Allows the content to be overriden without having to rewrite the wrapper.
   397 	 * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
       
   398 	 *
       
   399 	 * Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
       
   400 	 * Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
       
   401 	 *
       
   402 	 * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}.
   232 	 *
   403 	 *
   233 	 * @since 3.4.0
   404 	 * @since 3.4.0
   234 	 */
   405 	 */
   235 	protected function render_content() {
   406 	protected function render_content() {
   236 		switch( $this->type ) {
   407 		switch( $this->type ) {
   237 			case 'text':
       
   238 				?>
       
   239 				<label>
       
   240 					<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
       
   241 					<input type="text" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
       
   242 				</label>
       
   243 				<?php
       
   244 				break;
       
   245 			case 'checkbox':
   408 			case 'checkbox':
   246 				?>
   409 				?>
   247 				<label>
   410 				<label>
   248 					<input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
   411 					<input type="checkbox" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); checked( $this->value() ); ?> />
   249 					<?php echo esc_html( $this->label ); ?>
   412 					<?php echo esc_html( $this->label ); ?>
       
   413 					<?php if ( ! empty( $this->description ) ) : ?>
       
   414 						<span class="description customize-control-description"><?php echo $this->description; ?></span>
       
   415 					<?php endif; ?>
   250 				</label>
   416 				</label>
   251 				<?php
   417 				<?php
   252 				break;
   418 				break;
   253 			case 'radio':
   419 			case 'radio':
   254 				if ( empty( $this->choices ) )
   420 				if ( empty( $this->choices ) )
   255 					return;
   421 					return;
   256 
   422 
   257 				$name = '_customize-radio-' . $this->id;
   423 				$name = '_customize-radio-' . $this->id;
   258 
   424 
   259 				?>
   425 				if ( ! empty( $this->label ) ) : ?>
   260 				<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   426 					<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   261 				<?php
   427 				<?php endif;
       
   428 				if ( ! empty( $this->description ) ) : ?>
       
   429 					<span class="description customize-control-description"><?php echo $this->description ; ?></span>
       
   430 				<?php endif;
       
   431 
   262 				foreach ( $this->choices as $value => $label ) :
   432 				foreach ( $this->choices as $value => $label ) :
   263 					?>
   433 					?>
   264 					<label>
   434 					<label>
   265 						<input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />
   435 						<input type="radio" value="<?php echo esc_attr( $value ); ?>" name="<?php echo esc_attr( $name ); ?>" <?php $this->link(); checked( $this->value(), $value ); ?> />
   266 						<?php echo esc_html( $label ); ?><br/>
   436 						<?php echo esc_html( $label ); ?><br/>
   272 				if ( empty( $this->choices ) )
   442 				if ( empty( $this->choices ) )
   273 					return;
   443 					return;
   274 
   444 
   275 				?>
   445 				?>
   276 				<label>
   446 				<label>
   277 					<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   447 					<?php if ( ! empty( $this->label ) ) : ?>
       
   448 						<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
       
   449 					<?php endif;
       
   450 					if ( ! empty( $this->description ) ) : ?>
       
   451 						<span class="description customize-control-description"><?php echo $this->description; ?></span>
       
   452 					<?php endif; ?>
       
   453 
   278 					<select <?php $this->link(); ?>>
   454 					<select <?php $this->link(); ?>>
   279 						<?php
   455 						<?php
   280 						foreach ( $this->choices as $value => $label )
   456 						foreach ( $this->choices as $value => $label )
   281 							echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
   457 							echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
   282 						?>
   458 						?>
   283 					</select>
   459 					</select>
       
   460 				</label>
       
   461 				<?php
       
   462 				break;
       
   463 			case 'textarea':
       
   464 				?>
       
   465 				<label>
       
   466 					<?php if ( ! empty( $this->label ) ) : ?>
       
   467 						<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
       
   468 					<?php endif;
       
   469 					if ( ! empty( $this->description ) ) : ?>
       
   470 						<span class="description customize-control-description"><?php echo $this->description; ?></span>
       
   471 					<?php endif; ?>
       
   472 					<textarea rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
   284 				</label>
   473 				</label>
   285 				<?php
   474 				<?php
   286 				break;
   475 				break;
   287 			case 'dropdown-pages':
   476 			case 'dropdown-pages':
   288 				$dropdown = wp_dropdown_pages(
   477 				$dropdown = wp_dropdown_pages(
   302 					'<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
   491 					'<label class="customize-control-select"><span class="customize-control-title">%s</span> %s</label>',
   303 					$this->label,
   492 					$this->label,
   304 					$dropdown
   493 					$dropdown
   305 				);
   494 				);
   306 				break;
   495 				break;
   307 		}
   496 			default:
   308 	}
   497 				?>
       
   498 				<label>
       
   499 					<?php if ( ! empty( $this->label ) ) : ?>
       
   500 						<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
       
   501 					<?php endif;
       
   502 					if ( ! empty( $this->description ) ) : ?>
       
   503 						<span class="description customize-control-description"><?php echo $this->description; ?></span>
       
   504 					<?php endif; ?>
       
   505 					<input type="<?php echo esc_attr( $this->type ); ?>" <?php $this->input_attrs(); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
       
   506 				</label>
       
   507 				<?php
       
   508 				break;
       
   509 		}
       
   510 	}
       
   511 
       
   512 	/**
       
   513 	 * Render the control's JS template.
       
   514 	 *
       
   515 	 * This function is only run for control types that have been registered with
       
   516 	 * {@see WP_Customize_Manager::register_control_type()}.
       
   517 	 *
       
   518 	 * In the future, this will also print the template for the control's container
       
   519 	 * element and be override-able.
       
   520 	 *
       
   521 	 * @since 4.1.0
       
   522 	 */
       
   523 	final public function print_template() {
       
   524 		?>
       
   525 		<script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
       
   526 			<?php $this->content_template(); ?>
       
   527 		</script>
       
   528 		<?php
       
   529 	}
       
   530 
       
   531 	/**
       
   532 	 * An Underscore (JS) template for this control's content (but not its container).
       
   533 	 *
       
   534 	 * Class variables for this control class are available in the `data` JS object;
       
   535 	 * export custom variables by overriding {@see WP_Customize_Control::to_json()}.
       
   536 	 *
       
   537 	 * @see WP_Customize_Control::print_template()
       
   538 	 *
       
   539 	 * @since 4.1.0
       
   540 	 */
       
   541 	protected function content_template() {}
       
   542 
   309 }
   543 }
   310 
   544 
   311 /**
   545 /**
   312  * Customize Color Control Class
   546  * Customize Color Control class.
   313  *
   547  *
   314  * @package WordPress
       
   315  * @subpackage Customize
       
   316  * @since 3.4.0
   548  * @since 3.4.0
       
   549  *
       
   550  * @see WP_Customize_Control
   317  */
   551  */
   318 class WP_Customize_Color_Control extends WP_Customize_Control {
   552 class WP_Customize_Color_Control extends WP_Customize_Control {
   319 	/**
   553 	/**
   320 	 * @access public
   554 	 * @access public
   321 	 * @var string
   555 	 * @var string
   328 	 */
   562 	 */
   329 	public $statuses;
   563 	public $statuses;
   330 
   564 
   331 	/**
   565 	/**
   332 	 * Constructor.
   566 	 * Constructor.
   333 	 *
       
   334 	 * If $args['settings'] is not defined, use the $id as the setting ID.
       
   335 	 *
   567 	 *
   336 	 * @since 3.4.0
   568 	 * @since 3.4.0
   337 	 * @uses WP_Customize_Control::__construct()
   569 	 * @uses WP_Customize_Control::__construct()
   338 	 *
   570 	 *
   339 	 * @param WP_Customize_Manager $manager
   571 	 * @param WP_Customize_Manager $manager
   344 		$this->statuses = array( '' => __('Default') );
   576 		$this->statuses = array( '' => __('Default') );
   345 		parent::__construct( $manager, $id, $args );
   577 		parent::__construct( $manager, $id, $args );
   346 	}
   578 	}
   347 
   579 
   348 	/**
   580 	/**
   349 	 * Enqueue control related scripts/styles.
   581 	 * Enqueue scripts/styles for the color picker.
   350 	 *
   582 	 *
   351 	 * @since 3.4.0
   583 	 * @since 3.4.0
   352 	 */
   584 	 */
   353 	public function enqueue() {
   585 	public function enqueue() {
   354 		wp_enqueue_script( 'wp-color-picker' );
   586 		wp_enqueue_script( 'wp-color-picker' );
   362 	 * @uses WP_Customize_Control::to_json()
   594 	 * @uses WP_Customize_Control::to_json()
   363 	 */
   595 	 */
   364 	public function to_json() {
   596 	public function to_json() {
   365 		parent::to_json();
   597 		parent::to_json();
   366 		$this->json['statuses'] = $this->statuses;
   598 		$this->json['statuses'] = $this->statuses;
   367 	}
   599 		$this->json['defaultValue'] = $this->setting->default;
   368 
   600 	}
   369 	/**
   601 
   370 	 * Render the control's content.
   602 	/**
   371 	 *
   603 	 * Don't render the control content from PHP, as it's rendered via JS on load.
   372 	 * @since 3.4.0
   604 	 *
   373 	 */
   605 	 * @since 3.4.0
   374 	public function render_content() {
   606 	 */
   375 		$this_default = $this->setting->default;
   607 	public function render_content() {}
   376 		$default_attr = '';
   608 
   377 		if ( $this_default ) {
   609 	/**
   378 			if ( false === strpos( $this_default, '#' ) )
   610 	 * Render a JS template for the content of the color picker control.
   379 				$this_default = '#' . $this_default;
   611 	 *
   380 			$default_attr = ' data-default-color="' . esc_attr( $this_default ) . '"';
   612 	 * @since 4.1.0
   381 		}
   613 	 */
   382 		// The input's value gets set by JS. Don't fill it.
   614 	public function content_template() {
   383 		?>
   615 		?>
       
   616 		<# var defaultValue = '';
       
   617 		if ( data.defaultValue ) {
       
   618 			if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
       
   619 				defaultValue = '#' + data.defaultValue;
       
   620 			} else {
       
   621 				defaultValue = data.defaultValue;
       
   622 			}
       
   623 			defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
       
   624 		} #>
   384 		<label>
   625 		<label>
   385 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   626 			<# if ( data.label ) { #>
       
   627 				<span class="customize-control-title">{{{ data.label }}}</span>
       
   628 			<# } #>
       
   629 			<# if ( data.description ) { #>
       
   630 				<span class="description customize-control-description">{{{ data.description }}}</span>
       
   631 			<# } #>
   386 			<div class="customize-control-content">
   632 			<div class="customize-control-content">
   387 				<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>"<?php echo $default_attr; ?> />
   633 				<input class="color-picker-hex" type="text" maxlength="7" placeholder="<?php esc_attr_e( 'Hex Value' ); ?>" {{ defaultValue }} />
   388 			</div>
   634 			</div>
   389 		</label>
   635 		</label>
   390 		<?php
   636 		<?php
   391 	}
   637 	}
   392 }
   638 }
   393 
   639 
   394 /**
   640 /**
   395  * Customize Upload Control Class
   641  * Customize Media Control class.
   396  *
   642  *
   397  * @package WordPress
   643  * @since 4.2.0
   398  * @subpackage Customize
   644  *
   399  * @since 3.4.0
   645  * @see WP_Customize_Control
   400  */
   646  */
   401 class WP_Customize_Upload_Control extends WP_Customize_Control {
   647 class WP_Customize_Media_Control extends WP_Customize_Control {
   402 	public $type    = 'upload';
   648 	/**
   403 	public $removed = '';
   649 	 * Control type.
   404 	public $context;
   650 	 *
   405 	public $extensions = array();
   651 	 * @since 4.2.0
       
   652 	 * @access public
       
   653 	 * @var string
       
   654 	 */
       
   655 	public $type = 'media';
       
   656 
       
   657 	/**
       
   658 	 * Media control mime type.
       
   659 	 *
       
   660 	 * @since 4.2.0
       
   661 	 * @access public
       
   662 	 * @var string
       
   663 	 */
       
   664 	public $mime_type = '';
       
   665 
       
   666 	/**
       
   667 	 * Button labels.
       
   668 	 *
       
   669 	 * @since 4.2.0
       
   670 	 * @access public
       
   671 	 * @var array
       
   672 	 */
       
   673 	public $button_labels = array();
       
   674 
       
   675 	/**
       
   676 	 * Constructor.
       
   677 	 *
       
   678 	 * @since 4.1.0
       
   679 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
       
   680 	 *
       
   681 	 * @param WP_Customize_Manager $manager {@see WP_Customize_Manager} instance.
       
   682 	 */
       
   683 	public function __construct( $manager, $id, $args = array() ) {
       
   684 		parent::__construct( $manager, $id, $args );
       
   685 
       
   686 		$this->button_labels = array(
       
   687 			'select'       => __( 'Select File' ),
       
   688 			'change'       => __( 'Change File' ),
       
   689 			'default'      => __( 'Default' ),
       
   690 			'remove'       => __( 'Remove' ),
       
   691 			'placeholder'  => __( 'No file selected' ),
       
   692 			'frame_title'  => __( 'Select File' ),
       
   693 			'frame_button' => __( 'Choose File' ),
       
   694 		);
       
   695 	}
   406 
   696 
   407 	/**
   697 	/**
   408 	 * Enqueue control related scripts/styles.
   698 	 * Enqueue control related scripts/styles.
   409 	 *
   699 	 *
   410 	 * @since 3.4.0
   700 	 * @since 3.4.0
       
   701 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
   411 	 */
   702 	 */
   412 	public function enqueue() {
   703 	public function enqueue() {
   413 		wp_enqueue_script( 'wp-plupload' );
   704 		wp_enqueue_media();
   414 	}
   705 	}
   415 
   706 
   416 	/**
   707 	/**
   417 	 * Refresh the parameters passed to the JavaScript via JSON.
   708 	 * Refresh the parameters passed to the JavaScript via JSON.
   418 	 *
   709 	 *
   419 	 * @since 3.4.0
   710 	 * @since 3.4.0
   420 	 * @uses WP_Customize_Control::to_json()
   711 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
       
   712 	 *
       
   713 	 * @see WP_Customize_Control::to_json()
   421 	 */
   714 	 */
   422 	public function to_json() {
   715 	public function to_json() {
   423 		parent::to_json();
   716 		parent::to_json();
   424 
   717 		$this->json['mime_type'] = $this->mime_type;
   425 		$this->json['removed'] = $this->removed;
   718 		$this->json['button_labels'] = $this->button_labels;
   426 
   719 
   427 		if ( $this->context )
   720 		$value = $this->value();
   428 			$this->json['context'] = $this->context;
   721 
   429 
   722 		if ( is_object( $this->setting ) ) {
   430 		if ( $this->extensions )
   723 			if ( $this->setting->default ) {
   431 			$this->json['extensions'] = implode( ',', $this->extensions );
   724 				// Fake an attachment model - needs all fields used by template.
   432 	}
   725 				// Note that the default value must be a URL, NOT an attachment ID.
   433 
   726 				$type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
   434 	/**
   727 				$default_attachment = array(
   435 	 * Render the control's content.
   728 					'id' => 1,
   436 	 *
   729 					'url' => $this->setting->default,
   437 	 * @since 3.4.0
   730 					'type' => $type,
   438 	 */
   731 					'icon' => wp_mime_type_icon( $type ),
   439 	public function render_content() {
   732 					'title' => basename( $this->setting->default ),
       
   733 				);
       
   734 
       
   735 				if ( 'image' === $type ) {
       
   736 					$default_attachment['sizes'] = array(
       
   737 						'full' => array( 'url' => $this->setting->default ),
       
   738 					);
       
   739 				}
       
   740 
       
   741 				$this->json['defaultAttachment'] = $default_attachment;
       
   742 			}
       
   743 
       
   744 			if ( $value && $this->setting->default && $value === $this->setting->default ) {
       
   745 				// Set the default as the attachment.
       
   746 				$this->json['attachment'] = $this->json['defaultAttachment'];
       
   747 			} elseif ( $value ) {
       
   748 				$this->json['attachment'] = wp_prepare_attachment_for_js( $value );
       
   749 			}
       
   750 		}
       
   751 	}
       
   752 
       
   753 	/**
       
   754 	 * Don't render any content for this control from PHP.
       
   755 	 *
       
   756 	 * @since 3.4.0
       
   757 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
       
   758 	 *
       
   759 	 * @see WP_Customize_Media_Control::content_template()
       
   760 	 */
       
   761 	public function render_content() {}
       
   762 
       
   763 	/**
       
   764 	 * Render a JS template for the content of the media control.
       
   765 	 *
       
   766 	 * @since 4.1.0
       
   767 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
       
   768 	 */
       
   769 	public function content_template() {
   440 		?>
   770 		?>
   441 		<label>
   771 		<label for="{{ data.settings['default'] }}-button">
   442 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
   772 			<# if ( data.label ) { #>
   443 			<div>
   773 				<span class="customize-control-title">{{ data.label }}</span>
   444 				<a href="#" class="button-secondary upload"><?php _e( 'Upload' ); ?></a>
   774 			<# } #>
   445 				<a href="#" class="remove"><?php _e( 'Remove' ); ?></a>
   775 			<# if ( data.description ) { #>
       
   776 				<span class="description customize-control-description">{{{ data.description }}}</span>
       
   777 			<# } #>
       
   778 		</label>
       
   779 
       
   780 		<# if ( data.attachment && data.attachment.id ) { #>
       
   781 			<div class="current">
       
   782 				<div class="container">
       
   783 					<div class="attachment-media-view attachment-media-view-{{ data.attachment.type }} {{ data.attachment.orientation }}">
       
   784 						<div class="thumbnail thumbnail-{{ data.attachment.type }}">
       
   785 							<# if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.medium ) { #>
       
   786 								<img class="attachment-thumb" src="{{ data.attachment.sizes.medium.url }}" draggable="false" />
       
   787 							<# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #>
       
   788 								<img class="attachment-thumb" src="{{ data.attachment.sizes.full.url }}" draggable="false" />
       
   789 							<# } else if ( 'audio' === data.attachment.type ) { #>
       
   790 								<# if ( data.attachment.image && data.attachment.image.src && data.attachment.image.src !== data.attachment.icon ) { #>
       
   791 									<img src="{{ data.attachment.image.src }}" class="thumbnail" draggable="false" />
       
   792 								<# } else { #>
       
   793 									<img src="{{ data.attachment.icon }}" class="attachment-thumb type-icon" draggable="false" />
       
   794 								<# } #>
       
   795 								<p class="attachment-meta attachment-meta-title">&#8220;{{ data.attachment.title }}&#8221;</p>
       
   796 								<# if ( data.attachment.album || data.attachment.meta.album ) { #>
       
   797 								<p class="attachment-meta"><em>{{ data.attachment.album || data.attachment.meta.album }}</em></p>
       
   798 								<# } #>
       
   799 								<# if ( data.attachment.artist || data.attachment.meta.artist ) { #>
       
   800 								<p class="attachment-meta">{{ data.attachment.artist || data.attachment.meta.artist }}</p>
       
   801 								<# } #>
       
   802 								<audio style="visibility: hidden" controls class="wp-audio-shortcode" width="100%" preload="none">
       
   803 									<source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
       
   804 								</audio>
       
   805 							<# } else if ( 'video' === data.attachment.type ) { #>
       
   806 								<div class="wp-media-wrapper wp-video">
       
   807 									<video controls="controls" class="wp-video-shortcode" preload="metadata"
       
   808 										<# if ( data.attachment.image && data.attachment.image.src !== data.attachment.icon ) { #>poster="{{ data.attachment.image.src }}"<# } #>>
       
   809 										<source type="{{ data.attachment.mime }}" src="{{ data.attachment.url }}"/>
       
   810 									</video>
       
   811 								</div>
       
   812 							<# } else { #>
       
   813 								<img class="attachment-thumb type-icon" src="{{ data.attachment.icon }}" class="icon" draggable="false" />
       
   814 								<p class="attachment-title">{{ data.attachment.title }}</p>
       
   815 							<# } #>
       
   816 						</div>
       
   817 					</div>
       
   818 				</div>
   446 			</div>
   819 			</div>
   447 		</label>
   820 			<div class="actions">
       
   821 				<button type="button" class="button remove-button"><?php echo $this->button_labels['remove']; ?></button>
       
   822 				<button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['change']; ?></button>
       
   823 				<div style="clear:both"></div>
       
   824 			</div>
       
   825 		<# } else { #>
       
   826 			<div class="current">
       
   827 				<div class="container">
       
   828 					<div class="placeholder">
       
   829 						<div class="inner">
       
   830 							<span>
       
   831 								<?php echo $this->button_labels['placeholder']; ?>
       
   832 							</span>
       
   833 						</div>
       
   834 					</div>
       
   835 				</div>
       
   836 			</div>
       
   837 			<div class="actions">
       
   838 				<# if ( data.defaultAttachment ) { #>
       
   839 					<button type="button" class="button default-button"><?php echo $this->button_labels['default']; ?></button>
       
   840 				<# } #>
       
   841 				<button type="button" class="button upload-button" id="{{ data.settings['default'] }}-button"><?php echo $this->button_labels['select']; ?></button>
       
   842 				<div style="clear:both"></div>
       
   843 			</div>
       
   844 		<# } #>
   448 		<?php
   845 		<?php
   449 	}
   846 	}
   450 }
   847 }
   451 
   848 
   452 /**
   849 /**
   453  * Customize Image Control Class
   850  * Customize Upload Control Class.
   454  *
   851  *
   455  * @package WordPress
       
   456  * @subpackage Customize
       
   457  * @since 3.4.0
   852  * @since 3.4.0
       
   853  *
       
   854  * @see WP_Customize_Media_Control
       
   855  */
       
   856 class WP_Customize_Upload_Control extends WP_Customize_Media_Control {
       
   857 	public $type          = 'upload';
       
   858 	public $mime_type     = '';
       
   859 	public $button_labels = array();
       
   860 	public $removed = ''; // unused
       
   861 	public $context; // unused
       
   862 	public $extensions = array(); // unused
       
   863 
       
   864 	/**
       
   865 	 * Refresh the parameters passed to the JavaScript via JSON.
       
   866 	 *
       
   867 	 * @since 3.4.0
       
   868 	 *
       
   869 	 * @uses WP_Customize_Media_Control::to_json()
       
   870 	 */
       
   871 	public function to_json() {
       
   872 		parent::to_json();
       
   873 
       
   874 		$value = $this->value();
       
   875 		if ( $value ) {
       
   876 			// Get the attachment model for the existing file.
       
   877 			$attachment_id = attachment_url_to_postid( $value );
       
   878 			if ( $attachment_id ) {
       
   879 				$this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
       
   880 			}
       
   881 		}
       
   882 	}
       
   883 }
       
   884 
       
   885 /**
       
   886  * Customize Image Control class.
       
   887  *
       
   888  * @since 3.4.0
       
   889  *
       
   890  * @see WP_Customize_Upload_Control
   458  */
   891  */
   459 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
   892 class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
   460 	public $type = 'image';
   893 	public $type = 'image';
   461 	public $get_url;
   894 	public $mime_type = 'image';
   462 	public $statuses;
       
   463 	public $extensions = array( 'jpg', 'jpeg', 'gif', 'png' );
       
   464 
       
   465 	protected $tabs = array();
       
   466 
   895 
   467 	/**
   896 	/**
   468 	 * Constructor.
   897 	 * Constructor.
   469 	 *
       
   470 	 * If $args['settings'] is not defined, use the $id as the setting ID.
       
   471 	 *
   898 	 *
   472 	 * @since 3.4.0
   899 	 * @since 3.4.0
   473 	 * @uses WP_Customize_Upload_Control::__construct()
   900 	 * @uses WP_Customize_Upload_Control::__construct()
   474 	 *
   901 	 *
   475 	 * @param WP_Customize_Manager $manager
   902 	 * @param WP_Customize_Manager $manager
   476 	 * @param string $id
   903 	 * @param string $id
   477 	 * @param array $args
   904 	 * @param array  $args
   478 	 */
   905 	 */
   479 	public function __construct( $manager, $id, $args ) {
   906 	public function __construct( $manager, $id, $args = array() ) {
   480 		$this->statuses = array( '' => __('No Image') );
       
   481 
       
   482 		parent::__construct( $manager, $id, $args );
   907 		parent::__construct( $manager, $id, $args );
   483 
   908 
   484 		$this->add_tab( 'upload-new', __('Upload New'), array( $this, 'tab_upload_new' ) );
   909 		$this->button_labels = array(
   485 		$this->add_tab( 'uploaded',   __('Uploaded'),   array( $this, 'tab_uploaded' ) );
   910 			'select'       => __( 'Select Image' ),
   486 
   911 			'change'       => __( 'Change Image' ),
   487 		// Early priority to occur before $this->manager->prepare_controls();
   912 			'remove'       => __( 'Remove' ),
   488 		add_action( 'customize_controls_init', array( $this, 'prepare_control' ), 5 );
   913 			'default'      => __( 'Default' ),
   489 	}
   914 			'placeholder'  => __( 'No image selected' ),
   490 
   915 			'frame_title'  => __( 'Select Image' ),
   491 	/**
   916 			'frame_button' => __( 'Choose Image' ),
   492 	 * Prepares the control.
   917 		);
   493 	 *
   918 	}
   494 	 * If no tabs exist, removes the control from the manager.
   919 
   495 	 *
   920 	/**
   496 	 * @since 3.4.2
   921 	 * @since 3.4.2
   497 	 */
   922 	 * @deprecated 4.1.0
   498 	public function prepare_control() {
   923 	 */
   499 		if ( ! $this->tabs )
   924 	public function prepare_control() {}
   500 			$this->manager->remove_control( $this->id );
   925 
   501 	}
   926 	/**
   502 
   927 	 * @since 3.4.0
   503 	/**
   928 	 * @deprecated 4.1.0
   504 	 * Refresh the parameters passed to the JavaScript via JSON.
       
   505 	 *
       
   506 	 * @since 3.4.0
       
   507 	 * @uses WP_Customize_Upload_Control::to_json()
       
   508 	 */
       
   509 	public function to_json() {
       
   510 		parent::to_json();
       
   511 		$this->json['statuses'] = $this->statuses;
       
   512 	}
       
   513 
       
   514 	/**
       
   515 	 * Render the control's content.
       
   516 	 *
       
   517 	 * @since 3.4.0
       
   518 	 */
       
   519 	public function render_content() {
       
   520 		$src = $this->value();
       
   521 		if ( isset( $this->get_url ) )
       
   522 			$src = call_user_func( $this->get_url, $src );
       
   523 
       
   524 		?>
       
   525 		<div class="customize-image-picker">
       
   526 			<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
       
   527 
       
   528 			<div class="customize-control-content">
       
   529 				<div class="dropdown preview-thumbnail" tabindex="0">
       
   530 					<div class="dropdown-content">
       
   531 						<?php if ( empty( $src ) ): ?>
       
   532 							<img style="display:none;" />
       
   533 						<?php else: ?>
       
   534 							<img src="<?php echo esc_url( set_url_scheme( $src ) ); ?>" />
       
   535 						<?php endif; ?>
       
   536 						<div class="dropdown-status"></div>
       
   537 					</div>
       
   538 					<div class="dropdown-arrow"></div>
       
   539 				</div>
       
   540 			</div>
       
   541 
       
   542 			<div class="library">
       
   543 				<ul>
       
   544 					<?php foreach ( $this->tabs as $id => $tab ): ?>
       
   545 						<li data-customize-tab='<?php echo esc_attr( $id ); ?>' tabindex='0'>
       
   546 							<?php echo esc_html( $tab['label'] ); ?>
       
   547 						</li>
       
   548 					<?php endforeach; ?>
       
   549 				</ul>
       
   550 				<?php foreach ( $this->tabs as $id => $tab ): ?>
       
   551 					<div class="library-content" data-customize-tab='<?php echo esc_attr( $id ); ?>'>
       
   552 						<?php call_user_func( $tab['callback'] ); ?>
       
   553 					</div>
       
   554 				<?php endforeach; ?>
       
   555 			</div>
       
   556 
       
   557 			<div class="actions">
       
   558 				<a href="#" class="remove"><?php _e( 'Remove Image' ); ?></a>
       
   559 			</div>
       
   560 		</div>
       
   561 		<?php
       
   562 	}
       
   563 
       
   564 	/**
       
   565 	 * Add a tab to the control.
       
   566 	 *
       
   567 	 * @since 3.4.0
       
   568 	 *
   929 	 *
   569 	 * @param string $id
   930 	 * @param string $id
   570 	 * @param string $label
   931 	 * @param string $label
   571 	 * @param mixed $callback
   932 	 * @param mixed $callback
   572 	 */
   933 	 */
   573 	public function add_tab( $id, $label, $callback ) {
   934 	public function add_tab( $id, $label, $callback ) {}
   574 		$this->tabs[ $id ] = array(
   935 
   575 			'label'    => $label,
   936 	/**
   576 			'callback' => $callback,
   937 	 * @since 3.4.0
   577 		);
   938 	 * @deprecated 4.1.0
   578 	}
       
   579 
       
   580 	/**
       
   581 	 * Remove a tab from the control.
       
   582 	 *
       
   583 	 * @since 3.4.0
       
   584 	 *
   939 	 *
   585 	 * @param string $id
   940 	 * @param string $id
   586 	 */
   941 	 */
   587 	public function remove_tab( $id ) {
   942 	public function remove_tab( $id ) {}
   588 		unset( $this->tabs[ $id ] );
   943 
   589 	}
   944 	/**
   590 
   945 	 * @since 3.4.0
   591 	/**
   946 	 * @deprecated 4.1.0
   592 	 * @since 3.4.0
       
   593 	 */
       
   594 	public function tab_upload_new() {
       
   595 		if ( ! _device_can_upload() ) {
       
   596 			echo '<p>' . sprintf( __('The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.'), 'http://wordpress.org/mobile/' ) . '</p>';
       
   597 		} else {
       
   598 			?>
       
   599 			<div class="upload-dropzone">
       
   600 				<?php _e('Drop a file here or <a href="#" class="upload">select a file</a>.'); ?>
       
   601 			</div>
       
   602 			<div class="upload-fallback">
       
   603 				<span class="button-secondary"><?php _e('Select File'); ?></span>
       
   604 			</div>
       
   605 			<?php
       
   606 		}
       
   607 	}
       
   608 
       
   609 	/**
       
   610 	 * @since 3.4.0
       
   611 	 */
       
   612 	public function tab_uploaded() {
       
   613 		?>
       
   614 		<div class="uploaded-target"></div>
       
   615 		<?php
       
   616 	}
       
   617 
       
   618 	/**
       
   619 	 * @since 3.4.0
       
   620 	 *
   947 	 *
   621 	 * @param string $url
   948 	 * @param string $url
   622 	 * @param string $thumbnail_url
   949 	 * @param string $thumbnail_url
   623 	 */
   950 	 */
   624 	public function print_tab_image( $url, $thumbnail_url = null ) {
   951 	public function print_tab_image( $url, $thumbnail_url = null ) {}
   625 		$url = set_url_scheme( $url );
       
   626 		$thumbnail_url = ( $thumbnail_url ) ? set_url_scheme( $thumbnail_url ) : $url;
       
   627 		?>
       
   628 		<a href="#" class="thumbnail" data-customize-image-value="<?php echo esc_url( $url ); ?>">
       
   629 			<img src="<?php echo esc_url( $thumbnail_url ); ?>" />
       
   630 		</a>
       
   631 		<?php
       
   632 	}
       
   633 }
   952 }
   634 
   953 
   635 /**
   954 /**
   636  * Customize Background Image Control Class
   955  * Customize Background Image Control class.
   637  *
   956  *
   638  * @package WordPress
       
   639  * @subpackage Customize
       
   640  * @since 3.4.0
   957  * @since 3.4.0
       
   958  *
       
   959  * @see WP_Customize_Image_Control
   641  */
   960  */
   642 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
   961 class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control {
       
   962 	public $type = 'background';
   643 
   963 
   644 	/**
   964 	/**
   645 	 * Constructor.
   965 	 * Constructor.
   646 	 *
   966 	 *
   647 	 * @since 3.4.0
   967 	 * @since 3.4.0
   651 	 */
   971 	 */
   652 	public function __construct( $manager ) {
   972 	public function __construct( $manager ) {
   653 		parent::__construct( $manager, 'background_image', array(
   973 		parent::__construct( $manager, 'background_image', array(
   654 			'label'    => __( 'Background Image' ),
   974 			'label'    => __( 'Background Image' ),
   655 			'section'  => 'background_image',
   975 			'section'  => 'background_image',
   656 			'context'  => 'custom-background',
       
   657 			'get_url'  => 'get_background_image',
       
   658 		) );
   976 		) );
   659 
   977 	}
   660 		if ( $this->setting->default )
   978 
   661 			$this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_background' ) );
   979 	/**
   662 	}
   980 	 * Enqueue control related scripts/styles.
   663 
   981 	 *
   664 	/**
   982 	 * @since 4.1.0
   665 	 * @since 3.4.0
   983 	 */
   666 	 */
   984 	public function enqueue() {
   667 	public function tab_uploaded() {
   985 		parent::enqueue();
   668 		$backgrounds = get_posts( array(
   986 
   669 			'post_type'  => 'attachment',
   987 		wp_localize_script( 'customize-controls', '_wpCustomizeBackground', array(
   670 			'meta_key'   => '_wp_attachment_is_custom_background',
   988 			'nonces' => array(
   671 			'meta_value' => $this->manager->get_stylesheet(),
   989 				'add' => wp_create_nonce( 'background-add' ),
   672 			'orderby'    => 'none',
   990 			),
   673 			'nopaging'   => true,
       
   674 		) );
   991 		) );
   675 
       
   676 		?><div class="uploaded-target"></div><?php
       
   677 
       
   678 		if ( empty( $backgrounds ) )
       
   679 			return;
       
   680 
       
   681 		foreach ( (array) $backgrounds as $background )
       
   682 			$this->print_tab_image( esc_url_raw( $background->guid ) );
       
   683 	}
       
   684 
       
   685 	/**
       
   686 	 * @since 3.4.0
       
   687 	 * @uses WP_Customize_Image_Control::print_tab_image()
       
   688 	 */
       
   689 	public function tab_default_background() {
       
   690 		$this->print_tab_image( $this->setting->default );
       
   691 	}
   992 	}
   692 }
   993 }
   693 
   994 
   694 /**
   995 /**
   695  * Customize Header Image Control Class
   996  * Customize Header Image Control class.
   696  *
   997  *
   697  * @package WordPress
       
   698  * @subpackage Customize
       
   699  * @since 3.4.0
   998  * @since 3.4.0
       
   999  *
       
  1000  * @see WP_Customize_Image_Control
   700  */
  1001  */
   701 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
  1002 class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control {
   702 	/**
  1003 	public $type = 'header';
   703 	 * The processed default headers.
  1004 	public $uploaded_headers;
   704 	 * @since 3.4.2
  1005 	public $default_headers;
   705 	 * @var array
  1006 
   706 	 */
  1007 	/**
   707 	protected $default_headers;
       
   708 
       
   709 	/**
       
   710 	 * The uploaded headers.
       
   711 	 * @since 3.4.2
       
   712 	 * @var array
       
   713 	 */
       
   714 	protected $uploaded_headers;
       
   715 
       
   716 	/**
       
   717 	 * Constructor.
       
   718 	 *
       
   719 	 * @since 3.4.0
       
   720 	 * @uses WP_Customize_Image_Control::__construct()
       
   721 	 * @uses WP_Customize_Image_Control::add_tab()
       
   722 	 *
       
   723 	 * @param WP_Customize_Manager $manager
  1008 	 * @param WP_Customize_Manager $manager
   724 	 */
  1009 	 */
   725 	public function __construct( $manager ) {
  1010 	public function __construct( $manager ) {
   726 		parent::__construct( $manager, 'header_image', array(
  1011 		parent::__construct( $manager, 'header_image', array(
   727 			'label'    => __( 'Header Image' ),
  1012 			'label'    => __( 'Header Image' ),
   728 			'settings' => array(
  1013 			'settings' => array(
   729 				'default' => 'header_image',
  1014 				'default' => 'header_image',
   730 				'data'    => 'header_image_data',
  1015 				'data'    => 'header_image_data',
   731 			),
  1016 			),
   732 			'section'  => 'header_image',
  1017 			'section'  => 'header_image',
   733 			'context'  => 'custom-header',
       
   734 			'removed'  => 'remove-header',
  1018 			'removed'  => 'remove-header',
   735 			'get_url'  => 'get_header_image',
  1019 			'get_url'  => 'get_header_image',
   736 			'statuses' => array(
       
   737 				''                      => __('Default'),
       
   738 				'remove-header'         => __('No Image'),
       
   739 				'random-default-image'  => __('Random Default Image'),
       
   740 				'random-uploaded-image' => __('Random Uploaded Image'),
       
   741 			)
       
   742 		) );
  1020 		) );
   743 
  1021 
   744 		// Remove the upload tab.
  1022 	}
   745 		$this->remove_tab( 'upload-new' );
  1023 
   746 	}
  1024 	public function enqueue() {
   747 
  1025 		wp_enqueue_media();
   748 	/**
  1026 		wp_enqueue_script( 'customize-views' );
   749 	 * Prepares the control.
  1027 
   750 	 *
  1028 		$this->prepare_control();
   751 	 * If no tabs exist, removes the control from the manager.
  1029 
   752 	 *
  1030 		wp_localize_script( 'customize-views', '_wpCustomizeHeader', array(
   753 	 * @since 3.4.2
  1031 			'data' => array(
   754 	 */
  1032 				'width' => absint( get_theme_support( 'custom-header', 'width' ) ),
       
  1033 				'height' => absint( get_theme_support( 'custom-header', 'height' ) ),
       
  1034 				'flex-width' => absint( get_theme_support( 'custom-header', 'flex-width' ) ),
       
  1035 				'flex-height' => absint( get_theme_support( 'custom-header', 'flex-height' ) ),
       
  1036 				'currentImgSrc' => $this->get_current_image_src(),
       
  1037 			),
       
  1038 			'nonces' => array(
       
  1039 				'add' => wp_create_nonce( 'header-add' ),
       
  1040 				'remove' => wp_create_nonce( 'header-remove' ),
       
  1041 			),
       
  1042 			'uploads' => $this->uploaded_headers,
       
  1043 			'defaults' => $this->default_headers
       
  1044 		) );
       
  1045 
       
  1046 		parent::enqueue();
       
  1047 	}
       
  1048 
   755 	public function prepare_control() {
  1049 	public function prepare_control() {
   756 		global $custom_image_header;
  1050 		global $custom_image_header;
   757 		if ( empty( $custom_image_header ) )
  1051 		if ( empty( $custom_image_header ) ) {
   758 			return parent::prepare_control();
  1052 			return;
       
  1053 		}
   759 
  1054 
   760 		// Process default headers and uploaded headers.
  1055 		// Process default headers and uploaded headers.
   761 		$custom_image_header->process_default_headers();
  1056 		$custom_image_header->process_default_headers();
   762 		$this->default_headers = $custom_image_header->default_headers;
  1057 		$this->default_headers = $custom_image_header->get_default_header_images();
   763 		$this->uploaded_headers = get_uploaded_header_images();
  1058 		$this->uploaded_headers = $custom_image_header->get_uploaded_header_images();
   764 
  1059 	}
   765 		if ( $this->default_headers )
  1060 
   766 			$this->add_tab( 'default',  __('Default'),  array( $this, 'tab_default_headers' ) );
  1061 	public function print_header_image_template() {
   767 
       
   768 		if ( ! $this->uploaded_headers )
       
   769 			$this->remove_tab( 'uploaded' );
       
   770 
       
   771 		return parent::prepare_control();
       
   772 	}
       
   773 
       
   774 	/**
       
   775 	 * @since 3.4.0
       
   776 	 *
       
   777 	 * @param mixed $choice Which header image to select. (@see Custom_Image_Header::get_header_image() )
       
   778 	 * @param array $header
       
   779 	 */
       
   780 	public function print_header_image( $choice, $header ) {
       
   781 		$header['url']           = set_url_scheme( $header['url'] );
       
   782 		$header['thumbnail_url'] = set_url_scheme( $header['thumbnail_url'] );
       
   783 
       
   784 		$header_image_data = array( 'choice' => $choice );
       
   785 		foreach ( array( 'attachment_id', 'width', 'height', 'url', 'thumbnail_url' ) as $key ) {
       
   786 			if ( isset( $header[ $key ] ) )
       
   787 				$header_image_data[ $key ] = $header[ $key ];
       
   788 		}
       
   789 
       
   790 
       
   791 		?>
  1062 		?>
   792 		<a href="#" class="thumbnail"
  1063 		<script type="text/template" id="tmpl-header-choice">
   793 			data-customize-image-value="<?php echo esc_url( $header['url'] ); ?>"
  1064 			<# if (data.random) { #>
   794 			data-customize-header-image-data="<?php echo esc_attr( json_encode( $header_image_data ) ); ?>">
  1065 					<button type="button" class="button display-options random">
   795 			<img src="<?php echo esc_url( $header['thumbnail_url'] ); ?>" />
  1066 						<span class="dashicons dashicons-randomize dice"></span>
   796 		</a>
  1067 						<# if ( data.type === 'uploaded' ) { #>
       
  1068 							<?php _e( 'Randomize uploaded headers' ); ?>
       
  1069 						<# } else if ( data.type === 'default' ) { #>
       
  1070 							<?php _e( 'Randomize suggested headers' ); ?>
       
  1071 						<# } #>
       
  1072 					</button>
       
  1073 
       
  1074 			<# } else { #>
       
  1075 
       
  1076 			<# if (data.type === 'uploaded') { #>
       
  1077 				<div class="dashicons dashicons-no close"></div>
       
  1078 			<# } #>
       
  1079 
       
  1080 			<button type="button" class="choice thumbnail"
       
  1081 				data-customize-image-value="{{{data.header.url}}}"
       
  1082 				data-customize-header-image-data="{{JSON.stringify(data.header)}}">
       
  1083 				<span class="screen-reader-text"><?php _e( 'Set image' ); ?></span>
       
  1084 				<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}">
       
  1085 			</button>
       
  1086 
       
  1087 			<# } #>
       
  1088 		</script>
       
  1089 
       
  1090 		<script type="text/template" id="tmpl-header-current">
       
  1091 			<# if (data.choice) { #>
       
  1092 				<# if (data.random) { #>
       
  1093 
       
  1094 			<div class="placeholder">
       
  1095 				<div class="inner">
       
  1096 					<span><span class="dashicons dashicons-randomize dice"></span>
       
  1097 					<# if ( data.type === 'uploaded' ) { #>
       
  1098 						<?php _e( 'Randomizing uploaded headers' ); ?>
       
  1099 					<# } else if ( data.type === 'default' ) { #>
       
  1100 						<?php _e( 'Randomizing suggested headers' ); ?>
       
  1101 					<# } #>
       
  1102 					</span>
       
  1103 				</div>
       
  1104 			</div>
       
  1105 
       
  1106 				<# } else { #>
       
  1107 
       
  1108 			<img src="{{{data.header.thumbnail_url}}}" alt="{{{data.header.alt_text || data.header.description}}}" tabindex="0"/>
       
  1109 
       
  1110 				<# } #>
       
  1111 			<# } else { #>
       
  1112 
       
  1113 			<div class="placeholder">
       
  1114 				<div class="inner">
       
  1115 					<span>
       
  1116 						<?php _e( 'No image set' ); ?>
       
  1117 					</span>
       
  1118 				</div>
       
  1119 			</div>
       
  1120 
       
  1121 			<# } #>
       
  1122 		</script>
   797 		<?php
  1123 		<?php
   798 	}
  1124 	}
   799 
  1125 
   800 	/**
  1126 	public function get_current_image_src() {
   801 	 * @since 3.4.0
  1127 		$src = $this->value();
   802 	 */
  1128 		if ( isset( $this->get_url ) ) {
   803 	public function tab_uploaded() {
  1129 			$src = call_user_func( $this->get_url, $src );
   804 		?><div class="uploaded-target"></div><?php
  1130 			return $src;
   805 
  1131 		}
   806 		foreach ( $this->uploaded_headers as $choice => $header )
  1132 		return null;
   807 			$this->print_header_image( $choice, $header );
  1133 	}
   808 	}
  1134 
   809 
  1135 	public function render_content() {
   810 	/**
  1136 		$this->print_header_image_template();
   811 	 * @since 3.4.0
  1137 		$visibility = $this->get_current_image_src() ? '' : ' style="display:none" ';
   812 	 */
  1138 		$width = absint( get_theme_support( 'custom-header', 'width' ) );
   813 	public function tab_default_headers() {
  1139 		$height = absint( get_theme_support( 'custom-header', 'height' ) );
   814 		foreach ( $this->default_headers as $choice => $header )
  1140 		?>
   815 			$this->print_header_image( $choice, $header );
  1141 
       
  1142 
       
  1143 		<div class="customize-control-content">
       
  1144 			<p class="customizer-section-intro">
       
  1145 				<?php
       
  1146 				if ( $width && $height ) {
       
  1147 					printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header size of <strong>%s &times; %s</strong> pixels.' ), $width, $height );
       
  1148 				} elseif ( $width ) {
       
  1149 					printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header width of <strong>%s</strong> pixels.' ), $width );
       
  1150 				} else {
       
  1151 					printf( __( 'While you can crop images to your liking after clicking <strong>Add new image</strong>, your theme recommends a header height of <strong>%s</strong> pixels.' ), $height );
       
  1152 				}
       
  1153 				?>
       
  1154 			</p>
       
  1155 			<div class="current">
       
  1156 				<span class="customize-control-title">
       
  1157 					<?php _e( 'Current header' ); ?>
       
  1158 				</span>
       
  1159 				<div class="container">
       
  1160 				</div>
       
  1161 			</div>
       
  1162 			<div class="actions">
       
  1163 				<?php /* translators: Hide as in hide header image via the Customizer */ ?>
       
  1164 				<button type="button"<?php echo $visibility ?> class="button remove"><?php _ex( 'Hide image', 'custom header' ); ?></button>
       
  1165 				<?php /* translators: New as in add new header image via the Customizer */ ?>
       
  1166 				<button type="button" class="button new"><?php _ex( 'Add new image', 'header image' ); ?></button>
       
  1167 				<div style="clear:both"></div>
       
  1168 			</div>
       
  1169 			<div class="choices">
       
  1170 				<span class="customize-control-title header-previously-uploaded">
       
  1171 					<?php _ex( 'Previously uploaded', 'custom headers' ); ?>
       
  1172 				</span>
       
  1173 				<div class="uploaded">
       
  1174 					<div class="list">
       
  1175 					</div>
       
  1176 				</div>
       
  1177 				<span class="customize-control-title header-default">
       
  1178 					<?php _ex( 'Suggested', 'custom headers' ); ?>
       
  1179 				</span>
       
  1180 				<div class="default">
       
  1181 					<div class="list">
       
  1182 					</div>
       
  1183 				</div>
       
  1184 			</div>
       
  1185 		</div>
       
  1186 		<?php
   816 	}
  1187 	}
   817 }
  1188 }
       
  1189 
       
  1190 /**
       
  1191  * Customize Theme Control class.
       
  1192  *
       
  1193  * @since 4.2.0
       
  1194  *
       
  1195  * @see WP_Customize_Control
       
  1196  */
       
  1197 class WP_Customize_Theme_Control extends WP_Customize_Control {
       
  1198 
       
  1199 	/**
       
  1200 	 * Customize control type.
       
  1201 	 *
       
  1202 	 * @since 4.2.0
       
  1203 	 * @access public
       
  1204 	 * @var string
       
  1205 	 */
       
  1206 	public $type = 'theme';
       
  1207 
       
  1208 	/**
       
  1209 	 * Theme object.
       
  1210 	 *
       
  1211 	 * @since 4.2.0
       
  1212 	 * @access public
       
  1213 	 * @var WP_Theme
       
  1214 	 */
       
  1215 	public $theme;
       
  1216 
       
  1217 	/**
       
  1218 	 * Refresh the parameters passed to the JavaScript via JSON.
       
  1219 	 *
       
  1220 	 * @since 4.2.0
       
  1221 	 * @access public
       
  1222 	 *
       
  1223 	 * @see WP_Customize_Control::to_json()
       
  1224 	 */
       
  1225 	public function to_json() {
       
  1226 		parent::to_json();
       
  1227 		$this->json['theme'] = $this->theme;
       
  1228 	}
       
  1229 
       
  1230 	/**
       
  1231 	 * Don't render the control content from PHP, as it's rendered via JS on load.
       
  1232 	 *
       
  1233 	 * @since 4.2.0
       
  1234 	 * @access public
       
  1235 	 */
       
  1236 	public function render_content() {}
       
  1237 
       
  1238 	/**
       
  1239 	 * Render a JS template for theme display.
       
  1240 	 *
       
  1241 	 * @since 4.2.0
       
  1242 	 * @access public
       
  1243 	 */
       
  1244 	public function content_template() {
       
  1245 		$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
       
  1246 		$active_url  = esc_url( remove_query_arg( 'theme', $current_url ) );
       
  1247 		$preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
       
  1248 		$preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url );
       
  1249 		?>
       
  1250 		<# if ( data.theme.isActiveTheme ) { #>
       
  1251 			<div class="theme active" tabindex="0" data-preview-url="<?php echo esc_attr( $active_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
       
  1252 		<# } else { #>
       
  1253 			<div class="theme" tabindex="0" data-preview-url="<?php echo esc_attr( $preview_url ); ?>" aria-describedby="{{ data.theme.id }}-action {{ data.theme.id }}-name">
       
  1254 		<# } #>
       
  1255 
       
  1256 			<# if ( data.theme.screenshot[0] ) { #>
       
  1257 				<div class="theme-screenshot">
       
  1258 					<img data-src="{{ data.theme.screenshot[0] }}" alt="" />
       
  1259 				</div>
       
  1260 			<# } else { #>
       
  1261 				<div class="theme-screenshot blank"></div>
       
  1262 			<# } #>
       
  1263 
       
  1264 			<# if ( data.theme.isActiveTheme ) { #>
       
  1265 				<span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Customize' ); ?></span>
       
  1266 			<# } else { #>
       
  1267 				<span class="more-details" id="{{ data.theme.id }}-action"><?php _e( 'Live Preview' ); ?></span>
       
  1268 			<# } #>
       
  1269 
       
  1270 			<div class="theme-author"><?php printf( __( 'By %s' ), '{{ data.theme.author }}' ); ?></div>
       
  1271 
       
  1272 			<# if ( data.theme.isActiveTheme ) { #>
       
  1273 				<h3 class="theme-name" id="{{ data.theme.id }}-name">
       
  1274 					<?php
       
  1275 					/* translators: %s: theme name */
       
  1276 					printf( __( '<span>Active:</span> %s' ), '{{ data.theme.name }}' );
       
  1277 					?>
       
  1278 				</h3>
       
  1279 			<# } else { #>
       
  1280 				<h3 class="theme-name" id="{{ data.theme.id }}-name">{{ data.theme.name }}</h3>
       
  1281 				<div class="theme-actions">
       
  1282 					<button type="button" class="button theme-details"><?php _e( 'Theme Details' ); ?></button>
       
  1283 				</div>
       
  1284 			<# } #>
       
  1285 		</div>
       
  1286 	<?php
       
  1287 	}
       
  1288 }
       
  1289 
       
  1290 /**
       
  1291  * Widget Area Customize Control class.
       
  1292  *
       
  1293  * @since 3.9.0
       
  1294  *
       
  1295  * @see WP_Customize_Control
       
  1296  */
       
  1297 class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
       
  1298 	public $type = 'sidebar_widgets';
       
  1299 	public $sidebar_id;
       
  1300 
       
  1301 	public function to_json() {
       
  1302 		parent::to_json();
       
  1303 		$exported_properties = array( 'sidebar_id' );
       
  1304 		foreach ( $exported_properties as $key ) {
       
  1305 			$this->json[ $key ] = $this->$key;
       
  1306 		}
       
  1307 	}
       
  1308 
       
  1309 	public function render_content() {
       
  1310 		?>
       
  1311 		<span class="button-secondary add-new-widget" tabindex="0">
       
  1312 			<?php _e( 'Add a Widget' ); ?>
       
  1313 		</span>
       
  1314 
       
  1315 		<span class="reorder-toggle" tabindex="0">
       
  1316 			<span class="reorder"><?php _ex( 'Reorder', 'Reorder widgets in Customizer' ); ?></span>
       
  1317 			<span class="reorder-done"><?php _ex( 'Done', 'Cancel reordering widgets in Customizer' ); ?></span>
       
  1318 		</span>
       
  1319 		<?php
       
  1320 	}
       
  1321 
       
  1322 }
       
  1323 
       
  1324 /**
       
  1325  * Widget Form Customize Control class.
       
  1326  *
       
  1327  * @since 3.9.0
       
  1328  *
       
  1329  * @see WP_Customize_Control
       
  1330  */
       
  1331 class WP_Widget_Form_Customize_Control extends WP_Customize_Control {
       
  1332 	public $type = 'widget_form';
       
  1333 	public $widget_id;
       
  1334 	public $widget_id_base;
       
  1335 	public $sidebar_id;
       
  1336 	public $is_new = false;
       
  1337 	public $width;
       
  1338 	public $height;
       
  1339 	public $is_wide = false;
       
  1340 
       
  1341 	public function to_json() {
       
  1342 		parent::to_json();
       
  1343 		$exported_properties = array( 'widget_id', 'widget_id_base', 'sidebar_id', 'width', 'height', 'is_wide' );
       
  1344 		foreach ( $exported_properties as $key ) {
       
  1345 			$this->json[ $key ] = $this->$key;
       
  1346 		}
       
  1347 	}
       
  1348 
       
  1349 	public function render_content() {
       
  1350 		global $wp_registered_widgets;
       
  1351 		require_once ABSPATH . '/wp-admin/includes/widgets.php';
       
  1352 
       
  1353 		$widget = $wp_registered_widgets[ $this->widget_id ];
       
  1354 		if ( ! isset( $widget['params'][0] ) ) {
       
  1355 			$widget['params'][0] = array();
       
  1356 		}
       
  1357 
       
  1358 		$args = array(
       
  1359 			'widget_id' => $widget['id'],
       
  1360 			'widget_name' => $widget['name'],
       
  1361 		);
       
  1362 
       
  1363 		$args = wp_list_widget_controls_dynamic_sidebar( array( 0 => $args, 1 => $widget['params'][0] ) );
       
  1364 		echo $this->manager->widgets->get_widget_control( $args );
       
  1365 	}
       
  1366 
       
  1367 	/**
       
  1368 	 * Whether the current widget is rendered on the page.
       
  1369 	 *
       
  1370 	 * @since 4.0.0
       
  1371 	 * @access public
       
  1372 	 *
       
  1373 	 * @return bool Whether the widget is rendered.
       
  1374 	 */
       
  1375 	public function active_callback() {
       
  1376 		return $this->manager->widgets->is_widget_rendered( $this->widget_id );
       
  1377 	}
       
  1378 }