Today I received an error on WordPress that was somewhat interesting. I wanted to post my solution to one of the WordPress forums (many were started due to this error), but all I found were already closed with other solutions that didn’t work for me.
Here was the scenario:
There’s a site I’m debugging that is really slow and I’m tracking down where the trouble is. I decided, for fun, to create a clean install of WordPress with a clean and fresh database setup. Then the plan was to ONLY import data from the old database that was still relevant. One obvious table that is still relevant is wp_users.
In the process of setting up the WordPress site from scratch, I was prompted for the admin account, and I created my typical account username and password. Before importing the whole users table, I remembered that this username would already be in the existing table but with a different ID. To avoid confusion, I removed the INSERT statement from the export file that would import my user account, then just changed the ID (wp_users.ID) of my account in the new table to match the ID it had in the old table That way any posts I had done would still be associated with me (the IDs would match up). Then I imported the table.
Suddenly I had the error: You do not have sufficient permissions to access this page
So, here’s what happened: There are a lot of options set up for WordPress users in another table: wp_usermeta. In this clean install, I had two rows of options, and each row contains my user id. When I created this account, it was the first one in the fresh install, so the user ID was 1. When I changed my ID in wp_users, my user account could no longer sync up with the options. Easy, right? Should have thought of it ahead of time, but I missed it. Anyway, I simply updated the rows to set wp_usermeta.user_id = wp_users.ID.