Ticket #16357: garyc40.16356.2.diff

File garyc40.16356.2.diff, 9.0 KB (added by garyc40, 2 years ago)

centralize redirection in set_pagination_args()

Line 
1diff --git wp-admin/edit-comments.php wp-admin/edit-comments.php
2index 40ef4a4..d84e2f9 100644
3--- wp-admin/edit-comments.php
4+++ wp-admin/edit-comments.php
5@@ -101,12 +101,6 @@ if ( $doaction ) {
6 
7 $wp_list_table->prepare_items();
8 
9-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
10-if ( $pagenum > $total_pages && $total_pages > 0 ) {
11-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
12-       exit;
13-}
14-
15 wp_enqueue_script('admin-comments');
16 enqueue_comment_hotkeys_js();
17 
18diff --git wp-admin/edit-tags.php wp-admin/edit-tags.php
19index 13534de..d576b63 100644
20--- wp-admin/edit-tags.php
21+++ wp-admin/edit-tags.php
22@@ -148,10 +148,14 @@ case 'editedtag':
23 break;
24 
25 default:
26-
27 if ( ! empty($_REQUEST['_wp_http_referer']) ) {
28-        wp_redirect( remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) ) );
29-        exit;
30+       $location = remove_query_arg( array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI']) );
31+
32+       if ( ! empty( $_REQUEST['paged'] ) )
33+               $location = add_query_arg( 'paged', $_REQUEST['paged'] );
34+       
35+       wp_redirect( $location );
36+       exit;
37 }
38 
39 $wp_list_table->prepare_items();
40diff --git wp-admin/edit.php wp-admin/edit.php
41index 5c7b194..f55cb6e 100644
42--- wp-admin/edit.php
43+++ wp-admin/edit.php
44@@ -142,12 +142,6 @@ if ( 'post' != $post_type ) {
45 
46 $wp_list_table->prepare_items();
47 
48-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
49-if ( $pagenum > $total_pages && $total_pages > 0 ) {
50-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
51-       exit;
52-}
53-
54 wp_enqueue_script('inline-edit-post');
55 
56 $title = $post_type_object->labels->name;
57diff --git wp-admin/includes/class-wp-list-table.php wp-admin/includes/class-wp-list-table.php
58index e7ce9e5..c3b20c4 100644
59--- wp-admin/includes/class-wp-list-table.php
60+++ wp-admin/includes/class-wp-list-table.php
61@@ -138,7 +138,12 @@ class WP_List_Table {
62 
63                if ( !$args['total_pages'] && $args['per_page'] > 0 )
64                        $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
65-
66+               
67+               if( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
68+                       wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
69+                       exit;
70+               }
71+               
72                $this->_pagination_args = $args;
73        }
74 
75@@ -443,9 +448,6 @@ class WP_List_Table {
76        function get_pagenum() {
77                $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
78 
79-               if( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
80-                       $pagenum = $this->_pagination_args['total_pages'];
81-
82                return max( 1, $pagenum );
83        }
84 
85diff --git wp-admin/network/edit.php wp-admin/network/edit.php
86index 1e06e49..9d680b4 100644
87--- wp-admin/network/edit.php
88+++ wp-admin/network/edit.php
89@@ -427,7 +427,11 @@ switch ( $_GET['action'] ) {
90 
91                        wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
92                } else {
93-                       wp_redirect( network_admin_url( 'users.php' ) );
94+                       $location = network_admin_url( 'users.php' );
95+
96+                       if ( ! empty( $_REQUEST['paged'] ) )
97+                               $location = add_query_arg( 'paged', $_REQUEST['paged'], $location );
98+                       wp_redirect( $location );
99                }
100                exit();
101        break;
102diff --git wp-admin/network/sites.php wp-admin/network/sites.php
103index 8a77d63..45dd338 100644
104--- wp-admin/network/sites.php
105+++ wp-admin/network/sites.php
106@@ -17,7 +17,6 @@ if ( ! current_user_can( 'manage_sites' ) )
107        wp_die( __( 'You do not have permission to access this page.' ) );
108 
109 $wp_list_table = _get_list_table('WP_MS_Sites_List_Table');
110-$pagenum = $wp_list_table->get_pagenum();
111 
112 $title = __( 'Sites' );
113 $parent_file = 'sites.php';
114@@ -88,12 +87,6 @@ if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty(
115 
116 $wp_list_table->prepare_items();
117 
118-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
119-if ( $pagenum > $total_pages && $total_pages > 0 ) {
120-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
121-       exit;
122-}
123-
124 require_once( '../admin-header.php' );
125 ?>
126 
127diff --git wp-admin/network/themes.php wp-admin/network/themes.php
128index b802f74..f8545d3 100644
129--- wp-admin/network/themes.php
130+++ wp-admin/network/themes.php
131@@ -22,7 +22,6 @@ if ( !current_user_can('manage_network_themes') )
132        wp_die( __( 'You do not have sufficient permissions to manage network themes.' ) );
133 
134 $wp_list_table = _get_list_table('WP_MS_Themes_List_Table');
135-$pagenum = $wp_list_table->get_pagenum();
136 
137 $action = $wp_list_table->current_action();
138 
139@@ -171,12 +170,6 @@ if ( $action ) {
140 
141 $wp_list_table->prepare_items();
142 
143-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
144-if ( $pagenum > $total_pages && $total_pages > 0 ) {
145-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
146-       exit;
147-}
148-
149 add_thickbox();
150 
151 add_screen_option( 'per_page', array('label' => _x( 'Themes', 'themes per page (screen options)' )) );
152diff --git wp-admin/network/users.php wp-admin/network/users.php
153index eb59670..7e1f63c 100644
154--- wp-admin/network/users.php
155+++ wp-admin/network/users.php
156@@ -17,6 +17,7 @@ if ( ! current_user_can( 'manage_network_users' ) )
157        wp_die( __( 'You do not have permission to access this page.' ) );
158 
159 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
160+
161 $wp_list_table->prepare_items();
162 
163 $title = __( 'Users' );
164diff --git wp-admin/plugin-install.php wp-admin/plugin-install.php
165index 971ab68..0812750 100644
166--- wp-admin/plugin-install.php
167+++ wp-admin/plugin-install.php
168@@ -21,13 +21,8 @@ if ( is_multisite() && ! is_network_admin() ) {
169 }
170 
171 $wp_list_table = _get_list_table('WP_Plugin_Install_List_Table');
172-$pagenum = $wp_list_table->get_pagenum();
173+
174 $wp_list_table->prepare_items();
175-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
176-if ( $pagenum > $total_pages && $total_pages > 0 ) {
177-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
178-       exit;
179-}
180 
181 $title = __('Install Plugins');
182 $parent_file = 'plugins.php';
183diff --git wp-admin/plugins.php wp-admin/plugins.php
184index 0c36bbd..f423426 100644
185--- wp-admin/plugins.php
186+++ wp-admin/plugins.php
187@@ -20,7 +20,6 @@ if ( !current_user_can('activate_plugins') )
188        wp_die( __( 'You do not have sufficient permissions to manage plugins for this site.' ) );
189 
190 $wp_list_table = _get_list_table('WP_Plugins_List_Table');
191-$pagenum = $wp_list_table->get_pagenum();
192 
193 $action = $wp_list_table->current_action();
194 
195@@ -316,12 +315,6 @@ if ( $action ) {
196 
197 $wp_list_table->prepare_items();
198 
199-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
200-if ( $pagenum > $total_pages && $total_pages > 0 ) {
201-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
202-       exit;
203-}
204-
205 wp_enqueue_script('plugin-install');
206 add_thickbox();
207 
208diff --git wp-admin/theme-install.php wp-admin/theme-install.php
209index 263d9a9..d92b6ae 100644
210--- wp-admin/theme-install.php
211+++ wp-admin/theme-install.php
212@@ -21,13 +21,8 @@ if ( is_multisite() && ! is_network_admin() ) {
213 }
214 
215 $wp_list_table = _get_list_table('WP_Theme_Install_List_Table');
216-$pagenum = $wp_list_table->get_pagenum();
217+
218 $wp_list_table->prepare_items();
219-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
220-if ( $pagenum > $total_pages && $total_pages > 0 ) {
221-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
222-       exit;
223-}
224 
225 $title = __('Install Themes');
226 $parent_file = 'themes.php';
227diff --git wp-admin/upload.php wp-admin/upload.php
228index 6a1d9b4..2ca11ba 100644
229--- wp-admin/upload.php
230+++ wp-admin/upload.php
231@@ -13,7 +13,6 @@ if ( !current_user_can('upload_files') )
232        wp_die( __( 'You do not have permission to upload files.' ) );
233 
234 $wp_list_table = _get_list_table('WP_Media_List_Table');
235-$pagenum = $wp_list_table->get_pagenum();
236 
237 // Handle bulk actions
238 $doaction = $wp_list_table->current_action();
239@@ -130,12 +129,6 @@ if ( $doaction ) {
240 
241 $wp_list_table->prepare_items();
242 
243-$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
244-if ( $pagenum > $total_pages && $total_pages > 0 ) {
245-       wp_redirect( add_query_arg( 'paged', $total_pages ) );
246-       exit;
247-}
248-
249 $title = __('Media Library');
250 $parent_file = 'upload.php';
251 
252diff --git wp-includes/user.php wp-includes/user.php
253index e39d19e..2a1a101 100644
254--- wp-includes/user.php
255+++ wp-includes/user.php
256@@ -542,19 +542,19 @@ class WP_User_Query {
257         */
258        function query() {
259                global $wpdb;
260-
261+               
262                if ( is_array( $this->query_vars['fields'] ) || 'all' == $this->query_vars['fields'] ) {
263                        $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
264                } else {
265                        $this->results = $wpdb->get_col("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
266                }
267+               
268+               if ( $this->query_vars['count_total'] )
269+                       $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
270 
271                if ( !$this->results )
272                        return;
273 
274-               if ( $this->query_vars['count_total'] )
275-                       $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
276-
277                if ( 'all_with_meta' == $this->query_vars['fields'] ) {
278                        cache_users( $this->results );
279