Hi,
How to change course news page permission only to course student? I have set the permission on setting but not working. The news page still accessible to anyone who has direct link.
Please refer this:
http://prntscr.com/i5xh8s
This is my setting:
http://prntscr.com/i5xin3
News tab not visible to non-course student as it should. Refer:
http://prntscr.com/i5xj7p
But the course news page is still accessible to anyone with link.
Please help. Thank you.
This reply has been marked as private.
Hi,
please paste the following code in wp-admin>plugins>editor>wplms customizer plugin
add_action( 'template_redirect', 'check_course_news' );
function check_course_news(){
if( !is_singular('news') ){
return;
}
if( !is_user_logged_in() ){
wp_redirect( home_url() );
exit();
}
$user_id = get_current_user_id();
$course_id = get_post_meta(get_the_ID(),'vibe_news_course',true);
if(!empty($course_id) && is_numeric($course_id)){
$check = bp_course_is_member( $course_id,$user_id );
if(!$check){
wp_redirect( home_url() );
exit();
}
}
}
Works like charm. Thank you!