From 70e3fbe1e84fe9e003c00543a5391112fabad8fd Mon Sep 17 00:00:00 2001 From: scribu Date: Fri, 10 Dec 2010 08:49:16 +0000 Subject: [PATCH] Redirect to correct page after bulk action for posts and comments. Props garyc40. Fixes #15416 git-svn-id: https://develop.svn.wordpress.org/trunk@16855 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/edit-comments.php | 14 ++++++++++++++ wp-admin/edit.php | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/wp-admin/edit-comments.php b/wp-admin/edit-comments.php index 61d86333cf..ffe3cc1f55 100644 --- a/wp-admin/edit-comments.php +++ b/wp-admin/edit-comments.php @@ -13,6 +13,7 @@ if ( !current_user_can('edit_posts') ) $wp_list_table = get_list_table('WP_Comments_List_Table'); $wp_list_table->check_permissions(); +$pagenum = $wp_list_table->get_pagenum(); $doaction = $wp_list_table->current_action(); @@ -37,6 +38,11 @@ if ( $doaction ) { $approved = $unapproved = $spammed = $unspammed = $trashed = $untrashed = $deleted = 0; $redirect_to = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'spammed', 'unspammed', 'approved', 'unapproved', 'ids' ), wp_get_referer() ); + // Fix the problem with wrong page number. This happens when the user use the javascript + // pagination feature to navigate to a certain page, then does some bulk actions there, + // he will be redirected back to te original page number instead of the navigated one. + $redirect_to = add_query_arg( 'paged', $pagenum, $redirect_to ); + foreach ( $comment_ids as $comment_id ) { // Check the permissions on each if ( !current_user_can( 'edit_comment', $comment_id ) ) continue; @@ -99,6 +105,14 @@ if ( $doaction ) { $wp_list_table->prepare_items(); +// redirect to the last page if the page number is larger than the total number of pages +// this can happen when all the items in the last page are deleted, for example +$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); +if ( $pagenum > $total_pages && $total_pages > 0 ) { + wp_redirect( add_query_arg( 'paged', $total_pages ) ); + exit; +} + wp_enqueue_script('admin-comments'); enqueue_comment_hotkeys_js(); diff --git a/wp-admin/edit.php b/wp-admin/edit.php index 2228f65b5a..e202090589 100644 --- a/wp-admin/edit.php +++ b/wp-admin/edit.php @@ -10,6 +10,7 @@ require_once( './admin.php' ); $wp_list_table = get_list_table('WP_Posts_List_Table'); $wp_list_table->check_permissions(); +$pagenum = $wp_list_table->get_pagenum(); // Back-compat for viewing comments of an entry foreach ( array( 'p', 'attachment_id', 'page_id' ) as $_redirect ) { @@ -26,6 +27,11 @@ $doaction = $wp_list_table->current_action(); if ( $doaction ) { check_admin_referer('bulk-posts'); $sendback = remove_query_arg( array('trashed', 'untrashed', 'deleted', 'ids'), wp_get_referer() ); + + // Fix the problem with wrong page number. This happens when the user use the javascript + // pagination feature to navigate to a certain page, then does some bulk actions there, + // he will be redirected back to te original page number instead of the navigated one. + $sendback = add_query_arg( 'paged', $pagenum, $sendback ); if ( strpos($sendback, 'post.php') !== false ) $sendback = admin_url($post_new_file); @@ -60,7 +66,7 @@ if ( $doaction ) { $trashed++; } - $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids)), $sendback ); + $sendback = add_query_arg( array('trashed' => $trashed, 'ids' => join(',', $post_ids) ), $sendback ); break; case 'untrash': $untrashed = 0; @@ -127,6 +133,14 @@ if ( 'post' != $post_type ) { $wp_list_table->prepare_items(); +// redirect to the last page if the page number is larger than the total number of pages +// this can happen when all the items in the last page are deleted, for example +$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); +if ( $pagenum > $total_pages && $total_pages > 0 ) { + wp_redirect( add_query_arg( 'paged', $total_pages ) ); + exit; +} + wp_enqueue_script('inline-edit-post'); $title = $post_type_object->labels->name;