bp_core_delete_account( int $user_id )
Process account deletion requests.
Description
Primarily used for self-deletions, as requested through Settings.
Parameters
- $user_id
-
(Optional) ID of the user to be deleted. Default: the logged-in user.
Return
(bool) True on success, false on failure.
Source
File: bp-members/bp-members-functions.php
function bp_core_delete_account( $user_id = 0 ) { // Use logged in user ID if none is passed. if ( empty( $user_id ) ) { $user_id = bp_loggedin_user_id(); } // Site admins cannot be deleted. if ( is_super_admin( $user_id ) ) { return false; } // Extra checks if user is not deleting themselves. if ( bp_loggedin_user_id() !== absint( $user_id ) ) { // Bail if current user cannot delete any users. if ( ! bp_current_user_can( 'delete_users' ) ) { return false; } // Bail if current user cannot delete this user. if ( ! current_user_can_for_blog( bp_get_root_blog_id(), 'delete_user', $user_id ) ) { return false; } } /** * Fires before the processing of an account deletion. * * @since BuddyPress 1.6.0 * * @param int $user_id ID of the user account being deleted. */ do_action( 'bp_core_pre_delete_account', $user_id ); // Specifically handle multi-site environment. if ( is_multisite() ) { require_once( ABSPATH . '/wp-admin/includes/ms.php' ); require_once( ABSPATH . '/wp-admin/includes/user.php' ); $retval = wpmu_delete_user( $user_id ); // Single site user deletion. } else { require_once( ABSPATH . '/wp-admin/includes/user.php' ); $retval = wp_delete_user( $user_id ); } /** * Fires after the deletion of an account. * * @since BuddyPress 1.6.0 * * @param int $user_id ID of the user account that was deleted. */ do_action( 'bp_core_deleted_account', $user_id ); return $retval; }
Changelog
Version | Description |
---|---|
BuddyPress 1.0.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.