From b345e996c76e70bfba266ba09d273f2afa950b9f Mon Sep 17 00:00:00 2001 From: ryan Date: Tue, 25 Jan 2011 19:20:20 +0000 Subject: [PATCH] Pagination fixes. Props garyc40. fixes #16357 git-svn-id: http://svn.automattic.com/wordpress/trunk@17361 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-tags.php | 17 ++++++++++++++--- wp-admin/network/edit.php | 6 +++++- wp-admin/network/users.php | 6 ++++++ wp-admin/users.php | 8 ++++++-- wp-includes/user.php | 8 ++++---- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/wp-admin/edit-tags.php b/wp-admin/edit-tags.php index 13534de06..613855fed 100644 --- a/wp-admin/edit-tags.php +++ b/wp-admin/edit-tags.php @@ -13,6 +13,7 @@ if ( !current_user_can( $tax->cap->manage_terms ) ) wp_die( __( 'Cheatin’ uh?' ) ); $wp_list_table = _get_list_table('WP_Terms_List_Table'); +$pagenum = $wp_list_table->get_pagenum(); $title = $tax->labels->name; @@ -148,13 +149,23 @@ case 'editedtag': break; default: - if ( ! empty($_REQUEST['_wp_http_referer']) ) { - wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) ); - exit; + $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ); + + if ( ! empty( $_REQUEST['paged'] ) ) + $location = add_query_arg( 'paged', (int) $_REQUEST['paged'] ); + + wp_redirect( $location ); + exit; } $wp_list_table->prepare_items(); +$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); + +if ( $pagenum > $total_pages ) { + wp_redirect( add_query_arg( 'paged', $total_pages ) ); + exit; +} wp_enqueue_script('admin-tags'); if ( current_user_can($tax->cap->edit_terms) ) diff --git a/wp-admin/network/edit.php b/wp-admin/network/edit.php index 5d81e7795..2d3f95226 100644 --- a/wp-admin/network/edit.php +++ b/wp-admin/network/edit.php @@ -427,7 +427,11 @@ switch ( $_GET['action'] ) { wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) ); } else { - wp_redirect( network_admin_url( 'users.php' ) ); + $location = network_admin_url( 'users.php' ); + + if ( ! empty( $_REQUEST['paged'] ) ) + $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); + wp_redirect( $location ); } exit(); break; diff --git a/wp-admin/network/users.php b/wp-admin/network/users.php index eb596704a..c87bfd35f 100644 --- a/wp-admin/network/users.php +++ b/wp-admin/network/users.php @@ -17,8 +17,14 @@ if ( ! current_user_can( 'manage_network_users' ) ) wp_die( __( 'You do not have permission to access this page.' ) ); $wp_list_table = _get_list_table('WP_MS_Users_List_Table'); +$pagenum = $wp_list_table->get_pagenum(); $wp_list_table->prepare_items(); +$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); +if ( $pagenum > $total_pages ) { + wp_redirect( add_query_arg( 'paged', $total_pages ) ); + exit; +} $title = __( 'Users' ); $parent_file = 'users.php'; diff --git a/wp-admin/users.php b/wp-admin/users.php index 8f082119f..78d9ad842 100644 --- a/wp-admin/users.php +++ b/wp-admin/users.php @@ -13,7 +13,7 @@ if ( ! current_user_can( 'list_users' ) ) wp_die( __( 'Cheatin’ uh?' ) ); $wp_list_table = _get_list_table('WP_Users_List_Table'); - +$pagenum = $wp_list_table->get_pagenum(); $title = __('Users'); $parent_file = 'users.php'; @@ -290,7 +290,11 @@ default: } $wp_list_table->prepare_items(); - + $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); + if ( $pagenum > $total_pages ) { + wp_redirect( add_query_arg( 'paged', $total_pages ) ); + exit; + } include('./admin-header.php'); $messages = array(); diff --git a/wp-includes/user.php b/wp-includes/user.php index e39d19e3e..2a1a10136 100644 --- a/wp-includes/user.php +++ b/wp-includes/user.php @@ -542,19 +542,19 @@ class WP_User_Query { */ function query() { global $wpdb; - + if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) { $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } else { $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"); } + + if ( $this->query_vars['count_total'] ) + $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where"); if ( !$this->results ) return; - if ( $this->query_vars['count_total'] ) - $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where"); - if ( 'all_with_meta' == $this->query_vars['fields'] ) { cache_users( $this->results );