When you see this kinda message, there are a few things that can go wrong, I won’t go into detailing all of them. I will be focusing precisely on one, but before I do that, let’s quickly check what could go wrong
- Wrong user role for the user that is signing in
- Upgrade to latest version of wordpress has gone wrong
- wp_options table got corrupted
- Your site is hacked
- Wrong file level permissions
- Missing role of an Administrator
- and gazilion others …
Let’s focus on point 6,
The missing administrator role
This can happen because of various reasons
- Faulty plugin
- Human error
- Corrupt wp_options table
So let see what we can do to restore it
wp_options table have a column called option_name, execute the follow MySQL statement to see if our wp_user_roles value is present or not
1 |
SELECT * FROM wp_options WHERE option_name='wp_user_roles'; |
This should return you a row with option_value which should be a long string.
If above query doesn’t return anything, then check your database backup, restore it locally (not on production server) and see what value this property had
If above query returned an option value which did not list “Administrator” in the awkwardly looking JSON string, then also refer to the back and see what value you had to restore it.
If your backup is missing, then you can temporarily use the folling query to restore access
1 |
INSERT INTO `wp_options` (`option_id`, `option_name`, `option_value`, `autoload`) VALUES (NULL, 'wp_user_roles', 'a:5:{s:13:\"administrator\";a:2:{s:4:\"name\";s:13:\"Administrator\";s:12:\"capabilities\";a:61:{s:13:\"switch_themes\";b:1;s:11:\"edit_themes\";b:1;s:16:\"activate_plugins\";b:1;s:12:\"edit_plugins\";b:1;s:10:\"edit_users\";b:1;s:10:\"edit_files\";b:1;s:14:\"manage_options\";b:1;s:17:\"moderate_comments\";b:1;s:17:\"manage_categories\";b:1;s:12:\"manage_links\";b:1;s:12:\"upload_files\";b:1;s:6:\"import\";b:1;s:15:\"unfiltered_html\";b:1;s:10:\"edit_posts\";b:1;s:17:\"edit_others_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:10:\"edit_pages\";b:1;s:4:\"read\";b:1;s:8:\"level_10\";b:1;s:7:\"level_9\";b:1;s:7:\"level_8\";b:1;s:7:\"level_7\";b:1;s:7:\"level_6\";b:1;s:7:\"level_5\";b:1;s:7:\"level_4\";b:1;s:7:\"level_3\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:17:\"edit_others_pages\";b:1;s:20:\"edit_published_pages\";b:1;s:13:\"publish_pages\";b:1;s:12:\"delete_pages\";b:1;s:19:\"delete_others_pages\";b:1;s:22:\"delete_published_pages\";b:1;s:12:\"delete_posts\";b:1;s:19:\"delete_others_posts\";b:1;s:22:\"delete_published_posts\";b:1;s:20:\"delete_private_posts\";b:1;s:18:\"edit_private_posts\";b:1;s:18:\"read_private_posts\";b:1;s:20:\"delete_private_pages\";b:1;s:18:\"edit_private_pages\";b:1;s:18:\"read_private_pages\";b:1;s:12:\"delete_users\";b:1;s:12:\"create_users\";b:1;s:17:\"unfiltered_upload\";b:1;s:14:\"edit_dashboard\";b:1;s:14:\"update_plugins\";b:1;s:14:\"delete_plugins\";b:1;s:15:\"install_plugins\";b:1;s:13:\"update_themes\";b:1;s:14:\"install_themes\";b:1;s:11:\"update_core\";b:1;s:10:\"list_users\";b:1;s:12:\"remove_users\";b:1;s:13:\"promote_users\";b:1;s:18:\"edit_theme_options\";b:1;s:13:\"delete_themes\";b:1;s:6:\"export\";b:1;}}s:6:\"editor\";a:2:{s:4:\"name\";s:6:\"Editor\";s:12:\"capabilities\";a:34:{s:17:\"moderate_comments\";b:1;s:17:\"manage_categories\";b:1;s:12:\"manage_links\";b:1;s:12:\"upload_files\";b:1;s:15:\"unfiltered_html\";b:1;s:10:\"edit_posts\";b:1;s:17:\"edit_others_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:10:\"edit_pages\";b:1;s:4:\"read\";b:1;s:7:\"level_7\";b:1;s:7:\"level_6\";b:1;s:7:\"level_5\";b:1;s:7:\"level_4\";b:1;s:7:\"level_3\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:17:\"edit_others_pages\";b:1;s:20:\"edit_published_pages\";b:1;s:13:\"publish_pages\";b:1;s:12:\"delete_pages\";b:1;s:19:\"delete_others_pages\";b:1;s:22:\"delete_published_pages\";b:1;s:12:\"delete_posts\";b:1;s:19:\"delete_others_posts\";b:1;s:22:\"delete_published_posts\";b:1;s:20:\"delete_private_posts\";b:1;s:18:\"edit_private_posts\";b:1;s:18:\"read_private_posts\";b:1;s:20:\"delete_private_pages\";b:1;s:18:\"edit_private_pages\";b:1;s:18:\"read_private_pages\";b:1;}}s:6:\"author\";a:2:{s:4:\"name\";s:6:\"Author\";s:12:\"capabilities\";a:10:{s:12:\"upload_files\";b:1;s:10:\"edit_posts\";b:1;s:20:\"edit_published_posts\";b:1;s:13:\"publish_posts\";b:1;s:4:\"read\";b:1;s:7:\"level_2\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:12:\"delete_posts\";b:1;s:22:\"delete_published_posts\";b:1;}}s:11:\"contributor\";a:2:{s:4:\"name\";s:11:\"Contributor\";s:12:\"capabilities\";a:5:{s:10:\"edit_posts\";b:1;s:4:\"read\";b:1;s:7:\"level_1\";b:1;s:7:\"level_0\";b:1;s:12:\"delete_posts\";b:1;}}s:10:\"subscriber\";a:2:{s:4:\"name\";s:10:\"Subscriber\";s:12:\"capabilities\";a:2:{s:4:\"read\";b:1;s:7:\"level_0\";b:1;}}}'); |
Now try to login again, if administrator role was missing, you would’ve been redirected to /my-account page of your website or the website home page.
Couple of other points,
Check if your admin user has administrator capabilities,
1 |
SELECT * FROM wp_usermeta WHERE user_id = 1 AND meta_key = 'wp_capabilities'; |
I am assuming that your default user have an ID of 1. Check if the value of meta_value property has something like this as a value
a:1:{s:13:"administrator";b:1;}
If above is not sighted, the do this to have it added
1 |
UPDATE wp_usermeta SET meta_value='a:1:{s:13:"administrator";b:1;}' WHERE umeta_id=REPLACE_WITH_META_ID LIMIT 1; |
make sure to replate REPLACE_WITH_META_ID with your meta_id that corresponds to meta_key = ‘wp_capabilities’
Also make sure that meta_key = ‘wp_user_level’ for your user has a value of 10.
IF everthing fails
There are several hacks that can be performed on wordpress core to allow temporary admin access to your user. I generally mess up with /wp-includes/capabilities.php
In this file there is a function called current_user_can
1 2 3 4 |
function current_user_can( $capability, ...$args ) {<br /> $current_user = wp_get_current_user();<br /> if ( empty( $current_user ) ) {<br /> return false;<br /> } // PLEASE NOTE THAT USER ID OF 1 IS ASSUMED TO BE YOUR ADMIN<br />// add thE line below. please note that you upgrade wordpress, this line will go away. this is to just allow you the temporary access to the admin dashboard <br /> if(get_current_user_id() == 1) return true; |
I know that to the wordpress purists, above point may sound crazy, but that’s just one way of doing it.
I hope this helps
Leave a Reply