From f2af0507ecd74bcfcc8bdfba29194525441324a4 Mon Sep 17 00:00:00 2001 From: Sujal Gurung <86787475+gursuj@users.noreply.github.com> Date: Sat, 3 Jan 2026 10:04:57 +0545 Subject: [PATCH 1/3] mention empty value quirk for 'required' argument option This is just re-implementing patch #101 since the branch for that got deleted. --- extending-the-rest-api/adding-custom-endpoints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extending-the-rest-api/adding-custom-endpoints.md b/extending-the-rest-api/adding-custom-endpoints.md index 7ac3542..65396ad 100644 --- a/extending-the-rest-api/adding-custom-endpoints.md +++ b/extending-the-rest-api/adding-custom-endpoints.md @@ -119,7 +119,7 @@ If the request has the `Content-type: application/json` header set and valid JSO Arguments are defined as a map in the key `args` for each endpoint (next to your `callback` option). This map uses the name of the argument of the key, with the value being a map of options for that argument. This array can contain a key for `default`, `required`, `sanitize_callback` and `validate_callback`. * `default`: Used as the default value for the argument, if none is supplied. -* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. +* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. Note: this will be valid if the argument is empty. Use `'minLength' => 1` to make sure empty values are not allowed. * `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. From f170b7151086bea8a96794e619868cdb1b9acb23 Mon Sep 17 00:00:00 2001 From: Sujal Gurung <86787475+gursuj@users.noreply.github.com> Date: Sat, 3 Jan 2026 10:26:02 +0545 Subject: [PATCH 2/3] fix suggestion for ensuring required fails for empty values Seems `minLength` doesn't work unless you set a proper `type` like `string`. The type will also depend on what `Content-Type` you use. --- extending-the-rest-api/adding-custom-endpoints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extending-the-rest-api/adding-custom-endpoints.md b/extending-the-rest-api/adding-custom-endpoints.md index 65396ad..ba81af3 100644 --- a/extending-the-rest-api/adding-custom-endpoints.md +++ b/extending-the-rest-api/adding-custom-endpoints.md @@ -119,7 +119,7 @@ If the request has the `Content-type: application/json` header set and valid JSO Arguments are defined as a map in the key `args` for each endpoint (next to your `callback` option). This map uses the name of the argument of the key, with the value being a map of options for that argument. This array can contain a key for `default`, `required`, `sanitize_callback` and `validate_callback`. * `default`: Used as the default value for the argument, if none is supplied. -* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. Note: this will be valid if the argument is empty. Use `'minLength' => 1` to make sure empty values are not allowed. +* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. Note: this will be valid if the argument is empty. To ensure empty values are not allowed, set `'minLength' => 1` and an [appropriate `type`](https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types). * `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. From ee287ae03606e38e93c1b7470aad7c9edaf02d7f Mon Sep 17 00:00:00 2001 From: Sujal Gurung <86787475+gursuj@users.noreply.github.com> Date: Sat, 3 Jan 2026 11:08:48 +0545 Subject: [PATCH 3/3] update previous explanation about required argument --- extending-the-rest-api/adding-custom-endpoints.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extending-the-rest-api/adding-custom-endpoints.md b/extending-the-rest-api/adding-custom-endpoints.md index ba81af3..cfc5534 100644 --- a/extending-the-rest-api/adding-custom-endpoints.md +++ b/extending-the-rest-api/adding-custom-endpoints.md @@ -119,7 +119,7 @@ If the request has the `Content-type: application/json` header set and valid JSO Arguments are defined as a map in the key `args` for each endpoint (next to your `callback` option). This map uses the name of the argument of the key, with the value being a map of options for that argument. This array can contain a key for `default`, `required`, `sanitize_callback` and `validate_callback`. * `default`: Used as the default value for the argument, if none is supplied. -* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. Note: this will be valid if the argument is empty. To ensure empty values are not allowed, set `'minLength' => 1` and an [appropriate `type`](https://developer.wordpress.org/rest-api/extending-the-rest-api/schema/#primitive-types). +* `required`: If defined as true, and no value is passed for that argument, an error will be returned. No effect if a default value is set, as the argument will always have a value. Note: this will be valid if the argument is empty. To ensure empty values are not allowed, use something like `'minLength' => 1` and `'type' => 'string'`, or use appropriate logic in `validate_callback`. * `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.