Skip to content

Conversation

charlestonsoftware
Copy link

The example shows current_user_can() to validate permissions on a REST request. This is a common and useful permission check, however it does require the 'wp_rest' nonce to be present in the REST request or the request is treated as if the user was logged out.

The example shows current_user_can() to validate permissions on a REST request. This is a common and useful permission check, however it does require the 'wp_rest' nonce to be present in the REST request or the request is treated as if the user was logged out.

Note that the permission callback also receives the Request object as the first parameter, so you can do checks based on request arguments if you need to.

For user based permissions such as current_user_can() the app calling the REST endpoint must pass along the \_wpnonce argument that has been created with a wp_create_nonce( 'wp_rest' ) call. Failure to do so will cause the REST API to treat the request as if it was from a logged out user.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably just link to the Authentication page, with copy like...

Note: Users are authenticated before your permission callback is called. For cookie-based authentication, this includes nonce checks; a missing nonce will treat the request as if it was from a logged out user.

@kadamwhite
Copy link
Contributor

@charlestonsoftware I concur with Ryan's assessment above. If you can re-word I can review and merge.

@iandunn
Copy link
Contributor

iandunn commented May 22, 2019

#46 is similar to this, but links to the Auth page, and IMO has a clearer description.

@TimothyBJacobs
Copy link
Member

Closing since #46 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants