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
- How to use WP-REST API to login user and get user data for Android app?
- WP REST API returns blank response if post is too long
- REST API endpoint for elasticpress autosuggest
- How can I get users email (and additional data) from the rest API?
- How to feed a HTML5’s EventSource with a REST API custom endpoint?
- Retrieve CSS and JS From the REST API
- How to Authenticate WP REST API with JWT Authentication using Fetch API
- How to: Rest endpoint returning empty object
- REST API multiple media upload
- Can’t send emails through REST API
- 401 Error when trying to make a REST API call to site
- Does jQuery/Ajax send cookies when using the rest API or do I need to somehow add them?
- How to login to WordPress site using basic authentication HTTP headers?
- Can we access the REST request parameters from within the permission_callback to enforce a 401 by returning false?
- Upload image to wordpress using REST API
- Filter post content in REST API
- WP Rest API convert permalink to post ID for fetch
- Formating content rendered from wordpress REST API as JSON and not HTML
- How to filter users on custom meta fields in WP JSON v2?
- How can I return an image from a custom REST API endpoint?
- How add meta fields to a user with the wp-api?
- WordPress Rest API response
- Check Password Strength using WordPress API
- Why does AWStats show /wp-json* as Viewed URLs
- How send get request to external api with username and password
- permission_callback has no effect
- Updating link on page via REST api
- How to order WordPress Rest API data
- WP Rest API – How to convert embedded to json object in Java [closed]
- featured image not found in json from wp rest api
- WP REST API – Nonce passes wp_verify_nonce even after logout
- WP REST API plugin 500 errors?
- New user signup via REST API
- is it possible to filter a rest api endpoint by using a registered rest field?
- rendering view in backbone
- Update a post based on results from GET request to another server
- WP REST API can’t set post tags
- Manipulating/view postmeta remotely
- WP API post__not_in is not working
- Check authentication credentials using WP REST API
- WordPress REST API V2: how to get list of all posts?
- Getting 401 from ajax using an application password
- How to connect android app with WordPress website?
- WordPress REST API calls that depend on the WordPress User
- Sidebar endpoint using WordPress API
- How to get data from /wp-json/wp/v2/users/me
- Get custom posts in gutenberg block
- WordPress REST API parameters are not affecting a response
- Getting 401 (access denied) when trying to use the REST API
- Update meta_value in wp_postmeta using API
- WP_REST_Response – How to return Gzip answer and add Content-encoding header?
- WordPress plugin with CORS
- WordPress REST API not working on localhost
- User following system via REST API
- REST API – Allow /users endpoint depending on a custom capability
- “Error: cURL error 60: SSL certificate problem: certificate has expired” when create product in WooCommerce via REST API
- How to use WordPress REST api to login a user?
- Can I overwrite default WordPress Json API For no more pages text
- Secure WordPress API, how?
- Create User with Profile and Cover Images using REST API
- Wrong encoding of dynamic block properties problem when loggen in as editor
- Media gallery images url instead of ID on WP API
- Remove unwanted fields from WP API response
- Need wp rest api for featured video post
- WordPress API “code”:”rest_no_route” with Custom Route
- Need to forward Data from WooCommerce Webhook sent to same site WordPress REST API custom endpoint
- WordPress Update Role using API Cross site
- Rest API. Post content
- REST api header link href
- Error rest_post_invalid_page_number trying to call Rest API
- WordPress & React Native
- update meta data (like view counter) by rest-api
- Rest API hook ‘rest_insert_post’ not returning request object
- How Can I keep password protected posts in the json requests but not on frontend queries?
- REST API Integration without user account?
- WP_REST_Request::get_json_params() Parsing null as Zero
- WP REST API with Basic Auth at target website
- Getting current core version from an WordPress installation
- How to block external access to register_rest_route callback?
- Filter output of posts (Rest API)
- WordPress Application Passwords not authorizing
- Rest API nonce is being cached
- WordPress custom endpoint returns Security violated
- custom REST endpoints and application passwords
- Hide custom posts from certain taxonomy in rest api
- Creating Application Password using REST API results in 401 regardless of JWT token