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 |1 Answer
Reset to default 2That 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
版权声明:本文标题:How to clear capabilities cache? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736295621a1929608.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
list_users
notlist-users
– Tom J Nowell ♦ Commented Sep 4, 2024 at 14:59