bbp_is_user_subscribed_to_topic

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

Description

bbp_is_user_subscribed_to_topic( (int) $user_id = 0, (int) $topic_id = 0, (array) $subscribed_ids = array() ); 

Parameters (3)

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

Usage

  1. if ( !function_exists( 'bbp_is_user_subscribed_to_topic' ) ) { 
  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. $topic_id = -1; 
  9.  
  10. // Optional. Array of topic ID's to check 
  11. $subscribed_ids = array(); 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bbp_is_user_subscribed_to_topic($user_id, $topic_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_topic( $user_id = 0, $topic_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_topic_ids( $user_id ); 
  13.  
  14. // User has topic subscriptions 
  15. if ( ! empty( $subscribed_ids ) ) { 
  16.  
  17. // Checking a specific topic id 
  18. if ( ! empty( $topic_id ) ) { 
  19. $topic = bbp_get_topic( $topic_id ); 
  20. $topic_id = ! empty( $topic ) ? $topic->ID : 0; 
  21.  
  22. // Using the global topic id 
  23. } elseif ( bbp_get_topic_id() ) { 
  24. $topic_id = bbp_get_topic_id(); 
  25.  
  26. // Use the current post id 
  27. } elseif ( !bbp_get_topic_id() ) { 
  28. $topic_id = get_the_ID(); 
  29.  
  30. // Is topic_id in the user's favorites 
  31. if ( ! empty( $topic_id ) ) { 
  32. $retval = in_array( $topic_id, $subscribed_ids ); 
  33.  
  34. return (bool) apply_filters( 'bbp_is_user_subscribed_to_topic', (bool) $retval, $user_id, $topic_id, $subscribed_ids );