WP REST API and Access-Control-Allow-Origin

I found a .htaccess solution, but I will be happy if anyone know a working PHP solution. It’s my .htaccess with multiple domain access support and access for only GET request: # CORS Headers <ifModule mod_headers.c> SetEnvIf Origin “^http(s)?://(.+\.)?(localhost:8080|example\.com|example\.net)$” origin_is=$0 Header always set Access-Control-Allow-Origin %{origin_is}e env=origin_is Header always set Access-Control-Allow-Methods “GET” Header always set Access-Control-Allow-Headers … Read more

How to clone all WordPress Rest API end points

There is nothing wrong if API returns more than what you need. Unless there is a security/privacy issue it is unlikely that the additional info will matter. If you totally can not live with core’s API, you need to just write your own. “cloning”, “forking” or any other nice term you might want to use … Read more

Using the WordPress and WooCommerce REST APIs in the same Node app

I thought I’d share my solution for anyone working on a similar problem. I ended up switching to node-wpapi and using REST Autodiscovery to enable use of the WooCommerce & WordPress APIs from a single library. This can be done like so: const wpapi = require(‘wpapi’) let wp = new wpapi({ endpoint: ‘http://your.wp.site/wp-json/’, username: ‘user’, … Read more

How to add an endpoint to WP

You need to return a WP_REST_Response object instead of an array. See https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/ and https://developer.wordpress.org/reference/classes/wp_rest_response/.