Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide BP Components to Non Members Except Specific URL


  • zaino
    Participant

    @zaino

    I have successfully implemented the solution described in a closed thread https://buddypress.org/support/topic/hiding-groups-activity-members-list-to-non-members/ about how to hide BP components to non logged in users. The code is below and it works great. What I am looking to do is to make an exception for a single, specific member URL that will be accessible to all users.

    In summary:

    1. Hide all BP components to non logged in users [achieved]
    2. All non logged in users to see mysite.com/members/member-x

    This is the code used for the first part in. Any help would be greatly appreciated.

    /* Prevent logged out users from accessing bp components */
    function nonreg_visitor_redirect() {
    global $bp;
    if ( bp_is_activity_component() || bp_is_groups_component() || bp_is_members_component() ) {
    if(!is_user_logged_in()) { //just a visitor and not logged in
    wp_redirect( get_option(‘siteurl’) . ‘/register’ );
    }
    }
    }
    add_filter(‘get_header’,’nonreg_visitor_redirect’,1);

    ?>

    WP version 4.8.0
    BP version 2.12.12

Viewing 1 replies (of 1 total)

  • Henry Wright
    Moderator

    @henrywright

    In your code, just before global $bp;, try adding this:

    if ( 1 == bp_displayed_user_id() ) {
        return;
    }

    Where 1 is the ID of the member you would like to exclude.

Viewing 1 replies (of 1 total)
  • You must be logged in to reply to this topic.
Skip to toolbar