diff --git a/plugins/woocommerce/changelog/add-38832 b/plugins/woocommerce/changelog/add-38832 new file mode 100644 index 00000000000..ecc8e35a574 --- /dev/null +++ b/plugins/woocommerce/changelog/add-38832 @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Perform feature flag change and redirection in the same request and remove feature related query args after enabling/disabling it diff --git a/plugins/woocommerce/src/Internal/Features/FeaturesController.php b/plugins/woocommerce/src/Internal/Features/FeaturesController.php index c8b9c7b03a9..4418536b466 100644 --- a/plugins/woocommerce/src/Internal/Features/FeaturesController.php +++ b/plugins/woocommerce/src/Internal/Features/FeaturesController.php @@ -1152,8 +1152,9 @@ class FeaturesController { $query_params_to_remove[] = $feature_id; } } - if ( count( $query_params_to_remove ) > 1 ) { - wp_safe_redirect( remove_query_arg( $query_params_to_remove, wp_get_referer() ) ); + if ( count( $query_params_to_remove ) > 1 && isset( $_SERVER['REQUEST_URI'] ) ) { + // phpcs:disable WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized + wp_safe_redirect( remove_query_arg( $query_params_to_remove, $_SERVER['REQUEST_URI'] ) ); } } }