bb_remove_user_favorite

The BuddyPress bb remove user favorite function.

Description

bb_remove_user_favorite( $user_id, $topic_id ); 

Parameters (2)

0. $user_id
The user id.
1. $topic_id
The topic id.

Usage

  1. if ( !function_exists( 'bb_remove_user_favorite' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-forums/bbpress/bb-includes/functions.bb-users.php'; 
  3.  
  4. // The user id. 
  5. $user_id = null; 
  6.  
  7. // The topic id. 
  8. $topic_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bb_remove_user_favorite($user_id, $topic_id); 
  12.  

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-users.php  
  1. function bb_remove_user_favorite( $user_id, $topic_id ) { 
  2. global $bbdb; 
  3. $user_id = (int) $user_id; 
  4. $topic_id = (int) $topic_id; 
  5. $user = bb_get_user( $user_id ); 
  6. if ( !$user ) 
  7. return false; 
  8.  
  9. $favorites_key = $bbdb->prefix . 'favorites'; 
  10. $fav = explode(', ', $user->$favorites_key); 
  11. if ( is_int( $pos = array_search($topic_id, $fav) ) ) { 
  12. array_splice($fav, $pos, 1); 
  13. $fav = implode(', ', $fav); 
  14. bb_update_usermeta( $user->ID, $favorites_key, $fav); 
  15. do_action('bb_remove_user_favorite', $user_id, $topic_id); 
  16. return true;