bp_get_name_from_root_slug

Return the component name based on a root slug.

Description

bp_get_name_from_root_slug( (string) $root_slug = '' ); 

Parameters (1)

0. $root_slug — Optional. (string) => ''
Needle to our active component haystack.

Usage

  1. if ( !function_exists( 'bp_get_name_from_root_slug' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-template.php'; 
  3.  
  4. // Needle to our active component haystack. 
  5. $root_slug = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_get_name_from_root_slug($root_slug); 
  9.  

Defined (1)

The function is defined in the following location(s).

/bp-core/bp-core-template.php  
  1. function bp_get_name_from_root_slug( $root_slug = '' ) { 
  2. $bp =buddypress); 
  3.  
  4. // If no slug is passed, look at current_component. 
  5. if ( empty( $root_slug ) ) { 
  6. $root_slug = bp_current_component(); 
  7.  
  8. // No current component or root slug, so flee. 
  9. if ( empty( $root_slug ) ) { 
  10. return false; 
  11.  
  12. // Loop through active components and look for a match. 
  13. foreach ( array_keys( $bp->active_components ) as $component ) { 
  14. if ( ( ! empty( $bp->{$component}->slug ) && ( $bp->{$component}->slug == $root_slug ) ) || ( ! empty( $bp->{$component}->root_slug ) && ( $bp->{$component}->root_slug === $root_slug ) ) ) { 
  15. return $bp->{$component}->name; 
  16.  
  17. return false;