REST API: Return the proper status code for failed permission callbacks in `WP_REST_Server->dispatch()`.

Use the `rest_authorization_required_code()` function to return a 401 status code when a permission callback fails due to a user not being logged in.

Props jaswrks.
Fixes #42828.

git-svn-id: https://develop.svn.wordpress.org/trunk@42421 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker 2017-12-30 20:36:25 +00:00
parent 7567f588b3
commit 24b3f5e77c
1 changed files with 1 additions and 1 deletions

View File

@ -915,7 +915,7 @@ class WP_REST_Server {
if ( is_wp_error( $permission ) ) {
$response = $permission;
} elseif ( false === $permission || null === $permission ) {
$response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => 403 ) );
$response = new WP_Error( 'rest_forbidden', __( 'Sorry, you are not allowed to do that.' ), array( 'status' => rest_authorization_required_code() ) );
}
}
}