Hi,
On my homepage, I decided to feature directly units so that users can directly access free units content.
I don't want non-logged in users to access these free units. I tried the code I found on this webpage (
https://wplms.io/support/knowledge-base/restricting-non-logged-in-user-to-see-the-free-unit/) but it doesn't work. Can you help me please?
Thanks,
Vincent
This reply has been marked as private.
Hi Logan,
That's not exactly what I had in mind. Ideally, when a non logged-in user tries to access the unit content thanks to the URL, I would like to display a message: "Please log in to access this unit".
Is this doable?
Thanks!
Vincent
Hello,
i am sorry that is not available in wplms yet. you can create a custom feature request for this.
Managed to do it using this function:
add_filter( 'wp', 'f040925b_redirect', 0 );
function f040925b_redirect( $content ) {
global $post;
if(
(
$post->post_type == 'unit'
)
&&
!is_user_logged_in()
) {
wp_redirect( get_home_url() );
exit;
}
return $content;
}
Vincent
Thanks for letting me know, closing this topic.