Skip to content

Commit 2f2dbbf

Browse files
committed
General: Remove any usage of wp_reset_vars().
The way `wp_reset_vars()` sets global variables based on `$_POST` and `$_GET` values makes code hard to understand and maintain. It also makes it easy to forget to sanitize input. This change removes the few places where `wp_reset_vars()` is used in the admin to explicitly use `$_REQUEST` and sanitize any input. Props swissspidy, audrasjb, davideferre, killua99, weijland, voldemortensen. Fixes #38073. git-svn-id: https://develop.svn.wordpress.org/trunk@58069 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 816ff68 commit 2f2dbbf

22 files changed

Lines changed: 48 additions & 30 deletions

src/wp-admin/admin-post.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
/** This action is documented in wp-admin/admin.php */
3030
do_action( 'admin_init' );
3131

32-
$action = ! empty( $_REQUEST['action'] ) ? $_REQUEST['action'] : '';
32+
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
3333

3434
// Reject invalid parameters.
3535
if ( ! is_scalar( $action ) ) {

src/wp-admin/comment.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
* @global string $action
1717
*/
1818
global $action;
19-
wp_reset_vars( array( 'action' ) );
19+
20+
$action = ! empty( $_REQUEST['action'] ) ? sanitize_text_field( $_REQUEST['action'] ) : '';
2021

2122
if ( isset( $_POST['deletecomment'] ) ) {
2223
$action = 'deletecomment';

src/wp-admin/customize.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@
8484
}
8585
}
8686

87+
$url = ! empty( $_REQUEST['url'] ) ? sanitize_text_field( $_REQUEST['url'] ) : '';
88+
$return = ! empty( $_REQUEST['return'] ) ? sanitize_text_field( $_REQUEST['return'] ) : '';
89+
$autofocus = ! empty( $_REQUEST['autofocus'] ) ? sanitize_text_field( $_REQUEST['autofocus'] ) : '';
8790

88-
wp_reset_vars( array( 'url', 'return', 'autofocus' ) );
8991
if ( ! empty( $url ) ) {
9092
$wp_customize->set_preview_url( wp_unslash( $url ) );
9193
}

src/wp-admin/edit-tag-form.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@
4444
do_action_deprecated( 'edit_tag_form_pre', array( $tag ), '3.0.0', '{$taxonomy}_pre_edit_form' );
4545
}
4646

47-
/**
48-
* Use with caution, see https://developer.wordpress.org/reference/functions/wp_reset_vars/
49-
*/
50-
wp_reset_vars( array( 'wp_http_referer' ) );
51-
47+
$wp_http_referer = ! empty( $_REQUEST['wp_http_referer'] ) ? sanitize_text_field( $_REQUEST['wp_http_referer'] ) : '';
5248
$wp_http_referer = remove_query_arg( array( 'action', 'message', 'tag_ID' ), $wp_http_referer );
5349

5450
// Also used by Edit Tags.

src/wp-admin/includes/class-wp-links-list-table.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public function ajax_user_can() {
5050
public function prepare_items() {
5151
global $cat_id, $s, $orderby, $order;
5252

53-
wp_reset_vars( array( 'action', 'cat_id', 'link_id', 'orderby', 'order', 's' ) );
53+
$cat_id = ! empty( $_REQUEST['cat_id'] ) ? absint( $_REQUEST['cat_id'] ) : 0;
54+
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
55+
$order = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
56+
$s = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
5457

5558
$args = array(
5659
'hide_invisible' => 0,

src/wp-admin/includes/class-wp-ms-themes-list-table.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ public function ajax_user_can() {
9999
public function prepare_items() {
100100
global $status, $totals, $page, $orderby, $order, $s;
101101

102-
wp_reset_vars( array( 'orderby', 'order', 's' ) );
102+
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
103+
$order = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
104+
$s = ! empty( $_REQUEST['s'] ) ? sanitize_text_field( $_REQUEST['s'] ) : '';
103105

104106
$themes = array(
105107
/**

src/wp-admin/includes/class-wp-plugin-install-list-table.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function prepare_items() {
9292

9393
global $tabs, $tab, $paged, $type, $term;
9494

95-
wp_reset_vars( array( 'tab' ) );
95+
$tab = ! empty( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : '';
9696

9797
$paged = $this->get_pagenum();
9898

src/wp-admin/includes/class-wp-plugins-list-table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ public function ajax_user_can() {
9090
public function prepare_items() {
9191
global $status, $plugins, $totals, $page, $orderby, $order, $s;
9292

93-
wp_reset_vars( array( 'orderby', 'order' ) );
93+
$orderby = ! empty( $_REQUEST['orderby'] ) ? sanitize_text_field( $_REQUEST['orderby'] ) : '';
94+
$order = ! empty( $_REQUEST['order'] ) ? sanitize_text_field( $_REQUEST['order'] ) : '';
9495

9596
/**
9697
* Filters the full array of plugins to list in the Plugins list table.

src/wp-admin/includes/class-wp-theme-install-list-table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ public function prepare_items() {
3636
require ABSPATH . 'wp-admin/includes/theme-install.php';
3737

3838
global $tabs, $tab, $paged, $type, $theme_field_defaults;
39-
wp_reset_vars( array( 'tab' ) );
39+
40+
$tab = ! empty( $_REQUEST['tab'] ) ? sanitize_text_field( $_REQUEST['tab'] ) : '';
4041

4142
$search_terms = array();
4243
$search_string = '';

src/wp-admin/includes/misc.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,6 @@ function update_home_siteurl( $old_value, $value ) {
575575
}
576576
}
577577

578-
579578
/**
580579
* Resets global variables based on $_GET and $_POST.
581580
*

0 commit comments

Comments
 (0)