bp_get_name_from_root_slug( string $root_slug = '' )

Return the component name based on a root slug.

Description

Parameters

$root_slug

(Optional) Needle to our active component haystack.

Default value: ''

Return

(mixed) False if none found, component name if found.

Source

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

1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
function bp_get_name_from_root_slug( $root_slug = '' ) {
    $bp = buddypress();
 
    // If no slug is passed, look at current_component.
    if ( empty( $root_slug ) ) {
        $root_slug = bp_current_component();
    }
 
    // No current component or root slug, so flee.
    if ( empty( $root_slug ) ) {
        return false;
    }
 
    // Loop through active components and look for a match.
    foreach ( array_keys( $bp->active_components ) as $component ) {
        if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) {
            return $bp->{$component}->name;
        }
    }
 
    return false;
}

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.