Languages: English • Reference/wp delete user 日本語 (Add your language)
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.
<?php wp_delete_user( $id, $reassign ); ?>
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() { // Verify that the user intended to take this action. if ( ! wp_verify_nonce( 'delete_account' ) ) { return; } require_once(ABSPATH.'wp-admin/includes/user.php' ); $current_user = wp_get_current_user(); wp_delete_user( $current_user->ID ); }
Since: 2.0
wp_delete_user() is located in wp-admin/includes/user.php
.