Skip to content

Commit 12ffb6d

Browse files
committed
Fixed REST API permissions
1 parent 8caa48d commit 12ffb6d

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

includes/frontend/class-rest-api.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,14 @@ public function register_routes() {
120120
* @return \WP_Error|bool
121121
*/
122122
public function permissions_check( \WP_REST_Request $request ) {
123-
// Deny edit context for unauthenticated users to prevent exposing sensitive data like passwords.
124-
if ( 'edit' === $request->get_param( 'context' ) && ! is_user_logged_in() ) {
125-
return false;
123+
$context = $request->get_param( 'context' );
124+
125+
if ( 'edit' === $context && ! current_user_can( 'edit_posts' ) ) {
126+
return new \WP_Error(
127+
'rest_forbidden_context',
128+
__( 'Sorry, you are not allowed to view this context.', 'top-10' ),
129+
array( 'status' => rest_authorization_required_code() )
130+
);
126131
}
127132

128133
return apply_filters( 'top_ten_rest_api_permissions_check', true, $request );

0 commit comments

Comments
 (0)