最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp admin - Update to functions.php not showing in dashboard

programmeradmin4浏览0评论

Some time ago, I added the following lines to my custom theme's functions.php file, in order to allow authors on my site to edit posts and drafts from all users:

function add_theme_caps() {
$role = get_role( 'author' );
$role->add_cap( 'edit_others_posts' );
}
add_action( 'admin_init', 'add_theme_caps');

It worked as expected. However, I now no longer want that functionality. I have removed those lines from my functions.php file, but authors can still edit all of the posts on the site. It's been a few hours since I updated the functions file in my theme's root folder and I have done hard reloads and reloads emptying the browser cache, but there is still no change.

Any ideas on what the problem could be? Could it be that those lines of code changed some other central Wordpress file? Or am I missing something by simply removing the code?

Some time ago, I added the following lines to my custom theme's functions.php file, in order to allow authors on my site to edit posts and drafts from all users:

function add_theme_caps() {
$role = get_role( 'author' );
$role->add_cap( 'edit_others_posts' );
}
add_action( 'admin_init', 'add_theme_caps');

It worked as expected. However, I now no longer want that functionality. I have removed those lines from my functions.php file, but authors can still edit all of the posts on the site. It's been a few hours since I updated the functions file in my theme's root folder and I have done hard reloads and reloads emptying the browser cache, but there is still no change.

Any ideas on what the problem could be? Could it be that those lines of code changed some other central Wordpress file? Or am I missing something by simply removing the code?

Share Improve this question asked Apr 26, 2017 at 5:26 JCMJCM 311 silver badge8 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

It looks like I have solved my own problem. I'm guessing that a function like that creates a permanent change, regardless of whether the function remains in the functions.php file. So, to fix this, I just added a new function reversing this adding. Here is that function:

function remove_theme_caps() {
$role = get_role( 'author' );
$role->remove_cap( 'edit_others_posts' );
}
add_action( 'admin_init', 'remove_theme_caps');

This has restored the default setting of not allowing authors to edit other users' posts. And after uploading my functions file with this code, I have since deleted this section of code and re-uploaded my functions file, and the change (back to the default setting) has remained. So, problem solved!

add_cap will write to the database, this is not an operation you want to run every single time. You should hook this in very specific situations. ( most common would be register_activation_hook )

发布评论

评论列表(0)

  1. 暂无评论