0

In a twist of this post, I am unable to log into the WP Dashboard as the admin. When I do log in, it first just treats me as a subscriber with no access to anything. I just get the black bar at the top with the name of the site on the left and my username on the right. When I try to go to sitename.com/wp-admin, then I get the message "Sorry, you are not allowed to access this page." after logging into the dashboard.

In the wp_usermeta table, the admin user (user_id=1) has its wp_capabilities meta key set to the expected a:1:{s:13:"administrator";b:1;}.

rw-intechra
  • 197
  • 1
  • 14

1 Answers1

0

Try with below code put in functions.php

function  changeUserRole (){
    $wuser_ID = 1;
    if ($wuser_ID)
        {
          $userData = get_userdata($wuser_ID);
          $role = $userData->roles[0];
          if($role != 'administrator'){
            // Add role
            $userData->add_role( 'administrator' );
          }
        }
}

add_action('init','changeUserRole');
Akshay Shah
  • 3,391
  • 2
  • 20
  • 33