WordPress.org

Make WordPress Core

Changeset 16855


Ignore:
Timestamp:
12/10/2010 08:49:16 AM (9 years ago)
Author:
scribu
Message:

Redirect to correct page after bulk action for posts and comments. Props garyc40. Fixes #15416

Location:
trunk/wp-admin
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-comments.php

    r16619 r16855  
    1414$wp_list_table = get_list_table('WP_Comments_List_Table');
    1515$wp_list_table->check_permissions();
     16$pagenum = $wp_list_table->get_pagenum();
    1617
    1718$doaction = $wp_list_table->current_action();
     
    3738    $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0;
    3839    $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() );
     40
     41    // Fix the problem with wrong page number. This happens when the user use the javascript
     42    // pagination feature to navigate to a certain page, then does some bulk actions there,
     43    // he will be redirected back to te original page number instead of the navigated one.
     44    $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to );
    3945
    4046    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
     
    100106$wp_list_table->prepare_items();
    101107
     108// redirect to the last page if the page number is larger than the total number of pages
     109// this can happen when all the items in the last page are deleted, for example
     110$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
     111if ( $pagenum > $total_pages && $total_pages > 0 ) {
     112    wp_redirect( add_query_arg( 'paged', $total_pages ) );
     113    exit;
     114}
     115
    102116wp_enqueue_script('admin-comments');
    103117enqueue_comment_hotkeys_js();
  • trunk/wp-admin/edit.php

    r16779 r16855  
    1111$wp_list_table = get_list_table('WP_Posts_List_Table');
    1212$wp_list_table->check_permissions();
     13$pagenum = $wp_list_table->get_pagenum();
    1314
    1415// Back-compat for viewing comments of an entry
     
    2728    check_admin_referer('bulk-posts');
    2829    $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() );
     30   
     31    // Fix the problem with wrong page number. This happens when the user use the javascript
     32    // pagination feature to navigate to a certain page, then does some bulk actions there,
     33    // he will be redirected back to te original page number instead of the navigated one.
     34    $sendback = add_query_arg( 'paged', $pagenum, $sendback );
    2935
    3036    if ( strpos($sendback, 'post.php') !== false )
     
    6167                $trashed++;
    6268            }
    63             $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback );
     69            $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback );
    6470            break;
    6571        case 'untrash':
     
    127133
    128134$wp_list_table->prepare_items();
     135
     136// redirect to the last page if the page number is larger than the total number of pages
     137// this can happen when all the items in the last page are deleted, for example
     138$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
     139if ( $pagenum > $total_pages && $total_pages > 0 ) {
     140    wp_redirect( add_query_arg( 'paged', $total_pages ) );
     141    exit;
     142}
    129143
    130144wp_enqueue_script('inline-edit-post');
Note: See TracChangeset for help on using the changeset viewer.