diff -r 490d5cc509ed -r cf61fcea0001 wp/wp-includes/class-wp-customize-control.php
--- a/wp/wp-includes/class-wp-customize-control.php Tue Jun 09 11:14:17 2015 +0000
+++ b/wp/wp-includes/class-wp-customize-control.php Mon Oct 14 17:39:30 2019 +0200
@@ -20,7 +20,8 @@
* Used when sorting two instances whose priorities are equal.
*
* @since 4.1.0
- * @access protected
+ *
+ * @static
* @var int
*/
protected static $instance_count = 0;
@@ -29,19 +30,22 @@
* Order in which this instance was created in relation to other instances.
*
* @since 4.1.0
- * @access public
* @var int
*/
public $instance_number;
/**
- * @access public
+ * Customizer manager.
+ *
+ * @since 3.4.0
* @var WP_Customize_Manager
*/
public $manager;
/**
- * @access public
+ * Control ID.
+ *
+ * @since 3.4.0
* @var string
*/
public $id;
@@ -49,7 +53,7 @@
/**
* All settings tied to the control.
*
- * @access public
+ * @since 3.4.0
* @var array
*/
public $settings;
@@ -57,58 +61,91 @@
/**
* The primary setting for the control (if there is one).
*
- * @access public
+ * @since 3.4.0
* @var string
*/
public $setting = 'default';
/**
- * @access public
+ * 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;
+
+ /**
+ * Order priority to load the control in Customizer.
+ *
+ * @since 3.4.0
* @var int
*/
public $priority = 10;
/**
- * @access public
+ * Section the control belongs to.
+ *
+ * @since 3.4.0
* @var string
*/
public $section = '';
/**
- * @access public
+ * Label for the control.
+ *
+ * @since 3.4.0
* @var string
*/
public $label = '';
/**
- * @access public
+ * Description for the control.
+ *
+ * @since 4.0.0
* @var string
*/
public $description = '';
/**
- * @todo: Remove choices
+ * List of choices for 'radio' or 'select' type controls, where values are the keys, and labels are the values.
*
- * @access public
+ * @since 3.4.0
* @var array
*/
public $choices = array();
/**
- * @access public
+ * 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
* @var array
*/
public $input_attrs = array();
/**
+ * Show UI for adding new content, currently only used for the dropdown-pages control.
+ *
+ * @since 4.7.0
+ * @var bool
+ */
+ public $allow_addition = false;
+
+ /**
* @deprecated It is better to just call the json() method
- * @access public
+ * @since 3.4.0
* @var array
*/
public $json = array();
/**
- * @access public
+ * Control's Type.
+ *
+ * @since 3.4.0
* @var string
*/
public $type = 'text';
@@ -117,7 +154,6 @@
* Callback.
*
* @since 4.0.0
- * @access public
*
* @see WP_Customize_Control::active()
*
@@ -131,15 +167,42 @@
/**
* Constructor.
*
- * Supplied $args override class property defaults.
+ * Supplied `$args` override class property defaults.
*
- * If $args['settings'] is not defined, use the $id as the setting ID.
+ * If `$args['settings']` is not defined, use the $id as the setting ID.
*
* @since 3.4.0
*
- * @param WP_Customize_Manager $manager
- * @param string $id
- * @param array $args
+ * @param WP_Customize_Manager $manager Customizer bootstrap instance.
+ * @param string $id Control ID.
+ * @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.
+ * @type array $json Deprecated. Use WP_Customize_Control::json() instead.
+ * @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'.
+ * }
*/
public function __construct( $manager, $id, $args = array() ) {
$keys = array_keys( get_object_vars( $this ) );
@@ -158,7 +221,7 @@
$this->instance_number = self::$instance_count;
// Process settings.
- if ( empty( $this->settings ) ) {
+ if ( ! isset( $this->settings ) ) {
$this->settings = $id;
}
@@ -167,7 +230,7 @@
foreach ( $this->settings as $key => $setting ) {
$settings[ $key ] = $this->manager->get_setting( $setting );
}
- } else {
+ } else if ( is_string( $this->settings ) ) {
$this->setting = $this->manager->get_setting( $this->settings );
$settings['default'] = $this->setting;
}
@@ -185,7 +248,6 @@
* Check whether control is active to current Customizer preview.
*
* @since 4.0.0
- * @access public
*
* @return bool Whether the control is active to the current preview.
*/
@@ -194,7 +256,7 @@
$active = call_user_func( $this->active_callback, $this );
/**
- * Filter response of WP_Customize_Control::active().
+ * Filters response of WP_Customize_Control::active().
*
* @since 4.0.0
*
@@ -213,9 +275,8 @@
* provide an 'active_callback' argument to the constructor.
*
* @since 4.0.0
- * @access public
*
- * @return bool Always true.
+ * @return true Always true.
*/
public function active_callback() {
return true;
@@ -255,6 +316,10 @@
$this->json['label'] = $this->label;
$this->json['description'] = $this->description;
$this->json['instanceNumber'] = $this->instance_number;
+
+ if ( 'dropdown-pages' === $this->type ) {
+ $this->json['allow_addition'] = $this->allow_addition;
+ }
}
/**
@@ -270,21 +335,32 @@
}
/**
- * Check if the theme supports the control and check user capabilities.
+ * 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.
*
* @since 3.4.0
*
* @return bool False if theme doesn't support the control or user doesn't have the required permissions, otherwise true.
*/
final public function check_capabilities() {
+ if ( ! empty( $this->capability ) && ! current_user_can( $this->capability ) ) {
+ return false;
+ }
+
foreach ( $this->settings as $setting ) {
- if ( ! $setting->check_capabilities() )
+ if ( ! $setting || ! $setting->check_capabilities() ) {
return false;
+ }
}
$section = $this->manager->get_section( $this->section );
- if ( isset( $section ) && ! $section->check_capabilities() )
+ if ( isset( $section ) && ! $section->check_capabilities() ) {
return false;
+ }
return true;
}
@@ -299,9 +375,7 @@
final public function get_content() {
ob_start();
$this->maybe_render();
- $template = trim( ob_get_contents() );
- ob_end_clean();
- return $template;
+ return trim( ob_get_clean() );
}
/**
@@ -331,9 +405,9 @@
*
* @since 3.4.0
*
- * @param WP_Customize_Control $this {@see WP_Customize_Control} instance.
+ * @param WP_Customize_Control $this WP_Customize_Control instance.
*/
- do_action( 'customize_render_control_' . $this->id, $this );
+ do_action( "customize_render_control_{$this->id}", $this );
$this->render();
}
@@ -344,27 +418,30 @@
* @since 3.4.0
*/
protected function render() {
- $id = 'customize-control-' . str_replace( '[', '-', str_replace( ']', '', $this->id ) );
+ $id = 'customize-control-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
$class = 'customize-control customize-control-' . $this->type;
- ?>
- render_content(); ?>
-
', esc_attr( $id ), esc_attr( $class ) );
+ $this->render_content();
+ echo '';
}
/**
* Get the data link attribute for a setting.
*
* @since 3.4.0
+ * @since 4.9.0 Return a `data-customize-setting-key-link` attribute if a setting is not registered for the supplied setting key.
*
* @param string $setting_key
- * @return string Data link parameter, if $setting_key is a valid setting, empty string otherwise.
+ * @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.
*/
public function get_link( $setting_key = 'default' ) {
- if ( ! isset( $this->settings[ $setting_key ] ) )
- return '';
-
- return 'data-customize-setting-link="' . esc_attr( $this->settings[ $setting_key ]->id ) . '"';
+ 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 ) . '"';
+ }
}
/**
@@ -383,10 +460,9 @@
* Render the custom attributes for the control's input element.
*
* @since 4.0.0
- * @access public
*/
public function input_attrs() {
- foreach( $this->input_attrs as $attr => $value ) {
+ foreach ( $this->input_attrs as $attr => $value ) {
echo $attr . '="' . esc_attr( $value ) . '" ';
}
}
@@ -394,116 +470,190 @@
/**
* Render the control's content.
*
- * Allows the content to be overriden without having to rewrite the wrapper in $this->render().
+ * Allows the content to be overridden without having to rewrite the wrapper in `$this::render()`.
*
* 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.
*
- * Control content can alternately be rendered in JS. See {@see WP_Customize_Control::print_template()}.
+ * Control content can alternately be rendered in JS. See WP_Customize_Control::print_template().
*
* @since 3.4.0
*/
protected function render_content() {
- switch( $this->type ) {
+ $input_id = '_customize-input-' . $this->id;
+ $description_id = '_customize-description-' . $this->id;
+ $describedby_attr = ( ! empty( $this->description ) ) ? ' aria-describedby="' . esc_attr( $description_id ) . '" ' : '';
+ switch ( $this->type ) {
case 'checkbox':
?>
-
+
choices ) )
+ if ( empty( $this->choices ) ) {
return;
+ }
$name = '_customize-radio-' . $this->id;
-
- if ( ! empty( $this->label ) ) : ?>
+ ?>
+ label ) ) : ?>
label ); ?>
- description ) ) : ?>
- description ; ?>
-
+ description ) ) : ?>
+ description ; ?>
+
- foreach ( $this->choices as $value => $label ) :
- ?>
-
- link(); checked( $this->value(), $value ); ?> />
-
-
- choices as $value => $label ) : ?>
+
+
+ value=""
+ name=""
+ link(); ?>
+ value(), $value ); ?>
+ />
+
+
+
+ choices ) )
+ if ( empty( $this->choices ) ) {
return;
+ }
?>
-
- label ) ) : ?>
- label ); ?>
- description ) ) : ?>
- description; ?>
-
+ label ) ) : ?>
+ label ); ?>
+
+ description ) ) : ?>
+ description; ?>
+
-
-
+
-
- label ) ) : ?>
- label ); ?>
- description ) ) : ?>
- description; ?>
-
-
-
+ label ) ) : ?>
+ label ); ?>
+
+ description ) ) : ?>
+ description; ?>
+
+
+ label ) ) : ?>
+ label ); ?>
+
+ description ) ) : ?>
+ description; ?>
+
+
+ id;
+ $show_option_none = __( '— Select —' );
+ $option_none_value = '0';
$dropdown = wp_dropdown_pages(
array(
- 'name' => '_customize-dropdown-pages-' . $this->id,
+ 'name' => $dropdown_name,
'echo' => 0,
- 'show_option_none' => __( '— Select —' ),
- 'option_none_value' => '0',
+ 'show_option_none' => $show_option_none,
+ 'option_none_value' => $option_none_value,
'selected' => $this->value(),
)
);
+ if ( empty( $dropdown ) ) {
+ $dropdown = sprintf( '';
+ }
// Hackily add in the data link parameter.
- $dropdown = str_replace( '', $dropdown );
+ }
+ }
+
+ echo $dropdown;
+ ?>
+ allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
+
+
- Add new image, your theme recommends a header size of %s × %s pixels.' ), $width, $height );
- } elseif ( $width ) {
- printf( __( 'While you can crop images to your liking after clicking Add new image, your theme recommends a header width of %s pixels.' ), $width );
- } else {
- printf( __( 'While you can crop images to your liking after clicking Add new image, your theme recommends a header height of %s pixels.' ), $height );
- }
- ?>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- json['theme'] = $this->theme;
- }
-
- /**
- * Don't render the control content from PHP, as it's rendered via JS on load.
- *
- * @since 4.2.0
- * @access public
- */
- public function render_content() {}
-
- /**
- * Render a JS template for theme display.
- *
- * @since 4.2.0
- * @access public
- */
- public function content_template() {
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
- $active_url = esc_url( remove_query_arg( 'theme', $current_url ) );
- $preview_url = esc_url( add_query_arg( 'theme', '__THEME__', $current_url ) ); // Token because esc_url() strips curly braces.
- $preview_url = str_replace( '__THEME__', '{{ data.theme.id }}', $preview_url );
- ?>
- <# if ( data.theme.isActiveTheme ) { #>
-