bp_core_add_root_component

Add support for a top-level ("root") component.

Description

bp_core_add_root_component( (string) $slug ); 

This function originally (pre-1.5) let plugins add support for pages in the root of the install. These root level pages are now handled by actual WordPress pages and this function is now a convenience for compatibility with the new method.

Parameters (1)

0. $slug (string)
The slug of the component being added to the root list.

Usage

  1. if ( !function_exists( 'bp_core_add_root_component' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-core/bp-core-functions.php'; 
  3.  
  4. // The slug of the component being added to the root list. 
  5. $slug = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_core_add_root_component($slug); 
  9.  

Defined (1)

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

/bp-core/bp-core-functions.php  
  1. function bp_core_add_root_component( $slug ) { 
  2. $bp =buddypress); 
  3.  
  4. if ( empty( $bp->pages ) ) { 
  5. $bp->pages = bp_core_get_directory_pages(); 
  6.  
  7. $match = false; 
  8.  
  9. // Check if the slug is registered in the $bp->pages global. 
  10. foreach ( (array) $bp->pages as $key => $page ) { 
  11. if ( $key == $slug || $page->slug == $slug ) { 
  12. $match = true; 
  13.  
  14. // Maybe create the add_root array. 
  15. if ( empty( $bp->add_root ) ) { 
  16. $bp->add_root = array(); 
  17.  
  18. // If there was no match, add a page for this root component. 
  19. if ( empty( $match ) ) { 
  20. $add_root_items = $bp->add_root(); 
  21. $add_root_items[] = $slug; 
  22. $bp->add_root = $add_root_items; 
  23.  
  24. // Make sure that this component is registered as requiring a top-level directory. 
  25. if ( isset( $bp->{$slug} ) ) { 
  26. $bp->loaded_components[$bp->{$slug}->slug] = $bp->{$slug}->id; 
  27. $bp->{$slug}->has_directory = true;