Skip to content

Commit

Permalink
REST API: Improve token validation for plugin compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
eliot-akira committed Jan 15, 2025
1 parent cfcfbbc commit 99c3cf5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions framework/api/rest/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,20 @@ function reset_password( $request ) {
}

/**
* Provide current user to the request.
* Provide current user to the request if there is a valid token.
*/
function rest_pre_dispatch( $result, $server, $request ) {
// Only validate token for our namespace
if ( strpos( $request->get_route(), '/' . $this->namespace ) === false ) {
return false;
}
if ($request->get_route() !== '/' . $this->namespace . '/token/validate'
&& !empty($user_id = $this->determine_current_user())
&& !is_user_logged_in()
) {
wp_set_current_user($user_id);
if (!empty($result)) return $result;
try {
if ($request->get_route() !== '/' . $this->namespace . '/token/validate'
&& !empty($user_id = $this->determine_current_user())
&& !is_user_logged_in()
) {
wp_set_current_user($user_id);
}
} catch (\Throwable $th) {
// Continue
}
return $result;
}

};

0 comments on commit 99c3cf5

Please sign in to comment.