Common causes
- The table prefix in wp-config.php was changed but the prefix in wp_usermeta and wp_options keys was not
- The administrator role or wp_capabilities meta was removed or corrupted
- A deactivated or deleted plugin's admin page is still bookmarked
- A security or role-editor plugin removed capabilities
- Multisite: the user is not a network admin for network-level pages
How to fix it
- Check whether the page still exists. If the URL is admin.php?page=something from a plugin you removed, the page is gone. Go to the main Dashboard instead.
- Fix the prefix after a change. If you changed $table_prefix, update the option_name wp_user_roles in the options table and the meta_key values wp_capabilities and wp_user_level in usermeta to use the new prefix.
- Restore the administrator role. Use WP-CLI: wp user set-role yourname administrator. If roles are completely missing, wp role reset --all restores the default roles.
- Disable role and security plugins. Rename the folders of role-editor or security plugins in wp-content/plugins to see if access returns. Then review their settings.
- Check multisite permissions. On multisite, network admin pages require super admin. Grant it with wp super-admin add yourname.
SQL to update prefixed keys after changing wp_ to wpnew_
UPDATE wpnew_options SET option_name = 'wpnew_user_roles'
WHERE option_name = 'wp_user_roles';
UPDATE wpnew_usermeta SET meta_key = REPLACE(meta_key, 'wp_', 'wpnew_')
WHERE meta_key IN ('wp_capabilities', 'wp_user_level', 'wp_user-settings', 'wp_user-settings-time', 'wp_dashboard_quick_press_last_post_id'); How to stop it happening again
- Back up the database before changing the table prefix
- Use a tool that rewrites prefixed keys, not only table names
- Keep at least two administrator accounts
- Review role-editor plugin changes carefully