wp/wp-includes/customize/class-wp-customize-media-control.php
changeset 16 a86126ab1dd4
parent 9 177826044cd9
child 18 be944660c56a
equal deleted inserted replaced
15:3d4e9c994f10 16:a86126ab1dd4
    43 	 * Constructor.
    43 	 * Constructor.
    44 	 *
    44 	 *
    45 	 * @since 4.1.0
    45 	 * @since 4.1.0
    46 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
    46 	 * @since 4.2.0 Moved from WP_Customize_Upload_Control.
    47 	 *
    47 	 *
       
    48 	 * @see WP_Customize_Control::__construct()
       
    49 	 *
    48 	 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
    50 	 * @param WP_Customize_Manager $manager Customizer bootstrap instance.
    49 	 * @param string               $id      Control ID.
    51 	 * @param string               $id      Control ID.
    50 	 * @param array                $args    Optional. Arguments to override class property defaults.
    52 	 * @param array                $args    Optional. Arguments to override class property defaults.
       
    53 	 *                                      See WP_Customize_Control::__construct() for information
       
    54 	 *                                      on accepted arguments. Default empty array.
    51 	 */
    55 	 */
    52 	public function __construct( $manager, $id, $args = array() ) {
    56 	public function __construct( $manager, $id, $args = array() ) {
    53 		parent::__construct( $manager, $id, $args );
    57 		parent::__construct( $manager, $id, $args );
    54 
    58 
    55 		$this->button_labels = wp_parse_args( $this->button_labels, $this->get_default_button_labels() );
    59 		$this->button_labels = wp_parse_args( $this->button_labels, $this->get_default_button_labels() );
    84 
    88 
    85 		if ( is_object( $this->setting ) ) {
    89 		if ( is_object( $this->setting ) ) {
    86 			if ( $this->setting->default ) {
    90 			if ( $this->setting->default ) {
    87 				// Fake an attachment model - needs all fields used by template.
    91 				// Fake an attachment model - needs all fields used by template.
    88 				// Note that the default value must be a URL, NOT an attachment ID.
    92 				// 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';
    93 				$ext  = substr( $this->setting->default, -3 );
       
    94 				$type = in_array( $ext, array( 'jpg', 'png', 'gif', 'bmp' ), true ) ? 'image' : 'document';
       
    95 
    90 				$default_attachment = array(
    96 				$default_attachment = array(
    91 					'id'    => 1,
    97 					'id'    => 1,
    92 					'url'   => $this->setting->default,
    98 					'url'   => $this->setting->default,
    93 					'type'  => $type,
    99 					'type'  => $type,
    94 					'icon'  => wp_mime_type_icon( $type ),
   100 					'icon'  => wp_mime_type_icon( $type ),
   205 	 *
   211 	 *
   206 	 * Provides an array of the default button labels based on the mime type of the current control.
   212 	 * Provides an array of the default button labels based on the mime type of the current control.
   207 	 *
   213 	 *
   208 	 * @since 4.9.0
   214 	 * @since 4.9.0
   209 	 *
   215 	 *
   210 	 * @return array An associative array of default button labels.
   216 	 * @return string[] An associative array of default button labels keyed by the button name.
   211 	 */
   217 	 */
   212 	public function get_default_button_labels() {
   218 	public function get_default_button_labels() {
   213 		// Get just the mime type and strip the mime subtype if present.
   219 		// 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';
   220 		$mime_type = ! empty( $this->mime_type ) ? strtok( ltrim( $this->mime_type, '/' ), '/' ) : 'default';
   215 
   221