I' setting up a REST Endpoint in Wordpress and have a question about the "validate_callback" argument.
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.
When it returns a false a standard message is created like this:
{
"code": "rest_invalid_param",
"message": "Invalid parameter(s): minutes",
"data": {
"status": 400,
"params": {
"minutes": "Invalid parameter."
},
"details": []
}
Is there a way to return your own code and message instead?
Thanks Flemming
No, not with validate_callback, you can only return true or false, where false denotes that validation did not pass. WP then will take care of the error message (you perhaps have seen that).
However, for the whole rest-endpoint you can return a WP_Error instance, you can find it outline in the docs here: