Skip to content

Instantly share code, notes, and snippets.

@petenelson
Created February 27, 2017 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petenelson/ae99ed55b9a06342a70450dff61e979a to your computer and use it in GitHub Desktop.
Save petenelson/ae99ed55b9a06342a70450dff61e979a to your computer and use it in GitHub Desktop.
WordPress: Example of REST API route with schema type of array
<?php
register_rest_route( 'test', '/v1/schema-test', array(
'methods' => 'POST',
'callback' => __NAMESPACE__ . '\handle_endpoint',
'args' => array(
'mybools' => array(
'required' => true,
'type' => 'array', // We require an array of items.
'items' => array(
'type' => 'boolean', // The items must be all boolean values.
),
)
),
)
);
@petenelson
Copy link
Author

petenelson commented Feb 27, 2017

If you do a POST with mybools=true,1,0 or mybools[]=true&mybools[]=1&mybools[]=0it will perform the boolean schema check on all of the items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment