PluginProbe
Advanced Access Manager – Access Governance for WordPress / 7.1.2
Advanced Access Manager – Access Governance for WordPress v7.1.2
7.1.4 7.1.2 7.1.3 6.8.4 6.8.5 6.9.0 6.9.1 6.9.10 6.9.11 6.9.12 6.9.13 6.9.14 6.9.15 6.9.16 6.9.17 6.9.18 6.9.19 6.9.2 6.9.20 6.9.21 6.9.22 6.9.23 6.9.24 6.9.25 6.9.26 All 210 releases
advanced-access-manager / application / Framework / AccessLevel / User.php
User.php
107 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 access level
12 *
13 * @property array $caps
14 * @property array $allcaps
15 * @property array $roles
16 *
17 * @package AAM
18 * @version 7.0.0
19 */
20 class AAM_Framework_AccessLevel_User implements AAM_Framework_AccessLevel_Interface
21 {
22
23 use AAM_Framework_AccessLevel_BaseTrait;
24
25 /**
26 * @inheritDoc
27 */
28 protected $type = AAM_Framework_Type_AccessLevel::USER;
29
30 /**
31 * Get parent access level
32 *
33 * @return AAM_Framework_AccessLevel_Interface
34 * @access public
35 *
36 * @version 7.0.0
37 */
38 public function get_parent()
39 {
40 $roles = $this->roles;
41 $primary_role = array_shift($roles);
42
43 // It is possible that user either does not have any roles or the assigned
44 // role no longer exists.
45 // Note! AAM does not allow deleting roles if there is at least one user
46 // assigned. However, it can be delete through other plugin or custom code
47 if (wp_roles()->is_role($primary_role)) {
48 $parent = AAM_Framework_Manager::_()->access_levels->get(
49 AAM_Framework_Type_AccessLevel::ROLE, $primary_role
50 );
51
52 // If multi-role support is enabled & there are multiple roles assigned
53 // to user, then fetch them all
54 $mu_role_support = AAM_Framework_Manager::_()->config->get(
55 'core.settings.multi_access_levels'
56 );
57
58 if ($mu_role_support && count($roles)) {
59 foreach ($roles as $role) {
60 $parent->add_sibling(AAM_Framework_Manager::_()->access_levels->get(
61 AAM_Framework_Type_AccessLevel::ROLE, $role
62 ));
63 }
64 }
65 } else { // In this case - the Default access level is parent
66 $parent = AAM_Framework_Manager::_()->access_levels->get(
67 AAM_Framework_Type_AccessLevel::DEFAULT
68 );
69 }
70
71 return $parent;
72 }
73
74 /**
75 * @inheritDoc
76 */
77 public function get_id()
78 {
79 return $this->_proxy_instance->ID;
80 }
81
82 /**
83 * @inheritDoc
84 */
85 public function get_display_name()
86 {
87 return $this->_proxy_instance->display_name;
88 }
89
90 /**
91 * Initialize the access level
92 *
93 * @param WP_User $core_instance
94 *
95 * @return void
96 * @access protected
97 *
98 * @version 7.0.0
99 */
100 protected function initialize($core_instance)
101 {
102 $this->_proxy_instance = new AAM_Framework_Proxy_User(
103 $core_instance
104 );
105 }
106
107 }