bbp_get_forums_for_current_user

Get the forums the current user has the ability to see and post to.

Description

bbp_get_forums_for_current_user( (array) $args = array() ); 

Parameters (1)

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

Usage

  1. if ( !function_exists( 'bbp_get_forums_for_current_user' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // The args. 
  5. $args = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_forums_for_current_user($args); 
  9.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_get_forums_for_current_user( $args = array() ) { 
  2.  
  3. // Setup arrays 
  4. $private = $hidden = $post__not_in = array(); 
  5.  
  6. // Private forums 
  7. if ( !current_user_can( 'read_private_forums' ) ) 
  8. $private = bbp_get_private_forum_ids(); 
  9.  
  10. // Hidden forums 
  11. if ( !current_user_can( 'read_hidden_forums' ) ) 
  12. $hidden = bbp_get_hidden_forum_ids(); 
  13.  
  14. // Merge private and hidden forums together and remove any empties 
  15. $forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) ); 
  16.  
  17. // There are forums that need to be ex 
  18. if ( !empty( $forum_ids ) ) 
  19. $post__not_in = implode( ', ', $forum_ids ); 
  20.  
  21. // Parse arguments against default values 
  22. $r = bbp_parse_args( $args, array( 
  23. 'post_type' => bbp_get_forum_post_type(),  
  24. 'post_status' => bbp_get_public_status_id(),  
  25. 'numberposts' => -1,  
  26. 'exclude' => $post__not_in 
  27. ), 'get_forums_for_current_user' ); 
  28.  
  29. // Get the forums 
  30. $forums = get_posts( $r ); 
  31.  
  32. // No availabe forums 
  33. if ( empty( $forums ) ) 
  34. $forums = false; 
  35.  
  36. return apply_filters( 'bbp_get_forums_for_current_user', $forums );