bb_delete_user

The BuddyPress bb delete user function.

Description

bb_delete_user( $user_id, (int) $reassign = 0 ); 

Parameters (2)

0. $user_id
The user id.
1. $reassign — Optional. (int)
The reassign.

Usage

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

Defined (1)

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

/bp-forums/bbpress/bb-includes/functions.bb-users.php  
  1. function bb_delete_user( $user_id, $reassign = 0 ) { 
  2. global $wp_users_object, $bbdb; 
  3.  
  4. if ( !$user = bb_get_user( $user_id ) ) 
  5. return false; 
  6.  
  7. if ( $reassign ) { 
  8. if ( !$new_user = bb_get_user( $reassign ) ) 
  9. return false; 
  10. $bbdb->update( $bbdb->posts, array( 'poster_id' => $new_user->ID ), array( 'poster_id' => $user->ID ) ); 
  11. $bbdb->update( $bbdb->term_relationships, array( 'user_id' => $new_user->ID ), array( 'user_id' => $user->ID ) ); 
  12. $bbdb->update( $bbdb->topics, array( 'topic_poster' => $new_user->ID, 'topic_poster_name' => $new_user->user_login), array( 'topic_poster' => $user->ID ) ); 
  13. $bbdb->update( $bbdb->topics, array( 'topic_last_poster' => $new_user->ID, 'topic_last_poster_name' => $new_user->user_login ), array( 'topic_last_poster' => $user->ID ) ); 
  14. bb_update_topics_replied( $new_user->ID ); 
  15. wp_cache_flush( 'bb_post' ); 
  16. wp_cache_flush( 'bb_thread' ); 
  17. wp_cache_flush( 'bb_topic_tag' ); 
  18. wp_cache_flush( 'bb_topic' ); 
  19.  
  20. do_action( 'bb_delete_user', $user->ID, $reassign ); 
  21.  
  22. $wp_users_object->delete_user( $user->ID ); 
  23.  
  24. return true;