Fatal error if WooCommerce disabled only on a specific page
-
Hello
I’m the author of Freesoul Deactivate Plugins https://wordpress.org/plugins/freesoul-deactivate-plugins/
FDP lets you disable plugins on specific pages.
The website of a user is triggering a fatal error because he has disabled WooCommerce on a specific page, and RankMath has some code that depends on WooCommerce.The fatal error is triggered in wp-content/plugins/seo-by-rank-math/includes/class-post.php on line 176 because the function is_cart doesn’t exist if WooCommercee is disabled.
Probably you are checking if WooCommerce is active looking at the output of the option ‘active_plugins’. The output of that option can be filtered by other plugins, in this case, Freesoul Deactivate Plugins. So I suggest checking if WooCommerce is active by checking the existence of its classes or functions and don’t trust the output of ‘active_plugins’.
In this case according to the option ‘active_plugins’ WooCommerce is active, because FDP doesn’t change that option, but on the page where the fatal error is triggered, the filter applied on ‘active_plugins’ before WooCommerce is loaded return s an array of plugins without WooCommerce, then after all plugins are loaded FDP removes all its filters.If in your code you check if WooCommerce is active looking on the option ‘active_plugins’ after all plugins are loaded, you will think WooCommerce is active because at that point FDP has already removed all its filters. If it didn’t remove them, it would create problems when other plugins save the option active_plugins, because that option would be saved with the wrong set of plugins.
Let me know if you need more information from my side.
I think the problem can be easily solved wrapping your code in something that looks like:
if( function_exists( ‘is_cart’ ) ){
//your code
}or whatever ensures that WooCommerce is active.
- The topic ‘Fatal error if WooCommerce disabled only on a specific page’ is closed to new replies.