We've received internal reports of some sites we manage getting the following fatal error:
PHP Fatal error: Uncaught Error: Class "WooCommerce\Square\Gateway\Blocks_Handler" not found
in .../plugins/woocommerce-square/woocommerce-square.php:430
After looking into this, I found that we're init'ing our blocks handler code and our autoloader behind two different conditions, which results in cases where register_payment_method_block_integrations() is trying to call new WooCommerce\Square\Gateway\Blocks_Handler() without our autoloader existing.
For instance:
Registering our blocks handler requires is_environment_compatible() to pass which checks for PHP 7.4+
Init'ing our autoloader requires is_environment_compatible() + plugins_compatible() which also checks that WP version is 6.3+ and WC version is 8.7+.
What this difference means is if a store has WooCommerce 8.6 installed (an unsupported version), the autoloader won't be init'ed, however, the block handler code will still try to register our block integration classes resulting in the fatal error.
To reproduce
Install and activate WooCommerce 8.6 and the latest WooCommerce Square
Load any WP Admin page
Note the fatal error:
Environment (please complete the following information):
Describe the bug
We've received internal reports of some sites we manage getting the following fatal error:
After looking into this, I found that we're init'ing our blocks handler code and our autoloader behind two different conditions, which results in cases where
register_payment_method_block_integrations()
is trying to callnew WooCommerce\Square\Gateway\Blocks_Handler()
without our autoloader existing.For instance:
is_environment_compatible()
to pass which checks for PHP 7.4+is_environment_compatible()
+plugins_compatible()
which also checks that WP version is 6.3+ and WC version is 8.7+.What this difference means is if a store has WooCommerce 8.6 installed (an unsupported version), the autoloader won't be init'ed, however, the block handler code will still try to register our block integration classes resulting in the fatal error.
To reproduce
Environment (please complete the following information):
Additional details
System status
``` ```