Found the solution: By casting the return value to an object, it is ensured that in case of an empty array, an empty object will be returned on REST request.
Enhancing on my initial example, this code would work:
function rest_cb() {
return (object) array();
}
Related Posts:
- Custom endpoint that returns an xml
- Can’t retrieve body params from PUT endpoint using formdata
- Do I need to create an endpoint?
- REST Endpoint API 404
- Custom Endpoint – Does it possible to use PUT method with WP API Rest?
- GET request return value as error instead of success
- Is it possible to make WordPress as a RESTful app?
- oneOf two possible objects in WP REST API?
- How to check WordPress website username and password is correct
- How to Rewrite WordPress URL for a Plugin
- WordPress REST API call generates nonce twice on every call
- Plugin Sidebar is not Saving Meta Attribute to Post/Page after “Update”
- get all products of one category
- Rest Api How to get results of child categories with one api call
- Endpoint on Specific Page Slug
- WP rest api v2 posts filter by ‘search’ & ‘category_name’ not working
- What method to use to call a REST API?
- Continue execution after WP REST API response
- Generate dynamic page through data from another page
- WP REST API V2 – Add user data to response
- How can I pass get_the_author_meta(‘user_email’) through the REST API?
- How to get results of subcategories also?(WP Rest Api v2)
- Amending REST API function without deactivate/activate plugin every time changes is made
- Create a new post using rest api and save featured image using an external image url
- Why does wp_remote_post returns an empty body response on certain endpoints?
- Adding custom end points, No error line
- Custom endpoint to get all custom taxonomy terms
- Serve text/html from wp-json API via WPEngine, headers not being set properly
- How to enqueue or include json file to a plugin
- Secure REST with nonce works only when not logged
- How to do POST request with WP REST API v2 to custom table?
- Help writing custom function with rewrite endpoint that generates a page from dynamic content
- wordpress JSONAPI introspector always limits number at 10?
- rest_no_route on custom API endpoint wordpress
- json_decode does not work on WordPress
- wordpress is adding a second backslash when I use addslashes
- Custom Rest Endpoint: Post/Put/Patch not working
- JSON – Create rest api endpoint for Advanced Custom Fields
- WordPress Rest API with rest_do_request, possible race condition?
- How to use apiFetch to get author information in Gutenberg properly?
- WooCommerce Endpoints content
- Mock a dependency of a WP_REST_Controller class
- update_callback is not working in register_rest_field
- How to call code when adding WooCommerce menu items via woocommerce_account_menu_items
- Plugin Development: Storing and Manipulating Data That Fits JSON in Database
- How to write a shopping queue line plugin with a queue button?
- Allow REST API Endpoint to specific user and hide from public
- How to do admin ajax request in a plugin for rest api
- Showing results from json-string in WordPress search results page
- Attaching Image-file to userId
- Query String Filtering API
- Custom plugin & calling REST api of wordpress instance the plugins is running on
- howTo let wordpress endpoint return html-page
- How to query a nested field in wordpress api using _fields param
- Get Custom taxonomy parent with wordpress REST API
- register_meta not showing custom post type metabox data in rest api
- why is apiFetch throwing Unhandled Promise Rejection: TypeError: Object is not a function
- Securing custom rest API endpoints with public access from PWA
- WP_Query not ordering correctly
- What’s the right way to validate JSON data coming from an AJAX POST request?
- 403 error rest_’cookie_invalid_nonce’ on API Request
- Adding Amchart Interface to WordPress API
- ajax response strips multidimensional array and unable to decode
- WC REST API Error Handling
- Initializing rest endpoint issue
- Multisite and the JSON REST API: How to?
- React in plugins: REST endpoints vs. regular functions
- Query only title/field/featured media of posts [closed]
- WP API users per page
- Endpoint Callback Display for Custom Plugin
- Best place to keep files that are called by cron jobs?
- Developing a plugin, ran it through P3 Profiler, shows up slow, but I don’t know why
- Is it safe to use PUT and DELETE requests
- How to Rewrite WordPress URL for a Plugin
- How to Rewrite WordPress URL for a Plugin
- How to update WordPress Plugins in your own maintance application?
- Extend Plugin that creates an endpoint for GET request to also accepts POST requests
- Custom rest api endpoint response json problem
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- Rest Api WordPress
- Programmatically creating posts based on external JSON feed (asynchronously)
- External api call using wordpress
- Does WP REST API cache internally executed (rest_do_request) requests?
- Run different permission_callback depending on HTTP method of custom REST API endpoint
- REST API error in block editor for custom templates
- How do I add multiple custom menu Woo-commerce my account page?
- How to get locale within WP REST Request?
- Execute callback after REST API request completes + Response is sent
- How to boost WP custom post REST API GET queries by custom taxonomies
- How to debug a plugin with Xdebug?
- How to prevent loading of all plugin’s resources?
- Is it possible for a plugin to register a page template file?
- Error “Call to a member function switch_to_locale() on null” during insert_with_markers
- Show error, when selecting image in WordPress media uploader if params mismatch
- Redeclaring a plugin function within a class
- Will I get an error if I try unscheduling a WP Cron scheduled task that wasn’t scheduled?
- How to update global variables in plugin activation callback?
- How to include a page template and template part into my plugin
- Why does do_action pass a blank string as the first parameter if no $arg is set?
- problem with blank page