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

custom post types - Conditional editing CPT - using editor's role and author's usermeta

programmeradmin1浏览0评论

I have created a custom post type.

Each author is attributed to a editor group when her/his account is created. This is save on the author's user meta

I created two roles with administrator capabilities, one for each editor group.

I want to allow (or deny) the editors to edit the posts based on their role and on the author's user meta.

Where can I begin?

I have created a custom post type.

Each author is attributed to a editor group when her/his account is created. This is save on the author's user meta

I created two roles with administrator capabilities, one for each editor group.

I want to allow (or deny) the editors to edit the posts based on their role and on the author's user meta.

Where can I begin?

Share Improve this question asked Oct 29, 2020 at 18:48 drilippidrilippi 314 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

I manage to filter the posts, this seems to be enough for this project

function remove_notallowed_authors( $query ) {
    $user = wp_get_current_user();

    if ( in_array( 'editor_group_role', (array) $user->roles ) ) {
        $user_ids = get_users( [
            'role'   => 'user_role_that_posted',
            'fields' => 'ID'
        ] );

        $query->set( 'author__in', $user_ids );
    }
    
}
add_action( 'pre_get_posts', 'remove_notallowed_authors' );
发布评论

评论列表(0)

  1. 暂无评论