| 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 |
|