PluginProbe
Redirection / 5.1
Redirection v5.1
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 5.1, at matches/user-role.php

47 lines 1023 B
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Match a particular role or capability
5 */
6 class Role_Match extends Red_Match {
7 use FromNotFrom_Match;
8
9 /**
10 * WordPress role or capability
11 *
12 * @var String
13 */
14 public $role = '';
15
16 public function name() {
17 return __( 'URL and role/capability', 'redirection' );
18 }
19
20 public function save( array $details, $no_target_url = false ) {
21 $data = array( 'role' => isset( $details['role'] ) ? $details['role'] : '' );
22
23 return $this->save_data( $details, $no_target_url, $data );
24 }
25
26 public function is_match( $url ) {
27 return current_user_can( $this->role );
28 }
29
30 public function get_data() {
31 return array_merge( array(
32 'role' => $this->role,
33 ), $this->get_from_data() );
34 }
35
36 /**
37 * Load the match data into this instance.
38 *
39 * @param String $values Match values, as read from the database (plain text or serialized PHP).
40 * @return void
41 */
42 public function load( $values ) {
43 $values = $this->load_data( $values );
44 $this->role = isset( $values['role'] ) ? $values['role'] : '';
45 }
46 }
47