| 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 |
public static function mywp_controller_initial_data( $initial_data ) { |
| 34 |
|
| 35 |
$initial_data['custom_menu_ui'] = ''; |
| 36 |
|
| 37 |
return $initial_data; |
| 38 |
|
| 39 |
} |
| 40 |
|
| 41 |
public static function mywp_controller_default_data( $default_data ) { |
| 42 |
|
| 43 |
$default_data['custom_menu_ui'] = false; |
| 44 |
|
| 45 |
return $default_data; |
| 46 |
|
| 47 |
} |
| 48 |
|
| 49 |
public static function mywp_wp_loaded() { |
| 50 |
|
| 51 |
if( ! is_admin() ) { |
| 52 |
|
| 53 |
return false; |
| 54 |
|
| 55 |
} |
| 56 |
|
| 57 |
if( is_network_admin() ) { |
| 58 |
|
| 59 |
return false; |
| 60 |
|
| 61 |
} |
| 62 |
|
| 63 |
if( ! self::is_do_controller() ) { |
| 64 |
|
| 65 |
return false; |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
add_action( 'admin_enqueue_scripts' , array( __CLASS__ , 'admin_enqueue_scripts' ) ); |
| 70 |
add_action( 'wp_before_admin_bar_render' , array( __CLASS__ , 'remove_detault_menus' ) , 1000 ); |
| 71 |
add_action( 'wp_before_admin_bar_render' , array( __CLASS__ , 'customize_admin_bar' ) , 1000 ); |
| 72 |
|
| 73 |
} |
| 74 |
|
| 75 |
private static function get_toolbar() { |
| 76 |
|
| 77 |
if( ! empty( self::$toolbar ) ) { |
| 78 |
|
| 79 |
return self::$toolbar; |
| 80 |
|
| 81 |
} |
| 82 |
|
| 83 |
$args = array( 'post_status' => array( 'publish' ) , 'post_type' => 'mywp_admin_toolbar' , 'order' => 'ASC' , 'orderby' => 'menu_order' , 'posts_per_page' => -1 ); |
| 84 |
|
| 85 |
$args = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_args' , $args ); |
| 86 |
|
| 87 |
$posts = MywpPostType::get_posts( $args ); |
| 88 |
|
| 89 |
$toolbar = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar' , $posts ); |
| 90 |
|
| 91 |
self::$toolbar = $toolbar; |
| 92 |
|
| 93 |
return $toolbar; |
| 94 |
|
| 95 |
} |
| 96 |
|
| 97 |
private static function get_toolbar_items() { |
| 98 |
|
| 99 |
if( ! empty( self::$toolbar_items ) ) { |
| 100 |
|
| 101 |
return self::$toolbar_items; |
| 102 |
|
| 103 |
} |
| 104 |
|
| 105 |
$toolbar = self::get_toolbar(); |
| 106 |
|
| 107 |
if( empty( $toolbar ) ) { |
| 108 |
|
| 109 |
return false; |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
$toolbar_items = array(); |
| 114 |
|
| 115 |
foreach( $toolbar as $key => $toolbar_item ) { |
| 116 |
|
| 117 |
if( $toolbar_item->item_type == 'default') { |
| 118 |
|
| 119 |
$toolbar_item = MywpAdminToolbar::default_item_convert( $toolbar_item ); |
| 120 |
|
| 121 |
if( ! empty( $toolbar_item ) ) { |
| 122 |
|
| 123 |
$toolbar_items[] = $toolbar_item; |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
} else { |
| 128 |
|
| 129 |
$toolbar_items[] = $toolbar_item; |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
} |
| 134 |
|
| 135 |
$toolbar_items = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_item' , $toolbar_items ); |
| 136 |
|
| 137 |
if( empty( $toolbar_items ) ) { |
| 138 |
|
| 139 |
return false; |
| 140 |
|
| 141 |
} |
| 142 |
|
| 143 |
ksort( $toolbar_items ); |
| 144 |
|
| 145 |
self::$toolbar_items = $toolbar_items; |
| 146 |
|
| 147 |
return $toolbar_items; |
| 148 |
|
| 149 |
} |
| 150 |
|
| 151 |
private static function get_toolbar_items_added_classes(){ |
| 152 |
|
| 153 |
if( ! empty( self::$toolbar_items_added_classes ) ) { |
| 154 |
|
| 155 |
return self::$toolbar_items_added_classes; |
| 156 |
|
| 157 |
} |
| 158 |
|
| 159 |
$toolbar_items = self::get_toolbar_items(); |
| 160 |
|
| 161 |
if( empty( $toolbar_items ) ) { |
| 162 |
|
| 163 |
return false; |
| 164 |
|
| 165 |
} |
| 166 |
|
| 167 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 168 |
|
| 169 |
if( ! is_object( $toolbar_item ) ) { |
| 170 |
|
| 171 |
unset( $toolbar_item[ $key ] ); |
| 172 |
|
| 173 |
continue; |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
if( empty( $toolbar_item->item_li_class ) ) { |
| 178 |
|
| 179 |
$toolbar_items[ $key ]->item_li_class = ''; |
| 180 |
|
| 181 |
} |
| 182 |
|
| 183 |
if( empty( $toolbar_item->item_link_class ) ) { |
| 184 |
|
| 185 |
$toolbar_items[ $key ]->item_link_class = ''; |
| 186 |
|
| 187 |
} |
| 188 |
|
| 189 |
if( empty( $toolbar_item->item_link_url ) ) { |
| 190 |
|
| 191 |
$toolbar_items[ $key ]->item_link_url = ''; |
| 192 |
|
| 193 |
} |
| 194 |
|
| 195 |
if( empty( $toolbar_item->item_link_url_parse ) ) { |
| 196 |
|
| 197 |
$toolbar_items[ $key ]->item_link_url_parse = array(); |
| 198 |
|
| 199 |
} |
| 200 |
|
| 201 |
if( empty( $toolbar_item->item_link_url_parse_query ) ) { |
| 202 |
|
| 203 |
$toolbar_items[ $key ]->item_link_url_parse_query = array(); |
| 204 |
|
| 205 |
} |
| 206 |
|
| 207 |
$toolbar_item->item_link_url = do_shortcode( $toolbar_item->item_link_url ); |
| 208 |
|
| 209 |
$toolbar_items[ $key ]->item_link_url = $toolbar_item->item_link_url; |
| 210 |
|
| 211 |
if( ! empty( $toolbar_item->item_link_url ) ) { |
| 212 |
|
| 213 |
$item_link_url_parse = parse_url( $toolbar_item->item_link_url ); |
| 214 |
|
| 215 |
if( isset( $item_link_url_parse['fragment'] ) ) { |
| 216 |
|
| 217 |
unset( $item_link_url_parse['fragment'] ); |
| 218 |
|
| 219 |
} |
| 220 |
|
| 221 |
if( empty( $item_link_url_parse['query'] ) ) { |
| 222 |
|
| 223 |
$item_link_url_parse['query'] = ''; |
| 224 |
|
| 225 |
} |
| 226 |
|
| 227 |
$toolbar_items[ $key ]->item_link_url_parse = $item_link_url_parse; |
| 228 |
|
| 229 |
if( ! empty( $item_link_url_parse['query'] ) ) { |
| 230 |
|
| 231 |
wp_parse_str( $item_link_url_parse['query'] , $item_link_url_parse_query ); |
| 232 |
|
| 233 |
ksort( $item_link_url_parse_query ); |
| 234 |
|
| 235 |
$toolbar_items[ $key ]->item_link_url_parse_query = $item_link_url_parse_query; |
| 236 |
|
| 237 |
} |
| 238 |
|
| 239 |
} |
| 240 |
|
| 241 |
} |
| 242 |
|
| 243 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 244 |
|
| 245 |
self::$child_items[ $toolbar_item->item_parent ][] = $toolbar_item; |
| 246 |
|
| 247 |
} |
| 248 |
|
| 249 |
$tmp = $toolbar_items; |
| 250 |
|
| 251 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 252 |
|
| 253 |
if( empty( $toolbar_item->item_parent ) ) { |
| 254 |
|
| 255 |
continue; |
| 256 |
|
| 257 |
} |
| 258 |
|
| 259 |
foreach( $tmp as $tmp_key => $tmp_toolbar_item ) { |
| 260 |
|
| 261 |
if( $tmp_toolbar_item->ID == $toolbar_item->item_parent ) { |
| 262 |
|
| 263 |
self::$parent_items[ $toolbar_item->ID ][] = $tmp_toolbar_item; |
| 264 |
|
| 265 |
break; |
| 266 |
|
| 267 |
} |
| 268 |
|
| 269 |
} |
| 270 |
|
| 271 |
} |
| 272 |
|
| 273 |
unset( $tmp ); |
| 274 |
|
| 275 |
$first = true; |
| 276 |
|
| 277 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 278 |
|
| 279 |
} |
| 280 |
|
| 281 |
$current_url = self::get_current_url(); |
| 282 |
|
| 283 |
$current_url_parse = parse_url( $current_url ); |
| 284 |
$current_url_query = array(); |
| 285 |
|
| 286 |
if( isset( $current_url_parse['fragment'] ) ) { |
| 287 |
|
| 288 |
unset( $current_url_parse['fragment'] ); |
| 289 |
|
| 290 |
} |
| 291 |
|
| 292 |
if( ! empty( $current_url_parse['query'] ) ) { |
| 293 |
|
| 294 |
wp_parse_str( $current_url_parse['query'] , $current_url_query ); |
| 295 |
|
| 296 |
ksort( $current_url_query ); |
| 297 |
|
| 298 |
} else { |
| 299 |
|
| 300 |
$current_url_parse['query'] = ''; |
| 301 |
|
| 302 |
} |
| 303 |
|
| 304 |
$found_current_item_ids = array(); |
| 305 |
|
| 306 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 307 |
|
| 308 |
if( empty( $toolbar_item->item_link_url_parse['host'] ) or empty( $toolbar_item->item_link_url_parse['path'] ) ) { |
| 309 |
|
| 310 |
continue; |
| 311 |
|
| 312 |
} |
| 313 |
|
| 314 |
if( |
| 315 |
$current_url_parse['scheme'] === $toolbar_item->item_link_url_parse['scheme'] && |
| 316 |
$current_url_parse['host'] === $toolbar_item->item_link_url_parse['host'] && |
| 317 |
$current_url_parse['path'] === $toolbar_item->item_link_url_parse['path'] && |
| 318 |
$current_url_query === $toolbar_item->item_link_url_parse_query |
| 319 |
) { |
| 320 |
|
| 321 |
$found_current_item_ids[] = $toolbar_item->ID; |
| 322 |
|
| 323 |
} |
| 324 |
|
| 325 |
} |
| 326 |
|
| 327 |
if( empty( $found_current_item_ids ) ) { |
| 328 |
|
| 329 |
$identification_query = array(); |
| 330 |
|
| 331 |
if( ! empty( $current_url_query['page'] ) ) { |
| 332 |
|
| 333 |
$identification_query['page'] = $current_url_query['page']; |
| 334 |
|
| 335 |
} |
| 336 |
|
| 337 |
if( ! empty( $current_url_query['post_type'] ) ) { |
| 338 |
|
| 339 |
if( $current_url_query['post_type'] != 'post' ) { |
| 340 |
|
| 341 |
$identification_query['post_type'] = $current_url_query['post_type']; |
| 342 |
|
| 343 |
} |
| 344 |
|
| 345 |
} |
| 346 |
|
| 347 |
if( ! empty( $current_url_query['taxonomy'] ) ) { |
| 348 |
|
| 349 |
$identification_query['taxonomy'] = $current_url_query['taxonomy']; |
| 350 |
|
| 351 |
} |
| 352 |
|
| 353 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 354 |
|
| 355 |
if( empty( $toolbar_item->item_link_url_parse['host'] ) or empty( $toolbar_item->item_link_url_parse['path'] ) ) { |
| 356 |
|
| 357 |
continue; |
| 358 |
|
| 359 |
} |
| 360 |
|
| 361 |
if( |
| 362 |
$current_url_parse['scheme'] === $toolbar_item->item_link_url_parse['scheme'] && |
| 363 |
$current_url_parse['host'] === $toolbar_item->item_link_url_parse['host'] && |
| 364 |
$current_url_parse['path'] === $toolbar_item->item_link_url_parse['path'] && |
| 365 |
http_build_query( $identification_query ) === $toolbar_item->item_link_url_parse['query'] |
| 366 |
) { |
| 367 |
|
| 368 |
$found_current_item_ids[] = $toolbar_item->ID; |
| 369 |
|
| 370 |
} |
| 371 |
|
| 372 |
} |
| 373 |
|
| 374 |
} |
| 375 |
|
| 376 |
$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 ); |
| 377 |
|
| 378 |
if( ! empty( $found_current_item_ids ) ) { |
| 379 |
|
| 380 |
$found_current_item_ids = array_map( 'strip_tags' , $found_current_item_ids ); |
| 381 |
|
| 382 |
} |
| 383 |
|
| 384 |
if( ! empty( $found_current_item_ids ) ) { |
| 385 |
|
| 386 |
foreach( $toolbar_items as $key => $toolbar_item ) { |
| 387 |
|
| 388 |
if( in_array( $toolbar_item->ID , $found_current_item_ids ) ) { |
| 389 |
|
| 390 |
$toolbar_items[ $key ]->item_li_class .= ' current'; |
| 391 |
$toolbar_items[ $key ]->item_link_class .= ' current'; |
| 392 |
|
| 393 |
} |
| 394 |
|
| 395 |
} |
| 396 |
|
| 397 |
} |
| 398 |
|
| 399 |
$toolbar_items = apply_filters( 'mywp_controller_admin_toolbar_get_toolbar_item_added_classes' , $toolbar_items ); |
| 400 |
|
| 401 |
self::$toolbar_items_added_classes = $toolbar_items; |
| 402 |
|
| 403 |
return self::$toolbar_items_added_classes; |
| 404 |
|
| 405 |
} |
| 406 |
|
| 407 |
private static function get_find_menu_items_to_parent_id( $parent_id = 0 ) { |
| 408 |
|
| 409 |
$toolbar_items_added_classes = self::get_toolbar_items_added_classes(); |
| 410 |
|
| 411 |
if( empty( $toolbar_items_added_classes ) ) { |
| 412 |
|
| 413 |
return false; |
| 414 |
|
| 415 |
} |
| 416 |
|
| 417 |
if( ! empty( $parent_id ) ) { |
| 418 |
|
| 419 |
if( is_numeric( $parent_id ) ) { |
| 420 |
|
| 421 |
$parent_id = intval( $parent_id ); |
| 422 |
|
| 423 |
} else { |
| 424 |
|
| 425 |
$parent_id = strip_tags( $parent_id ); |
| 426 |
|
| 427 |
} |
| 428 |
|
| 429 |
} |
| 430 |
|
| 431 |
if( ! empty( self::$find_parent_id[ $parent_id ] ) ) { |
| 432 |
|
| 433 |
return self::$find_parent_id[ $parent_id ]; |
| 434 |
|
| 435 |
} |
| 436 |
|
| 437 |
$find_items = array(); |
| 438 |
|
| 439 |
foreach( $toolbar_items_added_classes as $item ) { |
| 440 |
|
| 441 |
$item_parent = $item->item_parent; |
| 442 |
|
| 443 |
if( ! empty( $item_parent ) ) { |
| 444 |
|
| 445 |
if( is_numeric( $item_parent ) ) { |
| 446 |
|
| 447 |
$item_parent = intval( $item_parent ); |
| 448 |
|
| 449 |
} else { |
| 450 |
|
| 451 |
$item_parent = strip_tags( $item_parent ); |
| 452 |
|
| 453 |
} |
| 454 |
|
| 455 |
} |
| 456 |
|
| 457 |
if( $item_parent !== $parent_id ) { |
| 458 |
|
| 459 |
continue; |
| 460 |
|
| 461 |
} |
| 462 |
|
| 463 |
$find_items[] = $item; |
| 464 |
|
| 465 |
} |
| 466 |
|
| 467 |
if( empty( $find_items ) ) { |
| 468 |
|
| 469 |
return false; |
| 470 |
|
| 471 |
} |
| 472 |
|
| 473 |
self::$find_parent_id[ $parent_id ] = $find_items; |
| 474 |
|
| 475 |
return $find_items; |
| 476 |
|
| 477 |
} |
| 478 |
|
| 479 |
private static function get_current_url() { |
| 480 |
|
| 481 |
if( ! empty( self::$current_url ) ) { |
| 482 |
|
| 483 |
return self::$current_url; |
| 484 |
|
| 485 |
} |
| 486 |
|
| 487 |
$current_url = urldecode( do_shortcode( '[mywp_url current="1"]' ) ); |
| 488 |
|
| 489 |
self::$current_url = $current_url; |
| 490 |
|
| 491 |
return $current_url; |
| 492 |
|
| 493 |
} |
| 494 |
|
| 495 |
public static function admin_enqueue_scripts() { |
| 496 |
|
| 497 |
$toolbar = self::get_toolbar(); |
| 498 |
|
| 499 |
if( empty( $toolbar ) ) { |
| 500 |
|
| 501 |
return false; |
| 502 |
|
| 503 |
} |
| 504 |
|
| 505 |
wp_register_style( 'mywp_admin_toolbar' , MywpApi::get_plugin_url( 'css' ) . 'admin-toolbar.css' , array() , MYWP_VERSION ); |
| 506 |
wp_register_script( 'mywp_admin_toolbar' , MywpApi::get_plugin_url( 'js' ) . 'admin-toolbar.js' , array( 'jquery' ) , MYWP_VERSION ); |
| 507 |
|
| 508 |
wp_enqueue_style( 'mywp_admin_toolbar' ); |
| 509 |
wp_enqueue_script( 'mywp_admin_toolbar' ); |
| 510 |
|
| 511 |
$setting_data = self::get_setting_data(); |
| 512 |
|
| 513 |
if( ! empty( $setting_data['custom_menu_ui'] ) ) { |
| 514 |
|
| 515 |
wp_register_style( 'mywp_admin_toolbar_custom_ui' , MywpApi::get_plugin_url( 'css' ) . 'admin-toolbar-custom-ui.css' , array( 'mywp_admin_toolbar' ) , MYWP_VERSION ); |
| 516 |
wp_register_script( 'mywp_admin_toolbar_custom_ui' , MywpApi::get_plugin_url( 'js' ) . 'admin-toolbar-custom-ui.js' , array( 'jquery' , 'mywp_admin_toolbar' ) , MYWP_VERSION ); |
| 517 |
|
| 518 |
wp_enqueue_style( 'mywp_admin_toolbar_custom_ui' ); |
| 519 |
wp_enqueue_script( 'mywp_admin_toolbar_custom_ui' ); |
| 520 |
|
| 521 |
} |
| 522 |
|
| 523 |
} |
| 524 |
|
| 525 |
public static function remove_detault_menus() { |
| 526 |
|
| 527 |
global $wp_admin_bar; |
| 528 |
|
| 529 |
if( empty( $wp_admin_bar ) ) { |
| 530 |
|
| 531 |
return false; |
| 532 |
|
| 533 |
} |
| 534 |
|
| 535 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 536 |
|
| 537 |
return false; |
| 538 |
|
| 539 |
} |
| 540 |
|
| 541 |
$parent_items = self::get_find_menu_items_to_parent_id(); |
| 542 |
|
| 543 |
if( empty( $parent_items ) ) { |
| 544 |
|
| 545 |
return false; |
| 546 |
|
| 547 |
} |
| 548 |
|
| 549 |
$admin_bar_all_nodes = $wp_admin_bar->get_nodes(); |
| 550 |
|
| 551 |
foreach( $admin_bar_all_nodes as $node ) { |
| 552 |
|
| 553 |
if( $node->id === 'top-secondary' ) { |
| 554 |
|
| 555 |
continue; |
| 556 |
|
| 557 |
} |
| 558 |
|
| 559 |
$wp_admin_bar->remove_menu( $node->id ); |
| 560 |
|
| 561 |
} |
| 562 |
|
| 563 |
self::after_do_function( __FUNCTION__ ); |
| 564 |
|
| 565 |
} |
| 566 |
|
| 567 |
public static function customize_admin_bar() { |
| 568 |
|
| 569 |
global $wp_admin_bar; |
| 570 |
|
| 571 |
if( empty( $wp_admin_bar ) ) { |
| 572 |
|
| 573 |
return false; |
| 574 |
|
| 575 |
} |
| 576 |
|
| 577 |
if( ! self::is_do_function( __FUNCTION__ ) ) { |
| 578 |
|
| 579 |
return false; |
| 580 |
|
| 581 |
} |
| 582 |
|
| 583 |
$parent_items = self::get_find_menu_items_to_parent_id(); |
| 584 |
|
| 585 |
if( empty( $parent_items ) ) { |
| 586 |
|
| 587 |
return false; |
| 588 |
|
| 589 |
} |
| 590 |
|
| 591 |
foreach( $parent_items as $item ) { |
| 592 |
|
| 593 |
self::add_toolbar_item( $item ); |
| 594 |
|
| 595 |
} |
| 596 |
|
| 597 |
self::after_do_function( __FUNCTION__ ); |
| 598 |
|
| 599 |
} |
| 600 |
|
| 601 |
private static function add_toolbar_item( $item ) { |
| 602 |
|
| 603 |
global $wp_admin_bar; |
| 604 |
|
| 605 |
if( empty( $item ) or empty( $item->item_type ) or empty( $item->ID ) ) { |
| 606 |
|
| 607 |
return false; |
| 608 |
|
| 609 |
} |
| 610 |
|
| 611 |
$toolbar_items_added_classes = self::get_toolbar_items_added_classes(); |
| 612 |
|
| 613 |
$item = apply_filters( 'mywp_controller_admin_toolbar_add_toolbar_item' , $item ); |
| 614 |
|
| 615 |
if( ! empty( $item->item_capability ) ) { |
| 616 |
|
| 617 |
if( ! current_user_can( $item->item_capability ) ) { |
| 618 |
|
| 619 |
return false; |
| 620 |
|
| 621 |
} |
| 622 |
|
| 623 |
} |
| 624 |
|
| 625 |
$item_id = $item->ID; |
| 626 |
|
| 627 |
if( is_numeric( $item_id ) ) { |
| 628 |
|
| 629 |
$item_id = intval( $item_id ); |
| 630 |
|
| 631 |
} else { |
| 632 |
|
| 633 |
$item_id = strip_tags( $item_id ); |
| 634 |
|
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
$item_type = $item->item_type; |
| 639 |
$node_parent = $item->item_parent; |
| 640 |
$item_location = $item->item_location; |
| 641 |
|
| 642 |
$item->item_link_title = do_shortcode( $item->item_link_title ); |
| 643 |
|
| 644 |
$li_class = ''; |
| 645 |
|
| 646 |
if( ! empty( $item->item_li_class ) ) { |
| 647 |
|
| 648 |
$li_class = $item->item_li_class; |
| 649 |
|
| 650 |
} |
| 651 |
|
| 652 |
$li_id = ''; |
| 653 |
|
| 654 |
if( ! empty( $item->item_li_id ) ) { |
| 655 |
|
| 656 |
$li_id = $item->item_li_id; |
| 657 |
|
| 658 |
} |
| 659 |
|
| 660 |
if( $node_parent == '0' ) { |
| 661 |
|
| 662 |
$node_parent = ''; |
| 663 |
|
| 664 |
} |
| 665 |
|
| 666 |
if( $item_location === 'right' ) { |
| 667 |
|
| 668 |
if( $node_parent == '' ) { |
| 669 |
|
| 670 |
$node_parent = 'top-secondary'; |
| 671 |
|
| 672 |
} |
| 673 |
|
| 674 |
} |
| 675 |
|
| 676 |
$node_id = $item->ID; |
| 677 |
|
| 678 |
if( ! empty( $item->item_default_id ) ) { |
| 679 |
|
| 680 |
$node_id = $item->item_default_id; |
| 681 |
|
| 682 |
foreach( $toolbar_items_added_classes as $toolbar_items_added_classes_item ) { |
| 683 |
|
| 684 |
if( $toolbar_items_added_classes_item->ID === $item->item_parent ) { |
| 685 |
|
| 686 |
$node_parent = $toolbar_items_added_classes_item->item_default_id; |
| 687 |
|
| 688 |
break; |
| 689 |
|
| 690 |
} |
| 691 |
|
| 692 |
} |
| 693 |
|
| 694 |
} |
| 695 |
|
| 696 |
$node_group = false; |
| 697 |
|
| 698 |
if( $item_type === 'group' ) { |
| 699 |
|
| 700 |
$node_group = 1; |
| 701 |
|
| 702 |
} elseif( $item_type === 'custom' ) { |
| 703 |
|
| 704 |
$item->item_meta['html'] = $item->item_custom_html; |
| 705 |
|
| 706 |
} |
| 707 |
|
| 708 |
if( ! empty( $item->item_icon_class ) ) { |
| 709 |
|
| 710 |
$title = sprintf( '<span class="%s"></span>' , esc_attr( $item->item_icon_class ) ) . $item->item_link_title; |
| 711 |
|
| 712 |
} else { |
| 713 |
|
| 714 |
$title = $item->item_link_title; |
| 715 |
|
| 716 |
} |
| 717 |
|
| 718 |
if( empty( $node_group ) ) { |
| 719 |
|
| 720 |
$add_menu = array( 'id' => $node_id , 'title' => $title , 'parent' => $node_parent , 'href' => $item->item_link_url , 'group' => $node_group , 'meta' => $item->item_meta ); |
| 721 |
|
| 722 |
$wp_admin_bar->add_menu( $add_menu ); |
| 723 |
|
| 724 |
} else { |
| 725 |
|
| 726 |
$add_menu = array( 'id' => $node_id , 'parent' => $node_parent , 'group' => $node_group , 'meta' => $item->item_meta ); |
| 727 |
|
| 728 |
$wp_admin_bar->add_group( $add_menu ); |
| 729 |
|
| 730 |
} |
| 731 |
|
| 732 |
$child_items = self::get_find_menu_items_to_parent_id( $item_id ); |
| 733 |
|
| 734 |
if( ! empty( $child_items ) ) { |
| 735 |
|
| 736 |
foreach( $child_items as $child_item ) { |
| 737 |
|
| 738 |
self::add_toolbar_item( $child_item ); |
| 739 |
|
| 740 |
} |
| 741 |
|
| 742 |
} |
| 743 |
|
| 744 |
} |
| 745 |
|
| 746 |
} |
| 747 |
|
| 748 |
MywpControllerModuleAdminToolbar::init(); |
| 749 |
|
| 750 |
endif; |
| 751 |
|