This is how I solved similar issue using validate callback – this is the part of code where bar
argument is defined:
'bar' => array(
'default' => FALSE,
'validate_callback' => function($param, $request, $key) {
if ($request['foo'] == 3)
return ($param !== FALSE);
return FALSE;
}
),
The default
parameter causes call of validate callback even if request parameter bar
is not supplied. Then in validate callback only if condition is met, check whether parameter has other than default value.
Related Posts:
- Why is my custom API endpoint not working?
- WordPress 4.7 REST API endpoints
- Can I define multiple callback methods depending on the call method?
- Query the REST API for a Tag by slug
- Rest API Custom Endpoint with space character
- Is there anyway to format my EndPoint URL in WordPress?
- How to force JWT auth for default GET endpoints of WordPress rest api?
- WordPress Rest API custom endpoint for RSS feed
- Custom endpoint to get all custom taxonomy terms
- What’s the right way to validate JSON data coming from an AJAX POST request?
- How can I secure my custom rest api endpoint or add under a already existing rest group
- Securing REST API wp-json/wp/v2/users endpoint
- Delete row from table using custom endpoint via API
- Custom rest api endpoint response json problem
- Is the WordPress REST API installed and enabled in a vanilla WordPress 4.7 installation?
- Does something like is_rest() exist
- How to: Make JWT-authenticated requests to the WordPress API
- WordPress Rest API custom endpoint optional param
- Using the Rewrite API to Construct a RESTful URL
- REST API purpose?
- Get post count in wp rest API v2 and get all categories
- WP REST API — How to change HTTP Response status code?
- wp_get_current_user() function not working in Rest API callback function
- How to use WP-REST API to login user and get user data for Android app?
- WP REST API Is it rather easy to rename the default wp-json uri part?
- Search WP API using the post title
- check the requesting url
- How would I add custom tables/endpoints to the WP REST API?
- WP REST API Require Password for GET Endpoint
- Displaying a page built with Elementor using the REST API [closed]
- Getting user meta data from WP REST API
- Understanding SHORTINIT with WordPress 5
- How to use _embed when using _fields?
- WP REST API V2 – Retrieve sub page by full slug (URL/Path)
- WP REST API create post authentication issue
- WordPress REST API validation
- Are there server performance benefits to fetching only specific fields when querying the REST API?
- WooCommerce: Can’t use wc_get_products for custom REST API endpoints
- How to define a query parameter with REST API?
- Filter posts by multiple custom taxonomy terms using AND operator in REST API v2 (WordPress)
- WP REST API returns blank response if post is too long
- How do I correctly setup an AJAX nonce for WordPress REST API?
- REST API endpoint for elasticpress autosuggest
- How can I get users email (and additional data) from the rest API?
- Increase per_page limit in REST API
- WordPress Rest API: How do we validate with our custom API key?
- Does pre_get_posts affect REST API responses?
- How to feed a HTML5’s EventSource with a REST API custom endpoint?
- Adding WordPress API Endpoint With Multiple Parameters
- Retrieve CSS and JS From the REST API
- Using the REST API (v2) javascript client on a private namespaced route
- How to stop WP API endpoint from caching?
- How to Authenticate WP REST API with JWT Authentication using Fetch API
- authentication issue with rest api – rest_cannot_create
- WP REST API core major changes
- How to get all posts from parent and children categories?
- wordpress wp-json prefix issue
- How to: Rest endpoint returning empty object
- Hiding API routes list
- Get blog title with REST v2
- Is it possible to nest the JSON result of WordPress REST API?
- register_rest_field for custom taxonomy fields that are assosiated with custom post type
- How to force Authentication on REST API for Password protected page using custom table and fetch() without Plugin
- Match REST API post output from custom endpoint
- Custom endpoint that returns an xml
- How to use the WP REST API for new user registration (sign up form)?
- Get post from custom REST endpoint in Gutenberg
- Can I authenticate with both WooCommerce consumer key and JWT?
- REST API multiple media upload
- “rest_no_route” – Debug error
- Filter post_content before loading in Gutenberg editor
- Attach featured image to custom endpoints
- Can’t send emails through REST API
- 401 Error when trying to make a REST API call to site
- WordPress: How to create custom REST API route?
- Create post using rest api with html content
- Does jQuery/Ajax send cookies when using the rest API or do I need to somehow add them?
- How to send multipart form data to WordPress endpoint
- WP REST API: check if user is logged in
- How to change user avatar using REST API?
- WordPress Rest API – Get all posts based on post_meta on custom endpoint
- How to login to WordPress site using basic authentication HTTP headers?
- REST API URL parameters not working with apache server
- Adding post fields in wp-json/wp/v2/search
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- How to Pull ALL Posts, Categories, or Tags in WordPress REST API
- rest api authentication
- Unable to get the info of the user which doesn’t have created any post via REST API
- Trying to get an api request getting error 404
- Upload image to wordpress using REST API
- Filter post content in REST API
- WordPress Gutenberg get page template value when post updated?
- rest_post_query on multiple post types?
- WP Rest API convert permalink to post ID for fetch
- Does accessing WordPress via REST API affect the site stats and analytics?
- Wp Rest Api Custom Endpoint for page subpages
- Request object for validate_callback
- x-wp-nonce is not allowed by Access-Control-Allow-Headers in preflight response
- WordPress REST API “rest_authentication_errors” doesn’t work external queries?
- How should an old API version be deprecated gracefully?