Last active
October 29, 2022 05:23
-
-
Save 10horizons/f52017e2818c904f83be4eb2ad8e5bdb to your computer and use it in GitHub Desktop.
How to prevent your account from being deleted by admins on WordPress.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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