bp_core_new_nav_item( array|string $args, string $component = 'members' )

Add an item to the primary navigation of the specified component.

Description

Parameters

$args

(array|string) (Required) 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.

$component

(string) (Optional) The component the navigation is attached to. Defaults to 'members'.

Default value: 'members'

Return

(null|false) Returns false on failure.

Source

File: bp-core/bp-core-buddybar.php

function bp_core_new_nav_item( $args, $component = 'members' ) {
	if ( ! bp_is_active( $component ) ) {
		return;
	}

	$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 );

	// Validate nav link data.
	$nav_item = bp_core_create_nav_link( $r, $component );

	/*
	 * To mimic legacy behavior, if bp_core_create_nav_link() returns false, we make
	 * an early exit and don't attempt to register the screen function.
	 */
	if ( false === $nav_item ) {
		return false;
	}

	// Then, hook the screen function for the added nav item.
	$hooked = bp_core_register_nav_screen_function( $nav_item );
	if ( false === $hooked ){
		return false;
	}

	/**
	 * Fires after adding an item to the main BuddyPress navigation array.
	 * Note that, when possible, the more specific action hooks
	 * `bp_core_create_nav_link` or `bp_core_register_nav_screen_function`
	 * should be used.
	 *
	 * @since BuddyPress 1.5.0
	 *
	 * @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.
	 */
	do_action( 'bp_core_new_nav_item', $r, $args, $defaults );
}

Changelog

Changelog
Version Description
BuddyPress 1.1.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.