How to Prevent deleting user accounts in WordPress Back-end?

A quick (and dirty) solution would be to prevent the final deletion where it happens (function delete_user). You could implement a little plugin or paste the code into your functions.php:

<?php

/*
Plugin Name: Please don't delete me!
Description: Prevent accidental user deletion of my account
*/

define('PDDM_USER_ID', 1); // User ID of your Account

add_action('delete_user', function($id) {
    if ($id == PDDM_USER_ID) {
        die('please don\'t delete me!');
    }
});

This just stops the script execution just before your user get’s deleted.

Not fancy and pretty … but it works 😉

br from Salzburg!

Leave a Comment