Skip to:
Content
Pages
Categories
Search
Top
Bottom

Login redirects not working

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

  • sharmavishal
    Participant

    @sharmavishal

    Sorry no idea.


    Henry Wright
    Moderator

    @henrywright

    Can you post your code?


    navyspitfire
    Participant

    @navyspitfire

    @sharmavishal – that didn’t work for me. No plugins have worked.

    @Henry- which code specifically? All of my redirect codes?


    sharmavishal
    Participant

    @sharmavishal

    @navyspitfire just tested right now and am able to redirect logins to groups section and logout to main site


    peter-hamilton
    Participant

    @peter-hamilton

    /**
     * Redirect user after successful login.
     *
     * @param string $redirect_to URL to redirect to.
     * @param string $request URL the user is coming from.
     * @param object $user Logged user's data.
     * @return string
     */
    function my_login_redirect( $redirect_to, $request, $user ) {
    	//is there a user to check?
    	if ( isset( $user->roles ) && is_array( $user->roles ) ) {
    		//check for admins
    		if ( in_array( 'administrator', $user->roles ) ) {
    			// redirect them to the default place
    			return $redirect_to;
    		} else {
    			return home_url();
    		}
    	} else {
    		return $redirect_to;
    	}
    }
    
    add_filter( 'login_redirect', create_function( '$url,$query,$user', 'return home_url();' ), 10, 3 );
    

    This should work when in your functions.php, but if as you said something overrides your functions file there is another problem afoot.


    peter-hamilton
    Participant

    @peter-hamilton

    And when you say “all your redirect codes” you might have referred the problem, you can have only 1 redirect code block functioning without conflicts, multiple redirect functions should be in one code block/function I think.


    Earl_D
    Participant

    @earl_d

    @peter-hamilton how would I use your code snippet to redirect to the user profile. Separately looking for some thing that works all the code I have tried does not


    danbp
    Participant

    @danbp

    hi @earl_d,

    add this snippet to bp-custom.php and give it a try.

    function bpex_redirect_to_profile( $redirect_to_calculated, $redirect_url_specified, $user ){
     
        if( empty( $redirect_to_calculated ) )
            $redirect_to_calculated = admin_url();
     
        // redirect logged in to his/her profile - except site admins
     
        if( isset( $user->ID) && ! is_super_admin( $user->ID ) )
            return bp_core_get_user_domain( $user->ID );
        else
            return $redirect_to_calculated; /* nada !*/
     
    }
    add_filter( 'bp_login_redirect', 'bpex_redirect_to_profile', 11, 3 );

    For the redirect URL error you mentionned here, use:

    return bp_core_get_user_domain( $user->ID ) .'/mypics';

    mypics is a slug, not a constant ( $user->ID ) .mypics


    socialc
    Participant

    @socialc

    … or just add a login link to your site anywhere in your theme files. e.g <a href="<?php echo wp_login_url(bp_loggedin_user_domain()); ?>"><?php _e('Login', 'buddypress'); ?></a>.

    This will redirect a user to their profile page after logging in.


    Earl_D
    Participant

    @earl_d

    @danbp thanks for the assistance. It seems to be working. I hope I did not hijack the OP request. That was my reason for starting a different topic

Viewing 11 replies - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.
Skip to toolbar