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

(Optional) Defaults to the current component.

Default value: ''

Return

(string) $root_slug The root slug.

Source

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

1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
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.