bp_get_root_slug( string $component = '' )

Get the root slug for given component.

Description

The "root slug" is the string used when concatenating component directory URLs. For example, on an installation where the Groups component’s directory is located at http://example.com/groups/, the root slug for the Groups component is ‘groups’. This string generally corresponds to page_name of the component’s directory page.

In order to maintain backward compatibility, the following procedure is used: 1) Use the short slug to get the canonical component name from the active component array. 2) Use the component name to get the root slug out of the appropriate part of the $bp global. 3) If nothing turns up, it probably means that $component is itself a root slug.

Example: If your groups directory is at /community/companies, this function first uses the short slug ‘companies’ (ie the current component) to look up the canonical name ‘groups’ in $bp->active_components. Then it uses ‘groups’ to get the root slug, from $bp->groups->root_slug.

Parameters

$component

(string) (Optional) Defaults to the current component.

Default value: ''

Return

(string) $root_slug The root slug.

Source

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

	function bp_get_root_slug( $component = '' ) {
		$bp        = buddypress();
		$root_slug = '';

		// Use current global component if none passed.
		if ( empty( $component ) ) {
			$component = bp_current_component();
		}

		// Component is active.
		if ( ! empty( $bp->active_components[ $component ] ) ) {

			// Backward compatibility: in legacy plugins, the canonical component id
			// was stored as an array value in $bp->active_components.
			$component_name = ( '1' == $bp->active_components[ $component ] )
				? $component
				: $bp->active_components[$component];

			// Component has specific root slug.
			if ( ! empty( $bp->{$component_name}->root_slug ) ) {
				$root_slug = $bp->{$component_name}->root_slug;
			}
		}

		// No specific root slug, so fall back to component slug.
		if ( empty( $root_slug ) ) {
			$root_slug = $component;
		}

		/**
		 * Filters the root slug for given component.
		 *
		 * @since BuddyPress 1.5.0
		 *
		 * @param string $root_slug Root slug for given component.
		 * @param string $component Current component.
		 */
		return apply_filters( 'bp_get_root_slug', $root_slug, $component );
	}

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.