| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* URL action - redirect to a URL |
| 5 |
*/ |
| 6 |
class Url_Action extends Red_Action { |
| 7 |
/** |
| 8 |
* Redirect to a URL |
| 9 |
* |
| 10 |
* @param integer $code HTTP status code. |
| 11 |
* @param string $target Target URL. |
| 12 |
* @return void |
| 13 |
*/ |
| 14 |
protected function redirect_to( $code, $target ) { |
| 15 |
// This is a known redirect, possibly extenal |
| 16 |
// phpcs:ignore |
| 17 |
$redirect = wp_redirect( $target, $code, 'redirection' ); |
| 18 |
|
| 19 |
if ( $redirect ) { |
| 20 |
/** @psalm-suppress InvalidGlobal */ |
| 21 |
global $wp_version; |
| 22 |
|
| 23 |
if ( version_compare( $wp_version, '5.1', '<' ) ) { |
| 24 |
header( 'X-Redirect-Agent: redirection' ); |
| 25 |
} |
| 26 |
|
| 27 |
die(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
public function process_after( $code, $target ) { |
| 32 |
$this->redirect_to( $code, $target ); |
| 33 |
} |
| 34 |
|
| 35 |
public function needs_target() { |
| 36 |
return true; |
| 37 |
} |
| 38 |
} |
| 39 |
|