Skip Navigation

[Resolved] Using Access control to limit access to a content template for a CPT

This support ticket is created 4 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 19 replies, has 2 voices.

Last updated by Gerard 4 years, 6 months ago.

Assisted by: Minesh.

Author
Posts
#1632191

It's possible that using the "Switch User" plugin is not a good way to test..

#1632201

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I've again adjusted the code as per your requirement to the custom code section.

add_filter( 'wpv_filter_force_template', 'prefix_fixed_content_for_visitors', 99, 3 );
    
function prefix_fixed_content_for_visitors( $template_selected, $id, $kind ) {
  global $current_user;
  global $post;
   if(is_singular("profile")) {
     
    if((in_array('student',$current_user->roles) and  $post->post_author != $current_user->ID) and (!in_array('administrator',$current_user->roles) or !in_array('manager',$current_user->roles))
      ){
           
       $template_selected = 1158;
    }
   }
    return $template_selected;
}

Can you please confirm it works now.

#1632243

It seems to work perfectly! Thank you very much for your patience and help!

I had tried that exact way myself, but looking at your code, I think I'd put the ending }  at the wrong place for the outside loop to check for the profile.

Thanks a million!

#1632251

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Great - please feel free to mark resolve this ticket.

#1632261

My issue is resolved now. Thank you!