You do not have permission to view this page (part 2)

Hi,

I had a similar problem last year and never solved it due to personal circumstances but have the same issue again.

I imported an existing website (in this case a woocommerce site) and when I try to go to the admin page I get forwarded to my accounts page after clicking the WP admin button in Local. When I then just type the address in the browser I do get forwarded to the back-end only to read: “You do not have permission to view this page”.

I now know what the problem is. I found it on this website: Fix : "Je hebt geen toestemming om deze pagina te bekijken" error in WP admin (in dutch) and it’s an error with the import of the wp-options table in the database. All user roles were deleted. I looked and indeed there is a whole bunch of stuff missing.

When I add this code to the functions.php of my theme:
// This goes to your theme’s functions.php
function codelight_all_permissions( $allcaps, $cap, $args ) {
$allcaps[$cap[0]] = true;
return $allcaps;
}
add_filter( ‘user_has_cap’, ‘codelight_all_permissions’, 0, 3 );

I can get back in.

The default roles could be restored by the following code overwriting the value in the database (in wp_options table the wp_user_roles option) :

a:5:{s:13:“administrator”;a:2:{s:4:“name”;s:13:“Administrator”;s:12:“capabilities”;a:62:{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:9:“add_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;}}}

However, I have no idea how to do that. Is there another solution? Or can someone tell me how to do this?

I am running Windows 11
Local version 9.2.3+6776

Hi @Martin1

Are you just trying to get back into the site? You can use the Site Shell function to create or edit a current admin user for example:

You could also try disabling plugins in Site Shell, or turning on One Click Login in the Local app as well will sometimes get around issues like this.

No, when I add this code to the functions.php of my theme:

function codelight_all_permissions( $allcaps, $cap, $args ) {
$allcaps[$cap[0]] = true;
return $allcaps;
}
add_filter( ‘user_has_cap’, ‘codelight_all_permissions’, 0, 3 );

I can get back in. But the problem is I shouldn’t have to add that. The wp_options table is nearly empty (somehow Local has trouble with importing it correctly) that’s why I need to add that code. I want to “refill” that table either by using the long code in my original post or another way. I am not sure how to use the code and I don’t know of another way.

Hi @Martin1,

Full Disclaimer … the kind of open-heart surgery you are inquiring about is really not recommended unless you have given up all hope and have fully accepted that the entire site is a total loss. You then need to be ok with breaking it even further as you turn this into a personal learning experience … and never do these techniques on a Production system. Plus, this is assuming you have already exhausted all other options like re-doing the full site import into a new local-site, etc, etc, etc.

The second thing to accept is that when something like this mis-behaves it is generally like a gremlin; you can safely assume that it is not alone and they are all up to no-good mischef. Even though you might successfully fix the first-obvious step, it generally leads to a rabbit hole of other never ending issues you did not know were waiting for you.

The third thing to accept is that even if it patched up … can you really trust it to be the foundation for ongoing future work to push to production. Probably not worth the risk. Hence, just be ok with knowing that this specific instance of the website that might be patched up, should be considered the last train for the night and at the end of the line, never to be used again the next day (as a metaphore). This patched up website instance should now be considered a learning and experimenting website.

Part 1 - The Specific wp_user_roles Record

(1) Visit the AdminerNeo database tool, once you have started up your LocalWP website.

(2) Visit the wp_options table, search for the specific wp_user_roles record and then click [Edit] link for that specific record.

(3) Paste the new content into the option_value field. Do not touch any other fied in this record. Click [Save] button.

Hint: Doing this kind of database record surgery can break your website in an instant. Be prepared to investigate all kinds of issues like hidden-characters, wrong back-ticks, different uni-code characters (minus vs dash, etc) … all because of where you copied the source text from, to past into the database record. A true plain text editor can be your best friend, even before you touch the database record.

Part 2 - The Whole wp_options Table.

Re-importing the whole wp_options table can get way too messy.

This is never really a recommended action for this type of open-heart surgery technique, as it contains more that a few site-wide specific values that are better to be set by following the official website import process; as it will do a way better job of making the changes needed.

Happy gremlin hunting … hope this helps. :vulcan_salute:

1 Like

Hello @johnlang86 ,

:slight_smile: I LOVE the Gremlin comparison (I am old enough to have seen the movies in the cinema/theatre) and I tried re-importing the site several times. Alas, no succes. I understand that it’s a risk but I don’t know of any other way so I will try this solution.

It IS strange that Local has problems with the wp_options table. It’s the second site it has problems with strangely enough.

Non the less, I thank you for taking the time to help and I’ll give it a go and see where it leads me.

LLAP

2 Likes

Thank you for the write up @johnlang86! :green_heart:

@Martin1 if you run into any other trouble keep us posted!

1 Like