Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Redirect from members page to profile page


  • bridieamelia
    Participant

    @bridieamelia

    I don’t want users to be able to see the members page, but rather redirect to their own profile page if they try to reach it (there is no accessible way through the menu, but just in case a savvy user types it into their URL).

    I have :

    add_action( 'template_redirect', 'redirect_members_page' );
    
    function redirect_members_page() {
    	global $current_user;
    	get_currentuserinfo();
    	if ($is_page('members')) {
    			wp_redirect(home_url() . '/members/' . $current_user->user_login . '/profile/' );
    			exit;
    	}
    }

    Which obviously creates a redirect loop.

    How can I specify the members/ component but not the profile page?

    Bridie

Viewing 2 replies - 1 through 2 (of 2 total)

  • Henry Wright
    Moderator

    @henrywright

    Hi @bridieamelia,

    Try this:

    function redirect_members_page() {
        if ( bp_is_user_profile() && ! bp_is_my_profile() ) {
            $user = get_userdata( get_current_user_id() );
            wp_redirect( home_url() . '/members/' . $user->user_login . '/profile/' );
            exit;
        }
    }
    add_action( 'template_redirect', 'redirect_members_page' );

    bridieamelia
    Participant

    @bridieamelia

    Cheers @henrywright,

    I tweaked it a bit and came up with this, which does what I want it to do. It was the conditional not for bp_is_my_profile() I was missing, for future readers.

    function redirect_members_page() {
        if ( is_page('members') && ! bp_is_my_profile() ) {
            $user = get_userdata( get_current_user_id() );
            wp_redirect( home_url() . '/members/' . $user->user_login );
            exit;
        }
    }
    add_action( 'template_redirect', 'redirect_members_page' );

    Bridie

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Redirect from members page to profile page’ is closed to new replies.
Skip to toolbar