Skip to content

Commit 9d96836

Browse files
committed
Merge pull request WP-API#20 from WP-API/late-authentication
Authenticate on init, rather than before
2 parents dbf8246 + 56a3b81 commit 9d96836

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

oauth-server.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,28 @@ function json_oauth_load() {
5959
add_filter( 'determine_current_user', array( $wp_json_authentication_oauth1, 'authenticate' ) );
6060
add_filter( 'json_authentication_errors', array( $wp_json_authentication_oauth1, 'get_authentication_errors' ) );
6161
}
62-
add_action( 'plugins_loaded', 'json_oauth_load' );
62+
add_action( 'init', 'json_oauth_load' );
63+
64+
/**
65+
* Force reauthentication after we've registered our handler
66+
*
67+
* We could have checked authentication before OAuth was loaded. If so, let's
68+
* try and reauthenticate now that OAuth is loaded.
69+
*/
70+
function json_oauth_force_reauthentication() {
71+
if ( is_user_logged_in() ) {
72+
// Another handler has already worked successfully, no need to
73+
// reauthenticate.
74+
75+
return;
76+
}
77+
78+
// Force reauthentication
79+
global $current_user;
80+
$current_user = null;
81+
get_currentuserinfo();
82+
}
83+
add_action( 'init', 'json_oauth_force_reauthentication', 100 );
6384

6485
/**
6586
* Load the JSON API

0 commit comments

Comments
 (0)