WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp delete user

Contents

Description

Remove user and optionally reassign posts and links to another user.

If the $reassign parameter is not assigned to a User ID, then all posts will be deleted of that user. The action 'delete_user' that is passed the User ID being deleted will be run after the posts are either reassigned or deleted. The user meta will also be deleted that are for that User ID.

Usage

<?php wp_delete_user$id$reassign ); ?>

Parameters

$id
(integer) (required) User ID.
Default: None
$reassign
(integer) (optional) Reassign posts and links to new User ID.
Default: null

Return Values

(boolean) 
True when finished.

Examples

Allow users to terminate their user accounts.

if(is_user_logged_in() && !empty($_GET['DeleteMyAccount'])) {
	add_action('init', 'remove_logged_in_user');
}

function remove_logged_in_user() {
	require_once(ABSPATH.'wp-admin/includes/user.php' );
	$current_user = wp_get_current_user();
	wp_delete_user( $current_user->ID );
}

Notes

  • If you wish to use this function in a plugin then you must include the ./wp-admin/includes/user.php file in your plugin function, else it will throw a 'call to undefined function' error
  • Uses global: (object) $wpdb
  • This is an Admin function.

Change Log

Since: 2.0

Source File

wp_delete_user() is located in wp-admin/includes/user.php.

Related

See also index of Function Reference and index of Template Tags.