From a1805ecada520fcd0daece57b8fd31920ffd8c56 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 17 Sep 2015 02:29:22 +0000 Subject: [PATCH] Media List Table: remove the counts from the "views" portion of the toolbar, which are inconsistent with grid view. Also reduces complexity and removes potentially expensive count query. Related to the toolbar view, remove the `wp_admin_canonical_url()` action in grid mode. Grid views that result from links from the list table view are lenses into the library and need to be indicated as such vs being a full attachment query. Fixes #29744. git-svn-id: https://develop.svn.wordpress.org/trunk@34256 602fd350-edb4-49c9-b593-d223f7449a82 --- .../includes/class-wp-media-list-table.php | 58 +++++++++++-------- src/wp-admin/upload.php | 2 + 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/wp-admin/includes/class-wp-media-list-table.php b/src/wp-admin/includes/class-wp-media-list-table.php index 8482e3304e..4b34c4db0e 100644 --- a/src/wp-admin/includes/class-wp-media-list-table.php +++ b/src/wp-admin/includes/class-wp-media-list-table.php @@ -84,36 +84,46 @@ class WP_Media_List_Table extends WP_List_Table { * @return array */ protected function get_views() { - global $wpdb, $post_mime_types, $avail_post_mime_types; + global $post_mime_types, $avail_post_mime_types; $type_links = array(); - $_num_posts = (array) wp_count_attachments(); - $_total_posts = array_sum($_num_posts) - $_num_posts['trash']; - $total_orphans = $wpdb->get_var( "SELECT COUNT( * ) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent < 1" ); - $matches = wp_match_mime_types(array_keys($post_mime_types), 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"' : ''; - $type_links['all'] = "'; + + $filter = empty( $_GET['attachment-filter'] ) ? '' : $_GET['attachment-filter']; + + $type_links['all'] = sprintf( + '', + selected( $filter, true, false ), + __( 'All media items' ) + ); + foreach ( $post_mime_types as $mime_type => $label ) { - if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) + 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] = ''; + $selected = selected( + $filter && 0 === strpos( $filter, 'post_mime_type:' ) && + wp_match_mime_types( $mime_type, str_replace( 'post_mime_type:', '', $filter ) ), + true, + false + ); + + $type_links[$mime_type] = sprintf( + '', + esc_attr( $mime_type ), + $selected, + $label[0] + ); } - $type_links['detached'] = ''; - - if ( !empty($_num_posts['trash']) ) - $type_links['trash'] = ''; + $type_links['detached'] = ''; + if ( $this->is_trash ) { + $type_links['trash'] = sprintf( + '', + selected( 'trash' === $filter, true, false ), + __( 'Trash' ) + ); + } return $type_links; } @@ -372,7 +382,7 @@ class WP_Media_List_Table extends WP_List_Table {

- ID ); echo wp_basename( $file ); ?> diff --git a/src/wp-admin/upload.php b/src/wp-admin/upload.php index 7154148cdd..66ec318a43 100644 --- a/src/wp-admin/upload.php +++ b/src/wp-admin/upload.php @@ -25,6 +25,8 @@ if ( 'grid' === $mode ) { wp_enqueue_script( 'media-grid' ); wp_enqueue_script( 'media' ); + remove_action( 'admin_head', 'wp_admin_canonical_url' ); + $q = $_GET; // let JS handle this unset( $q['s'] );