bp_core_new_subnav_item( array|string $args, string|null $component = null )

Add an item to secondary navigation of the specified component.


Description Description


Parameters Parameters

$args

(Required) Array describing the new subnav item.

  • 'name'
    (string) Display name for the subnav item.
  • 'slug'
    (string) Unique URL slug for the subnav item.
  • 'parent_slug'
    (string) Slug of the top-level nav item under which the new subnav item should be added.
  • 'parent_url'
    (string) URL of the parent nav item.
  • 'item_css_id'
    (bool|string) Optional. 'id' attribute for the nav item. Default: the value of $slug.
  • 'user_has_access'
    (bool) Optional. True if the logged-in user has access to the subnav item, otherwise false. Can be set dynamically when registering the subnav; eg, use bp_is_my_profile() to restrict access to profile owners only. 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 subnav array. Default: 90.
  • 'screen_function'
    (callable) The callback function that will run when the nav item is clicked.
  • 'link'
    (string) Optional. The URL that the subnav item should point to. Defaults to a value generated from the $parent_url + $slug.
  • 'show_in_admin_bar'
    (bool) Optional. Whether the nav item should be added into the group's "Edit" Admin Bar menu for group admins. Default: false.

$component

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

Default value: null


Top ↑

Return Return

(null|false) Returns false on failure.


Top ↑

Source Source

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

function bp_core_new_subnav_item( $args, $component = null ) {
	// Backward compatibility for plugins using `bp_core_new_subnav_item()` without `$component`
	// to add group subnav items.
	if ( null === $component && bp_is_active( 'groups' ) && bp_is_group() && isset( $args['parent_slug'] ) ) {
		/*
		 * Assume that this item is intended to belong to the current group if:
		 * a) the 'parent_slug' is the same as the slug of the current group, or
		 * b) the 'parent_slug' starts with the slug of the current group, and the members nav doesn't have
		 *    a primary item with that slug.
		 */
		$group_slug = bp_get_current_group_slug();
		if (
			$group_slug === $args['parent_slug'] ||
			( 0 === strpos( $args['parent_slug'], $group_slug ) && ! buddypress()->members->nav->get_primary( array( 'slug' => $args['parent_slug'] ), false ) )
		) {
			$component = 'groups';
		}
	}

	if ( ! $component ) {
		$component = 'members';
	}

	if ( ! bp_is_active( $component ) ) {
		return;
	}

	// First, register the subnav item in the nav.
	$subnav_item = bp_core_create_subnav_link( $args, $component );

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

	// Then, hook the screen function for the added subnav item.
	$hooked = bp_core_register_subnav_screen_function( $subnav_item, $component );
	if ( false === $hooked ) {
		return false;
	}
}

Top ↑

Changelog Changelog

Changelog
Version Description
2.6.0 Introduced the $component parameter.
1.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.