Analyzing "You do not have sufficient permissions to access this page" error in WP admin

June 18, 2020 – Tested with WP 5.4.2.

March 23, 2018 – Updated the default value for wp_user_roles from WP 4.9.4. Everything else in this post still applies.

Recently, a client came to us with a problem – they were suddenly unable to log in to their WordPress/WooCommerce site.


Even when logged in as Administrator, You do not have sufficient permissions to access this page error message was displayed and it was not possible to navigate to any page in wp-admin – even the account’s profile page. This symptom indicates that WP cannot find the roles and permissions of your account from the database – so it assumes you don’t have any permissions at all.

The most typical cause for this problem is the database prefix setting. In wp-config.php, it looks like this:

 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
$table_prefix = 'wp_';

Some developers change the DB prefix for various reasons (which I’ll not discuss in this post). When this is done during the installation process, it shouldn’t cause any problems. However, when migrating your site or changing the DB prefix after installation, there’s a chance to break something. This is because the field titled “Database Table Prefix” is actually not only for table prefixes, but also for some field prefixes. For example, each account’s capabilities (i.e. permissions) are stored in [$table_prefix]usermeta table on the row where meta_key is [$table_prefix]capabilities.

So if your table prefix is “ASD_” then that table row’s meta key is not ‘wp_capabilities’ but ‘ASD_capabilities’.

The same applies for quite a few other usermeta fields, options fields, etc.


However, in my case this was not the problem. I reviewed the db table fields and everything looked fine. So the next step in debugging the problem was disabling all plugins – the client had installed some suspicious plugins from CodeCanyon and I assumed they were causing this issue. But this didn’t give me any results either.

Next, I wanted to make sure that it actually is an issue with the database, so I wrote a simple function which filters all capability checks and returns true.

