2012-03-28 00:14:09 -04:00
< ? php
/**
2015-02-25 02:56:25 -05:00
* WordPress Customize Control classes
2012-03-28 00:14:09 -04:00
*
* @ package WordPress
* @ subpackage Customize
* @ since 3.4 . 0
*/
2015-02-25 02:56:25 -05:00
/**
* Customize Control class .
*
* @ since 3.4 . 0
*/
2012-03-28 00:14:09 -04:00
class WP_Customize_Control {
2014-11-03 16:35:23 -05: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
2015-05-29 11:43:29 -04:00
*
* @ static
2014-11-03 16:35:23 -05:00
* @ access protected
* @ var int
*/
protected static $instance_count = 0 ;
/**
* Order in which this instance was created in relation to other instances .
*
* @ since 4.1 . 0
* @ access public
* @ var int
*/
public $instance_number ;
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var WP_Customize_Manager
*/
2012-03-28 00:14:09 -04:00
public $manager ;
2012-07-31 22:30:02 -04:00
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var string
*/
2012-03-28 00:14:09 -04:00
public $id ;
2012-07-26 17:45:33 -04:00
/**
* All settings tied to the control .
*
* @ access public
* @ var array
*/
2012-03-28 00:14:09 -04:00
public $settings ;
2012-06-09 20:32:19 -04:00
2012-07-26 17:45:33 -04:00
/**
* The primary setting for the control ( if there is one ) .
*
* @ access public
* @ var string
*/
2012-06-09 20:32:19 -04:00
public $setting = 'default' ;
2012-03-28 00:14:09 -04:00
2016-02-24 13:28:28 -05: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
* @ access public
* @ var string
*/
public $capability ;
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var int
*/
2014-03-04 15:21:14 -05:00
public $priority = 10 ;
2012-07-31 22:30:02 -04:00
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var string
*/
2014-03-04 15:21:14 -05:00
public $section = '' ;
2012-07-31 22:30:02 -04:00
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var string
*/
2014-03-04 15:21:14 -05:00
public $label = '' ;
2012-07-31 22:30:02 -04:00
2014-06-30 11:55:17 -04:00
/**
* @ access public
* @ var string
*/
public $description = '' ;
2012-07-26 17:45:33 -04:00
/**
* @ todo : Remove choices
*
* @ access public
* @ var array
*/
2014-03-04 15:21:14 -05:00
public $choices = array ();
2012-03-28 00:14:09 -04:00
2014-06-30 15:48:13 -04:00
/**
* @ access public
* @ var array
*/
public $input_attrs = array ();
2016-10-25 02:31:31 -04:00
/**
* Show UI for adding new content , currently only used for the dropdown - pages control .
*
* @ since 4.7 . 0
* @ access public
* @ var array
*/
public $allow_addition = false ;
2012-07-26 17:45:33 -04:00
/**
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
* @ deprecated It is better to just call the json () method
2012-07-26 17:45:33 -04:00
* @ access public
* @ var array
*/
2012-03-29 02:35:54 -04:00
public $json = array ();
2012-07-26 17:45:33 -04:00
/**
* @ access public
* @ var string
*/
2012-03-28 00:14:09 -04:00
public $type = 'text' ;
2014-07-09 19:58:16 -04:00
/**
2014-07-13 20:32:16 -04:00
* Callback .
2014-07-09 19:58:16 -04:00
*
* @ since 4.0 . 0
* @ access public
2014-07-13 20:32:16 -04:00
*
2014-07-09 19:58:16 -04:00
* @ see WP_Customize_Control :: active ()
2014-07-13 20:32:16 -04: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 19:58:16 -04:00
*/
public $active_callback = '' ;
2012-03-28 00:14:09 -04:00
/**
* Constructor .
*
2015-12-28 15:10:35 -05:00
* Supplied `$args` override class property defaults .
2014-03-04 15:21:14 -05:00
*
2015-12-28 15:10:35 -05:00
* If `$args['settings']` is not defined , use the $id as the setting ID .
2012-03-28 00:14:09 -04:00
*
* @ since 3.4 . 0
2012-07-26 17:45:33 -04:00
*
2015-07-13 16:25:24 -04:00
* @ param WP_Customize_Manager $manager Customizer bootstrap instance .
* @ param string $id Control ID .
2015-12-28 15:10:35 -05: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 13:28:27 -04:00
* @ type array $json Deprecated . Use WP_Customize_Control :: json () instead .
2015-12-28 15:10:35 -05: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 00:14:09 -04:00
*/
2014-05-19 01:45:16 -04:00
public function __construct ( $manager , $id , $args = array () ) {
2012-03-29 02:35:54 -04:00
$keys = array_keys ( get_object_vars ( $this ) );
2012-03-28 00:14:09 -04:00
foreach ( $keys as $key ) {
2014-07-09 19:58:16 -04:00
if ( isset ( $args [ $key ] ) ) {
2012-03-28 00:14:09 -04:00
$this -> $key = $args [ $key ];
2014-07-09 19:58:16 -04:00
}
2012-03-28 00:14:09 -04:00
}
$this -> manager = $manager ;
$this -> id = $id ;
2014-07-09 19:58:16 -04:00
if ( empty ( $this -> active_callback ) ) {
$this -> active_callback = array ( $this , 'active_callback' );
}
2014-11-03 16:35:23 -05:00
self :: $instance_count += 1 ;
$this -> instance_number = self :: $instance_count ;
2012-03-28 00:14:09 -04:00
// Process settings.
2016-02-24 13:28:28 -05:00
if ( ! isset ( $this -> settings ) ) {
2012-03-28 00:14:09 -04:00
$this -> settings = $id ;
2014-07-09 19:58:16 -04:00
}
2012-03-28 00:14:09 -04:00
$settings = array ();
if ( is_array ( $this -> settings ) ) {
foreach ( $this -> settings as $key => $setting ) {
$settings [ $key ] = $this -> manager -> get_setting ( $setting );
}
2016-02-24 13:28:28 -05:00
} else if ( is_string ( $this -> settings ) ) {
2012-03-28 00:14:09 -04:00
$this -> setting = $this -> manager -> get_setting ( $this -> settings );
$settings [ 'default' ] = $this -> setting ;
}
$this -> settings = $settings ;
}
/**
* Enqueue control related scripts / styles .
*
* @ since 3.4 . 0
*/
2012-04-25 17:03:29 -04:00
public function enqueue () {}
2012-03-28 00:14:09 -04:00
2014-07-09 19:58:16 -04:00
/**
2014-10-15 13:21:19 -04:00
* Check whether control is active to current Customizer preview .
2014-07-09 19:58:16 -04:00
*
* @ since 4.0 . 0
2014-07-13 20:32:16 -04:00
* @ access public
2014-07-09 19:58:16 -04:00
*
2014-07-13 20:32:16 -04:00
* @ return bool Whether the control is active to the current preview .
2014-07-09 19:58:16 -04:00
*/
2015-01-08 01:02:24 -05:00
final public function active () {
2014-07-09 19:58:16 -04:00
$control = $this ;
$active = call_user_func ( $this -> active_callback , $this );
/**
2016-05-22 14:10:29 -04:00
* Filters response of WP_Customize_Control :: active () .
2014-07-09 19:58:16 -04:00
*
* @ since 4.0 . 0
*
2014-07-13 20:32:16 -04:00
* @ param bool $active Whether the Customizer control is active .
* @ param WP_Customize_Control $control WP_Customize_Control instance .
2014-07-09 19:58:16 -04: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-13 20:32:16 -04:00
* @ since 4.0 . 0
* @ access public
*
2015-05-21 18:05:24 -04:00
* @ return true Always true .
2014-07-09 19:58:16 -04:00
*/
public function active_callback () {
return true ;
}
2012-03-28 00:14:09 -04:00
/**
* Fetch a setting ' s value .
* Grabs the main setting by default .
*
* @ since 3.4 . 0
2012-07-26 17:45:33 -04:00
*
* @ param string $setting_key
* @ return mixed The requested setting ' s value , if the setting exists .
2012-03-28 00:14:09 -04:00
*/
2015-01-08 01:02:24 -05:00
final public function value ( $setting_key = 'default' ) {
2014-07-09 19:58:16 -04:00
if ( isset ( $this -> settings [ $setting_key ] ) ) {
2012-03-28 00:14:09 -04:00
return $this -> settings [ $setting_key ] -> value ();
2014-07-09 19:58:16 -04:00
}
2012-03-28 00:14:09 -04:00
}
2012-03-29 02:35:54 -04: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 00:14:09 -04:00
foreach ( $this -> settings as $key => $setting ) {
2012-03-29 02:35:54 -04:00
$this -> json [ 'settings' ][ $key ] = $setting -> id ;
2012-03-28 00:14:09 -04:00
}
2014-11-03 16:35:23 -05: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 ;
2014-10-24 12:32:18 -04:00
$this -> json [ 'description' ] = $this -> description ;
2014-11-03 16:35:23 -05:00
$this -> json [ 'instanceNumber' ] = $this -> instance_number ;
2016-10-25 02:31:31 -04:00
if ( 'dropdown-pages' === $this -> type ) {
$this -> json [ 'allow_addition' ] = $this -> allow_addition ;
}
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
}
/**
* Get the data to export to the client via JSON .
*
* @ since 4.1 . 0
*
2014-11-28 04:20:23 -05:00
* @ return array Array of parameters passed to the JavaScript .
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
*/
public function json () {
$this -> to_json ();
return $this -> json ;
2012-03-28 00:14:09 -04:00
}
/**
2016-02-24 13:28:28 -05: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 00:14:09 -04: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 01:02:24 -05:00
final public function check_capabilities () {
2016-02-24 13:28:28 -05:00
if ( ! empty ( $this -> capability ) && ! current_user_can ( $this -> capability ) ) {
return false ;
}
2012-03-28 00:14:09 -04:00
foreach ( $this -> settings as $setting ) {
2016-02-24 13:28:28 -05:00
if ( ! $setting || ! $setting -> check_capabilities () ) {
2012-03-28 00:14:09 -04:00
return false ;
2016-02-24 13:28:28 -05:00
}
2012-03-28 00:14:09 -04:00
}
$section = $this -> manager -> get_section ( $this -> section );
2016-02-24 13:28:28 -05:00
if ( isset ( $section ) && ! $section -> check_capabilities () ) {
2012-03-28 00:14:09 -04:00
return false ;
2016-02-24 13:28:28 -05:00
}
2012-03-28 00:14:09 -04:00
return true ;
}
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
/**
* Get the control ' s content for insertion into the Customizer pane .
*
* @ since 4.1 . 0
*
2014-11-28 04:20:23 -05:00
* @ return string Contents of the control .
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
*/
2015-01-08 01:02:24 -05:00
final public function get_content () {
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
ob_start ();
$this -> maybe_render ();
2015-06-26 21:12:24 -04:00
return trim ( ob_get_clean () );
Improve/introduce Customizer JavaScript models for Controls, Sections, and Panels.
* Introduce models for panels and sections.
* Introduce API to expand and focus a control, section or panel.
* Allow deep-linking to panels, sections, and controls inside of the Customizer.
* Clean up `accordion.js`, removing all Customizer-specific logic.
* Add initial unit tests for `wp.customize.Class` in `customize-base.js`.
https://make.wordpress.org/core/2014/10/27/toward-a-complete-javascript-api-for-the-customizer/ provides an overview of how to use the JavaScript API.
props westonruter, celloexpressions, ryankienstra.
see #28032, #28579, #28580, #28650, #28709, #29758.
fixes #29529.
Built from https://develop.svn.wordpress.org/trunk@30102
git-svn-id: http://core.svn.wordpress.org/trunk@30102 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2014-10-29 18:51:22 -04:00
}
2012-03-28 00:14:09 -04:00
/**
2012-04-04 13:32:03 -04:00
* Check capabilities and render the control .
2012-03-28 00:14:09 -04:00
*
* @ since 3.4 . 0
2012-07-26 17:45:33 -04:00
* @ uses WP_Customize_Control :: render ()
2012-03-28 00:14:09 -04:00
*/
2015-01-08 01:02:24 -05:00
final public function maybe_render () {
2012-03-28 00:14:09 -04:00
if ( ! $this -> check_capabilities () )
return ;
2014-03-06 08:51:14 -05: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 00:14:09 -04:00
do_action ( 'customize_render_control' , $this );
2014-03-06 08:51:14 -05:00
/**
* Fires just before a specific Customizer control is rendered .
*
2014-11-30 07:10:23 -05:00
* The dynamic portion of the hook name , `$this->id` , refers to
2014-03-06 08:51:14 -05:00
* the control ID .
*
* @ since 3.4 . 0
*
2016-05-02 00:00:28 -04:00
* @ param WP_Customize_Control $this WP_Customize_Control instance .
2014-03-06 08:51:14 -05:00
*/
2016-08-22 14:25:31 -04:00
do_action ( " customize_render_control_ { $this -> id } " , $this );
2012-03-28 00:14:09 -04:00
$this -> render ();
}
/**
2014-03-04 15:21:14 -05:00
* Renders the control wrapper and calls $this -> render_content () for the internals .
2012-03-28 00:14:09 -04:00
*
* @ since 3.4 . 0
*/
protected function render () {
2015-10-20 16:15:26 -04:00
$id = 'customize-control-' . str_replace ( array ( '[' , ']' ), array ( '-' , '' ), $this -> id );
2012-03-28 00:14:09 -04:00
$class = 'customize-control customize-control-' . $this -> type ;
2012-04-18 13:13:31 -04:00
?> <li id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $class ); ?>">
2012-03-28 00:14:09 -04:00
< ? php $this -> render_content (); ?>
</ li >< ? php
}
2012-07-31 22:30:02 -04:00
2012-07-26 17:45:33 -04:00
/**
2014-03-04 15:21:14 -05:00
* Get the data link attribute for a setting .
2012-07-26 17:45:33 -04:00
*
* @ since 3.4 . 0
*
* @ param string $setting_key
* @ return string Data link parameter , if $setting_key is a valid setting , empty string otherwise .
*/
2012-03-28 05:45:51 -04:00
public function get_link ( $setting_key = 'default' ) {
2012-03-28 00:14:09 -04:00
if ( ! isset ( $this -> settings [ $setting_key ] ) )
2012-03-28 05:45:51 -04:00
return '' ;
2012-03-28 00:14:09 -04:00
2012-03-28 05:45:51 -04:00
return 'data-customize-setting-link="' . esc_attr ( $this -> settings [ $setting_key ] -> id ) . '"' ;
}
2012-07-31 22:30:02 -04:00
2012-07-26 17:45:33 -04:00
/**
2014-03-04 15:21:14 -05:00
* Render the data link attribute for the control ' s input element .
2012-07-26 17:45:33 -04:00
*
* @ since 3.4 . 0
* @ uses WP_Customize_Control :: get_link ()
*
* @ param string $setting_key
*/
2012-03-28 05:45:51 -04:00
public function link ( $setting_key = 'default' ) {
echo $this -> get_link ( $setting_key );
2012-03-28 00:14:09 -04:00
}
2014-07-09 19:58:16 -04:00
/**
2014-06-30 15:48:13 -04:00
* Render the custom attributes for the control ' s input element .
*
* @ since 4.0 . 0
2014-07-13 20:32:16 -04:00
* @ access public
2014-06-30 15:48:13 -04:00
*/
public function input_attrs () {
2015-08-25 16:28:22 -04:00
foreach ( $this -> input_attrs as $attr => $value ) {
2014-06-30 15:48:13 -04:00
echo $attr . '="' . esc_attr ( $value ) . '" ' ;
}
}
2012-03-28 00:14:09 -04:00
/**
* Render the control ' s content .
*
2016-10-31 02:28:32 -04:00
* Allows the content to be overridden without having to rewrite the wrapper in `$this::render()` .
2014-03-04 15:21:14 -05:00
*
2014-06-30 15:48:13 -04: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 00:14:09 -04:00
*
2016-05-01 13:28:27 -04:00
* Control content can alternately be rendered in JS . See WP_Customize_Control :: print_template () .
2014-10-24 12:32:18 -04:00
*
2012-03-28 00:14:09 -04:00
* @ since 3.4 . 0
*/
protected function render_content () {
switch ( $this -> type ) {
case 'checkbox' :
?>
< label >
2012-04-25 17:03:29 -04:00
< input type = " checkbox " value = " <?php echo esc_attr( $this->value () ); ?> " < ? php $this -> link (); checked ( $this -> value () ); ?> />
2012-05-11 20:48:20 -04:00
< ? php echo esc_html ( $this -> label ); ?>
2014-06-30 11:55:17 -04:00
< ? php if ( ! empty ( $this -> description ) ) : ?>
2014-07-03 16:11:15 -04:00
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
2014-06-30 11:55:17 -04:00
< ? php endif ; ?>
2012-03-28 00:14:09 -04:00
</ label >
< ? php
break ;
case 'radio' :
if ( empty ( $this -> choices ) )
return ;
$name = '_customize-radio-' . $this -> id ;
2014-06-30 11:55:17 -04:00
if ( ! empty ( $this -> label ) ) : ?>
< span class = " customize-control-title " >< ? php echo esc_html ( $this -> label ); ?> </span>
< ? php endif ;
if ( ! empty ( $this -> description ) ) : ?>
2014-07-03 16:11:15 -04:00
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
2014-06-30 11:55:17 -04:00
< ? php endif ;
2012-03-28 00:14:09 -04:00
foreach ( $this -> choices as $value => $label ) :
?>
< label >
< input type = " radio " value = " <?php echo esc_attr( $value ); ?> " name = " <?php echo esc_attr( $name ); ?> " < ? php $this -> link (); checked ( $this -> value (), $value ); ?> />
< ? php echo esc_html ( $label ); ?> <br/>
</ label >
< ? php
endforeach ;
break ;
case 'select' :
if ( empty ( $this -> choices ) )
return ;
?>
< label >
2014-06-30 11:55:17 -04:00
< ? php if ( ! empty ( $this -> label ) ) : ?>
< span class = " customize-control-title " >< ? php echo esc_html ( $this -> label ); ?> </span>
< ? php endif ;
if ( ! empty ( $this -> description ) ) : ?>
2014-07-03 16:11:15 -04:00
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
2014-06-30 11:55:17 -04:00
< ? php endif ; ?>
2012-04-25 17:03:29 -04:00
< select < ? php $this -> link (); ?> >
2012-03-28 00:14:09 -04:00
< ? php
foreach ( $this -> choices as $value => $label )
echo '<option value="' . esc_attr ( $value ) . '"' . selected ( $this -> value (), $value , false ) . '>' . $label . '</option>' ;
?>
</ select >
</ label >
< ? php
break ;
2014-06-30 15:48:13 -04:00
case 'textarea' :
?>
< label >
< ? php if ( ! empty ( $this -> label ) ) : ?>
< span class = " customize-control-title " >< ? php echo esc_html ( $this -> label ); ?> </span>
< ? php endif ;
if ( ! empty ( $this -> description ) ) : ?>
2014-07-03 16:11:15 -04:00
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
2014-06-30 15:48:13 -04:00
< ? php endif ; ?>
2016-10-25 18:52:10 -04:00
< textarea rows = " 5 " < ? php $this -> input_attrs (); ?> <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
2014-06-30 15:48:13 -04:00
</ label >
< ? php
break ;
2012-03-28 00:14:09 -04:00
case 'dropdown-pages' :
2015-10-19 23:48:26 -04:00
?>
< label >
< ? php if ( ! empty ( $this -> label ) ) : ?>
< span class = " customize-control-title " >< ? php echo esc_html ( $this -> label ); ?> </span>
< ? php endif ;
if ( ! empty ( $this -> description ) ) : ?>
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
< ? php endif ; ?>
2016-09-19 20:47:30 -04:00
< ? php
$dropdown_name = '_customize-dropdown-pages-' . $this -> id ;
$show_option_none = __ ( '— Select —' );
$option_none_value = '0' ;
$dropdown = wp_dropdown_pages (
2012-03-28 05:45:51 -04:00
array (
2016-09-19 20:47:30 -04:00
'name' => $dropdown_name ,
2012-03-28 05:45:51 -04:00
'echo' => 0 ,
2016-09-19 20:47:30 -04:00
'show_option_none' => $show_option_none ,
'option_none_value' => $option_none_value ,
2012-03-28 05:45:51 -04:00
'selected' => $this -> value (),
)
);
2016-09-19 20:47:30 -04:00
if ( empty ( $dropdown ) ) {
$dropdown = sprintf ( '<select id="%1$s" name="%1$s">' , esc_attr ( $dropdown_name ) );
$dropdown .= sprintf ( '<option value="%1$s">%2$s</option>' , esc_attr ( $option_none_value ), esc_html ( $show_option_none ) );
$dropdown .= '</select>' ;
}
2012-03-28 05:45:51 -04:00
// Hackily add in the data link parameter.
$dropdown = str_replace ( '<select' , '<select ' . $this -> get_link (), $dropdown );
2016-10-25 02:31:31 -04: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-19 23:48:26 -04:00
echo $dropdown ;
?>
</ label >
2016-10-25 02:31:31 -04:00
< ? php if ( $this -> allow_addition && current_user_can ( 'publish_pages' ) && current_user_can ( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
2016-11-09 21:56:30 -05:00
< button type = " button " class = " button-link add-new-toggle " >< ? php
/* translators: %s: add new page label */
printf ( __ ( '+ %s' ), get_post_type_object ( 'page' ) -> labels -> add_new_item );
?> </button>
2016-10-25 02:31:31 -04: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 >
< ? php endif ;
2012-03-28 00:14:09 -04:00
break ;
2014-06-30 15:48:13 -04:00
default :
?>
< label >
< ? php if ( ! empty ( $this -> label ) ) : ?>
< span class = " customize-control-title " >< ? php echo esc_html ( $this -> label ); ?> </span>
< ? php endif ;
if ( ! empty ( $this -> description ) ) : ?>
2014-07-03 16:11:15 -04:00
< span class = " description customize-control-description " >< ? php echo $this -> description ; ?> </span>
2014-06-30 15:48:13 -04:00
< ? php endif ; ?>
< input type = " <?php echo esc_attr( $this->type ); ?> " < ? php $this -> input_attrs (); ?> value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
</ label >
< ? php
break ;
2012-03-28 00:14:09 -04:00
}
}
2014-10-24 12:32:18 -04:00
/**
* Render the control ' s JS template .
*
2014-11-28 04:20:23 -05:00
* This function is only run for control types that have been registered with
2016-05-02 00:00:28 -04:00
* WP_Customize_Manager :: register_control_type () .
2014-10-24 12:32:18 -04:00
*
2014-11-28 04:20:23 -05:00
* In the future , this will also print the template for the control ' s container
* element and be override - able .
2014-10-24 12:32:18 -04:00
*
* @ since 4.1 . 0
*/
final public function print_template () {
2015-03-10 14:02:28 -04:00
?>
< script type = " text/html " id = " tmpl-customize-control-<?php echo $this->type ; ?>-content " >
< ? php $this -> content_template (); ?>
</ script >
< ? php
2014-10-24 12:32:18 -04: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 00:00:28 -04:00
* export custom variables by overriding WP_Customize_Control :: to_json () .
2014-10-24 12:32:18 -04:00
*
* @ see WP_Customize_Control :: print_template ()
*
* @ since 4.1 . 0
*/
protected function content_template () {}
2012-03-29 02:35:54 -04:00
}
2016-08-31 12:31:29 -04:00
/** WP_Customize_Color_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-color-control.php' );
/** WP_Customize_Media_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-media-control.php' );
/** WP_Customize_Upload_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php' );
/** WP_Customize_Image_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php' );
/** WP_Customize_Background_Image_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
Customize: Improve custom background properties UI.
Introduces new control for managing the background position. Adds control for setting the `background-size`.
Props cdog, celloexpressions, grapplerulrich, MikeHansenMe, FolioVision, afercia, helen, melchoyce, karmatosed, westonruter, Kelderic, sebastian.pisula.
Fixes #22058.
Built from https://develop.svn.wordpress.org/trunk@38948
git-svn-id: http://core.svn.wordpress.org/trunk@38891 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2016-10-26 02:52:29 -04:00
/** WP_Customize_Background_Position_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
2016-08-31 12:31:29 -04:00
/** WP_Customize_Cropped_Image_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-cropped-image-control.php' );
/** WP_Customize_Site_Icon_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-site-icon-control.php' );
/** WP_Customize_Header_Image_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
/** WP_Customize_Theme_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
/** WP_Widget_Area_Customize_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' );
/** WP_Widget_Form_Customize_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' );
/** WP_Customize_Nav_Menu_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php' );
/** WP_Customize_Nav_Menu_Item_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php' );
/** WP_Customize_Nav_Menu_Location_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php' );
/** WP_Customize_Nav_Menu_Name_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-name-control.php' );
/** WP_Customize_Nav_Menu_Auto_Add_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-auto-add-control.php' );
/** WP_Customize_New_Menu_Control class */
require_once ( ABSPATH . WPINC . '/customize/class-wp-customize-new-menu-control.php' );