How do I run my custom function in my plugin when a wordpress user is deleted?

admin2025-06-04  3

I have a custom function in my plugin, I want to run it when any of the wordpress user is deleted so i can know that a user and which user was deleted. I implemented this but it is'nt working.

 function my_delete_user( $user_id ) {
    global $wpdb;
    require_once(ABSPATH.'wp-admin/includes/user.php' );
        $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' );

but this is not working, as it should send a mail. I want to know which user was deleted from their email.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749023280a315703.html

最新回复(0)