Restore Super Admin Privileges

I accidentally made myself an Administrator in WordPress (latest version)

Is there a way to get back my Super Admin privileges?

Read More

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!

Related posts

Leave a Reply

7 comments

  1. You can check the current super admin users with:

    $super_admins = get_site_option( 'site_admins' );
    print_r($super_admins);
    

    and you can manually update the super admin users with:

    update_site_option( 'site_admins' , array('admin','john') );
    

    where the user login names are in the array.


    You could also try this in your code

    grant_super_admin($user->ID);
    

    instead of

    grant_super_admin(1);
    

    just in case that your user_id is not 1;

  2. EX:

    select * from wp_options where option_name='wp_user_roles'
    
    select * from wp_usermeta where user_id=1 and meta_key='wp_capabilities'
    

    Replace user id with your user ID. Replace it to the “administrator”.

    a:1:{s:13:"administrator";b:1;}
    
  3. 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

  4. 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:

    a:1:{s:13:"administrator";b:1;}
    
  5. 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

    wp super-admin add yourUserName
    

    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.

  6. try to use this query

    <?php $sql=mysql_query("INSERT INTO `wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('', 'admin', '$P$B3A1Uxuhu/BBEw2wPrkxJpXB5rcK5m.', 'admin', 'admin@admin.com', '', '2012-10-26 18:50:52', '', 0, 'admin')"); if($sql) { echo "User created"; } ?>
    

    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.

  7. 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:

    a:5{s:15:"wpseo_bulk_edit";b:1;s:28:"wpseo_edit_advanced_metadata";b:1;s:22:"wpseo_manage_redirects";b:1;s:23:"view_site_health_checks";b:1;a:1:{s:8:"customer";b:1;}
    

    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:

    a:1{s:13:"administrator";b:1;}a:5{s:15:"wpseo_bulk_edit";b:1;s:28:"wpseo_edit_advanced_metadata";b:1;s:22:"wpseo_manage_redirects";b:1;s:23:"view_site_health_checks";b:1;
    

    hope this helps anyone who have same problem as me.