Informations about the task system and how to setup one:
Task Manager - MyBB Documentation
Every task is connected to a file in the
inc/tasks directory, which name is specified in the field "Task File". In this file you will specify what to do when your task is performed inside a function named
task_filename
, where filename is obv the name of the file connected to the task.
How to integrate it with a plugin? As you can see, to set up a task you just need to add a new task from the task manager (that is gonna insert a new row in the
mybb_tasks
table) and create a file connected to the task in the tasks directory. So, for integrating it with a plugin you just need to insert a new row in the
mybb_tasks
table during plugin installation with the specifics of your task, something like:
require_once MYBB_ROOT . '/inc/functions_task.php';
$new_task = [
'title' => 'Task Name',
'description' => 'Task Description.',
'file' => 'filename',
'minute' => '0',
'hour' => '0',
'day' => '*',
'month' => '*',
'weekday' => '*',
'enabled' => '1',
'logging' => '1',
];
$new_task['nextrun'] = fetch_next_run($new_task);
$db->insert_query('tasks', $new_task);
$cache->update_tasks();
And include in your plugin files a new file in the
inc/tasks directory:
<?php
function task_filename($task)
{
global $mybb;
/*
* Your task operations
*/
add_task_log($task, "This plugin task successfully ran.");
}