X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/af50974463450c98503e763a7836a50e260461a9..073c5ed6408e2f00dc1863b463fe205467628905:/wp-includes/class-wp-customize-control.php
diff --git a/wp-includes/class-wp-customize-control.php b/wp-includes/class-wp-customize-control.php
index 3c8a8bd9..1920140f 100644
--- a/wp-includes/class-wp-customize-control.php
+++ b/wp-includes/class-wp-customize-control.php
@@ -1,11 +1,17 @@
instance_number = self::$instance_count;
// Process settings.
- if ( empty( $this->settings ) ) {
+ if ( ! isset( $this->settings ) ) {
$this->settings = $id;
}
@@ -161,7 +208,7 @@ class WP_Customize_Control {
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;
}
@@ -183,12 +230,12 @@ class WP_Customize_Control {
*
* @return bool Whether the control is active to the current preview.
*/
- public final function active() {
+ final public function active() {
$control = $this;
$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
*
@@ -209,7 +256,7 @@ class WP_Customize_Control {
* @since 4.0.0
* @access public
*
- * @return bool Always true.
+ * @return true Always true.
*/
public function active_callback() {
return true;
@@ -224,7 +271,7 @@ class WP_Customize_Control {
* @param string $setting_key
* @return mixed The requested setting's value, if the setting exists.
*/
- public final function value( $setting_key = 'default' ) {
+ final public function value( $setting_key = 'default' ) {
if ( isset( $this->settings[ $setting_key ] ) ) {
return $this->settings[ $setting_key ]->value();
}
@@ -264,21 +311,32 @@ class WP_Customize_Control {
}
/**
- * 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.
*/
- public final function check_capabilities() {
+ 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;
}
@@ -290,12 +348,10 @@ class WP_Customize_Control {
*
* @return string Contents of the control.
*/
- public final function get_content() {
+ 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() );
}
/**
@@ -304,7 +360,7 @@ class WP_Customize_Control {
* @since 3.4.0
* @uses WP_Customize_Control::render()
*/
- public final function maybe_render() {
+ final public function maybe_render() {
if ( ! $this->check_capabilities() )
return;
@@ -325,7 +381,7 @@ class WP_Customize_Control {
*
* @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 );
@@ -338,7 +394,7 @@ class WP_Customize_Control {
* @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;
?>
@@ -380,7 +436,7 @@ class WP_Customize_Control {
* @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 ) . '" ';
}
}
@@ -388,12 +444,12 @@ class WP_Customize_Control {
/**
* 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 overriden 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
*/
@@ -468,7 +524,16 @@ class WP_Customize_Control {
+
+
@@ -507,7 +570,7 @@ class WP_Customize_Control {
* Render the control's JS template.
*
* This function is only run for control types that have been registered with
- * {@see WP_Customize_Manager::register_control_type()}.
+ * WP_Customize_Manager::register_control_type().
*
* In the future, this will also print the template for the control's container
* element and be override-able.
@@ -515,18 +578,18 @@ class WP_Customize_Control {
* @since 4.1.0
*/
final public function print_template() {
- ?>
-
-
+
+ statuses = array( '' => __('Default') );
- parent::__construct( $manager, $id, $args );
- }
-
- /**
- * Enqueue scripts/styles for the color picker.
- *
- * @since 3.4.0
- */
- public function enqueue() {
- wp_enqueue_script( 'wp-color-picker' );
- wp_enqueue_style( 'wp-color-picker' );
- }
-
- /**
- * Refresh the parameters passed to the JavaScript via JSON.
- *
- * @since 3.4.0
- * @uses WP_Customize_Control::to_json()
- */
- public function to_json() {
- parent::to_json();
- $this->json['statuses'] = $this->statuses;
- $this->json['defaultValue'] = $this->setting->default;
- }
-
- /**
- * Don't render the control content from PHP, as it's rendered via JS on load.
- *
- * @since 3.4.0
- */
- public function render_content() {}
-
- /**
- * Render a JS template for the content of the color picker control.
- *
- * @since 4.1.0
- */
- public function content_template() {
- ?>
- <# var defaultValue = '';
- if ( data.defaultValue ) {
- if ( '#' !== data.defaultValue.substring( 0, 1 ) ) {
- defaultValue = '#' + data.defaultValue;
- } else {
- defaultValue = data.defaultValue;
- }
- defaultValue = ' data-default-color=' + defaultValue; // Quotes added automatically.
- } #>
-
- <# if ( data.label ) { #>
- {{{ data.label }}}
- <# } #>
- <# if ( data.description ) { #>
- {{{ data.description }}}
- <# } #>
-
-
-
-
- button_labels = array(
- 'select' => __( 'Select File' ),
- 'change' => __( 'Change File' ),
- 'default' => __( 'Default' ),
- 'remove' => __( 'Remove' ),
- 'placeholder' => __( 'No file selected' ),
- 'frame_title' => __( 'Select File' ),
- 'frame_button' => __( 'Choose File' ),
- );
- }
-
- /**
- * Enqueue control related scripts/styles.
- *
- * @since 3.4.0
- */
- public function enqueue() {
- wp_enqueue_media();
- }
-
- /**
- * Refresh the parameters passed to the JavaScript via JSON.
- *
- * @since 3.4.0
- * @uses WP_Customize_Control::to_json()
- */
- public function to_json() {
- parent::to_json();
- $this->json['mime_type'] = $this->mime_type;
- $this->json['button_labels'] = $this->button_labels;
-
- $value = $this->value();
-
- if ( is_object( $this->setting ) ) {
- if ( $this->setting->default ) {
- // Fake an attachment model - needs all fields used by template.
- $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
- $default_attachment = array(
- 'id' => 1,
- 'url' => $this->setting->default,
- 'type' => $type,
- 'icon' => wp_mime_type_icon( $type ),
- 'title' => basename( $this->setting->default ),
- );
-
- if ( 'image' === $type ) {
- $default_attachment['sizes'] = array(
- 'full' => array( 'url' => $this->setting->default ),
- );
- }
-
- $this->json['defaultAttachment'] = $default_attachment;
- }
-
- if ( $value && $this->setting->default && $value === $this->setting->default ) {
- // Set the default as the attachment.
- $this->json['attachment'] = $this->json['defaultAttachment'];
- } elseif ( $value ) {
- // Get the attachment model for the existing file.
- $attachment_id = attachment_url_to_postid( $value );
- if ( $attachment_id ) {
- $this->json['attachment'] = wp_prepare_attachment_for_js( $attachment_id );
- }
- }
- }
- }
-
- /**
- * Don't render any content for this control from PHP.
- *
- * @see WP_Customize_Upload_Control::content_template()
- * @since 3.4.0
- */
- public function render_content() {}
-
- /**
- * Render a JS template for the content of the upload control.
- *
- * @since 4.1.0
- */
- public function content_template() {
- ?>
-
- <# if ( data.label ) { #>
- {{ data.label }}
- <# } #>
- <# if ( data.description ) { #>
- {{{ data.description }}}
- <# } #>
-
-
- <# if ( data.attachment && data.attachment.id ) { #>
-
- 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 );
- }
- ?>
-