From c1f070b605d3f97af9b7786ac74d04f72a19617f Mon Sep 17 00:00:00 2001 From: Michael Nelson Date: Wed, 8 Apr 2015 07:19:17 -0700 Subject: [PATCH 1/2] addresses #12 in WP-API/Basic-Auth so you can use basic auth AND be logged in the browser --- basic-auth.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/basic-auth.php b/basic-auth.php index 805918c..f426156 100644 --- a/basic-auth.php +++ b/basic-auth.php @@ -44,10 +44,15 @@ function json_basic_auth_handler( $user ) { } $wp_json_basic_auth_error = true; - + //if we found a user, remove regular cookie filters because + //they're just going to overwrite what we've found + if( $user->ID ){ + remove_filter( 'determine_current_user', 'wp_validate_auth_cookie' ); + remove_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 ); + } return $user->ID; } -add_filter( 'determine_current_user', 'json_basic_auth_handler', 20 ); +add_filter( 'determine_current_user', 'json_basic_auth_handler', 5 ); function json_basic_auth_error( $error ) { // Passthrough other errors From 09ad41ecf5907588b14852184be68f34f0b3e975 Mon Sep 17 00:00:00 2001 From: Mike Nelson Date: Wed, 24 Feb 2016 16:28:08 -0800 Subject: [PATCH 2/2] if bad username and login are provided while using wp api v2, this commit makes it so it also shows an error like it did with wp api v1 --- basic-auth.php | 1 + 1 file changed, 1 insertion(+) diff --git a/basic-auth.php b/basic-auth.php index 805918c..0f4eba5 100644 --- a/basic-auth.php +++ b/basic-auth.php @@ -60,3 +60,4 @@ function json_basic_auth_error( $error ) { return $wp_json_basic_auth_error; } add_filter( 'json_authentication_errors', 'json_basic_auth_error' ); +add_filter( 'rest_authentication_errors', 'json_basic_auth_error' );