do_action( 'delete_user', int $id, int|null $reassign, WP_User $user )

Fires immediately before a user is deleted from the database.


Parameters Parameters

$id

(int) ID of the user to delete.

$reassign

(int|null) ID of the user to reassign posts and links to. Default null, for no reassignment.

$user

(WP_User) WP_User object of the user to delete.


Top ↑

More Information More Information

The delete_user action/hook can be used to perform additional actions when a user is deleted. For example, you can delete rows from custom tables created by a plugin.

This hook runs before a user is deleted. The hook deleted_user (notice the “ed”) runs after a user is deleted. Choose the appropriate hook for your needs. If you need access to user meta or fields from the user table, use delete_user.

Users deleted from Network Site installs may not trigger this hook. Be sure to use the wpmu_delete_user hook for those cases. The deleted_user hook is called in either case.


Top ↑

Source Source

File: wp-admin/includes/user.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
5.5.0 Added the $user parameter.
2.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example migrated from Codex:

    In this example we send a friendly message to a user before their account is deleted a few milliseconds later.

    function my_delete_user( $user_id ) {
    	global $wpdb;
    
    	$user_obj = get_userdata( $user_id );
    	$email = $user_obj->user_email;
    
    	$headers = 'From: ' . get_bloginfo( "name" ) . ' <' . get_bloginfo( "admin_email" ) . '>' . "\r\n";
    	wp_mail( $email, 'You are being deleted, brah', 'Your account at ' . get_bloginfo("name") . ' is being deleted right now.', $headers );
    }
    add_action( 'delete_user', 'my_delete_user' );
    
  2. Skip to note 2 content
    Contributed by yongkiagustinus

    Example usage
    Send email notification when a user is deleted

    add_action( 'delete_user', 'my_delete_user' );
    function my_delete_user() {
    	$user_data = get_userdata( $user_id );
    	
    	$headers 	= 'From: ' . get_bloginfo( 'name' ) . ' ' . "\r\n";
    
    	wp_mail( $user_data->user_email, 'We are deleting your account', 'Your account at ' . get_bloginfo( 'name' ) . ' will be deleted.', $headers);
    }
    

You must log in before being able to contribute a note or feedback.