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
|
|
|
*/
|
|
|
|
|
|
|
|
use Automattic\WooCommerce\Admin\Features\Onboarding;
|
|
|
|
|
|
|
|
/**
|
2020-12-11 02:29:45 +00:00
|
|
|
* Register the task list item and the JS.
|
2019-10-21 03:11:21 +00:00
|
|
|
*/
|
|
|
|
function add_task_register_script() {
|
|
|
|
|
|
|
|
if (
|
|
|
|
! class_exists( 'Automattic\WooCommerce\Admin\Loader' ) ||
|
2021-09-02 21:40:02 +00:00
|
|
|
! \Automattic\WooCommerce\Admin\Loader::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
|
|
|
|
);
|
|
|
|
|
|
|
|
$client_data = array(
|
|
|
|
'isComplete' => get_option( 'woocommerce_admin_add_task_example_complete', false ),
|
|
|
|
);
|
|
|
|
wp_localize_script( 'add-task', 'addTaskData', $client_data );
|
|
|
|
wp_enqueue_script( 'add-task' );
|
2021-01-27 18:40:02 +00:00
|
|
|
add_filter( 'woocommerce_get_registered_extended_tasks', 'pluginprefix_register_extended_task', 10, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register task.
|
|
|
|
*
|
|
|
|
* @param array $registered_tasks_list_items List of registered extended task list items.
|
|
|
|
*/
|
|
|
|
function pluginprefix_register_extended_task( $registered_tasks_list_items ) {
|
|
|
|
$new_task_name = 'woocommerce_admin_add_task_example_name';
|
|
|
|
if ( ! in_array( $new_task_name, $registered_tasks_list_items, true ) ) {
|
|
|
|
array_push( $registered_tasks_list_items, $new_task_name );
|
|
|
|
}
|
|
|
|
return $registered_tasks_list_items;
|
2019-10-21 03:11:21 +00:00
|
|
|
}
|
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' );
|