bbp_is_user_favorite

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

Description

bbp_is_user_favorite( (int) $user_id = 0, (int) $topic_id = 0 ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_is_user_favorite( $user_id = 0, $topic_id = 0 ) { 
  2.  
  3. $user_id = bbp_get_user_id( $user_id, true, true ); 
  4. if ( empty( $user_id ) ) 
  5. return false; 
  6.  
  7. $retval = false; 
  8. $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 
  9.  
  10. if ( !empty( $favorites ) ) { 
  11.  
  12. // Checking a specific topic id 
  13. if ( !empty( $topic_id ) ) { 
  14. $topic = bbp_get_topic( $topic_id ); 
  15. $topic_id = !empty( $topic ) ? $topic->ID : 0; 
  16.  
  17. // Using the global topic id 
  18. } elseif ( bbp_get_topic_id() ) { 
  19. $topic_id = bbp_get_topic_id(); 
  20.  
  21. // Use the current post id 
  22. } elseif ( !bbp_get_topic_id() ) { 
  23. $topic_id = get_the_ID(); 
  24.  
  25. // Is topic_id in the user's favorites 
  26. if ( !empty( $topic_id ) ) { 
  27. $retval = in_array( $topic_id, $favorites ); 
  28.  
  29. return (bool) apply_filters( 'bbp_is_user_favorite', (bool) $retval, $user_id, $topic_id, $favorites );