| 1 | Index: src/wp-admin/includes/class-wp-comments-list-table.php |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- src/wp-admin/includes/class-wp-comments-list-table.php (revision 40293) |
|---|
| 4 | +++ src/wp-admin/includes/class-wp-comments-list-table.php (working copy) |
|---|
| 5 | @@ -354,7 +354,7 @@ |
|---|
| 6 | submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
|---|
| 7 | } |
|---|
| 8 | |
|---|
| 9 | - if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) ) { |
|---|
| 10 | + if ( ( 'spam' === $comment_status || 'trash' === $comment_status ) && current_user_can( 'moderate_comments' ) && $this->has_items() ) { |
|---|
| 11 | wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); |
|---|
| 12 | $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); |
|---|
| 13 | submit_button( $title, 'apply', 'delete_all', false ); |
|---|
| 14 | Index: src/wp-admin/includes/class-wp-media-list-table.php |
|---|
| 15 | =================================================================== |
|---|
| 16 | --- src/wp-admin/includes/class-wp-media-list-table.php (revision 40293) |
|---|
| 17 | +++ src/wp-admin/includes/class-wp-media-list-table.php (working copy) |
|---|
| 18 | @@ -177,7 +177,7 @@ |
|---|
| 19 | submit_button( __( 'Filter' ), '', 'filter_action', false, array( 'id' => 'post-query-submit' ) ); |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | - if ( $this->is_trash && current_user_can( 'edit_others_posts' ) ) { |
|---|
| 23 | + if ( $this->is_trash && current_user_can( 'edit_others_posts' ) && $this->has_items() ) { |
|---|
| 24 | submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
|---|
| 25 | } ?> |
|---|
| 26 | </div> |
|---|
| 27 | Index: src/wp-admin/includes/class-wp-posts-list-table.php |
|---|
| 28 | =================================================================== |
|---|
| 29 | --- src/wp-admin/includes/class-wp-posts-list-table.php (revision 40293) |
|---|
| 30 | +++ src/wp-admin/includes/class-wp-posts-list-table.php (working copy) |
|---|
| 31 | @@ -489,7 +489,7 @@ |
|---|
| 32 | } |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | - if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) ) { |
|---|
| 36 | + if ( $this->is_trash && current_user_can( get_post_type_object( $this->screen->post_type )->cap->edit_others_posts ) && $this->has_items() ) { |
|---|
| 37 | submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); |
|---|
| 38 | } |
|---|
| 39 | ?> |
|---|
| 40 | Index: src/wp-admin/js/edit-comments.js |
|---|
| 41 | =================================================================== |
|---|
| 42 | --- src/wp-admin/js/edit-comments.js (revision 40293) |
|---|
| 43 | +++ src/wp-admin/js/edit-comments.js (working copy) |
|---|
| 44 | @@ -461,6 +461,10 @@ |
|---|
| 45 | updateCountText( 'span.trash-count', trashDiff ); |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | +
if ( 0 === getCount( $( 'span.trash-count' ) ) ) {
|
|---|
| 49 | + $( '#delete_all' ).hide(); |
|---|
| 50 | +
} |
|---|
| 51 | + |
|---|
| 52 | if ( ! isDashboard ) { |
|---|
| 53 | total = totalInput.val() ? parseInt( totalInput.val(), 10 ) : 0; |
|---|
| 54 | if ( $(settings.target).parent().is('span.undo') ) |
|---|
| 55 | Index: tests/phpunit/tests/admin/includesListTable.php |
|---|
| 56 | =================================================================== |
|---|
| 57 | --- tests/phpunit/tests/admin/includesListTable.php (revision 40293) |
|---|
| 58 | +++ tests/phpunit/tests/admin/includesListTable.php (working copy) |
|---|
| 59 | @@ -235,4 +235,18 @@ |
|---|
| 60 | |
|---|
| 61 | $this->assertNotContains( 'id="cat"', $output ); |
|---|
| 62 | } |
|---|
| 63 | + |
|---|
| 64 | + /** |
|---|
| 65 | + * @ticket 38341 |
|---|
| 66 | + */ |
|---|
| 67 | + function test_empty_trash_button_should_not_be_shown_if_there_are_no_posts() { |
|---|
| 68 | + // Set post type to a non-existent one. |
|---|
| 69 | + $this->table->screen->post_type = 'foo'; |
|---|
| 70 | + |
|---|
| 71 | + ob_start(); |
|---|
| 72 | + $this->table->extra_tablenav( 'top' ); |
|---|
| 73 | + $output = ob_get_clean(); |
|---|
| 74 | + |
|---|
| 75 | + $this->assertNotContains( 'id="delete_all"', $output ); |
|---|
| 76 | + } |
|---|
| 77 | } |
|---|