/** WP_Media_List_Table does not provide a filter for managing get_views() so,
  *  so we have done the next best thing.  Override
  *
  * @global wpdb  $wpdb
  * @global array $post_mime_types
  * @global array $avail_post_mime_types
  * @return array
  */
 public function get_views()
 {
     global $wpdb, $cb_post_id, $post_mime_types, $avail_post_mime_types;
     $type_links = array();
     // $_num_posts = (array) wp_count_attachments();
     $_num_posts = (array) clearbase_count_attachments($cb_post_id);
     //$_total_posts = array_sum($_num_posts) - $_num_posts['trash'];
     $media_filter = clearbase_get_value('media_filter', '', clearbase_get_folder_settings($cb_post_id));
     if (empty($media_filter)) {
         $media_filter = array_keys($post_mime_types);
     }
     $matches = wp_match_mime_types($media_filter, array_keys($_num_posts));
     $num_posts = array();
     foreach ($matches as $type => $reals) {
         foreach ($reals as $real) {
             $num_posts[$type] = isset($num_posts[$type]) ? $num_posts[$type] + $_num_posts[$real] : $_num_posts[$real];
         }
     }
     $selected = empty($_GET['attachment-filter']) ? ' selected="selected"' : '';
     if (count($num_posts) > 1) {
         $_total_posts = array_sum($num_posts) - $_num_posts['trash'];
         $type_links['all'] = "<option value=''{$selected}>" . sprintf(_nx('All (%s)', 'All (%s)', $_total_posts, 'uploaded files'), number_format_i18n($_total_posts)) . '</option>';
     }
     foreach ($post_mime_types as $mime_type => $label) {
         if (!wp_match_mime_types($mime_type, $avail_post_mime_types)) {
             continue;
         }
         $selected = '';
         if (!empty($_GET['attachment-filter']) && strpos($_GET['attachment-filter'], 'post_mime_type:') === 0 && wp_match_mime_types($mime_type, str_replace('post_mime_type:', '', $_GET['attachment-filter']))) {
             $selected = ' selected="selected"';
         }
         if (!empty($num_posts[$mime_type])) {
             $type_links[$mime_type] = '<option value="post_mime_type:' . esc_attr($mime_type) . '"' . $selected . '>' . sprintf(translate_nooped_plural($label[2], $num_posts[$mime_type]), number_format_i18n($num_posts[$mime_type])) . '</option>';
         }
     }
     // $type_links['detached'] = '<option value="detached"' . ( $this->detached ? ' selected="selected"' : '' ) . '>' . sprintf( _nx( 'Unattached (%s)', 'Unattached (%s)', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '</option>';
     if (!empty($_num_posts['trash'])) {
         $type_links['trash'] = '<option value="trash"' . (isset($_GET['attachment-filter']) && $_GET['attachment-filter'] == 'trash' ? ' selected="selected"' : '') . '>' . sprintf(_nx('Trash (%s)', 'Trash (%s)', $_num_posts['trash'], 'uploaded files'), number_format_i18n($_num_posts['trash'])) . '</option>';
     }
     return $type_links;
 }
 public function _media_view_settings($settings = array(), $post = null)
 {
     $media_filter = clearbase_get_value('media_filter', '', clearbase_get_folder_settings($cb_post_id));
     if (!empty($media_filter)) {
         $post_mime_types = get_post_mime_types();
         $matches = wp_match_mime_types($media_filter, array_keys($post_mime_types));
         $settings['mimeTypes'] = wp_list_pluck(array_intersect_key($post_mime_types, $matches), 0);
         global $wpdb, $wp_locale;
         $post_parent = absint($post->ID);
         $and_where_mime = wp_post_mime_type_where($media_filter);
         $months = $wpdb->get_results("\n              SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month\n              FROM {$wpdb->posts}\n              WHERE post_parent = {$post_parent} AND post_type = 'attachment' {$and_where_mime}\n              ORDER BY post_date DESC");
         foreach ($months as $month_year) {
             $month_year->text = sprintf(__('%1$s %2$d'), $wp_locale->get_month($month_year->month), $month_year->year);
         }
         $settings['months'] = $months;
     }
     return $settings;
 }