admin管理员组

文章数量:1316666

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' );

本文标签: custom post typesConditional editing CPTusing editor39s role and author39s usermeta