PluginProbe ʕ •ᴥ•ʔ
Advanced Access Manager – Access Governance for WordPress / trunk
Advanced Access Manager – Access Governance for WordPress vtrunk
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 / Service / BackendMenu.php
advanced-access-manager / application / Service Last commit date
Shortcode 4 months ago AccessDeniedRedirect.php 1 year ago AdminToolbar.php 1 year ago ApiRoute.php 1 year ago BackendMenu.php 1 year ago BaseTrait.php 1 year ago Capability.php 1 year ago Content.php 4 months ago Core.php 8 months ago Hooks.php 1 year ago Identity.php 1 month ago Jwt.php 1 month ago LoginRedirect.php 1 year ago LogoutRedirect.php 1 month ago Metaboxes.php 1 year ago NotFoundRedirect.php 1 year ago Policies.php 1 year ago SecureLogin.php 1 year ago SecurityAudit.php 1 year ago Shortcodes.php 4 months ago Urls.php 1 year ago Welcome.php 1 year ago Widgets.php 1 year ago
BackendMenu.php
207 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 * Admin Menu service
12 *
13 * @package AAM
14 * @version 7.0.0
15 */
16 class AAM_Service_BackendMenu
17 {
18 use AAM_Service_BaseTrait;
19
20 /**
21 * Constructor
22 *
23 * @return void
24 * @access protected
25 *
26 * @version 7.0.4
27 */
28 protected function __construct()
29 {
30 // Register RESTful API endpoints
31 AAM_Restful_BackendMenu::bootstrap();
32
33 add_action('init', function() {
34 $this->initialize_hooks();
35 }, PHP_INT_MAX);
36 }
37
38 /**
39 * Initialize Admin Menu hooks
40 *
41 * @return void
42 * @access protected
43 *
44 * @version 7.0.4
45 */
46 protected function initialize_hooks()
47 {
48 if (is_admin()) {
49 // Hook that initialize the AAM UI part of the service
50 add_action('aam_initialize_ui_action', function () {
51 AAM_Backend_Feature_Main_BackendMenu::register();
52 });
53
54 // Filter the admin menu only when we are not on the AAM page and user
55 // does not have the ability to manage admin menu through AAM UI
56 add_filter('parent_file', function($parent_file) {
57 if (is_admin()
58 && filter_input(INPUT_GET, 'page') === 'aam'
59 && current_user_can('aam_manage_backend_menu')
60 ) {
61 AAM::api()->backend_menu()->get_items();
62 } else {
63 $this->filter_menu();
64 }
65
66 return $parent_file;
67 }, PHP_INT_MAX);
68 }
69
70 // Control admin area
71 if (!defined('DOING_AJAX') || !DOING_AJAX) {
72 add_action('admin_init', function() {
73 $this->_admin_init();
74 }, PHP_INT_MAX);
75 }
76 }
77
78 /**
79 * Filter Admin Menu
80 *
81 * Keep in mind that this function only filter the menu items but does not
82 * restrict access to them.
83 *
84 * @return void
85 * @access public
86 *
87 * @version 7.0.0
88 */
89 public function filter_menu()
90 {
91 global $menu, $submenu;
92
93 $service = AAM::api()->backend_menu();
94
95 foreach ($menu as $id => $item) {
96 $menu_slug = $item[2];
97 $is_restricted = $service->is_denied('menu/' . $menu_slug);
98
99 // If top level menu has submenu items - filter them out as well
100 if (!empty($submenu[$menu_slug])) {
101 $submenus = $this->_filter_submenu(
102 $submenu[$menu_slug], $service
103 );
104
105 // If all submenu items are restricted, there is no need to
106 // render the top level menu because the top level menu always
107 // points to the first submenu item
108 if (count($submenus) === 0) {
109 unset($submenu[$menu_slug]);
110 unset($menu[$id]);
111 } else {
112 $submenu[$menu_slug] = $submenus;
113 }
114 }
115
116 // Remove the top level menu item if it is restricted and no other
117 // sub menu items are available
118 if ($is_restricted
119 && empty($submenu[$menu_slug])
120 && $menu_slug !== 'index.php'
121 ) {
122 unset($menu[$id]);
123 }
124 }
125
126 // Remove duplicated separators
127 $count = 0;
128
129 foreach ($menu as $id => $item) {
130 if (preg_match('/^separator/', $item[2])) {
131 if ($count === 0) {
132 $count++;
133 } else {
134 unset($menu[$id]);
135 }
136 } else {
137 $count = 0;
138 }
139 }
140 }
141
142 /**
143 * Check screen direct access
144 *
145 * @return void
146 * @access public
147 *
148 * @version 7.0.0
149 */
150 private function _admin_init()
151 {
152 global $plugin_page;
153
154 // Compile menu
155 $id = $plugin_page;
156
157 if (empty($id)) {
158 $id = basename(AAM::api()->misc->get($_SERVER, 'SCRIPT_NAME'));
159 $taxonomy = filter_input(INPUT_GET, 'taxonomy');
160 $post_type = filter_input(INPUT_GET, 'post_type');
161 $page = filter_input(INPUT_GET, 'page');
162 $params = [];
163
164 if (!empty($taxonomy)) {
165 array_push($params, 'taxonomy=' . $taxonomy);
166 }
167
168 if (!empty($post_type) && ($post_type !== 'post')) {
169 array_push($params, 'post_type=' . $post_type);
170 } elseif (!empty($page)) {
171 array_push($params, 'page=' . $page);
172 }
173
174 if (count($params)) {
175 $id .= '?' . implode('&', $params);
176 }
177 }
178
179 if (AAM::api()->backend_menu()->is_denied($id)) {
180 AAM::api()->redirect->do_access_denied_redirect();
181 }
182 }
183
184 /**
185 * Filter submenu
186 *
187 * @param array $submenus
188 * @param AAM_Framework_Service_BackendMenu $service
189 * @param bool $default_effect
190 *
191 * @return array
192 * @access private
193 *
194 * @version 7.0.0
195 */
196 private function _filter_submenu($submenus, $service)
197 {
198 foreach ($submenus as $id => $item) {
199 if ($service->is_denied($item[2])) {
200 unset($submenus[$id]);
201 }
202 }
203
204 return array_values($submenus);
205 }
206
207 }