You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Find how other plugins are behaving. For example see how paypal woocommerce gateway still uses plugins_loaded to called bootstrap() function but avoids it running multiple times by checking a flag variable
Also looks like we have too much initialization code in one place. Anyway we can follow better practices
The text was updated successfully, but these errors were encountered:
shivaenigma
changed the title
blockonomics_woocommerce_init repeatedly getting called
blockonomics_woocommerce_init repeatedly getting exceuted on each page load
Feb 17, 2021
Investigating into Paypal's Plugin as mentioned, it seems they're using the _bootstrapped variable to deal with this, but that is more of a fail-safe than a solution. It just prevents the plugin to bootstrap twice if it happens sometimes.
Upon several tests, I found that the reason you must be seeing the "Calling Woocommerce Init" is because the hook plugins_loaded is executed multiple times, but it's only being executed once per page load, the reason you're seeing it multiple times is because of the AJAX Requests such as wc-ajax, or sometimes static resources such as favicons or combined js/css files may trigger the page loads in WordPress causing the plugin to be initialised for that request and it seems that the function is being called twice, to test it out I made the following changes:
On seeing the logs, "Plugin Already Initialized" was never called! Check Screenshots below:
We can break down the code into different functions for modularity, but we should do it in a separate release.
This can be verified by this patch
Find how other plugins are behaving. For example see how paypal woocommerce gateway still uses plugins_loaded to called bootstrap() function but avoids it running multiple times by checking a flag variable
Also looks like we have too much initialization code in one place. Anyway we can follow better practices
The text was updated successfully, but these errors were encountered: