I faced a surprise issue today. When I was working in the wp-admin (WordPress admin panel) of my WordPress based website, suddenly it logged me out and throw me an error “Sorry, you are not allowed to access this page”.
I tried in different browser but after logging in, it gave me a permission denied error. Though I am the administrator user of the website. After wasting many hours, check out how I fixed this error.
Changes that I made before the error occurred?
The only thing that I did before was update a few plugins. Plugins were Pretty Link, Spectra, and Yoast SEO. I don’t know which plugin has caused the issue. Even I am not sure that it was caused due to the plugin update.
I tried to disable the plugin, but still no recovery
I tried to disable the plugins that I had updated by renaming the plugin folders (I had no access to the admin panel), but still no luck. I tried to rename the whole plugin folder, but the error was still there. Now one thing was sure: plugin files were not causing the error. Actually, it was a user permission issue.
How I fixed the “You are not allowed to access this page” error
To check the user’s permissions, I opened the MySQL database through the cPanel provided by the hosting company. And found that wp_capabilities meta key in user_meta table was not available for the admin user.
Now the question is that who deleted this meta key? Till now this question is unanswered. But any way finally I found the issue and fixed it by adding this meta key in the database.
if you have different prefix than default “wp”. then use your prefix. Following are the possible value for different user types.
Fixed the permission issue but now there was new problem
After adding the wp_capabilities the original problem had been fixed, and admin panel can be accessed. But now a new problem arose. I was not able to access the post editor. It was showing me like the below screenshot.
Insert block icon was disabled for Gutenberg editor, I was not able to insert a new block and all previously inserted block in old posts were also missing. Title and content fields are just simple text fields without any formatting or block.
I tried to open the post in the classic editor. But it was also showing the source HTML editor. TinyMCE toolbar was missing.
How I fixed the disabled block insert button issue?
Surely, it was also a user permission issue, but I was unable to find the solution. I searched it all over the internet, but there was no clue. I tried everything, like deactivating the plugins, reinstalling the WordPress update, etc., without any luck.
Randomly, I got the idea to check the user profile in the admin panel. I tried to save the profile, but it gave me the error that the nick name was empty. Then I filled in the nickname and saved it.
Surprisingly, this resolved the problem.
So, in the admin panel click on the right top corner where username and user icon is appearing. Click on the edit profile menu item. And it will bring up the user profile as like the below screenshot. Now you can edit the profile. In my case the nickname field which is a required field was empty.
I don’t know how it get empty. But anyway finally I managed to fix the issue.
It was a suspicious thing, So I scanned the WordPress for any hacking attempt, but didn’t found any suspicious file or plugin. I am using the WordFence plugin for security purpose.
In the end I fixed the “Sorry, You are not allowed to access this page” error by adding wp_capabilities user meta field in the user_meta table in WordPress database. And managed to fixed the post editor issue where insert block editor button was disabled by adding the nickname of the user and saving the profile again. Hopefully, anyone else facing the same issues will find this post helpful.