PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / 5.0
Advanced Access Manager – Access Governance for WordPress v5.0
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 / Manager.php
advanced-access-manager / Application / Backend Last commit date
Feature 8 years ago View 8 years ago Widget 8 years ago phtml 8 years ago Authorization.php 8 years ago Feature.php 8 years ago Filter.php 8 years ago Manager.php 8 years ago Subject.php 8 years ago View.php 8 years ago
Manager.php
647 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 manager
12 *
13 * @package AAM
14 * @author Vasyl Martyniuk <vasyl@vasyltech.com>
15 */
16 class AAM_Backend_Manager {
17
18 /**
19 * Single instance of itself
20 *
21 * @var AAM_Backend_Manager
22 *
23 * @access private
24 */
25 private static $_instance = null;
26
27 /**
28 * Initialize the object
29 *
30 * @return void
31 *
32 * @access protected
33 */
34 protected function __construct() {
35 //check if user is allowed to see backend
36 $this->checkUserAccess();
37
38 //check if user switch is required
39 $this->checkUserSwitch();
40
41 //print required JS & CSS
42 add_action('admin_print_scripts', array($this, 'printJavascript'));
43 add_action('admin_print_styles', array($this, 'printStylesheet'));
44
45 //map AAM UI specific capabilities
46 add_filter('map_meta_cap', array($this, 'mapMetaCap'), 10, 4);
47
48 //post title decorator
49 add_filter('the_title', array($this, 'theTitle'), 10, 2);
50
51 //screen options & contextual help hooks
52 add_filter('screen_options_show_screen', array($this, 'screenOptions'));
53 add_filter('contextual_help', array($this, 'helpOptions'), 10, 3);
54
55 //manager Admin Menu
56 if (is_multisite() && is_network_admin()) {
57 //register AAM in the network admin panel
58 add_action('network_admin_menu', array($this, 'adminMenu'));
59 } else {
60 add_action('admin_menu', array($this, 'adminMenu'));
61 add_action('all_admin_notices', array($this, 'notification'));
62 }
63
64 if (AAM_Core_Config::get('render-access-metabox', true)) {
65 add_action('edit_category_form_fields', array($this, 'renderTermMetabox'), 1);
66 add_action('edit_link_category_form_fields', array($this, 'renderTermMetabox'), 1);
67 add_action('edit_tag_form_fields', array($this, 'renderTermMetabox'), 1);
68
69 //register custom access control metabox
70 add_action('add_meta_boxes', array($this, 'metabox'));
71 }
72
73 //manager AAM Ajax Requests
74 add_action('wp_ajax_aam', array($this, 'ajax'));
75 //manager AAM Features Content rendering
76 add_action('admin_action_aamc', array($this, 'renderContent'));
77 //manager user search and authentication control
78 add_filter('user_search_columns', array($this, 'searchColumns'));
79
80 //manager WordPress metaboxes
81 add_action("in_admin_header", array($this, 'initMetaboxes'), 999);
82
83 if (AAM_Core_Config::get('show-access-link', true)) {
84 //extend post inline actions
85 add_filter('page_row_actions', array($this, 'postRowActions'), 10, 2);
86 add_filter('post_row_actions', array($this, 'postRowActions'), 10, 2);
87
88 //extend term inline actions
89 add_filter('tag_row_actions', array($this, 'tagRowActions'), 10, 2);
90
91 //manage access action to the user list
92 add_filter('user_row_actions', array($this, 'userActions'), 10, 2);
93 }
94
95 //footer thank you
96 add_filter('admin_footer_text', array($this, 'thankYou'), 999);
97
98 //control admin area
99 add_action('admin_init', array($this, 'adminInit'));
100
101 //register login widget
102 if (AAM_Core_Config::get('secure-login', true)) {
103 add_action('widgets_init', array($this, 'registerLoginWidget'));
104 add_action('wp_ajax_nopriv_aamlogin', array($this, 'handleLogin'));
105 }
106
107 //register backend hooks and filters
108 if (AAM_Core_Config::get('backend-access-control', true)) {
109 AAM_Backend_Filter::register();
110 }
111
112 AAM_Extension_Repository::getInstance()->hasUpdates();
113 }
114
115 /**
116 *
117 * @param type $caps
118 * @param type $cap
119 * @return type
120 */
121 public function mapMetaCap($caps, $cap) {
122 if (in_array($cap, AAM_Backend_Feature_Main_Capability::$groups['aam'])) {
123 if (!AAM_Core_API::capabilityExists($cap)) {
124 $caps = array(AAM_Core_Config::get('page.capability', 'administrator'));
125 }
126 }
127
128 return $caps;
129 }
130
131 /**
132 *
133 * @param type $title
134 * @param type $id
135 * @return type
136 */
137 public function theTitle($title, $id) {
138 if (empty($title)) {
139 $title = '[No Title]: ID ' . $id;
140 }
141
142 return $title;
143 }
144
145 /**
146 *
147 * @param type $flag
148 * @return type
149 */
150 public function screenOptions($flag) {
151 if (AAM_Core_API::capabilityExists('show_screen_options')) {
152 $flag = AAM::getUser()->hasCapability('show_screen_options');
153 }
154
155 if (AAM::isAAM()) {
156 $flag = false;
157 }
158
159 return $flag;
160 }
161
162 /**
163 *
164 * @param array $help
165 * @param type $id
166 * @param type $screen
167 * @return array
168 */
169 public function helpOptions($help, $id, $screen) {
170 if (AAM_Core_API::capabilityExists('show_help_tabs')) {
171 if (!AAM::getUser()->hasCapability('show_help_tabs')) {
172 $screen->remove_help_tabs();
173 $help = array();
174 }
175 }
176
177 if (AAM::isAAM()) {
178 $screen->remove_help_tabs();
179 }
180
181 return $help;
182 }
183
184 /**
185 *
186 * @return type
187 */
188 public function handleLogin() {
189 $login = AAM_Core_Login::getInstance();
190
191 echo json_encode($login->execute());
192 exit;
193 }
194
195 /**
196 *
197 */
198 public function adminInit() {
199 $user = AAM::getUser();
200 $frame = AAM_Core_Request::get('aamframe');
201
202 if ($frame && $user->hasCapability('aam_manage_posts')) {
203 echo AAM_Backend_View::getInstance()->renderAccessFrame();
204 exit;
205 }
206 }
207
208 /**
209 *
210 * @param type $text
211 * @return string
212 */
213 public function thankYou($text) {
214 if (AAM::isAAM()) {
215 $text = '<span id="footer-thankyou">';
216 $text .= '<b>Please help us</b> and submit your review <a href="';
217 $text .= 'https://wordpress.org/support/plugin/advanced-access-manager/reviews/"';
218 $text .= 'target="_blank"><i class="icon-star"></i>';
219 $text .= '<i class="icon-star"></i><i class="icon-star"></i>';
220 $text .= '<i class="icon-star"></i><i class="icon-star"></i></a>';
221 $text .= '</span>';
222 }
223
224 return $text;
225 }
226
227 /**
228 *
229 */
230 public function registerLoginWidget() {
231 register_widget('AAM_Backend_Widget_Login');
232 }
233
234 /**
235 *
236 */
237 protected function checkUserAccess() {
238 $uid = get_current_user_id();
239
240 if ($uid && AAM_Core_API::capabilityExists('access_dashboard')) {
241 $caps = AAM::getUser()->allcaps;
242 if (empty($caps['access_dashboard'])) {
243 //also additionally check for AJAX calls
244 if (defined('DOING_AJAX') && empty($caps['allow_ajax_calls'])) {
245 AAM_Core_API::reject(
246 'backend', array('hook' => 'access_dashboard')
247 );
248 } elseif (!defined('DOING_AJAX')) {
249 AAM_Core_API::reject(
250 'backend', array('hook' => 'access_dashboard')
251 );
252 }
253 }
254 }
255 }
256
257 /**
258 *
259 */
260 protected function checkUserSwitch() {
261 if (AAM_Core_Request::get('action') == 'aam-switch-back') {
262 $current = get_current_user_id();
263 $uid = AAM_Core_API::getOption('aam-user-switch-' . $current);
264 $redirect = admin_url('admin.php?page=aam&user=' . $current);
265
266 check_admin_referer('aam-switch-' . $uid);
267
268 wp_clear_auth_cookie();
269 wp_set_auth_cookie( $uid, true );
270 wp_set_current_user( $uid );
271
272 AAM_Core_API::deleteOption('aam-user-switch-' . $current);
273
274 wp_redirect($redirect);
275 exit;
276 }
277 }
278
279 /**
280 *
281 */
282 public function notification() {
283 $uid = AAM_Core_API::getOption('aam-user-switch-' . get_current_user_id());
284
285 if ($uid) {
286 //get user's name
287 $user = new WP_User($uid);
288 $name = $user->display_name ? $user->display_name : $user->user_nicename;
289
290 //generate switch back URL
291 $url = wp_nonce_url(
292 'index.php?action=aam-switch-back', 'aam-switch-' . $uid
293 );
294
295 $style = 'padding: 10px; font-weight: 700; letter-spacing:0.5px;';
296
297 echo '<div class="updated notice">';
298 echo '<p style="' . $style . '">';
299 echo sprintf('Switch back to <a href="%s">%s</a>.', $url, $name);
300 echo '</p></div>';
301 }
302 }
303
304 /**
305 *
306 */
307 public function metabox() {
308 $frontend = AAM_Core_Config::get('frontend-access-control', true);
309 $backend = AAM_Core_Config::get('backend-access-control', true);
310
311 if (($frontend || $backend) && AAM::getUser()->hasCapability('aam_manage_posts')) {
312 add_meta_box(
313 'aam-acceess-manager',
314 __('Access Manager', AAM_KEY) . ' <small style="color:#999999;">by AAM plugin</small>',
315 array($this, 'renderPostMetabox'),
316 null,
317 'advanced',
318 'high'
319 );
320 }
321 }
322
323 /**
324 *
325 * @global type $post
326 */
327 public function renderPostMetabox() {
328 global $post;
329
330 if (is_a($post, 'WP_Post')) {
331 echo AAM_Backend_View::getInstance()->renderPostMetabox($post);
332 }
333 }
334
335 /**
336 *
337 * @param type $term
338 */
339 public function renderTermMetabox($term) {
340 if (is_a($term, 'WP_Term') && is_taxonomy_hierarchical($term->taxonomy)) {
341 $frontend = AAM_Core_Config::get('frontend-access-control', true);
342 $backend = AAM_Core_Config::get('backend-access-control', true);
343
344 if (($frontend || $backend) && AAM::getUser()->hasCapability('aam_manage_posts')) {
345 echo AAM_Backend_View::getInstance()->renderTermMetabox($term);
346 }
347 }
348 }
349
350 /**
351 * Hanlde Metabox initialization process
352 *
353 * @return void
354 *
355 * @access public
356 */
357 public function initMetaboxes() {
358 global $post;
359
360 if (AAM_Core_Request::get('init') == 'metabox') {
361 //make sure that nobody is playing with screen options
362 if (is_a($post, 'WP_Post')) {
363 $screen = $post->post_type;
364 } elseif ($screen_object = get_current_screen()) {
365 $screen = $screen_object->id;
366 } else {
367 $screen = '';
368 }
369
370 $model = new AAM_Backend_Feature_Main_Metabox;
371 $model->initialize($screen);
372 }
373 }
374
375 /**
376 * Add extra column to search in for User search
377 *
378 * @param array $columns
379 *
380 * @return array
381 *
382 * @access public
383 */
384 public function searchColumns($columns) {
385 $columns[] = 'display_name';
386
387 return $columns;
388 }
389
390 /**
391 *
392 * @param type $actions
393 * @param type $post
394 * @return string
395 */
396 public function postRowActions($actions, $post) {
397 if ($this->renderExternalUIFeature('aam_manage_posts')) {
398 $url = admin_url('admin.php?page=aam&oid=' . $post->ID . '&otype=post#post');
399
400 $actions['aam'] = '<a href="' . $url . '" target="_blank">';
401 $actions['aam'] .= __('Access', AAM_KEY) . '</a>';
402 }
403
404 return $actions;
405 }
406
407 /**
408 *
409 * @param type $actions
410 * @param type $term
411 * @return string
412 */
413 public function tagRowActions($actions, $term) {
414 if ($this->renderExternalUIFeature('aam_manage_posts')) {
415 $oid = $term->term_id . '|' . $term->taxonomy;
416 $url = admin_url('admin.php?page=aam&oid=' . $oid . '&otype=term#post');
417
418 $actions['aam'] = '<a href="' . $url . '" target="_blank">';
419 $actions['aam'] .= __('Access', AAM_KEY) . '</a>';
420 }
421
422 return $actions;
423 }
424
425 /**
426 * Add "Manage Access" action
427 *
428 * Add additional action to the user list table.
429 *
430 * @param array $actions
431 * @param WP_User $user
432 *
433 * @return array
434 *
435 * @access public
436 */
437 public function userActions($actions, $user) {
438 if ($this->renderExternalUIFeature('list_users')) {
439 $url = admin_url('admin.php?page=aam&user=' . $user->ID);
440
441 $actions['aam'] = '<a href="' . $url . '" target="_blank">';
442 $actions['aam'] .= __('Access', AAM_KEY) . '</a>';
443 }
444
445 return $actions;
446 }
447
448 /**
449 *
450 * @param type $cap
451 * @return type
452 */
453 protected function renderExternalUIFeature($cap) {
454 $frontend = AAM_Core_Config::get('frontend-access-control', true);
455 $backend = AAM_Core_Config::get('backend-access-control', true);
456 $aamManager = AAM::getUser()->hasCapability('aam_manager');
457 $featureManager = AAM::getUser()->hasCapability($cap);
458
459 return ($frontend || $backend) && $aamManager && $featureManager;
460 }
461
462 /**
463 * Print javascript libraries
464 *
465 * @return void
466 *
467 * @access public
468 */
469 public function printJavascript() {
470 if (AAM::isAAM()) {
471 wp_enqueue_script('aam-vendor', AAM_MEDIA . '/js/vendor.js');
472 wp_enqueue_script('aam-main', AAM_MEDIA . '/js/aam.js');
473
474 //add plugin localization
475 $this->printLocalization('aam-main');
476 }
477 }
478
479 /**
480 * Print plugin localization
481 *
482 * @param string $localKey
483 *
484 * @return void
485 *
486 * @access protected
487 */
488 protected function printLocalization($localKey) {
489 $subject = AAM_Backend_Subject::getInstance();
490
491 $locals = array(
492 'nonce' => wp_create_nonce('aam_ajax'),
493 'ajaxurl' => admin_url('admin-ajax.php'),
494 'url' => array(
495 'site' => admin_url('index.php'),
496 'editUser' => admin_url('user-edit.php'),
497 'addUser' => admin_url('user-new.php')
498 ),
499 'level' => AAM_Core_API::maxLevel(wp_get_current_user()->allcaps),
500 'subject' => array(
501 'type' => $subject->getUID(),
502 'id' => $subject->getId(),
503 'name' => $subject->getName(),
504 'level' => $subject->getMaxLevel(),
505 'blog' => get_current_blog_id()
506 ),
507 'translation' => AAM_Backend_View_Localization::get(),
508 'caps' => array(
509 'create_roles' => current_user_can('aam_create_roles'),
510 'create_users' => current_user_can('create_users')
511 )
512 );
513
514 if (AAM_Core_Request::get('aamframe')) {
515 $locals['ui'] = 'post';
516 }
517
518 wp_localize_script($localKey, 'aamLocal', $locals);
519 }
520
521 /**
522 * Print necessary styles
523 *
524 * @return void
525 *
526 * @access public
527 */
528 public function printStylesheet() {
529 if (AAM::isAAM()) {
530 wp_enqueue_style('aam-bt', AAM_MEDIA . '/css/bootstrap.min.css');
531 wp_enqueue_style('aam-db', AAM_MEDIA . '/css/datatables.min.css');
532 wp_enqueue_style('aam-main', AAM_MEDIA . '/css/aam.css');
533 }
534 }
535
536 /**
537 * Register Admin Menu
538 *
539 * @return void
540 *
541 * @access public
542 */
543 public function adminMenu() {
544 if (AAM_Core_Console::count()) {
545 $counter = '&nbsp;<span class="update-plugins">'
546 . '<span class="plugin-count">' . AAM_Core_Console::count()
547 . '</span></span>';
548 } else {
549 $counter = '';
550 }
551
552 //register the menu
553 add_menu_page(
554 'AAM',
555 'AAM' . $counter,
556 'aam_manager',
557 'aam',
558 array($this, 'renderPage'),
559 AAM_MEDIA . '/active-menu.svg'
560 );
561 }
562
563 /**
564 * Render Main Content page
565 *
566 * @return void
567 *
568 * @access public
569 */
570 public function renderPage() {
571 echo AAM_Backend_View::getInstance()->renderPage();
572 }
573
574 /**
575 * Render list of AAM Features
576 *
577 * Must be separate from Ajax call because WordPress ajax does not load
578 * a lot of UI stuff like admin menu
579 *
580 * @return void
581 *
582 * @access public
583 */
584 public function renderContent() {
585 check_ajax_referer('aam_ajax');
586
587 if (AAM::getUser()->hasCapability('aam_manager')) {
588 echo AAM_Backend_View::getInstance()->renderContent(
589 AAM_Core_Request::post('uiType', 'main')
590 );
591 } else {
592 echo __('Access Denied', AAM_KEY);
593 }
594
595 exit();
596 }
597
598 /**
599 * Handle Ajax calls to AAM
600 *
601 * @return void
602 *
603 * @access public
604 */
605 public function ajax() {
606 check_ajax_referer('aam_ajax');
607
608 //clean buffer to make sure that nothing messing around with system
609 while (@ob_end_clean()){}
610
611 //process ajax request
612 if (AAM::getUser()->hasCapability('aam_manager')) {
613 echo AAM_Backend_View::getInstance()->processAjax();
614 } else {
615 echo __('Access Denied', AAM_KEY);
616 }
617
618 exit();
619 }
620
621 /**
622 * Bootstrap the manager
623 *
624 * @return void
625 *
626 * @access public
627 */
628 public static function bootstrap() {
629 if (is_null(self::$_instance)) {
630 self::$_instance = new self;
631 }
632 }
633
634 /**
635 * Get instance of itself
636 *
637 * @return AAM_Backend_View
638 *
639 * @access public
640 */
641 public static function getInstance() {
642 self::bootstrap();
643
644 return self::$_instance;
645 }
646
647 }