bbp_get_forum_subscribers

Get the users who have subscribed to the forum.

Description

(array|bool) bbp_get_forum_subscribers( (int) $forum_id = 0 ); 

Returns (array|bool)

Results if the forum has any subscribers, otherwise false

Parameters (1)

0. $forum_id — Optional. (int)
forum id

Usage

  1. if ( !function_exists( 'bbp_get_forum_subscribers' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4. // Optional. forum id 
  5. $forum_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_forum_subscribers($forum_id); 
  9.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_get_forum_subscribers( $forum_id = 0 ) { 
  2. $forum_id = bbp_get_forum_id( $forum_id ); 
  3. if ( empty( $forum_id ) ) 
  4. return; 
  5.  
  6. global $wpdb; 
  7.  
  8. $key = $wpdb->prefix . '_bbp_forum_subscriptions'; 
  9. $users = wp_cache_get( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 
  10. if ( false === $users ) { 
  11. $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$forum_id}', meta_value) > 0" ); 
  12. wp_cache_set( 'bbp_get_forum_subscribers_' . $forum_id, $users, 'bbpress_users' ); 
  13.  
  14. return apply_filters( 'bbp_get_forum_subscribers', $users );