1. Go to this page and download the library: Download duckdev/wp-queue-process library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
duckdev / wp-queue-process example snippets
class WP_Example_Request extends \DuckDev\Queue\Async {
/**
* @var string Unique action name.
*/
protected $action = 'example_request';
/**
* Perform the work. The dispatched data is available in $_POST.
*/
protected function handle() {
// Actions to perform.
}
}
class WP_Example_Process extends \DuckDev\Queue\Task {
/**
* @var string Unique action name.
*/
protected $action = 'example_process';
/**
* Process a single queue item.
*
* Return the (optionally modified) item to push it back for another
* pass, or false to remove it from the queue.
*
* @param mixed $item Queue item to process.
* @param string $group Group name the item was saved under.
*
* @return mixed
*/
protected function task( $item, $group ) {
// Actions to perform.
return false;
}
/**
* Optional. Runs once the queue is fully drained.
*/
protected function complete() {
parent::complete();
// Show a notice, log, etc.
}
}
$this->example_process = new WP_Example_Process();
foreach ( $items as $item ) {
$this->example_process->push_to_queue( $item );
}
// Or set the whole queue at once when the data is already shaped correctly:
// $this->example_process->set_queue( $items );
$this->example_process->save( 'my-group' )->dispatch();
$process = new WP_Example_Process( new MyCustomStore( 'my_plugin_example_process' ) );