The delete_user_form WordPress PHP action fires at the end of the delete users form prior to the confirm button. It allows you to add custom elements or modifications to the form.
Usage
add_action('delete_user_form', 'your_custom_function', 10, 2); function your_custom_function($current_user, $userids) { // your custom code here }
Parameters
$current_user
(WP_User): WP_User object for the current user.$userids
(int[]): Array of IDs for users being deleted.
More information
See WordPress Developer Resources: delete_user_form
Examples
Add a custom warning message
Display a custom warning message before the confirm button.
add_action('delete_user_form', 'custom_warning_message', 10, 2); function custom_warning_message($current_user, $userids) { _e('<p><strong>Note:</strong> This action cannot be undone!</p>', 'your-text-domain'); }
Log user deletion
Log the deletion of users to a custom table in the database.
add_action('delete_user_form', 'log_user_deletion', 10, 2); function log_user_deletion($current_user, $userids) { global $wpdb; // your custom code to insert the log into your custom table }
Send email notification
Send an email notification to the site admin when users are being deleted.
add_action('delete_user_form', 'send_email_notification', 10, 2); function send_email_notification($current_user, $userids) { // your custom code to send the email notification }
Display a custom message based on user role
Show a custom message for users with a specific role.
add_action('delete_user_form', 'display_message_based_on_role', 10, 2); function display_message_based_on_role($current_user, $userids) { if (in_array('administrator', $current_user->roles)) { _e('<p><strong>Warning:</strong> You are deleting an administrator!</p>', 'your-text-domain'); } }
Add a custom checkbox
Add a custom checkbox to the delete user form.
add_action('delete_user_form', 'add_custom_checkbox', 10, 2); function add_custom_checkbox($current_user, $userids) { _e('<p><label><input type="checkbox" name="custom_option"> Custom Option</label></p>', 'your-text-domain'); }