wp/wp-includes/customize/class-wp-customize-media-control.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    73 	 *
    73 	 *
    74 	 * @see WP_Customize_Control::to_json()
    74 	 * @see WP_Customize_Control::to_json()
    75 	 */
    75 	 */
    76 	public function to_json() {
    76 	public function to_json() {
    77 		parent::to_json();
    77 		parent::to_json();
    78 		$this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) );
    78 		$this->json['label']         = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) );
    79 		$this->json['mime_type'] = $this->mime_type;
    79 		$this->json['mime_type']     = $this->mime_type;
    80 		$this->json['button_labels'] = $this->button_labels;
    80 		$this->json['button_labels'] = $this->button_labels;
    81 		$this->json['canUpload'] = current_user_can( 'upload_files' );
    81 		$this->json['canUpload']     = current_user_can( 'upload_files' );
    82 
    82 
    83 		$value = $this->value();
    83 		$value = $this->value();
    84 
    84 
    85 		if ( is_object( $this->setting ) ) {
    85 		if ( is_object( $this->setting ) ) {
    86 			if ( $this->setting->default ) {
    86 			if ( $this->setting->default ) {
    87 				// Fake an attachment model - needs all fields used by template.
    87 				// Fake an attachment model - needs all fields used by template.
    88 				// Note that the default value must be a URL, NOT an attachment ID.
    88 				// Note that the default value must be a URL, NOT an attachment ID.
    89 				$type = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
    89 				$type               = in_array( substr( $this->setting->default, -3 ), array( 'jpg', 'png', 'gif', 'bmp' ) ) ? 'image' : 'document';
    90 				$default_attachment = array(
    90 				$default_attachment = array(
    91 					'id' => 1,
    91 					'id'    => 1,
    92 					'url' => $this->setting->default,
    92 					'url'   => $this->setting->default,
    93 					'type' => $type,
    93 					'type'  => $type,
    94 					'icon' => wp_mime_type_icon( $type ),
    94 					'icon'  => wp_mime_type_icon( $type ),
    95 					'title' => basename( $this->setting->default ),
    95 					'title' => wp_basename( $this->setting->default ),
    96 				);
    96 				);
    97 
    97 
    98 				if ( 'image' === $type ) {
    98 				if ( 'image' === $type ) {
    99 					$default_attachment['sizes'] = array(
    99 					$default_attachment['sizes'] = array(
   100 						'full' => array( 'url' => $this->setting->default ),
   100 						'full' => array( 'url' => $this->setting->default ),
   130 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
   130 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
   131 	 */
   131 	 */
   132 	public function content_template() {
   132 	public function content_template() {
   133 		?>
   133 		?>
   134 		<#
   134 		<#
   135 		var selectButtonId = _.uniqueId( 'customize-media-control-button-' );
       
   136 		var descriptionId = _.uniqueId( 'customize-media-control-description-' );
   135 		var descriptionId = _.uniqueId( 'customize-media-control-description-' );
   137 		var describedByAttr = data.description ? ' aria-describedby="' + descriptionId + '" ' : '';
   136 		var describedByAttr = data.description ? ' aria-describedby="' + descriptionId + '" ' : '';
   138 		#>
   137 		#>
   139 		<# if ( data.label ) { #>
   138 		<# if ( data.label ) { #>
   140 			<label class="customize-control-title" for="{{ selectButtonId }}">{{ data.label }}</label>
   139 			<span class="customize-control-title">{{ data.label }}</span>
   141 		<# } #>
   140 		<# } #>
   142 		<div class="customize-control-notifications-container"></div>
   141 		<div class="customize-control-notifications-container"></div>
   143 		<# if ( data.description ) { #>
   142 		<# if ( data.description ) { #>
   144 			<span id="{{ descriptionId }}" class="description customize-control-description">{{{ data.description }}}</span>
   143 			<span id="{{ descriptionId }}" class="description customize-control-description">{{{ data.description }}}</span>
   145 		<# } #>
   144 		<# } #>
   180 					<# } #>
   179 					<# } #>
   181 				</div>
   180 				</div>
   182 				<div class="actions">
   181 				<div class="actions">
   183 					<# if ( data.canUpload ) { #>
   182 					<# if ( data.canUpload ) { #>
   184 					<button type="button" class="button remove-button">{{ data.button_labels.remove }}</button>
   183 					<button type="button" class="button remove-button">{{ data.button_labels.remove }}</button>
   185 					<button type="button" class="button upload-button control-focus" id="{{ selectButtonId }}" {{{ describedByAttr }}}>{{ data.button_labels.change }}</button>
   184 					<button type="button" class="button upload-button control-focus" {{{ describedByAttr }}}>{{ data.button_labels.change }}</button>
   186 					<# } #>
   185 					<# } #>
   187 				</div>
   186 				</div>
   188 			</div>
   187 			</div>
   189 		<# } else { #>
   188 		<# } else { #>
   190 			<div class="attachment-media-view">
   189 			<div class="attachment-media-view">
   191 				<div class="placeholder">
   190 				<# if ( data.canUpload ) { #>
   192 						{{ data.button_labels.placeholder }}
   191 					<button type="button" class="upload-button button-add-media" {{{ describedByAttr }}}>{{ data.button_labels.select }}</button>
   193 				</div>
   192 				<# } #>
   194 				<div class="actions">
   193 				<div class="actions">
   195 					<# if ( data.defaultAttachment ) { #>
   194 					<# if ( data.defaultAttachment ) { #>
   196 						<button type="button" class="button default-button">{{ data.button_labels['default'] }}</button>
   195 						<button type="button" class="button default-button">{{ data.button_labels['default'] }}</button>
   197 					<# } #>
       
   198 					<# if ( data.canUpload ) { #>
       
   199 					<button type="button" class="button upload-button" id="{{ selectButtonId }}" {{{ describedByAttr }}}>{{ data.button_labels.select }}</button>
       
   200 					<# } #>
   196 					<# } #>
   201 				</div>
   197 				</div>
   202 			</div>
   198 			</div>
   203 		<# } #>
   199 		<# } #>
   204 		<?php
   200 		<?php
   239 					'frame_button' => __( 'Choose audio' ),
   235 					'frame_button' => __( 'Choose audio' ),
   240 				);
   236 				);
   241 			case 'image':
   237 			case 'image':
   242 				return array(
   238 				return array(
   243 					'select'       => __( 'Select image' ),
   239 					'select'       => __( 'Select image' ),
       
   240 					'site_icon'    => __( 'Select site icon' ),
   244 					'change'       => __( 'Change image' ),
   241 					'change'       => __( 'Change image' ),
   245 					'default'      => __( 'Default' ),
   242 					'default'      => __( 'Default' ),
   246 					'remove'       => __( 'Remove' ),
   243 					'remove'       => __( 'Remove' ),
   247 					'placeholder'  => __( 'No image selected' ),
   244 					'placeholder'  => __( 'No image selected' ),
   248 					'frame_title'  => __( 'Select image' ),
   245 					'frame_title'  => __( 'Select image' ),