Skip to content

Commit 518dfe8

Browse files
authored
Warn developer to send nonce after registering permission callback.
Previously the documentation did not make this obvious, and a developer could easily fail to connect the dots, and not realize why their requests are failing.
1 parent c6f7fc6 commit 518dfe8

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

extending-the-rest-api/adding-custom-endpoints.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ This callback can be registered as `permission_callback`, again in the endpoint
213213

214214
The permissions callback is run after remote authentication, which sets the current user. This means you can use `current_user_can` to check if the user that has been authenticated has the appropriate capability for the action, or any other check based on current user ID. Where possible, you should always use `current_user_can`; instead of checking if the user is logged in (authentication), check whether they can perform the action (authorization).
215215

216+
Once you register a `permission_callback`, you will need to start sending a nonce along with your requests. If you don't, you'll receieve a `rest_forbidden` error. See [Authentication](https://developer.wordpress.org/rest-api/using-the-rest-api/authentication/) for more details.
217+
216218
Continuing with our previous example, we can make it so that only editors or above can view this author data. We can check a number of different capabilities here, but the best is `edit_others_posts`, which is really the core of what an editor is. To do this, we just need a callback here:
217219

218220
```php

0 commit comments

Comments
 (0)