woocommerce / woocommerce-legacy-rest-api

The legacy WooCommerce REST API, which used to be part of WooCommerce itself but is removed as of WooCommerce 9.0.
10 stars 11 forks source link

Correct the logic that removes legacy API/HPOS compatibility notices. #14

Closed barryhughes closed 5 months ago

barryhughes commented 5 months ago

In some circumstances, deactivating the Legacy REST API plugin can lead to a fatal error (see reports here). The core problem seems to be our remove_notice() calls reference the wrong class.

fatal-error

Steps to replicate

Although some of the reports we've received reference multisite networks, it is entirely possible to replicate the problem using a single site setup:

  1. Install and activate WooCommerce.
  2. Enable HPOS (though, if you start with a recent version of WooCommerce, it will probably already be active).
  3. Install and activate the WooCommerce Legacy REST API plugin.
  4. Deactivate it and a fatal error will occur, as in the above screenshot. However, I'm using Query Monitor, and so am provided with additional information: the error you see may contain less information.

Testing instructions

  1. Start with WooCommerce, and HPOS enabled.
  2. If you are testing with a version of WooCommerce where https://github.com/woocommerce/woocommerce/pull/40627 hasn't been merged yet (so 8.9 or older, or a development version of 9.0) you need to explicitly enable the Legacy REST API (WooCommerce - Settings - Legacy API).
  3. Install the WooCommerce Legacy REST API plugin.
  4. You should now see a warning notice, as follows:
hpos-compat
  1. Deactivate the plugin.
    • Before this change, you would encounter the fatal error documented in the PR's introduction.
    • With this change, there should be no fatal error and the above notice should be removed.
barryhughes commented 5 months ago

🔢 I have not yet bumped the version number, in case any other issues are revealed during testing.

📝 I did also make some small corrections to existing changelog entries, as the headers and bullets were not formatted correctly:

Screenshot 2024-05-15 at 19 24 05