bp_core_delete_account

Process account deletion requests.

Description

bp_core_delete_account( (int) $user_id = 0 ); 

Primarily used for self-deletions, as requested through Settings.

Parameters (1)

0. $user_id — Optional. (int)
ID of the user to be deleted. Default: the logged-in user.

Usage

  1. if ( !function_exists( 'bp_core_delete_account' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // Optional. ID of the user to be deleted. Default: the 
  5. // logged-in user. 
  6. $user_id = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_core_delete_account($user_id); 
  10.  

Defined (1)

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

/bp-members/bp-members-functions.php  
  1. function bp_core_delete_account( $user_id = 0 ) { 
  2.  
  3. // Use logged in user ID if none is passed. 
  4. if ( empty( $user_id ) ) { 
  5. $user_id = bp_loggedin_user_id(); 
  6.  
  7. // Site admins cannot be deleted. 
  8. if ( is_super_admin( $user_id ) ) { 
  9. return false; 
  10.  
  11. // Extra checks if user is not deleting themselves. 
  12. if ( bp_loggedin_user_id() !== absint( $user_id ) ) { 
  13.  
  14. // Bail if current user cannot delete any users. 
  15. if ( ! bp_current_user_can( 'delete_users' ) ) { 
  16. return false; 
  17.  
  18. // Bail if current user cannot delete this user. 
  19. if ( ! current_user_can_for_blog( bp_get_root_blog_id(), 'delete_user', $user_id ) ) { 
  20. return false; 
  21.  
  22. /** 
  23. * Fires before the processing of an account deletion. 
  24. * @since 1.6.0 
  25. * @param int $user_id ID of the user account being deleted. 
  26. */ 
  27.  
  28. // Specifically handle multi-site environment. 
  29. if ( is_multisite() ) { 
  30. require_once( ABSPATH . '/wp-admin/includes/ms.php' ); 
  31. require_once( ABSPATH . '/wp-admin/includes/user.php' ); 
  32.  
  33. $retval = wpmu_delete_user( $user_id ); 
  34.  
  35. // Single site user deletion. 
  36. } else { 
  37. require_once( ABSPATH . '/wp-admin/includes/user.php' ); 
  38. $retval = wp_delete_user( $user_id ); 
  39.  
  40. /** 
  41. * Fires after the deletion of an account. 
  42. * @since 1.6.0 
  43. * @param int $user_id ID of the user account that was deleted. 
  44. */ 
  45.  
  46. return $retval;