It’s not good practice to trigger a fatal error (or to use die
or exit
).
trigger_error() found. Debug code should not normally be used in production. (WordPress.PHP.DevelopmentFunctions.error_log_trigger_error)
Imagine you’re troubleshooting a problem on a site. You disable all the plugins, address the cause of the problem and are about to re-enable all the plugins. So you select-all on the plugins screen, and choose enable. Any plugins that come alphabetically before WooCommerce will be activated before it. If they check for WooCommerce and trigger a fatal error, the process stops and no further plugins are activated, even though the user wanted to activate all their plugins including WooCommerce.
I’ve had this happen on a live site and it just added to the stress of fixing the issue.
So why do plugins do this check? It’s partly so WooCommerce’s functions (e.g. wc_get_order()
) aren’t accessed when WooCommerce’s files have not been loaded. The correct way to get around this is to use WooCommerce’s hooks – i.e. you can safely infer that WooCommerce is loaded when your code is running on the ‘woocommerce_process_shop_order_meta’ hook!
If a plugin wants to communicate to a user that a required plugin is missing, a much better way is to use an admin notice. Even then, I don’t think a plugin like this, with “Woo” in its name, really needs to tell the users they need WooCommerce!
I’ll open a PR to remove this if it’s welcome.