You can find a complete example of how to add a custom task as a WordPress plugin in the [examples directory](../examples/extensions/add-task/).
## Models and classes
### TaskLists
The `TaskLists` class serves as a data store for tasks, providing functionality to create, initialize, add tasks, retrieve task lists, and perform other task management operations.
#### Methods
-`TaskLists::instance()`: Returns the class instance of the `TaskLists` interface.
-`TaskLists::init()`: Initializes the task lists. This method should be called to set up the necessary configurations and hooks for task management.
-`TaskLists::is_experiment_treatment($name)`: Checks if an experiment is the treatment or control. This is internally used by Woo.
-`TaskLists::init_default_lists()`: Initializes the default task lists. This method adds predefined task lists with their properties and tasks.
-`TaskLists::init_tasks()`: Initializes the tasks. This method should be called to initialize the tasks associated with the task lists.
-`TaskLists::set_active_task()`: Temporarily stores the active task to persist across page loads when necessary. This method is used to manage active tasks.
-`TaskLists::add_list($args)`: Adds a task list with the specified properties.
-`TaskLists::add_task($list_id, $args)`: Adds a task to the specified task list.
The `Task` class represents a task. It contains properties and methods for managing tasks. You can see the predefined tasks in [this directory](https://github.com/woocommerce/woocommerce/tree/trunk/plugins/woocommerce/src/Admin/Features/OnboardingTasks/Tasks).
Please note that the `Task` class is abstract and intended to be extended by custom task classes.
#### Example
```php
<?php
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
-`$task->get_id(): string`: Returns the ID of the task.
-`$task->get_title(): string`: Returns the title of the task.
-`$task->get_content(): string`: Returns the content of the task.
-`$task->get_time(): string`: Returns the estimated time to complete the task.
-`$task->get_parent_id(): string`: Returns the ID of the parent task list.
-`$task->get_parent_options(): array`: Returns the options of the parent task list.
-`$task->get_parent_option($option_name): mixed|null`: Returns the value of a specific option from the parent task list.
-`$task->prefix_event($event_name): string`: Returns the event name prefixed with the task list's event prefix.
-`$task->get_additional_info(): string`: Returns additional information about the task. Typically includes details, notes, or instructions related to the task itself.
-`$task->get_additional_data(): mixed|null`: Returns additional data associated with the task. It can be any type of data, such as arrays, objects, or simple values.
-`$task->get_action_label(): string`: Returns the label for the action button of the task.
-`$task->get_action_url(): string|null`: Returns the URL associated with the task's action.
-`$task->is_dismissable(): bool`: Checks if the task is dismissable.
-`$task->is_dismissed(): bool`: Checks if the task is dismissed.
-`$task->dismiss(): bool`: Dismisses the task.
-`$task->undo_dismiss(): bool`: Undoes the dismissal of the task.
-`$task->has_previously_completed(): bool`: Checks if the task has been completed in the past.
-`$task->possibly_track_completion(): void`: Tracks the completion of the task if necessary.
-`$task->set_active(): void`: Sets the task as the active task.
-`$task->is_active(): bool`: Checks if the task is the active task.
-`$task->can_view(): bool`: Checks if the task can be viewed based on store capabilities.
-`$task->is_complete(): bool`: Checks if the task is complete.
-`$task->is_visited(): bool`: Checks if the task has been visited.
-`$task->get_record_view_event(): bool`: Checks if the task view event should be recorded.
-`$task->convert_object_to_camelcase($data): object`: Converts an array's keys to camel case.
-`$task->mark_actioned(): bool`: Marks the task as actioned.
-`$task->is_actioned(): bool`: Checks if the task has been actioned.
-`$task->is_task_actioned($id): bool`: Checks if a specific task has been actioned.
-`$task->sort($a, $b, $sort_by): int`: Sorts tasks based on given sort criteria.
-`$task->get_json(): array`: Returns the task data as a JSON-formatted array.
We use the `@woocommerce/onboarding` package to render the onboarding task lists on the frontend and use the `@woocommerce/data` package to interact with the onboarding store.
The following REST endpoints are available to interact with tasks. For ease of use, we recommend using the data store actions above to interact with these endpoints.
The task UI can be supplemented by registering plugins that fill the provided task slots. Learn more about slot fills in the [SlotFill documentation](https://developer.wordpress.org/block-editor/reference-guides/slotfills/) and [here](https://developer.wordpress.org/block-editor/reference-guides/components/slot-fill/).
The items shown in the list can be customized beyond the default task list item. This can allow for custom appearance or specific `onClick` behavior for your task. For example, we're using this to install and activate WooPayments when clicking on the WooPayments task