| 1 |
<?php |
| 2 |
|
| 3 |
class Login_Match extends Red_Match { |
| 4 |
public $logged_in; |
| 5 |
public $logged_out; |
| 6 |
|
| 7 |
function name() { |
| 8 |
return __( 'URL and login status', 'redirection' ); |
| 9 |
} |
| 10 |
|
| 11 |
public function save( array $details, $no_target_url = false ) { |
| 12 |
if ( $no_target_url ) { |
| 13 |
return null; |
| 14 |
} |
| 15 |
|
| 16 |
return array( |
| 17 |
'logged_in' => isset( $details['logged_in'] ) ? $this->sanitize_url( $details['logged_in'] ) : '', |
| 18 |
'logged_out' => isset( $details['logged_out'] ) ? $this->sanitize_url( $details['logged_out'] ) : '', |
| 19 |
); |
| 20 |
} |
| 21 |
|
| 22 |
function get_target( $url, $matched_url, $regex ) { |
| 23 |
$target = false; |
| 24 |
|
| 25 |
if ( is_user_logged_in() && $this->logged_in !== '' ) { |
| 26 |
$target = $this->logged_in; |
| 27 |
} else if ( ! is_user_logged_in() && $this->logged_out !== '' ) { |
| 28 |
$target = $this->logged_out; |
| 29 |
} |
| 30 |
|
| 31 |
if ( $regex && $target ) { |
| 32 |
$target = $this->get_target_regex_url( $matched_url, $target, $url ); |
| 33 |
} |
| 34 |
|
| 35 |
return $target; |
| 36 |
} |
| 37 |
|
| 38 |
public function get_data() { |
| 39 |
return array( |
| 40 |
'logged_in' => $this->logged_in, |
| 41 |
'logged_out' => $this->logged_out, |
| 42 |
); |
| 43 |
} |
| 44 |
|
| 45 |
public function load( $values ) { |
| 46 |
$values = unserialize( $values ); |
| 47 |
$this->logged_in = $values['logged_in']; |
| 48 |
$this->logged_out = $values['logged_out']; |
| 49 |
} |
| 50 |
} |
| 51 |
|