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

Is it possible to lock all new and existing WordPress posts to one specific author?

programmeradmin1浏览0评论

I have a case where there will be multiple users writing, editing, and publishing posts. All these posts should always have the same user as the author, a catch-all user if you will.

Is it possible to programmatically set the author for every new post to this user, no matter which user is logged in? I think I will be able to figure out how to remove the ability to change author on posts, but I am kind of stuck on this one question.

If someone could point me in the right direction I would be very thankful!

I have a case where there will be multiple users writing, editing, and publishing posts. All these posts should always have the same user as the author, a catch-all user if you will.

Is it possible to programmatically set the author for every new post to this user, no matter which user is logged in? I think I will be able to figure out how to remove the ability to change author on posts, but I am kind of stuck on this one question.

If someone could point me in the right direction I would be very thankful!

Share Improve this question asked Apr 20, 2020 at 5:41 TASanTASan 421 silver badge9 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

This is untested, but you could use the wp_insert_post_data filter to change the post author to a specific value whenever a post is inserted or updated:

add_filter(
    'wp_insert_post_data',
    function( $data ) {
        if ( 'post' === $data['post_type'] ) {
            $data['post_author'] = 2; // Replace with desired author's user ID.
        }

        return $data;
    }
);

Just be aware that if posts are being created by users who do not have the edit_others_posts capability, such as Authors and Contributors, then they will experience unusual behaviour, because they will not have permission to do anything with the post once it has been saved. So they could see an error when the post page reloads after pressing Publish, for example.

发布评论

评论列表(0)

  1. 暂无评论