2019-10-21 03:11:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Plugin Name: WooCommerce Admin Add Task Example
|
|
|
|
*
|
2020-08-11 19:18:47 +00:00
|
|
|
* @package WooCommerce\Admin
|
2019-10-21 03:11:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-10-27 19:03:27 +00:00
|
|
|
* Register the task.
|
2019-10-21 03:11:21 +00:00
|
|
|
*/
|
2021-10-27 19:03:27 +00:00
|
|
|
function add_task_my_task() {
|
2023-05-18 03:21:53 +00:00
|
|
|
require_once __DIR__ . '/class-mytask.php';
|
|
|
|
$task_lists = \Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists::instance();
|
|
|
|
|
|
|
|
// Add the task to the extended list.
|
|
|
|
$task_lists::add_task(
|
2021-10-27 19:03:27 +00:00
|
|
|
'extended',
|
2023-05-18 03:21:53 +00:00
|
|
|
new MyTask(
|
|
|
|
$task_lists::get_list( 'extended' ),
|
2021-10-27 19:03:27 +00:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
add_action( 'init', 'add_task_my_task' );
|
2019-10-21 03:11:21 +00:00
|
|
|
|
2021-10-27 19:03:27 +00:00
|
|
|
/**
|
|
|
|
* Register the scripts to fill the task content on the frontend.
|
|
|
|
*/
|
|
|
|
function add_task_register_script() {
|
2019-10-21 03:11:21 +00:00
|
|
|
if (
|
2022-03-09 14:04:34 +00:00
|
|
|
! class_exists( 'Automattic\WooCommerce\Internal\Admin\Loader' ) ||
|
|
|
|
! \Automattic\WooCommerce\Admin\PageController::is_admin_or_embed_page()
|
2019-10-21 03:11:21 +00:00
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-23 22:10:32 +00:00
|
|
|
$asset_file = require __DIR__ . '/dist/index.asset.php';
|
2019-10-21 03:11:21 +00:00
|
|
|
wp_register_script(
|
|
|
|
'add-task',
|
|
|
|
plugins_url( '/dist/index.js', __FILE__ ),
|
2021-03-23 22:10:32 +00:00
|
|
|
$asset_file['dependencies'],
|
|
|
|
$asset_file['version'],
|
2019-10-21 03:11:21 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_enqueue_script( 'add-task' );
|
|
|
|
}
|
2020-12-11 02:29:45 +00:00
|
|
|
|
2021-01-27 18:40:02 +00:00
|
|
|
add_action( 'admin_enqueue_scripts', 'add_task_register_script' );
|