From d512973c842d8ed93f82bf973d42028d0f6ffff8 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sun, 4 Feb 2018 16:04:10 +0000 Subject: [PATCH] Canonical: Add `$x_redirect_by` parameter to `wp_safe_redirect()`. See [42633] and [42408]. Fixes #42313. git-svn-id: https://develop.svn.wordpress.org/trunk@42647 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 14 ++++++++------ tests/phpunit/tests/pluggable.php | 3 ++- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index da53ee3d25..cf480d081f 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1186,6 +1186,7 @@ if ( ! function_exists( 'wp_redirect' ) ) : * } * * @since 1.5.1 + * @since 5.0.0 The `$x_redirect_by` parameter was added. * * @global bool $is_IIS * @@ -1323,13 +1324,14 @@ if ( ! function_exists( 'wp_safe_redirect' ) ) : * } * * @since 2.3.0 - * @since 5.0.0 The return value from wp_redirect() is now passed on. + * @since 5.0.0 The return value from wp_redirect() is now passed on, and the `$x_redirect_by` parameter was added. * - * @param string $location The path or URL to redirect to. - * @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily). - * @return bool $redirect False if the redirect was cancelled, true otherwise. + * @param string $location The path or URL to redirect to. + * @param int $status Optional. HTTP response status code to use. Default '302' (Moved Temporarily). + * @param string $x_redirect_by Optional. The application doing the redirect. Default 'WordPress'. + * @return bool $redirect False if the redirect was cancelled, true otherwise. */ - function wp_safe_redirect( $location, $status = 302 ) { + function wp_safe_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) { // Need to look at the URL the way it will end up in wp_redirect() $location = wp_sanitize_redirect( $location ); @@ -1344,7 +1346,7 @@ if ( ! function_exists( 'wp_safe_redirect' ) ) : */ $location = wp_validate_redirect( $location, apply_filters( 'wp_safe_redirect_fallback', admin_url(), $status ) ); - return wp_redirect( $location, $status ); + return wp_redirect( $location, $status, $x_redirect_by ); } endif; diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index 73b7aecea9..bc2c02e039 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -183,7 +183,8 @@ class Tests_Pluggable extends WP_UnitTestCase { '_wp_sanitize_utf8_in_redirect' => array( 'matches' ), 'wp_safe_redirect' => array( 'location', - 'status' => 302, + 'status' => 302, + 'x_redirect_by' => 'WordPress', ), 'wp_validate_redirect' => array( 'location',