This topic has 2 replies, 2 voices, and was last updated 8 years by Radu.

  • Author
  • #119989
     kiskuba
    Participant

    Hi,

    How can i set a link to redirect logged in users to membership level when they have no access ? Right now they a landing on homepage.

    Regards

    Jakub

    #120115
     Radu
    Moderator

    Hi,

    Try with this snippet

    COPY CODE
    
    add_action( 'template_redirect', 'my_membersip_restrict' );
    
    function my_membersip_restrict() {
        global $pmpro_pages, $post;
    
        if ( is_user_logged_in() && !pmpro_hasMembershipLevel() ) {
            if (isset($post->ID) && !in_array($post->ID, $pmpro_pages)) {
                wp_redirect( pmpro_url() );
            }
        }
    }
    

    Cheers
    R.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
    #120116
     Radu
    Moderator

    If you want to redirect the visitors to certain page use this

    COPY CODE
    
    add_action( 'template_redirect', 'my_membersip_restrict' );
     
    function my_membersip_restrict() {
        global $pmpro_pages, $post;
     
        if ( is_user_logged_in() && !pmpro_hasMembershipLevel() ) {
            if (isset($post->ID) && !in_array($post->ID, $pmpro_pages)) {
                wp_redirect( 'http://www.example.com/mypage', 301);
            }
        }
    }
    

    REplace http://www.example.com/mypage with your url

    Cheers

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution
Viewing 3 posts - 1 through 3 (of 3 total)

The forum ‘Bugs & Issues’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?