WordPress.org

Make WordPress Core

Changeset 40297


Ignore:
Timestamp:
03/17/17 16:53:08 (9 months ago)
Author:
swissspidy
Message:

List Tables: Hide 'Empty Trash' and 'Empty Spam' buttons when view is already empty.

Props ivantedja, Presskopp, printsachen1, Jaydeep Rami, mathieuhays, cazm.
Fixes #38341.

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r39669 r40297  
    355355        } 
    356356 
    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() ) { 
    358358            wp_nonce_field( 'bulk-destroy', '_destroy_nonce' ); 
    359359            $title = ( 'spam' === $comment_status ) ? esc_attr__( 'Empty Spam' ) : esc_attr__( 'Empty Trash' ); 
  • trunk/src/wp-admin/includes/class-wp-media-list-table.php

    r39917 r40297  
    178178        } 
    179179 
    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() ) { 
    181181            submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); 
    182182        } ?> 
  • trunk/src/wp-admin/includes/class-wp-posts-list-table.php

    r39956 r40297  
    490490        } 
    491491 
    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() ) { 
    493493            submit_button( __( 'Empty Trash' ), 'apply', 'delete_all', false ); 
    494494        } 
  • trunk/src/wp-admin/js/edit-comments.js

    r37303 r40297  
    460460        if ( trashDiff ) { 
    461461            updateCountText( 'span.trash-count', trashDiff ); 
     462        } 
     463 
     464        if ( 
     465            ( ( 'trash' === settings.data.comment_status ) && !getCount( $( 'span.trash-count' ) ) ) || 
     466            ( ( 'spam' === settings.data.comment_status ) && !getCount( $( 'span.spam-count' ) ) ) 
     467        ) { 
     468            $( '#delete_all' ).hide(); 
    462469        } 
    463470 
  • trunk/tests/phpunit/tests/admin/includesListTable.php

    r39481 r40297  
    236236        $this->assertNotContains( 'id="cat"', $output ); 
    237237    } 
     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    } 
    238265} 
Note: See TracChangeset for help on using the changeset viewer.