| 1 |
<?php |
| 2 |
/** |
| 3 |
* WPSEO plugin file. |
| 4 |
* |
| 5 |
* @package WPSEO\Admin\Capabilities |
| 6 |
*/ |
| 7 |
|
| 8 |
/** |
| 9 |
* Default WordPress capability manager implementation. |
| 10 |
*/ |
| 11 |
final class WPSEO_Capability_Manager_WP extends WPSEO_Abstract_Capability_Manager { |
| 12 |
|
| 13 |
/** |
| 14 |
* Adds the capabilities to the roles. |
| 15 |
* |
| 16 |
* @return void |
| 17 |
*/ |
| 18 |
public function add() { |
| 19 |
foreach ( $this->capabilities as $capability => $roles ) { |
| 20 |
$filtered_roles = $this->filter_roles( $capability, $roles ); |
| 21 |
|
| 22 |
$wp_roles = $this->get_wp_roles( $filtered_roles ); |
| 23 |
foreach ( $wp_roles as $wp_role ) { |
| 24 |
$wp_role->add_cap( $capability ); |
| 25 |
} |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
/** |
| 30 |
* Unregisters the capabilities from the system. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function remove() { |
| 35 |
// Remove from any roles it has been added to. |
| 36 |
$roles = wp_roles()->get_names(); |
| 37 |
$roles = array_keys( $roles ); |
| 38 |
|
| 39 |
foreach ( $this->capabilities as $capability => $_roles ) { |
| 40 |
$registered_roles = array_unique( array_merge( $roles, $this->capabilities[ $capability ] ) ); |
| 41 |
|
| 42 |
// Allow filtering of roles. |
| 43 |
$filtered_roles = $this->filter_roles( $capability, $registered_roles ); |
| 44 |
|
| 45 |
$wp_roles = $this->get_wp_roles( $filtered_roles ); |
| 46 |
foreach ( $wp_roles as $wp_role ) { |
| 47 |
$wp_role->remove_cap( $capability ); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
} |
| 52 |
|