Register new task

If a new task is needed, there are only two required steps that are needed.

A class needs to be created and this class needs to extend the TheFrosty\WpUpgradeTaskRunner\Api\AbstractTaskRunner class. See the ExampleMigrationTask example class.

Register the new task class via the TheFrosty\WpUpgradeTaskRunner\Tasks\TaskLoader::REGISTER_TASKS_TAG filter:

use TheFrosty\WpUpgradeTaskRunner\Tasks\TaskLoader;

\add_filter(TaskLoader::REGISTER_TASKS_TAG, static function(array $tasks): array {
    $tasks[] = new \Project\SomeCustomTask();
    return $tasks;
});

Your task class

When a class is added, it needs to have a few pre-defined class constant values: DATA, DESCRIPTION and TITLE; both the DATE and TITLE constants are required to be unique. These are what registers a one off cron task when manually running the task from the admin page.

Leave a Reply

Your email address will not be published.