Skip to content

Commit 1d6e3e8

Browse files
authored
Merge pull request #185 from dshanske/loadorder
Loadorder
2 parents 2738f9e + dce8dce commit 1d6e3e8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

includes/class-indieauth-authorize.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function load() {
2121

2222
add_filter( 'indieauth_scopes', array( $this, 'get_indieauth_scopes' ), 9 );
2323
add_filter( 'indieauth_response', array( $this, 'get_indieauth_response' ), 9 );
24+
add_filter( 'wp_rest_server_class', array( $this, 'wp_rest_server_class' ) );
2425

2526
}
2627

@@ -38,6 +39,29 @@ abstract public static function get_authorization_endpoint();
3839
**/
3940
abstract public static function get_token_endpoint();
4041

42+
43+
/**
44+
* Prevent caching of unauthenticated status. See comment below.
45+
*
46+
* We don't actually care about the `wp_rest_server_class` filter, it just
47+
* happens right after the constant we do care about is defined. This is taken from the Application Passwords plugin.
48+
*
49+
*/
50+
public static function wp_rest_server_class( $class ) {
51+
global $current_user;
52+
if ( defined( 'REST_REQUEST' ) && REST_REQUEST && $current_user instanceof WP_User && 0 === $current_user->ID ) {
53+
/*
54+
* For our authentication to work, we need to remove the cached lack
55+
* of a current user, so the next time it checks, we can detect that
56+
* this is a rest api request and allow our override to happen. This
57+
* is because the constant is defined later than the first get current
58+
* user call may run.
59+
*/
60+
$current_user = null; // phpcs:ignore
61+
}
62+
return $class;
63+
}
64+
4165
/**
4266
* Add authentication information into the REST API Index
4367
*

indieauth.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ public static function load( $files, $dir = 'includes/' ) {
102102

103103
}
104104

105-
add_action( 'plugins_loaded', array( 'IndieAuth_Plugin', 'plugins_loaded' ), 9 );
105+
add_action( 'plugins_loaded', array( 'IndieAuth_Plugin', 'plugins_loaded' ), 2 );

0 commit comments

Comments
 (0)