bbp_is_user_subscribed_to_forum

Check if a forum is in user's subscription list or not.

Description

bbp_is_user_subscribed_to_forum( (int) $user_id = 0, (int) $forum_id = 0, (array) $subscribed_ids = array() ); 

Parameters (3)

0. $user_id — Optional. (int)
User id
1. $forum_id — Optional. (int)
Topic id
2. $subscribed_ids — Optional. (array) => array()
Array of forum ID's to check

Usage

  1. if ( !function_exists( 'bbp_is_user_subscribed_to_forum' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4. // Optional. User id 
  5. $user_id = -1; 
  6.  
  7. // Optional. Topic id 
  8. $forum_id = -1; 
  9.  
  10. // Optional. Array of forum ID's to check 
  11. $subscribed_ids = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bbp_is_user_subscribed_to_forum($user_id, $forum_id, $subscribed_ids); 
  15.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_is_user_subscribed_to_forum( $user_id = 0, $forum_id = 0, $subscribed_ids = array() ) { 
  2.  
  3. // Assume user is not subscribed 
  4. $retval = false; 
  5.  
  6. // Validate user 
  7. $user_id = bbp_get_user_id( $user_id, true, true ); 
  8. if ( ! empty( $user_id ) ) { 
  9.  
  10. // Get subscription ID's if none passed 
  11. if ( empty( $subscribed_ids ) ) { 
  12. $subscribed_ids = bbp_get_user_subscribed_forum_ids( $user_id ); 
  13.  
  14. // User has forum subscriptions 
  15. if ( ! empty( $subscribed_ids ) ) { 
  16.  
  17. // Checking a specific forum id 
  18. if ( ! empty( $forum_id ) ) { 
  19. $forum = bbp_get_forum( $forum_id ); 
  20. $forum_id = ! empty( $forum ) ? $forum->ID : 0; 
  21.  
  22. // Using the global forum id 
  23. } elseif ( bbp_get_forum_id() ) { 
  24. $forum_id = bbp_get_forum_id(); 
  25.  
  26. // Use the current post id 
  27. } elseif ( ! bbp_get_forum_id() ) { 
  28. $forum_id = get_the_ID(); 
  29.  
  30. // Is forum_id in the user's favorites 
  31. if ( ! empty( $forum_id ) ) { 
  32. $retval = in_array( $forum_id, $subscribed_ids ); 
  33.  
  34. return (bool) apply_filters( 'bbp_is_user_subscribed_to_forum', (bool) $retval, $user_id, $forum_id, $subscribed_ids );