bbp_add_user_forum_subscription

Add a forum to user's subscriptions.

Description

bbp_add_user_forum_subscription( (int) $user_id = 0, (int) $forum_id = 0 ); 

Parameters (2)

0. $user_id — Optional. (int)
User id
1. $forum_id — Optional. (int)
forum id

Usage

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

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_add_user_forum_subscription( $user_id = 0, $forum_id = 0 ) { 
  2. if ( empty( $user_id ) || empty( $forum_id ) ) { 
  3. return false; 
  4.  
  5. $forum = bbp_get_forum( $forum_id ); 
  6. if ( empty( $forum ) ) { 
  7. return false; 
  8.  
  9. $subscriptions = (array) bbp_get_user_subscribed_forum_ids( $user_id ); 
  10. if ( !in_array( $forum_id, $subscriptions ) ) { 
  11. $subscriptions[] = $forum_id; 
  12. $subscriptions = implode( ', ', wp_parse_id_list( array_filter( $subscriptions ) ) ); 
  13. update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); 
  14.  
  15. wp_cache_delete( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 
  16.  
  17. do_action( 'bbp_add_user_forum_subscription', $user_id, $forum_id ); 
  18.  
  19. return true;