bp_core_component_slug_from_root_slug( string $root_slug )

Create a default component slug from a WP page root_slug.


Description 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 Parameters

$root_slug

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


Top ↑

Return Return

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


Top ↑

Source 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 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 );
}

Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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