Make WordPress Core

Changeset 41550


Ignore:
Timestamp:
09/20/2017 09:23:51 PM (9 years ago)
Author:
westonruter
Message:

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

Props Christian1012, celloexpressions, westonruter.
Fixes #38796.

Location:
trunk/src/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-customize-manager.php

    r41397 r41550  
    40054005                        'section'        => 'header_image',
    40064006                        'mime_type'      => 'video',
    4007                         // @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>.
    4008                         'button_labels'  => array(
    4009                                 'select'       => __( 'Select Video' ),
    4010                                 'change'       => __( 'Change Video' ),
    4011                                 'placeholder'  => __( 'No video selected' ),
    4012                                 'frame_title'  => __( 'Select Video' ),
    4013                                 'frame_button' => __( 'Choose Video' ),
    4014                         ),
    40154007                        'active_callback' => 'is_header_video_active',
    40164008                ) ) );
  • trunk/src/wp-includes/customize/class-wp-customize-image-control.php

    r41273 r41550  
    1818        public $type = 'image';
    1919        public $mime_type = 'image';
    20 
    21         /**
    22          * Constructor.
    23          *
    24          * @since 3.4.0
    25          * @uses WP_Customize_Upload_Control::__construct()
    26          *
    27          * @param WP_Customize_Manager $manager Customizer bootstrap instance.
    28          * @param string               $id      Control ID.
    29          * @param array                $args    Optional. Arguments to override class property defaults.
    30          */
    31         public function __construct( $manager, $id, $args = array() ) {
    32                 parent::__construct( $manager, $id, $args );
    33 
    34                 $this->button_labels = wp_parse_args( $this->button_labels, array(
    35                         'select'       => __( 'Select Image' ),
    36                         'change'       => __( 'Change Image' ),
    37                         'remove'       => __( 'Remove' ),
    38                         'default'      => __( 'Default' ),
    39                         'placeholder'  => __( 'No image selected' ),
    40                         'frame_title'  => __( 'Select Image' ),
    41                         'frame_button' => __( 'Choose Image' ),
    42                 ) );
    43         }
    4420
    4521        /**
  • trunk/src/wp-includes/customize/class-wp-customize-media-control.php

    r41162 r41550  
    5353                parent::__construct( $manager, $id, $args );
    5454
    55                 if ( ! ( $this instanceof WP_Customize_Image_Control ) ) {
    56                         $this->button_labels = wp_parse_args( $this->button_labels, array(
    57                                 'select'       => __( 'Select File' ),
    58                                 'change'       => __( 'Change File' ),
    59                                 'default'      => __( 'Default' ),
    60                                 'remove'       => __( 'Remove' ),
    61                                 'placeholder'  => __( 'No file selected' ),
    62                                 'frame_title'  => __( 'Select File' ),
    63                                 'frame_button' => __( 'Choose File' ),
    64                         ) );
    65                 }
     55                $this->button_labels = wp_parse_args( $this->button_labels, $this->get_default_button_labels() );
    6656        }
    6757
     
    210200                <?php
    211201        }
     202
     203        /**
     204         * Get default button labels.
     205         *
     206         * Provides an array of the default button labels based on the mime type of the current control.
     207         *
     208         * @since 4.9.0
     209         *
     210         * @return array An associative array of default button labels.
     211         */
     212        public function get_default_button_labels() {
     213                // Get just the mime type and strip the mime subtype if present.
     214                $mime_type = ! empty( $this->mime_type ) ? strtok( ltrim( $this->mime_type, '/' ), '/' ) : 'default';
     215
     216                switch ( $mime_type ) {
     217                        case 'video':
     218                                return array(
     219                                        'select'       => __( 'Select video' ),
     220                                        'change'       => __( 'Change video' ),
     221                                        'default'      => __( 'Default' ),
     222                                        'remove'       => __( 'Remove' ),
     223                                        'placeholder'  => __( 'No video selected' ),
     224                                        'frame_title'  => __( 'Select video' ),
     225                                        'frame_button' => __( 'Choose video' ),
     226                                );
     227                        case 'audio':
     228                                return array(
     229                                        'select'       => __( 'Select audio' ),
     230                                        'change'       => __( 'Change audio' ),
     231                                        'default'      => __( 'Default' ),
     232                                        'remove'       => __( 'Remove' ),
     233                                        'placeholder'  => __( 'No audio selected' ),
     234                                        'frame_title'  => __( 'Select audio' ),
     235                                        'frame_button' => __( 'Choose audio' ),
     236                                );
     237                        case 'image':
     238                                return array(
     239                                        'select'       => __( 'Select image' ),
     240                                        'change'       => __( 'Change image' ),
     241                                        'default'      => __( 'Default' ),
     242                                        'remove'       => __( 'Remove' ),
     243                                        'placeholder'  => __( 'No image selected' ),
     244                                        'frame_title'  => __( 'Select image' ),
     245                                        'frame_button' => __( 'Choose image' ),
     246                                );
     247                        default:
     248                                return array(
     249                                        'select'       => __( 'Select file' ),
     250                                        'change'       => __( 'Change file' ),
     251                                        'default'      => __( 'Default' ),
     252                                        'remove'       => __( 'Remove' ),
     253                                        'placeholder'  => __( 'No file selected' ),
     254                                        'frame_title'  => __( 'Select file' ),
     255                                        'frame_button' => __( 'Choose file' ),
     256                                );
     257                } // End switch().
     258        }
    212259}
Note: See TracChangeset for help on using the changeset viewer.