Restrict non-logged in users to see free units

Home Forums Legacy Support Support queries How-to & Troubleshooting Restrict non-logged in users to see free units

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #209960
    vincent-r
    Participant
    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
    #210065
    logan
    Member
    This reply has been marked as private.
    #210071
    vincent-r
    Participant
    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
    #210229
    logan
    Member
    Hello, i am sorry that is not available in wplms yet. you can create a custom feature request for this.
    #210235
    vincent-r
    Participant
    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
    #210243
    logan
    Member
    Thanks for letting me know, closing this topic.
Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Restrict non-logged in users to see free units’ is closed to new replies.