bp_core_create_nav_link( array|string $args = '', string $component = 'members' )
Add a link to the main BuddyPress navigation.
Description
Parameters
- $args
-
(Optional) Array describing the new nav item.
- 'name'
(string) Display name for the nav item. - 'slug'
(string) Unique URL slug for the nav item. - 'item_css_id'
(bool|string) Optional. 'id' attribute for the nav item. Default: the value of$slug
. - 'show_for_displayed_user'
(bool) Optional. Whether the nav item should be visible when viewing a member profile other than your own. Default: true. - 'site_admin_only'
(bool) Optional. Whether the nav item should be visible only to site admins (those with the 'bp_moderate' cap). Default: false. - 'position'
(int) Optional. Numerical index specifying where the item should appear in the nav array. Default: 99. - 'screen_function'
(callable) The callback function that will run when the nav item is clicked. - 'default_subnav_slug'
(bool|string) Optional. The slug of the default subnav item to select when the nav item is clicked.
Default value: ''
- 'name'
- $component
-
(Optional) Component that the nav belongs to.
Default value: 'members'
Return
(false|array) Returns false on failure, new nav item on success.
Source
File: bp-core/bp-core-buddybar.php
function bp_core_create_nav_link( $args = '', $component = 'members' ) { $bp = buddypress(); $defaults = array( 'name' => false, // Display name for the nav item. 'slug' => false, // URL slug for the nav item. 'item_css_id' => false, // The CSS ID to apply to the HTML of the nav item. 'show_for_displayed_user' => true, // When viewing another user does this nav item show up? 'site_admin_only' => false, // Can only site admins see this nav item? 'position' => 99, // Index of where this nav item should be positioned. 'screen_function' => false, // The name of the function to run when clicked. 'default_subnav_slug' => false // The slug of the default subnav item to select when clicked. ); $r = wp_parse_args( $args, $defaults ); // If we don't have the required info we need, don't create this nav item. if ( empty( $r['name'] ) || empty( $r['slug'] ) ) { return false; } // If this is for site admins only and the user is not one, don't create the nav item. if ( ! empty( $r['site_admin_only'] ) && ! bp_current_user_can( 'bp_moderate' ) ) { return false; } if ( empty( $r['item_css_id'] ) ) { $r['item_css_id'] = $r['slug']; } $nav_item = array( 'name' => $r['name'], 'slug' => $r['slug'], 'link' => trailingslashit( bp_loggedin_user_domain() . $r['slug'] ), 'css_id' => $r['item_css_id'], 'show_for_displayed_user' => $r['show_for_displayed_user'], 'position' => $r['position'], 'screen_function' => &$r['screen_function'], 'default_subnav_slug' => $r['default_subnav_slug'] ); // Add the item to the nav. buddypress()->{$component}->nav->add_nav( $nav_item ); /** * Fires after a link is added to the main BuddyPress nav. * * @since BuddyPress 2.4.0 * @since BuddyPress 2.6.0 Added `$component` parameter. * * @param array $r Parsed arguments for the nav item. * @param array $args Originally passed in arguments for the nav item. * @param array $defaults Default arguments for a nav item. * @param string $component Component that the nav belongs to. */ do_action( 'bp_core_create_nav_link', $r, $args, $defaults, $component ); return $nav_item; }
Changelog
Version | Description |
---|---|
BuddyPress 2.4.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.