Closed Konamiman closed 1 year ago
@barryhughes readme.txt
added, please check if something is incorrect or missing (especially in the list of contributors and tags).
Great, thanks @Konamiman! Left a couple of suggested tweaks but A) they are minor, so pre-emptively hitting approve so you can merge as soon as you and Jorge are happy B) confirmed the readme.txt file is valid :+1:
Context: The Legacy REST API will move to a dedicated extension in WooCommerce 9.0
This pull request adds an initial version of the Legacy REST API extension code and the README file to an otherwise still empty repository. It's intended to be tested together with WooCommerce, both with the latest one (still having the Legacy REST API built-in) and with a build that has the Legacy REST API removed (https://github.com/woocommerce/woocommerce/pull/40627).
Installing the extension
In a local environment: clone the repository directly inside the
wp-content/plugins
directory of the same WordPress install where you have WooCommerce (so the directory where all the plugin files are located iswp-content/plugins/woocommerce-legacy-rest-api
).In a remote test site: clone the repository, put all the files inside a
woocommerce-legacy-rest-api
directory (it can be the samewp-content/plugins/woocommerce-legacy-rest-api
directory if you have tested locally already) , and create a zip file containing that directory. Then you are ready to install the extension using the WordPress plugin install UI (Add New - Upload Plugin).Testing the extension
Testing the extension boils down to testing that the Legacy REST API continues working as expected, so the API documentation itself is the way to go. But in a nusthell:
http://localhost:8034/wc-api/v3/orders
. If you are testing locally (so no HTTPS) you'll need to use a tool capable of handling the OAuth authentication (e.g. Postman); otherwise:curl http://thehost/wc-api/w3/orders -u <consumer key>:<consumer secret>
Additionally, webhooks that are configured to be delivered with the legacy REST API payload format will continue to work when the extension is installed, and will fail "gracefully" (an exception will cause the delivery scheduled action to fail with an informative message) otherwise. More on that later.
Testing with old WooCommerce
Here "old WooCommerce" means any WooCommerce (it can be the latest released version, or the current trunk) that doesn't have https://github.com/woocommerce/woocommerce/pull/40627 applied.
wp plugin deactivate woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php
).wp option update woocommerce_api_enabled no
wp plugin activate woocommerce-legacy-rest-api/woocommerce-legacy-rest-api.php
).wp option get woocommerce_api_enabled
, expected value isno
).wp option update woocommerce_api_enabled yes
)wp option get woocommerce_api_enabled
, expected value isyes
).Testing webhooks
woocommerce_deliver_webhook_async
).Testing with new WooCommerce
Here "new WooCommerce" means WooCommerce with https://github.com/woocommerce/woocommerce/pull/40627 applied. You can check out the pull request branch locally, or use the WooCommerce Live Branches feature offered in the pull request itself.
Once the new WooCommerce is installed, and without the extension active, going to WooCommerce - Settings - Legacy API should look like this:
Trying to query any of the Legacy REST API endpoints should result in the "WooCommerce API is disabled on this site" error being returned.
After installing and activating the extension the settings page should have changed to:
...and the Legacy REST API endpoints should work as usual.
Test also the
/wp-json/wc/v3/settings/general/woocommerce_specific_allowed_countries
endpoint as it was using code that belonged to the legacy REST API package and has been moved to WooCommerce core.NOTE: The value of the disabled checkbox is taken from the
woocommerce_api_enabled
option, which for compatibility will continue to beyes
when the extension is enabled andno
when it's not (controlled by the activation/deactivation hooks of the extension). In fact, if the option has a value ofno
the Legacy REST API endpoints will continue to return the "WooCommerce API is disabled on this site" error even when the extension is active.For now, if an old WooCommerce that has the Legacy REST API enabled gets upgraded to a new one, the option will still be set to
yes
even if the extension is not installed. To fix this an upgrade migration needs to be added to https://github.com/woocommerce/woocommerce/pull/40627 so that if the Legacy API is enabled and the extension is not installed, the option value is changed tono
(also this would mean that the site is broken so we should probably add a loud admin notice too if that happens, or try to auto-install the extension).Testing webhooks