bbp_remove_user_forum_subscription

Remove a forum from user's subscriptions.

Description

bbp_remove_user_forum_subscription( (int) $user_id, (int) $forum_id ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'bbp_remove_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_remove_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_remove_user_forum_subscription( $user_id, $forum_id ) { 
  2. if ( empty( $user_id ) || empty( $forum_id ) ) { 
  3. return false; 
  4.  
  5. $subscriptions = (array) bbp_get_user_subscribed_forum_ids( $user_id ); 
  6. if ( empty( $subscriptions ) ) { 
  7. return false; 
  8.  
  9. $pos = array_search( $forum_id, $subscriptions ); 
  10. if ( false === $pos ) { 
  11. return false; 
  12.  
  13. array_splice( $subscriptions, $pos, 1 ); 
  14. $subscriptions = array_filter( $subscriptions ); 
  15.  
  16. if ( !empty( $subscriptions ) ) { 
  17. $subscriptions = implode( ', ', wp_parse_id_list( $subscriptions ) ); 
  18. update_user_option( $user_id, '_bbp_forum_subscriptions', $subscriptions ); 
  19. } else { 
  20. delete_user_option( $user_id, '_bbp_forum_subscriptions' ); 
  21.  
  22. wp_cache_delete( 'bbp_get_forum_subscribers_' . $forum_id, 'bbpress_users' ); 
  23.  
  24. do_action( 'bbp_remove_user_forum_subscription', $user_id, $forum_id ); 
  25.  
  26. return true;