admin管理员组

文章数量:1122846

I ran the following code on init:

 $author_role = get_role('author');
 $author_role->add_cap('manage_options');

That added the Settings menu at the left for a logged in Author. Then I removed the second line above and the Settings menu remains! I can reproduce this e.g. of 'list-users'. It seems WordPress is caching the capabilities. How do I clear this cache and end this frustrating behaviour?

wp_cache_flush();  

does not do anything in this case

Thanks

I ran the following code on init:

 $author_role = get_role('author');
 $author_role->add_cap('manage_options');

That added the Settings menu at the left for a logged in Author. Then I removed the second line above and the Settings menu remains! I can reproduce this e.g. of 'list-users'. It seems WordPress is caching the capabilities. How do I clear this cache and end this frustrating behaviour?

wp_cache_flush();  

does not do anything in this case

Thanks

Share Improve this question edited Sep 4, 2024 at 14:34 Justin Wylllie asked Sep 4, 2024 at 14:29 Justin WylllieJustin Wylllie 374 bronze badges 1
  • note it's list_users not list-users – Tom J Nowell Commented Sep 4, 2024 at 14:59
Add a comment  | 

1 Answer 1

Reset to default 2

That added the Settings menu at the left for a logged in Author.

Because the author role now has the required capabilities.

Then I removed the second line above and the Settings menu remains!

That's because role data is stored in dedicated tables the same way as user meta and posts. It's not like post type registration, it's more like post/user creation.

I can reproduce this e.g. of 'list-users'. It seems WordPress is caching the capabilities. How do I clear this cache and end this frustrating behaviour?

There is no cache, you would need to modify the role again with something like this:

$author_role = get_role('author');
$author_role->remove_cap('manage_options');

Or a CLI command such as this:

wp role reset author

本文标签: How to clear capabilities cache