Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)

  • kpkreative
    Participant

    @kpkreative

    Just incase it helps anyone else, the following code resolved the issue for me:

    //Hide for non-logged-in users (public visitors)
    add_action( ‘init’, function() {
    if ( ! is_user_logged_in() && !bp_is_members_directory() && bp_is_user() ) {
    bp_core_redirect( site_url(‘/content-restricted/’) );
    } else {
    // Do nothing.
    }
    } );


    kpkreative
    Participant

    @kpkreative

    Hi Michael,

    Thank you so much for sharing the code for the redirect and the great source.

    There must be something on my website that is conflicting as I’ve added the code and the redirect still goes to the homepage rather than the custom link.

    I want the non logged in user to still see the directory, though not the single profiles, so I referenced the page below in the code

    My code is as follows:
    function ps_guest_redirect() {
    global $bp;
    if ( bp_is_user() ) {
    if(!is_user_logged_in() and !bp_is_register_page() and !bp_is_activation_page() and !is_page(‘member-directory’)) {
    wp_redirect(‘https://websiteurl/content-restricted’);
    exit;
    }
    }
    }
    add_filter( ‘get_header’,’ps_guest_redirect’,1);


    kpkreative
    Participant

    @kpkreative

    I tried something like the following without success:

    //Hide for non-logged-in users (public visitors)
    function bp_logged_out_page_template_redirect() {
    if( ! is_user_logged_in() && bp_is_user() ) {
    wp_redirect( home_url( ‘/content-restricted/’ ) );
    exit();
    }
    } add_action( ‘template_redirect’, ‘bp_logged_out_page_template_redirect’ )


    kpkreative
    Participant

    @kpkreative

    Hi Evie,

    Do you have an example of working code for this with regards to if non logged in user tries to view a members profile, redirect them to a custom url?

    Thanks @Michael w/regards to plugin reference. I was hoping to achieve this without the use of another plugin. The one referenced hasnt been updated in sometime and i am a bit sceptical about that.

    Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
Skip to toolbar