2012-03-28 04:14:09 +00:00
<? php
/**
2015-02-25 07:56:25 +00:00
* WordPress Customize Control classes
2012-03-28 04:14:09 +00:00
*
* @package WordPress
* @subpackage Customize
* @since 3.4.0
*/
2015-02-25 07:56:25 +00:00
/**
* Customize Control class.
*
* @since 3.4.0
*/
2012-03-28 04:14:09 +00:00
class WP_Customize_Control {
2014-11-03 21:35:23 +00:00
/**
* Incremented with each new class instantiation, then stored in $instance_number.
*
* Used when sorting two instances whose priorities are equal.
*
* @since 4.1.0
* @var int
*/
protected static $instance_count = 0 ;
/**
* Order in which this instance was created in relation to other instances.
*
* @since 4.1.0
* @var int
*/
public $instance_number ;
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Customizer manager.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var WP_Customize_Manager
*/
2012-03-28 04:14:09 +00:00
public $manager ;
2012-08-01 02:30:02 +00:00
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Control ID.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var string
*/
2012-03-28 04:14:09 +00:00
public $id ;
2012-07-26 21:45:33 +00:00
/**
* All settings tied to the control.
*
2017-05-19 20:25:41 +00:00
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var array
*/
2012-03-28 04:14:09 +00:00
public $settings ;
2012-06-10 00:32:19 +00:00
2012-07-26 21:45:33 +00:00
/**
* The primary setting for the control (if there is one).
*
2017-05-19 20:25:41 +00:00
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var string
*/
2012-06-10 00:32:19 +00:00
public $setting = 'default' ;
2012-03-28 04:14:09 +00:00
2016-02-24 18:28:28 +00:00
/**
* Capability required to use this control.
*
* Normally this is empty and the capability is derived from the capabilities
* of the associated `$settings`.
*
* @since 4.5.0
* @var string
*/
public $capability ;
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Order priority to load the control in Customizer.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var int
*/
2014-03-04 20:21:14 +00:00
public $priority = 10 ;
2012-08-01 02:30:02 +00:00
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Section the control belongs to.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var string
*/
2014-03-04 20:21:14 +00:00
public $section = '' ;
2012-08-01 02:30:02 +00:00
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Label for the control.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var string
*/
2014-03-04 20:21:14 +00:00
public $label = '' ;
2012-08-01 02:30:02 +00:00
2014-06-30 15:55:17 +00:00
/**
2017-05-19 20:25:41 +00:00
* Description for the control.
*
* @since 4.0.0
2014-06-30 15:55:17 +00:00
* @var string
*/
public $description = '' ;
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
2012-07-26 21:45:33 +00:00
*
2017-05-19 20:25:41 +00:00
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var array
*/
2014-03-04 20:21:14 +00:00
public $choices = array ();
2012-03-28 04:14:09 +00:00
2014-06-30 19:48:13 +00:00
/**
2017-05-19 20:25:41 +00:00
* List of custom input attributes for control output, where attribute names are the keys and values are the values.
*
* Not used for 'checkbox', 'radio', 'select', 'textarea', or 'dropdown-pages' control types.
*
* @since 4.0.0
2014-06-30 19:48:13 +00:00
* @var array
*/
public $input_attrs = array ();
2016-10-25 06:31:31 +00:00
/**
* Show UI for adding new content, currently only used for the dropdown-pages control.
*
* @since 4.7.0
2016-11-23 06:05:32 +00:00
* @var bool
2016-10-25 06:31:31 +00:00
*/
public $allow_addition = false ;
2012-07-26 21:45:33 +00:00
/**
2014-10-29 22:51:22 +00:00
* @deprecated It is better to just call the json() method
2017-05-19 20:25:41 +00:00
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var array
*/
2012-03-29 06:35:54 +00:00
public $json = array ();
2012-07-26 21:45:33 +00:00
/**
2017-05-19 20:25:41 +00:00
* Control's Type.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @var string
*/
2012-03-28 04:14:09 +00:00
public $type = 'text' ;
2014-07-09 23:58:16 +00:00
/**
2014-07-14 00:32:16 +00:00
* Callback.
2014-07-09 23:58:16 +00:00
*
* @since 4.0.0
2014-07-14 00:32:16 +00:00
*
2014-07-09 23:58:16 +00:00
* @see WP_Customize_Control::active()
2014-07-14 00:32:16 +00:00
*
* @var callable Callback is called with one argument, the instance of
* WP_Customize_Control, and returns bool to indicate whether
* the control is active (such as it relates to the URL
* currently being previewed).
2014-07-09 23:58:16 +00:00
*/
public $active_callback = '' ;
2012-03-28 04:14:09 +00:00
/**
* Constructor.
*
2015-12-28 20:10:35 +00:00
* Supplied `$args` override class property defaults.
2014-03-04 20:21:14 +00:00
*
2015-12-28 20:10:35 +00:00
* If `$args['settings']` is not defined, use the $id as the setting ID.
2012-03-28 04:14:09 +00:00
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
*
2015-07-13 20:25:24 +00:00
* @param WP_Customize_Manager $manager Customizer bootstrap instance.
* @param string $id Control ID.
2015-12-28 20:10:35 +00:00
* @param array $args {
* Optional. Arguments to override class property defaults.
*
* @type int $instance_number Order in which this instance was created in relation
* to other instances.
* @type WP_Customize_Manager $manager Customizer bootstrap instance.
* @type string $id Control ID.
* @type array $settings All settings tied to the control. If undefined, `$id` will
* be used.
* @type string $setting The primary setting for the control (if there is one).
* Default 'default'.
* @type int $priority Order priority to load the control. Default 10.
* @type string $section Section the control belongs to. Default empty.
* @type string $label Label for the control. Default empty.
* @type string $description Description for the control. Default empty.
* @type array $choices List of choices for 'radio' or 'select' type controls, where
* values are the keys, and labels are the values.
* Default empty array.
* @type array $input_attrs List of custom input attributes for control output, where
* attribute names are the keys and values are the values. Not
* used for 'checkbox', 'radio', 'select', 'textarea', or
* 'dropdown-pages' control types. Default empty array.
2016-05-01 17:28:27 +00:00
* @type array $json Deprecated. Use WP_Customize_Control::json() instead.
2015-12-28 20:10:35 +00:00
* @type string $type Control type. Core controls include 'text', 'checkbox',
* 'textarea', 'radio', 'select', and 'dropdown-pages'. Additional
* input types such as 'email', 'url', 'number', 'hidden', and
* 'date' are supported implicitly. Default 'text'.
* }
2012-03-28 04:14:09 +00:00
*/
2014-05-19 05:45:16 +00:00
public function __construct ( $manager , $id , $args = array () ) {
2012-03-29 06:35:54 +00:00
$keys = array_keys ( get_object_vars ( $this ) );
2012-03-28 04:14:09 +00:00
foreach ( $keys as $key ) {
2014-07-09 23:58:16 +00:00
if ( isset ( $args [ $key ] ) ) {
2012-03-28 04:14:09 +00:00
$this -> $key = $args [ $key ];
2014-07-09 23:58:16 +00:00
}
2012-03-28 04:14:09 +00:00
}
$this -> manager = $manager ;
2017-11-30 23:11:00 +00:00
$this -> id = $id ;
2014-07-09 23:58:16 +00:00
if ( empty ( $this -> active_callback ) ) {
$this -> active_callback = array ( $this , 'active_callback' );
}
2014-11-03 21:35:23 +00:00
self :: $instance_count += 1 ;
$this -> instance_number = self :: $instance_count ;
2012-03-28 04:14:09 +00:00
// Process settings.
2016-02-24 18:28:28 +00:00
if ( ! isset ( $this -> settings ) ) {
2012-03-28 04:14:09 +00:00
$this -> settings = $id ;
2014-07-09 23:58:16 +00:00
}
2012-03-28 04:14:09 +00:00
$settings = array ();
if ( is_array ( $this -> settings ) ) {
foreach ( $this -> settings as $key => $setting ) {
$settings [ $key ] = $this -> manager -> get_setting ( $setting );
}
2017-11-30 23:11:00 +00:00
} elseif ( is_string ( $this -> settings ) ) {
$this -> setting = $this -> manager -> get_setting ( $this -> settings );
2012-03-28 04:14:09 +00:00
$settings [ 'default' ] = $this -> setting ;
}
$this -> settings = $settings ;
}
/**
* Enqueue control related scripts/styles.
*
* @since 3.4.0
*/
2012-04-25 21:03:29 +00:00
public function enqueue () {}
2012-03-28 04:14:09 +00:00
2014-07-09 23:58:16 +00:00
/**
2014-10-15 17:21:19 +00:00
* Check whether control is active to current Customizer preview.
2014-07-09 23:58:16 +00:00
*
* @since 4.0.0
*
2014-07-14 00:32:16 +00:00
* @return bool Whether the control is active to the current preview.
2014-07-09 23:58:16 +00:00
*/
2015-01-08 06:02:24 +00:00
final public function active () {
2014-07-09 23:58:16 +00:00
$control = $this ;
2017-11-30 23:11:00 +00:00
$active = call_user_func ( $this -> active_callback , $this );
2014-07-09 23:58:16 +00:00
/**
2016-05-22 18:10:29 +00:00
* Filters response of WP_Customize_Control::active().
2014-07-09 23:58:16 +00:00
*
* @since 4.0.0
*
2014-07-14 00:32:16 +00:00
* @param bool $active Whether the Customizer control is active.
* @param WP_Customize_Control $control WP_Customize_Control instance.
2014-07-09 23:58:16 +00:00
*/
$active = apply_filters ( 'customize_control_active' , $active , $control );
return $active ;
}
/**
* Default callback used when invoking WP_Customize_Control::active().
*
* Subclasses can override this with their specific logic, or they may
* provide an 'active_callback' argument to the constructor.
*
2014-07-14 00:32:16 +00:00
* @since 4.0.0
*
2015-05-21 22:05:24 +00:00
* @return true Always true.
2014-07-09 23:58:16 +00:00
*/
public function active_callback () {
return true ;
}
2012-03-28 04:14:09 +00:00
/**
* Fetch a setting's value.
* Grabs the main setting by default.
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
*
* @param string $setting_key
* @return mixed The requested setting's value, if the setting exists.
2012-03-28 04:14:09 +00:00
*/
2015-01-08 06:02:24 +00:00
final public function value ( $setting_key = 'default' ) {
2014-07-09 23:58:16 +00:00
if ( isset ( $this -> settings [ $setting_key ] ) ) {
2012-03-28 04:14:09 +00:00
return $this -> settings [ $setting_key ] -> value ();
2014-07-09 23:58:16 +00:00
}
2012-03-28 04:14:09 +00:00
}
2012-03-29 06:35:54 +00:00
/**
* Refresh the parameters passed to the JavaScript via JSON.
*
* @since 3.4.0
*/
public function to_json () {
$this -> json [ 'settings' ] = array ();
2012-03-28 04:14:09 +00:00
foreach ( $this -> settings as $key => $setting ) {
2012-03-29 06:35:54 +00:00
$this -> json [ 'settings' ][ $key ] = $setting -> id ;
2012-03-28 04:14:09 +00:00
}
2017-11-30 23:11:00 +00:00
$this -> json [ 'type' ] = $this -> type ;
$this -> json [ 'priority' ] = $this -> priority ;
$this -> json [ 'active' ] = $this -> active ();
$this -> json [ 'section' ] = $this -> section ;
$this -> json [ 'content' ] = $this -> get_content ();
$this -> json [ 'label' ] = $this -> label ;
$this -> json [ 'description' ] = $this -> description ;
2014-11-03 21:35:23 +00:00
$this -> json [ 'instanceNumber' ] = $this -> instance_number ;
2016-10-25 06:31:31 +00:00
if ( 'dropdown-pages' === $this -> type ) {
$this -> json [ 'allow_addition' ] = $this -> allow_addition ;
}
2014-10-29 22:51:22 +00:00
}
/**
* Get the data to export to the client via JSON.
*
* @since 4.1.0
*
2014-11-28 09:20:23 +00:00
* @return array Array of parameters passed to the JavaScript.
2014-10-29 22:51:22 +00:00
*/
public function json () {
$this -> to_json ();
return $this -> json ;
2012-03-28 04:14:09 +00:00
}
/**
2016-02-24 18:28:28 +00:00
* Checks if the user can use this control.
*
* Returns false if the user cannot manipulate one of the associated settings,
* or if one of the associated settings does not exist. Also returns false if
* the associated section does not exist or if its capability check returns
* false.
2012-03-28 04:14:09 +00:00
*
* @since 3.4.0
*
* @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
*/
2015-01-08 06:02:24 +00:00
final public function check_capabilities () {
2016-02-24 18:28:28 +00:00
if ( ! empty ( $this -> capability ) && ! current_user_can ( $this -> capability ) ) {
return false ;
}
2012-03-28 04:14:09 +00:00
foreach ( $this -> settings as $setting ) {
2016-02-24 18:28:28 +00:00
if ( ! $setting || ! $setting -> check_capabilities () ) {
2012-03-28 04:14:09 +00:00
return false ;
2016-02-24 18:28:28 +00:00
}
2012-03-28 04:14:09 +00:00
}
$section = $this -> manager -> get_section ( $this -> section );
2016-02-24 18:28:28 +00:00
if ( isset ( $section ) && ! $section -> check_capabilities () ) {
2012-03-28 04:14:09 +00:00
return false ;
2016-02-24 18:28:28 +00:00
}
2012-03-28 04:14:09 +00:00
return true ;
}
2014-10-29 22:51:22 +00:00
/**
* Get the control's content for insertion into the Customizer pane.
*
* @since 4.1.0
*
2014-11-28 09:20:23 +00:00
* @return string Contents of the control.
2014-10-29 22:51:22 +00:00
*/
2015-01-08 06:02:24 +00:00
final public function get_content () {
2014-10-29 22:51:22 +00:00
ob_start ();
$this -> maybe_render ();
2015-06-27 01:12:24 +00:00
return trim ( ob_get_clean () );
2014-10-29 22:51:22 +00:00
}
2012-03-28 04:14:09 +00:00
/**
2012-04-04 17:32:03 +00:00
* Check capabilities and render the control.
2012-03-28 04:14:09 +00:00
*
* @since 3.4.0
2012-07-26 21:45:33 +00:00
* @uses WP_Customize_Control::render()
2012-03-28 04:14:09 +00:00
*/
2015-01-08 06:02:24 +00:00
final public function maybe_render () {
2017-11-30 23:11:00 +00:00
if ( ! $this -> check_capabilities () ) {
2012-03-28 04:14:09 +00:00
return ;
2017-11-30 23:11:00 +00:00
}
2012-03-28 04:14:09 +00:00
2014-03-06 13:51:14 +00:00
/**
* Fires just before the current Customizer control is rendered.
*
* @since 3.4.0
*
* @param WP_Customize_Control $this WP_Customize_Control instance.
*/
2012-03-28 04:14:09 +00:00
do_action ( 'customize_render_control' , $this );
2014-03-06 13:51:14 +00:00
/**
* Fires just before a specific Customizer control is rendered.
*
2014-11-30 12:10:23 +00:00
* The dynamic portion of the hook name, `$this->id`, refers to
2014-03-06 13:51:14 +00:00
* the control ID.
*
* @since 3.4.0
*
2016-05-02 04:00:28 +00:00
* @param WP_Customize_Control $this WP_Customize_Control instance.
2014-03-06 13:51:14 +00:00
*/
2016-08-22 18:25:31 +00:00
do_action ( "customize_render_control_ { $this -> id } " , $this );
2012-03-28 04:14:09 +00:00
$this -> render ();
}
/**
2014-03-04 20:21:14 +00:00
* Renders the control wrapper and calls $this->render_content() for the internals.
2012-03-28 04:14:09 +00:00
*
* @since 3.4.0
*/
protected function render () {
2015-10-20 20:15:26 +00:00
$id = 'customize-control-' . str_replace ( array ( '[' , ']' ), array ( '-' , '' ), $this -> id );
2012-03-28 04:14:09 +00:00
$class = 'customize-control customize-control-' . $this -> type ;
2017-10-19 03:04:49 +00:00
printf ( '<li id="%s" class="%s">' , esc_attr ( $id ), esc_attr ( $class ) );
$this -> render_content ();
echo '</li>' ;
2012-03-28 04:14:09 +00:00
}
2012-08-01 02:30:02 +00:00
2012-07-26 21:45:33 +00:00
/**
2014-03-04 20:21:14 +00:00
* Get the data link attribute for a setting.
2012-07-26 21:45:33 +00:00
*
* @since 3.4.0
2017-10-04 20:02:49 +00:00
* @since 4.9.0 Return a `data-customize-setting-key-link` attribute if a setting is not registered for the supplied setting key.
2012-07-26 21:45:33 +00:00
*
* @param string $setting_key
2017-10-04 20:02:49 +00:00
* @return string Data link parameter, a `data-customize-setting-link` attribute if the `$setting_key` refers to a pre-registered setting,
* and a `data-customize-setting-key-link` attribute if the setting is not yet registered.
2012-07-26 21:45:33 +00:00
*/
2012-03-28 09:45:51 +00:00
public function get_link ( $setting_key = 'default' ) {
2017-10-04 20:02:49 +00:00
if ( isset ( $this -> settings [ $setting_key ] ) && $this -> settings [ $setting_key ] instanceof WP_Customize_Setting ) {
return 'data-customize-setting-link="' . esc_attr ( $this -> settings [ $setting_key ] -> id ) . '"' ;
} else {
return 'data-customize-setting-key-link="' . esc_attr ( $setting_key ) . '"' ;
}
2012-03-28 09:45:51 +00:00
}
2012-08-01 02:30:02 +00:00
2012-07-26 21:45:33 +00:00
/**
2014-03-04 20:21:14 +00:00
* Render the data link attribute for the control's input element.
2012-07-26 21:45:33 +00:00
*
* @since 3.4.0
* @uses WP_Customize_Control::get_link()
*
* @param string $setting_key
*/
2012-03-28 09:45:51 +00:00
public function link ( $setting_key = 'default' ) {
echo $this -> get_link ( $setting_key );
2012-03-28 04:14:09 +00:00
}
2014-07-09 23:58:16 +00:00
/**
2014-06-30 19:48:13 +00:00
* Render the custom attributes for the control's input element.
*
* @since 4.0.0
*/
public function input_attrs () {
2015-08-25 20:28:22 +00:00
foreach ( $this -> input_attrs as $attr => $value ) {
2014-06-30 19:48:13 +00:00
echo $attr . '="' . esc_attr ( $value ) . '" ' ;
}
}
2012-03-28 04:14:09 +00:00
/**
* Render the control's content.
*
2016-10-31 06:28:32 +00:00
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
2014-03-04 20:21:14 +00:00
*
2014-06-30 19:48:13 +00:00
* Supports basic input types `text`, `checkbox`, `textarea`, `radio`, `select` and `dropdown-pages`.
* Additional input types such as `email`, `url`, `number`, `hidden` and `date` are supported implicitly.
2012-03-28 04:14:09 +00:00
*
2016-05-01 17:28:27 +00:00
* Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
2014-10-24 16:32:18 +00:00
*
2012-03-28 04:14:09 +00:00
* @since 3.4.0
*/
protected function render_content () {
2017-11-30 23:11:00 +00:00
$input_id = '_customize-input-' . $this -> id ;
$description_id = '_customize-description-' . $this -> id ;
2017-10-05 02:56:47 +00:00
$describedby_attr = ( ! empty ( $this -> description ) ) ? ' aria-describedby="' . esc_attr ( $description_id ) . '" ' : '' ;
2017-10-04 18:12:46 +00:00
switch ( $this -> type ) {
2012-03-28 04:14:09 +00:00
case 'checkbox' :
?>
2017-10-04 18:12:46 +00:00
<span class="customize-inside-control-row">
<input
id="<?php echo esc_attr( $input_id ); ?>"
<?php echo $describedby_attr; ?>
type="checkbox"
value="<?php echo esc_attr( $this->value() ); ?>"
<?php $this->link(); ?>
<?php checked( $this->value() ); ?>
/>
<label for="<?php echo esc_attr( $input_id ); ?>"><?php echo esc_html( $this->label ); ?></label>
2014-06-30 15:55:17 +00:00
<?php if ( ! empty( $this->description ) ) : ?>
2017-10-04 18:12:46 +00:00
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
2014-06-30 15:55:17 +00:00
<?php endif; ?>
2017-10-04 18:12:46 +00:00
</span>
2012-03-28 04:14:09 +00:00
<?php
break;
case 'radio':
2017-10-04 18:12:46 +00:00
if ( empty( $this->choices ) ) {
2012-03-28 04:14:09 +00:00
return;
2017-10-04 18:12:46 +00:00
}
2012-03-28 04:14:09 +00:00
$name = '_customize-radio-' . $this->id;
2017-10-04 18:12:46 +00:00
?>
<?php if ( ! empty( $this->label ) ) : ?>
2014-06-30 15:55:17 +00:00
<span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
2017-10-04 18:12:46 +00:00
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
2017-11-30 23:11:00 +00:00
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
2017-10-04 18:12:46 +00:00
<?php endif; ?>
2014-06-30 15:55:17 +00:00
2017-10-04 18:12:46 +00:00
<?php foreach ( $this->choices as $value => $label ) : ?>
<span class="customize-inside-control-row">
<input
id="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>"
2017-10-05 02:56:47 +00:00
type="radio"
<?php echo $describedby_attr; ?>
2017-10-04 18:12:46 +00:00
value="<?php echo esc_attr( $value ); ?>"
name="<?php echo esc_attr( $name ); ?>"
<?php $this->link(); ?>
<?php checked( $this->value(), $value ); ?>
/>
<label for="<?php echo esc_attr( $input_id . '-radio-' . $value ); ?>"><?php echo esc_html( $label ); ?></label>
</span>
<?php endforeach; ?>
<?php
2012-03-28 04:14:09 +00:00
break;
case 'select':
2017-10-04 18:12:46 +00:00
if ( empty( $this->choices ) ) {
2012-03-28 04:14:09 +00:00
return;
2017-10-04 18:12:46 +00:00
}
2012-03-28 04:14:09 +00:00
?>
2017-10-04 18:12:46 +00:00
<?php if ( ! empty( $this->label ) ) : ?>
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
2014-06-30 15:55:17 +00:00
2017-10-04 18:12:46 +00:00
<select id="<?php echo esc_attr( $input_id ); ?>" <?php echo $describedby_attr; ?> <?php $this->link(); ?>>
<?php
foreach ( $this->choices as $value => $label ) {
echo '<option value="' . esc_attr( $value ) . '"' . selected( $this->value(), $value, false ) . '>' . $label . '</option>';
}
?>
</select>
2012-03-28 04:14:09 +00:00
<?php
break;
2014-06-30 19:48:13 +00:00
case 'textarea':
?>
2017-10-04 18:12:46 +00:00
<?php if ( ! empty( $this->label ) ) : ?>
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
<textarea
id="<?php echo esc_attr( $input_id ); ?>"
rows="5"
<?php echo $describedby_attr; ?>
<?php $this->input_attrs(); ?>
2018-02-08 10:59:30 +00:00
<?php $this->link(); ?>
><?php echo esc_textarea( $this->value() ); ?></textarea>
2014-06-30 19:48:13 +00:00
<?php
break;
2012-03-28 04:14:09 +00:00
case 'dropdown-pages':
2015-10-20 03:48:26 +00:00
?>
<?php if ( ! empty( $this->label ) ) : ?>
2017-10-04 18:12:46 +00:00
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
2015-10-20 03:48:26 +00:00
<?php endif; ?>
2016-09-20 00:47:30 +00:00
<?php
2017-11-30 23:11:00 +00:00
$dropdown_name = '_customize-dropdown-pages-' . $this->id;
$show_option_none = __( '— Select —' );
2016-09-20 00:47:30 +00:00
$option_none_value = '0';
2017-11-30 23:11:00 +00:00
$dropdown = wp_dropdown_pages(
2012-03-28 09:45:51 +00:00
array(
2016-09-20 00:47:30 +00:00
'name' => $dropdown_name,
2012-03-28 09:45:51 +00:00
'echo' => 0,
2016-09-20 00:47:30 +00:00
'show_option_none' => $show_option_none,
'option_none_value' => $option_none_value,
2012-03-28 09:45:51 +00:00
'selected' => $this->value(),
)
);
2016-09-20 00:47:30 +00:00
if ( empty( $dropdown ) ) {
2017-11-30 23:11:00 +00:00
$dropdown = sprintf( '<select id="%1$s" name="%1$s">', esc_attr( $dropdown_name ) );
2016-09-20 00:47:30 +00:00
$dropdown .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $option_none_value ), esc_html( $show_option_none ) );
$dropdown .= '</select>';
}
2012-03-28 09:45:51 +00:00
// Hackily add in the data link parameter.
2017-10-04 18:12:46 +00:00
$dropdown = str_replace( '<select', '<select ' . $this->get_link() . ' id="' . esc_attr( $input_id ) . '" ' . $describedby_attr, $dropdown );
2016-10-25 06:31:31 +00:00
// Even more hacikly add auto-draft page stubs.
// @todo Eventually this should be removed in favor of the pages being injected into the underlying get_pages() call. See <https://github.com/xwp/wp-customize-posts/pull/250>.
$nav_menus_created_posts_setting = $this->manager->get_setting( 'nav_menus_created_posts' );
if ( $nav_menus_created_posts_setting && current_user_can( 'publish_pages' ) ) {
$auto_draft_page_options = '';
foreach ( $nav_menus_created_posts_setting->value() as $auto_draft_page_id ) {
$post = get_post( $auto_draft_page_id );
if ( $post && 'page' === $post->post_type ) {
$auto_draft_page_options .= sprintf( '<option value="%1$s">%2$s</option>', esc_attr( $post->ID ), esc_html( $post->post_title ) );
}
}
if ( $auto_draft_page_options ) {
$dropdown = str_replace( '</select>', $auto_draft_page_options . '</select>', $dropdown );
}
}
2015-10-20 03:48:26 +00:00
echo $dropdown;
?>
2016-10-25 06:31:31 +00:00
<?php if ( $this->allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
2017-10-04 18:12:46 +00:00
<button type="button" class="button-link add-new-toggle">
<?php
2016-11-10 02:56:30 +00:00
/* translators: %s: add new page label */
printf( __( '+ %s' ), get_post_type_object( 'page' )->labels->add_new_item );
2017-10-04 18:12:46 +00:00
?>
</button>
2016-10-25 06:31:31 +00:00
<div class="new-content-item">
<label for="create-input-<?php echo $this->id; ?>"><span class="screen-reader-text"><?php _e( 'New page title' ); ?></span></label>
<input type="text" id="create-input-<?php echo $this->id; ?>" class="create-item-input" placeholder="<?php esc_attr_e( 'New page title…' ); ?>">
<button type="button" class="button add-content"><?php _e( 'Add' ); ?></button>
</div>
2017-10-04 18:12:46 +00:00
<?php endif; ?>
<?php
2012-03-28 04:14:09 +00:00
break;
2014-06-30 19:48:13 +00:00
default:
?>
2017-10-04 18:12:46 +00:00
<?php if ( ! empty( $this->label ) ) : ?>
<label for="<?php echo esc_attr( $input_id ); ?>" class="customize-control-title"><?php echo esc_html( $this->label ); ?></label>
<?php endif; ?>
<?php if ( ! empty( $this->description ) ) : ?>
<span id="<?php echo esc_attr( $description_id ); ?>" class="description customize-control-description"><?php echo $this->description; ?></span>
<?php endif; ?>
<input
id="<?php echo esc_attr( $input_id ); ?>"
type="<?php echo esc_attr( $this->type ); ?>"
<?php echo $describedby_attr; ?>
<?php $this->input_attrs(); ?>
2017-10-11 04:26:48 +00:00
<?php if ( ! isset( $this->input_attrs['value'] ) ) : ?>
value="<?php echo esc_attr( $this->value() ); ?>"
<?php endif; ?>
2017-10-04 18:12:46 +00:00
<?php $this->link(); ?>
/>
2014-06-30 19:48:13 +00:00
<?php
break;
2012-03-28 04:14:09 +00:00
}
}
2014-10-24 16:32:18 +00:00
/**
* Render the control's JS template.
*
2014-11-28 09:20:23 +00:00
* This function is only run for control types that have been registered with
2016-05-02 04:00:28 +00:00
* WP_Customize_Manager::register_control_type().
2014-10-24 16:32:18 +00:00
*
2014-11-28 09:20:23 +00:00
* In the future, this will also print the template for the control's container
* element and be override-able.
2014-10-24 16:32:18 +00:00
*
* @since 4.1.0
*/
final public function print_template() {
2015-03-10 18:02:28 +00:00
?>
<script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
<?php $this->content_template(); ?>
</script>
<?php
2014-10-24 16:32:18 +00:00
}
/**
* An Underscore (JS) template for this control's content (but not its container).
*
* Class variables for this control class are available in the `data` JS object;
2016-05-02 04:00:28 +00:00
* export custom variables by overriding WP_Customize_Control::to_json().
2014-10-24 16:32:18 +00:00
*
* @see WP_Customize_Control::print_template()
*
* @since 4.1.0
*/
protected function content_template() {}
2012-03-29 06:35:54 +00:00
}
2016-08-31 16:31:29 +00:00
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Color_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Media_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Upload_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Image_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Background_Image_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Background_Position_Control class.
*/
2016-10-26 06:52:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Cropped_Image_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Site_Icon_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Header_Image_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Theme_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Widget_Area_Customize_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Widget_Form_Customize_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Nav_Menu_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Nav_Menu_Item_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Nav_Menu_Location_Control class.
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php' );
2017-05-19 20:25:41 +00:00
/**
* WP_Customize_Nav_Menu_Name_Control class.
2017-10-28 05:48:47 +00:00
*
* As this file is deprecated, it will trigger a deprecation notice if instantiated. In a subsequent
* release, the require_once() here will be removed and _deprecated_file() will be called if file is
* required at all.
*
* @deprecated 4.9.0 This file is no longer used due to new menu creation UX.
2017-05-19 20:25:41 +00:00
*/
2016-08-31 16:31:29 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' );
2017-05-19 20:25:41 +00:00
/**
2017-10-05 02:22:49 +00:00
* WP_Customize_Nav_Menu_Locations_Control class.
2017-05-19 20:25:41 +00:00
*/
2017-10-05 02:22:49 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-locations-control.php' );
2016-08-31 16:31:29 +00:00
2017-05-19 20:25:41 +00:00
/**
2017-10-05 02:22:49 +00:00
* WP_Customize_Nav_Menu_Auto_Add_Control class.
2017-05-19 20:25:41 +00:00
*/
2017-10-05 02:22:49 +00:00
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' );
2017-09-27 22:25:46 +00:00
/**
* WP_Customize_Date_Time_Control class.
*/
require_once( ABSPATH . WPINC . '/customize/class-wp-customize-date-time-control.php' );