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
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
| 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.