@@ -241,7 +241,21 @@ public function authenticate( $result ) {
241
241
// Validate the bearer token.
242
242
$ token = $ this ->validate_token ();
243
243
if ( is_wp_error ( $ token ) ) {
244
- return $ token ;
244
+ /**
245
+ * Filter the response when a token is invalid.
246
+ *
247
+ * By default an authentication error will be returned. This filter
248
+ * allows us to modify that response ignoring an invalid token,
249
+ * allowing the REST API response to continue, making JWT auth
250
+ * optional.
251
+ *
252
+ * @param object|WP_Error $token Return the JSON Web Token object,
253
+ * or WP_Error on failure.
254
+ * @param mixed $result Result of any other
255
+ * authentication errors.
256
+ * @return mixed
257
+ */
258
+ return apply_filters ( 'rest_authentication_invalid_token ' , $ token , $ result );
245
259
}
246
260
247
261
// If it's a wp_user based token, set the current user.
@@ -382,7 +396,7 @@ public function require_token() {
382
396
383
397
/**
384
398
* GET requests do not typically require authentication, but if the
385
- * Authorization header is provided, we will use it. WHat 's happening
399
+ * Authorization header is provided, we will use it. What 's happening
386
400
* here is that `WP_REST_Token::get_auth_header` returns the bearer
387
401
* token or a `WP_Error`. So if we have an error then we can safely skip
388
402
* the GET request.
0 commit comments