I need to check if users have the exact roles for the purpose of allow users to edit each others posts if they have a same two roles.
One role 'X'
is a common one, and the other role 'Y'
is a unique one - I'm generating it dynamically based on a user meta value.
The second role is the main role for what I'm trying to do, grouping users and give them access to each others posts and the first role is the role associated to manage the targeted post type.
The problem now is: users can edit all others users with role X posts , no matter they have the role y or not .... what i need is , they can only edit when they have the both roles , not only one of them . this is the code:
function get_current_user_role() {
global $wp_roles;
$current_user = wp_get_current_user();
$roles = $current_user->roles;
$role = array_shift($roles);
return isset($wp_roles->role_names[$role]) ? translate_user_role($wp_roles->role_names[$role] ) : false;
}
$userRole = get_current_user_role();
$contributors = get_users(array('role'=> $userRole ));
$contributors_ids = array();
foreach ($contributors as $user) {
$contributors_ids[] = $user->ID;
}
$args = apply_filters( 'moe_cars_args', array(
'post_type' => 'cars',
'offset' => ( max( 1, get_query_var('paged') ) - 1 ) * $posts_per_page,
'orderby' => 'date',
'order' => 'desc',
"author" => implode( ',', $contributors_ids )
) );