PluginProbe
MainWP Dashboard: Self-hosted WordPress Management for Agencies / 5.1
MainWP Dashboard: Self-hosted WordPress Management for Agencies v5.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.1, at class/class-mainwp-menu.php

1,387 lines 65.2 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 $level = (int) $level;
573
574 if ( 1 !== $level && 2 !== $level && 0 !== $level ) {
575 $level = 1;
576 }
577
578 $title = $params['title'];
579 $before_title = ! empty( $params['before_title'] ) ? $params['before_title'] : '';
580
581 $slug = isset( $params['slug'] ) ? $params['slug'] : '';
582 $href = $params['href'];
583 $right = isset( $params['right'] ) ? $params['right'] : '';
584 $id = isset( $params['id'] ) ? $params['id'] : '';
585
586 $icon = isset( $params['icon'] ) ? $params['icon'] : '';
587 $leftsub_order = isset( $params['leftsub_order'] ) ? $params['leftsub_order'] : '';
588 $leftsub_order_level2 = isset( $params['leftsub_order_level2'] ) ? $params['leftsub_order_level2'] : '';
589 $ext_state = isset( $params['ext_status'] ) && ( 'activated' === $params['ext_status'] || 'inactive' === $params['ext_status'] ) ? $params['ext_status'] : '';
590 $parent_key = isset( $params['parent_key'] ) ? $params['parent_key'] : '';
591
592 /**
593 * MainWP Left Menu, Sub Menu & Active menu slugs.
594 *
595 * @global object $mainwp_leftmenu
596 * @global object $mainwp_sub_leftmenu
597 * @global object $_mainwp_menu_active_slugs
598 */
599 global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
600
601 if ( ! is_array( $mainwp_leftmenu ) ) {
602 $mainwp_leftmenu = array();
603 }
604
605 if ( ! isset( $mainwp_leftmenu['mainwp_tab'] ) ) {
606 $mainwp_leftmenu['mainwp_tab'] = array(); // to compatible with old hooks.
607 }
608
609 if ( ! is_array( $_mainwp_menu_active_slugs ) ) {
610 $_mainwp_menu_active_slugs = array();
611 }
612
613 $active_path = false;
614
615 if ( isset( $params['active_path'] ) && is_array( $params['active_path'] ) && ! empty( $params['active_path'] ) ) {
616 $active_path = $params['active_path'];
617 reset( $active_path );
618 $item = key( $active_path );
619 $active = current( $active_path );
620 $_mainwp_menu_active_slugs['leftbar'][ $item ] = $active;
621 $_mainwp_menu_active_slugs['parent_slug'][ $item ] = $parent_key;
622 }
623
624 if ( 0 === $level ) {
625 $parent_key = 'mainwp_tab'; // forced value.
626 $mainwp_leftmenu['leftbar'][] = array( $title, $slug, $href, $id, $icon );
627 } elseif ( 1 === $level ) {
628
629 if ( empty( $parent_key ) ) {
630 $parent_key = 'mainwp_tab'; // forced value.
631 }
632
633 if ( 'mainwp_tab' === $parent_key ) {
634 $mainwp_leftmenu[ $parent_key ][] = array( $title, $slug, $href, $id );
635 } else {
636 $mainwp_sub_leftmenu['leftbar'][ $parent_key ][] = array( $title, $slug, $href, $id, $leftsub_order, $ext_state, $active_path );
637
638 if ( ! empty( $slug ) ) {
639 $_mainwp_menu_active_slugs['leftbar'][ $slug ] = $parent_key; // to get active menu.
640 }
641 }
642 } else {
643 if ( empty( $parent_key ) ) {
644 $parent_key = 'mainwp_tab'; // forced value.
645 }
646 $mainwp_sub_leftmenu[ $parent_key ][] = array( $title, $href, $right, $id, $slug, $leftsub_order_level2, $ext_state, $active_path, $before_title );
647 }
648
649 if ( ! empty( $slug ) ) {
650 $no_submenu = ! empty( $params['nosubmenu'] ) ? true : false;
651 if ( $no_submenu ) {
652 $_mainwp_menu_active_slugs[ $slug ] = $slug; // to get active menu.
653 } else {
654 $_mainwp_menu_active_slugs[ $slug ] = $parent_key; // to get active menu.
655 }
656 }
657 }
658
659 /**
660 * Method render_left_menu
661 *
662 * Build Top Level Main Menu HTML & Render.
663 */
664 public static function render_left_menu() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
665
666 /**
667 * MainWP Left Menu, Sub Menu & Active menu slugs.
668 *
669 * @global object $mainwp_leftmenu
670 * @global object $mainwp_sub_leftmenu
671 * @global object $_mainwp_menu_active_slugs
672 */
673 global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs, $plugin_page;
674
675 /**
676 * Filter: mainwp_main_menu
677 *
678 * Filters main navigation menu items
679 *
680 * @since 4.0
681 */
682 $mainwp_leftmenu = apply_filters( 'mainwp_main_menu', $mainwp_leftmenu );
683 $bar_leftmenu = isset( $mainwp_leftmenu['leftbar'] ) ? $mainwp_leftmenu['leftbar'] : array();
684
685 /**
686 * Filter: mainwp_main_menu_submenu
687 *
688 * Filters main navigation subt-menu items
689 *
690 * @since 4.0
691 */
692
693 $mainwp_sub_leftmenu = apply_filters( 'mainwp_main_menu_submenu', $mainwp_sub_leftmenu );
694 $sub_bar_leftmenu = isset( $mainwp_sub_leftmenu['leftbar'] ) ? $mainwp_sub_leftmenu['leftbar'] : array();
695
696 $version = get_option( 'mainwp_plugin_version' );
697
698 ?>
699 <?php
700 /**
701 * Action: before_mainwp_menu
702 *
703 * Fires before the main navigation element.
704 *
705 * @since 4.0
706 */
707 do_action( 'before_mainwp_menu' );
708 ?>
709 <div id="mainwp-main-navigation-container">
710 <div id="mainwp-first-level-navigation">
711 <div id="mainwp-first-level-navigation-menu" class="ui vertical labeled inverted icon tiny menu">
712 <?php
713
714 $bar_item_actived_key = '';
715 if ( is_array( $_mainwp_menu_active_slugs ) && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
716 $menu_item_actived_key = $_mainwp_menu_active_slugs[ $plugin_page ];
717 if ( isset( $_mainwp_menu_active_slugs['leftbar'] ) && is_array( $_mainwp_menu_active_slugs['leftbar'] ) && isset( $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ] ) ) {
718 $bar_item_actived_key = $_mainwp_menu_active_slugs['leftbar'][ $menu_item_actived_key ];
719 }
720 }
721
722 $bar_item_active = null;
723
724 $sites_count = MainWP_DB::instance()->get_websites_count();
725 if ( empty( $sites_count ) ) {
726 ?>
727 <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">
728 <i class="magic large icon"></i><span class="ui small text"><?php esc_html_e( 'Quick Setup', 'mainwp' ); ?></span>
729 </a>
730 <?php
731 }
732
733 if ( is_array( $bar_leftmenu ) && ! empty( $bar_leftmenu ) ) {
734 foreach ( $bar_leftmenu as $item ) {
735 $title = wptexturize( $item[0] );
736 $item_key = $item[1];
737 $href = $item[2];
738 $item_id = isset( $item[3] ) ? $item[3] : '';
739 $item_icon = isset( $item[4] ) ? $item[4] : '';
740
741 $has_sub = true;
742 if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
743 $has_sub = false;
744 }
745 $active_item = '';
746
747 if ( empty( $bar_item_actived_key ) ) {
748 if ( isset( $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) ) {
749 if ( $item_key === $_mainwp_menu_active_slugs['leftbar'][ $plugin_page ] ) {
750 $bar_item_actived_key = $item_key;
751 }
752 } elseif ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
753 if ( $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
754 $bar_item_actived_key = $item_key;
755 }
756 }
757 }
758
759 if ( ! empty( $bar_item_actived_key ) && $item_key === $bar_item_actived_key ) {
760 $active_item = 'active';
761 $bar_item_active = $item;
762 }
763
764 $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
765
766 // phpcs:disable WordPress.Security.EscapeOutput
767 echo '<a ' . $id_attr . ' title="' . esc_html( $title ) . "\" class=\"item $active_item\" href=\"$href\">";
768 echo ! empty( $item_icon ) ? $item_icon : '<i class="th large icon"></i>';
769 echo '<span class="ui small text">' . esc_html( $title ) . '</span>';
770 echo '</a>';
771 // phpcs:enable
772 }
773 }
774 ?>
775 </div>
776 <?php
777 $go_back_wpadmin_url = admin_url( 'index.php' );
778
779 $link = array(
780 'url' => $go_back_wpadmin_url,
781 'text' => esc_html__( 'WP Admin', 'mainwp' ),
782 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
783 );
784 /**
785 * Filter: mainwp_go_back_wpadmin_link
786 *
787 * Filters URL for the Go to WP Admin button in Main navigation.
788 *
789 * @since 4.0
790 */
791 $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
792
793 if ( false !== $go_back_link && is_array( $go_back_link ) ) {
794 if ( isset( $go_back_link['url'] ) ) {
795 $link['url'] = $go_back_link['url'];
796 }
797 if ( isset( $go_back_link['text'] ) ) {
798 $link['text'] = $go_back_link['text'];
799 }
800 if ( isset( $go_back_link['tip'] ) ) {
801 $link['tip'] = $go_back_link['tip'];
802 }
803 }
804 ?>
805 <div id="mainwp-first-level-wpitems-menu" class="ui vertical labeled inverted icon mini menu">
806 <a class="item" href="#" id="mainwp-collapse-second-level-navigation" aria-label="<?php esc_attr_e( 'Collapse menu.', 'mainwp' ); ?>">
807 <i class="double angle left icon"></i>
808 </a>
809 </div>
810 <div id="mainwp-first-level-navigation-version-label">
811 <span id="mainwp-version-label" class="ui mini green fluid centered label"><?php echo esc_html( $version ); ?></span>
812 </div>
813 </div>
814 <div id="mainwp-second-level-navigation">
815 <div id="mainwp-main-menu" class="ui inverted vertical accordion menu">
816 <?php
817 $bar_active_item_key = '';
818
819 $set_actived = false;
820
821 if ( ! empty( $bar_item_active ) ) {
822 $item = $bar_item_active;
823 $title = wptexturize( $item[0] );
824 $item_key = $item[1];
825 $href = $item[2];
826 $item_id = isset( $item[3] ) ? $item[3] : '';
827
828 $bar_active_item_key = $item_key;
829
830 $has_sub = true;
831 if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
832 $has_sub = false;
833 }
834 $active_item = '';
835
836 if ( ! $set_actived && isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
837 $active_item = 'active';
838 $set_actived = true;
839 }
840
841 // to fix active menu.
842 if ( ! $set_actived && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
843 $active_item = 'active';
844 $set_actived = true;
845 }
846
847 $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
848
849 // phpcs:disable WordPress.Security.EscapeOutput
850 if ( $has_sub ) {
851 echo '<div ' . $id_attr . " class=\"item $active_item\">";
852 echo "<a class=\"title with-sub $active_item\" href=\"$href\">$title <i class=\"dropdown icon\"></i></a>";
853 echo "<div class=\"content menu $active_item\">";
854 static::render_sub_item( $item_key );
855 echo '</div>';
856 echo '</div>';
857 } else {
858 echo '<div ' . $id_attr . ' class="item">';
859 echo "<a class='title $active_item' href=\"$href\">$title</a>";
860 echo '</div>';
861 }
862 // phpcs:enable
863
864 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 ] ) ) {
865 $sub_bar_leftmenu_active_items = $sub_bar_leftmenu[ $bar_active_item_key ];
866 MainWP_Utility::array_sort_existed_keys( $sub_bar_leftmenu_active_items, 4 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 4 => 'leftsub_order'.
867 $set_actived = false;
868 foreach ( $sub_bar_leftmenu_active_items as $item ) {
869
870 if ( empty( $item ) || ! is_array( $item ) ) {
871 continue;
872 }
873
874 $title = wptexturize( $item[0] );
875 $item_key = $item[1];
876
877 $has_sub = true;
878 if ( ! isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
879 $has_sub = false;
880 }
881
882 $href = $item[2];
883 $item_id = isset( $item[3] ) ? $item[3] : '';
884 $ext_state = isset( $item[5] ) ? $item[5] : '';
885
886 $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
887
888 $active_item = '';
889
890 if ( ! $set_actived && isset( $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs['parent_slug'][ $plugin_page ] ) {
891 $active_item = 'active';
892 $set_actived = true;
893 }
894
895 // to fix active menu.
896 if ( ! $set_actived && isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) && $item_key === $_mainwp_menu_active_slugs[ $plugin_page ] ) {
897 $active_item = 'active';
898 $set_actived = true;
899 }
900
901 $id_attr = ! empty( $item_id ) ? 'id="' . esc_html( $item_id ) . '"' : '';
902
903 $hide_item = '';
904 if ( 'admin.php?page=ManageApiBackups' === $href ) {
905 $hide_item = ' style="display:none"';
906 }
907
908 // phpcs:disable WordPress.Security.EscapeOutput
909 if ( $has_sub ) {
910 echo '<div ' . $id_attr . " class=\"item $active_item $item_classes\">";
911 echo "<a class=\"title with-sub $active_item\" href=\"$href\">$title <i class=\"dropdown icon\"></i></a>";
912 echo "<div class=\"content menu $active_item\">";
913 static::render_sub_item( $item_key );
914 echo '</div>';
915 echo '</div>';
916 } else {
917 echo '<div ' . $id_attr . $hide_item . " class=\"item $active_item $item_classes\">";
918 echo "<a class='title $active_item' href=\"$href\">$title</a>";
919 echo '</div>';
920 }
921 // phpcs:enable
922 }
923 }
924 }
925 ?>
926 </div>
927 </div>
928 </div>
929
930 <?php
931 /**
932 * Action: after_mainwp_menu
933 *
934 * Fires after the main navigation element.
935 *
936 * @since 4.0
937 */
938 do_action( 'after_mainwp_menu' );
939 ?>
940 <script type="text/javascript">
941 jQuery( document ).ready( function () {
942
943 let mainwp_left_bar_showhide_init = function(){
944 if(jQuery('body').hasClass('mainwp-hidden-second-level-navigation')){
945 return; // hide always.
946 }
947 if(jQuery('body').hasClass('toplevel_page_mainwp_tab')){
948 return; // hide always.
949 }
950 let lbar = jQuery( '#mainwp-collapse-second-level-navigation' );
951 let show = ( typeof mainwp_ui_state_load !== 'undefined' ) && 0 != mainwp_ui_state_load( 'showmenu' );
952 mainwp_left_bar_showhide( lbar, show);
953 }
954 mainwp_left_bar_showhide = function( lbar, show ){
955 if ( show ) {
956 jQuery( '#mainwp-second-level-navigation' ).show();
957 jQuery( '.mainwp-content-wrap' ).css( "margin-left", "272px" );
958 jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "272px" );
959 jQuery( '#mainwp-main-navigation-container' ).css( "width", "272px" );
960 jQuery( lbar ).find( '.icon' ).removeClass( 'right' );
961 jQuery( lbar ).find( '.icon' ).addClass( 'left' );
962 jQuery( lbar ).css( "left", "272px" );
963 jQuery( lbar ).removeClass( 'collapsed' );
964 if( ( typeof mainwp_ui_state_save !== 'undefined' ) ) {
965 mainwp_ui_state_save( 'showmenu', 1 );
966 }
967 } else {
968 jQuery( '#mainwp-second-level-navigation' ).hide();
969 jQuery( '.mainwp-content-wrap' ).css( "margin-left", "72px" );
970 jQuery( '#mainwp-screenshots-sites' ).css( "margin-left", "72px" );
971 jQuery( '#mainwp-main-navigation-container' ).css( "width", "72px" );
972 jQuery( lbar ).find( '.icon' ).removeClass( 'left' );
973 jQuery( lbar ).find( '.icon' ).addClass( 'right' );
974 jQuery( lbar ).css( "left", "72px" );
975 jQuery( lbar ).addClass( 'collapsed' );
976 jQuery( '#mainwp-top-header' ).css( "width", "100%" );
977 if( ( typeof mainwp_ui_state_save !== 'undefined' ) ) {
978 mainwp_ui_state_save( 'showmenu', 0 );
979 }
980 }
981 }
982
983 jQuery( '#mainwp-collapse-second-level-navigation' ).on( 'click', function() {
984 let show = jQuery( this ).hasClass( 'collapsed' ) ? true : false;
985 mainwp_left_bar_showhide( this, show);
986 return false;
987 } );
988 mainwp_left_bar_showhide_init();
989
990 // click on menu with-sub icon.
991 jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.with-sub .icon' ).on( "click", function ( event ) {
992 let pr = jQuery( this ).closest( '.item' );
993 let title = jQuery( this ).closest( '.title' );
994 let active = jQuery( title ).hasClass( 'active' );
995
996 // remove current active.
997 mainwp_menu_collapse();
998
999 // if current menu item are not active then set it active.
1000 if ( !active ) {
1001 jQuery( title ).addClass( 'active' );
1002 jQuery( pr ).find('.content.menu').addClass( 'active' );
1003 pr.addClass('active');
1004 }
1005 return false;
1006 } );
1007
1008 jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.with-sub' ).on( "click", function ( event ) {
1009 let pr = jQuery( this ).closest( '.item' );
1010 let active = jQuery( this ).hasClass( 'active' );
1011
1012 // remove current active.
1013 mainwp_menu_collapse();
1014
1015 // set active before go to the page.
1016 if ( !active ) {
1017 jQuery( this ).addClass( 'active' );
1018 jQuery( pr ).find('.content.menu').addClass( 'active' );
1019 pr.addClass('active');
1020 }
1021 } );
1022
1023 mainwp_menu_collapse = function() {
1024 // remove current active.
1025 jQuery( '#mainwp-main-navigation-container #mainwp-main-menu a.title.active').removeClass('active');
1026 jQuery( '#mainwp-main-navigation-container #mainwp-main-menu .item').removeClass('active');
1027 jQuery( '#mainwp-main-navigation-container #mainwp-main-menu .content.menu.active').removeClass('active');
1028 };
1029
1030 jQuery('.mainwp-main-mobile-navigation-container #mainwp-main-menu').accordion();
1031
1032 } );
1033 </script>
1034 <?php
1035 }
1036
1037 /**
1038 * Method render_mobile_menu
1039 *
1040 * Renders the mobile menu.
1041 */
1042 public static function render_mobile_menu() { // phpcs:ignore -- NOSONAR -Current complexity is the only way to achieve desired results, pull request solutions appreciated.
1043 $mainwp_show_language_updates = get_option( 'mainwp_show_language_updates', 1 );
1044 ?>
1045 <div class="mainwp-main-mobile-navigation-container">
1046 <div class="mainwp-nav-menu">
1047 <?php
1048 /**
1049 * Action: before_mainwp_menu
1050 *
1051 * Fires before the main navigation element.
1052 *
1053 * @since 4.0
1054 */
1055 do_action( 'before_mainwp_menu' );
1056 ?>
1057
1058 <div id="mainwp-main-menu" class="test-menu ui inverted vertical accordion menu">
1059 <div class="hamburger">
1060 <span class="hamburger-bun"></span>
1061 <span class="hamburger-patty"></span>
1062 <span class="hamburger-bun"></span>
1063 </div>
1064
1065 <div class="item"><a href="admin.php?page=mainwp_tab"><?php esc_html_e( 'Overview', 'mainwp' ); ?></a></div>
1066 <div class="item">
1067 <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>
1068 <div class="content menu" id="mainwp-sites-mobile-menu-item">
1069 <div class="accordion item">
1070 <div class="title"><a href="admin.php?page=managesites"><?php esc_html_e( 'Sites', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1071 <div class="content menu">
1072 <a class="item" href="admin.php?page=managesites"><?php esc_html_e( 'Manage Sites', 'mainwp' ); ?></a>
1073 <a class="item" href="admin.php?page=managesites&do=new"><?php esc_html_e( 'Add New Site', 'mainwp' ); ?></a>
1074 <a class="item" href="admin.php?page=managesites&do=bulknew"><?php esc_html_e( 'Import Sites', 'mainwp' ); ?></a>
1075 <a class="item" href="admin.php?page=MonitoringSites"><?php esc_html_e( 'Monitoring', 'mainwp' ); ?></a>
1076 </div>
1077 </div>
1078 <div class="item accordion">
1079 <div class="title"><a class="" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Tags', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1080 <div class="content menu">
1081 <a class="item" href="admin.php?page=ManageGroups"><?php esc_html_e( 'Manage Tags', 'mainwp' ); ?></a>
1082 </div>
1083 </div>
1084 <div class="item accordion">
1085 <div class="title"><a href="admin.php?page=UpdatesManage"><?php esc_html_e( 'Updates', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1086 <div class="content menu">
1087 <a class="item" href="admin.php?page=UpdatesManage&tab=plugins-updates"><?php esc_html_e( 'Plugins Updates', 'mainwp' ); ?></a>
1088 <a class="item" href="admin.php?page=UpdatesManage&tab=themes-updates"><?php esc_html_e( 'Themes Updates', 'mainwp' ); ?></a>
1089 <a class="item" href="admin.php?page=UpdatesManage&tab=wordpress-updates"><?php esc_html_e( 'WordPress Updates', 'mainwp' ); ?></a>
1090 <?php if ( $mainwp_show_language_updates ) : ?>
1091 <a class="item" href="admin.php?page=UpdatesManage&tab=translations-updates"><?php esc_html_e( 'Translation Plugins', 'mainwp' ); ?></a>
1092 <?php endif; ?>
1093 <a class="item" href="admin.php?page=UpdatesManage&tab=abandoned-plugins"><?php esc_html_e( 'Abandoned Plugins', 'mainwp' ); ?></a>
1094 <a class="item" href="admin.php?page=UpdatesManage&tab=abandoned-themes"><?php esc_html_e( 'Abandoned Themes', 'mainwp' ); ?></a>
1095 </div>
1096 </div>
1097 <div class="item accordion">
1098 <div class="title"><a href="admin.php?page=PluginsManage"><?php esc_html_e( 'Plugins', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1099 <div class="content menu">
1100 <a class="item" href="admin.php?page=PluginsManage"><?php esc_html_e( 'Manage Plugins', 'mainwp' ); ?></a>
1101 <a class="item" href="admin.php?page=PluginsInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1102 <a class="item" href="admin.php?page=PluginsAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1103 <a class="item" href="admin.php?page=PluginsIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1104 <a class="item" href="admin.php?page=PluginsIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1105 </div>
1106 </div>
1107 <div class="item accordion">
1108 <div class="title"><a href="admin.php?page=ThemesManage"><?php esc_html_e( 'Themes', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1109 <div class="content menu">
1110 <a class="item" href="admin.php?page=ThemesManage"><?php esc_html_e( 'Manage Themes', 'mainwp' ); ?></a>
1111 <a class="item" href="admin.php?page=ThemesInstall"><?php esc_html_e( 'Install', 'mainwp' ); ?></a>
1112 <a class="item" href="admin.php?page=ThemesAutoUpdate"><?php esc_html_e( 'Advanced Auto Updates', 'mainwp' ); ?></a>
1113 <a class="item" href="admin.php?page=ThemesIgnore"><?php esc_html_e( 'Ignored Updates', 'mainwp' ); ?></a>
1114 <a class="item" href="admin.php?page=ThemesIgnoredAbandoned"><?php esc_html_e( 'Ignored Abandoned', 'mainwp' ); ?></a>
1115 </div>
1116 </div>
1117 <div class="item accordion">
1118 <div class="title"><a href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Users', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1119 <div class="content menu">
1120 <a class="item" href="admin.php?page=UserBulkManage"><?php esc_html_e( 'Manage Users', 'mainwp' ); ?></a>
1121 <a class="item" href="admin.php?page=UserBulkAdd"><?php esc_html_e( 'Add New User', 'mainwp' ); ?></a>
1122 <a class="item" href="admin.php?page=BulkImportUsers"><?php esc_html_e( 'Import Users', 'mainwp' ); ?></a>
1123 <a class="item" href="admin.php?page=UpdateAdminPasswords"><?php esc_html_e( 'Admin Passwords', 'mainwp' ); ?></a>
1124 </div>
1125 </div>
1126 <div class="item accordion">
1127 <div class="title"><a href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Posts', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1128 <div class="content menu">
1129 <a class="item" href="admin.php?page=PostBulkManage"><?php esc_html_e( 'Manage Pages', 'mainwp' ); ?></a>
1130 <a class="item" href="admin.php?page=PostBulkAdd"><?php esc_html_e( 'Add New Post', 'mainwp' ); ?></a>
1131 </div>
1132 </div>
1133 <div class="item accordion">
1134 <div class="title"><a href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Pages', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1135 <div class="content menu">
1136 <a class="item" href="admin.php?page=PageBulkManage"><?php esc_html_e( 'Manage Pages', 'mainwp' ); ?></a>
1137 <a class="item" href="admin.php?page=PageBulkAdd"><?php esc_html_e( 'Add New Page', 'mainwp' ); ?></a>
1138 </div>
1139 </div>
1140 <div class="item accordion">
1141 <div class="title"><a href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1142 <div class="content menu">
1143 <a class="item" href="admin.php?page=ManageApiBackups"><?php esc_html_e( 'Backups', 'mainwp' ); ?></a>
1144 </div>
1145 </div>
1146 </div>
1147 </div>
1148 <div class="item">
1149 <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>
1150 <div class="content menu">
1151 <a class="item" href="admin.php?page=ManageClients"><?php esc_html_e( 'Clients', 'mainwp' ); ?></a>
1152 <a class="item" href="admin.php?page=ClientAddNew"><?php esc_html_e( 'Add Client', 'mainwp' ); ?></a>
1153 <a class="item" href="admin.php?page=ClientAddField"><?php esc_html_e( 'Client Fields', 'mainwp' ); ?></a>
1154 </div>
1155 </div>
1156
1157 <div class="item">
1158 <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>
1159 <div class="content menu">
1160 <a class="item" href="admin.php?page=ManageCostTracker"><?php esc_html_e( 'Cost Tracker', 'mainwp' ); ?></a>
1161 <a class="item" href="admin.php?page=CostTrackerAdd"><?php esc_html_e( 'Add Cost', 'mainwp' ); ?></a>
1162 <a class="item" href="admin.php?page=CostTrackerSettings"><?php esc_html_e( 'Cost Tracker Settings', 'mainwp' ); ?></a>
1163 </div>
1164 </div>
1165
1166 <div class="item">
1167 <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>
1168 <div class="content menu">
1169 <a class="item" href="admin.php?page=InsightsOverview"><?php esc_html_e( 'Insights', 'mainwp' ); ?></a>
1170 </div>
1171 </div>
1172
1173 <div class="item">
1174 <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>
1175 <div class="content menu">
1176 <a class="item" href="admin.php?page=RESTAPI"><?php esc_html_e( 'Manage API Keys', 'mainwp' ); ?></a>
1177 <a class="item" href="admin.php?page=AddApiKeys"><?php esc_html_e( 'Add API Keys', 'mainwp' ); ?></a>
1178 </div>
1179 </div>
1180 <div class="item">
1181 <div class="title"><a href="admin.php?page=Extensions" class=""><?php esc_html_e( 'Extensions', 'mainwp' ); ?></a><i class="dropdown icon"></i></div>
1182 <div class="content menu">
1183 <a class="item" href="admin.php?page=Extensions"><?php esc_html_e( 'Manage Extensions', 'mainwp' ); ?></a>
1184 </div>
1185 </div>
1186 <div class="item">
1187 <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>
1188 <div class="content menu">
1189 <a class="item" href="admin.php?page=Settings"><?php esc_html_e( 'General Settings', 'mainwp' ); ?></a>
1190 <a class="item" href="admin.php?page=SettingsAdvanced"><?php esc_html_e( 'Advanced Settings', 'mainwp' ); ?></a>
1191 <a class="item" href="admin.php?page=SettingsEmail"><?php esc_html_e( 'Email Settings', 'mainwp' ); ?></a>
1192 <a class="item" href="admin.php?page=MainWPTools"><?php esc_html_e( 'Tools', 'mainwp' ); ?></a>
1193 </div>
1194 </div>
1195 <div class="item">
1196 <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>
1197 <div class="content menu">
1198 <a class="item" href="admin.php?page=ServerInformation"><?php esc_html_e( 'Server', 'mainwp' ); ?></a>
1199 <a class="item" href="admin.php?page=ServerInformationCron"><?php esc_html_e( 'Cron Schedules', 'mainwp' ); ?></a>
1200 <a class="item" href="admin.php?page=ErrorLog"><?php esc_html_e( 'Error Log', 'mainwp' ); ?></a>
1201 <a class="item" href="admin.php?page=ActionLogs"><?php esc_html_e( 'Custom Event Monitor', 'mainwp' ); ?></a>
1202 <a class="item" href="admin.php?page=PluginPrivacy"><?php esc_html_e( 'Plugin Privacy', 'mainwp' ); ?></a>
1203 </div>
1204 </div>
1205 <?php
1206 $go_back_wpadmin_url = admin_url( 'index.php' );
1207
1208 $link = array(
1209 'url' => $go_back_wpadmin_url,
1210 'text' => esc_html__( 'WP Admin', 'mainwp' ),
1211 'tip' => esc_html__( 'Click to go back to the site WP Admin area.', 'mainwp' ),
1212 );
1213
1214 /**
1215 * Filter: mainwp_go_back_wpadmin_link
1216 *
1217 * Filters URL for the Go to WP Admin button in Main navigation.
1218 *
1219 * @since 4.0
1220 */
1221 $go_back_link = apply_filters( 'mainwp_go_back_wpadmin_link', $link );
1222
1223 if ( false !== $go_back_link ) {
1224 if ( is_array( $go_back_link ) ) {
1225 if ( isset( $go_back_link['url'] ) ) {
1226 $link['url'] = $go_back_link['url'];
1227 }
1228 if ( isset( $go_back_link['text'] ) ) {
1229 $link['text'] = $go_back_link['text'];
1230 }
1231 if ( isset( $go_back_link['tip'] ) ) {
1232 $link['tip'] = $go_back_link['tip'];
1233 }
1234 }
1235 ?>
1236 <div class="item item-wp-admin">
1237 <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 ?>
1238 </div>
1239 <?php } ?>
1240
1241 </div>
1242 <?php
1243 /**
1244 * Action: after_mainwp_menu
1245 *
1246 * Fires after the main navigation element.
1247 *
1248 * @since 4.0
1249 */
1250 do_action( 'after_mainwp_menu' );
1251 ?>
1252 </div>
1253 </div>
1254 <?php
1255 }
1256
1257 /**
1258 * Method render_sub_item
1259 *
1260 * Grabs all submenu items and attatches to Main Menu.
1261 *
1262 * @param mixed $parent_key The parent key.
1263 */
1264 public static function render_sub_item( $parent_key ) { //phpcs:ignore -- NOSONAR - complex method.
1265 if ( empty( $parent_key ) ) {
1266 return;
1267 }
1268
1269 /**
1270 * MainWP Left Menu.
1271 *
1272 * @global object $mainwp_sub_leftmenu
1273 */
1274 global $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
1275
1276 $submenu_items = $mainwp_sub_leftmenu[ $parent_key ];
1277
1278 if ( ! is_array( $submenu_items ) || empty( $submenu_items ) ) {
1279 return;
1280 }
1281
1282 global $plugin_page;
1283
1284 $set_actived = false;
1285
1286 MainWP_Utility::array_sort_existed_keys( $submenu_items, 5 ); //phpcs:ignore Squiz.PHP.CommentedOutCode.Found -- 5 => 'leftsub_order_level2'.
1287
1288 foreach ( $submenu_items as $sub_item ) {
1289 $title = $sub_item[0];
1290 $href = $sub_item[1];
1291 $right = $sub_item[2];
1292 $id = isset( $sub_item[3] ) ? $sub_item[3] : '';
1293 $slug = isset( $sub_item[4] ) ? $sub_item[4] : '';
1294 $ext_state = isset( $sub_item[6] ) ? $sub_item[6] : '';
1295 $active_path = isset( $sub_item[7] ) ? $sub_item[7] : '';
1296 $before_title = isset( $sub_item[8] ) ? $sub_item[8] : '';
1297
1298 $item_classes = 'inactive' === $ext_state ? 'extension-inactive' : '';
1299
1300 $_blank = false;
1301 if ( '_blank' === $id ) {
1302 $_blank = true;
1303 }
1304
1305 $level2_active = false;
1306
1307 if ( ! $set_actived ) {
1308 $level2_active = static::is_level2_menu_item_active( $href ) ? true : false;
1309 if ( is_array( $active_path ) && ! empty( $active_path ) ) {
1310 reset( $active_path );
1311 $item = key( $active_path );
1312 if ( $item === $plugin_page ) {
1313 $level2_active = true;
1314 }
1315 }
1316 // hard fix managesite menu items active status.
1317 //phpcs:disable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1318 if ( false !== strpos( $href, 'admin.php?page=managesites' ) ) {
1319 $page_name = isset( $_GET['page'] ) ? wp_unslash( $_GET['page'] ) : '';
1320 $level2_active = false;
1321
1322 if ( isset( $_GET['do'] ) && 'new' === $_GET['do'] && false !== strpos( $href, 'admin.php?page=managesites&do=new' ) ) {
1323 $level2_active = true;
1324 }
1325
1326 if ( ! $level2_active && isset( $_GET['do'] ) && 'bulknew' === $_GET['do'] && false !== strpos( $href, 'admin.php?page=managesites&do=bulknew' ) ) {
1327 $level2_active = true;
1328 }
1329
1330 if ( ! $level2_active && ! isset( $_GET['do'] ) && 'NonMainWPChanges' !== $page_name && 'admin.php?page=managesites' === $href ) {
1331 $level2_active = true;
1332 }
1333 }
1334 //phpcs:enable WordPress.Security.NonceVerification.Recommended,WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
1335 if ( $level2_active ) {
1336 $set_actived = true;
1337 }
1338 }
1339
1340 $right_group = 'dashboard';
1341 if ( ! empty( $right ) && strpos( $right, 'extension_' ) === 0 ) {
1342 $right_group = 'extension';
1343 $right = str_replace( 'extension_', '', $right );
1344 }
1345 if ( empty( $right ) || ( ! empty( $right ) && mainwp_current_user_have_right( $right_group, $right ) ) ) {
1346 ?>
1347 <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"' : ''; ?>>
1348 <?php echo $before_title . $title; //phpcs:ignore -- requires escaped. ?>
1349 </a>
1350
1351 <?php
1352 }
1353 }
1354 }
1355
1356
1357 /**
1358 * Method is_level2_menu_item_active().
1359 *
1360 * Check if menu item level 2 is active.
1361 *
1362 * @param mixed $href The href value.
1363 */
1364 public static function is_level2_menu_item_active( $href ) {
1365 $current_path = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
1366 $san_path = $current_path;
1367
1368 if ( 0 === stripos( $san_path, '/wp-admin/' ) ) {
1369 $san_path = str_replace( '/wp-admin/', '', $san_path );
1370 }
1371
1372 $orther = '';
1373 if ( 0 === stripos( $san_path, $href ) ) {
1374 $orther = str_replace( $href, '', $san_path );
1375 }
1376
1377 if ( ! empty( $orther ) && '&' === substr( $orther, 0, 1 ) ) { // cheat: start by &, it is addition params string.
1378 $san_path = str_replace( $orther, '', $san_path ); // remove other path of uri.
1379 }
1380
1381 $san_path = MainWP_Utility::sanitize_attr_slug( $san_path );
1382 $san_href = MainWP_Utility::sanitize_attr_slug( $href );
1383
1384 return $san_path === $san_href;
1385 }
1386 }
1387