X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/wordpress.git/blobdiff_plain/849f15aeed7a5e39314057bdc0064d8edd60dd7d..HEAD:/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..07c6dcfc 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 +217,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 +239,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 +265,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 +280,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();
}
@@ -249,6 +305,10 @@ class WP_Customize_Control {
$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;
+ }
}
/**
@@ -264,21 +324,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 +361,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 +373,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,9 +394,9 @@ 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 );
+ do_action( "customize_render_control_{$this->id}", $this );
$this->render();
}
@@ -338,7 +407,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 +449,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 +457,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 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
*/
@@ -463,29 +532,72 @@ class WP_Customize_Control {
if ( ! empty( $this->description ) ) : ?>
description; ?>
-
+
+
+ allow_addition && current_user_can( 'publish_pages' ) && current_user_can( 'edit_theme_options' ) ) : // Currently tied to menus functionality. ?>
+
+
+
+
+
+
+
@@ -507,7 +619,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 +627,18 @@ class WP_Customize_Control {
* @since 4.1.0
*/
final public function print_template() {
- ?>
-
-
+
+ statuses = array( '' => __('Default') );
- parent::__construct( $manager, $id, $args );
- }
+/** WP_Customize_Upload_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-upload-control.php' );
- /**
- * 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' );
- }
+/** WP_Customize_Image_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-image-control.php' );
- /**
- * 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;
- }
+/** WP_Customize_Background_Image_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-image-control.php' );
- /**
- * Don't render the control content from PHP, as it's rendered via JS on load.
- *
- * @since 3.4.0
- */
- public function render_content() {}
+/** WP_Customize_Background_Position_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-background-position-control.php' );
- /**
- * 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' ),
- );
- }
+/** WP_Customize_Header_Image_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-header-image-control.php' );
- /**
- * Enqueue control related scripts/styles.
- *
- * @since 3.4.0
- */
- public function enqueue() {
- wp_enqueue_media();
- }
+/** WP_Customize_Theme_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-theme-control.php' );
- /**
- * 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 ),
- );
+/** WP_Widget_Area_Customize_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-widget-area-customize-control.php' );
- if ( 'image' === $type ) {
- $default_attachment['sizes'] = array(
- 'full' => array( 'url' => $this->setting->default ),
- );
- }
+/** WP_Widget_Form_Customize_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-widget-form-customize-control.php' );
- $this->json['defaultAttachment'] = $default_attachment;
- }
+/** WP_Customize_Nav_Menu_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-control.php' );
- 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 );
- }
- }
- }
- }
+/** WP_Customize_Nav_Menu_Item_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-item-control.php' );
- /**
- * 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() {}
+/** WP_Customize_Nav_Menu_Location_Control class */
+require_once( ABSPATH . WPINC . '/customize/class-wp-customize-nav-menu-location-control.php' );
- /**
- * 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 );
- }
- ?>
-