BuddyDev

Search

[Resolved] Redirect to a custom url when i visited a user profile (logged in)

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

    I have been trying the following code so that when I see a profile of another user, send me to the following url:

    site.com/members/USERNAME/reviews

    all the code works except the line
    bp_core_redirect('./reviews' );

    my code is:

    function bpfr_hide_tabs() {
    global $bp;
    
           if( class_exists( 'bbPress' ) || bp_is_active ( 'groups' ) ) :
        if ( bp_is_user() && !is_super_admin() && !bp_is_my_profile() ) {
        bp_core_redirect('./reviews'  );
        bp_core_remove_nav_item( 'activity' );
    
        }
        endif;
         }
         add_action( 'bp_setup_nav', 'bpfr_hide_tabs', 15 );

    Any suggest? Thanks!!!

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

    Hello Jennifer,

    Thank you for posting. Please clear me out for the following points.

    1. Is ‘reviews’ is custom WordPress page or user profile tab?.
    2. Do you want to redirect user for all tabs of user profile or certain tabs?.
    3. Is there any need to remove activity nav item?.

    Please let me know.

    Regards
    Ravi

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

    Hi Revi!
    1. Reviews is a tab of profile page ( like activity or message) but I dont have the name to redirect ( because I didnt create it..). I have tried with define(‘ BP_DEFAULT_COMPONENT’, ‘reviews’ ) but it dont works.

    2. Yes. I want redirect to all the users that are looking other profile to tabs of reviews
    3. Yes I want hide all the tabs except reviews.members/USERNAME/reviews

    Thanks very much!!
    Regards
    Jennifer

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

    Hello Jenifer,

    Thank you for sharing the details. Please try the following code and let me know if works for you or not.

    
    function buddydev_redirect_to_reviews() {
    
    	if ( bp_is_user() && ! bp_is_my_profile() && ! bp_is_current_component( 'reviews' ) ) {
    		$user_domain = bp_core_get_user_domain( bp_displayed_user_id() );
    
    		$review_url = trailingslashit( $user_domain ) . 'reviews';
    
    		bp_core_redirect( $review_url );
    	}
    }
    add_action( 'bp_template_redirect', 'buddydev_redirect_to_reviews' );
    

    Regards
    Ravi

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

    Hi Ravi! You’re great! I’ve been running around with this for days!
    I take the boldness to open a last forum of the last doubt I have about friendships.
    Regards
    Jennifer

You must be logged in to reply to this topic.

This topic is: resolved