BuddyDev

Search

[Resolved] Redirect a unregistered user

Tagged: ,

  • Participant
    Level: Enlightened
    Posts: 53
    Jennifer on #25479

    Hello! I’m looking for a way that if an unregistered user tries to access a member/jennifer/activity/111 for example it be redirect to member/jennifer/profile,any suggestions? All I found is blocking access.
    Thanks!!

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #25482

    Hello Jennifer,

    Thank you for posting. Please try the following code to redirect non logged-in user to Activity author profile when try to access single activity.

    
    /**
     * Redirect user to user profile.
     */
    add_action( 'bp_template_redirect', function() {
    
    	if ( ! is_user_logged_in() && bp_is_single_activity() ) {
    		$profile_link = trailingslashit( bp_displayed_user_domain() ) . bp_get_profile_slug();
    		bp_core_redirect( $profile_link );
    	}
    } );
    
    

    Let me know it is works or not.

    Regards
    Ravi

  • Participant
    Level: Enlightened
    Posts: 53
    Jennifer on #25502

    Hi thanks! its works! It works when it is member/jennifer/activity/111 to member/jennifer/profile but when the url is like /members/jennifer/reviews/ or /members/jennifer/friends/ is not redirect to the profile. any suggest??
    Regards,
    Jennifer

  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #25503

    Hi Jennifer,
    Thank you.

    The above code by @ravisharma only checks for single activity page and redirect.

    Can you please post your issue and help us understand it better. That will help us assist you better.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 53
    Jennifer on #25505
  • Keymaster
    (BuddyDev Team)
    Posts: 24623
    Brajesh Singh on #25507

    Thank you.

    Please remove this code and use the code shared in the other thread.

    Regards
    Brajesh

The topic ‘ [Resolved] Redirect a unregistered user’ is closed to new replies.

This topic is: resolved