Skip to content

Commit

Permalink
Bugfix: WP-API#27 WP-API#33 WP-API#45 Avoid wp_authenticate's errors
Browse files Browse the repository at this point in the history
Merge pull request #2 from BrianHenryIE/wp_authenticate-bugfix
  • Loading branch information
martin-rueegg committed Apr 14, 2020
2 parents 9e9d526 + 5339062 commit 30b435f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion basic-auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,19 @@ function json_basic_auth_handler( $user ) {
*/
remove_filter( 'determine_current_user', 'json_basic_auth_handler', 20 );

$user = wp_authenticate( $username, $password );
$user = get_user_by('login', $username);

if ( !$user ) {
$user = get_user_by('email', $username);
}

if ( !$user ) {
return null;
}

if ( ! wp_check_password( $password, $user->user_pass, $user->ID ) ) {
return null;
}

add_filter( 'determine_current_user', 'json_basic_auth_handler', 20 );

Expand Down

0 comments on commit 30b435f

Please sign in to comment.