PluginProbe
My WP Customize Admin/Frontend / 1.8
My WP Customize Admin/Frontend v1.8
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.toolbar.php

mywp.controller.module.admin.toolbar.php in My WP Customize Admin/Frontend 1.8, at controller/modules/mywp.controller.module.admin.toolbar.php

1,092 lines 25.8 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( 'MywpControllerModuleAdminToolbar' ) ) :
12
13 final class MywpControllerModuleAdminToolbar extends MywpControllerAbstractModule {
14
15 static protected $id = 'admin_toolbar';
16
17 static private $toolbar = false;
18
19 static private $toolbar_items = false;
20
21 static private $toolbar_items_added_classes = false;
22
23 static private $child_items = array();
24
25 static private $parent_items = array();
26
27 static private $found_parent_item_ids = array();
28
29 static private $current_url = false;
30
31 static private $find_parent_id = array();
32
33 protected static function after_init() {
34
35 add_filter( 'mywp_controller_admin_toolbar_get_toolbar' , array( __CLASS__ , 'mywp_controller_admin_toolbar_get_toolbar' ) );
36
37 }
38
39 public static function mywp_controller_admin_toolbar_get_toolbar( $posts ) {
40
41 global $wp_admin_bar;
42
43 if( ! is_multisite() ) {
44
45 return $posts;
46
47 }
48
49 if( empty( $posts ) ) {
50
51 return $posts;
52
53 }
54
55 $found_my_sites_post_id = false;
56 $found_my_sites_post_key = false;
57 $found_my_sites_item_location = false;
58
59 foreach( $posts as $key => $post ) {
60
61 if( $post->item_default_id === 'my-sites' ) {
62
63 $found_my_sites_post_id = $post->ID;
64 $found_my_sites_post_key = $key;
65 $found_my_sites_item_location = $post->item_location;
66
67 }
68
69 }
70
71 if( ! empty( $found_my_sites_post_id ) ) {
72
73 if( count( $wp_admin_bar->user->blogs ) > 1 ) {
74
75 foreach( $wp_admin_bar->user->blogs as $blog ) {
76
77 switch_to_blog( $blog->userblog_id );
78
79 $menu_base_id = sprintf( 'blog-%s' , $blog->userblog_id );
80
81 $posts[ $menu_base_id ] = (object) array(
82 'ID' => $menu_base_id,
83 'item_parent' => $found_my_sites_post_id,
84 'item_type' => 'default',
85 'item_location' => $found_my_sites_item_location,
86 'item_default_id' => $menu_base_id,
87 'item_default_parent_id' => 'my-sites-list',
88 'item_default_title' => sprintf( '<div class="blavatar"></div>%s' , $blog->blogname ),
89 'item_link_title' => get_bloginfo( 'name' ),
90 'item_link_url' => home_url(),
91 'item_capability' => 'read',
92 );
93
94 if ( current_user_can( 'read' ) ) {
95
96 $menu_dashboard_id = sprintf( '%s-d' , $menu_base_id );
97
98 $posts[ $menu_dashboard_id ] = (object) array(
99 'ID' => $menu_dashboard_id,
100 'item_parent' => $menu_base_id,
101 'item_type' => 'default',
102 'item_location' => $found_my_sites_item_location,
103 'item_default_id' => $menu_dashboard_id,
104 'item_default_parent_id' => $menu_base_id,
105 'item_default_title' => __( 'Dashboard' ),
106 'item_link_title' => __( 'Dashboard' ),
107 'item_link_url' => admin_url(),
108 'item_capability' => 'read',
109 );
110
111 }
112
113 if ( current_user_can( 'manage_options' ) ) {
114
115 $menu_setting_id = sprintf( '%s-o' , $menu_base_id );
116
117 $posts[ $menu_setting_id ] = (object) array(
118 'ID' => $menu_setting_id,
119 'item_parent' => $menu_base_id,
120 'item_type' => 'link',
121 'item_location' => $found_my_sites_item_location,
122 'item_default_id' => '',
123 'item_default_parent_id' => '',
124 'item_default_title' => '',
125 'item_link_title' => __( 'Settings' ),
126 'item_link_url' => admin_url( '/options-general.php' ),
127 'item_capability' => 'manage_options',
128 );
129
130 }
131
132 $menu_frontend_id = sprintf( '%s-v' , $menu_base_id );
133
134 $posts[ $menu_frontend_id ] = (object) array(
135 'ID' => $menu_frontend_id,
136 'item_parent' => $menu_base_id,
137 'item_type' => 'default',
138 'item_location' => $found_my_sites_item_location,
139 'item_default_id' => $menu_frontend_id,
140 'item_default_parent_id' => $menu_base_id,
141 'item_default_title' => __( 'Visit Site' ),
142 'item_link_title' => __( 'Visit Site' ),
143 'item_link_url' => home_url( '/' ),
144 'item_capability' => '',
145 );
146
147 restore_current_blog();
148
149 }
150
151 } else {
152
153 unset( $posts[ $found_my_sites_post_key ] );
154
155 }
156
157 }
158
159 if( current_user_can( 'manage_network' ) ) {
160
161 $found_network_admin_post_id = false;
162 $found_network_admin_post_key = false;
163 $found_network_admin_item_location = false;
164
165 foreach( $posts as $key => $post ) {
166
167 if( $post->item_default_id === 'network-admin' ) {
168
169 $found_network_admin_post_id = $post->ID;
170 $found_network_admin_post_key = $key;
171 $found_network_admin_item_location = $post->item_location;
172
173 }
174
175 }
176
177 if( ! empty( $found_network_admin_post_id ) ) {
178
179 $posts[ $found_network_admin_post_key ]->item_type = 'link';
180 $posts[ $found_network_admin_post_key ]->item_default_title = __( 'Network Admin' );
181 $posts[ $found_network_admin_post_key ]->item_link_url = network_admin_url();
182 $posts[ $found_network_admin_post_key ]->item_capability = 'manage_network';
183
184 $posts['network-admin-d'] = (object) array(
185 'ID' => 'network-admin-d',
186 'item_parent' => $found_network_admin_post_id,
187 'item_type' => 'default',
188 'item_location' => $found_network_admin_item_location,
189 'item_default_id' => 'network-admin-d',
190 'item_default_parent_id' => 'network-admin',
191 'item_default_title' => __( 'Dashboard' ),
192 'item_link_title' => __( 'Dashboard' ),
193 'item_link_url' => network_admin_url(),
194 'item_capability' => 'manage_network',
195 );
196
197 $posts['network-admin-s'] = (object) array(
198 'ID' => 'network-admin-s',
199 'item_parent' => $found_network_admin_post_id,
200 'item_type' => 'default',
201 'item_location' => $found_network_admin_item_location,
202 'item_default_id' => 'network-admin-s',
203 'item_default_parent_id' => 'network-admin',
204 'item_default_title' => __( 'Sites' ),
205 'item_link_title' => __( 'Sites' ),
206 'item_link_url' => network_admin_url( 'sites.php' ),
207 'item_capability' => 'manage_sites',
208 );
209
210 $posts['network-admin-u'] = (object) array(
211 'ID' => 'network-admin-u',
212 'item_parent' => $found_network_admin_post_id,
213 'item_type' => 'default',
214 'item_location' => $found_network_admin_item_location,
215 'item_default_id' => 'network-admin-u',
216 'item_default_parent_id' => 'network-admin',
217 'item_default_title' => __( 'Users' ),
218 'item_link_title' => __( 'Users' ),
219 'item_link_url' => network_admin_url( 'users.php' ),
220 'item_capability' => 'manage_network_users',
221 );
222
223 $posts['network-admin-t'] = (object) array(
224 'ID' => 'network-admin-t',
225 'item_parent' => $found_network_admin_post_id,
226 'item_type' => 'default',
227 'item_location' => $found_network_admin_item_location,
228 'item_default_id' => 'network-admin-t',
229 'item_default_parent_id' => 'network-admin',
230 'item_default_title' => __( 'Themes' ),
231 'item_link_title' => __( 'Themes' ),
232 'item_link_url' => network_admin_url( 'themes.php' ),
233 'item_capability' => 'manage_network_themes',
234 );
235
236 $posts['network-admin-p'] = (object) array(
237 'ID' => 'network-admin-p',
238 'item_parent' => $found_network_admin_post_id,
239 'item_type' => 'default',
240 'item_location' => $found_network_admin_item_location,
241 'item_default_id' => 'network-admin-p',
242 'item_default_parent_id' => 'network-admin',
243 'item_default_title' => __( 'Plugins' ),
244 'item_link_title' => __( 'Plugins' ),
245 'item_link_url' => network_admin_url( 'plugins.php' ),
246 'item_capability' => 'manage_network_plugins',
247 );
248
249 $posts['network-admin-o'] = (object) array(
250 'ID' => 'network-admin-o',
251 'item_parent' => $found_network_admin_post_id,
252 'item_type' => 'default',
253 'item_location' => $found_network_admin_item_location,
254 'item_default_id' => 'network-admin-o',
255 'item_default_parent_id' => 'network-admin',
256 'item_default_title' => __( 'Settings' ),
257 'item_link_title' => __( 'Settings' ),
258 'item_link_url' => network_admin_url( 'settings.php' ),
259 'item_capability' => 'manage_network_options',
260 );
261
262 $posts['network-admin-o'] = (object) array(
263 'ID' => 'network-admin-o',
264 'item_parent' => $found_network_admin_post_id,
265 'item_type' => 'default',
266 'item_location' => $found_network_admin_item_location,
267 'item_default_id' => 'network-admin-o',
268 'item_default_parent_id' => 'network-admin',
269 'item_default_title' => __( 'Settings' ),
270 'item_link_title' => __( 'Settings' ),
271 'item_link_url' => network_admin_url( 'settings.php' ),
272 'item_capability' => 'manage_network_options',
273 );
274
275 if( MywpApi::is_network_manager() ) {
276
277 $posts['network-admin-mywp'] = (object) array(
278 'ID' => 'network-admin-mywp',
279 'item_parent' => $found_network_admin_post_id,
280 'item_type' => 'link',
281 'item_location' => $found_network_admin_item_location,
282 'item_default_id' => '',
283 'item_default_parent_id' => '',
284 'item_default_title' => __( 'My WP' , 'my-wp' ),
285 'item_link_title' => __( 'My WP' , 'my-wp' ),
286 'item_link_url' => add_query_arg( array( 'page' => 'mywp_network' ) , network_admin_url( 'admin.php' ) ),
287 'item_capability' => MywpApi::get_network_manager_capability(),
288 );
289
290 }
291
292 }
293
294 }
295
296 return $posts;
297
298 }
299
300 public static function mywp_controller_initial_data( $initial_data ) {
301
302 $initial_data['custom_menu_ui'] = '';
303 $initial_data['cache_timeout'] = '';
304
305 return $initial_data;
306
307 }
308
309 public static function mywp_controller_default_data( $default_data ) {
310
311 $default_data['custom_menu_ui'] = false;
312 $default_data['cache_timeout'] = '60';
313
314 return $default_data;
315
316 }
317
318 public static function mywp_wp_loaded() {
319
320 if( ! is_admin() ) {
321
322 return false;
323
324 }
325
326 if( is_network_admin() ) {
327
328 return false;
329
330 }
331
332 if( ! self::is_do_controller() ) {
333
334 return false;
335
336 }
337
338 add_action( 'wp_before_admin_bar_render' , array( __CLASS__ , 'remove_detault_menus' ) , 1000 );
339 add_action( 'wp_before_admin_bar_render' , array( __CLASS__ , 'customize_admin_bar' ) , 1000 );
340 add_action( 'wp_after_admin_bar_render' , array( __CLASS__ , 'wp_after_admin_bar_render' ) );
341
342 }
343
344 private static function get_toolbar() {
345
346 global $wp_admin_bar;
347
348 if( ! empty( self::$toolbar ) ) {
349
350 return self::$toolbar;
351
352 }
353
354 $setting_data = self::get_setting_data();
355
356 $timeout_min = 0;
357
358 if( ! empty( $setting_data['cache_timeout'] ) ) {
359
360 $timeout_min = intval( $setting_data['cache_timeout'] );
361
362 }
363
364 $mywp_transient = new MywpTransient( 'admin_toolbar_get_toolbar' , 'controller' );
365
366 if( ! empty( $timeout_min ) ) {
367
368 $transient_toolbar = $mywp_transient->get_data();
369
370 if( ! empty( $transient_toolbar ) ) {
371
372 self::$toolbar = $transient_toolbar;
373
374 return self::$toolbar;
375
376 }
377
378 }
379
380 $args = array(
381 'post_status' => array( 'publish' ),
382 'post_type' => 'mywp_admin_toolbar',
383 'order' => 'ASC',
384 'orderby' => 'menu_order',
385 'posts_per_page' => -1,
386 'tax_query' => array(
387 array(
388 'taxonomy' => 'mywp_term',
389 'field' => 'slug',
390 'terms' => 'default',
391 ),
392 ),
393 );
394
395 $args = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_args' , $args );
396
397 $posts = MywpController::get_posts( $args , self::$id );
398
399 $toolbar = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar' , $posts );
400
401 self::$toolbar = $toolbar;
402
403 if( ! empty( $timeout_min ) && ! empty( $toolbar ) ) {
404
405 $toolbar_strlen = strlen( maybe_serialize( self::$toolbar ) );
406
407 if( $toolbar_strlen < MywpHelper::get_max_allowed_packet_size() ) {
408
409 $mywp_transient->update_data( self::$toolbar , $timeout_min * MINUTE_IN_SECONDS );
410
411 }
412
413 }
414
415 return $toolbar;
416
417 }
418
419 private static function get_toolbar_items() {
420
421 if( ! empty( self::$toolbar_items ) ) {
422
423 return self::$toolbar_items;
424
425 }
426
427 $toolbar = self::get_toolbar();
428
429 if( empty( $toolbar ) ) {
430
431 return false;
432
433 }
434
435 $toolbar_items = array();
436
437 foreach( $toolbar as $key => $toolbar_item ) {
438
439 if( $toolbar_item->item_type === 'default') {
440
441 $toolbar_item = MywpAdminToolbar::default_item_convert( $toolbar_item );
442
443 if( ! empty( $toolbar_item ) ) {
444
445 $toolbar_items[] = $toolbar_item;
446
447 }
448
449 } else {
450
451 $toolbar_items[] = $toolbar_item;
452
453 }
454
455 }
456
457 $toolbar_items = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_item' , $toolbar_items );
458
459 if( empty( $toolbar_items ) ) {
460
461 return false;
462
463 }
464
465 ksort( $toolbar_items );
466
467 self::$toolbar_items = $toolbar_items;
468
469 return $toolbar_items;
470
471 }
472
473 private static function get_toolbar_items_added_classes(){
474
475 if( ! empty( self::$toolbar_items_added_classes ) ) {
476
477 return self::$toolbar_items_added_classes;
478
479 }
480
481 $toolbar_items = self::get_toolbar_items();
482
483 if( empty( $toolbar_items ) ) {
484
485 return false;
486
487 }
488
489 foreach( $toolbar_items as $key => $toolbar_item ) {
490
491 if( ! is_object( $toolbar_item ) ) {
492
493 unset( $toolbar_item[ $key ] );
494
495 continue;
496
497 }
498
499 if( empty( $toolbar_item->item_li_class ) ) {
500
501 $toolbar_items[ $key ]->item_li_class = '';
502
503 }
504
505 if( empty( $toolbar_item->item_link_class ) ) {
506
507 $toolbar_items[ $key ]->item_link_class = '';
508
509 }
510
511 if( empty( $toolbar_item->item_link_url ) ) {
512
513 $toolbar_items[ $key ]->item_link_url = '';
514
515 }
516
517 if( empty( $toolbar_item->item_link_url_parse ) ) {
518
519 $toolbar_items[ $key ]->item_link_url_parse = array();
520
521 }
522
523 if( empty( $toolbar_item->item_link_url_parse_query ) ) {
524
525 $toolbar_items[ $key ]->item_link_url_parse_query = array();
526
527 }
528
529 $toolbar_item->item_link_url = do_shortcode( $toolbar_item->item_link_url );
530
531 $toolbar_items[ $key ]->item_link_url = $toolbar_item->item_link_url;
532
533 if( ! empty( $toolbar_item->item_link_url ) ) {
534
535 $item_link_url_parse = parse_url( $toolbar_item->item_link_url );
536
537 if( isset( $item_link_url_parse['fragment'] ) ) {
538
539 unset( $item_link_url_parse['fragment'] );
540
541 }
542
543 if( empty( $item_link_url_parse['query'] ) ) {
544
545 $item_link_url_parse['query'] = '';
546
547 }
548
549 $toolbar_items[ $key ]->item_link_url_parse = $item_link_url_parse;
550
551 if( ! empty( $item_link_url_parse['query'] ) ) {
552
553 wp_parse_str( $item_link_url_parse['query'] , $item_link_url_parse_query );
554
555 ksort( $item_link_url_parse_query );
556
557 $toolbar_items[ $key ]->item_link_url_parse_query = $item_link_url_parse_query;
558
559 }
560
561 }
562
563 }
564
565 foreach( $toolbar_items as $key => $toolbar_item ) {
566
567 self::$child_items[ $toolbar_item->item_parent ][] = $toolbar_item;
568
569 }
570
571 $tmp = $toolbar_items;
572
573 foreach( $toolbar_items as $key => $toolbar_item ) {
574
575 if( empty( $toolbar_item->item_parent ) ) {
576
577 continue;
578
579 }
580
581 foreach( $tmp as $tmp_key => $tmp_toolbar_item ) {
582
583 if( (string) $tmp_toolbar_item->ID === (string) $toolbar_item->item_parent ) {
584
585 self::$parent_items[ $toolbar_item->ID ][] = $tmp_toolbar_item;
586
587 break;
588
589 }
590
591 }
592
593 }
594
595 unset( $tmp );
596
597 $first = true;
598
599 foreach( $toolbar_items as $key => $toolbar_item ) {
600
601 }
602
603 $current_url = self::get_current_url();
604
605 $current_url_parse = parse_url( $current_url );
606 $current_url_query = array();
607
608 if( isset( $current_url_parse['fragment'] ) ) {
609
610 unset( $current_url_parse['fragment'] );
611
612 }
613
614 if( ! empty( $current_url_parse['query'] ) ) {
615
616 wp_parse_str( $current_url_parse['query'] , $current_url_query );
617
618 ksort( $current_url_query );
619
620 } else {
621
622 $current_url_parse['query'] = '';
623
624 }
625
626 $found_current_item_ids = array();
627
628 foreach( $toolbar_items as $key => $toolbar_item ) {
629
630 if( empty( $toolbar_item->item_link_url_parse['host'] ) or empty( $toolbar_item->item_link_url_parse['path'] ) ) {
631
632 continue;
633
634 }
635
636 if(
637 $current_url_parse['scheme'] === $toolbar_item->item_link_url_parse['scheme'] &&
638 $current_url_parse['host'] === $toolbar_item->item_link_url_parse['host'] &&
639 $current_url_parse['path'] === $toolbar_item->item_link_url_parse['path'] &&
640 $current_url_query === $toolbar_item->item_link_url_parse_query
641 ) {
642
643 $found_current_item_ids[] = $toolbar_item->ID;
644
645 }
646
647 }
648
649 if( empty( $found_current_item_ids ) ) {
650
651 $identification_query = array();
652
653 if( ! empty( $current_url_query['page'] ) ) {
654
655 $identification_query['page'] = $current_url_query['page'];
656
657 }
658
659 if( ! empty( $current_url_query['post_type'] ) ) {
660
661 if( $current_url_query['post_type'] != 'post' ) {
662
663 $identification_query['post_type'] = $current_url_query['post_type'];
664
665 }
666
667 }
668
669 if( ! empty( $current_url_query['taxonomy'] ) ) {
670
671 $identification_query['taxonomy'] = $current_url_query['taxonomy'];
672
673 }
674
675 foreach( $toolbar_items as $key => $toolbar_item ) {
676
677 if( empty( $toolbar_item->item_link_url_parse['host'] ) or empty( $toolbar_item->item_link_url_parse['path'] ) ) {
678
679 continue;
680
681 }
682
683 if(
684 $current_url_parse['scheme'] === $toolbar_item->item_link_url_parse['scheme'] &&
685 $current_url_parse['host'] === $toolbar_item->item_link_url_parse['host'] &&
686 $current_url_parse['path'] === $toolbar_item->item_link_url_parse['path'] &&
687 http_build_query( $identification_query ) === $toolbar_item->item_link_url_parse['query']
688 ) {
689
690 $found_current_item_ids[] = $toolbar_item->ID;
691
692 }
693
694 }
695
696 }
697
698 $found_current_item_ids = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_item_added_classes_found_current_item_ids' , $found_current_item_ids , $toolbar_items , $current_url , $current_url_parse , $current_url_query );
699
700 if( ! empty( $found_current_item_ids ) ) {
701
702 $found_current_item_ids = array_map( 'strip_tags' , $found_current_item_ids );
703
704 }
705
706 if( ! empty( $found_current_item_ids ) ) {
707
708 foreach( $toolbar_items as $key => $toolbar_item ) {
709
710 if( in_array( $toolbar_item->ID , $found_current_item_ids ) ) {
711
712 $toolbar_items[ $key ]->item_li_class .= ' current';
713 $toolbar_items[ $key ]->item_link_class .= ' current';
714
715 }
716
717 }
718
719 }
720
721 $toolbar_items = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_item_added_classes' , $toolbar_items );
722
723 self::$toolbar_items_added_classes = $toolbar_items;
724
725 return self::$toolbar_items_added_classes;
726
727 }
728
729 private static function get_find_menu_items_to_parent_id( $parent_id = 0 ) {
730
731 $toolbar_items_added_classes = self::get_toolbar_items_added_classes();
732
733 if( empty( $toolbar_items_added_classes ) ) {
734
735 return false;
736
737 }
738
739 if( ! empty( $parent_id ) ) {
740
741 if( is_numeric( $parent_id ) ) {
742
743 $parent_id = intval( $parent_id );
744
745 } else {
746
747 $parent_id = strip_tags( $parent_id );
748
749 }
750
751 }
752
753 if( ! empty( self::$find_parent_id[ $parent_id ] ) ) {
754
755 return self::$find_parent_id[ $parent_id ];
756
757 }
758
759 $find_items = array();
760
761 foreach( $toolbar_items_added_classes as $item ) {
762
763 $item_parent = $item->item_parent;
764
765 if( ! empty( $item_parent ) ) {
766
767 if( is_numeric( $item_parent ) ) {
768
769 $item_parent = intval( $item_parent );
770
771 } else {
772
773 $item_parent = strip_tags( $item_parent );
774
775 }
776
777 }
778
779 if( $item_parent !== $parent_id ) {
780
781 continue;
782
783 }
784
785 $find_items[] = $item;
786
787 }
788
789 if( empty( $find_items ) ) {
790
791 return false;
792
793 }
794
795 self::$find_parent_id[ $parent_id ] = $find_items;
796
797 return $find_items;
798
799 }
800
801 private static function get_current_url() {
802
803 if( ! empty( self::$current_url ) ) {
804
805 return self::$current_url;
806
807 }
808
809 $current_url = urldecode( do_shortcode( '[mywp_url current="1"]' ) );
810
811 self::$current_url = $current_url;
812
813 return $current_url;
814
815 }
816
817 public static function remove_detault_menus() {
818
819 global $wp_admin_bar;
820
821 if( empty( $wp_admin_bar ) ) {
822
823 return false;
824
825 }
826
827 if( ! self::is_do_function( __FUNCTION__ ) ) {
828
829 return false;
830
831 }
832
833 $parent_items = self::get_find_menu_items_to_parent_id();
834
835 if( empty( $parent_items ) ) {
836
837 return false;
838
839 }
840
841 $admin_bar_all_nodes = $wp_admin_bar->get_nodes();
842
843 foreach( $admin_bar_all_nodes as $node ) {
844
845 if( $node->id === 'top-secondary' ) {
846
847 continue;
848
849 }
850
851 $wp_admin_bar->remove_menu( $node->id );
852
853 }
854
855 self::after_do_function( __FUNCTION__ );
856
857 }
858
859 public static function customize_admin_bar() {
860
861 global $wp_admin_bar;
862
863 if( empty( $wp_admin_bar ) ) {
864
865 return false;
866
867 }
868
869 if( ! self::is_do_function( __FUNCTION__ ) ) {
870
871 return false;
872
873 }
874
875 $parent_items = self::get_find_menu_items_to_parent_id();
876
877 if( empty( $parent_items ) ) {
878
879 return false;
880
881 }
882
883 foreach( $parent_items as $item ) {
884
885 self::add_toolbar_item( $item );
886
887 }
888
889 self::after_do_function( __FUNCTION__ );
890
891 }
892
893 private static function add_toolbar_item( $item ) {
894
895 global $wp_admin_bar;
896
897 if( empty( $item ) or empty( $item->item_type ) or empty( $item->ID ) ) {
898
899 return false;
900
901 }
902
903 $toolbar_items_added_classes = self::get_toolbar_items_added_classes();
904
905 $item = apply_filters( 'mywp_controller_admin_toolbar_add_toolbar_item' , $item );
906
907 if( ! empty( $item->item_capability ) ) {
908
909 if( ! current_user_can( $item->item_capability ) ) {
910
911 return false;
912
913 }
914
915 }
916
917 $item_id = $item->ID;
918
919 if( is_numeric( $item_id ) ) {
920
921 $item_id = intval( $item_id );
922
923 } else {
924
925 $item_id = strip_tags( $item_id );
926
927 }
928
929 $item_type = $item->item_type;
930 $node_parent = $item->item_parent;
931 $item_location = $item->item_location;
932
933 $item_meta = array();
934
935 if( ! empty( $item->item_meta ) ) {
936
937 $item_meta = $item->item_meta;
938
939 }
940
941 if( ! isset( $item_meta['class'] ) ) {
942
943 $item_meta['class'] = false;
944
945 }
946
947 $item->item_link_title = do_shortcode( $item->item_link_title );
948
949 $li_class = '';
950
951 if( ! empty( $item->item_li_class ) ) {
952
953 $li_class = $item->item_li_class;
954
955 }
956
957 $li_id = '';
958
959 if( ! empty( $item->item_li_id ) ) {
960
961 $li_id = $item->item_li_id;
962
963 }
964
965 if( (string) $node_parent === '0' ) {
966
967 $node_parent = '';
968
969 }
970
971 if( $item_location === 'right' ) {
972
973 if( (string) $node_parent === '' ) {
974
975 $node_parent = 'top-secondary';
976
977 }
978
979 }
980
981 $node_id = $item->ID;
982
983 if( ! empty( $item->item_default_id ) ) {
984
985 $node_id = $item->item_default_id;
986
987 foreach( $toolbar_items_added_classes as $toolbar_items_added_classes_item ) {
988
989 if( $toolbar_items_added_classes_item->ID === $item->item_parent ) {
990
991 $node_parent = $toolbar_items_added_classes_item->item_default_id;
992
993 break;
994
995 }
996
997 }
998
999 }
1000
1001 $node_group = false;
1002
1003 if( $item_type === 'group' ) {
1004
1005 $node_group = 1;
1006
1007 } elseif( $item_type === 'custom' ) {
1008
1009 $item_meta['html'] = do_shortcode( $item->item_custom_html );
1010
1011 }
1012
1013 if( ! empty( $item->item_icon_class ) ) {
1014
1015 $title = sprintf( '<span class="%s"></span>' , esc_attr( $item->item_icon_class ) ) . $item->item_link_title;
1016
1017 } else {
1018
1019 $title = $item->item_link_title;
1020
1021 }
1022
1023 if( empty( $node_group ) ) {
1024
1025 $add_menu = array( 'id' => $node_id , 'title' => $title , 'parent' => $node_parent , 'href' => $item->item_link_url , 'meta' => $item_meta );
1026
1027 $wp_admin_bar->add_menu( $add_menu );
1028
1029 } else {
1030
1031 if( strpos( $item_meta['class'] , 'ab-sub-secondary' ) === false ) {
1032
1033 $item_meta['class'] .= ' ab-sub-secondary';
1034
1035 }
1036
1037 $add_menu = array( 'id' => $node_id , 'parent' => $node_parent , 'meta' => $item_meta );
1038
1039 $wp_admin_bar->add_group( $add_menu );
1040
1041 }
1042
1043 $child_items = self::get_find_menu_items_to_parent_id( $item_id );
1044
1045 if( ! empty( $child_items ) ) {
1046
1047 foreach( $child_items as $child_item ) {
1048
1049 self::add_toolbar_item( $child_item );
1050
1051 }
1052
1053 }
1054
1055 }
1056
1057 public static function wp_after_admin_bar_render() {
1058
1059 global $wp_scripts;
1060
1061 $toolbar = self::get_toolbar();
1062
1063 if( empty( $toolbar ) ) {
1064
1065 return false;
1066
1067 }
1068
1069 $wp_styles = wp_styles();
1070
1071 printf( '<link rel="stylesheet" id="mywp_admin_toolbar-css" href="%sadmin-toolbar.css?ver=%s" type="text/css" media="all" />' , esc_url( MywpApi::get_plugin_url( 'css' ) ) , $wp_styles->default_version );
1072
1073 printf( '<script type="text/javascript" src="%sadmin-toolbar.js?ver=%s"></script>' , esc_url( MywpApi::get_plugin_url( 'js' ) ) , $wp_styles->default_version );
1074
1075 $setting_data = self::get_setting_data();
1076
1077 if( ! empty( $setting_data['custom_menu_ui'] ) ) {
1078
1079 printf( '<link rel="stylesheet" id="mywp_admin_toolbar-custom-ui-css" href="%sadmin-toolbar-custom-ui.css?ver=%s" type="text/css" media="all" />' , esc_url( MywpApi::get_plugin_url( 'css' ) ) , MYWP_VERSION );
1080
1081 printf( '<script type="text/javascript" src="%sadmin-toolbar-custom-ui.js?ver=%s"></script>' , esc_url( MywpApi::get_plugin_url( 'js' ) ) , MYWP_VERSION );
1082
1083 }
1084
1085 }
1086
1087 }
1088
1089 MywpControllerModuleAdminToolbar::init();
1090
1091 endif;
1092