Skip Navigation

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

This support ticket is created hace 4 años, 6 meses. 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.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

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)

Este tema contiene 19 respuestas, tiene 2 mensajes.

Última actualización por Gerard hace 4 años, 6 meses.

Asistido por: Minesh.

Autor
Mensajes
#1632191

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

#1632201

Minesh
Supporter

Idiomas: Inglés (English )

Zona horaria: 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

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Great - please feel free to mark resolve this ticket.

#1632261

My issue is resolved now. Thank you!