Get 15% off on all our plugins, themes and memberships till 4th December. Use coupon: BLACKFRIDAY2021.

BuddyDev

Search

[Resolved] Buddypress group is not member redirect

  • Participant
    Level: Initiated
    Posts: 12
    simon on #41063

    Hi is there a way that if a user is not a member in the group when they click the group from the group listing (eg “https://www.domainname.com/groups/” ) it will redirect to a certain page?

    Thanks in advance.

  • Keymaster
    (BuddyDev Team)
    Posts: 19833
    Brajesh Singh on #41089

    Hi Simon,
    Thank you for the question.

    Please use the following code.

    
    
    /**
     * Redirects user to custom url if they visit the group and are not member of the group.
     * Site admins are not restricted.
     */
    add_action( 'bp_template_redirect', function () {
    	if ( ! is_super_admin() && bp_is_group() && ! groups_is_user_member( get_current_user_id(), groups_get_current_group()->id ) ) {
    		// change the url to any page.
    		$redirect_url = site_url( '/about' );
    		bp_core_redirect( $redirect_url );
    	}
    } );
    

    You can change the redirect url as you please.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 12
    simon on #41126

    Thank you Brajesh!

  • Keymaster
    (BuddyDev Team)
    Posts: 19833
    Brajesh Singh on #41163

    You are welcome.

The topic ‘ [Resolved] Buddypress group is not member redirect’ is closed to new replies.

This topic is: resolved