PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / 5.3.5
Advanced Access Manager – Access Governance for WordPress v5.3.5
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 6.9.27 6.9.28 6.9.29 6.9.3 6.9.30 6.9.31 6.9.32 6.9.33 6.9.34 6.9.35 6.9.36 6.9.37 6.9.38 6.9.39 6.9.4 6.9.41 6.9.42 6.9.43 6.9.44 6.9.45 6.9.46 6.9.47 6.9.48 6.9.49 6.9.5 6.9.51 6.9.6 6.9.7 6.9.8 6.9.9 7.0.0 7.0.0-alpha.6 7.0.0-alpha.7 7.0.0-beta.1 7.0.0-rc1 7.0.0-rc2 7.0.0-rc3 7.0.1 7.0.10 7.0.11 7.0.2 7.0.3 7.0.4 7.0.5 7.0.6 7.0.7 7.0.8 7.0.9 7.1.0 7.1.1 trunk 3.0 4.0 4.0.1 4.1 4.2 4.3 4.4 4.4.1 4.5 4.6 4.6.1 4.6.2 4.7 4.7.1 4.7.2 4.7.5 4.7.6 4.8 4.8.1 4.9 4.9.1 4.9.2 4.9.3 4.9.4 4.9.5 4.9.5.1 4.9.5.2 5.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 5.0.6 5.0.7 5.0.8 5.1 5.1.1 5.10 5.11 5.2 5.2.1 5.2.5 5.2.6 5.2.7 5.3 5.3.1 5.3.2 5.3.3 5.3.4 5.3.5 5.4 5.4.1 5.4.2 5.4.3 5.4.3.1 5.4.3.2 5.5 5.5.1 5.5.2 5.6 5.6.1 5.6.1.1 5.7 5.7.1 5.7.2 5.7.3 5.8 5.8.1 5.8.2 5.8.3 5.9 5.9.1 5.9.1.1 5.9.2 5.9.2.1 5.9.3 5.9.4 5.9.5 5.9.6 5.9.6.1 5.9.6.2 5.9.6.3 5.9.7 5.9.7.1 5.9.7.2 5.9.7.3 5.9.8 5.9.8.1 5.9.9 5.9.9.1 6.0.0 6.0.1 6.0.2 6.0.3 6.0.4 6.0.5 6.1.0 6.1.1 6.2.0 6.2.1 6.2.2 6.3.0 6.3.1 6.3.2 6.3.3 6.4.0 6.4.1 6.4.2 6.4.3 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.6.0 6.6.1 6.6.2 6.6.3 6.6.4 6.7.0 6.7.1 6.7.2 6.7.3 6.7.4 6.7.5 6.7.6 6.7.7 6.7.8 6.7.9 6.8.0 6.8.1 6.8.2 6.8.3
advanced-access-manager / Application / Backend / Feature / Main / Capability.php
advanced-access-manager / Application / Backend / Feature / Main Last commit date
404Redirect.php 8 years ago Capability.php 8 years ago LoginRedirect.php 8 years ago LogoutRedirect.php 8 years ago Menu.php 8 years ago Metabox.php 8 years ago Post.php 8 years ago Redirect.php 8 years ago Route.php 8 years ago
Capability.php
308 lines
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 * Backend capability manager
12 *
13 * @package AAM
14 * @author Vasyl Martyniuk <vasyl@vasyltech.com>
15 */
16 class AAM_Backend_Feature_Main_Capability extends AAM_Backend_Feature_Abstract {
17
18 /**
19 * Capability groups
20 *
21 * @var array
22 *
23 * @access private
24 */
25 public static $groups = array(
26 'system' => array(
27 'level_0', 'level_1', 'level_2', 'level_3', 'level_4', 'level_5',
28 'level_6', 'level_7', 'level_8', 'level_9', 'level_10'
29 ),
30 'post' => array(
31 'delete_others_pages', 'delete_others_posts', 'edit_others_pages',
32 'delete_posts', 'delete_private_pages', 'delete_private_posts',
33 'delete_published_pages', 'delete_published_posts', 'delete_pages',
34 'edit_others_posts', 'edit_pages', 'edit_private_posts',
35 'edit_private_pages', 'edit_posts', 'edit_published_pages',
36 'edit_published_posts', 'publish_pages', 'publish_posts', 'read',
37 'read_private_pages', 'read_private_posts', 'edit_permalink'
38 ),
39 'backend' => array(
40 'aam_manage', 'activate_plugins', 'add_users', 'update_plugins',
41 'delete_users', 'delete_themes', 'edit_dashboard', 'edit_files',
42 'edit_plugins', 'edit_theme_options', 'edit_themes', 'edit_users',
43 'export', 'import', 'install_plugins', 'install_themes',
44 'manage_options', 'manage_links', 'manage_categories', 'customize',
45 'unfiltered_html', 'unfiltered_upload', 'update_themes',
46 'update_core', 'upload_files', 'delete_plugins', 'remove_users',
47 'switch_themes', 'list_users', 'promote_users', 'create_users', 'delete_site'
48 ),
49 'aam' => array(
50 'aam_manage_admin_menu', 'aam_manage_metaboxes', 'aam_manage_capabilities',
51 'aam_manage_posts', 'aam_manage_access_denied_redirect', 'aam_create_roles',
52 'aam_manage_login_redirect', 'aam_manage_logout_redirect', 'aam_manager',
53 'aam_manage_settings', 'aam_manage_extensions', 'aam_show_notifications',
54 'aam_manage_404_redirect', 'aam_manage_ip_check',
55 'aam_manage_default', 'aam_manage_visitors', 'aam_list_roles',
56 'aam_edit_roles', 'aam_delete_roles', 'aam_toggle_users', 'aam_switch_users',
57 'aam_manage_configpress', 'aam_manage_api_routes'
58 )
59 );
60
61 /**
62 *
63 * @return type
64 */
65 public function getTable() {
66 $response = array('data' => $this->retrieveAllCaps());
67
68 return json_encode($response);
69 }
70
71 /**
72 * Update capability tag
73 *
74 * @return string
75 *
76 * @access public
77 */
78 public function update() {
79 $capability = AAM_Core_Request::post('capability');
80 $updated = AAM_Core_Request::post('updated');
81 $roles = AAM_Core_API::getRoles();
82
83 if (AAM_Core_API::capabilityExists($updated) === false) {
84 foreach($roles->role_objects as $role) {
85 //check if capability is present for current role! Note, we
86 //can not use the native WP_Role::has_cap function because it will
87 //return false if capability exists but not checked
88 if (is_array($role->capabilities)
89 && array_key_exists($capability, $role->capabilities)) {
90 $role->add_cap($updated, $role->capabilities[$capability]);
91 $role->remove_cap($capability);
92 }
93 }
94 $response = array('status' => 'success');
95 } else {
96 $response = array(
97 'status' => 'failure',
98 'message' => __('Capability already exists', AAM_KEY)
99 );
100 }
101
102 return json_encode($response);
103 }
104
105 /**
106 * Delete capability
107 *
108 * This function delete capability in all roles.
109 *
110 * @return string
111 *
112 * @access public
113 */
114 public function delete() {
115 $capability = AAM_Core_Request::post('capability');
116 $roles = AAM_Core_API::getRoles();
117 $subject = AAM_Backend_Subject::getInstance();
118
119 if ($subject->getUID() == AAM_Core_Subject_Role::UID) {
120 foreach($roles->role_objects as $role) {
121 $role->remove_cap($capability);
122 }
123 $response = array('status' => 'success');
124 } else {
125 $response = array(
126 'status' => 'failure',
127 'message' => __('Can not remove the capability', AAM_KEY)
128 );
129 }
130
131 return json_encode($response);
132 }
133
134 /**
135 * @inheritdoc
136 */
137 public static function getTemplate() {
138 return 'main/capability.phtml';
139 }
140
141 /**
142 *
143 * @param type $cap
144 * @return type
145 */
146 protected function prepareActionList($cap) {
147 $subject = AAM_Backend_Subject::getInstance();
148 $actions = array();
149
150 $actions[] = ($subject->hasCapability($cap) ? 'checked' : 'unchecked');
151
152 //allow to delete or update capability only for roles!
153 if (AAM_Core_Config::get('core.settings.editCapabilities', false)
154 && ($subject->getUID() == AAM_Core_Subject_Role::UID)) {
155 $actions[] = 'edit';
156 $actions[] = 'delete';
157 }
158
159 return implode(',', $actions);
160 }
161
162 /**
163 * Get list of user roles
164 *
165 * @param array $roles
166 *
167 * @return array
168 *
169 * @access protected
170 */
171 protected function getUserRoles($roles) {
172 $response = array();
173
174 $names = AAM_Core_API::getRoles()->get_names();
175
176 if (is_array($roles)) {
177 foreach($roles as $role) {
178 if (is_array($names) && array_key_exists($role, $names)) {
179 $response[] = translate_user_role($names[$role]);
180 }
181 }
182 }
183
184 return $response;
185 }
186
187 /**
188 *
189 * @return type
190 */
191 protected function retrieveAllCaps() {
192 $response = array();
193 $caps = AAM_Core_API::getAllCapabilities();
194
195 foreach (array_keys($caps) as $cap) {
196 $response[] = array(
197 $cap,
198 $this->getGroup($cap),
199 $cap,
200 $this->prepareActionList($cap)
201 );
202 }
203
204 return $response;
205 }
206
207 /**
208 * Get capability group list
209 *
210 * @return array
211 *
212 * @access public
213 */
214 public function getGroupList() {
215 return apply_filters('aam-capability-groups-filter', array(
216 __('System', AAM_KEY),
217 __('Posts & Pages', AAM_KEY),
218 __('Backend', AAM_KEY),
219 __('AAM Interface', AAM_KEY),
220 __('Miscellaneous', AAM_KEY)
221 ));
222 }
223
224 /**
225 * Add new capability
226 *
227 * @return string
228 *
229 * @access public
230 */
231 public function add() {
232 $capability = sanitize_text_field(AAM_Core_Request::post('capability'));
233
234 if ($capability) {
235 //add the capability to administrator's role as default behavior
236 AAM_Core_API::getRoles()->add_cap('administrator', $capability);
237 AAM_Backend_Subject::getInstance()->addCapability($capability);
238 $response = array('status' => 'success');
239 } else {
240 $response = array('status' => 'failure');
241 }
242
243 return json_encode($response);
244 }
245
246 /**
247 * Get capability group name
248 *
249 * @param string $capability
250 *
251 * @return string
252 *
253 * @access protected
254 */
255 protected function getGroup($capability) {
256 if (in_array($capability, self::$groups['system'])) {
257 $response = __('System', AAM_KEY);
258 } elseif (in_array($capability, self::$groups['post'])) {
259 $response = __('Posts & Pages', AAM_KEY);
260 } elseif (in_array($capability, self::$groups['backend'])) {
261 $response = __('Backend', AAM_KEY);
262 } elseif (in_array($capability, self::$groups['aam'])) {
263 $response = __('AAM Interface', AAM_KEY);
264 } else {
265 $response = __('Miscellaneous', AAM_KEY);
266 }
267
268 return apply_filters(
269 'aam-capability-group-filter', $response, $capability
270 );
271 }
272
273 /**
274 * Check overwritten status
275 *
276 * @return boolean
277 *
278 * @access protected
279 */
280 protected function isOverwritten() {
281 $object = AAM_Backend_Subject::getInstance()->getObject('capability');
282
283 return $object->isOverwritten();
284 }
285
286 /**
287 * Register capability feature
288 *
289 * @return void
290 *
291 * @access public
292 */
293 public static function register() {
294 AAM_Backend_Feature::registerFeature((object) array(
295 'uid' => 'capability',
296 'position' => 15,
297 'title' => __('Capabilities', AAM_KEY),
298 'capability' => 'aam_manage_capabilities',
299 'type' => 'main',
300 'subjects' => array(
301 AAM_Core_Subject_Role::UID,
302 AAM_Core_Subject_User::UID
303 ),
304 'view' => __CLASS__
305 ));
306 }
307
308 }