User.php
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * User resource class |
| 12 | * |
| 13 | * @package AAM |
| 14 | * @version 7.0.0 |
| 15 | */ |
| 16 | class AAM_Framework_Resource_User implements AAM_Framework_Resource_Interface |
| 17 | { |
| 18 | |
| 19 | use AAM_Framework_Resource_BaseTrait; |
| 20 | |
| 21 | /** |
| 22 | * @inheritDoc |
| 23 | */ |
| 24 | protected $type = AAM_Framework_Type_Resource::USER; |
| 25 | |
| 26 | /** |
| 27 | * Determine correct resource identifier based on provided data |
| 28 | * |
| 29 | * @param WP_User $resource_identifier |
| 30 | * |
| 31 | * @return mixed |
| 32 | * @access private |
| 33 | * |
| 34 | * @version 7.0.0 |
| 35 | */ |
| 36 | private function _get_resource_id($resource_identifier) |
| 37 | { |
| 38 | return $resource_identifier->ID; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @inheritDoc |
| 43 | * |
| 44 | * @version 7.0.11 |
| 45 | */ |
| 46 | private function _get_resource_identifier($id) |
| 47 | { |
| 48 | return get_user($id); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * @inheritDoc |
| 53 | */ |
| 54 | private function _apply_policy() |
| 55 | { |
| 56 | $result = []; |
| 57 | |
| 58 | foreach($this->policies()->statements('User:*') as $stm) { |
| 59 | $bits = explode(':', $stm['Resource']); |
| 60 | |
| 61 | // If user identifier is not numeric, convert it to WP_User::ID for |
| 62 | // consistency |
| 63 | if (is_numeric($bits[1])) { |
| 64 | $id = intval($bits[1]); |
| 65 | } else { |
| 66 | $user = $this->users->get_user($bits[1]); |
| 67 | $id = is_object($user) ? $user->ID : null; |
| 68 | } |
| 69 | |
| 70 | if (!empty($id)) { |
| 71 | $result[$id] = array_replace( |
| 72 | isset($result[$id]) ? $result[$id] : [], |
| 73 | $this->policy->statement_to_permission($stm, $this->type) |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return apply_filters('aam_apply_policy_filter', $result, $this); |
| 79 | } |
| 80 | |
| 81 | } |