bbp_exclude_forum_ids

Returns a meta_query that either includes or excludes hidden forum IDs from a query.

Description

bbp_exclude_forum_ids( (string) $type = 'string' ); 

Parameters (1)

0. $type — Optional. (string) => 'string'
The type of value to return. (string|array|meta_query)

Usage

  1. if ( !function_exists( 'bbp_exclude_forum_ids' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/forums/functions.php'; 
  3.  
  4. // Optional. The type of value to return. (string|array|meta_query) 
  5. $type = 'string'; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_exclude_forum_ids($type); 
  9.  

Defined (1)

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

/includes/forums/functions.php  
  1. function bbp_exclude_forum_ids( $type = 'string' ) { 
  2.  
  3. // Setup arrays 
  4. $private = $hidden = $meta_query = $forum_ids = array(); 
  5.  
  6. // Default return value 
  7. switch ( $type ) { 
  8. case 'string' : 
  9. $retval = ''; 
  10. break; 
  11.  
  12. case 'array' : 
  13. $retval = array(); 
  14. break; 
  15.  
  16. case 'meta_query' : 
  17. $retval = array( array() ) ; 
  18. break; 
  19.  
  20. // Exclude for everyone but keymasters 
  21. if ( ! bbp_is_user_keymaster() ) { 
  22.  
  23. // Private forums 
  24. if ( !current_user_can( 'read_private_forums' ) ) 
  25. $private = bbp_get_private_forum_ids(); 
  26.  
  27. // Hidden forums 
  28. if ( !current_user_can( 'read_hidden_forums' ) ) 
  29. $hidden = bbp_get_hidden_forum_ids(); 
  30.  
  31. // Merge private and hidden forums together 
  32. $forum_ids = (array) array_filter( wp_parse_id_list( array_merge( $private, $hidden ) ) ); 
  33.  
  34. // There are forums that need to be excluded 
  35. if ( !empty( $forum_ids ) ) { 
  36.  
  37. switch ( $type ) { 
  38.  
  39. // Separate forum ID's into a comma separated string 
  40. case 'string' : 
  41. $retval = implode( ', ', $forum_ids ); 
  42. break; 
  43.  
  44. // Use forum_ids array 
  45. case 'array' : 
  46. $retval = $forum_ids; 
  47. break; 
  48.  
  49. // Build a meta_query 
  50. case 'meta_query' : 
  51. $retval = array( 
  52. 'key' => '_bbp_forum_id',  
  53. 'value' => implode( ', ', $forum_ids ),  
  54. 'type' => 'numeric',  
  55. 'compare' => ( 1 < count( $forum_ids ) ) ? 'NOT IN' : '!=' 
  56. ); 
  57. break; 
  58.  
  59. // Filter and return the results 
  60. return apply_filters( 'bbp_exclude_forum_ids', $retval, $forum_ids, $type );