$10
Can I make it impossible for a user account to be deleted?
Japh, to answer your question, it is just certain users that I need to keep safe. I am using a lot of custom fields on this project, and I feel the setup is fragile. I worry about someone deleting a user, and then not knowing how to re-create that user, with all of the right info in the custom fields.
paddy | 01/04/10 at 2:27pm
| Edit
(4) Possible Answers Submitted...
-

Last edited:
01/04/10
3:07pmDan Davies says:I'm not sure of any way of preventing users from being deleted. You could perhaps edit the core files and remove the delete button, or use some CSS to hide it?
For backup methods, why not consider just a standard database backup, something that can be provided with this plugin: http://wordpress.org/extend/plugins/wp-db-backup/ -

Last edited:
01/04/10
3:35pmAndrew Jones says:It's possible for a plug-in to extend the Users page. From there, you could pass in an array of user-ids and do whichever with them including disabling the "Delete" function. That way you don't have to muck about in the core and have your solution killed by a WP upgrade.
-

Last edited:
01/04/10
5:11pmJaph says:paddy, do you want to block the deletion of ALL user accounts or only "certain" ones? if only certain ones, what are the criterion for when a user can or can't be deleted?
if you can give this information, we can more easily provide you with some sample code, rather than just directions :) -

Last edited:
01/05/10
1:40pmJustin Tadlock says:You can add this to your theme's functions.php file:
add_action( 'delete_user', 'dont_delete_user' );
function dont_delete_user( $id ) {
$dont_delete_ids = array( 1, 2, 3, 4 );
if ( in_array( $id, $dont_delete_ids ) )
wp_die( 'You cannot delete this user account.' );
}
The most important line is this one:
$dont_delete_ids = array( 1, 2, 3, 4 );
Add any user IDs that you don't want deleted to that array.
This code will create an error page when a user account is trying to be deleted from the WordPress admin if you've added the user ID.
This question has expired.
Current status of this question: Completed





