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

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