PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.2.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.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 5.2.2 5.3 All 153 releases
mainwp / class / class-mainwp-menu.php

class-mainwp-menu.php in MainWP Dashboard: Self-hosted WordPress Management for Agencies 5.2.1, at class/class-mainwp-menu.php

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