| 1 |
<?php |
| 2 |
|
| 3 |
class Login_Match extends Red_Match { |
| 4 |
public $user_agent = ''; |
| 5 |
|
| 6 |
function name() { |
| 7 |
return __( 'URL and login status', 'redirection' ); |
| 8 |
} |
| 9 |
|
| 10 |
public function save( array $details, $no_target_url = false ) { |
| 11 |
if ( $no_target_url ) { |
| 12 |
return null; |
| 13 |
} |
| 14 |
|
| 15 |
return array( |
| 16 |
'logged_in' => isset( $details['action_data_logged_in'] ) ? $this->sanitize_url( $details['action_data_logged_in'] ) : '', |
| 17 |
'logged_out' => isset( $details['action_data_logged_out'] ) ? $this->sanitize_url( $details['action_data_logged_out'] ) : '', |
| 18 |
); |
| 19 |
} |
| 20 |
|
| 21 |
function initialize( $url ) { |
| 22 |
$this->url = array( $url, '' ); |
| 23 |
} |
| 24 |
|
| 25 |
function get_target( $url, $matched_url, $regex ) { |
| 26 |
if ( is_user_logged_in() === false ) { |
| 27 |
$target = $this->url_loggedout; |
| 28 |
} else { |
| 29 |
$target = $this->url_loggedin; |
| 30 |
} |
| 31 |
|
| 32 |
if ( $regex ) { |
| 33 |
$target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url ); |
| 34 |
} |
| 35 |
|
| 36 |
return $target; |
| 37 |
} |
| 38 |
} |
| 39 |
|