bb_get_forums

The BuddyPress bb get forums function.

Description

bb_get_forums( (null) $args = null ); 

Parameters (1)

0. $args — Optional. (null) => null
The args.

Usage

  1. if ( !function_exists( 'bb_get_forums' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-forums.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bb_get_forums($args); 
  9.  

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( $args = null ) { 
  2. global $bbdb; 
  3.  
  4. if ( is_numeric($args) ) { 
  5. $args = array( 'child_of' => $args, 'hierarchical' => 1, 'depth' => 0 ); 
  6. } elseif ( is_callable($args) ) { 
  7. $_args = func_get_args(); 
  8. $args = array( 'callback' => $args ); 
  9. if ( 1 < func_num_args() ) 
  10. $args['callback_args'] = $_args[1]; 
  11.  
  12. $defaults = array( 'callback' => false, 'callback_args' => false, 'child_of' => 0, 'hierarchical' => 0, 'depth' => 0, 'cut_branch' => 0, 'where' => '', 'order_by' => 'forum_order' ); 
  13. $args = wp_parse_args( $args, $defaults ); 
  14.  
  15. extract($args, EXTR_SKIP); 
  16. $child_of = (int) $child_of; 
  17. $hierarchical = 'false' === $hierarchical ? false : (bool) $hierarchical; 
  18. $depth = (int) $depth; 
  19.  
  20. $where = apply_filters( 'get_forums_where', $where ); 
  21. $key = md5( serialize( $where . '|' . $order_by ) ); // The keys that change the SQL query 
  22. if ( false !== $forum_ids = wp_cache_get( $key, 'bb_forums' ) ) { 
  23. $forums = _bb_get_cached_data( $forum_ids, 'bb_forum', 'bb_get_forum' ); 
  24. } else { 
  25. $forum_ids = array(); 
  26. $forums = array(); 
  27. $_forums = (array) $bbdb->get_results("SELECT * FROM $bbdb->forums $where ORDER BY `$order_by`;"); 
  28. $_forums = bb_append_meta( $_forums, 'forum' ); 
  29. foreach ( $_forums as $f ) { 
  30. $forums[(int) $f->forum_id] = $f; 
  31. $forum_ids[] = (int) $f->forum_id; 
  32. wp_cache_add( $f->forum_id, $f, 'bb_forum' ); 
  33. wp_cache_add( $f->forum_slug, $f->forum_id, 'bb_forum_slug' ); 
  34. wp_cache_set( $key, $forum_ids, 'bb_forums' ); 
  35.  
  36. $forums = (array) apply_filters( 'get_forums', $forums ); 
  37.  
  38. if ( $child_of || $hierarchical || $depth ) { 
  39.  
  40. $_forums = bb_get_forums_hierarchical( $child_of, $depth, $forums ); 
  41.  
  42. if ( !is_array( $_forums ) ) 
  43. return false; 
  44.  
  45. $_forums = (array) bb_flatten_array( $_forums, $cut_branch ); 
  46.  
  47. foreach ( array_keys($_forums) as $_id ) 
  48. $_forums[$_id] = $forums[$_id]; 
  49.  
  50. $forums = $_forums; 
  51.  
  52. if ( !is_callable($callback) ) 
  53. return $forums; 
  54.  
  55. if ( !is_array($callback_args) ) 
  56. $callback_args = array(); 
  57.  
  58. foreach ( array_keys($forums) as $f ) : 
  59. $_callback_args = $callback_args; 
  60. array_push( $_callback_args, $forums[$f]->forum_id ); 
  61. if ( false == call_user_func_array( $callback, $_callback_args ) ) // $forum_id will be last arg; 
  62. unset($forums[$f]); 
  63. endforeach; 
  64. return $forums;