From 40f76ae917c57c574403f02645a7d40d30675aea Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Thu, 1 Feb 2018 15:05:50 +0000 Subject: [PATCH] Canonical: Add `$x_redirect_by` parameter to `wp_redirect()` that allows applications doing the redirect to identify themselves. This complements the `x_redirect_by` filter added in [42408]. Props NathanAtmoz, johnbillion. Fixes #42313. git-svn-id: https://develop.svn.wordpress.org/trunk@42633 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 9 +++++---- tests/phpunit/tests/pluggable.php | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 9af88a6ea2..da53ee3d25 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1189,11 +1189,12 @@ if ( ! function_exists( 'wp_redirect' ) ) : * * @global bool $is_IIS * - * @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 $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 False if the redirect was cancelled, true otherwise. */ - function wp_redirect( $location, $status = 302 ) { + function wp_redirect( $location, $status = 302, $x_redirect_by = 'WordPress' ) { global $is_IIS; /** @@ -1237,7 +1238,7 @@ if ( ! function_exists( 'wp_redirect' ) ) : * @param int $status Status code to use. * @param string $location The path to redirect to. */ - $x_redirect_by = apply_filters( 'x_redirect_by', 'WordPress', $status, $location ); + $x_redirect_by = apply_filters( 'x_redirect_by', $x_redirect_by, $status, $location ); if ( is_string( $x_redirect_by ) ) { header( "X-Redirect-By: $x_redirect_by" ); } diff --git a/tests/phpunit/tests/pluggable.php b/tests/phpunit/tests/pluggable.php index 9cbb2905c2..73b7aecea9 100644 --- a/tests/phpunit/tests/pluggable.php +++ b/tests/phpunit/tests/pluggable.php @@ -176,7 +176,8 @@ class Tests_Pluggable extends WP_UnitTestCase { ), 'wp_redirect' => array( 'location', - 'status' => 302, + 'status' => 302, + 'x_redirect_by' => 'WordPress', ), 'wp_sanitize_redirect' => array( 'location' ), '_wp_sanitize_utf8_in_redirect' => array( 'matches' ),