I have a custom function which is based off the wp_login_form().

I copied the function and essentially wrote it to add in two new fields to validate against - "mbjbookdomain" and "mbjbookreference".

In the validation:

function mb_authenticate_username_password( $user, $username, $password ) {
    if( is_a( $user, 'WP_User' ) ) { return $user; }

    // set up the variables to call
    $mb_reference   = ( isset( $_POST['mbjbookreference'] ) && !empty( $_POST['mbjbookreference'] ) ? '.' . $_POST['mbjbookreference']  : null  );
    $mb_domain      = ( isset( $_POST['mbjbookdomain'] )    && !empty( $_POST['mbjbookdomain'] )    ? '@' . $_POST['mbjbookdomain']     : null  );
    $mb_username    = ( !empty( $username ) ? $username : 0 );
    $mb_username    = ( ( $mb_domain && $mb_username ) ? ( $mb_username . $mb_reference . $mb_domain ) : 0 );

    // begin the checks
    if( empty( $mb_username ) || empty( $password ) ) {
        wp_redirect( home_url('/admin/login/?a=1') );
        exit;
    } else {
        if( is_email( $mb_username ) ) {
            $mb_user = get_user_by( 'email', $mb_username );
            if( isset( $mb_user, $mb_user->user_login, $mb_user->user_status ) ) {
                if( 0 === intval( $mb_user->user_status ) ) {
                    $username = $mb_user->user_login;
                    return wp_authenticate_username_password( null, $username, $password );
                }
            }
        }
    }
}

This is done the way it is above so the user only has to type in user1 into the login field, but it is validated against their auto generated, internal use only email address (eg. user1.example1@site.dev)

The code above works and the user can log in without any issues. But when I authenticate, and gain access as the Super Admin, then try to get to the wp-admin I am then sent to the wp_redirect( home_url('/admin/login/?a=1') ); line as there is no username or password passed.

Are there two authentication hooks for the user to call when logging in, or is there something stupid I am doing?

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.