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

1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
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

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.