Troubleshooting a “You do not have sufficient permissions to access this page” error

I spent several hours of my Saturday looking for this error. I could not find a guide anywhere on the ‘net that described my eventual solution. Here is my solution.

In the WP core, the “You do not have sufficient permissions to access this page.” error is generated at the end of /wp-admin/includes/menu.php. A grep of my plugin directories also showed that several plugins also could generate this error.

Make a backup of menu.php, and replace the code inside the if block on lines 224-227 (as of v3.5) with the following:

if ( !user_can_access_admin_page() ) {
   $a = array(
       'Pages No Access' => $_wp_menu_nopriv,
       'User Info' => $current_user,
       'Roles' => $wp_roles->get_names(),
   );
   $s = sprintf("\n<br /><pre>%s</pre>", print_r($a, true));
   do_action('admin_page_access_denied');
   wp_die( __('You do not have sufficient permissions to access this page.'.$s) );
}

DON’T Leave this code live on your site unless you are actively debugging! Replace this with the backup menu.php if you need to step away for a while.

Try to access the admin side again. This error page will tell you a few things:

  1. If you get additional output on your failure page, this tells you that the failure is being generated by the WP core. In my case it was. If you don’t get additional output, you know you need to start looking for the plugin that is causing the error.
  2. Any page in the Pages No Access array set to 1 is not accessible to the user. In my case, all pages were set to 1.
  3. In User Info, check to see if the user has the correct roles and capabilities. In my case, the user had a role of 10 and the capabilities they should have as an admin.
  4. In Roles you will see a list of defined roles for the site. In my case, I had no defined roles. Here was my problem.

In my case, I was able to browse my database in phpMyAdmin, and look for the [WPDB_PREFIX]_[SITENO]_user_roles entry in the [WPDB_PREFIX]_[SITENO]_options table. I had changed my WPDB_PREFIX, but some plugin had created a custom user role and written this with the default wp_ prefix. I was able to copy over the entry from a working site into the non-working site. As soon as I did the admin was immediately able to access the site.

My install was further complicated because I was using the new blog templates plugin, and my template site also had it’s database corrupted in the same way.

I hope this helps.

Leave a Comment