I’m trying to define a new REST Api endpoint based on WP REST API (version 2) and have question relating to what arguments are available to the validate_callback
and sanitize_callback
. Is the Request
object made available for these callbacks?
For example:
add_action( 'rest_api_init', function () {
register_rest_route( 'myplugin/v1', '/author/(?P<id>\d+)', array(
'methods' => 'GET',
'callback' => 'my_awesome_func',
'args' => array(
'id' => array(
'validate_callback' => 'my_validation'
),
),
) );
} );
function my_validation (WP_REST_Request $request) {
return is_numeric( $request['id'] ); // Is this acceptable???
}