yiv-dev / wp-scheduller
helps add and remove the wpcron tasks
Installs: 128
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:wordpress-helper
Requires
- php: >=7.2.0
- phpunit/phpunit: ^8
Requires (Dev)
- 10up/wp_mock: ^0.4.2
This package is auto-updated.
Last update: 2024-05-23 20:01:44 UTC
README
add the task
use YIVDEV\WPSCHEDULLER\wpScheduller;
$scheduler = new wpScheduller('test_task');
$scheduler
->setPeriod(10800)
->setTaskClass('Path\\to\\Your\\Task\\Class')
->setTaskClassParameters(['id' => 999]);
$scheduler->set_cron_task();
You can create your task Clas:
use YIVDEV\WPSCHEDULLER\TaskInterface;
class TestTask implements TaskInterface
{
private $id;
public function run(): void
{
try {
$file = \uniqid() . '_' . $this->id . '_test.txt';
$content = 'TEST CONTENT';
file_put_contents($file, $content);
} catch (\Exception $e) {
throw $e;
}
}
public function setParameters(array $parameters): void
{
try {
$this->id = $parameters['id'];
} catch (\Exception $e) {
throw $e;
}
}
}
remove the task
$scheduler = new wpScheduller('test_task');
$scheduler->remove_cron_task();
get the jobs
$scheduler = new wpScheduller('test_task');
$scheduler->get_wpcron_jobs();