X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/a7cd4c052013b423c6301153f68c7fdbaa2a447b..5e031ad59895b5682d1509675cafe9f2c5081c12:/wp-includes/class-wp-customize-control.php?ds=sidebyside diff --git a/wp-includes/class-wp-customize-control.php b/wp-includes/class-wp-customize-control.php index 950b0d5a..bf17fb20 100644 --- a/wp-includes/class-wp-customize-control.php +++ b/wp-includes/class-wp-customize-control.php @@ -1,11 +1,17 @@ active_callback, $this ); @@ -224,7 +230,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 +276,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,7 +296,7 @@ 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() ); @@ -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() { - ?> - - + + 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 +745,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 +753,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 +787,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,6 +799,16 @@ 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 }}

@@ -803,11 +847,47 @@ class WP_Customize_Upload_Control extends WP_Customize_Control { } /** - * Customize Image Control Class + * Customize Upload Control Class. * - * @package WordPress - * @subpackage Customize * @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. + * + * @since 3.4.0 + * + * @see WP_Customize_Upload_Control */ class WP_Customize_Image_Control extends WP_Customize_Upload_Control { public $type = 'image'; @@ -872,11 +952,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'; @@ -912,6 +992,13 @@ class WP_Customize_Background_Image_Control extends WP_Customize_Image_Control { } } +/** + * 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; @@ -934,10 +1021,6 @@ class WP_Customize_Header_Image_Control extends WP_Customize_Image_Control { } - public function to_json() { - parent::to_json(); - } - public function enqueue() { wp_enqueue_media(); wp_enqueue_script( 'customize-views' ); @@ -975,7 +1058,7 @@ 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() { + public function print_header_image_template() { ?>