X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/985e04597a9f1ddc4a3b406d0fb33722e097ee8b..refs/tags/wordpress-4.3:/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 950b0d5a..1e621462 100644 --- a/wp-includes/class-wp-customize-control.php +++ b/wp-includes/class-wp-customize-control.php @@ -1,11 +1,17 @@ active_callback, $this ); @@ -209,7 +217,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 +232,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(); } @@ -270,7 +278,7 @@ class WP_Customize_Control { * * @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() { foreach ( $this->settings as $setting ) { if ( ! $setting->check_capabilities() ) return false; @@ -290,12 +298,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 +310,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; @@ -515,11 +521,11 @@ class WP_Customize_Control { * @since 4.1.0 */ final public function print_template() { - ?> - - + + statuses = array( '' => __('Default') ); @@ -632,26 +638,49 @@ class WP_Customize_Color_Control extends WP_Customize_Control { } /** - * Customize Upload Control Class + * Customize Media Control class. * - * @package WordPress - * @subpackage Customize - * @since 3.4.0 + * @since 4.2.0 + * + * @see WP_Customize_Control */ -class WP_Customize_Upload_Control extends WP_Customize_Control { - public $type = 'upload'; - public $mime_type = ''; +class WP_Customize_Media_Control extends WP_Customize_Control { + /** + * Control type. + * + * @since 4.2.0 + * @access public + * @var string + */ + public $type = 'media'; + + /** + * Media control mime type. + * + * @since 4.2.0 + * @access public + * @var string + */ + public $mime_type = ''; + + /** + * Button labels. + * + * @since 4.2.0 + * @access public + * @var array + */ public $button_labels = array(); - public $removed = ''; // unused - public $context; // unused - public $extensions = array(); // unused /** * Constructor. * * @since 4.1.0 + * @since 4.2.0 Moved from WP_Customize_Upload_Control. * - * @param WP_Customize_Manager $manager {@see WP_Customize_Manager} instance. + * @param WP_Customize_Manager $manager Customizer bootstrap instance. + * @param string $id Control ID. + * @param array $args Optional. Arguments to override class property defaults. */ public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); @@ -671,6 +700,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { * Enqueue control related scripts/styles. * * @since 3.4.0 + * @since 4.2.0 Moved from WP_Customize_Upload_Control. */ public function enqueue() { wp_enqueue_media(); @@ -680,18 +710,23 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { * Refresh the parameters passed to the JavaScript via JSON. * * @since 3.4.0 - * @uses WP_Customize_Control::to_json() + * @since 4.2.0 Moved from WP_Customize_Upload_Control. + * + * @see WP_Customize_Control::to_json() */ public function to_json() { parent::to_json(); + $this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) ); $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; + $this->json['canUpload'] = current_user_can( 'upload_files' ); $value = $this->value(); if ( is_object( $this->setting ) ) { if ( $this->setting->default ) { // Fake an attachment model - needs all fields used by template. + // Note that the default value must be a URL, NOT an attachment ID. $type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document'; $default_attachment = array( 'id' => 1, @@ -714,11 +749,7 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { // 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 ); - } + $this->json['attachment'] = wp_prepare_attachment_for_js( $value ); } } } @@ -726,15 +757,18 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { /** * Don't render any content for this control from PHP. * - * @see WP_Customize_Upload_Control::content_template() * @since 3.4.0 + * @since 4.2.0 Moved from WP_Customize_Upload_Control. + * + * @see WP_Customize_Media_Control::content_template() */ public function render_content() {} /** - * Render a JS template for the content of the upload control. + * Render a JS template for the content of the media control. * * @since 4.1.0 + * @since 4.2.0 Moved from WP_Customize_Upload_Control. */ public function content_template() { ?> @@ -757,7 +791,11 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { <# } else if ( 'image' === data.attachment.type && data.attachment.sizes && data.attachment.sizes.full ) { #> <# } else if ( 'audio' === data.attachment.type ) { #> - + <# if ( data.attachment.image && data.attachment.image.src && data.attachment.image.src !== data.attachment.icon ) { #> + + <# } else { #> + + <# } #>

“{{ data.attachment.title }}”

<# if ( data.attachment.album || data.attachment.meta.album ) { #>

{{ data.attachment.album || data.attachment.meta.album }}

@@ -765,8 +803,18 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { <# if ( data.attachment.artist || data.attachment.meta.artist ) { #>

{{ data.attachment.artist || data.attachment.meta.artist }}

<# } #> + + <# } else if ( 'video' === data.attachment.type ) { #> +
+ +
<# } else { #> - +

{{ data.attachment.title }}

<# } #> @@ -774,9 +822,11 @@ class WP_Customize_Upload_Control extends WP_Customize_Control {
+ <# if ( data.canUpload ) { #>
+ <# } #>
<# } else { #>
@@ -794,7 +844,9 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { <# if ( data.defaultAttachment ) { #> <# } #> + <# if ( data.canUpload ) { #> + <# } #>
<# } #> @@ -803,11 +855,47 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { } /** - * Customize Image Control Class + * Customize Upload Control Class. + * + * @since 3.4.0 + * + * @see WP_Customize_Media_Control + */ +class WP_Customize_Upload_Control extends WP_Customize_Media_Control { + public $type = 'upload'; + public $mime_type = ''; + public $button_labels = array(); + public $removed = ''; // unused + public $context; // unused + public $extensions = array(); // unused + + /** + * Refresh the parameters passed to the JavaScript via JSON. + * + * @since 3.4.0 + * + * @uses WP_Customize_Media_Control::to_json() + */ + public function to_json() { + parent::to_json(); + + $value = $this->value(); + if ( $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 ); + } + } + } +} + +/** + * Customize Image Control class. * - * @package WordPress - * @subpackage Customize * @since 3.4.0 + * + * @see WP_Customize_Upload_Control */ class WP_Customize_Image_Control extends WP_Customize_Upload_Control { public $type = 'image'; @@ -819,9 +907,9 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control { * @since 3.4.0 * @uses WP_Customize_Upload_Control::__construct() * - * @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. */ public function __construct( $manager, $id, $args = array() ) { parent::__construct( $manager, $id, $args ); @@ -872,11 +960,11 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control { } /** - * Customize Background Image Control Class + * Customize Background Image Control class. * - * @package WordPress - * @subpackage Customize * @since 3.4.0 + * + * @see WP_Customize_Image_Control */ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { public $type = 'background'; @@ -887,7 +975,7 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { * @since 3.4.0 * @uses WP_Customize_Image_Control::__construct() * - * @param WP_Customize_Manager $manager + * @param WP_Customize_Manager $manager Customizer bootstrap instance. */ public function __construct( $manager ) { parent::__construct( $manager, 'background_image', array( @@ -912,13 +1000,145 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { } } +/** + * Customize Cropped Image Control class. + * + * @since 4.3.0 + * + * @see WP_Customize_Media_Control + */ +class WP_Customize_Cropped_Image_Control extends WP_Customize_Media_Control { + + /** + * Control type. + * + * @since 4.3.0 + * @access public + * @var string + */ + public $type = 'cropped_image'; + + /** + * Suggested width for cropped image. + * + * @since 4.3.0 + * @access public + * @var int + */ + public $width = 150; + + /** + * Suggested height for cropped image. + * + * @since 4.3.0 + * @access public + * @var int + */ + public $height = 150; + + /** + * Whether the width is flexible. + * + * @since 4.3.0 + * @access public + * @var bool + */ + public $flex_width = false; + + /** + * Whether the height is flexible. + * + * @since 4.3.0 + * @access public + * @var bool + */ + public $flex_height = false; + + /** + * Enqueue control related scripts/styles. + * + * @since 4.3.0 + * @access public + */ + public function enqueue() { + wp_enqueue_script( 'customize-views' ); + + parent::enqueue(); + } + + /** + * Refresh the parameters passed to the JavaScript via JSON. + * + * @since 4.3.0 + * @access public + * + * @see WP_Customize_Control::to_json() + */ + public function to_json() { + parent::to_json(); + + $this->json['width'] = absint( $this->width ); + $this->json['height'] = absint( $this->height ); + $this->json['flex_width'] = absint( $this->flex_width ); + $this->json['flex_height'] = absint( $this->flex_height ); + } + +} + +/** + * Customize Site Icon control class. + * + * Used only for custom functionality in JavaScript. + * + * @since 4.3.0 + * + * @see WP_Customize_Cropped_Image_Control + */ +class WP_Customize_Site_Icon_Control extends WP_Customize_Cropped_Image_Control { + + /** + * Control type. + * + * @since 4.3.0 + * @access public + * @var string + */ + public $type = 'site_icon'; + + /** + * Constructor. + * + * @since 4.3.0 + * @access public + * + * @param WP_Customize_Manager $manager Customizer bootstrap instance. + * @param string $id Control ID. + * @param array $args Optional. Arguments to override class property defaults. + */ + public function __construct( $manager, $id, $args = array() ) { + parent::__construct( $manager, $id, $args ); + add_action( 'customize_controls_print_styles', 'wp_site_icon', 99 ); + } +} + +/** + * Customize Header Image Control class. + * + * @since 3.4.0 + * + * @see WP_Customize_Image_Control + */ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { public $type = 'header'; public $uploaded_headers; public $default_headers; /** - * @param WP_Customize_Manager $manager + * Constructor. + * + * @since 3.4.0 + * + * @param WP_Customize_Manager $manager Customizer bootstrap instance. */ public function __construct( $manager ) { parent::__construct( $manager, 'header_image', array( @@ -934,10 +1154,9 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { } - public function to_json() { - parent::to_json(); - } - + /** + * @access public + */ public function enqueue() { wp_enqueue_media(); wp_enqueue_script( 'customize-views' ); @@ -963,6 +1182,10 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { parent::enqueue(); } + /** + * + * @global Custom_Image_Header $custom_image_header + */ public function prepare_control() { global $custom_image_header; if ( empty( $custom_image_header ) ) { @@ -975,23 +1198,26 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { $this->uploaded_headers = $custom_image_header->get_uploaded_header_images(); } - function print_header_image_template() { + /** + * @access public + */ + public function print_header_image_template() { ?>