bbp_get_topic_favoriters

Get the users who have made the topic favorite.

Description

(array|bool) bbp_get_topic_favoriters( (int) $topic_id = 0 ); 

Returns (array|bool)

Results if the topic has any favoriters, otherwise false

Parameters (1)

0. $topic_id — Optional. (int)
Topic id

Usage

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

Defined (1)

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

/includes/users/functions.php  
  1. function bbp_get_topic_favoriters( $topic_id = 0 ) { 
  2. $topic_id = bbp_get_topic_id( $topic_id ); 
  3. if ( empty( $topic_id ) ) 
  4. return; 
  5.  
  6. global $wpdb; 
  7.  
  8. $key = $wpdb->prefix . '_bbp_favorites'; 
  9. $users = wp_cache_get( 'bbp_get_topic_favoriters_' . $topic_id, 'bbpress_users' ); 
  10. if ( false === $users ) { 
  11. $users = $wpdb->get_col( "SELECT user_id FROM {$wpdb->usermeta} WHERE meta_key = '{$key}' and FIND_IN_SET('{$topic_id}', meta_value) > 0" ); 
  12. wp_cache_set( 'bbp_get_topic_favoriters_' . $topic_id, $users, 'bbpress_users' ); 
  13.  
  14. return apply_filters( 'bbp_get_topic_favoriters', $users );