Skip to content

Instantly share code, notes, and snippets.

@10horizons
Last active October 29, 2022 05:23
Show Gist options
  • Save 10horizons/f52017e2818c904f83be4eb2ad8e5bdb to your computer and use it in GitHub Desktop.
Save 10horizons/f52017e2818c904f83be4eb2ad8e5bdb to your computer and use it in GitHub Desktop.
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