// This goes to your theme's functions.php
function codelight_all_permissions( $allcaps, $cap, $args ) {
    $allcaps[$cap[0]] = true;
    return $allcaps;
add_filter( 'user_has_cap', 'codelight_all_permissions', 0, 3 );

After adding this code to the theme, I was able to log in, which confirmed my suspicion that it was an issue with the database. A quick look in WP admin revealed that something had deleted all user roles and there was only one role remaining (which was called something like Wholesale Customer).

In order to restore the default roles, I re-added the default content to wp_options table, wp_user_roles option (this has not changed between WP v4.9.x and v5.4.x)


.. which fixed the issue.

In the end, I suspect one of the Codecanyon plugins deleted all WP roles, but I didn’t bother figuring out the exact reason – the plugins contained 5000+ lines of very similar code with minor variations so it was rather difficult to read and not worth the time.


Indrek Kõnnussaar

I'm a veteran Wordpress developer, context-driven tester, security enthusiast and the mastermind behind Codelight. I love building stuff that works and fixing stuff that doesn't.

Write me directly

45 Responses to “Analyzing “You do not have sufficient permissions to access this page” error in WP admin”

  1. Rub

    Thanks, your solution helped me restoring the default roles on user_roles option.
    So one of the plugin I install and deleted made this problem?
    Why someone make such a thing?

  2. Lior

    Thanks you, it worked!

  3. Sean

    Saved my butt. Thanks.

  4. angel alfaro

    thanks, for your work, i solved my problem

  5. dragomir

    Great. Helped me a lot.


  6. Irish

    Thanks a lot! I’ve been looking for fix when I thought its the plugin whew!

  7. Gary Donovan

    Thanks heaps.

  8. Jeroen

    You made my day!! After visiting many useluss forums this resolved my problem.

  9. Jay

    Awesome, finally it worked.. thanks a lot

  10. ken

    You’re the man bro! saves m tons of time for your code! very helpful!

  11. Seun

    Thanks for the post, but in my own case what worked for me was just to change the wpje_user_roles to wp_user_roles inside the wp_options table.

  12. Samirah Mamode

    YOU saved my hardwork of 6month.. God bless you!

  13. Jerry

    This helped me, albeit one minor work-around.

    I reset the user roles, but I noticed my login user had a slightly different array for wp_capabilities.

    Somehow, it had the value = a:1:{s:13:”administrator”;b:1;}

    I changed the last two to “a:2” and it worked! Thanks!

  14. Antonio Mª Martín

    Muchas gracias. Para mí ha sido la solución. He aplicado las reglas por defecto que usted indica (mediante el método de copiar y pegar el código que usted proporciona en esta página web) y también sirven para WP 4.5.3

  15. roie

    Thank you very much! Searched for hours before coming to this post.

  16. Cyber

    You are the MAN! Thanks, this worked like a charm after hours of research.

  17. Dee

    You are AMAZING!!! I never comment on things (serial lurker), but I just had to write to THANK YOU SO MUCH for your help with this.

    I was unable to access my /wp-admin dashboard (I could access all the other admin pages though) for like 6 months or longer and had no idea why.

    I would search periodically for hours for solutions and then get tired of searching and give up, only to try again a few days or weeks later -but finally, thanks to you I can finally access everything.


  18. ZeleRoman

    Thanks, it helped a lot!

  19. Muneeb


    Thanks for the article, i was able to login by adding filter, but restoring capabilities and removing filter gives the same error…..what i understood, filter hook by-pass the permissions and allow user to login, correct?

    • Indrek Kõnnussaar

      Yes, the filter basically bypasses all permissions checks, which means that the error is probably in your database. Perhaps try getting the wp_user_roles contents from a clean WP install that matches your WP version?

  20. Abdul Alim

    Thanks a tonne! This, and only this worked for me. You are incredible!

  21. Al

    Nicely done! Thanks for making me look very clever lol

  22. JB

    You’re the best, man. This solution fixed it

  23. Valentin

    Thank you sir, nice hack that restored the wpadmin area where I did “make order” in those evil plugins that caused the problem in first place (I also mention that renaming the plugin folders, all of them, did not solved the problem since the culprit was the database).
    Have a great day ! Thanks a lot !

  24. Manuel Herrera


    Dont work for me, still dont get wp-admin access

    • Indrek Kõnnussaar

      Can you clarify what you did exactly?

  25. Lerry

    Adding the function to functions.php and changing “b:1” to “a:2” in user_capabilities fixed it all.
    Thank you.

  26. Timo

    You saved my life ! Thank you sooooo much for this !

  27. Danielius

    You saved my ass, Indrek. Thanks! 🙂

    (I logged in using the functions code you wrote, saw that everyhing is roleless, installed “role editor” plugin and reseted everything with it.)

  28. Pablo

    Indrek, The Master of the masters!
    Amazing trick, it was like magic!
    Thank you, you ended 4 days of search in forums and to attempts several solutions with no luck.
    many thanks!! You rock! \m/ \m/ \m/

  29. Sitezilla Webdesign

    You are a true god! Thank you so much. I have been struggling with this for many hours. You’re solution made this work again. Our customer is able to login again. Instead of the wholesale role we only saw the wpseo_manager role.

  30. Isaac

    Thank you soo much my dude you saved my life.

  31. Toku

    Thanks Indrek Kõnnussaar!
    I’ve been battling with this issue for 6 days!
    God bless you man!

  32. Tom van der wal

    Thanks, even in 2018, this solved my problem and the code was still oke for me!

  33. Hendrik-Jan

    Thank you for your solution. The function worked perfect and so I could adjust the database in your way.


  34. Shakira

    This has resolved my issue, thank you 🙂

  35. Megavado

    You are the one. Saved my “life”

  36. Liana

    You are genius! Thank you! I spent a week to try so many things, only your solution worked.

  37. Robin

    Contributing my experience: should you get this error just after switching from HTTP to HTTPS, then your hosting provider probably uses SSL offloading.

    Add the following to your wp-config.php, but make sure that these lines are *above* the require of wp-settings.php:

    if ($_SERVER[‘HTTP_X_FORWARDED_PROTO’] == ‘https’)

    if (isset($_SERVER[‘HTTP_X_FORWARDED_HOST’])) {

  38. Carlos Martínez

    Love you. Thanks so much!

  39. Evandro

    Thank you so much. I didn’t know what to do anymore!

  40. Ricardo de Jesús Pelcastre Cervantes

    Solve the problem as you indicated.

    The question is, can the same problem happen again within the same code.

    Thank you

    • Indrek Kõnnussaar


  41. Jamal

    Worked for me

  42. Ahmet Parıltı

    thank you so much. that was what i was looking for


Leave a Reply

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now