BuddyDev

Search

[Resolved] Hide BuddyPress members directory from non logged users(non members)

  • Participant
    Level: Guru
    Posts: 900
    Tosin on #21097

    Hello,

    How can I redirect your code to the buddypress registration page instead of 404 error page

     /**
     * Hide Members Directory from non members(not logged in users)
     */
    function buddydev_hide_members_directory_for_non_members() {
        if ( bp_is_members_directory() && ! is_user_logged_in() ) {
            bp_do_404();
            load_template( get_404_template() );
            exit( 0 );
        }
    }
     
    add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_for_non_members' ); 
  • Participant
    Level: Guru
    Posts: 900
    Tosin on #21098

    I think I found a solution I got it to work for both members directory page and single members page with this code.

     /**
     * Hide Members Directory and single members page from non members(not logged in users)
     */
    function buddydev_hide_members_directory_for_non_members() {
        if ( bp_is_members_directory() || bp_is_user() ) {
            if (!is_user_logged_in() ) {
                 bp_core_redirect( bp_get_signup_page() );
    exit;
            }
        }
    }
     
    add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_for_non_members' ); 
  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #21102

    Hi Tosin,
    Yes, That will work 🙂

    You may remove the ‘exit’ line as ‘bp_core_redirect’ does it for us. Still, keeping it is not going to harm.

    Regards
    Brajesh

The topic ‘ [Resolved] Hide BuddyPress members directory from non logged users(non members)’ is closed to new replies.

This topic is: resolved