WordPress.org

Ready to get started?Download WordPress

Forums

Recover super admin access after username change? (13 posts)

  1. revolutionfrance
    Member
    Posted 4 years ago #

    Hello! I am using wp 3 multi-site, and I changed my admin username in the MYSQL database. Only problem is, I now lost super admin access, and am finding no way to recover it. Any kind soul willing to enlighten me?

  2. revolutionfrance
    Member
    Posted 4 years ago #

    Any help to find?

  3. revolutionfrance
    Member
    Posted 4 years ago #

    No answer in 2 days...is there really no one that knows how to do this?

  4. Kevin
    Member
    Posted 4 years ago #

    I just had this same problem occur. Did you find a solution?

  5. mrmist
    Forum Janitor
    Posted 4 years ago #

    I'll move this to the multi-site forum, folk might know there.

  6. You'll have to fix it in the database now. :)

    Super Admin staus is kept track of separately. And you have to be logged in as a Super Admin to make another one, so. In your case, the only way to fix it now is in the db.

    look in the wp_sitemeta table for the site admins field. you'll see a value like this:

    a:1:{i:0;s:6:"andrea";}

    The 6 means my usenrame has 6 characters. andrea is my username. :) Change whatever you have to your new changed username and that integer.

  7. Ruben.cc
    Member
    Posted 3 years ago #

    Thank you so much Andrea! This problem has kept me busy for the past three hours after changing my name "Ruben" to "Beheerder" (Dutch for Admin) using a search-and-replace in the SQL. Lost my Super Admin "powers" but couldn't easily change things back since I already re-added "Ruben" as a regular user afterwards.

    Although I find this "number-of-characters-in-username" an ultimately stupid "feature" in WordPress, I thank you very very much for this simple solution. Couldn't find a fix anywhere, only ended up here after searching Google xxx times.

    Perhaps you can tell why this "character count" is useful, just to satisfy my curiosity and hopefully find it less stupid?

  8. James Collins
    Member
    Posted 3 years ago #

    The contents of that wp_sitemeta record is a PHP array that has been serialized (http://php.net/manual/en/function.serialize.php) so that it can be stored in the database.

    For example, if you have 3 usernames that are allowed to be site admins, this is stored in a PHP array with 3 elements, which is serialized before being stored in the database.

  9. In other words, the command I listed above is a database thing, not a wordpress thing.

  10. DPoncy
    Member
    Posted 3 years ago #

    I have also lost my super admin. I accidently dropped the database record for my administrator user, but I had backed it up and restored the database field to the identical setting.

    I still somehow lost my super admin. I double checked the wp_sitemeta table and my site admins says:

    a:1:{i:1;s:10:"administra";} which matches up to my admin name.

    Any ideas about what else might be causing a problem?

  11. DPoncy
    Member
    Posted 3 years ago #

    Never mind. I fixed it by adding a new identity into the database.

  12. ekitel
    Member
    Posted 3 years ago #

    I see a lot of threads about this, explaining how to edit the database records to fix this, but that didn't work for me

    instead I just put this in a plugin and later removed it (4 is user id I want to make super admin)
    grant_super_admin(4);

    that alone caused some errors, I had to add other code to make it work, which still caused a different error but it had the desired effect and I could just delete all this when I was done (I'm just wondering if this is a symptom of other problems with my installation)

    require_once(ABSPATH . 'wp-includes/pluggable.php');
    
    grant_super_admin(4);
    
    function grant_super_admin( $user_id ) {
    	global $super_admins;
    
    	// If global super_admins override is defined, there is nothing to do here.
    	if ( isset($super_admins) )
    		return false;
    
    	do_action( 'grant_super_admin', $user_id );
    
    	// Directly fetch site_admins instead of using get_super_admins()
    	$super_admins = get_site_option( 'site_admins', array( 'admin' ) );
    
    	$user = new WP_User( $user_id );
    	if ( ! in_array( $user->user_login, $super_admins ) ) {
    		$super_admins[] = $user->user_login;
    		update_site_option( 'site_admins' , $super_admins );
    		do_action( 'granted_super_admin', $user_id );
    		return true;
    	}
    	return false;
    }
  13. (I'm just wondering if this is a symptom of other problems with my installation)

    Probably, yes.

Topic Closed

This topic has been closed to new replies.

About this Topic