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
|
|
|
*/
|
|
|
|
|
2022-03-17 20:10:43 +00:00
|
|
|
use Automattic\WooCommerce\Internal\Admin\Onboarding;
|
2021-10-27 19:03:27 +00:00
|
|
|
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\Task;
|
|
|
|
use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
|
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() {
|
|
|
|
TaskLists::add_task(
|
|
|
|
'extended',
|
|
|
|
array(
|
|
|
|
'id' => 'my-task',
|
|
|
|
'title' => __( 'My task', 'woocommerce-admin' ),
|
|
|
|
'content' => __(
|
|
|
|
'Add your task description here for display in the task list.',
|
|
|
|
'woocommerce-admin'
|
|
|
|
),
|
|
|
|
'action_label' => __( 'Do action', 'woocommerce-admin' ),
|
|
|
|
'is_complete' => Task::is_task_actioned( 'my-task' ),
|
|
|
|
'can_view' => 'US' === WC()->countries->get_base_country(),
|
|
|
|
'time' => __( '2 minutes', 'woocommerce-admin' ),
|
|
|
|
'is_dismissable' => true,
|
|
|
|
'is_snoozeable' => true,
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
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' );
|