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
Solving this took a good twenty hours of my life away, and maybe it's "common sense" but I thought it might be good to keep here as a note for some future troubleshooting reference.
The example plugin works on page load by checking GET for process and nonce, then pushing strings to the queue.
For my logic, I needed two changes: a class instance be pushed to the queue instead of a string, and the trigger to be a php function called by AJAX, which I declared in functions.php like this:
$instance = new Example_Background_Processing()
$instance->handle_all();
after adjusting handle_all to public, and having handle_all instantiate instances of a class to push_to_queue, instead of the names.
When WP_Background_Process->task($item) is called this way, rather than from the plugin declaration, PHP often - but importantly, not always! - does not recognize the class of the instantiated class object being pushed to the queue as having been declared, and re-casts that object as __PHP_Incomplete_Class containing the instantiated object.
This adds an extra layer, breaking references to variables in functions. But if you're testing this several times in a row, sometimes the background process DOES recognize the class, and lets it go through as intended. Which is awesome for troubleshooting.
So, in order to call this handle_all function via AJAX in functions.php, I needed to include/define the class that I was creating and passing to task($item) at the top of functions.php, even though it wasn't being used until handle_all(), which allowed PHP to always see the class as correctly defined during task($item), and not recast it.
The text was updated successfully, but these errors were encountered:
Solving this took a good twenty hours of my life away, and maybe it's "common sense" but I thought it might be good to keep here as a note for some future troubleshooting reference.
The example plugin works on page load by checking GET for process and nonce, then pushing strings to the queue.
For my logic, I needed two changes: a class instance be pushed to the queue instead of a string, and the trigger to be a php function called by AJAX, which I declared in functions.php like this:
after adjusting handle_all to public, and having handle_all instantiate instances of a class to push_to_queue, instead of the names.
When WP_Background_Process->task($item) is called this way, rather than from the plugin declaration, PHP often - but importantly, not always! - does not recognize the class of the instantiated class object being pushed to the queue as having been declared, and re-casts that object as __PHP_Incomplete_Class containing the instantiated object.
This adds an extra layer, breaking references to variables in functions. But if you're testing this several times in a row, sometimes the background process DOES recognize the class, and lets it go through as intended. Which is awesome for troubleshooting.
So, in order to call this handle_all function via AJAX in functions.php, I needed to include/define the class that I was creating and passing to task($item) at the top of functions.php, even though it wasn't being used until handle_all(), which allowed PHP to always see the class as correctly defined during task($item), and not recast it.
The text was updated successfully, but these errors were encountered: