| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Helpers; |
| 4 |
|
| 5 |
/** |
| 6 |
* A helper object for redirects. |
| 7 |
*/ |
| 8 |
class Redirect_Helper { |
| 9 |
|
| 10 |
/** |
| 11 |
* Wraps wp_redirect to allow testing for redirects. |
| 12 |
* |
| 13 |
* @codeCoverageIgnore It only wraps a WordPress function. |
| 14 |
* |
| 15 |
* @param string $location The path to redirect to. |
| 16 |
* @param int $status The status code to use. |
| 17 |
*/ |
| 18 |
public function do_unsafe_redirect( $location, $status = 302 ) { |
| 19 |
// phpcs:ignore WordPress.Security.SafeRedirect -- intentional, function has been renamed to make unsafe more clear. |
| 20 |
\wp_redirect( $location, $status, 'Yoast SEO' ); |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
/** |
| 25 |
* Wraps wp_safe_redirect to allow testing for safe redirects. |
| 26 |
* |
| 27 |
* @codeCoverageIgnore It only wraps a WordPress function. |
| 28 |
* |
| 29 |
* @param string $location The path to redirect to. |
| 30 |
* @param int $status The status code to use. |
| 31 |
*/ |
| 32 |
public function do_safe_redirect( $location, $status = 302 ) { |
| 33 |
\wp_safe_redirect( $location, $status, 'Yoast SEO' ); |
| 34 |
exit; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Wraps wp_redirect to allow testing for redirects. |
| 39 |
* |
| 40 |
* @deprecated 16.x |
| 41 |
* @codeCoverageIgnore It only wraps a WordPress function. |
| 42 |
* |
| 43 |
* @param string $location The path to redirect to. |
| 44 |
* @param int $status The status code to use. |
| 45 |
*/ |
| 46 |
public function do_redirect( $location, $status = 302 ) { |
| 47 |
\_deprecated_function( __METHOD__, 'WPSEO 16.x', 'Yoast\WP\SEO\Helpers\Redirect_Helper::do_unsafe_redirect' ); |
| 48 |
|
| 49 |
$this->do_unsafe_redirect( $location, $status ); |
| 50 |
} |
| 51 |
} |
| 52 |
|