Action hook 'delete_user'

in WP Core File wp-admin/includes/user.php at line 380

View Source

delete_user

Action Hook
Description
Fires immediately before a user is deleted from the site. Note that on a Multisite installation the user only gets removed from the site and does not get deleted from the database.

Hook Information

File Location wp-admin/includes/user.php View on GitHub
Hook Type Action
Line Number 380

Hook Parameters

Type Name Description
int $id ID of the user to delete.
int|null $reassign ID of the user to reassign posts and links to. Default null, for no reassignment.
WP_User $user WP_User object of the user to delete.

Usage Examples

Basic Usage
<?php
// Hook into delete_user
add_action('delete_user', 'my_custom_function', 10, 3);

function my_custom_function($id, $reassign, $user) {
    // Your custom code here
}

Source Code Context

wp-admin/includes/user.php:380 - How this hook is used in WordPress core
<?php
 375  	 * @param int      $id       ID of the user to delete.
 376  	 * @param int|null $reassign ID of the user to reassign posts and links to.
 377  	 *                           Default null, for no reassignment.
 378  	 * @param WP_User  $user     WP_User object of the user to delete.
 379  	 */
 380  	do_action( 'delete_user', $id, $reassign, $user );
 381  
 382  	if ( null === $reassign ) {
 383  		$post_types_to_delete = array();
 384  		foreach ( get_post_types( array(), 'objects' ) as $post_type ) {
 385  			if ( $post_type->delete_with_user ) {

PHP Documentation

<?php
/**
	 * Fires immediately before a user is deleted from the site.
	 *
	 * Note that on a Multisite installation the user only gets removed from the site
	 * and does not get deleted from the database.
	 *
	 * @since 2.0.0
	 * @since 5.5.0 Added the `$user` parameter.
	 *
	 * @param int      $id       ID of the user to delete.
	 * @param int|null $reassign ID of the user to reassign posts and links to.
	 *                           Default null, for no reassignment.
	 * @param WP_User  $user     WP_User object of the user to delete.
	 */
Quick Info
  • Hook Type: Action
  • Parameters: 3
  • File: wp-admin/includes/user.php
Related Hooks

Related hooks will be displayed here in future updates.