From 927ad00bab32e03ad9945474959a71e559635bd9 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 12 Sep 2015 08:12:43 +0000 Subject: [PATCH] List Tables: don't render "extra tablenav" if there are no posts. This includes Bulk Actions, Dates Dropdown, Category Dropdowns, Pagination. Also ensure that the Months dropdown, when it is shown, shows months from the proper set of posts. Props egower, CoenJacobs, MikeHansenMe, mehulkaklotar. Fixes #33824, #21015, #21856. git-svn-id: https://develop.svn.wordpress.org/trunk@34076 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-list-table.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-list-table.php b/src/wp-admin/includes/class-wp-list-table.php index 8015e628cd..850aab94e4 100644 --- a/src/wp-admin/includes/class-wp-list-table.php +++ b/src/wp-admin/includes/class-wp-list-table.php @@ -528,10 +528,22 @@ class WP_List_Table { return; } + $extra_checks = "AND post_status != 'auto-draft'"; + if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) { + $extra_checks .= " AND post_status != 'trash'"; + } elseif ( isset( $_GET['post_status'] ) ) { + $stati = explode( ',', $_GET['post_status'] ); + $extra_checks = ''; + foreach ( $stati as $status ) { + $extra_checks .= $wpdb->prepare( ' AND post_status = %s', $status ); + } + } + $months = $wpdb->get_results( $wpdb->prepare( " SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month FROM $wpdb->posts WHERE post_type = %s + $extra_checks ORDER BY post_date DESC ", $post_type ) ); @@ -1118,7 +1130,8 @@ class WP_List_Table { protected function display_tablenav( $which ) { if ( 'top' == $which ) wp_nonce_field( 'bulk-' . $this->_args['plural'] ); -?> + + if ( $this->has_items() ) : ?>
@@ -1132,6 +1145,7 @@ class WP_List_Table {