Customize: Let media control button labels better automatically reflect the specified MIME type.

Props Christian1012, celloexpressions, westonruter.
Fixes #38796.

Built from https://develop.svn.wordpress.org/trunk@41550


git-svn-id: http://core.svn.wordpress.org/trunk@41383 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter 2017-09-20 21:24:46 +00:00
parent 379e0371dd
commit 800ad7bd04
4 changed files with 59 additions and 44 deletions

View File

@ -4004,14 +4004,6 @@ final class WP_Customize_Manager {
'description' => $control_description,
'section' => 'header_image',
'mime_type' => 'video',
// @todo These button_labels can be removed once WP_Customize_Media_Control provides mime_type-specific labels automatically. See <https://core.trac.wordpress.org/ticket/38796>.
'button_labels' => array(
'select' => __( 'Select Video' ),
'change' => __( 'Change Video' ),
'placeholder' => __( 'No video selected' ),
'frame_title' => __( 'Select Video' ),
'frame_button' => __( 'Choose Video' ),
),
'active_callback' => 'is_header_video_active',
) ) );

View File

@ -18,30 +18,6 @@ class WP_Customize_Image_Control extends WP_Customize_Upload_Control {
public $type = 'image';
public $mime_type = 'image';
/**
* Constructor.
*
* @since 3.4.0
* @uses WP_Customize_Upload_Control::__construct()
*
* @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 );
$this->button_labels = wp_parse_args( $this->button_labels, array(
'select' => __( 'Select Image' ),
'change' => __( 'Change Image' ),
'remove' => __( 'Remove' ),
'default' => __( 'Default' ),
'placeholder' => __( 'No image selected' ),
'frame_title' => __( 'Select Image' ),
'frame_button' => __( 'Choose Image' ),
) );
}
/**
* @since 3.4.2
* @deprecated 4.1.0

View File

@ -52,17 +52,7 @@ class WP_Customize_Media_Control extends WP_Customize_Control {
public function __construct( $manager, $id, $args = array() ) {
parent::__construct( $manager, $id, $args );
if ( ! ( $this instanceof WP_Customize_Image_Control ) ) {
$this->button_labels = wp_parse_args( $this->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' ),
) );
}
$this->button_labels = wp_parse_args( $this->button_labels, $this->get_default_button_labels() );
}
/**
@ -209,4 +199,61 @@ class WP_Customize_Media_Control extends WP_Customize_Control {
<# } #>
<?php
}
/**
* Get default button labels.
*
* Provides an array of the default button labels based on the mime type of the current control.
*
* @since 4.9.0
*
* @return array An associative array of default button labels.
*/
public function get_default_button_labels() {
// Get just the mime type and strip the mime subtype if present.
$mime_type = ! empty( $this->mime_type ) ? strtok( ltrim( $this->mime_type, '/' ), '/' ) : 'default';
switch ( $mime_type ) {
case 'video':
return array(
'select' => __( 'Select video' ),
'change' => __( 'Change video' ),
'default' => __( 'Default' ),
'remove' => __( 'Remove' ),
'placeholder' => __( 'No video selected' ),
'frame_title' => __( 'Select video' ),
'frame_button' => __( 'Choose video' ),
);
case 'audio':
return array(
'select' => __( 'Select audio' ),
'change' => __( 'Change audio' ),
'default' => __( 'Default' ),
'remove' => __( 'Remove' ),
'placeholder' => __( 'No audio selected' ),
'frame_title' => __( 'Select audio' ),
'frame_button' => __( 'Choose audio' ),
);
case 'image':
return array(
'select' => __( 'Select image' ),
'change' => __( 'Change image' ),
'default' => __( 'Default' ),
'remove' => __( 'Remove' ),
'placeholder' => __( 'No image selected' ),
'frame_title' => __( 'Select image' ),
'frame_button' => __( 'Choose image' ),
);
default:
return array(
'select' => __( 'Select file' ),
'change' => __( 'Change file' ),
'default' => __( 'Default' ),
'remove' => __( 'Remove' ),
'placeholder' => __( 'No file selected' ),
'frame_title' => __( 'Select file' ),
'frame_button' => __( 'Choose file' ),
);
} // End switch().
}
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.9-alpha-41549';
$wp_version = '4.9-alpha-41550';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.