I just disabled all plugins, and then upgraded my WP to 4.7.3. And then first thing i do is to login as Administrator to the Panel.

Then i'm getting:

Sorry, you are not allowed to access this page

( Note: My Wordpress is using the default prefix wp_, so it shouldn't be the prefix issue. )

Then i did a bit of manual debugging. Here are steps:

(1) Inside wp-includes/user.php, after line 104, put print_r( $user ); exit; before the last line inside function wp_signon( ). And it returns the VALID user object which is correct:

104:      do_action( 'wp_login', $user->user_login, $user );
105:      print_r( $user ); exit;
106:      return $user;
107:  }

WP_User Object ( [data] => stdClass Object ( [ID] => 1 [user_login] => admin [user_pass] => $Q$BipvC2ydjzFlGFKbY.JKJhPqbEU7Ue. [user_nicename] => admin [user_email] => [email protected] [user_url] => [user_registered] => 2013-08-05 06:46:16 [user_activation_key] => [user_status] => 1 [display_name] => Administrator ) [ID] => 1 [caps] => Array ( [administrator] => 1 ) [cap_key] => wp_capabilities [roles] => Array ( [0] => administrator ) [allcaps] => Array ( [switch_themes] => 1 [edit_themes] => 1 [activate_plugins] => 1 [edit_plugins] => 1 [edit_users] => 1 [edit_files] => 1 [manage_options] => 1 [moderate_comments] = .................

( That means, at this point, Wordpress can properly authenticate the user and retrieve it's Object. So nothing is wrong with authentication part! )

(2) Then, inside wp-admin/admin.php, after line 31, put the echo get_current_user_id();

31:      require_once(dirname(dirname(__FILE__)) . '/wp-load.php');
32:      echo get_current_user_id();

Then, here it comes!


Sorry, you are not allowed to access this page.

So that means, at this point, the logged in Admin User just now has gone. Wordpress has lost the User, and hence is not remembering the user.

Can anyone help me understand to solve WHY is that happening please?

In case you want to know, here are my Database values, inside wp_usermeta table (for user_id=1):

wp_capabilities = a:1:{s:13:"administrator";s:1:"1";}

wp_user_level = 10

  • Are you only getting this on the admin area? Does is_user_logged_in() return true on the front end vs the admin area if you hook it via init?
    – iyrin
    Commented Mar 29, 2017 at 4:27
  • @iyrin I have verified it is only happening in Admin Area. The front-end returns: 1. (Thanks for helping out! :)) Commented Mar 29, 2017 at 4:34
  • You nay want to play with wp_get_current_user() to find different details as well. developer.wordpress.org/reference/functions/get_current_user_id/… If you're really curious about pinpointing the problem, this may help. Although because you have been editing core files, I think the answer I've provided below is the best option to restore your site to function properly again.
    – iyrin
    Commented Mar 29, 2017 at 4:46

1 Answer 1


Editing the core files is not recommended. You may try downloading a clean install of WordPress files. If you can, set the current theme to TwentySeventeen so your database is ready to work with a clean install.

Make sure to back up your database if you have not already.

Follow the codex instructions to delete the old WordPress files. They have a nice list of all the files you want to keep for the clean install. Although, rather than deleting, I recommend changing the directory name to something like wordpress-backup and then installing the new files with the original directory name wordpress or whatever it's currently called.

Then you can start copying over the essential files. Be sure to do this before trying to run the site again. Especially if you could not switch to the TwentySeventeen theme first. You will want to make sure the theme you're currently using will be found. Here are the files to copy to the clean install:

  • wp-config.php file;

  • wp-content folder;

  • wp-includes/languages/ folder--if you are using a language file, and it is here rather than in wp-content/languages/, do not delete this
    folder (you might want to move your language files
    to wp-content/languages/ for easier upgrading in the future);

  • .htaccess file--if you have added custom rules to your .htaccess, do not delete it.

  • Custom Content (themes) and/or Plugins--if you have any images or other custom content or Plugins inside the wp-content folder, do NOT delete them.

Now test the site and try changing the theme to TwentySeventeen theme if you couldn't do that before. It's always best to test the defaults first to rule out an incompatible theme or plugin as you did earlier.

  • Thanks for the approach. This would be the safest one. But i still wanna know why normal "upgrading" didn't work as expected. That is why I'm digging into core files. ("Pin-pointing" as you labelled) So... any idea why the Admin User Object has gone after some point of the login process? Commented Mar 29, 2017 at 5:10
  • If you want to narrow your search, I would try a diff between your current WordPress files against a clean installation. This will show any instances where your current installation does not match. Please be sure to answer your own question if you identify the problem. en.wikipedia.org/wiki/Diff_utility
    – iyrin
    Commented Mar 29, 2017 at 5:16
  • Btw, whwn running the diff be sure to exclude any of the files listed in this answer (wp-config, wp-content folder, etc). We already know those will be different and they are supposed to be.
    – iyrin
    Commented Mar 29, 2017 at 5:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.