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
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.