PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 6.2.2
MainWP Dashboard: Self-hosted WordPress Management for Agencies v6.2.2
6.2.2 6.2.1 6.2 6.1.8 6.1.7 6.1.6 6.1.5 6.1.4 6.1.3 6.1.2 6.1.1 6.1 6.0.12 6.0.11 4.6.0.1 5.0 5.0.1 5.0.2 5.0.3 5.0.3.1 5.0.3.2 5.1 5.1.1 5.2 5.2.1 All 155 releases
← All changes | class/class-mainwp-menu.php +1319 -1308 5.0.3.2 → 6.2.2 View file →
@@ -8,1467 +8,1478 @@
8 8 */
9 9
10 10 namespace MainWP\Dashboard;
11 11
12 +// Exit if accessed directly.
13 +if ( ! defined( 'ABSPATH' ) ) {
14 + exit;
15 +}
16 +
12 17 /**
13 18 * Class MainWP_Menu
14 19 *
15 20 * @package MainWP\Dashboard
16 21 */
17 -class MainWP_Menu {
22 +class MainWP_Menu { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.
18 23
19 - /**
20 - * Method get_class_name()
21 - *
22 - * Get Class Name.
23 - *
24 - * @return object
25 - */
26 - public static function get_class_name() {
27 - return __CLASS__;
28 - }
24 + /**
25 + * Method get_class_name()
26 + *
27 + * Get Class Name.
28 + *
29 + * @return object
30 + */
31 + public static function get_class_name() {
32 + return __CLASS__;
33 + }
29 34
30 - /**
31 - * MainWP_Menu constructor.
32 - *
33 - * Run each time the class is called.
34 - * Define MainWP Main Menu Items.
35 - */
36 - public function __construct() {
35 + /**
36 + * Method get_instance().
37 + */
38 + public static function get_instance() {
39 + return new self();
40 + }
37 41
38 - /**
39 - * MainWP Disable Menus items array.
40 - *
41 - * @global object
42 - */
43 - global $_mainwp_disable_menus_items;
42 + /**
43 + * MainWP_Menu constructor.
44 + *
45 + * Run each time the class is called.
46 + * Define MainWP Main Menu Items.
47 + */
48 + public function __construct() {
44 49
45 - // Init disable menu items, default is false.
46 - // Use the MainWP Hook 'mainwp_main_menu_disable_menu_items' to disable menu items.
47 - if ( null === $_mainwp_disable_menus_items ) {
48 - $_mainwp_disable_menus_items = array(
49 - // Compatible with old hooks.
50 - 'level_1' => array(
51 - 'not_set_this_level' => true,
52 - ),
53 - 'level_2' => array(
54 - // 'mainwp_tab' - Do not hide this menu.
55 - 'UpdatesManage' => false,
56 - 'managesites' => false,
57 - 'ManageClients' => false,
58 - 'ManageGroups' => false,
59 - 'PostBulkManage' => false,
60 - 'PageBulkManage' => false,
61 - 'ThemesManage' => false,
62 - 'PluginsManage' => false,
63 - 'UserBulkManage' => false,
64 - 'ManageBackups' => false,
65 - 'Settings' => false,
66 - 'Extensions' => false,
67 - 'ServerInformation' => false,
68 - ),
69 - // Compatible with old hooks.
70 - 'level_3' => array(),
71 - );
72 - }
73 - }
50 + /**
51 + * MainWP Disable Menus items array.
52 + *
53 + * @global object
54 + */
55 + global $_mainwp_disable_menus_items;
74 56
75 - /**
76 - * Method init_mainwp_menus()
77 - *
78 - * Init MainWP menus.
79 - *
80 - * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
81 - * @uses \MainWP\Dashboard\MainWP_Updates::init_menu()
82 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::init_menu()
83 - * @uses \MainWP\Dashboard\MainWP_Post::init_menu()
84 - * @uses \MainWP\Dashboard\MainWP_Page::init_menu()
85 - * @uses \MainWP\Dashboard\MainWP_Themes::init_menu()
86 - * @uses \MainWP\Dashboard\MainWP_Plugins::init_menu()
87 - * @uses \MainWP\Dashboard\MainWP_User::init_menu()
88 - * @uses \MainWP\Dashboard\MainWP_Manage_Backups::init_menu()
89 - * @uses \MainWP\Dashboard\MainWP_Manage_Groups::init_menu()
90 - * @uses \MainWP\Dashboard\MainWP_Monitoring::init_menu()
91 - * @uses \MainWP\Dashboard\MainWP_Settings::init_menu()
92 - * @uses \MainWP\Dashboard\MainWP_Extensions::init_menu()
93 - * @uses \MainWP\Dashboard\MainWP_Bulk_Update_Admin_Passwords::init_menu()
94 - */
95 - public static function init_mainwp_menus() { // phpcs:ignore -- complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
96 - if ( MainWP_System_Utility::is_admin() ) {
57 + // Init disable menu items, default is false.
58 + // Use the MainWP Hook 'mainwp_main_menu_disable_menu_items' to disable menu items.
59 + if ( null === $_mainwp_disable_menus_items ) {
60 + $_mainwp_disable_menus_items = array(
61 + // Compatible with old hooks.
62 + 'level_1' => array(
63 + 'not_set_this_level' => true,
64 + ),
65 + 'level_2' => array(
66 + // 'mainwp_tab' - Do not hide this menu.
67 + 'UpdatesManage' => false,
68 + 'managesites' => false,
69 + 'ManageClients' => false,
70 + 'ManageGroups' => false,
71 + 'PostBulkManage' => false,
72 + 'PageBulkManage' => false,
73 + 'ThemesManage' => false,
74 + 'PluginsManage' => false,
75 + 'UserBulkManage' => false,
76 + 'ManageBackups' => false,
77 + 'Settings' => false,
78 + 'Extensions' => false,
79 + 'ServerInformation' => false,
80 + ),
81 + // Compatible with old hooks.
82 + 'level_3' => array(),
83 + );
84 + }
85 + }
97 86
98 - $menus_items = array();
87 + /**
88 + * Method init_mainwp_menus()
89 + *
90 + * Init MainWP menus.
91 + *
92 + * @uses \MainWP\Dashboard\MainWP_System_Utility::is_admin()
93 + * @uses \MainWP\Dashboard\MainWP_Updates::init_menu()
94 + * @uses \MainWP\Dashboard\MainWP_Manage_Sites::init_menu()
95 + * @uses \MainWP\Dashboard\MainWP_Post::init_menu()
96 + * @uses \MainWP\Dashboard\MainWP_Page::init_menu()
97 + * @uses \MainWP\Dashboard\MainWP_Themes::init_menu()
98 + * @uses \MainWP\Dashboard\MainWP_Plugins::init_menu()
99 + * @uses \MainWP\Dashboard\MainWP_User::init_menu()
100 + * @uses \MainWP\Dashboard\MainWP_Manage_Backups::init_menu()
101 + * @uses \MainWP\Dashboard\MainWP_Manage_Groups::init_menu()
102 + * @uses \MainWP\Dashboard\MainWP_Monitoring::init_menu()
103 + * @uses \MainWP\Dashboard\MainWP_Settings::init_menu()
104 + * @uses \MainWP\Dashboard\MainWP_Extensions::init_menu()
105 + * @uses \MainWP\Dashboard\MainWP_Bulk_Update_Admin_Passwords::init_menu()
106 + */
107 + public static function init_mainwp_menus() { // phpcs:ignore -- NOSONAR - complex method. Current complexity is the only way to achieve desired results, pull request solutions appreciated.
108 + if ( MainWP_System_Utility::is_admin() ) {
99 109
100 - // Manage Sites.
101 - $menus_items[] = array(
102 - 'slug' => 'managesites',
103 - 'menu_level' => 2,
104 - 'menu_rights' => array(
105 - 'dashboard' => array(
106 - 'add_sites',
107 - 'edit_sites',
108 - 'delete_sites',
109 - 'access_individual_dashboard',
110 - 'access_wpadmin_on_child_sites',
111 - 'manage_security_issues',
112 - 'test_connection',
113 - 'manage_groups',
114 - ),
115 - ),
116 - 'init_menu_callback' => array( MainWP_Manage_Sites::class, 'init_menu' ),
117 - 'leftbar_order' => 1,
118 - );
110 + $menus_items = array();
119 111
120 - // Manage Clients.
121 - $menus_items[] = array(
122 - 'slug' => 'ManageClients',
123 - 'menu_level' => 2,
124 - 'menu_rights' => array(
125 - 'dashboard' => array(
126 - 'manage_clients',
127 - ),
128 - ),
129 - 'init_menu_callback' => array( MainWP_Client::class, 'init_menu' ),
130 - 'leftbar_order' => 2,
131 - );
112 + // Manage Sites.
113 + $menus_items[] = array(
114 + 'slug' => 'managesites',
115 + 'menu_level' => 2,
116 + 'menu_rights' => array(
117 + 'dashboard' => array(
118 + 'add_sites',
119 + 'edit_sites',
120 + 'delete_sites',
121 + 'access_individual_dashboard',
122 + 'access_wpadmin_on_child_sites',
123 + 'manage_security_issues',
124 + 'test_connection',
125 + 'manage_groups',
126 + 'manage_uptime_monitoring',
127 + ),
128 + ),
129 + 'init_menu_callback' => array( MainWP_Manage_Sites::class, 'init_menu' ),
130 + 'leftbar_order' => 1,
131 + );
132 132
133 - // Manage Tags.
134 - $menus_items[] = array(
135 - 'slug' => 'ManageGroups',
136 - 'menu_level' => 2,
137 - 'menu_rights' => array(
138 - 'dashboard' => array(
139 - 'manage_groups',
140 - ),
141 - ),
142 - 'init_menu_callback' => array( MainWP_Manage_Groups::class, 'init_menu' ),
143 - );
133 + // Manage Clients.
134 + $menus_items[] = array(
135 + 'slug' => 'ManageClients',
136 + 'menu_level' => 2,
137 + 'menu_rights' => array(
138 + 'dashboard' => array(
139 + 'manage_clients',
140 + ),
141 + ),
142 + 'init_menu_callback' => array( MainWP_Client::class, 'init_menu' ),
143 + 'leftbar_order' => 2,
144 + );
144 145
145 - // Manage Updates.
146 - $menus_items[] = array(
147 - 'slug' => 'UpdatesManage',
148 - 'menu_level' => 2,
149 - 'menu_rights' => array(
150 - 'dashboard' => array(
151 - 'update_wordpress',
152 - 'update_plugins',
153 - 'update_themes',
154 - 'update_translations',
155 - 'ignore_unignore_updates',
156 - 'trust_untrust_updates',
157 - ),
158 - ),
159 - 'init_menu_callback' => array( MainWP_Updates::class, 'init_menu' ),
160 - );
146 + // Manage Tags.
147 + $menus_items[] = array(
148 + 'slug' => 'ManageGroups',
149 + 'menu_level' => 2,
150 + 'menu_rights' => array(
151 + 'dashboard' => array(
152 + 'manage_groups',
153 + ),
154 + ),
155 + 'init_menu_callback' => array( MainWP_Manage_Groups::class, 'init_menu' ),
156 + );
161 157
162 - // Manage Plugins.
163 - $menus_items[] = array(
164 - 'slug' => 'PluginsManage',
165 - 'menu_level' => 2,
166 - 'menu_rights' => array(
167 - 'dashboard' => array(
168 - 'install_plugins',
169 - 'delete_plugins',
170 - 'activate_deactivate_plugins',
171 - ),
172 - ),
173 - 'init_menu_callback' => array( MainWP_Plugins::class, 'init_menu' ),
174 - );
158 + // Manage Updates.
159 + $menus_items[] = array(
160 + 'slug' => 'UpdatesManage',
161 + 'menu_level' => 2,
162 + 'menu_rights' => array(
163 + 'dashboard' => array(
164 + 'update_wordpress',
165 + 'update_plugins',
166 + 'update_themes',
167 + 'update_translations',
168 + 'ignore_unignore_updates',
169 + 'trust_untrust_updates',
170 + ),
171 + ),
172 + 'init_menu_callback' => array( MainWP_Updates::class, 'init_menu' ),
173 + );
175 174
176 - // Manage Themes.
177 - $menus_items[] = array(
178 - 'slug' => 'ThemesManage',
179 - 'menu_level' => 2,
180 - 'menu_rights' => array(
181 - 'dashboard' => array(
182 - 'install_themes',
183 - 'delete_themes',
184 - 'activate_deactivate_themes',
185 - ),
186 - ),
187 - 'init_menu_callback' => array( MainWP_Themes::class, 'init_menu' ),
188 - );
175 + // Manage Plugins.
176 + $menus_items[] = array(
177 + 'slug' => 'PluginsManage',
178 + 'menu_level' => 2,
179 + 'menu_rights' => array(
180 + 'dashboard' => array(
181 + 'install_plugins',
182 + 'delete_plugins',
183 + 'activate_deactivate_plugins',
184 + ),
185 + ),
186 + 'init_menu_callback' => array( MainWP_Plugins::class, 'init_menu' ),
187 + );
189 188
190 - // Manage Users.
191 - $menus_items[] = array(
192 - 'slug' => 'UserBulkManage',
193 - 'menu_level' => 2,
194 - 'menu_rights' => array(
195 - 'dashboard' => array(
196 - 'manage_users',
197 - ),
198 - ),
199 - 'init_menu_callback' => array( MainWP_User::class, 'init_menu' ),
200 - );
189 + // Manage Themes.
190 + $menus_items[] = array(
191 + 'slug' => 'ThemesManage',
192 + 'menu_level' => 2,
193 + 'menu_rights' => array(
194 + 'dashboard' => array(
195 + 'install_themes',
196 + 'delete_themes',
197 + 'activate_deactivate_themes',
198 + ),
199 + ),
200 + 'init_menu_callback' => array( MainWP_Themes::class, 'init_menu' ),
201 + );
201 202
202 - // Manage Posts.
203 - $menus_items[] = array(
204 - 'slug' => 'PostBulkManage',
205 - 'menu_level' => 2,
206 - 'menu_rights' => array(
207 - 'dashboard' => array(
208 - 'manage_posts',
209 - ),
210 - ),
211 - 'init_menu_callback' => array( MainWP_Post::class, 'init_menu' ),
212 - );
203 + // Manage Users.
204 + $menus_items[] = array(
205 + 'slug' => 'UserBulkManage',
206 + 'menu_level' => 2,
207 + 'menu_rights' => array(
208 + 'dashboard' => array(
209 + 'manage_users',
210 + ),
211 + ),
212 + 'init_menu_callback' => array( MainWP_User::class, 'init_menu' ),
213 + );
213 214
214 - // Manage Pages.
215 - $menus_items[] = array(
216 - 'slug' => 'PageBulkManage',
217 - 'menu_level' => 2,
218 - 'menu_rights' => array(
219 - 'dashboard' => array(
220 - 'manage_pages',
221 - ),
222 - ),
223 - 'init_menu_callback' => array( MainWP_Page::class, 'init_menu' ),
224 - );
215 + // Manage Posts.
216 + $menus_items[] = array(
217 + 'slug' => 'PostBulkManage',
218 + 'menu_level' => 2,
219 + 'menu_rights' => array(
220 + 'dashboard' => array(
221 + 'manage_posts',
222 + ),
223 + ),
224 + 'init_menu_callback' => array( MainWP_Post::class, 'init_menu' ),
225 + );
225 226
226 - // Manage Backups.
227 - $menus_items[] = array(
228 - 'slug' => 'ManageBackups',
229 - 'menu_level' => 2,
230 - 'menu_rights' => true,
231 - 'init_menu_callback' => array( MainWP_Manage_Backups::class, 'init_menu' ),
232 - );
227 + // Manage Pages.
228 + $menus_items[] = array(
229 + 'slug' => 'PageBulkManage',
230 + 'menu_level' => 2,
231 + 'menu_rights' => array(
232 + 'dashboard' => array(
233 + 'manage_pages',
234 + ),
235 + ),
236 + 'init_menu_callback' => array( MainWP_Page::class, 'init_menu' ),
237 + );
233 238
234 - // Manage Settings.
235 - $menus_items[] = array(
236 - 'slug' => 'Settings',
237 - 'menu_level' => 2,
238 - 'menu_rights' => array(
239 - 'dashboard' => array(
240 - 'manage_dashboard_settings',
241 - ),
242 - ),
243 - 'init_menu_callback' => array( MainWP_Settings::class, 'init_menu' ),
244 - 'leftbar_order' => 5,
245 - );
239 + // Manage Backups.
240 + $menus_items[] = array(
241 + 'slug' => 'ManageBackups',
242 + 'menu_level' => 2,
243 + 'menu_rights' => true,
244 + 'init_menu_callback' => array( MainWP_Manage_Backups::class, 'init_menu' ),
245 + );
246 246
247 - // Manage RESTAPI.
248 - $menus_items[] = array(
249 - 'slug' => 'RESTAPI',
250 - 'menu_level' => 2,
251 - 'menu_rights' => array(
252 - 'dashboard' => array(
253 - 'manage_dashboard_restapi',
254 - ),
255 - ),
256 - 'init_menu_callback' => array( MainWP_Rest_Api_Page::class, 'init_menu' ),
257 - 'leftbar_order' => 4,
258 - );
247 + // Manage Settings.
248 + $menus_items[] = array(
249 + 'slug' => 'Settings',
250 + 'menu_level' => 2,
251 + 'menu_rights' => array(
252 + 'dashboard' => array(
253 + 'manage_dashboard_settings',
254 + ),
255 + ),
256 + 'init_menu_callback' => array( MainWP_Settings::class, 'init_menu' ),
257 + 'leftbar_order' => 5,
258 + );
259 259
260 - // Manage Extensions.
261 - $menus_items[] = array(
262 - 'slug' => 'Extensions',
263 - 'menu_level' => 2,
264 - 'menu_rights' => array(
265 - 'dashboard' => array(
266 - 'manage_extensions',
267 - ),
268 - ),
269 - 'init_menu_callback' => array( MainWP_Extensions::class, 'init_menu' ),
270 - 'leftbar_order' => 3,
271 - );
260 + // Manage RESTAPI.
261 + $menus_items[] = array(
262 + 'slug' => 'RESTAPI',
263 + 'menu_level' => 2,
264 + 'menu_rights' => true,
265 + 'init_menu_callback' => array( MainWP_Rest_Api_Page::class, 'init_menu' ),
266 + 'leftbar_order' => 4,
267 + );
272 268
273 - // Manage Admin Passwords.
274 - $menus_items[] = array(
275 - 'slug' => 'UpdateAdminPasswords',
276 - 'menu_level' => 2,
277 - 'menu_rights' => array(
278 - 'dashboard' => array(
279 - 'manage_users',
280 - ),
281 - ),
282 - 'init_menu_callback' => array( MainWP_Bulk_Update_Admin_Passwords::class, 'init_menu' ),
283 - );
269 + // Manage Extensions.
270 + $menus_items[] = array(
271 + 'slug' => 'Extensions',
272 + 'menu_level' => 2,
273 + 'menu_rights' => true,
274 + 'init_menu_callback' => array( MainWP_Extensions::class, 'init_menu' ),
275 + 'leftbar_order' => 3,
276 + );
284 277
285 - // Monitoring Sites.
286 - $menus_items[] = array(
287 - 'slug' => 'MonitoringSites',
288 - 'menu_level' => 3,
289 - 'menu_rights' => true,
290 - 'init_menu_callback' => array( MainWP_Monitoring::class, 'init_menu' ),
291 - );
278 + // Manage Admin Passwords.
279 + $menus_items[] = array(
280 + 'slug' => 'UpdateAdminPasswords',
281 + 'menu_level' => 2,
282 + 'menu_rights' => array(
283 + 'dashboard' => array(
284 + 'manage_users',
285 + ),
286 + ),
287 + 'init_menu_callback' => array( MainWP_Bulk_Update_Admin_Passwords::class, 'init_menu' ),
288 + );
292 289
293 - self::init_mainwp_menu_items( $menus_items, 'first' ); // do NOT change 'first', it related other hooks.
290 + // Password Policy Settings.
291 + $menus_items[] = array(
292 + 'slug' => 'PasswordPolicy',
293 + 'menu_level' => 2,
294 + 'menu_rights' => array(
295 + 'dashboard' => array(
296 + 'manage_users',
297 + ),
298 + ),
299 + 'init_menu_callback' => array( MainWP_Password_Policy_Settings::class, 'init_menu' ),
300 + );
294 301
295 - /**
296 - * Action: mainwp_admin_menu
297 - *
298 - * Hooks main navigation menu items.
299 - *
300 - * @since 4.0
301 - */
302 - do_action( 'mainwp_admin_menu' ); // to compatible.
302 + // Monitoring Sites.
303 + $menus_items[] = array(
304 + 'slug' => 'MonitoringSites',
305 + 'menu_level' => 3,
306 + 'menu_rights' => true,
307 + 'init_menu_callback' => array( MainWP_Monitoring::class, 'init_menu' ),
308 + );
303 309
304 - $menus_items_low = array();
310 + static::init_mainwp_menu_items( $menus_items, 'first' ); // do NOT change 'first', it related other hooks.
305 311
306 - // Manage Admin Passwords.
307 - $menus_items_low[] = array(
308 - 'slug' => 'ServerInformation',
309 - 'menu_level' => 2,
310 - 'menu_rights' => array(
311 - 'dashboard' => array(
312 - 'see_server_information',
313 - ),
314 - ),
315 - 'init_menu_callback' => array( MainWP_Server_Information::class, 'init_menu' ),
316 - 'leftbar_order' => 6,
317 - );
312 + /**
313 + * Action: mainwp_admin_menu
314 + *
315 + * Hooks main navigation menu items.
316 + *
317 + * @since 4.0
318 + */
319 + do_action( 'mainwp_admin_menu' ); // to compatible.
318 320
319 - self::init_mainwp_menu_items( $menus_items_low, 'second' );
321 + $menus_items_low = array();
320 322
321 - }
322 - }
323 + // Manage Admin Passwords.
324 + $menus_items_low[] = array(
325 + 'slug' => 'ServerInformation',
326 + 'menu_level' => 2,
327 + 'menu_rights' => array(
328 + 'dashboard' => array(
329 + 'see_server_information',
330 + ),
331 + ),
332 + 'init_menu_callback' => array( MainWP_Server_Information::class, 'init_menu' ),
333 + 'leftbar_order' => 6,
334 + );
323 335
324 - /**
325 - * Method init_mainwp_menu_items()
326 - *
327 - * Init MainWP menus.
328 - *
329 - * @param array $menus_items menus items.
330 - * @param string $part menus part.
331 - */
332 - public static function init_mainwp_menu_items( $menus_items, $part ) { //phpcs:ignore -- complex method.
333 - if ( ! is_array( $menus_items ) ) {
334 - return;
335 - }
336 + static::init_mainwp_menu_items( $menus_items_low, 'second' );
336 337
337 - $menus_items = apply_filters( 'mainwp_init_primary_menu_items', $menus_items, $part );
338 + }
339 + }
338 340
339 - MainWP_Utility::array_sort_existed_keys( $menus_items, 'leftbar_order' );
341 + /**
342 + * Method init_mainwp_menu_items()
343 + *
344 + * Init MainWP menus.
345 + *
346 + * @param array $menus_items menus items.
347 + * @param string $part menus part.
348 + */
349 + public static function init_mainwp_menu_items( $menus_items, $part ) { //phpcs:ignore -- NOSONAR - complex method.
350 + if ( ! is_array( $menus_items ) ) {
351 + return;
352 + }
340 353
341 - foreach ( $menus_items as $item ) {
342 - if ( ! is_array( $item ) ) {
343 - continue;
344 - }
345 - if ( ! empty( $item['slug'] ) && ! empty( $item['menu_level'] ) && ! empty( $item['init_menu_callback'] ) ) {
346 - if ( ! self::is_disable_menu_item( intval( $item['menu_level'] ), $item['slug'] ) ) {
347 - if ( is_callable( $item['init_menu_callback'] ) ) {
348 - $accessable = false;
349 - if ( isset( $item['menu_rights'] ) ) {
350 - $item_rights = $item['menu_rights'];
351 - if ( is_array( $item_rights ) && ! empty( $item_rights ) ) {
352 - foreach ( $item_rights as $group_right => $rights ) {
353 - if ( is_array( $rights ) ) {
354 - foreach ( $rights as $func_right ) {
355 - if ( mainwp_current_user_have_right( $group_right, $func_right ) ) {
356 - $accessable = true;
357 - break;
358 - }
359 - }
360 - }
361 - if ( $accessable ) {
362 - break;
363 - }
364 - }
365 - } elseif ( true === $item['menu_rights'] ) {
366 - $accessable = true;
367 - }
368 - }
354 + $menus_items = apply_filters( 'mainwp_init_primary_menu_items', $menus_items, $part );
369 355
370 - if ( $accessable ) {
371 - call_user_func( $item['init_menu_callback'] );
372 - }
373 - }
374 - }
375 - }
376 - }
377 - }
356 + MainWP_Utility::array_sort_existed_keys( $menus_items, 'leftbar_order' );
378 357
379 - /**
380 - * Method init_sub_pages()
381 - *
382 - * Init subpages MainWP menus.
383 - *
384 - * @uses \MainWP\Dashboard\MainWP_Extensions::init_subpages_menu()
385 - * @uses \MainWP\Dashboard\MainWP_Manage_Backups::init_subpages_menu()
386 - * @uses \MainWP\Dashboard\MainWP_Manage_Sites::init_subpages_menu()
387 - * @uses \MainWP\Dashboard\MainWP_Page::init_subpages_menu()
388 - * @uses \MainWP\Dashboard\MainWP_Post::init_subpages_menu()
389 - * @uses \MainWP\Dashboard\MainWP_Settings::init_subpages_menu()
390 - * @uses \MainWP\Dashboard\MainWP_Themes::init_subpages_menu()
391 - * @uses \MainWP\Dashboard\MainWP_Themes::init_subpages_menu()
392 - * @uses \MainWP\Dashboard\MainWP_Plugins::init_subpages_menu()
393 - * @uses \MainWP\Dashboard\MainWP_User::init_subpages_menu()
394 - * @uses \MainWP\Dashboard\MainWP_Settings::init_subpages_menu()
395 - */
396 - public static function init_sub_pages() {
358 + foreach ( $menus_items as $item ) {
359 + if ( ! is_array( $item ) ) {
360 + continue;
361 + }
397 362
398 - if ( ! self::is_disable_menu_item( 2, 'PostBulkManage' ) ) {
399 - MainWP_Post::init_subpages_menu();
400 - }
401 - if ( ! self::is_disable_menu_item( 2, 'managesites' ) ) {
402 - MainWP_Manage_Sites::init_subpages_menu();
403 - }
363 + $empty_level = true;
404 364
405 - if ( ! self::is_disable_menu_item( 2, 'RESTAPI' ) ) {
406 - MainWP_Rest_Api_Page::init_subpages_menu();
407 - }
365 + if ( ! empty( $item['slug'] ) && ! empty( $item['menu_level'] ) && ! empty( $item['init_menu_callback'] ) ) {
366 + $empty_level = false;
367 + }
408 368
409 - if ( ! self::is_disable_menu_item( 2, 'Settings' ) ) {
410 - MainWP_Settings::init_subpages_menu();
411 - }
369 + if ( ! $empty_level && ! static::is_disable_menu_item( intval( $item['menu_level'] ), $item['slug'] ) && is_callable( $item['init_menu_callback'] ) ) {
370 + $accessable = false;
371 + if ( isset( $item['menu_rights'] ) ) {
372 + $item_rights = $item['menu_rights'];
373 + if ( is_array( $item_rights ) && ! empty( $item_rights ) ) {
374 + foreach ( $item_rights as $group_right => $rights ) {
375 + if ( is_array( $rights ) ) {
376 + foreach ( $rights as $func_right ) {
377 + if ( \mainwp_current_user_can( $group_right, $func_right ) ) {
378 + $accessable = true;
379 + break;
380 + }
381 + }
382 + }
383 + if ( $accessable ) {
384 + break;
385 + }
386 + }
387 + } elseif ( true === $item['menu_rights'] ) {
388 + $accessable = true;
389 + }
390 + }
412 391
413 - if ( ! self::is_disable_menu_item( 2, 'Extensions' ) ) {
414 - MainWP_Extensions::init_subpages_menu();
415 - }
416 - if ( ! self::is_disable_menu_item( 2, 'PageBulkManage' ) ) {
417 - MainWP_Page::init_subpages_menu();
418 - }
419 - if ( ! self::is_disable_menu_item( 2, 'ThemesManage' ) ) {
420 - MainWP_Themes::init_subpages_menu();
421 - }
422 - if ( ! self::is_disable_menu_item( 2, 'PluginsManage' ) ) {
423 - MainWP_Plugins::init_subpages_menu();
424 - }
425 - if ( ! self::is_disable_menu_item( 2, 'UserBulkManage' ) ) {
426 - MainWP_User::init_subpages_menu();
427 - }
428 - if ( ! self::is_disable_menu_item( 2, 'ManageClients' ) ) {
429 - MainWP_Client::init_subpages_menu();
430 - }
431 - if ( get_option( 'mainwp_enableLegacyBackupFeature' ) ) {
432 - if ( ! self::is_disable_menu_item( 2, 'ManageBackups' ) ) {
433 - MainWP_Manage_Backups::init_subpages_menu();
434 - }
435 - }
436 - if ( ! self::is_disable_menu_item( 2, 'Settings' ) ) {
437 - MainWP_Settings::init_subpages_menu();
438 - }
392 + if ( $accessable ) {
393 + call_user_func( $item['init_menu_callback'] );
394 + }
395 + }
396 + }
397 + }
439 398
440 - /**
441 - * Action: mainwp_admin_menu_sub
442 - *
443 - * Hooks main navigation sub-menu items.
444 - *
445 - * @since 4.0
446 - */
447 - do_action( 'mainwp_admin_menu_sub' );
399 + /**
400 + * Method set_menu_active_slugs
401 + *
402 + * @param string $item Menu item.
403 + * @param string $active Menu active slug.
404 + */
405 + public static function set_menu_active_slugs( $item, $active ) {
406 + global $_mainwp_menu_active_slugs;
407 + if ( ! is_array( $_mainwp_menu_active_slugs ) ) {
408 + $_mainwp_menu_active_slugs = array();
409 + }
410 + $_mainwp_menu_active_slugs[ $item ] = $active;
411 + }
448 412
449 - if ( ! self::is_disable_menu_item( 2, 'ServerInformation' ) ) {
450 - MainWP_Server_Information::init_subpages_menu();
451 - }
452 - }
453 413
454 - /**
455 - * Method set_menu_active_slugs
456 - *
457 - * @param string $item Menu item.
458 - * @param string $active Menu active slug.
459 - */
460 - public static function set_menu_active_slugs( $item, $active ) {
461 - global $_mainwp_menu_active_slugs;
462 - if ( ! is_array( $_mainwp_menu_active_slugs ) ) {
463 - $_mainwp_menu_active_slugs = array();
464 - }
465 - $_mainwp_menu_active_slugs[ $item ] = $active;
466 - }
414 + /**
415 + * Method init_subpages_left_menu
416 + *
417 + * Build left menu subpages array.
418 + *
419 + * @param array $subPages Array of SubPages.
420 + * @param array $initSubpage Initial SubPage Array.
421 + * @param string $parentKey Parent Menu Slug.
422 + * @param mixed $slug SubPage Slug.
423 + */
424 + public static function init_subpages_left_menu( $subPages, &$initSubpage, $parentKey, $slug ) { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR - complexity.
467 425
426 + if ( ! is_array( $subPages ) ) {
427 + $subPages = array();
428 + }
468 429
469 - /**
470 - * Method init_subpages_left_menu
471 - *
472 - * Build left menu subpages array.
473 - *
474 - * @param array $subPages Array of SubPages.
475 - * @param array $initSubpage Initial SubPage Array.
476 - * @param string $parentKey Parent Menu Slug.
477 - * @param mixed $slug SubPage Slug.
478 - */
479 - public static function init_subpages_left_menu( $subPages, &$initSubpage, $parentKey, $slug ) {
430 + global $_mainwp_menu_active_slugs;
480 431
481 - if ( ! is_array( $subPages ) ) {
482 - $subPages = array();
483 - }
432 + $subPages = apply_filters( 'mainwp_subpages_left_menu', $subPages, $initSubpage, $parentKey, $slug );
484 433
485 - global $_mainwp_menu_active_slugs;
434 + foreach ( $subPages as $subPage ) {
435 + if ( ! isset( $subPage['menu_hidden'] ) || ( isset( $subPage['menu_hidden'] ) && empty( $subPage['menu_hidden'] ) ) ) {
436 + $sub_slug = isset( $subPage['slug'] ) ? $subPage['slug'] : '';
437 + $_item = array(
438 + 'title' => isset( $subPage['title'] ) ? $subPage['title'] : '',
439 + 'parent_key' => $parentKey,
440 + 'href' => 'admin.php?page=' . $slug . $sub_slug,
441 + 'slug' => $slug . $sub_slug,
442 + 'right' => '',
443 + );
486 444
487 - $subPages = apply_filters( 'mainwp_subpages_left_menu', $subPages, $initSubpage, $parentKey, $slug );
445 + if ( ! empty( $subPage['before_title'] ) ) {
446 + $_item['before_title'] = $subPage['before_title'];
447 + }
488 448
489 - foreach ( $subPages as $subPage ) {
490 - if ( ! isset( $subPage['menu_hidden'] ) || ( isset( $subPage['menu_hidden'] ) && empty( $subPage['menu_hidden'] ) ) ) {
491 - $_item = array(
492 - 'title' => $subPage['title'],
493 - 'parent_key' => $parentKey,
494 - 'href' => 'admin.php?page=' . $slug . $subPage['slug'],
495 - 'slug' => $slug . $subPage['slug'],
496 - 'right' => '',
497 - );
449 + // To support check right to open menu for sometime.
450 + if ( isset( $subPage['item_slug'] ) ) {
451 + $_item['item_slug'] = $subPage['item_slug'];
452 + }
498 453
499 - if ( ! empty( $subPage['before_title'] ) ) {
500 - $item['before_title'] = $subPage['before_title'];
501 - }
454 + if ( isset( $subPage['href'] ) && ! empty( $subPage['href'] ) ) { // override href.
455 + $_item['href'] = $subPage['href'];
456 + }
502 457
503 - // To support check right to open menu for sometime.
504 - if ( isset( $subPage['item_slug'] ) ) {
505 - $_item['item_slug'] = $subPage['item_slug'];
506 - }
458 + $initSubpage[] = $_item;
459 + } elseif ( isset( $subPage['slug'] ) ) {
460 + $_mainwp_menu_active_slugs[ $slug . $subPage['slug'] ] = $parentKey; // to fix.
461 + }
462 + }
463 + }
507 464
508 - if ( isset( $subPage['href'] ) && ! empty( $subPage['href'] ) ) { // override href.
509 - $_item['href'] = $subPage['href'];
510 - }
465 + /**
466 + * Method is_disable_menu_item
467 + *
468 + * Check if $_mainwp_disable_menus_items contains any menu items to hide.
469 + *
470 + * @param string $level The level the menu item is on.
471 + * @param array|string $item The menu items meta data.
472 + *
473 + * @return bool True|False, default is False.
474 + */
475 + public static function is_disable_menu_item( $level, $item ) {
511 476
512 - $initSubpage[] = $_item;
513 - } elseif ( isset( $subPage['slug'] ) ) {
514 - $_mainwp_menu_active_slugs[ $slug . $subPage['slug'] ] = $parentKey; // to fix.
515 - }
516 - }
517 - }
477 + /**
478 + * MainWP Disable Menus items array.
479 + *
480 + * @global object
481 + */
482 + global $_mainwp_disable_menus_items;
483 + $disabled = false;
484 + $_level = 'level_' . $level;
485 + if ( is_array( $_mainwp_disable_menus_items ) && isset( $_mainwp_disable_menus_items[ $_level ] ) && isset( $_mainwp_disable_menus_items[ $_level ][ $item ] ) ) {
486 + $disabled = $_mainwp_disable_menus_items[ $_level ][ $item ];
487 + }
488 + $disabled = apply_filters( 'mainwp_is_disable_menu_item', $disabled, $level, $item );
489 + $_mainwp_disable_menus_items[ $_level ][ $item ] = $disabled;
490 + return $disabled;
491 + }
518 492
519 - /**
520 - * Method is_disable_menu_item
521 - *
522 - * Check if $_mainwp_disable_menus_items contains any menu items to hide.
523 - *
524 - * @param string $level The level the menu item is on.
525 - * @param array $item The menu items meta data.
526 - *
527 - * @return bool True|False, default is False.
528 - */
529 - public static function is_disable_menu_item( $level, $item ) {
493 + /**
494 + * Method add_left_menu
495 + *
496 + * Build Top Level Menu
497 + *
498 + * @param array $params Menu Item parameters.
499 + * @param integer $level Menu Item Level 1 or 2.
500 + *
501 + * @return array $mainwp_leftmenu[] | $mainwp_sub_leftmenu[].
502 + */
503 + public static function add_left_menu( $params = array(), $level = 1 ) { //phpcs:ignore -- NOSONAR - complex method.
530 504
531 - /**
532 - * MainWP Disable Menus items array.
533 - *
534 - * @global object
535 - */
536 - global $_mainwp_disable_menus_items;
537 - $disabled = false;
538 - $_level = 'level_' . $level;
539 - if ( is_array( $_mainwp_disable_menus_items ) && isset( $_mainwp_disable_menus_items[ $_level ] ) && isset( $_mainwp_disable_menus_items[ $_level ][ $item ] ) ) {
540 - $disabled = $_mainwp_disable_menus_items[ $_level ][ $item ];
541 - }
542 - $disabled = apply_filters( 'mainwp_is_disable_menu_item', $disabled, $level, $item );
543 - $_mainwp_disable_menus_items[ $_level ][ $item ] = $disabled;
544 - return $disabled;
545 - }
505 + if ( empty( $params ) ) {
506 + return;
507 + }
546 508
547 - /**
548 - * Method add_left_menu
549 - *
550 - * Build Top Level Menu
551 - *
552 - * @param array $params Menu Item parameters.
553 - * @param integer $level Menu Item Level 1 or 2.
554 - *
555 - * @return array $mainwp_leftmenu[] | $mainwp_sub_leftmenu[].
556 - */
557 - public static function add_left_menu( $params = array(), $level = 1 ) { //phpcs:ignore -- complex method.
509 + if ( ! empty( $params['menu_hidden'] ) ) {
510 + return;
511 + }
558 512
559 - if ( empty( $params ) ) {
560 - return;
561 - }
513 + $level = (int) $level;
562 514
563 - $level = (int) $level;
515 + if ( 1 !== $level && 2 !== $level && 0 !== $level ) {
516 + $level = 1;
517 + }
564 518
565 - if ( 1 !== $level && 2 !== $level && 0 !== $level ) {
566 - $level = 1;
567 - }
519 + $title = $params['title'];
520 + $before_title = ! empty( $params['before_title'] ) ? $params['before_title'] : '';
568 521
569 - $title = $params['title'];
570 - $before_title = ! empty( $params['before_title'] ) ? $params['before_title'] : '';
522 + $slug = isset( $params['slug'] ) ? $params['slug'] : '';
523 + $href = isset( $params['href'] ) ? $params['href'] : '';
524 + $right = isset( $params['right'] ) ? $params['right'] : '';
525 + $id = isset( $params['id'] ) ? $params['id'] : '';
526 + $level_cls = 'left-menu-item-level-' . $level;
571 527
572 - $slug = isset( $params['slug'] ) ? $params['slug'] : '';
573 - $href = $params['href'];
574 - $right = isset( $params['right'] ) ? $params['right'] : '';
575 - $id = isset( $params['id'] ) ? $params['id'] : '';
528 + if ( ! MainWP_Cache_Warm_Helper::is_excluded_warm_cache_pages() ) {
529 + $level_cls .= ' mainwp-js-prefetch ';
530 + }
576 531
577 - $icon = isset( $params['icon'] ) ? $params['icon'] : '';
578 - $leftsub_order = isset( $params['leftsub_order'] ) ? $params['leftsub_order'] : '';
579 - $leftsub_order_level2 = isset( $params['leftsub_order_level2'] ) ? $params['leftsub_order_level2'] : '';
580 - $ext_state = isset( $params['ext_status'] ) && ( 'activated' === $params['ext_status'] || 'inactive' === $params['ext_status'] ) ? $params['ext_status'] : '';
581 - $parent_key = isset( $params['parent_key'] ) ? $params['parent_key'] : '';
532 + $icon = isset( $params['icon'] ) ? $params['icon'] : '';
533 + $leftsub_order = isset( $params['leftsub_order'] ) ? $params['leftsub_order'] : '';
534 + $leftsub_order_level2 = isset( $params['leftsub_order_level2'] ) ? $params['leftsub_order_level2'] : '';
535 + $ext_state = isset( $params['ext_status'] ) && ( 'activated' === $params['ext_status'] || 'inactive' === $params['ext_status'] ) ? $params['ext_status'] : '';
536 + $parent_key = isset( $params['parent_key'] ) ? $params['parent_key'] : '';
537 + $others = array( 'level_class' => $level_cls );
582 538
583 - /**
584 - * MainWP Left Menu, Sub Menu & Active menu slugs.
585 - *
586 - * @global object $mainwp_leftmenu
587 - * @global object $mainwp_sub_leftmenu
588 - * @global object $_mainwp_menu_active_slugs
589 - */
590 - global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
539 + $others['classes_item'] = '';
540 + if ( ! empty( $params['classes_item'] ) ) {
541 + if ( is_array( $params['classes_item'] ) ) {
542 + $others['classes_item'] = implode( ' ', $params['classes_item'] );
543 + } elseif ( is_string( $params['classes_item'] ) ) {
544 + $others['classes_item'] = $params['classes_item'];
545 + }
546 + }
591 547
592 - if ( ! is_array( $mainwp_leftmenu ) ) {
593 - $mainwp_leftmenu = array();
594 - }
548 + $excluded_warm_cached_page = MainWP_Cache_Warm_Helper::is_excluded_warm_cache_pages();
595 549
596 - if ( ! isset( $mainwp_leftmenu['mainwp_tab'] ) ) {
597 - $mainwp_leftmenu['mainwp_tab'] = array(); // to compatible with old hooks.
598 - }
550 + /**
551 + * Menu excluded warm cache item.
552 + *
553 + * @since 5.5.
554 + */
555 + if ( ! apply_filters( 'mainwp_menu_excluded_warm_cache_item', $excluded_warm_cached_page, $params ) ) {
556 + $others['classes_item'] .= ' mainwp-js-prefetch ';
557 + }
599 558
600 - if ( ! is_array( $_mainwp_menu_active_slugs ) ) {
601 - $_mainwp_menu_active_slugs = array();
602 - }
559 + if ( isset( $params['active_params'] ) ) {
560 + $others['active_params'] = $params['active_params'];
561 + }
562 + if ( ! empty( $params['item_class'] ) ) {
563 + $others['item_class'] = $params['item_class'];
564 + }
603 565
604 - $active_path = false;
566 + /**
567 + * MainWP Left Menu, Sub Menu & Active menu slugs.
568 + *
569 + * @global object $mainwp_leftmenu
570 + * @global object $mainwp_sub_leftmenu
571 + * @global object $_mainwp_menu_active_slugs
572 + */
573 + global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
605 574
606 - if ( isset( $params['active_path'] ) && is_array( $params['active_path'] ) && ! empty( $params['active_path'] ) ) {
607 - $active_path = $params['active_path'];
608 - reset( $active_path );
609 - $item = key( $active_path );
610 - $active = current( $active_path );
611 - $_mainwp_menu_active_slugs['leftbar'][ $item ] = $active;
612 - $_mainwp_menu_active_slugs['parent_slug'][ $item ] = $parent_key;
613 - }
575 + if ( ! is_array( $mainwp_leftmenu ) ) {
576 + $mainwp_leftmenu = array();
577 + }
614 578
615 - if ( 0 === $level ) {
616 - $parent_key = 'mainwp_tab'; // forced value.
617 - $mainwp_leftmenu['leftbar'][] = array( $title, $slug, $href, $id, $icon );
618 - } elseif ( 1 === $level ) {
579 + if ( ! isset( $mainwp_leftmenu['mainwp_tab'] ) ) {
580 + $mainwp_leftmenu['mainwp_tab'] = array(); // to compatible with old hooks.
581 + }
619 582
620 - if ( empty( $parent_key ) ) {
621 - $parent_key = 'mainwp_tab'; // forced value.
622 - }
583 + if ( ! is_array( $_mainwp_menu_active_slugs ) ) {
584 + $_mainwp_menu_active_slugs = array();
585 + }
623 586
624 - if ( 'mainwp_tab' === $parent_key ) {
625 - $mainwp_leftmenu[ $parent_key ][] = array( $title, $slug, $href, $id );
626 - } else {
627 - $mainwp_sub_leftmenu['leftbar'][ $parent_key ][] = array( $title, $slug, $href, $id, $leftsub_order, $ext_state, $active_path );
587 + $active_path = false;
628 588
629 - if ( ! empty( $slug ) ) {
630 - $_mainwp_menu_active_slugs['leftbar'][ $slug ] = $parent_key; // to get active menu.
631 - }
632 - }
633 - } else {
634 - if ( empty( $parent_key ) ) {
635 - $parent_key = 'mainwp_tab'; // forced value.
636 - }
637 - $mainwp_sub_leftmenu[ $parent_key ][] = array( $title, $href, $right, $id, $slug, $leftsub_order_level2, $ext_state, $active_path, $before_title );
638 - }
589 + if ( isset( $params['active_path'] ) && is_array( $params['active_path'] ) && ! empty( $params['active_path'] ) ) {
590 + $active_path = $params['active_path'];
591 + reset( $active_path );
592 + $item = key( $active_path );
593 + $active = current( $active_path );
594 + $_mainwp_menu_active_slugs['leftbar'][ $item ] = $active;
595 + $_mainwp_menu_active_slugs['parent_slug'][ $item ] = $parent_key;
596 + }
639 597
640 - if ( ! empty( $slug ) ) {
641 - $no_submenu = ! empty( $params['nosubmenu'] ) ? true : false;
642 - if ( $no_submenu ) {
643 - $_mainwp_menu_active_slugs[ $slug ] = $slug; // to get active menu.
644 - } else {
645 - $_mainwp_menu_active_slugs[ $slug ] = $parent_key; // to get active menu.
646 - }
647 - }
648 - }
598 + if ( 0 === $level ) {
599 + $parent_key = 'mainwp_tab'; // forced value.
600 + $mainwp_leftmenu['leftbar'][] = array( $title, $slug, $href, $id, $icon, $level_cls );
601 + } elseif ( 1 === $level ) {
649 602
650 - /**
651 - * Method render_left_menu
652 - *
653 - * Build Top Level Main Menu HTML & Render.
654 - */
655 - public static function render_left_menu() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
603 + if ( empty( $parent_key ) ) {
604 + $parent_key = 'mainwp_tab'; // forced value.
605 + }
656 606
657 - /**
658 - * MainWP Left Menu, Sub Menu & Active menu slugs.
659 - *
660 - * @global object $mainwp_leftmenu
661 - * @global object $mainwp_sub_leftmenu
662 - * @global object $_mainwp_menu_active_slugs
663 - */
664 - global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs, $plugin_page;
607 + if ( 'mainwp_tab' === $parent_key ) {
608 + $mainwp_leftmenu[ $parent_key ][] = array( $title, $slug, $href, $id, $level_cls );
609 + } else {
610 + $mainwp_sub_leftmenu['leftbar'][ $parent_key ][] = array( $title, $slug, $href, $id, $leftsub_order, $ext_state, $active_path, $level_cls );
665 611
666 - /**
667 - * Filter: mainwp_main_menu
668 - *
669 - * Filters main navigation menu items
670 - *
671 - * @since 4.0
672 - */
673 - $mainwp_leftmenu = apply_filters( 'mainwp_main_menu', $mainwp_leftmenu );
674 - $main_leftmenu = isset( $mainwp_leftmenu['mainwp_tab'] ) ? $mainwp_leftmenu['mainwp_tab'] : array();
675 - $bar_leftmenu = isset( $mainwp_leftmenu['leftbar'] ) ? $mainwp_leftmenu['leftbar'] : array();
612 + if ( ! empty( $slug ) ) {
613 + $_mainwp_menu_active_slugs['leftbar'][ $slug ] = $parent_key; // to get active menu.
614 + }
615 + }
616 + } else {
617 + if ( empty( $parent_key ) ) {
618 + $parent_key = 'mainwp_tab'; // forced value.
619 + }
620 + $mainwp_sub_leftmenu[ $parent_key ][] = array( $title, $href, $right, $id, $slug, $leftsub_order_level2, $ext_state, $active_path, $before_title, $others );
621 + }
676 622
677 - /**
678 - * Filter: mainwp_main_menu_submenu
679 - *
680 - * Filters main navigation subt-menu items
681 - *
682 - * @since 4.0
683 - */
623 + if ( ! empty( $slug ) ) {
624 + $no_submenu = ! empty( $params['nosubmenu'] ) ? true : false;
625 + if ( $no_submenu ) {
626 + $_mainwp_menu_active_slugs[ $slug ] = $slug; // to get active menu.
627 + } else {
628 + $_mainwp_menu_active_slugs[ $slug ] = $parent_key; // to get active menu.
629 + }
630 + }
631 + }
684 632
685 - $mainwp_sub_leftmenu = apply_filters( 'mainwp_main_menu_submenu', $mainwp_sub_leftmenu );
686 - $sub_bar_leftmenu = isset( $mainwp_sub_leftmenu['leftbar'] ) ? $mainwp_sub_leftmenu['leftbar'] : array();
633 + /**
634 + * Method render_left_menu
635 + *
636 + * Build Top Level Main Menu HTML & Render.
637 + */
638 + public static function render_left_menu() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
687 639
688 - $version = get_option( 'mainwp_plugin_version' );
640 + /**
641 + * MainWP Left Menu, Sub Menu & Active menu slugs.
642 + *
643 + * @global object $mainwp_leftmenu
644 + * @global object $mainwp_sub_leftmenu
645 + * @global object $_mainwp_menu_active_slugs
646 + */
647 + global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs, $plugin_page;
689 648
690 - ?>
691 - <?php
692 - /**
693 - * Action: before_mainwp_menu
694 - *
695 - * Fires before the main navigation element.
696 - *
697 - * @since 4.0
698 - */
699 - do_action( 'before_mainwp_menu' );
700 - ?>
701 - <div id="mainwp-main-navigation-container">
702 - <div id="mainwp-first-level-navigation">
703 - <div id="mainwp-first-level-navigation-logo">
704 - <a href="
705 - <?php
706 - /**
707 - * Filter: mainwp_menu_logo_href
708 - *
709 - * Filters the Logo link.
710 - *
711 - * @since 4.1.4
712 - */
713 - echo esc_url( apply_filters( 'mainwp_menu_logo_href', admin_url( 'admin.php?page=mainwp_tab' ) ) );
714 - ?>
715 - ">
716 - <img src="
717 - <?php
718 - /**
719 - * Filter: mainwp_menu_logo_src
720 - *
721 - * Filters the Logo src attribute.
722 - *
723 - * @since 4.1
724 - */
725 - echo esc_url( apply_filters( 'mainwp_menu_logo_src', MAINWP_PLUGIN_URL . 'assets/images/mainwp-icon.svg' ) );
726 - ?>
727 - " alt="
728 - <?php
729 - /**
730 - * Filter: mainwp_menu_logo_alt
731 - *
732 - * Filters the Logo alt attribute.
733 - *
734 - * @since 4.1
735 - */
736 - echo esc_html( apply_filters( 'mainwp_menu_logo_alt', 'MainWP' ) );
737 - ?>
738 - " id="mainwp-navigation-icon" />
739 - </a>
740 - </div>
741 - <div id="mainwp-first-level-navigation-version-label">
742 - <span id="mainwp-version-label" class="ui mini green fluid centered label"><?php echo esc_html( $version ); ?></span>
743 - </div>
744 - <div id="mainwp-first-level-navigation-menu" class="ui vertical labeled inverted icon tiny menu">
745 - <?php
649 + /**
650 + * Filter: mainwp_main_menu
651 + *
652 + * Filters main navigation menu items
653 + *
654 + * @since 4.0
655 + */
656 + $mainwp_leftmenu = apply_filters( 'mainwp_main_menu', $mainwp_leftmenu );
657 + $bar_leftmenu = isset( $mainwp_leftmenu['leftbar'] ) ? $mainwp_leftmenu['leftbar'] : array();
746 658
747 - $bar_item_actived_key = '';
748 - if ( is_array( $_mainwp_menu_active_slugs ) && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
749 - $menu_item_actived_key = $_mainwp_menu_active_slugs[ $plugin_page ];
750 - if ( isset( $_mainwp_menu_active_slugs['leftbar'] ) && is_array( $_mainwp_menu_active_slugs['leftbar'] ) && isset( $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ] ) ) {
751 - $bar_item_actived_key = $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ];
752 - }
753 - }
659 + /**
660 + * Filter: mainwp_main_menu_submenu
661 + *
662 + * Filters main navigation subt-menu items
663 + *
664 + * @since 4.0
665 + */
754 666
755 - $bar_item_active = null;
667 + $mainwp_sub_leftmenu = apply_filters( 'mainwp_main_menu_submenu', $mainwp_sub_leftmenu );
668 + $sub_bar_leftmenu = isset( $mainwp_sub_leftmenu['leftbar'] ) ? $mainwp_sub_leftmenu['leftbar'] : array();
756 669
757 - $sites_count = MainWP_DB::instance()->get_websites_count();
758 - if ( empty( $sites_count ) ) {
759 - ?>
760 - <a style="background: #FFD300 !important;" id="leftbar-item-quick-setup" title="<?php esc_html_e( 'Quick Setup', 'mainwp' ); ?>" class="item" href="admin.php?page=mainwp-setup">
761 - <i class="magic large icon"></i><span class="ui small text"><?php esc_html_e( 'Quick Setup', 'mainwp' ); ?></span>
762 - </a>
763 - <?php
764 - }
670 + if ( is_array( $mainwp_sub_leftmenu ) && ! empty( $mainwp_sub_leftmenu['Extensions'] ) ) {
671 + $add_on_items = $mainwp_sub_leftmenu['Extensions'];
765 672
766 - if ( is_array( $bar_leftmenu ) && ! empty( $bar_leftmenu ) ) {
767 - foreach ( $bar_leftmenu as $item ) {
768 - $title = wptexturize( $item[0] );
769 - $item_key = $item[1];
770 - $href = $item[2];
771 - $item_id = isset( $item[3] ) ? $item[3] : '';
772 - $item_icon = isset( $item[4] ) ? $item[4] : '';
673 + $head = array_shift( $add_on_items );
674 + // sort the rest by first element.
675 + usort(
676 + $add_on_items,
677 + function ( $a, $b ) {
678 + return strcmp( (string) $a[0], (string) $b[0] );
679 + }
680 + );
681 + // put the head back.
682 + array_unshift( $add_on_items, $head );
773 683
774 - $has_sub = true;
775 - if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
776 - $has_sub = false;
777 - }
778 - $active_item = '';
684 + $mainwp_sub_leftmenu['Extensions'] = $add_on_items;
685 + }
779 686
780 - if ( empty( $bar_item_actived_key ) ) {
781 - if ( isset( $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) ) {
782 - if ( $item_key === $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) {
783 - $bar_item_actived_key = $item_key;
784 - }
785 - } elseif ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
786 - if ( $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
787 - $bar_item_actived_key = $item_key;
788 - }
789 - }
790 - }
687 + $version = get_option( 'mainwp_plugin_version' );
791 688
792 - if ( ! empty( $bar_item_actived_key ) && $item_key === $bar_item_actived_key ) {
793 - $active_item = 'active';
794 - $bar_item_active = $item;
795 - }
689 + ?>
690 + <?php
691 + /**
692 + * Action: before_mainwp_menu
693 + *
694 + * Fires before the main navigation element.
695 + *
696 + * @since 4.0
697 + */
698 + do_action( 'before_mainwp_menu' );
699 + ?>
700 + <div id="mainwp-main-navigation-container">
701 + <div id="mainwp-first-level-navigation">
702 + <div id="mainwp-first-level-navigation-menu" class="ui vertical labeled inverted icon tiny menu">
703 + <?php
796 704
797 - $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
705 + $bar_item_actived_key = '';
706 + if ( is_array( $_mainwp_menu_active_slugs ) && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
707 + $menu_item_actived_key = $_mainwp_menu_active_slugs[ $plugin_page ];
708 + if ( isset( $_mainwp_menu_active_slugs['leftbar'] ) && is_array( $_mainwp_menu_active_slugs['leftbar'] ) && isset( $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ] ) ) {
709 + $bar_item_actived_key = $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ];
710 + }
711 + }
798 712
799 - // phpcs:disable WordPress.Security.EscapeOutput
800 - if ( $has_sub ) {
801 - echo '<a ' . $id_attr . ' title="' . esc_html( $title ) . "\" class=\"item $active_item\" href=\"$href\">";
802 - echo ! empty( $item_icon ) ? $item_icon : '<i class="th large icon"></i>';
803 - echo '<span class="ui small text">' . esc_html( $title ) . '</span>';
804 - echo '</a>';
805 - } else {
806 - echo '<a ' . $id_attr . ' title="' . esc_html( $title ) . "\" class=\"item $active_item\" href=\"$href\">";
807 - echo ! empty( $item_icon ) ? $item_icon : '<i class="th large icon"></i>';
808 - echo '<span class="ui small text">' . esc_html( $title ) . '</span>';
809 - echo '</a>';
810 - }
811 - // phpcs:enable
812 - }
813 - }
814 - ?>
815 - </div>
816 - <?php
817 - $go_back_wpadmin_url = admin_url( 'index.php' );
713 + $bar_item_active = null;
818 714
819 - $link = array(
820 - 'url' => $go_back_wpadmin_url,
821 - 'text' => esc_html__( 'WP Admin', 'mainwp' ),
822 - 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
823 - );
824 - /**
825 - * Filter: mainwp_go_back_wpadmin_link
826 - *
827 - * Filters URL for the Go to WP Admin button in Main navigation.
828 - *
829 - * @since 4.0
830 - */
831 - $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
715 + $sites_count = MainWP_DB::instance()->get_websites_count();
716 + if ( empty( $sites_count ) ) {
717 + ?>
718 + <a style="background: #FFD300 !important;" id="leftbar-item-quick-setup" title="<?php esc_html_e( 'Quick Setup', 'mainwp' ); ?>" class="item" href="admin.php?page=mainwp-setup">
719 + <i class="magic large icon"></i><span class="ui small text"><?php esc_html_e( 'Quick Setup', 'mainwp' ); ?></span>
720 + </a>
721 + <?php
722 + }
832 723
833 - if ( false !== $go_back_link ) {
834 - if ( is_array( $go_back_link ) ) {
835 - if ( isset( $go_back_link['url'] ) ) {
836 - $link['url'] = $go_back_link['url'];
837 - }
838 - if ( isset( $go_back_link['text'] ) ) {
839 - $link['text'] = $go_back_link['text'];
840 - }
841 - if ( isset( $go_back_link['tip'] ) ) {
842 - $link['tip'] = $go_back_link['tip'];
843 - }
844 - }
845 - }
846 - ?>
847 - <div id="mainwp-first-level-wpitems-menu" class="ui vertical labeled inverted icon mini menu">
848 - <a class="item" href="#" id="mainwp-collapse-second-level-navigation">
849 - <i class="double angle left icon"></i>
850 - </a>
851 - </div>
852 - </div>
853 - <div id="mainwp-second-level-navigation">
854 - <div id="mainwp-main-menu" class="ui inverted vertical accordion menu">
855 - <?php
856 - $bar_active_item_key = '';
724 + if ( is_array( $bar_leftmenu ) && ! empty( $bar_leftmenu ) ) {
725 + foreach ( $bar_leftmenu as $item ) {
726 + $title = wptexturize( $item[0] );
727 + $item_key = $item[1];
728 + $href = $item[2];
729 + $item_id = isset( $item[3] ) ? $item[3] : '';
730 + $item_icon = isset( $item[4] ) ? $item[4] : '';
731 + $level_cls = isset( $item[5] ) ? $item[5] : '';
857 732
858 - $set_actived = false;
733 + $has_sub = true;
734 + if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
735 + $has_sub = false;
736 + }
737 + $active_item = '';
859 738
860 - if ( ! empty( $bar_item_active ) ) {
861 - $item = $bar_item_active;
862 - $title = wptexturize( $item[0] );
863 - $item_key = $item[1];
864 - $href = $item[2];
865 - $item_id = isset( $item[3] ) ? $item[3] : '';
739 + if ( empty( $bar_item_actived_key ) ) {
740 + if ( isset( $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) ) {
741 + if ( $item_key === $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) {
742 + $bar_item_actived_key = $item_key;
743 + }
744 + } elseif ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
745 + if ( $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
746 + $bar_item_actived_key = $item_key;
747 + }
748 + }
749 + }
866 750
867 - $bar_active_item_key = $item_key;
751 + if ( ! empty( $bar_item_actived_key ) && $item_key === $bar_item_actived_key ) {
752 + $active_item = 'active';
753 + $bar_item_active = $item;
754 + }
868 755
869 - $has_sub = true;
870 - if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
871 - $has_sub = false;
872 - }
873 - $active_item = '';
756 + $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
874 757
875 - if ( ! $set_actived ) {
876 - if ( isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) ) {
877 - if ( $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
878 - $active_item = 'active';
879 - $set_actived = true;
880 - $bar_item_active = $item;
881 - }
882 - }
883 - }
758 + $item_cls = $level_cls . ' ' . $active_item;
884 759
885 - // to fix active menu.
886 - if ( ! $set_actived ) {
887 - if ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
888 - if ( $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
889 - $active_item = 'active';
890 - $set_actived = true;
891 - $bar_item_active = $item;
892 - }
893 - }
894 - }
760 + // phpcs:disable WordPress.Security.EscapeOutput
761 + echo '<a ' . $id_attr . ' title="' . esc_html( $title ) . '" class="item ' . esc_attr( $item_cls ) . "\" href=\"$href\">";
762 + echo ! empty( $item_icon ) ? $item_icon : '<i class="th large icon"></i>';
763 + echo '<span class="ui small text">' . esc_html( $title ) . '</span>';
764 + echo '</a>';
765 + // phpcs:enable
766 + }
767 + }
768 + ?>
769 + </div>
770 + <?php
771 + $all_updates = wp_get_update_data();
772 + $go_back_wpadmin_url = admin_url( 'index.php' );
895 773
896 - $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
774 + $link = array(
775 + 'url' => $go_back_wpadmin_url,
776 + 'text' => esc_html__( 'WP Admin', 'mainwp' ),
777 + 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
778 + );
779 + /**
780 + * Filter: mainwp_go_back_wpadmin_link
781 + *
782 + * Filters URL for the Go to WP Admin button in Main navigation.
783 + *
784 + * @since 4.0
785 + */
786 + $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
897 787
898 - // phpcs:disable WordPress.Security.EscapeOutput
899 - if ( $has_sub ) {
900 - echo '<div ' . $id_attr . " class=\"item $active_item\">";
901 - echo "<a class=\"title with-sub $active_item\" href=\"$href\">$title <i class=\"dropdown icon\"></i></a>";
902 - echo "<div class=\"content menu $active_item\">";
903 - self::render_sub_item( $item_key );
904 - echo '</div>';
905 - echo '</div>';
906 - } else {
907 - echo '<div ' . $id_attr . ' class="item">';
908 - echo "<a class='title $active_item' href=\"$href\">$title</a>";
909 - echo '</div>';
910 - }
911 - // phpcs:enable
788 + if ( false !== $go_back_link && is_array( $go_back_link ) ) {
789 + if ( isset( $go_back_link['url'] ) ) {
790 + $link['url'] = $go_back_link['url'];
791 + }
792 + if ( isset( $go_back_link['text'] ) ) {
793 + $link['text'] = $go_back_link['text'];
794 + }
795 + if ( isset( $go_back_link['tip'] ) ) {
796 + $link['tip'] = $go_back_link['tip'];
797 + }
798 + }
799 + ?>
800 + <div id="mainwp-support-menu">
801 + <a class="mainwp-help-menu-item-open" id="mainwp-help-menu-item" title="<?php esc_attr_e( 'Support', 'mainwp' ); ?>" href="#">
802 + <i class="question circle outline icon"></i><br/>
803 + <span class="ui small text"><?php esc_html_e( 'Support', 'mainwp' ); ?></span>
804 + </a>
805 + <?php if ( MainWP_Utility::show_mainwp_message( 'notice', 'mainwp_support_popup' ) ) : ?>
806 + <span class="ui mainwp-help-popup popup" style="width: 200px !important;">
807 + <em data-emoji=":ring_buoy:" class="large"></em>
808 + <h4 class="ui large header"><?php esc_html_e( 'Feeling stuck?', 'mainwp' ); ?></h4>
809 + <p><?php esc_html_e( 'Help is just a click away.', 'mainwp' ); ?></p>
810 + <a class="ui mini green button mainwp-notice-dismiss" notice-id="mainwp_support_popup" href="#"><?php esc_html_e( 'Thanks!', 'mainwp' ); ?></a>
811 + </span>
812 + <script>
813 + jQuery(document).ready(function() {
814 + jQuery('.mainwp-help-menu-item-open').popup({
815 + popup : jQuery('.mainwp-help-popup'),
816 + delay : { show: 2000 },
817 + distanceAway : 10,
818 + closable: false,
819 + position : 'top left',
820 + }).popup('show');
912 821
913 - if ( is_array( $sub_bar_leftmenu ) && ! empty( $bar_active_item_key ) && isset( $sub_bar_leftmenu[ $bar_active_item_key ] ) && is_array( $sub_bar_leftmenu[ $bar_active_item_key ] ) ) {
914 - $sub_bar_leftmenu_active_items = $sub_bar_leftmenu[ $bar_active_item_key ];
915 - MainWP_Utility::array_sort_existed_keys( $sub_bar_leftmenu_active_items, 4 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 4 => 'leftsub_order'.
916 - $set_actived = false;
917 - foreach ( $sub_bar_leftmenu_active_items as $item ) {
822 + jQuery('.mainwp-help-popup .mainwp-notice-dismiss').on('click', function (e) {
823 + jQuery('.mainwp-help-popup').removeClass('visible').addClass('hidden').hide();
918 824
919 - if ( empty( $item ) || ! is_array( $item ) ) {
920 - continue;
921 - }
825 + });
826 + });
827 + </script>
828 + <?php endif; ?>
829 + </div>
830 + <div id="mainwp-first-level-navigation-version-label">
831 + <?php if ( is_array( $all_updates ) && isset( $all_updates['counts']['total'] ) && 0 < $all_updates['counts']['total'] ) : ?>
832 + <a class="ui tiny red fluid centered pulse looping transition label" id="mainwp-dashboard-update-available" data-inverted="" data-position="left center" data-tooltip="<?php esc_attr_e( 'Your MainWP Dashboard sites needs your attention. Please check the available updates', 'mainwp' ); ?>" aria-label="<?php esc_attr_e( 'Your MainWP Dashboard sites needs your attention. Please check the available updates', 'mainwp' ); ?>" href="update-core.php">
833 + <i class="exclamation triangle icon" style="color:#fff"></i> <?php esc_html_e( 'Update Dashboard Site', 'mainwp' ); ?>
834 + </a>
835 + <?php endif; ?>
836 + <div id="mainwp-version-label" class="ui tiny green fluid centered label"><?php echo esc_html( $version ); ?></div>
837 + </div>
838 + </div>
839 + <div id="mainwp-divider-handle">
840 + <div id="mainwp-collapse-second-level-navigation" aria-label="<?php esc_attr_e( 'Collapse menu.', 'mainwp' ); ?>">
841 + <i class="double angle left small icon"></i>
842 + </div>
843 + </div>
844 + <div id="mainwp-second-level-navigation">
845 + <div id="mainwp-main-menu" class="mainwp-main-navigation-menu ui inverted vertical accordion menu">
846 + <?php
847 + $bar_active_item_key = '';
922 848
923 - $title = wptexturize( $item[0] );
924 - $item_key = $item[1];
849 + $set_actived = false;
925 850
926 - $has_sub = true;
927 - if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
928 - $has_sub = false;
929 - }
851 + if ( ! empty( $bar_item_active ) ) {
852 + $item = $bar_item_active;
853 + $title = wptexturize( $item[0] );
854 + $item_key = $item[1];
855 + $item_id = isset( $item[3] ) ? $item[3] : '';
856 + $level_cls = isset( $item[5] ) ? $item[5] : '';
930 857
931 - $href = $item[2];
932 - $item_id = isset( $item[3] ) ? $item[3] : '';
933 - $ext_state = isset( $item[5] ) ? $item[5] : '';
934 - $active_path = isset( $item[6] ) ? $item[6] : '';
858 + $bar_active_item_key = $item_key;
935 859
936 - $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
860 + $has_sub = true;
861 + if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
862 + $has_sub = false;
863 + }
864 + $active_item = '';
937 865
938 - $active_item = '';
866 + if ( ! $set_actived && isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
867 + $active_item = 'active';
868 + $set_actived = true;
869 + }
939 870
940 - if ( ! $set_actived ) {
941 - if ( isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) ) {
942 - if ( $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
943 - $active_item = 'active';
944 - $set_actived = true;
945 - }
946 - }
947 - }
871 + // to fix active menu.
872 + if ( ! $set_actived && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
873 + $active_item = 'active';
874 + $set_actived = true;
875 + }
948 876
949 - // to fix active menu.
950 - if ( ! $set_actived ) {
951 - if ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
952 - if ( $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
953 - $active_item = 'active';
954 - $set_actived = true;
955 - }
956 - }
957 - }
877 + $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
958 878
959 - $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
879 + // phpcs:disable WordPress.Security.EscapeOutput
880 + if ( $has_sub ) {
881 + echo '<div ' . $id_attr . " class=\"item $active_item " . esc_attr( $level_cls ) . ' ">';
882 + echo "<a class=\"title with-sub $active_item\" href=\"javascript:void(0)\">$title <i class=\"dropdown icon\"></i></a>";
883 + echo "<div class=\"content menu $active_item\">";
884 + static::render_sub_item( $item_key );
885 + echo '</div>';
886 + echo '</div>';
887 + } else {
888 + echo '<div ' . $id_attr . ' class="item ' . esc_attr( $level_cls ) . '">';
889 + echo "<a class='title $active_item' href=\"javascript:void(0)\">$title</a>";
890 + echo '</div>';
891 + }
892 + // phpcs:enable
960 893
961 - $hide_item = '';
962 - if ( 'admin.php?page=ManageApiBackups' === $href ) {
963 - $hide_item = ' style="display:none"';
964 - }
894 + if ( is_array( $sub_bar_leftmenu ) && ! empty( $bar_active_item_key ) && isset( $sub_bar_leftmenu[ $bar_active_item_key ] ) && is_array( $sub_bar_leftmenu[ $bar_active_item_key ] ) ) {
895 + $sub_bar_leftmenu_active_items = $sub_bar_leftmenu[ $bar_active_item_key ];
896 + MainWP_Utility::array_sort_existed_keys( $sub_bar_leftmenu_active_items, 4 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 4 => 'leftsub_order'.
897 + $set_actived = false;
898 + foreach ( $sub_bar_leftmenu_active_items as $item ) {
965 899
966 - // phpcs:disable WordPress.Security.EscapeOutput
967 - if ( $has_sub ) {
968 - echo '<div ' . $id_attr . " class=\"item $active_item $item_classes\">";
969 - echo "<a class=\"title with-sub $active_item\" href=\"$href\">$title <i class=\"dropdown icon\"></i></a>";
970 - echo "<div class=\"content menu $active_item\">";
971 - self::render_sub_item( $item_key );
972 - echo '</div>';
973 - echo '</div>';
974 - } else {
975 - echo '<div ' . $id_attr . $hide_item . " class=\"item $active_item $item_classes\">";
976 - echo "<a class='title $active_item' href=\"$href\">$title</a>";
977 - echo '</div>';
978 - }
979 - // phpcs:enable
980 - }
981 - }
982 - }
983 - ?>
984 - </div>
985 - </div>
986 - </div>
900 + if ( empty( $item ) || ! is_array( $item ) ) {
901 + continue;
902 + }
987 903
988 - <?php
989 - /**
990 - * Action: after_mainwp_menu
991 - *
992 - * Fires after the main navigation element.
993 - *
994 - * @since 4.0
995 - */
996 - do_action( 'after_mainwp_menu' );
997 - ?>
998 - <script type="text/javascript">
999 - jQuery( document ).ready( function () {
904 + $title = wptexturize( $item[0] );
905 + $item_key = $item[1];
1000 906
1001 - mainwp_left_bar_showhide_init = function(){
1002 - if(jQuery('body').hasClass('mainwp-hidden-second-level-navigation')){
1003 - return; // hide always.
1004 - }
1005 - if(jQuery('body').hasClass('toplevel_page_mainwp_tab')){
1006 - return; // hide always.
1007 - }
1008 - var lbar = jQuery( '#mainwp-collapse-second-level-navigation' );
1009 - var show = ( 0 != mainwp_ui_state_load( 'showmenu' ) ) ? true : false;
1010 - mainwp_left_bar_showhide( lbar, show);
1011 - }
1012 - mainwp_left_bar_showhide = function( lbar, show ){
1013 - if ( show ) {
1014 - jQuery( '#mainwp-second-level-navigation' ).show();
1015 - jQuery( '.mainwp-content-wrap' ).css( "margin-left", "272px" );
1016 - jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "272px" );
1017 - jQuery( '#mainwp-main-navigation-container' ).css( "width", "272px" );
1018 - jQuery( lbar ).find( '.icon' ).removeClass( 'right' );
1019 - jQuery( lbar ).find( '.icon' ).addClass( 'left' );
1020 - jQuery( lbar ).css( "left", "272px" );
1021 - jQuery( lbar ).removeClass( 'collapsed' );
1022 - mainwp_ui_state_save( 'showmenu', 1 );
1023 - } else {
1024 - jQuery( '#mainwp-second-level-navigation' ).hide();
1025 - jQuery( '.mainwp-content-wrap' ).css( "margin-left", "72px" );
1026 - jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "72px" );
1027 - jQuery( '#mainwp-main-navigation-container' ).css( "width", "72px" );
1028 - jQuery( lbar ).find( '.icon' ).removeClass( 'left' );
1029 - jQuery( lbar ).find( '.icon' ).addClass( 'right' );
1030 - jQuery( lbar ).css( "left", "72px" );
1031 - jQuery( lbar ).addClass( 'collapsed' );
1032 - jQuery( '#mainwp-top-header' ).css( "width", "100%" );
1033 - mainwp_ui_state_save( 'showmenu', 0 );
1034 - }
1035 - }
907 + $has_sub = true;
908 + if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
909 + $has_sub = false;
910 + }
1036 911
1037 - jQuery( '#mainwp-collapse-second-level-navigation' ).on( 'click', function() {
1038 - var show = jQuery( this ).hasClass( 'collapsed' ) ? true : false;
1039 - mainwp_left_bar_showhide( this, show);
1040 - return false;
1041 - } );
1042 - mainwp_left_bar_showhide_init();
912 + $href = $item[2];
913 + $item_id = isset( $item[3] ) ? $item[3] : '';
914 + $ext_state = isset( $item[5] ) ? $item[5] : '';
915 + $level_cls = isset( $item[7] ) ? $item[7] : '';
1043 916
1044 - // click on menu with-sub icon.
1045 - jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.with-sub .icon' ).on( "click", function ( event ) {
1046 - var pr = jQuery( this ).closest( '.item' );
1047 - var title = jQuery( this ).closest( '.title' );
1048 - var active = jQuery( title ).hasClass( 'active' );
917 + $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
1049 918
1050 - // remove current active.
1051 - mainwp_menu_collapse();
919 + $active_item = '';
1052 920
1053 - // if current menu item are not active then set it active.
1054 - if ( !active ) {
1055 - jQuery( title ).addClass( 'active' );
1056 - jQuery( pr ).find('.content.menu').addClass( 'active' );
1057 - pr.addClass('active');
1058 - }
1059 - return false;
1060 - } );
921 + if ( ! $set_actived && isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
922 + $active_item = 'active';
923 + $set_actived = true;
924 + }
1061 925
1062 - jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.with-sub' ).on( "click", function ( event ) {
1063 - var pr = jQuery( this ).closest( '.item' );
1064 - var active = jQuery( this ).hasClass( 'active' );
926 + // to fix active menu.
927 + if ( ! $set_actived && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
928 + $active_item = 'active';
929 + $set_actived = true;
930 + }
1065 931
1066 - // remove current active.
1067 - mainwp_menu_collapse();
932 + $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
1068 933
1069 - // set active before go to the page.
1070 - if ( !active ) {
1071 - jQuery( this ).addClass( 'active' );
1072 - jQuery( pr ).find('.content.menu').addClass( 'active' );
1073 - pr.addClass('active');
1074 - }
1075 - } );
934 + $hide_item = '';
935 + if ( 'admin.php?page=ManageApiBackups' === $href ) {
936 + $hide_item = ' style="display:none"';
937 + }
1076 938
1077 - mainwp_menu_collapse = function() {
1078 - // remove current active.
1079 - jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.active').removeClass('active');
1080 - jQuery( '#mainwp-main-navigation-container #mainwp-main-menu .item').removeClass('active');
1081 - jQuery( '#mainwp-main-navigation-container #mainwp-main-menu .content.menu.active').removeClass('active');
1082 - };
939 + if ( ! empty( $level_cls ) ) {
940 + $item_classes = $item_classes . ' ' . $level_cls;
941 + }
1083 942
1084 - jQuery('.mainwp-main-mobile-navigation-container #mainwp-main-menu').accordion();
943 + // phpcs:disable WordPress.Security.EscapeOutput
944 + if ( $has_sub ) {
945 + echo '<div ' . $id_attr . " class=\"item $active_item $item_classes\">";
946 + echo "<a class=\"title with-sub $active_item\" href=\"javascript:void(0)\">$title <i class=\"dropdown icon\"></i></a>";
947 + echo "<div class=\"content menu $active_item\">";
948 + static::render_sub_item( $item_key );
949 + echo '</div>';
950 + echo '</div>';
951 + } else {
952 + echo '<div ' . $id_attr . $hide_item . " class=\"item $active_item $item_classes\">";
953 + echo "<a class='title $active_item' href=\"javascript:void(0)\">$title</a>";
954 + echo '</div>';
955 + }
956 + // phpcs:enable
957 + }
958 + }
959 + }
960 + ?>
961 + </div>
962 + </div>
963 + </div>
1085 964
1086 - } );
1087 - </script>
1088 - <?php
1089 - }
965 + <?php
966 + /**
967 + * Action: after_mainwp_menu
968 + *
969 + * Fires after the main navigation element.
970 + *
971 + * @since 4.0
972 + */
973 + do_action( 'after_mainwp_menu' );
974 + ?>
975 + <script type="text/javascript">
1090 976
1091 - /**
1092 - * Method render_mobile_menu
1093 - *
1094 - * Renders the mobile menu.
1095 - */
1096 - public static function render_mobile_menu() { // phpcs:ignore -- Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1097 - $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
1098 - ?>
1099 - <div class="mainwp-main-mobile-navigation-container">
1100 - <div id="mainwp-logo">
1101 - <a href="
1102 - <?php
1103 - /**
1104 - * Filter: mainwp_menu_logo_href
1105 - *
1106 - * Filters the Logo link.
1107 - *
1108 - * @since 4.1.4
1109 - */
1110 - echo esc_url( apply_filters( 'mainwp_menu_logo_href', admin_url( 'admin.php?page=mainwp_tab' ) ) );
1111 - ?>
1112 - ">
1113 - <img src="
1114 - <?php
1115 - /**
1116 - * Filter: mainwp_menu_logo_src
1117 - *
1118 - * Filters the Logo src attribute.
1119 - *
1120 - * @since 4.1
1121 - */
1122 - echo esc_url( apply_filters( 'mainwp_menu_logo_src', MAINWP_PLUGIN_URL . 'assets/images/logo.png' ) );
1123 - ?>
1124 - " alt="
1125 - <?php
1126 - /**
1127 - * Filter: mainwp_menu_logo_alt
1128 - *
1129 - * Filters the Logo alt attribute.
1130 - *
1131 - * @since 4.1
1132 - */
1133 - echo apply_filters( 'mainwp_menu_logo_alt', 'MainWP' ); // phpcs:ignore WordPress.Security.EscapeOutput
1134 - ?>
1135 - " id="mainwp-navigation-icon"/>
1136 - </a>
1137 - </div>
1138 - <div class="mainwp-nav-menu">
1139 - <?php
1140 - /**
1141 - * Action: before_mainwp_menu
1142 - *
1143 - * Fires before the main navigation element.
1144 - *
1145 - * @since 4.0
1146 - */
1147 - do_action( 'before_mainwp_menu' );
1148 - ?>
977 + jQuery( document ).ready( function () {
1149 978
1150 - <div id="mainwp-main-menu" class="test-menu ui inverted vertical accordion menu">
1151 - <div class="item"></div>
1152 - <div class="item"><a href="admin.php?page=mainwp_tab"><?php esc_html_e( 'Overview', 'mainwp' ); ?></a></div>
1153 - <div class="item">
1154 - <div class="title"><a href="admin.php?page=managesites" class=" with-sub"><?php esc_html_e( 'Sites', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1155 - <div class="content menu" id="mainwp-sites-mobile-menu-item">
1156 - <div class="accordion item">
1157 - <div class="title"><a href="admin.php?page=managesites"><?php esc_html_e( 'Sites', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1158 - <div class="content menu">
1159 - <a class="item" href="admin.php?page=managesites"><?php esc_html_e( 'Manage Sites', 'mainwp' ); ?></a>
1160 - <a class="item" href="admin.php?page=managesites&do=new"><?php esc_html_e( 'Add New Site', 'mainwp' ); ?></a>
1161 - <a class="item" href="admin.php?page=managesites&do=bulknew"><?php esc_html_e( 'Import Sites', 'mainwp' ); ?></a>
1162 - <a class="item" href="admin.php?page=MonitoringSites"><?php esc_html_e( 'Monitoring', 'mainwp' ); ?></a>
1163 - </div>
1164 - </div>
1165 - <div class="item accordion">
1166 - <div class="title"><a class="" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Tags', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1167 - <div class="content menu">
1168 - <a class="item" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Manage Tags', 'mainwp' ); ?></a>
1169 - </div>
1170 - </div>
1171 - <div class="item accordion">
1172 - <div class="title"><a href="admin.php?page=UpdatesManage"><?php esc_html_e( 'Updates', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1173 - <div class="content menu">
1174 - <a class="item" href="admin.php?page=UpdatesManage&tab=plugins-updates"><?php esc_html_e( 'Plugins Updates', 'mainwp' ); ?></a>
1175 - <a class="item" href="admin.php?page=UpdatesManage&tab=themes-updates"><?php esc_html_e( 'Themes Updates', 'mainwp' ); ?></a>
1176 - <a class="item" href="admin.php?page=UpdatesManage&tab=wordpress-updates"><?php esc_html_e( 'WordPress Updates', 'mainwp' ); ?></a>
1177 - <?php if ( $mainwp_show_language_updates ) : ?>
1178 - <a class="item" href="admin.php?page=UpdatesManage&tab=translations-updates"><?php esc_html_e( 'Translation Plugins', 'mainwp' ); ?></a>
1179 - <?php endif; ?>
1180 - <a class="item" href="admin.php?page=UpdatesManage&tab=abandoned-plugins"><?php esc_html_e( 'Abandoned Plugins', 'mainwp' ); ?></a>
1181 - <a class="item" href="admin.php?page=UpdatesManage&tab=abandoned-themes"><?php esc_html_e( 'Abandoned Themes', 'mainwp' ); ?></a>
1182 - </div>
1183 - </div>
1184 - <div class="item accordion">
1185 - <div class="title"><a href="admin.php?page=PluginsManage"><?php esc_html_e( 'Plugins', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1186 - <div class="content menu">
1187 - <a class="item" href="admin.php?page=PluginsManage"><?php esc_html_e( 'Manage Plugins', 'mainwp' ); ?></a>
1188 - <a class="item" href="admin.php?page=PluginsInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1189 - <a class="item" href="admin.php?page=PluginsAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1190 - <a class="item" href="admin.php?page=PluginsIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1191 - <a class="item" href="admin.php?page=PluginsIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1192 - </div>
1193 - </div>
1194 - <div class="item accordion">
1195 - <div class="title"><a href="admin.php?page=ThemesManage"><?php esc_html_e( 'Themes', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1196 - <div class="content menu">
1197 - <a class="item" href="admin.php?page=ThemesManage"><?php esc_html_e( 'Manage Themes', 'mainwp' ); ?></a>
1198 - <a class="item" href="admin.php?page=ThemesInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1199 - <a class="item" href="admin.php?page=ThemesAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1200 - <a class="item" href="admin.php?page=ThemesIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1201 - <a class="item" href="admin.php?page=ThemesIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1202 - </div>
1203 - </div>
1204 - <div class="item accordion">
1205 - <div class="title"><a href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Users', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1206 - <div class="content menu">
1207 - <a class="item" href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Manage Users', 'mainwp' ); ?></a>
1208 - <a class="item" href="admin.php?page=UserBulkAdd"><?php esc_html_e( 'Add New User', 'mainwp' ); ?></a>
1209 - <a class="item" href="admin.php?page=BulkImportUsers"><?php esc_html_e( 'Import Users', 'mainwp' ); ?></a>
1210 - <a class="item" href="admin.php?page=UpdateAdminPasswords"><?php esc_html_e( 'Admin Passwords', 'mainwp' ); ?></a>
1211 - </div>
1212 - </div>
1213 - <div class="item accordion">
1214 - <div class="title"><a href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Posts', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1215 - <div class="content menu">
1216 - <a class="item" href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Manage Pages', 'mainwp' ); ?></a>
1217 - <a class="item" href="admin.php?page=PostBulkAdd"><?php esc_html_e( 'Add New Post', 'mainwp' ); ?></a>
1218 - </div>
1219 - </div>
1220 - <div class="item accordion">
1221 - <div class="title"><a href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Pages', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1222 - <div class="content menu">
1223 - <a class="item" href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Manage Pages', 'mainwp' ); ?></a>
1224 - <a class="item" href="admin.php?page=PageBulkAdd"><?php esc_html_e( 'Add New Page', 'mainwp' ); ?></a>
1225 - </div>
1226 - </div>
1227 - <div class="item accordion">
1228 - <div class="title"><a href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1229 - <div class="content menu">
1230 - <a class="item" href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a>
1231 - </div>
1232 - </div>
1233 - </div>
1234 - </div>
1235 - <div class="item">
1236 - <div class="title"><a href="admin.php?page=ManageClients" class="with-sub"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1237 - <div class="content menu">
1238 - <a class="item" href="admin.php?page=ManageClients"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a>
1239 - <a class="item" href="admin.php?page=ClientAddNew"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
1240 - <a class="item" href="admin.php?page=ClientAddField"><?php esc_html_e( 'Client Fields', 'mainwp' ); ?></a>
1241 - </div>
1242 - </div>
979 + setTimeout(() => {
980 + jQuery('#mainwp-dashboard-update-available').removeClass('looping');
981 + }, 1500);
1243 982
1244 - <div class="item">
1245 - <div class="title"><a href="admin.php?page=ManageCostTracker" class="with-sub"><?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1246 - <div class="content menu">
1247 - <a class="item" href="admin.php?page=ManageCostTracker"><?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?></a>
1248 - <a class="item" href="admin.php?page=CostTrackerAdd"><?php esc_html_e( 'Add Cost', 'mainwp' ); ?></a>
1249 - <a class="item" href="admin.php?page=CostTrackerSettings"><?php esc_html_e( 'Cost Tracker Settings', 'mainwp' ); ?></a>
1250 - </div>
1251 - </div>
983 + let mainwp_left_bar_showhide_init = function(){
984 + if(jQuery('body').hasClass('mainwp-hidden-second-level-navigation')){
985 + return; // hide always.
986 + }
987 + if(jQuery('body').hasClass('toplevel_page_mainwp_tab')){
988 + return; // hide always.
989 + }
990 + let lbar = jQuery( '#mainwp-collapse-second-level-navigation' );
991 + let show = ( typeof mainwp_ui_state_load !== 'undefined' ) && 0 != mainwp_ui_state_load( 'showmenu' );
992 + mainwp_left_bar_showhide( lbar, show);
993 + }
994 + mainwp_left_bar_showhide = function( lbar, show ){
995 + if ( show ) {
996 + jQuery( '#mainwp-second-level-navigation' ).show();
997 + jQuery( '.mainwp-content-wrap' ).css( "margin-left", "272px" );
998 + //jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "272px" );
999 + jQuery( '#mainwp-main-navigation-container' ).css( "width", "272px" );
1000 + jQuery( lbar ).find( '.icon' ).removeClass( 'right' );
1001 + jQuery( lbar ).find( '.icon' ).addClass( 'left' );
1002 + jQuery( lbar ).parent('#mainwp-divider-handle').css( "left", "200px" );
1003 + jQuery( lbar ).removeClass( 'collapsed' );
1004 + if( ( typeof mainwp_ui_state_save !== 'undefined' ) ) {
1005 + mainwp_ui_state_save( 'showmenu', 1 );
1006 + }
1007 + } else {
1008 + jQuery( '#mainwp-second-level-navigation' ).hide();
1009 + jQuery( '.mainwp-content-wrap' ).css( "margin-left", "72px" );
1010 + //jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "72px" );
1011 + jQuery( '#mainwp-main-navigation-container' ).css( "width", "72px" );
1012 + jQuery( lbar ).find( '.icon' ).removeClass( 'left' );
1013 + jQuery( lbar ).find( '.icon' ).addClass( 'right' );
1014 + jQuery( lbar ).parent('#mainwp-divider-handle').css( "left", "0px" );
1015 + jQuery( lbar ).addClass( 'collapsed' );
1016 + jQuery( '#mainwp-top-header' ).css( "width", "100%" );
1017 + if( ( typeof mainwp_ui_state_save !== 'undefined' ) ) {
1018 + mainwp_ui_state_save( 'showmenu', 0 );
1019 + }
1020 + }
1021 + }
1252 1022
1253 - <div class="item">
1254 - <div class="title"><a href="admin.php?page=InsightsOverview" class="with-sub"><?php esc_html_e( 'Insights', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1255 - <div class="content menu">
1256 - <a class="item" href="admin.php?page=InsightsOverview"><?php esc_html_e( 'Insights', 'mainwp' ); ?></a>
1257 - </div>
1258 - </div>
1023 + jQuery( '#mainwp-collapse-second-level-navigation' ).on( 'click', function() {
1024 + let show = jQuery( this ).hasClass( 'collapsed' ) ? true : false;
1025 + mainwp_left_bar_showhide( this, show);
1026 + return false;
1027 + } );
1028 + mainwp_left_bar_showhide_init();
1259 1029
1260 - <div class="item">
1261 - <div class="title"><a href="admin.php?page=RESTAPI" class="with-sub"><?php esc_html_e( 'REST API', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1262 - <div class="content menu">
1263 - <a class="item" href="admin.php?page=RESTAPI"><?php esc_html_e( 'Manage API Keys', 'mainwp' ); ?></a>
1264 - <a class="item" href="admin.php?page=AddApiKeys"><?php esc_html_e( 'Add API Keys', 'mainwp' ); ?></a>
1265 - </div>
1266 - </div>
1267 - <div class="item">
1268 - <div class="title"><a href="admin.php?page=Extensions" class=""><?php esc_html_e( 'Extensions', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1269 - <div class="content menu">
1270 - <a class="item" href="admin.php?page=Extensions"><?php esc_html_e( 'Manage Extensions', 'mainwp' ); ?></a>
1271 - </div>
1272 - </div>
1273 - <div class="item">
1274 - <div class="title"><a href="admin.php?page=Settings" class="with-sub"><?php esc_html_e( 'Settings', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1275 - <div class="content menu">
1276 - <a class="item" href="admin.php?page=Settings"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a>
1277 - <a class="item" href="admin.php?page=SettingsAdvanced"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a>
1278 - <a class="item" href="admin.php?page=SettingsEmail"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a>
1279 - <a class="item" href="admin.php?page=MainWPTools"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a>
1280 - </div>
1281 - </div>
1282 - <div class="item">
1283 - <div class="title"><a href="admin.php?page=ServerInformation" class="with-sub"><?php esc_html_e( 'Info', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1284 - <div class="content menu">
1285 - <a class="item" href="admin.php?page=ServerInformation"><?php esc_html_e( 'Server', 'mainwp' ); ?></a>
1286 - <a class="item" href="admin.php?page=ServerInformationCron"><?php esc_html_e( 'Cron Schedules', 'mainwp' ); ?></a>
1287 - <a class="item" href="admin.php?page=ErrorLog"><?php esc_html_e( 'Error Log', 'mainwp' ); ?></a>
1288 - <a class="item" href="admin.php?page=ActionLogs"><?php esc_html_e( 'Custom Event Monitor', 'mainwp' ); ?></a>
1289 - <a class="item" href="admin.php?page=PluginPrivacy"><?php esc_html_e( 'Plugin Privacy', 'mainwp' ); ?></a>
1290 - </div>
1291 - </div>
1292 - <?php
1293 - $go_back_wpadmin_url = admin_url( 'index.php' );
1030 + // click on menu with-sub icon.
1031 + jQuery( '#mainwp-main-navigation-container .mainwp-main-navigation-menu a.title.with-sub .icon' ).on( "click", function ( event ) {
1032 + let pr = jQuery( this ).closest( '.item' );
1033 + let title = jQuery( this ).closest( '.title' );
1034 + let active = jQuery( title ).hasClass( 'active' );
1294 1035
1295 - $link = array(
1296 - 'url' => $go_back_wpadmin_url,
1297 - 'text' => esc_html__( 'WP Admin', 'mainwp' ),
1298 - 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
1299 - );
1036 + // remove current active.
1037 + mainwp_menu_collapse();
1300 1038
1301 - /**
1302 - * Filter: mainwp_go_back_wpadmin_link
1303 - *
1304 - * Filters URL for the Go to WP Admin button in Main navigation.
1305 - *
1306 - * @since 4.0
1307 - */
1308 - $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
1039 + // if current menu item are not active then set it active.
1040 + if ( !active ) {
1041 + jQuery( title ).addClass( 'active' );
1042 + jQuery( pr ).find('.content.menu').addClass( 'active' );
1043 + pr.addClass('active');
1044 + }
1045 + return false;
1046 + } );
1309 1047
1310 - if ( false !== $go_back_link ) {
1311 - if ( is_array( $go_back_link ) ) {
1312 - if ( isset( $go_back_link['url'] ) ) {
1313 - $link['url'] = $go_back_link['url'];
1314 - }
1315 - if ( isset( $go_back_link['text'] ) ) {
1316 - $link['text'] = $go_back_link['text'];
1317 - }
1318 - if ( isset( $go_back_link['tip'] ) ) {
1319 - $link['tip'] = $go_back_link['tip'];
1320 - }
1321 - }
1322 - ?>
1323 - <div class="item item-wp-admin">
1324 - <a href="<?php echo esc_html( $link['url'] ); ?>" class="title" style="display:inline" data-position="top left" data-tooltip="<?php echo esc_html( $link['tip'] ); ?>"><b><i class="icon wordpress"></i> <?php echo esc_html( $link['text'] ); ?></b></a> <a class="ui small label" data-position="top right" data-tooltip="<?php esc_html_e( 'Logout', 'mainwp' ); ?>" href="<?php echo wp_logout_url(); ?>"><i class="sign out icon" style="margin:0"></i></a> <?php //phpcs:ignore -- to avoid auto fix icon wordpress ?>
1325 - </div>
1326 - <?php } ?>
1327 - <div class="hamburger">
1328 - <span class="hamburger-bun"></span>
1329 - <span class="hamburger-patty"></span>
1330 - <span class="hamburger-bun"></span>
1331 - </div>
1332 - </div>
1333 - <?php
1334 - /**
1335 - * Action: after_mainwp_menu
1336 - *
1337 - * Fires after the main navigation element.
1338 - *
1339 - * @since 4.0
1340 - */
1341 - do_action( 'after_mainwp_menu' );
1342 - ?>
1343 - </div>
1344 - </div>
1345 - <?php
1346 - }
1048 + jQuery( '#mainwp-main-navigation-container .mainwp-main-navigation-menu a.title.with-sub' ).on( "click", function ( event ) {
1049 + let pr = jQuery( this ).closest( '.item' );
1050 + let active = jQuery( this ).hasClass( 'active' );
1347 1051
1348 - /**
1349 - * Method render_sub_item
1350 - *
1351 - * Grabs all submenu items and attatches to Main Menu.
1352 - *
1353 - * @param mixed $parent_key The parent key.
1354 - */
1355 - public static function render_sub_item( $parent_key ) { //phpcs:ignore -- complex method.
1356 - if ( empty( $parent_key ) ) {
1357 - return;
1358 - }
1052 + // remove current active.
1053 + mainwp_menu_collapse();
1359 1054
1360 - /**
1361 - * MainWP Left Menu.
1362 - *
1363 - * @global object $mainwp_sub_leftmenu
1364 - */
1365 - global $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
1055 + // set active before go to the page.
1056 + if ( !active ) {
1057 + jQuery( this ).addClass( 'active' );
1058 + jQuery( pr ).find('.content.menu').addClass( 'active' );
1059 + pr.addClass('active');
1060 + }
1061 + } );
1366 1062
1367 - $submenu_items = $mainwp_sub_leftmenu[ $parent_key ];
1063 + mainwp_menu_collapse = function() {
1064 + // remove current active.
1065 + jQuery( '#mainwp-main-navigation-container .mainwp-main-navigation-menu a.title.active').removeClass('active');
1066 + jQuery( '#mainwp-main-navigation-container .mainwp-main-navigation-menu .item').removeClass('active');
1067 + jQuery( '#mainwp-main-navigation-container .mainwp-main-navigation-menu .content.menu.active').removeClass('active');
1068 + };
1368 1069
1369 - if ( ! is_array( $submenu_items ) || 0 === count( $submenu_items ) ) {
1370 - return;
1371 - }
1070 + jQuery( '#mainwp-main-mobile-navigation-container .accordion.menu' ).accordion();
1372 1071
1373 - global $plugin_page;
1072 + } );
1073 + </script>
1074 + <?php
1075 + }
1374 1076
1375 - $set_actived = false;
1077 + /**
1078 + * Method render_mobile_menu
1079 + *
1080 + * Renders the mobile menu.
1081 + */
1082 + public static function render_mobile_menu() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1083 + $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
1084 + ?>
1085 + <div id="mainwp-overlay"></div>
1086 + <div id="mainwp-main-mobile-navigation-container" class="mainwp-main-mobile-navigation-container ui top fullscreen flyout">
1087 + <div class="mainwp-nav-menu scrolling content">
1088 + <?php
1089 + /**
1090 + * Action: before_mainwp_menu
1091 + *
1092 + * Fires before the main navigation element.
1093 + *
1094 + * @since 4.0
1095 + */
1096 + do_action( 'before_mainwp_menu' );
1097 + ?>
1376 1098
1377 - MainWP_Utility::array_sort_existed_keys( $submenu_items, 5 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 5 => 'leftsub_order_level2'.
1099 + <div id="mainwp-main-menu-mobile" class="mainwp-main-navigation-menu test-menu ui inverted vertical accordion menu">
1100 + <div class="item"><a href="admin.php?page=mainwp_tab"><i class="th icon"></i> <?php esc_html_e( 'Operations', 'mainwp' ); ?></a></div>
1378 1101
1379 - foreach ( $submenu_items as $sub_key => $sub_item ) {
1380 - $title = $sub_item[0];
1381 - $href = $sub_item[1];
1382 - $right = $sub_item[2];
1383 - $id = isset( $sub_item[3] ) ? $sub_item[3] : '';
1384 - $slug = isset( $sub_item[4] ) ? $sub_item[4] : '';
1385 - $ext_state = isset( $sub_item[6] ) ? $sub_item[6] : '';
1386 - $active_path = isset( $sub_item[7] ) ? $sub_item[7] : '';
1387 - $before_title = isset( $sub_item[8] ) ? $sub_item[8] : '';
1102 + <div class="item">
1103 + <div class="title"><a href="admin.php?page=managesites" class="with-sub"><i class="globe left floated icon"></i> <?php esc_html_e( 'Sites', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1104 + <div class="content menu" id="mainwp-sites-mobile-menu-item">
1105 + <div class="item">
1106 + <div class="title"><a href="admin.php?page=managesites"><?php esc_html_e( 'Sites', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1107 + <div class="content menu">
1108 + <a class="item" href="admin.php?page=managesites"><?php esc_html_e( 'Manage Sites', 'mainwp' ); ?></a>
1109 + <a class="item" href="admin.php?page=managesites&do=new"><?php esc_html_e( 'Add New Site', 'mainwp' ); ?></a>
1110 + <a class="item" href="admin.php?page=managesites&do=bulknew"><?php esc_html_e( 'Import Sites', 'mainwp' ); ?></a>
1111 + <a class="item" href="admin.php?page=MonitoringSites"><?php esc_html_e( 'Monitoring', 'mainwp' ); ?></a>
1112 + </div>
1113 + </div>
1114 + <div class="item">
1115 + <div class="title"><a class="" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Tags', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1116 + <div class="content menu">
1117 + <a class="item" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Manage Tags', 'mainwp' ); ?></a>
1118 + </div>
1119 + </div>
1120 + <div class="item">
1121 + <div class="title"><a href="admin.php?page=UpdatesManage"><?php esc_html_e( 'Updates', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1122 + <div class="content menu">
1123 + <a class="item" href="admin.php?page=UpdatesManage&tab=plugins-updates"><?php esc_html_e( 'Plugin Updates', 'mainwp' ); ?></a>
1124 + <a class="item" href="admin.php?page=UpdatesManage&tab=themes-updates"><?php esc_html_e( 'Theme Updates', 'mainwp' ); ?></a>
1125 + <a class="item" href="admin.php?page=UpdatesManage&tab=wordpress-updates"><?php esc_html_e( 'WordPress Updates', 'mainwp' ); ?></a>
1126 + <?php if ( $mainwp_show_language_updates ) : ?>
1127 + <a class="item" href="admin.php?page=UpdatesManage&tab=translations-updates"><?php esc_html_e( 'Translation Plugins', 'mainwp' ); ?></a>
1128 + <?php endif; ?>
1129 + <a class="item" href="admin.php?page=PluginsAbandoned"><?php esc_html_e( 'Abandoned Plugins', 'mainwp' ); ?></a>
1130 + <a class="item" href="admin.php?page=ThemesAbandoned"><?php esc_html_e( 'Abandoned Themes', 'mainwp' ); ?></a>
1131 + </div>
1132 + </div>
1133 + <div class="item">
1134 + <div class="title"><a href="admin.php?page=PluginsManage"><?php esc_html_e( 'Plugins', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1135 + <div class="content menu">
1136 + <a class="item" href="admin.php?page=PluginsManage"><?php esc_html_e( 'Manage Plugins', 'mainwp' ); ?></a>
1137 + <a class="item" href="admin.php?page=PluginsInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1138 + <a class="item" href="admin.php?page=PluginsAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1139 + <a class="item" href="admin.php?page=PluginsIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1140 + <a class="item" href="admin.php?page=PluginsIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1141 + </div>
1142 + </div>
1143 + <div class="item">
1144 + <div class="title"><a href="admin.php?page=ThemesManage"><?php esc_html_e( 'Themes', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1145 + <div class="content menu">
1146 + <a class="item" href="admin.php?page=ThemesManage"><?php esc_html_e( 'Manage Themes', 'mainwp' ); ?></a>
1147 + <a class="item" href="admin.php?page=ThemesInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1148 + <a class="item" href="admin.php?page=ThemesAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1149 + <a class="item" href="admin.php?page=ThemesIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1150 + <a class="item" href="admin.php?page=ThemesIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1151 + </div>
1152 + </div>
1153 + <div class="item">
1154 + <div class="title"><a href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Users', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1155 + <div class="content menu">
1156 + <a class="item" href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Manage Users', 'mainwp' ); ?></a>
1157 + <a class="item" href="admin.php?page=UserBulkAdd"><?php esc_html_e( 'Add New User', 'mainwp' ); ?></a>
1158 + <a class="item" href="admin.php?page=BulkImportUsers"><?php esc_html_e( 'Import Users', 'mainwp' ); ?></a>
1159 + <a class="item" href="admin.php?page=UpdateAdminPasswords"><?php esc_html_e( 'Admin Passwords', 'mainwp' ); ?></a>
1160 + </div>
1161 + </div>
1162 + <div class="item">
1163 + <div class="title"><a href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Posts', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1164 + <div class="content menu">
1165 + <a class="item" href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Manage Posts', 'mainwp' ); ?></a>
1166 + <a class="item" href="admin.php?page=PostBulkAdd"><?php esc_html_e( 'Add New Post', 'mainwp' ); ?></a>
1167 + </div>
1168 + </div>
1169 + <div class="item">
1170 + <div class="title"><a href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Pages', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1171 + <div class="content menu">
1172 + <a class="item" href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Manage Pages', 'mainwp' ); ?></a>
1173 + <a class="item" href="admin.php?page=PageBulkAdd"><?php esc_html_e( 'Add New Page', 'mainwp' ); ?></a>
1174 + </div>
1175 + </div>
1176 + <div class="item">
1177 + <div class="title"><a href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1178 + <div class="content menu">
1179 + <a class="item" href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a>
1180 + </div>
1181 + </div>
1182 + </div>
1183 + </div>
1388 1184
1389 - $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
1185 + <div class="item">
1186 + <div class="title"><a href="admin.php?page=ManageClients" class="with-sub"><i class="users icon"></i> <?php esc_html_e( 'Clients', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1187 + <div class="content menu">
1188 + <a class="item" href="admin.php?page=ManageClients"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a>
1189 + <a class="item" href="admin.php?page=ClientAddNew"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
1190 + <a class="item" href="admin.php?page=ClientAddField"><?php esc_html_e( 'Client Fields', 'mainwp' ); ?></a>
1191 + </div>
1192 + </div>
1390 1193
1391 - $_blank = false;
1392 - if ( '_blank' === $id ) {
1393 - $_blank = true;
1394 - }
1194 + <div class="item">
1195 + <div class="title"><a href="admin.php?page=ManageCostTracker" class="with-sub"><i class="dollar sign icon"></i> <?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1196 + <div class="content menu">
1197 + <a class="item" href="admin.php?page=CostSummary"><?php esc_html_e( 'Cost Summary', 'mainwp' ); ?></a>
1198 + <a class="item" href="admin.php?page=ManageCostTracker"><?php esc_html_e( 'Manage Costs', 'mainwp' ); ?></a>
1199 + <a class="item" href="admin.php?page=CostTrackerAdd"><?php esc_html_e( 'Add Cost', 'mainwp' ); ?></a>
1200 + </div>
1201 + </div>
1395 1202
1396 - $level2_active = false;
1203 + <div class="item">
1204 + <div class="title"><a href="admin.php?page=InsightsOverview" class="with-sub"><i class="chart pie icon"></i> <?php esc_html_e( 'Insights', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1205 + <div class="content menu">
1206 + <a class="item" href="admin.php?page=InsightsOverview"><?php esc_html_e( 'Insights', 'mainwp' ); ?></a>
1207 + </div>
1208 + </div>
1397 1209
1398 - if ( ! $set_actived ) {
1399 - $level2_active = self::is_level2_menu_item_active( $href ) ? true : false;
1400 - if ( is_array( $active_path ) && ! empty( $active_path ) ) {
1401 - reset( $active_path );
1402 - $item = key( $active_path );
1403 - if ( $item === $plugin_page ) {
1404 - $level2_active = true;
1405 - }
1406 - }
1407 - // hard fix managesite menu items active status.
1408 - //phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1409 - if ( false !== strpos( $href, 'admin.php?page=managesites' ) ) {
1410 - $page_name = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : '';
1411 - $level2_active = false;
1412 - if ( isset( $_GET['do'] ) && 'new' === $_GET['do'] && false !== strpos( $href, 'admin.php?page=managesites&do=new' ) ) {
1413 - $level2_active = true;
1414 - } elseif ( isset( $_GET['do'] ) && 'bulknew' === $_GET['do'] && false !== strpos( $href, 'admin.php?page=managesites&do=bulknew' ) ) {
1415 - $level2_active = true;
1416 - } elseif ( ! isset( $_GET['do'] ) && 'NonMainWPChanges' !== $page_name && 'admin.php?page=managesites' === $href ) {
1417 - $level2_active = true;
1418 - }
1419 - }
1420 - //phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1421 - if ( $level2_active ) {
1422 - $set_actived = true;
1423 - }
1424 - }
1210 + <div class="item">
1211 + <div class="title"><a href="admin.php?page=Extensions" class=""><i class="box icon"></i> <?php esc_html_e( 'Add-ons', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1212 + <div class="content menu">
1213 + <a class="item" href="admin.php?page=Extensions"><?php esc_html_e( 'Manage Add-ons', 'mainwp' ); ?></a>
1214 + </div>
1215 + </div>
1425 1216
1426 - $right_group = 'dashboard';
1427 - if ( ! empty( $right ) ) {
1428 - if ( strpos( $right, 'extension_' ) === 0 ) {
1429 - $right_group = 'extension';
1430 - $right = str_replace( 'extension_', '', $right );
1431 - }
1432 - }
1433 - if ( empty( $right ) || ( ! empty( $right ) && mainwp_current_user_have_right( $right_group, $right ) ) ) {
1434 - ?>
1435 - <a class="item <?php echo $level2_active ? 'active level-two-active' : ''; ?> <?php echo esc_attr( $item_classes ); ?>" href="<?php echo esc_url( $href ); ?>" id="<?php echo esc_attr( $slug ); ?>" <?php echo $_blank ? 'target="_blank"' : ''; ?>>
1436 - <?php echo $before_title . $title; //phpcs:ignore -- requires escaped. ?>
1437 - </a>
1217 + <div class="item">
1218 + <div class="title"><a href="admin.php?page=RESTAPI" class="with-sub"><i class="key icon"></i> <?php esc_html_e( 'REST API', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1219 + <div class="content menu">
1220 + <a class="item" href="admin.php?page=RESTAPI"><?php esc_html_e( 'Manage API Keys', 'mainwp' ); ?></a>
1221 + <a class="item" href="admin.php?page=AddApiKeys"><?php esc_html_e( 'Add API Keys', 'mainwp' ); ?></a>
1222 + <a class="item" href="admin.php?page=ApplicationPasswords"><?php esc_html_e( 'Application Passwords', 'mainwp' ); ?></a>
1223 + </div>
1224 + </div>
1438 1225
1439 - <?php
1440 - }
1441 - }
1442 - }
1226 + <div class="item">
1227 + <div class="title"><a href="admin.php?page=Settings" class="with-sub"><i class="cog icon"></i> <?php esc_html_e( 'Settings', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1228 + <div class="content menu">
1229 + <a class="item" href="admin.php?page=Settings"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a>
1230 + <a class="item" href="admin.php?page=SettingsAdvanced"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a>
1231 + <a class="item" href="admin.php?page=MonitoringSettings"><?php esc_html_e( 'Monitoring Settings', 'mainwp' ); ?></a>
1232 + <a class="item" href="admin.php?page=SettingsEmail"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a>
1233 + <a class="item" href="admin.php?page=PremiumUpdates"><?php esc_html_e( 'Premium Updates', 'mainwp' ); ?></a>
1234 + <a class="item" href="admin.php?page=MainWPTools"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a>
1235 + </div>
1236 + </div>
1443 1237
1238 + <div class="item">
1239 + <div class="title"><a href="admin.php?page=ServerInformation" class="with-sub"><i class="info circle icon"></i> <?php esc_html_e( 'Info', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1240 + <div class="content menu">
1241 + <a class="item" href="admin.php?page=ServerInformation"><?php esc_html_e( 'Server', 'mainwp' ); ?></a>
1242 + <a class="item" href="admin.php?page=ServerInformationCron"><?php esc_html_e( 'Cron Schedules', 'mainwp' ); ?></a>
1243 + <a class="item" href="admin.php?page=ErrorLog"><?php esc_html_e( 'Error Log', 'mainwp' ); ?></a>
1244 + <a class="item" href="admin.php?page=ActionLogs"><?php esc_html_e( 'Custom Event Monitor', 'mainwp' ); ?></a>
1245 + <a class="item" href="admin.php?page=PluginPrivacy"><?php esc_html_e( 'Plugin Privacy', 'mainwp' ); ?></a>
1246 + </div>
1247 + </div>
1248 + </div>
1249 + <?php
1250 + /**
1251 + * Action: after_mainwp_menu
1252 + *
1253 + * Fires after the main navigation element.
1254 + *
1255 + * @since 4.0
1256 + */
1257 + do_action( 'after_mainwp_menu' );
1258 + ?>
1259 + </div>
1260 + <div class="actions">
1261 + <?php
1262 + $go_back_wpadmin_url = admin_url( 'index.php' );
1444 1263
1445 - /**
1446 - * Method is_level2_menu_item_active().
1447 - *
1448 - * Check if menu item level 2 is active.
1449 - *
1450 - * @param mixed $href The href value.
1451 - */
1452 - public static function is_level2_menu_item_active( $href ) {
1453 - $current_path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
1454 - $san_path = $current_path;
1264 + $link = array(
1265 + 'url' => $go_back_wpadmin_url,
1266 + 'text' => esc_html__( 'WP Admin', 'mainwp' ),
1267 + 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
1268 + );
1455 1269
1456 - if ( 0 === stripos( $san_path, '/wp-admin/' ) ) {
1457 - $san_path = str_replace( '/wp-admin/', '', $san_path );
1458 - }
1270 + /**
1271 + * Filter: mainwp_go_back_wpadmin_link
1272 + *
1273 + * Filters URL for the Go to WP Admin button in Main navigation.
1274 + *
1275 + * @since 4.0
1276 + */
1277 + $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
1459 1278
1460 - $orther = '';
1461 - if ( 0 === stripos( $san_path, $href ) ) {
1462 - $orther = str_replace( $href, '', $san_path );
1463 - }
1279 + if ( false !== $go_back_link ) {
1280 + if ( is_array( $go_back_link ) ) {
1281 + if ( isset( $go_back_link['url'] ) ) {
1282 + $link['url'] = $go_back_link['url'];
1283 + }
1284 + if ( isset( $go_back_link['text'] ) ) {
1285 + $link['text'] = $go_back_link['text'];
1286 + }
1287 + if ( isset( $go_back_link['tip'] ) ) {
1288 + $link['tip'] = $go_back_link['tip'];
1289 + }
1290 + }
1291 + }
1292 + ?>
1293 + <div class="ui three column grid">
1294 + <div class="column">
1295 + <a href="<?php echo esc_url( $link['url'] ); ?>" class="ui mini basic fluid button small text"><i class="icon wordpress"></i> <?php echo esc_html( $link['text'] ); ?></a><?php //phpcs:ignore -- to avoid auto fix icon wordpress. ?>
1296 + </div>
1297 + <div class="column">
1298 + <a id="mainwp-help-menu-item-mobile" class="ui mini basic fluid button" href="#"><i class="question circle icon"></i> <?php esc_html_e( 'Help', 'mainwp' ); ?></a><?php //NOSONAR -- ignore double ID, elements not rendered at the same time. ?>
1299 + </div>
1300 + <div class="column item-wp-admin">
1301 + <a class="ui mini basic fluid button" href="<?php echo esc_url_raw( wp_logout_url() ); ?>"><i class="sign out icon"></i> <?php esc_html_e( 'Log Out', 'mainwp' ); ?></a>
1302 + </div>
1303 + </div>
1304 + </div>
1305 + </div>
1306 + <?php
1307 + }
1464 1308
1465 - if ( ! empty( $orther ) && '&' === substr( $orther, 0, 1 ) ) { // cheat: start by &, it is addition params string.
1466 - $san_path = str_replace( $orther, '', $san_path ); // remove other path of uri.
1467 - }
1309 + /**
1310 + * Method render_sub_item
1311 + *
1312 + * Grabs all submenu items and attatches to Main Menu.
1313 + *
1314 + * @param mixed $parent_key The parent key.
1315 + */
1316 + public static function render_sub_item( $parent_key ) { //phpcs:ignore -- NOSONAR - complex method.
1317 + if ( empty( $parent_key ) ) {
1318 + return;
1319 + }
1468 1320
1469 - $san_path = MainWP_Utility::sanitize_attr_slug( $san_path );
1470 - $san_href = MainWP_Utility::sanitize_attr_slug( $href );
1321 + /**
1322 + * MainWP Left Menu.
1323 + *
1324 + * @global object $mainwp_sub_leftmenu
1325 + */
1326 + global $mainwp_sub_leftmenu;
1471 1327
1472 - return $san_path === $san_href;
1473 - }
1328 + $submenu_items = $mainwp_sub_leftmenu[ $parent_key ];
1329 +
1330 + if ( ! is_array( $submenu_items ) || empty( $submenu_items ) ) {
1331 + return;
1332 + }
1333 +
1334 + global $plugin_page;
1335 +
1336 + $set_actived = false;
1337 +
1338 + MainWP_Utility::array_sort_existed_keys( $submenu_items, 5 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 5 => 'leftsub_order_level2'.
1339 +
1340 + $idx = 0;
1341 + $fix_douplicate_ids = array();
1342 +
1343 + foreach ( $submenu_items as $sub_item ) {
1344 + $title = $sub_item[0];
1345 + $href = $sub_item[1];
1346 + $right = $sub_item[2];
1347 + $id = isset( $sub_item[3] ) ? $sub_item[3] : '';
1348 + $slug = isset( $sub_item[4] ) ? $sub_item[4] : '';
1349 + $ext_state = isset( $sub_item[6] ) ? $sub_item[6] : '';
1350 + $active_path = isset( $sub_item[7] ) ? $sub_item[7] : '';
1351 + $before_title = isset( $sub_item[8] ) ? $sub_item[8] : '';
1352 + $others = isset( $sub_item[9] ) ? $sub_item[9] : array();
1353 +
1354 + if ( ! is_array( $others ) ) {
1355 + $others = array();
1356 + }
1357 +
1358 + $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
1359 +
1360 + if ( ! empty( $others['item_class'] ) ) {
1361 + $item_classes .= ' ' . $others['item_class'];
1362 + }
1363 +
1364 + $_blank = false;
1365 + if ( '_blank' === $id ) {
1366 + $_blank = true;
1367 + }
1368 +
1369 + $level2_active = false;
1370 +
1371 + if ( ! $set_actived ) {
1372 + $level2_active = static::is_level2_menu_item_active( $href ) ? true : false;
1373 + if ( is_array( $active_path ) && ! empty( $active_path ) ) {
1374 + foreach ( $active_path as $item => $value ) {
1375 + if ( $item === $plugin_page ) {
1376 + $level2_active = true;
1377 + break;
1378 + }
1379 + }
1380 + }
1381 + // hard fix managesite menu items active status.
1382 + //phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1383 + if ( false !== strpos( $href, 'admin.php?page=managesites' ) ) {
1384 + $page_name = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : '';
1385 + $level2_active = false;
1386 +
1387 + if ( isset( $_GET['do'] ) && 'new' === $_GET['do'] && false !== strpos( $href, 'admin.php?page=managesites&do=new' ) ) {
1388 + $level2_active = true;
1389 + }
1390 +
1391 + if ( ! $level2_active && isset( $_GET['do'] ) && 'bulknew' === $_GET['do'] && ( false !== strpos( $href, 'admin.php?page=managesites&do=bulknew' ) || 'managesites-addnew' === $id ) ) {
1392 + $level2_active = true;
1393 + }
1394 +
1395 + if ( ! $level2_active && ! isset( $_GET['do'] ) && 'InsightsManage' !== $page_name && 'Extensions-Mainwp-Clone-Extension' !== $page_name && 'managesites-root' === $id ) {
1396 + $level2_active = true;
1397 + }
1398 + }
1399 +
1400 + if ( ! $level2_active && ! empty( $others['active_params'] ) && is_array( $others['active_params'] ) ) {
1401 + foreach ( $others['active_params'] as $name => $value ) {
1402 + if ( isset( $_GET[ $name ] ) && wp_unslash( $_GET[ $name ] ) === $value ) {
1403 + $level2_active = true;
1404 + break;
1405 + }
1406 + }
1407 + }
1408 +
1409 + //phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1410 + if ( $level2_active ) {
1411 + $set_actived = true;
1412 + }
1413 + }
1414 +
1415 + $right_group = 'dashboard';
1416 + if ( ! empty( $right ) && strpos( $right, 'extension_' ) === 0 ) {
1417 + $right_group = 'extension';
1418 + $right = str_replace( 'extension_', '', $right );
1419 + }
1420 +
1421 + if ( ! empty( $others['level_class'] ) ) {
1422 + $item_classes = $item_classes . ' ' . $others['level_class'];
1423 + }
1424 +
1425 + if ( ! empty( $others['classes_item'] ) ) {
1426 + $item_classes = $item_classes . ' ' . $others['classes_item'];
1427 + }
1428 +
1429 + if ( empty( $right ) || ( ! empty( $right ) && \mainwp_current_user_can( $right_group, $right ) ) ) {
1430 + $menu_itemid = $slug; // compatible.
1431 + $menu_itemid = 'managesites' === $slug && ! empty( $id ) ? $id : $menu_itemid;
1432 +
1433 + // Fix duplicate ID issue caused by empty id="" (kept for backward compatibility).
1434 + if ( empty( $menu_itemid ) ) {
1435 + $menu_itemid = ! empty( $title ) ? sanitize_title( $title ) : 'left-menu-item';
1436 + $menu_itemid = 'left-menu-item-' . hash( 'crc32b', $menu_itemid . '-' . $idx );
1437 + }
1438 +
1439 + // Fix duplicate ID issue caused by same id in multiple extensions.
1440 + if ( ! empty( $fix_douplicate_ids ) && in_array( $menu_itemid, $fix_douplicate_ids ) ) {
1441 + $menu_itemid = $menu_itemid . '-' . $idx;
1442 + }
1443 + $fix_douplicate_ids[] = $menu_itemid;
1444 +
1445 + ?>
1446 + <a class="item <?php echo $level2_active ? 'active level-two-active' : ''; ?> <?php echo esc_attr( $item_classes ); ?>" href="<?php echo esc_url( $href ); ?>" id="<?php echo esc_attr( $menu_itemid ); ?>" <?php echo $_blank ? 'target="_blank"' : ''; ?>>
1447 + <?php echo $before_title . $title; //phpcs:ignore -- requires escaped. ?>
1448 + </a>
1449 + <?php
1450 + }
1451 + ++$idx;
1452 + }
1453 + }
1454 +
1455 +
1456 + /**
1457 + * Method is_level2_menu_item_active().
1458 + *
1459 + * Check if menu item level 2 is active.
1460 + *
1461 + * @param mixed $href The href value.
1462 + */
1463 + public static function is_level2_menu_item_active( $href ) {
1464 + $current_path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
1465 + $san_path = $current_path;
1466 +
1467 + if ( 0 === stripos( $san_path, '/wp-admin/' ) ) {
1468 + $san_path = str_replace( '/wp-admin/', '', $san_path );
1469 + }
1470 +
1471 + $orther = '';
1472 + if ( 0 === stripos( $san_path, $href ) ) {
1473 + $orther = str_replace( $href, '', $san_path );
1474 + }
1475 +
1476 + if ( ! empty( $orther ) && '&' === substr( $orther, 0, 1 ) ) { // cheat: start by &, it is addition params string.
1477 + $san_path = str_replace( $orther, '', $san_path ); // remove other path of uri.
1478 + }
1479 +
1480 + $san_path = MainWP_Utility::sanitize_attr_slug( $san_path );
1481 + $san_href = MainWP_Utility::sanitize_attr_slug( $href );
1482 +
1483 + return $san_path === $san_href;
1484 + }
1474 1485 }