BuddyDev

Search

[Resolved] redirecting not logged in users to login IF accessing buddypress pages (profile)

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23532

    Hey there,

    What php code do I need to add in the buddypress custom to redirect not logged in users to login IF accessing buddypress pages (such as profile and site-wide activity)?

    Thank you

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #23540

    Hi Kristian,
    Thank you for the question.

    You may use the following code.

    
    
    /**
     * Restrict access to BuddyPress for non logged users completely.
     */
    function buddydev_restrict_bp_pages() {
    	// If Logged in
    	// Or not on BuddyPress pages
    	// Or it is register/activation page
    	// Do not restrict.
    	if ( is_user_logged_in() || ! is_buddypress() || bp_is_register_page() || bp_is_activation_page() ) {
    		return;
    	}
    
    	bp_core_redirect( wp_login_url() );
    }
    
    add_action( 'bp_template_redirect', 'buddydev_restrict_bp_pages' );
    
    

    Hope that helps.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 46
    Kristian Yngve on #23568

    Thank you Brajesh!

    By the way, only yours works when the Youzer devs offered their code.

    You really are a master in what you do.

    Thank you so much sir.

    It’s such an honor to know to you :,)

    Kristian

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #23591

    Hi Kristian,
    Thank you for the kind words. I am honoured.

    I am thankful to have members like you.

    Have a great day.
    Brajesh

The topic ‘ [Resolved] redirecting not logged in users to login IF accessing buddypress pages (profile)’ is closed to new replies.

This topic is: resolved