lambry / batchpress
WordPress plugin to help process data in batches.
Installs: 8
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 2
Forks: 0
Open Issues: 0
Type:wordpress-plugin
pkg:composer/lambry/batchpress
Requires
- php: >=7.4
- composer/installers: ~1.0
This package is auto-updated.
Last update: 2025-12-15 05:13:13 UTC
README
BatchPress is a little plugin to help process data in batches, with BatchPress you can run, monitor and cancel batched jobs.
Install: composer require lambry/batchpress
Usage
To use BatchPress create a new class per job and register those classes using the batchpress/jobs filter.
Job class outline:
- Required:
labelproperty to describe the job. - Required:
processmethod which is passed a single item for processing; any info/errors can be returned and will be displayed in the log. - Optional|Required:
itemsmethod is optional if the upload property is set to true, in this case it can be used to filter the uploaded content before staring the job. If upload if false or not defined the method is then required to return an array of items for processing. - Optional:
uploadproperty to tell BatchPress if a CSV upload is required. - Optional:
batchproperty to set the number of items to process per batch. - Optional:
descriptionproperty to provide extra details about the job.
Basic Example
class Update { public $batch = 10; public $label = 'Update data'; // Prepare an array of items for processing public function items() : array { } // Process each item and optionally return log info public function process($item) : mixed { } }
Example with CSV upload
class Import { public $batch = 10; public $upload = true; public $label = 'Import data'; // Optionally filter and format the uploaded content before processing public function items(array $data) : array { } // Process each item and optionally return log info public function process($item) : mixed { } }
Registering jobs
add_filter('batchpress/jobs', fn() => [Update::class, Import::class]);
Helpers
BatchPress provides some helper methods as well, to use them just include the Helpers trait in your job class.
use Lambry\BatchPress\Helpers; class Update { use Helpers; public function process($item) : mixed { // Adding an image to a post $id = this->uploadImage($item['url'], $item['id'], $item['title']); // Adding a file to a post $id = this->uploadFile($item['url'], $item['id'], $item['title']); } }
