| 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 string $target Target URL. |
| 11 |
* @return void |
| 12 |
*/ |
| 13 |
protected function redirect_to( $target ) { |
| 14 |
// This is a known redirect, possibly extenal |
| 15 |
// phpcs:ignore |
| 16 |
$redirect = wp_redirect( $target, $this->get_code(), 'redirection' ); |
| 17 |
|
| 18 |
if ( $redirect ) { |
| 19 |
global $wp_version; |
| 20 |
|
| 21 |
if ( version_compare( $wp_version, '5.1', '<' ) ) { |
| 22 |
header( 'X-Redirect-Agent: redirection' ); |
| 23 |
} |
| 24 |
|
| 25 |
die(); |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Run this action. May not return from this function. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function run() { |
| 35 |
$target = $this->get_target(); |
| 36 |
|
| 37 |
if ( $target !== null ) { |
| 38 |
$this->redirect_to( $target ); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* Does this action need a target? |
| 44 |
* |
| 45 |
* @return boolean |
| 46 |
*/ |
| 47 |
public function needs_target() { |
| 48 |
return true; |
| 49 |
} |
| 50 |
|
| 51 |
public function name() { |
| 52 |
return __( 'Redirect to URL', 'redirection' ); |
| 53 |
} |
| 54 |
} |
| 55 |
|