button_labels = wp_parse_args( $this->button_labels, array( 'select' => __( 'Select File', 'benjamin' ), 'change' => __( 'Change File', 'benjamin' ), 'default' => __( 'Default', 'benjamin' ), 'remove' => __( 'Remove', 'benjamin' ), 'placeholder' => __( 'No file selected', 'benjamin' ), 'frame_title' => __( 'Select File', 'benjamin' ), 'frame_button' => __( 'Choose File', 'benjamin' ), ) ); } /** * Enqueue control related scripts/styles. * * @since 3.4.0 * @since 4.2.0 Moved from WP_Customize_Upload_Control. */ public function enqueue() { wp_enqueue_media(); } public function to_json() { parent::to_json(); $this->json['label'] = html_entity_decode( $this->label, ENT_QUOTES, get_bloginfo( 'charset' ) ); $this->json['mime_type'] = $this->mime_type; $this->json['button_labels'] = $this->button_labels; $this->json['canUpload'] = current_user_can( 'upload_files' ); $this->json['control_name'] = $this->id; $this->json['setting_name'] = $this->setting->id; $this->json['value'] = $this->value(); $this->json['localURL'] = $this->is_local_file(); $this->json['video_type'] = $this->get_type(); // if the settings attr is not an object, we do nothing if ( !is_object( $this->setting ) ) return; } private function is_local_file() { // if the file a local file? $val = str_replace(array('http://', 'https://'), '', $this->value() ); $home = str_replace(array('http://', 'https://'), '', home_url() ); if( strpos( $val, $home ) !== false){ return true; } return false; } private function get_type() { $url = $this->value(); $type = null; if('.mp4' == substr( $url, -4 ) ){ $type = 'mp4'; } elseif( '.mov' == substr( $url, -4 ) ) { $type = 'mov'; } elseif('.webm' == substr( $url, -5 )) { $type = 'webm'; } elseif ( preg_match( '#^https?://(?:www\.)?(?:youtube\.com/watch|youtu\.be/)#', $url ) ) { $type = 'youtube'; } return $type; } private function url_field() { ?> - or use URL -
<# if ( data.value ) { #>
<# if ( data.canUpload ) { #> {{ data.button_labels.change }} {{ data.button_labels.remove }} url_field(); ?>
<# } #>
<# } else { #>
{{ data.button_labels.placeholder }}
<# if ( data.defaultAttachment ) { #> {{ data.button_labels['default'] }} url_field(); ?> <# } #> <# if ( data.canUpload ) { #> {{ data.button_labels.select }} url_field(); ?> <# } #>
<# } #>