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 badges1 Answer
Reset to default 0I 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' );