bbp_remove_user_favorite

Remove a topic from user's favorites.

Description

bbp_remove_user_favorite( (int) $user_id, (int) $topic_id ); 

Parameters (2)

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

Usage

  1. if ( !function_exists( 'bbp_remove_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_remove_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_remove_user_favorite( $user_id, $topic_id ) { 
  2. if ( empty( $user_id ) || empty( $topic_id ) ) 
  3. return false; 
  4.  
  5. $favorites = (array) bbp_get_user_favorites_topic_ids( $user_id ); 
  6. if ( empty( $favorites ) ) 
  7. return false; 
  8.  
  9. $pos = array_search( $topic_id, $favorites ); 
  10. if ( is_numeric( $pos ) ) { 
  11. array_splice( $favorites, $pos, 1 ); 
  12. $favorites = array_filter( $favorites ); 
  13.  
  14. if ( !empty( $favorites ) ) { 
  15. $favorites = implode( ', ', wp_parse_id_list( $favorites ) ); 
  16. update_user_option( $user_id, '_bbp_favorites', $favorites ); 
  17. } else { 
  18. delete_user_option( $user_id, '_bbp_favorites' ); 
  19.  
  20. do_action( 'bbp_remove_user_favorite', $user_id, $topic_id ); 
  21.  
  22. return true;