PluginProbe
Redirection / 4.0
Redirection v4.0
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 / user-role.php

user-role.php in Redirection 4.0, at matches/user-role.php

60 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Role_Match extends Red_Match {
4 public $role;
5 public $url_from;
6 public $url_notfrom;
7
8 function name() {
9 return __( 'URL and role/capability', 'redirection' );
10 }
11
12 public function save( array $details, $no_target_url = false ) {
13 $data = array( 'role' => isset( $details['role'] ) ? $details['role'] : '' );
14
15 if ( $no_target_url === false ) {
16 $data['url_from'] = isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : '';
17 $data['url_notfrom'] = isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : '';
18 }
19
20 return $data;
21 }
22
23 public function get_target( $requested_url, $source_url, Red_Source_Flags $flags ) {
24 // Check if referrer matches
25 $matched = current_user_can( $this->role );
26
27 $target = false;
28 if ( $this->url_from !== '' && $matched ) {
29 $target = $this->url_from;
30 } elseif ( $this->url_notfrom !== '' && ! $matched ) {
31 $target = $this->url_notfrom;
32 }
33
34 if ( $flags->is_regex() && $target ) {
35 $target = $this->get_target_regex_url( $source_url, $target, $requested_url, $flags );
36 }
37
38 return $target;
39 }
40
41 public function get_data() {
42 return array(
43 'url_from' => $this->url_from,
44 'url_notfrom' => $this->url_notfrom,
45 'role' => $this->role,
46 );
47 }
48
49 public function load( $values ) {
50 $values = unserialize( $values );
51
52 if ( isset( $values['url_from'] ) ) {
53 $this->url_from = $values['url_from'];
54 $this->url_notfrom = $values['url_notfrom'];
55 }
56
57 $this->role = $values['role'];
58 }
59 }
60