bp_core_component_slug_from_root_slug( string $root_slug )

Create a default component slug from a WP page root_slug.

Description

Since 1.5, BP components get their root_slug (the slug used immediately following the root domain) from the slug of a corresponding WP page.

E.g. if your BP installation at example.com has its members page at example.com/community/people, $bp->members->root_slug will be ‘community/people’.

By default, this function creates a shorter version of the root_slug for use elsewhere in the URL, by returning the content after the final ‘/’ in the root_slug (‘people’ in the example above).

Filter on ‘bp_core_component_slug_from_root_slug’ to override this method in general, or define a specific component slug constant (e.g. BP_MEMBERS_SLUG) to override specific component slugs.

Parameters

$root_slug

(Required) The root slug, which comes from $bp->pages->[component]->slug.

Return

(string) The short slug for use in the middle of URLs.

Source

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

function bp_core_component_slug_from_root_slug( $root_slug ) {
	$slug_chunks = explode( '/', $root_slug );
	$slug        = array_pop( $slug_chunks );

	/**
	 * Filters the default component slug from a WP page root_slug.
	 *
	 * @since BuddyPress 1.5.0
	 *
	 * @param string $slug      Short slug for use in the middle of URLs.
	 * @param string $root_slug The root slug which comes from $bp->pages-[component]->slug.
	 */
	return apply_filters( 'bp_core_component_slug_from_root_slug', $slug, $root_slug );
}

Changelog

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.