How to use nonces the right way #28
Replies: 5 comments 1 reply
-
The documentation team is also working on centralizing the nonces information that is right now in multiple places. |
Beta Was this translation helpful? Give feedback.
-
Looking through some of the code examples, noticed this anonymous / lambda function as callback to an Using anonymous functions in The "best practice" there is to use a separate function, like in the other examples on the same page. Example: https://developer.wordpress.org/apis/security/nonces/#performing-additional-verification. Ideally all code examples would be like that. The general idea is that code examples would have the same requirements as the WP core code, including formatting, white space, best practices, etc. |
Beta Was this translation helpful? Give feedback.
-
I've often struggled to remember all the different places/ways nonces are used with developing for WordPress, so I usually keep a few sample code snippets around for both form submission handlers, as well as ajax handlers. If no one else wants to tackle this post, I'd be happy to. |
Beta Was this translation helpful? Give feedback.
-
As @jonathanbossenger noted, we need to use nonces with Ajax handlers. Any web interface that establishes a session with WP via Ajax needs to authenticate and exchange nonces. This should include front-end React apps that use api-fetch, axios, useQuery, or any other tooling. |
Beta Was this translation helpful? Give feedback.
-
@zzap has taking this on. This discussion is locked. Please continue the discussion on the issue: How to use nonces the right way |
Beta Was this translation helpful? Give feedback.
-
Thank you to @zzap for suggesting this topic!
What would be the flow of such a post?
Beta Was this translation helpful? Give feedback.
All reactions