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

291 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class MainWP_Menu {
4
5 public function __construct() {
6
7 // use the hook mainwp_main_menu_disable_menu_items to disable menu items
8 global $_mainwp_disable_menus_items;
9 if ( $_mainwp_disable_menus_items === null ) {
10 // init some disable menu items, default is false
11 $_mainwp_disable_menus_items = array(
12 // compatible with old hooks
13 'level_1' => array(
14 'not_set_this_level' => true
15 //'mainwp_tab' => false, // not hide this menu
16 //'Extensions' => false,
17 //'childsites_menu' => false,
18 ),
19 'level_2' => array(
20 //'mainwp_tab' => false, // not hide this menu
21 'UpdatesManage' => false,
22 'managesites' => false,
23 'PostBulkManage' => false,
24 'PageBulkManage' => false,
25 'ThemesManage' => false,
26 'PluginsManage' => false,
27 'UserBulkManage' => false,
28 'ManageBackups' => false,
29 'Settings' => false,
30 'Extensions' => false,
31 'ServerInformation' => false,
32 ),
33 // compatible with old hooks
34 'level_3' => array(
35 )
36 );
37 }
38 }
39
40 public static function init_subpages_left_menu( $subPages, &$initSubpage, $parentKey, $slug ) {
41 if ( !is_array( $subPages ) ) {
42 return;
43 }
44 foreach ( $subPages as $subPage ) {
45 if ( !isset( $subPage[ 'menu_hidden' ] ) || (isset( $subPage[ 'menu_hidden' ] ) && $subPage[ 'menu_hidden' ] != true) ) {
46 $_item = array(
47 'title' => $subPage[ 'title' ],
48 'parent_key' => $parentKey,
49 'href' => 'admin.php?page=' . $slug . $subPage[ 'slug' ],
50 'slug' => $slug . $subPage[ 'slug' ],
51 'right' => ''
52 );
53
54 // to support check right to open menu for sometime
55 if ( isset( $subPage[ 'item_slug' ] ) ) {
56 $_item[ 'item_slug' ] = $subPage[ 'item_slug' ];
57 }
58
59 $initSubpage[] = $_item;
60 }
61 }
62 }
63
64 public static function is_disable_menu_item( $level, $item ) {
65
66 global $_mainwp_disable_menus_items;
67 $_level = 'level_' . $level;
68 if ( is_array( $_mainwp_disable_menus_items ) && isset( $_mainwp_disable_menus_items[ $_level ] ) && isset( $_mainwp_disable_menus_items[ $_level ][ $item ] ) ) {
69 if ( $_mainwp_disable_menus_items[ $_level ][ $item ] )
70 return true;
71 else
72 return false;
73 }
74 $_mainwp_disable_menus_items[ $_level ][ $item ] = false;
75 return false;
76 }
77
78 public static function add_left_menu( $params = array(), $level = 1 ) {
79
80 if ( empty( $params ) )
81 return;
82
83 if ($level != 1 && $level != 2)
84 $level = 1;
85
86 $title = $params[ 'title' ];
87
88 if ( 1 === $level ) {
89 $parent_key = 'mainwp_tab'; // forced value
90 } else {
91 if ( isset( $params[ 'parent_key' ] ) )
92 $parent_key = $params[ 'parent_key' ];
93 else
94 $parent_key = 'mainwp_tab'; // forced value
95 }
96
97 $slug = $params[ 'slug' ];
98 $href = $params[ 'href' ];
99 $right = isset( $params[ 'right' ] ) ? $params[ 'right' ] : '';
100 $id = isset( $params[ 'id' ] ) ? $params[ 'id' ] : '';
101
102 global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs;
103
104 $title = esc_html($title);
105
106 if ( 1 == $level ) {
107 $mainwp_leftmenu[ $parent_key ][] = array( $title, $slug, $href, $id );
108 if ( !empty( $slug ) )
109 $_mainwp_menu_active_slugs[ $slug ] = $slug; // to get active menu
110 } else if ( 2 == $level ) {
111 $mainwp_sub_leftmenu[ $parent_key ][] = array( $title, $href, $right, $id );
112 if ( !empty( $slug ) )
113 $_mainwp_menu_active_slugs[ $slug ] = $parent_key; // to get active menu
114 }
115 }
116
117 public static function render_left_menu() {
118
119 global $mainwp_leftmenu, $mainwp_sub_leftmenu, $_mainwp_menu_active_slugs, $plugin_page;
120
121 $mainwp_leftmenu = apply_filters( 'mainwp_main_menu', $mainwp_leftmenu );
122 $mainwp_sub_leftmenu = apply_filters( 'mainwp_main_menu_submenu', $mainwp_sub_leftmenu );
123
124 $mainwp_leftmenu = isset( $mainwp_leftmenu['mainwp_tab'] ) ? $mainwp_leftmenu['mainwp_tab'] : array();
125
126 ?>
127 <div class="mainwp-nav-wrap">
128
129
130 <div id="mainwp-logo">
131 <img src="<?php echo MAINWP_PLUGIN_URL . 'assests/images/logo.png'; ?>" alt="MainWP"/>
132 </div>
133 <div class="ui hidden divider"></div>
134 <div class="mainwp-nav-menu">
135 <?php do_action( 'before_mainwp_menu' ); ?>
136 <div id="mainwp-main-menu" class="ui inverted vertical accordion menu stackable">
137 <?php
138 if ( is_array( $mainwp_leftmenu ) && !empty( $mainwp_leftmenu ) ) {
139 foreach ( $mainwp_leftmenu as $item ) {
140 $title = wptexturize( $item[ 0 ] );
141 $item_key = $item[ 1 ];
142 $href = $item[ 2 ];
143 $item_id = isset($item[ 3 ]) ? $item[ 3 ] : '';
144
145 $has_sub = true;
146 if ( !isset( $mainwp_sub_leftmenu[ $item_key ] ) || empty( $mainwp_sub_leftmenu[ $item_key ] ) ) {
147 $has_sub = false;
148 }
149 $active_item = '';
150 $set_actived = false;
151 // to fix active menu
152 if ( !$set_actived ) {
153 if ( isset( $_mainwp_menu_active_slugs[ $plugin_page ] ) ) {
154 if ( $item_key == $_mainwp_menu_active_slugs[ $plugin_page ] ) {
155 $active_item = 'active';
156 $set_actived = true;
157 }
158 }
159 }
160
161 $id_attr = !empty($item_id) ? 'id="' . esc_html($item_id) . '"': '';
162
163 if ( $has_sub ) {
164 echo "<div " . $id_attr . " class=\"item $active_item\">";
165 echo "<a class=\"title with-sub $active_item\" href=\"$href\"><b>$title</b> <i class=\"dropdown icon\"></i></a>";
166 echo "<div class=\"content menu $active_item\">";
167 self::render_sub_item( $item_key );
168 echo "</div>";
169 echo "</div>";
170 } else {
171 echo '<div ' . $id_attr . ' class="item">';
172 echo "<a class='title $active_item' href=\"$href\"><b>$title</b></a>";
173 echo "</div>";
174 }
175 }
176 } else {
177 echo "\n\t<div class='item'>";
178 echo "</div>";
179 }
180
181 $go_back_wpadmin_url = admin_url( 'index.php' );
182
183 $link = array(
184 'url' => $go_back_wpadmin_url,
185 'text' => __('Go to WP Admin', 'mainwp'),
186 'tip' => __( 'Click to go back to the site WP Admin area.', 'mainwp' )
187 );
188
189 $go_back_link = apply_filters('mainwp_go_back_wpadmin_link' , $link );
190 if (is_array($go_back_link)) {
191 if (isset($go_back_link['url'])) {
192 $link['url'] = $go_back_link['url'];
193 }
194 if (isset($go_back_link['text'])) {
195 $link['text'] = $go_back_link['text'];
196 }
197 if (isset($go_back_link['tip'])) {
198 $link['tip'] = $go_back_link['tip'];
199 }
200 }
201
202 ?>
203 <div class="item item-wp-admin" style="background-color: rgba(255,255,255,.15);">
204 <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="wordpress icon"></i> <?php echo esc_html($link['text']); ?></b></a> <a class="ui small label" data-position="top right" data-tooltip="<?php _e( 'Logout', 'mainwp' ); ?>" href="<?php echo wp_logout_url(); ?>"><i class="sign-out icon" style="margin:0"></i></a>
205 </div>
206 <div class="hamburger">
207 <span class="hamburger-bun"></span>
208 <span class="hamburger-patty"></span>
209 <span class="hamburger-bun"></span>
210 </div>
211 </div>
212 <?php do_action( 'after_mainwp_menu' ); ?>
213 </div>
214 </div>
215 <script type="text/javascript">
216 jQuery( document ).ready( function () {
217 // click on menu with-sub icon
218 jQuery( '.mainwp-nav-menu a.title.with-sub .icon' ).on( "click", function ( event ) {
219 var pr = jQuery( this ).closest( '.item' );
220 var title = jQuery( this ).closest( '.title' );
221 var active = jQuery( title ).hasClass( 'active' );
222
223 // remove current active
224 mainwp_menu_collapse();
225
226 // if current menu item are not active then set it active
227 if ( !active ) {
228 jQuery( title ).addClass( 'active' );
229 jQuery( pr ).find('.content.menu').addClass( 'active' );
230 pr.addClass('active');
231 }
232 return false;
233 } );
234
235 jQuery( '.mainwp-nav-menu a.title.with-sub' ).on( "click", function ( event ) {
236 var pr = jQuery( this ).closest( '.item' );
237 var active = jQuery( this ).hasClass( 'active' );
238
239 // remove current active
240 mainwp_menu_collapse();
241
242 // set active before go to the page
243 if ( !active ) {
244 jQuery( this ).addClass( 'active' );
245 jQuery( pr ).find('.content.menu').addClass( 'active' );
246 pr.addClass('active');
247 }
248 } );
249
250 mainwp_menu_collapse = function() {
251 // remove current active
252 jQuery( '.mainwp-nav-menu a.title.active').removeClass('active');
253 jQuery( '.mainwp-nav-menu .menu .item').removeClass('active');
254 jQuery( '.mainwp-nav-menu .content.menu.active').removeClass('active');
255 };
256 } );
257 </script>
258 <?php
259 }
260
261 public static function render_sub_item( $parent_key ) {
262 if ( empty( $parent_key ) )
263 return;
264 global $mainwp_sub_leftmenu;
265 $submenu_items = $mainwp_sub_leftmenu[ $parent_key ];
266
267 if ( !is_array( $submenu_items ) || count( $submenu_items ) == 0 )
268 return;
269
270 foreach ( $submenu_items as $sub_key => $sub_item ) {
271 $title = $sub_item[ 0 ];
272 $href = $sub_item[ 1 ];
273 $right = $sub_item[ 2 ];
274 $right_group = 'dashboard';
275 if ( !empty( $right ) ) {
276 if ( strpos( $right, 'extension_' ) === 0 ) {
277 $right_group = 'extension';
278 $right = str_replace( 'extension_', '', $right );
279 }
280 }
281 if ( empty( $right ) || (!empty( $right ) && mainwp_current_user_can( $right_group, $right ) ) ) {
282 ?>
283 <a class="item" href="<?php echo esc_url($href); ?>"><?php echo esc_html($title); ?></a>
284 <?php
285 }
286 }
287
288 }
289
290 }
291