You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Related: WP-API/docs#194
```php
'type' => 'string',
'validate_callback' => function( $should_be_date ) {
return preg_match( '/^\d{4}-\d{2}-\d{2}$/u', $should_be_date );
}
```
Above validation expects the parameter should be 'YYYY-MM-DD' format, but actually any string as "valid" because `preg_match()` returns 0(falsy value) for mismatch.
So, validation priority should be `is_wp_error()` -> "is true?" -> "else, invalid."
Concerns:
`strpos()` return 0 for match.
In Adding Custom Endpoints,
validate_callback
for arguments list is described like below.source: https://github.com/WP-API/docs/blob/master/extending-the-rest-api/adding-custom-endpoints.md?plain=1#L123
But it seems that extra descriptions are required.
WP_Error
as return value.WP_Error
adds extra messages to response.false
is checked strictly, so other falsey values like''
,0
, andnull
will be recognized asvalid
.Code is here: https://github.com/WordPress/WordPress/blob/master/wp-includes/rest-api/class-wp-rest-request.php#L911-L923
The text was updated successfully, but these errors were encountered: