bbp_get_user_favorites

Get a user's favorite topics.

Description

(array|bool) bbp_get_user_favorites( (int) $user_id = 0 ); 

Returns (array|bool)

Results if user has favorites, otherwise false

Parameters (1)

0. $user_id — Optional. (int)
User id

Usage

  1. if ( !function_exists( 'bbp_get_user_favorites' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/functions.php'; 
  3.  
  4. // Optional. User id 
  5. $user_id = -1; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_user_favorites($user_id); 
  9.  

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_get_user_favorites( $user_id = 0 ) { 
  2. $user_id = bbp_get_user_id( $user_id ); 
  3. if ( empty( $user_id ) ) 
  4. return false; 
  5.  
  6. // If user has favorites, load them 
  7. $favorites = bbp_get_user_favorites_topic_ids( $user_id ); 
  8. if ( !empty( $favorites ) ) { 
  9. $query = bbp_has_topics( array( 'post__in' => $favorites ) ); 
  10. } else { 
  11. $query = false; 
  12.  
  13. return apply_filters( 'bbp_get_user_favorites', $query, $user_id, $favorites );