'cx-ui-media-id', 'name' => 'cx-ui-media-name', 'value' => '', 'multi_upload' => true, 'library_type' => '', // image, video, sound 'upload_button_text' => 'Choose Media', 'label' => '', 'class' => '', ); /** * Register control dependencies * * @return [type] [description] */ public function register_depends() { wp_enqueue_media(); } /** * Retrun scripts dependencies list for current control. * * @return array */ public function get_script_depends() { return array( 'jquery-ui-sortable' ); } /** * Render html CX_Control_Media. * * @since 1.0.0 */ public function render() { $html = ''; if ( ! current_user_can( 'upload_files' ) ) { return $html; } $class = implode( ' ', array( $this->settings['class'], ) ); $html .= '
'; if ( '' != $this->settings['value'] ) { $this->settings['value'] = str_replace( ' ', '', $this->settings['value'] ); $medias = explode( ',', $this->settings['value'] ); } else { $this->settings['value'] = ''; $medias = array(); } $img_style = ! $this->settings['value'] ? 'style="display:none;"' : '' ; if ( '' !== $this->settings['label'] ) { $html .= ' '; } $html .= '
'; $html .= '
'; $html .= '
'; if ( is_array( $medias ) && ! empty( $medias ) ) { foreach ( $medias as $medias_key => $medias_value ) { $media_title = get_the_title( $medias_value ); $mime_type = get_post_mime_type( $medias_value ); $tmp = wp_get_attachment_metadata( $medias_value ); $img_src = ''; $thumb = ''; switch ( $mime_type ) { case 'image/jpeg': case 'image/png': case 'image/gif': $img_src = wp_get_attachment_image_src( $medias_value, 'thumbnail' ); $img_src = $img_src[0]; $thumb = ''; break; case 'image/x-icon': $thumb = ''; break; case 'video/mpeg': case 'video/mp4': case 'video/quicktime': case 'video/webm': case 'video/ogg': $thumb = ''; break; case 'audio/mpeg': case 'audio/wav': case 'audio/ogg': $thumb = ''; break; } $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; $html .= $thumb; $html .= '
'; $html .= '
'; $html .= '' . $media_title . ''; $html .= ''; $html .= '
'; $html .= '
'; } } $html .= '
'; $html .= '
'; $html .= '
'; $html .= ''; $html .= ''; $html .= '
'; $html .= '
'; $html .= '
'; $html .= '
'; return $html; } } }