BP_Component::setup_admin_bar( array $wp_admin_nav = array() )
Set up the component entries in the WordPress Admin Bar.
Description
See also
- WP_Admin_Bar::add_menu(): for a description of the syntax required by each item in the $wp_admin_nav parameter array.
Parameters
- $wp_admin_nav
-
(Optional) An array of nav item arguments. Each item in this parameter array is passed to WP_Admin_Bar::add_menu(). See that method for a description of the required syntax for each item.
Default value: array()
Source
File: bp-core/classes/class-bp-component.php
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 | public function setup_admin_bar( $wp_admin_nav = array () ) { // Bail if this is an ajax request. if ( defined( 'DOING_AJAX' ) ) { return ; } // Do not proceed if BP_USE_WP_ADMIN_BAR constant is not set or is false. if ( ! bp_use_wp_admin_bar() ) { return ; } /** * Filters the admin navigation passed into setup_admin_bar. * * This is a dynamic hook that is based on the component string ID. * * @since BuddyPress 1.9.0 * * @param array $wp_admin_nav Array of navigation items to add. */ $wp_admin_nav = apply_filters( 'bp_' . $this ->id . '_admin_nav' , $wp_admin_nav ); // Do we have Toolbar menus to add? if ( ! empty ( $wp_admin_nav ) ) { // Fill in position if one wasn't passed for backpat. $pos = 0; $not_set_pos = 1; foreach ( $wp_admin_nav as $key => $nav ) { if ( ! isset( $nav [ 'position' ] ) ) { $wp_admin_nav [ $key ][ 'position' ] = $pos + $not_set_pos ; if ( 9 !== $not_set_pos ) { ++ $not_set_pos ; } } else { $pos = $nav [ 'position' ]; // Reset not set pos to 1 if ( $pos % 10 === 0 ) { $not_set_pos = 1; } } } // Sort admin nav by position. $wp_admin_nav = bp_sort_by_key( $wp_admin_nav , 'position' , 'num' ); // Set this objects menus. $this ->admin_menu = $wp_admin_nav ; // Define the WordPress global. global $wp_admin_bar ; // Add each admin menu. foreach ( $this ->admin_menu as $admin_menu ) { $wp_admin_bar ->add_menu( $admin_menu ); } } /** * Fires at the end of the setup_admin_bar method inside BP_Component. * * This is a dynamic hook that is based on the component string ID. * * @since BuddyPress 1.5.0 */ do_action( 'bp_' . $this ->id . '_setup_admin_bar' ); } |
Changelog
Version | Description |
---|---|
BuddyPress 1.5.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.