yiv-dev/wp-scheduller

帮助添加和移除 wpcron 任务

安装: 150

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 0

开放问题: 0

类型:wordpress助手

dev-master 2021-03-23 13:09 UTC

This package is auto-updated.

Last update: 2024-09-23 20:42:12 UTC


README

添加任务

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();

您可以创建自己的任务类

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;
        }
    }
}

移除任务

$scheduler = new wpScheduller('test_task');
$scheduler->remove_cron_task();

获取作业

$scheduler = new wpScheduller('test_task');
$scheduler->get_wpcron_jobs();