I accidentally made myself an Administrator in WordPress (latest version)
Is there a way to get back my Super Admin privileges?
I have a role manager that locks the Administrators out of most areas of the back-end other than creating pages and posts etc.
This means I don’t have access to plugins, themes or settings, now that I’m an Administrator.
I’ve tried adding the below code to the functions.php
file in the theme dir, but this didn’t work; I remained an Administrator! 🙁
include(ABSPATH . 'wp-admin/includes/ms.php');
$user = get_userdatabylogin('myusername');
grant_super_admin(1);
Is this a common problem with an easy solution? I’ve been searching Google all day with no luck!
You can check the current super admin users with:
and you can manually update the super admin users with:
where the user login names are in the array.
You could also try this in your code
instead of
just in case that your
user_id
is not1
;EX:
Replace user id with your user ID. Replace it to the “administrator”.
I did this trying to restore a backup which replaced my current super admin user, with an old user who was just an admin, so I got locked out of my super admin user privileges.
The fix is for this is really straightforward and easy. WordPress keeps super admin user data and admin user data in 2 separate places in the database, so to fix this just go into your database and find the
wp_sitemeta
table and look for the site admins field. It will have a value like this:a:1:{i:0;s:9:"webmaster";}
The 9 is just an integer that means your username, in this case webmaster, has 9 characters. Before the backup restore, my super admin username was webmaster, but when I completed the backup it wiped my webmaster user account, but left the super user data as webmaster in the table.
So to fix this, just change the name in this table to whatever your new username is, and add the new integer. So if your new username is newwebmaster then it should look like:
a:1{i:0;s:12:"newwebmaster";}
This should restore your super admin privileges
If your user still exists in the phpmyadmin or any database handler and you have access to the wordpress database then try this:
Change your wp_capabilities in the user_meta table to:
If you have access to wpcli, you can do this without mucking around with a meta table and a serialized capabilities array. Do this with wp super-admin
If you don’t have access to wpcli and you operate a if installation, you absolutely should go to the trouble of getting it set up. It’s astonishingly useful. But practice using it on a staging site; it’s powerful like a chainsaw.
try to use this query
it will create new user admin with password admin you can change password laterly from admin you can place the query in your header file.
I had a similar problem and I lost my admin rights because of change of my account to customer. I tried all the above and found out rankmath added some lines like below:
to wp_capabilities and when I changed
a:1:{s:13:"administrator";b:1;}
that didnt work and after I moved this line to the begining it did work for me like this:hope this helps anyone who have same problem as me.