How to Fix the “Sorry, You Are Not Allowed to Access This Page” Error in WordPress
--
You are visiting this page because you just encountered this error “Sorry you are not allowed to access this page” and you cannot access your WordPress admin dashboard or some of the pages. It's really a nightmare when this happened. Or it was for me as I was stuck out of the admin portal and I spent a lot of time going through the answers on the web for it.
Luckily there are many solutions to fix this as this error is quite generic and does not generally happen due to a single cause. In this blog firstly I will tell you what was the solution that fixed my issue and then I will list out some other fixes as well.
The solution that worked for me
In my case somehow my administrative privileges were removed from the database and to fix that I used phpmyadmin.
For that look for the wp_users table in PHPMyAdmin
Look for your user record and copy the ID of it. Then go to the wp_usermeta table and look for the record that has meta_key wp_capabilies and with the user_id that you have copied in the previous step
If you have Administrator privileges, the meta_value in this row will read:
a:1:{s:13:"administrator";s:1:"1";}
In my case the record was not at all there so I manually inserted it with my user_id. In some cases the admin value can be different so just edit and past this record as it is
Refresh the admin portal and you will be in.
Some Other Solutions
1. Restore Backup
The easiest and fastest solution would be to just restore your previous latest backup when the website was working fine and you are good to go.