Closed shoroar closed 1 year ago
did you get it working ?
Could the problem be that there is no background process to work on the queue once WP has finished the request to activate the plugin? If I am not mistaken, you have to instantiate the background process on every WP load (i.e. that is why it works when you instantiate with 'plugins_loaded').
dispatch() will 'only' launch a new asynchronous request to WP. To serve this request, the server will launch a new instance of WP that can be used to do the work on the queue. If I am not mistaken, this new instance will not run the code to activate the plugin, so with your design, there is no background process to do the processing.
If you instantiate the background process on 'plugins_loaded', each WP instance has the background process and the processing can start. I believe this is actually intended behavior since the background process may die or time out and processing may only resume once WP_cron spins up a new instance of WP.
Closing ancient issue. :smile:
(duplicate of #21)
Hello, I am using plugin boilerplate of DevinVinson/WordPress-Plugin-Boilerplate. I want to use the background processing when the plugin is activated. my code is
the WP table options have a new row:
wp_background_process_batch_1f8a9447c3ecec7570a4de37af
But
Plugin_Name_Background_Processing() task($item) is never called. What is the problem????
when When I instantiate the class on 'plugins_loaded' action, it works just fine.
I want to work the background processing when activate the plugin, not with 'plugins_loaded' action