From 58ac7648592e3e8ee237b672c65761d94b6ee6ad Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Thu, 17 Sep 2015 02:30:26 +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. Built from https://develop.svn.wordpress.org/trunk@34256 git-svn-id: http://core.svn.wordpress.org/trunk@34220 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-media-list-table.php | 58 +++++++++++-------- wp-admin/upload.php | 2 + wp-includes/version.php | 2 +- 3 files changed, 37 insertions(+), 25 deletions(-) diff --git a/wp-admin/includes/class-wp-media-list-table.php b/wp-admin/includes/class-wp-media-list-table.php index 8482e3304e..4b34c4db0e 100644 --- a/wp-admin/includes/class-wp-media-list-table.php +++ b/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/wp-admin/upload.php b/wp-admin/upload.php index 7154148cdd..66ec318a43 100644 --- a/wp-admin/upload.php +++ b/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'] ); diff --git a/wp-includes/version.php b/wp-includes/version.php index e0725d8f86..ea23c84d11 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-34255'; +$wp_version = '4.4-alpha-34256'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.