So far what i achieved.
- Created user role using user role editor
- Using ACF pro, user relation field, i am displaying all the users related to "pro access" in taxonomy section.
- Created Two taxonomies and two users and tagged them to check the results
Below is the code which checks wether current user has access to taxonomy tagged or not.
$current_user = wp_get_current_user();
if(in_array('project',$current_user->roles)){
$pro_cats = get_terms('pro-category','hide_empty=0');
//print_r( $pro_cats);
$allowed_cats = array();
if(is_array($pro_cats) && count($pro_cats)){
foreach($pro_cats as $pro_cat){
$auth_users = get_field('authorized_users', 'pro-category_'.$pro_cat->term_id);
if(is_array($auth_users) && count($auth_users)){
foreach($auth_users as $auth_user){
if($auth_user['ID'] == $current_user->ID){
$allowed_cats[] = $pro_cat;
$link = get_bloginfo( 'url' ) . '/pro-category/' . $pro_cat->slug . '/';
echo 'Name - '.$pro_cat->name.' - link -'.$link.'<br />';
//print_r( $pro_cat->name);
//print_r( $pro_cat->slug);
}
}
}
}
}
}
So from the above, when user logs in, i can see what taxonomy he is tagged in.
Now, I wanted to put restriction on taxonomy archive / single posts. So when a user is logged in, he must access only taxonomies related to his profile.