Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chad Butler

    (@cbutlerjr)

    That’s not actually the plugin (although it could be related, if you’re using one or more of the plugin’s functions or hooks to facilitate redirecting wp-login.php to the front end login).

    It has to do with whatever you’re doing to redirect to the front end login, so I’d need to know what that is in order to give an answer to this.

    Thread Starter airdrummer

    (@airdrummer)

    i’ve added this code to my site-specific plugin, as was suggested a while ago for email login, etc:

    // wp-members login redirect to referrer
    add_filter( ‘login_url’, ‘my_login_url’ );
    function my_login_url( $url ) {
    return add_query_arg( ‘redirect_to’, wpmem_current_url(), wpmem_login_url() );
    }

    // wp-members login with username or email
    add_filter( ‘authenticate’, ‘my_login_with_email’, 10, 3 );
    function my_login_with_email( $user=null, $username, $password ){

    // First, check by username.
    $user = get_user_by( ‘login’, $username );

    // If the username is invalid, check by email.
    if( ! $user )
    $user = get_user_by( ’email’, $username );

    // Validate the password.
    if( $user and wp_check_password( $password, $user->user_pass ) )
    // If password checks out, return a valid login.
    return $user;

    // Return a failed login.
    return new WP_Error( ‘login’, “Login Failed” );
    }

    add_filter( ‘wpmem_inc_login_inputs’, ‘my_login_with_email_form’ );
    function my_login_with_email_form( $array ){
    $array[0][‘name’] = ‘Email or Username’;
    return $array;
    }

    // wp-members reset passwd with username or email
    add_filter( ‘wpmem_inc_resetpassword_inputs’, ‘my_resetpassword_inputs’ );
    function my_resetpassword_inputs( $array )
    {
    $array[0][‘name’] = ‘Email or Username’;
    return array_slice($array, 0, 1);
    }

    add_filter( ‘wpmem_pwdreset_args’, ‘my_pwdreset_args’ );
    function my_pwdreset_args( $args )
    {
    // First, check by username.
    $user = get_user_by( ‘login’, $args[‘user’] );

    // If the username is invalid, check by email.
    if( !$user )
    $user = get_user_by( ’email’, $args[‘user’] );

    if( $user )
    {
    $args[‘user’] = $user->user_login;
    $args[’email’] = $user->user_email;
    }

    return $args;
    }

    Thread Starter airdrummer

    (@airdrummer)

    // wp-members login redirect to referrer
    add_filter( 'login_url', 'my_login_url' );
    function my_login_url( $url ) {
        return add_query_arg( 'redirect_to', wpmem_current_url(), wpmem_login_url() );
    }
    
    // wp-members login with username or email
    add_filter( 'authenticate', 'my_login_with_email', 10, 3 );
    function my_login_with_email( $user=null, $username, $password ){
     
        // First, check by username.
        $user = get_user_by( 'login', $username );
     
        // If the username is invalid, check by email.
        if( ! $user )
            $user = get_user_by( 'email', $username );  
         
        // Validate the password.
        if( $user and wp_check_password( $password, $user->user_pass ) )
            // If password checks out, return a valid login.
            return $user;
                
        // Return a failed login.
        return new WP_Error( 'login', "Login Failed" );
    }
    
    add_filter( 'wpmem_inc_login_inputs', 'my_login_with_email_form' );
    function my_login_with_email_form( $array ){
        $array[0]['name'] = 'Email or Username';
        return $array;
    }
    
    // wp-members reset passwd with username or email
    add_filter( 'wpmem_inc_resetpassword_inputs', 'my_resetpassword_inputs' );
    function my_resetpassword_inputs( $array )
    {
        $array[0]['name'] = 'Email or Username';
        return array_slice($array, 0, 1);
    }
    
    add_filter( 'wpmem_pwdreset_args', 'my_pwdreset_args' );
    function my_pwdreset_args( $args )
    {
        // First, check by username.
        $user = get_user_by( 'login', $args['user'] );
     
        // If the username is invalid, check by email.
        if( !$user ) 
            $user = get_user_by( 'email', $args['user'] );
        
        if( $user ) 
        {
        	$args['user']  =  $user->user_login;
        	$args['email'] =  $user->user_email;
        }
    
        return $args;
    }
    
    /* fix wp-members.hidden 
    https://www.ads-software.com/support/topic/hidden-posts-still-appear-in-prev-next-links/
    */
    function filter_get_adjacent_post_where( $where ) 
    {
    	global $wpmem;
    	$hidden = implode( ",", $wpmem->get_hidden_posts() );
    	if (!empty($hidden))
    		$where  = $where . " AND p.ID NOT IN ( $hidden )";
    	return $where;
    }
    add_filter( 'get_previous_post_where', 'filter_get_adjacent_post_where' );
    add_filter( 'get_next_post_where', 'filter_get_adjacent_post_where' );
    
    Plugin Author Chad Butler

    (@cbutlerjr)

    Unfortunately, I don’t see anything there that would be the issue. Do you have something that redirects wp-login.php to your front end login? If so, that’s what you need to look at. (The ‘login_url’ filter isn’t it – that just filters the URL WP generates when outputting the login URL for a link. It’s not a redirecting filter/action.)

    On a side note, the filters/actions you have in there for allowing login with email are not necessary. The plugin does that by default (and has for awhile). (This wasn’t always the case, so I assume you’ve probably had that in there from before it was supported, but now that it is native, you’re best off removing it.)

    Thread Starter airdrummer

    (@airdrummer)

    after removing the obsolete email login code, it’s working now:

    https://cardinalglen.org/wp-login.php?redirect_to=https%3A%2F%2Fcardinalglen.org%2Fwp-admin%2Fuser-edit.php%3Fuser_id%3D337&reauth=1

    redirect url apparently was over-sanitized;-)

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘redirect after login still not working right’ is closed to new replies.