I want to create an admin ( role ), that cannot be deleted by other admins... something like a super admin. Of Course without using a plugin. Is a simple site. But has many admins (not by my choice), so I need one admin to be above all, and cant be deleted by other admins.
I want to create an admin ( role ), that cannot be deleted by other admins... something like a super admin. Of Course without using a plugin. Is a simple site. But has many admins (not by my choice), so I need one admin to be above all, and cant be deleted by other admins.
Share Improve this question edited Feb 24, 2020 at 1:24 Fede asked Feb 23, 2020 at 23:26 FedeFede 1377 bronze badges 4- Are you using a multisite install? Why do you need to do this? – Tom J Nowell ♦ Commented Feb 24, 2020 at 0:27
- no, it's a simple site, but have a few admins. So I need 1 admin too rule them all. – Fede Commented Feb 24, 2020 at 1:10
- "Of Course without using a plugin. Is a simple site." - well how else do you expect to make logic changes to the site? You can probably do this with one hook that blocks user delete either by a new role or by hard-coded ID, and this is probably only be half a dozen lines, but you'll need somewhere to put those half dozen lines, and your choices are either in your theme (if you've written it yourself) or in a plugin. It doesn't have to be a very big plugin, e.g. see 'Hello Dolly' as an example of a single file plugin. – Rup Commented Feb 24, 2020 at 10:36
- @Rup the user may mean they don't want a plugin recommendation. Either way it helps to know that a plugin is just WP code with a comment at the top, there's nothing slow about having lots of plugins, what makes it slow is when plugins do lots of things. Putting the code in the theme doesn't fix that – Tom J Nowell ♦ Commented Feb 24, 2020 at 20:33
1 Answer
Reset to default 1There are 2 approaches to get something equivalent to what you want, but, it isn't possible to have exactly what you want. On a single site administrator is the highest level, so you can't have higher than the highest.
Instead, here are alternatives:
- Turn your site into a multisite install that contains only 1 site, and declare yourself super-admin. Other admins will be able to remove you from that site, but you are a super admin, you do not need a role on the site in order to administer it, and they would need super admin rights to administer it
- Create a new user role that can do almost everything the admin role can, but isn't
- Add code that prevents users with the admin role being deleted, so nobody can delete admins, then use alternative means such as WP CLI to do it
Fundamentally, if you're concerned these other users might delete your admin user, then this is not a technical problem, but a business problem. The real solution lays in contracts and management. If these admin users are the client, then they're within their rights to evict you if they've paid their bills, either way, it's not a technical problem. Having this problem is usually a sign that something else has been done incorrectly, e.g. hiring a subcontractor to do dev work but making them do it via the edit theme page in WP-Admin rather than using version control or SFTP.