From 99e40d1752cfc27669fe58f603c1e9d82706a237 Mon Sep 17 00:00:00 2001 From: Kalimah Apps Date: Mon, 16 Nov 2020 15:39:17 +1100 Subject: [PATCH] Update adding-custom-endpoints.md Added a clarification for required property and empty values being allowed. --- extending-the-rest-api/adding-custom-endpoints.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/extending-the-rest-api/adding-custom-endpoints.md b/extending-the-rest-api/adding-custom-endpoints.md index f77682e..b20e303 100644 --- a/extending-the-rest-api/adding-custom-endpoints.md +++ b/extending-the-rest-api/adding-custom-endpoints.md @@ -119,6 +119,10 @@ Arguments are defined as a map in the key `args` for each endpoint (next to your * `validate_callback`: Used to pass a function that will be passed the value of the argument. That function should return true if the value is valid, and false if not. * `sanitize_callback`: Used to pass a function that is used to sanitize the value of the argument before passing it to the main callback. +[alert] +Required will return valid if the argument is empty. Use `'minLength' => 1` to make sure empty values are not allowed. +[/alert] + Using `sanitize_callback` and `validate_callback` allows the main callback to act only to process the request, and prepare data to be returned using the `WP_REST_Response` class. By using these two callbacks, you will be able to safely assume your inputs are valid and safe when processing. Taking our previous example, we can ensure the parameter passed in is always a number: