diff --git src/wp-admin/includes/class-wp-comments-list-table.php src/wp-admin/includes/class-wp-comments-list-table.php
index 8f53ae4be7..fa41a7203c 100644
|
|
class WP_Comments_List_Table extends WP_List_Table { |
354 | 354 | submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
355 | 355 | } |
356 | 356 | |
357 | | if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) ) { |
| 357 | if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $this->has_items() ) { |
358 | 358 | wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); |
359 | 359 | $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); |
360 | 360 | submit_button( $title, 'apply', 'delete_all', false ); |
diff --git src/wp-admin/includes/class-wp-media-list-table.php src/wp-admin/includes/class-wp-media-list-table.php
index 97b166e59c..805f4017d3 100644
|
|
class WP_Media_List_Table extends WP_List_Table { |
177 | 177 | submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
178 | 178 | } |
179 | 179 | |
180 | | if ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { |
| 180 | if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) { |
181 | 181 | submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
182 | 182 | } ?> |
183 | 183 | </div> |
diff --git src/wp-admin/includes/class-wp-posts-list-table.php src/wp-admin/includes/class-wp-posts-list-table.php
index 668c3d20a4..535a2dd0c8 100644
|
|
class WP_Posts_List_Table extends WP_List_Table { |
489 | 489 | } |
490 | 490 | } |
491 | 491 | |
492 | | if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) { |
| 492 | if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) { |
493 | 493 | submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
494 | 494 | } |
495 | 495 | ?> |
diff --git src/wp-admin/js/edit-comments.js src/wp-admin/js/edit-comments.js
index 3de031022c..491d61e015 100644
|
|
setCommentsList = function() { |
461 | 461 | updateCountText( 'span.trash-count', trashDiff ); |
462 | 462 | } |
463 | 463 | |
| 464 | if ( ( 'trash' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.trash-count' ) ) ) { |
| 465 | $( '#delete_all' ).hide(); |
| 466 | } |
| 467 | |
| 468 | if ( ( 'spam' === settings.data.comment_status ) && ( 0 === getCount( $( 'span.spam-count' ) ) ) { |
| 469 | $( '#delete_all' ).hide(); |
| 470 | } |
| 471 | |
464 | 472 | if ( ! isDashboard ) { |
465 | 473 | total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
466 | 474 | if ( $(settings.target).parent().is('span.undo') ) |
diff --git tests/phpunit/tests/admin/includesListTable.php tests/phpunit/tests/admin/includesListTable.php
index b0be74f28c..cf40457cdf 100644
|
|
class Tests_Admin_includesListTable extends WP_UnitTestCase { |
235 | 235 | |
236 | 236 | $this->assertNotContains( 'id="cat"', $output ); |
237 | 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @ticket 38341 |
| 241 | */ |
| 242 | public function test_empty_trash_button_should_not_be_shown_if_there_are_no_posts() { |
| 243 | // Set post type to a non-existent one. |
| 244 | $this->table->screen->post_type = 'foo'; |
| 245 | |
| 246 | ob_start(); |
| 247 | $this->table->extra_tablenav( 'top' ); |
| 248 | $output = ob_get_clean(); |
| 249 | |
| 250 | $this->assertNotContains( 'id="delete_all"', $output ); |
| 251 | } |
| 252 | |
| 253 | /** |
| 254 | * @ticket 38341 |
| 255 | */ |
| 256 | public function test_empty_trash_button_should_not_be_shown_if_there_are_no_comments() { |
| 257 | $table = _get_list_table( 'WP_Comments_List_Table', array( 'screen' => 'edit-comments' ) ); |
| 258 | |
| 259 | ob_start(); |
| 260 | $table->extra_tablenav( 'top' ); |
| 261 | $output = ob_get_clean(); |
| 262 | |
| 263 | $this->assertNotContains( 'id="delete_all"', $output ); |
| 264 | } |
238 | 265 | } |