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

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