bbp_is_user_subscribed

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

Description

bbp_is_user_subscribed( (int) $user_id = 0, (int) $object_id = 0 ); 

Parameters (2)

0. $user_id — Optional. (int)
User id
1. $object_id — Optional. (int)
Topic id

Usage

  1. if ( !function_exists( 'bbp_is_user_subscribed' ) ) { 
  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. $object_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_is_user_subscribed($user_id, $object_id); 
  12.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_is_user_subscribed( $user_id = 0, $object_id = 0 ) { 
  2.  
  3. // Assume user is not subscribed 
  4. $retval = false; 
  5.  
  6. // Setup ID's array 
  7. $subscribed_ids = array(); 
  8.  
  9. // User and object ID's are passed 
  10. if ( ! empty( $user_id ) && ! empty( $object_id ) ) { 
  11.  
  12. // Get the post type 
  13. $post_type = get_post_type( $object_id ); 
  14.  
  15. // Post exists, so check the types 
  16. if ( ! empty( $post_type ) ) { 
  17.  
  18. switch( $post_type ) { 
  19.  
  20. // Forum 
  21. $subscribed_ids = bbp_get_user_subscribed_forum_ids( $user_id ); 
  22. $retval = bbp_is_user_subscribed_to_forum( $user_id, $object_id, $subscribed_ids ); 
  23. break; 
  24.  
  25. // Topic (default) 
  26. default : 
  27. $subscribed_ids = bbp_get_user_subscribed_topic_ids( $user_id ); 
  28. $retval = bbp_is_user_subscribed_to_topic( $user_id, $object_id, $subscribed_ids ); 
  29. break; 
  30.  
  31. return (bool) apply_filters( 'bbp_is_user_subscribed', $retval, $user_id, $object_id, $subscribed_ids );