PluginProbe
My WP Customize Admin/Frontend / 1.5
My WP Customize Admin/Frontend v1.5
1.27.4 1.27.3 trunk 1.0 1.1 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.10 1.10.1 1.10.2 1.11 1.12 1.12.1 1.12.2 1.13 1.13.1 1.13.2 1.14 1.15.0 1.16 1.17.0 All 76 releases
my-wp / controller / modules / mywp.controller.module.admin.nav-menu.php

mywp.controller.module.admin.nav-menu.php in My WP Customize Admin/Frontend 1.5, at controller/modules/mywp.controller.module.admin.nav-menu.php

384 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 if( ! class_exists( 'MywpControllerAbstractModule' ) ) {
8 return false;
9 }
10
11 if ( ! class_exists( 'MywpControllerModuleAdminNavMenu' ) ) :
12
13 final class MywpControllerModuleAdminNavMenu extends MywpControllerAbstractModule {
14
15 static protected $id = 'admin_nav_menu';
16
17 public static function mywp_controller_initial_data( $initial_data ) {
18
19 $initial_data['hide_add_new_menu'] = '';
20 $initial_data['hide_delete_menu'] = '';
21 $initial_data['hide_manage_locations'] = '';
22 $initial_data['hide_menu_settings'] = '';
23 $initial_data['hide_live_preview_button'] = '';
24
25 $initial_data['remove_meta_boxes_items'] = array();
26
27 $initial_data['hide_link_target'] = '';
28 $initial_data['hide_title_attribute'] = '';
29 $initial_data['hide_css_classes'] = '';
30 $initial_data['hide_xfn'] = '';
31 $initial_data['hide_description'] = '';
32
33 return $initial_data;
34
35 }
36
37 public static function mywp_controller_default_data( $default_data ) {
38
39 $default_data['hide_add_new_menu'] = false;
40 $default_data['hide_delete_menu'] = false;
41 $default_data['hide_manage_locations'] = false;
42 $default_data['hide_menu_settings'] = false;
43 $default_data['hide_live_preview_button'] = false;
44
45 $default_data['remove_meta_boxes_items'] = array();
46
47 $default_data['hide_link_target'] = false;
48 $default_data['hide_title_attribute'] = false;
49 $default_data['hide_css_classes'] = false;
50 $default_data['hide_xfn'] = false;
51 $default_data['hide_description'] = false;
52
53 return $default_data;
54
55 }
56
57 public static function mywp_wp_loaded() {
58
59 if( ! is_admin() ) {
60
61 return false;
62
63 }
64
65 if( is_network_admin() ) {
66
67 return false;
68
69 }
70
71 if( ! self::is_do_controller() ) {
72
73 return false;
74
75 }
76
77 add_action( 'load-nav-menus.php' , array( __CLASS__ , 'load_nav_menus' ) , 1000 );
78
79 }
80
81 public static function load_nav_menus() {
82
83 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_menus' ) );
84 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_advanced_menu_properties' ) );
85 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_delete_menu' ) );
86 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_manage_locations' ) );
87 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_menu_settings' ) );
88 add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_live_preview_button' ) );
89 add_action( 'admin_head-nav-menus.php' , array( __CLASS__ , 'remove_menu_meta_boxes_items' ) );
90
91 }
92
93 public static function hide_menus() {
94
95 if( ! self::is_do_function( __FUNCTION__ ) ) {
96
97 return false;
98
99 }
100
101 $setting_data = self::get_setting_data();
102
103 if( empty( $setting_data['hide_add_new_menu'] ) ) {
104
105 return false;
106
107 }
108
109 echo '<style>';
110
111 $nav_menus = wp_get_nav_menus();
112
113 if( count( $nav_menus ) > 1 ) {
114
115 echo 'body.wp-admin .wrap > .manage-menus .add-new-menu-action, .locations-row-links .locations-add-menu-link { display: none; }';
116
117 } else {
118
119 echo 'body.wp-admin .wrap > .manage-menus, .locations-row-links .locations-add-menu-link { display: none; }';
120
121 }
122
123 echo '</style>';
124
125 self::after_do_function( __FUNCTION__ );
126
127 }
128
129 public static function hide_advanced_menu_properties() {
130
131 if( ! self::is_do_function( __FUNCTION__ ) ) {
132
133 return false;
134
135 }
136
137 $setting_data = self::get_setting_data();
138
139 if( empty( $setting_data ) ) {
140
141 return false;
142
143 }
144
145 echo '<style>';
146
147 if(
148 ! empty( $setting_data['hide_link_target'] )
149 && ! empty( $setting_data['hide_title_attribute'] )
150 && ! empty( $setting_data['hide_css_classes'] )
151 && ! empty( $setting_data['hide_xfn'] )
152 && ! empty( $setting_data['hide_description'] )
153 ) {
154
155 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) { display: none; }';
156
157 }
158
159 if( ! empty( $setting_data['hide_link_target'] ) ) {
160
161 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) label:nth-of-type(1) { display: none; }';
162 echo 'body.wp-admin #menu-to-edit .menu-item-settings p.field-link-target { display: none; }';
163
164 }
165
166 if( ! empty( $setting_data['hide_title_attribute'] ) ) {
167
168 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) label:nth-of-type(2) { display: none; }';
169 echo 'body.wp-admin #menu-to-edit .menu-item-settings p.field-title-attribute { display: none; }';
170
171 }
172
173 if( ! empty( $setting_data['hide_css_classes'] ) ) {
174
175 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) label:nth-of-type(3) { display: none; }';
176 echo 'body.wp-admin #menu-to-edit .menu-item-settings p.field-css-classes { display: none; }';
177
178 }
179
180 if( ! empty( $setting_data['hide_xfn'] ) ) {
181
182 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) label:nth-of-type(4) { display: none; }';
183 echo 'body.wp-admin #menu-to-edit .menu-item-settings p.field-xfn { display: none; }';
184
185 }
186
187 if( ! empty( $setting_data['hide_description'] ) ) {
188
189 echo 'body.wp-admin #screen-meta #adv-settings .metabox-prefs:nth-child(2) label:nth-of-type(5) { display: none; }';
190 echo 'body.wp-admin #menu-to-edit .menu-item-settings p.field-description { display: none; }';
191
192 }
193
194 echo '</style>';
195
196 self::after_do_function( __FUNCTION__ );
197
198 }
199
200 public static function hide_delete_menu() {
201
202 if( ! self::is_do_function( __FUNCTION__ ) ) {
203
204 return false;
205
206 }
207
208 $setting_data = self::get_setting_data();
209
210 if( empty( $setting_data['hide_delete_menu'] ) ) {
211
212 return false;
213
214 }
215
216 echo '<style>';
217
218 echo 'body.wp-admin .major-publishing-actions .delete-action { display: none; }';
219
220 echo '</style>';
221
222 self::after_do_function( __FUNCTION__ );
223
224 }
225
226 public static function hide_manage_locations() {
227
228 if( ! self::is_do_function( __FUNCTION__ ) ) {
229
230 return false;
231
232 }
233
234 $setting_data = self::get_setting_data();
235
236 if( empty( $setting_data['hide_manage_locations'] ) ) {
237
238 return false;
239
240 }
241
242 echo '<style>';
243
244 echo 'body.wp-admin h2.nav-tab-wrapper a:nth-child(2) { display: none; }';
245
246 echo '</style>';
247
248 self::after_do_function( __FUNCTION__ );
249
250 }
251
252 public static function hide_menu_settings() {
253
254 if( ! self::is_do_function( __FUNCTION__ ) ) {
255
256 return false;
257
258 }
259
260 $setting_data = self::get_setting_data();
261
262 if( empty( $setting_data['hide_menu_settings'] ) ) {
263
264 return false;
265
266 }
267
268 echo '<style>';
269
270 echo 'body.wp-admin .menu-settings { display: none; }';
271
272 echo '</style>';
273
274 self::after_do_function( __FUNCTION__ );
275
276 }
277
278 public static function hide_live_preview_button() {
279
280 if( ! self::is_do_function( __FUNCTION__ ) ) {
281
282 return false;
283
284 }
285
286 $setting_data = self::get_setting_data();
287
288 if( empty( $setting_data['hide_live_preview_button'] ) ) {
289
290 return false;
291
292 }
293
294 echo '<style>';
295
296 echo 'body.wp-admin .wrap h1 a { display: none; }';
297 echo 'body.wp-admin .wrap .page-title-action { display: none; }';
298
299 echo '</style>';
300
301 self::after_do_function( __FUNCTION__ );
302
303 }
304
305 public static function remove_menu_meta_boxes_items() {
306
307 if( ! self::is_do_function( __FUNCTION__ ) ) {
308
309 return false;
310
311 }
312
313 $setting_data = self::get_setting_data();
314
315 if( empty( $setting_data['remove_meta_boxes_items'] ) ) {
316
317 return false;
318
319 }
320
321 foreach( $setting_data['remove_meta_boxes_items'] as $meta_box_id => $v ) {
322
323 $context = self::get_meta_box_context( $meta_box_id );
324
325 if( empty( $context ) ) {
326
327 continue;
328
329 }
330
331 remove_meta_box( $meta_box_id , 'nav-menus' , $context );
332
333 }
334
335 self::after_do_function( __FUNCTION__ );
336
337 }
338
339 private static function get_meta_box_context( $find_meta_box_id ) {
340
341 global $wp_meta_boxes;
342
343 if( empty( $wp_meta_boxes['nav-menus'] ) ) {
344
345 return false;
346
347 }
348
349 $nav_menu_meta_boxes = $wp_meta_boxes['nav-menus'];
350
351 $meta_box_context = false;
352
353 foreach( $nav_menu_meta_boxes as $context => $priority_meta_boxes ) {
354
355 foreach( $priority_meta_boxes as $priority => $meta_boxes ) {
356
357 foreach( $meta_boxes as $meta_box_id => $meta_box ) {
358
359 if( $find_meta_box_id != $meta_box_id ) {
360
361 continue;
362
363 }
364
365 $meta_box_context = $context;
366
367 break;
368
369 }
370
371 }
372
373 }
374
375 return $meta_box_context;
376
377 }
378
379 }
380
381 MywpControllerModuleAdminNavMenu::init();
382
383 endif;
384