From 46c336e78a6d96f4b1517b42f5109e724e45033b Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Wed, 2 Sep 2015 11:28:11 +0000 Subject: [PATCH] Introduce `wp_removable_query_args()`, which returns an array of single-use query variables which can be removed from a URL. Also applies the function to the return URL when the Customizer is closed. Fixes #32692 Props swissspidy, Mte90 git-svn-id: https://develop.svn.wordpress.org/trunk@33849 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/customize.php | 1 + src/wp-admin/includes/misc.php | 19 +--------------- src/wp-includes/functions.php | 41 ++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/src/wp-admin/customize.php b/src/wp-admin/customize.php index 6ee2de007a..bfc96233eb 100644 --- a/src/wp-admin/customize.php +++ b/src/wp-admin/customize.php @@ -21,6 +21,7 @@ $url = wp_unslash( $url ); $url = wp_validate_redirect( $url, home_url( '/' ) ); if ( $return ) { $return = wp_unslash( $return ); + $return = remove_query_arg( wp_removable_query_args(), $return ); $return = wp_validate_redirect( $return ); } if ( ! $return ) { diff --git a/src/wp-admin/includes/misc.php b/src/wp-admin/includes/misc.php index 83e7548175..d65d22b2d7 100644 --- a/src/wp-admin/includes/misc.php +++ b/src/wp-admin/includes/misc.php @@ -865,24 +865,7 @@ function post_form_autocomplete_off() { * @since 4.2.0 */ function wp_admin_canonical_url() { - $removable_query_args = array( - 'message', 'settings-updated', 'saved', - 'update', 'updated', 'activated', - 'activate', 'deactivate', 'locked', - 'deleted', 'trashed', 'untrashed', - 'enabled', 'disabled', 'skipped', - 'spammed', 'unspammed', - 'error', - ); - - /** - * Filter the list of URL parameters to remove. - * - * @since 4.2.0 - * - * @param array $removable_query_args An array of parameters to remove from the URL. - */ - $removable_query_args = apply_filters( 'removable_query_args', $removable_query_args ); + $removable_query_args = wp_removable_query_args(); if ( empty( $removable_query_args ) ) { return; diff --git a/src/wp-includes/functions.php b/src/wp-includes/functions.php index 006cb6cb7e..9206f9bffd 100644 --- a/src/wp-includes/functions.php +++ b/src/wp-includes/functions.php @@ -824,6 +824,47 @@ function remove_query_arg( $key, $query = false ) { return add_query_arg( $key, false, $query ); } +/** + * Returns an array of single-use query variable names that can be removed from a URL. + * + * @since 4.4.0 + * + * @return array An array of parameters to remove from the URL. + */ +function wp_removable_query_args() { + $removable_query_args = array( + 'activate', + 'activated', + 'approved', + 'deactivate', + 'deleted', + 'disabled', + 'enabled', + 'error', + 'locked', + 'message', + 'same', + 'saved', + 'settings-updated', + 'skipped', + 'spammed', + 'trashed', + 'unspammed', + 'untrashed', + 'update', + 'updated', + ); + + /** + * Filter the list of query variables to remove. + * + * @since 4.2.0 + * + * @param array $removable_query_args An array of query variables to remove from a URL. + */ + return apply_filters( 'removable_query_args', $removable_query_args ); +} + /** * Walks the array while sanitizing the contents. *