bb_get_forums_hierarchical

Forums.

Description

bb_get_forums_hierarchical( (int) $root = 0, (int) $depth = 0, (constant) $leaves = false, (bool) $_recursed = false ); 

Parameters (4)

0. $root — Optional. (int)
The root.
1. $depth — Optional. (int)
The depth.
2. $leaves — Optional. (constant) => false
The leaves.
3. $recursed (bool)
The recursed.

Usage

  1. if ( !function_exists( 'bb_get_forums_hierarchical' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-forums.php'; 
  3.  
  4. // The root. 
  5. $root = -1; 
  6.  
  7. // The depth. 
  8. $depth = -1; 
  9.  
  10. // The leaves. 
  11. $leaves = false; 
  12.  
  13. // The recursed. 
  14. $recursed = true; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = bb_get_forums_hierarchical($root, $depth, $leaves, $recursed); 
  18.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-forums.php  
  1. function bb_get_forums_hierarchical( $root = 0, $depth = 0, $leaves = false, $_recursed = false ) { 
  2. static $_leaves = false; 
  3.  
  4. if (!$_recursed) 
  5. $_leaves = false; 
  6.  
  7. $root = (int) $root; 
  8.  
  9. if ( false === $_leaves ) 
  10. $_leaves = $leaves ? $leaves : bb_get_forums(); 
  11.  
  12. if ( !$_leaves ) 
  13. return false; 
  14.  
  15. $branch = array(); 
  16.  
  17. reset($_leaves); 
  18.  
  19. while ( list($l, $leaf) = each($_leaves) ) { 
  20. if ( $root == $leaf->forum_parent ) { 
  21. $new_root = (int) $leaf->forum_id; 
  22. unset($_leaves[$l]); 
  23. $branch[$new_root] = 1 == $depth ? true : bb_get_forums_hierarchical( $new_root, $depth - 1, false, true ); 
  24. reset($_leaves); 
  25.  
  26. if ( !$_recursed ) { 
  27. if ( !$root ) 
  28. foreach ( $_leaves as $leaf ) // Attach orphans to root 
  29. $branch[$leaf->forum_id] = true; 
  30. $_leaves = false; 
  31. return ( empty($branch) ? false : $branch ); 
  32.  
  33. return $branch ? $branch : true;