PluginProbe
Redirection / 5.3.3
Redirection v5.3.3
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
redirection / matches / login.php

login.php in Redirection 5.3.3, at matches/login.php

75 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Check whether the user is logged in or out
5 */
6 class Login_Match extends Red_Match {
7 /**
8 * Target URL when logged in.
9 *
10 * @var String
11 */
12 public $logged_in = '';
13
14 /**
15 * Target URL when logged out.
16 *
17 * @var String
18 */
19 public $logged_out = '';
20
21 public function name() {
22 return __( 'URL and login status', 'redirection' );
23 }
24
25 public function save( array $details, $no_target_url = false ) {
26 if ( $no_target_url ) {
27 return null;
28 }
29
30 return [
31 'logged_in' => isset( $details['logged_in'] ) ? $this->sanitize_url( $details['logged_in'] ) : '',
32 'logged_out' => isset( $details['logged_out'] ) ? $this->sanitize_url( $details['logged_out'] ) : '',
33 ];
34 }
35
36 public function is_match( $url ) {
37 return is_user_logged_in();
38 }
39
40 public function get_target_url( $requested_url, $source_url, Red_Source_Flags $flags, $match ) {
41 $target = false;
42
43 if ( $match && $this->logged_in !== '' ) {
44 $target = $this->logged_in;
45 } elseif ( ! $match && $this->logged_out !== '' ) {
46 $target = $this->logged_out;
47 }
48
49 if ( $flags->is_regex() && $target ) {
50 $target = $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
51 }
52
53 return $target;
54 }
55
56 public function get_data() {
57 return [
58 'logged_in' => $this->logged_in,
59 'logged_out' => $this->logged_out,
60 ];
61 }
62
63 /**
64 * Load the match data into this instance.
65 *
66 * @param String $values Match values, as read from the database (plain text or serialized PHP).
67 * @return void
68 */
69 public function load( $values ) {
70 $values = unserialize( $values );
71 $this->logged_in = isset( $values['logged_in'] ) ? $values['logged_in'] : '';
72 $this->logged_out = isset( $values['logged_out'] ) ? $values['logged_out'] : '';
73 }
74 }
75