Resetting admin rights

Members 2 posts 2 voices

  1. OK I have don’t something really stupid after installing the members plugin and managed to remove admin rights from my account and now I am locked out from the admin panel of my site!

    Any advice on what I can try to regain access?

    Thanks

  2. Probably the easiest way to regain access is to add this code to your theme’s functions.php file:

    add_action( 'admin_init', 'my_reset_admin_role', 0 );
    
    function my_reset_admin_role() {
    
    	$role = get_role( 'administrator' );
    
    	if ( ! empty( $role ) ) {
    
    		$role->add_cap( 'read'         );
    		$role->add_cap( 'list_roles'   );
    		$role->add_cap( 'create_roles' );
    		$role->add_cap( 'delete_roles' );
    		$role->add_cap( 'edit_roles'   );
    	}
    }

    That should give you enough access to edit your role via the admin and reset everything back the way it should be.

    Now, here’s the important bit. After you add that code to your theme’s functions.php file, you need to visit the WP admin on your site for it to execute. Once that’s done, remove that code from your theme’s functions.php file. Otherwise, it’ll run on every page load in the admin, which is not something you want.