Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to prevent your account from being deleted by admins on WordPress.
<?php
function wproot_prevent_user_deletion( $deleting_userid ) {
$protected_userid = 1; //change 1 to the ID of the user you don't want to be deleted.
if ( $deleting_userid == $protected_userid ) {
$user_obj = get_user_by('id', $deleting_userid);
$name = $user_obj->user_login;
wp_die( sprintf( 'Sorry, you are not allowed to delete user %s.', $name ) );
}
}
add_action('delete_user', 'wproot_prevent_user_deletion');
/*
Blog post URL: https://wproot.dev/blog/wordpress-how-to-prevent-your-account-from-being-deleted-by-admins/
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment