1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
<?php /** * WooCommerce Onboarding Helper */
namespace Automattic\WooCommerce\Internal\Admin\Onboarding;
use Automattic\WooCommerce\Admin\PageController; use Automattic\WooCommerce\Admin\Features\OnboardingTasks\TaskLists;
/** * Contains backend logic for the onboarding profile and checklist feature. */ class OnboardingHelper {
/** * Class instance. * * @var OnboardingHelper instance */ private static $instance = null;
/** * Get class instance. */ final public static function instance() { if ( ! static::$instance ) { static::$instance = new static(); } return static::$instance; }
/** * Init. */ public function init() { if ( ! is_admin() ) { return; }
add_action( 'current_screen', array( $this, 'add_help_tab' ), 60 ); add_action( 'current_screen', array( $this, 'reset_task_list' ) ); add_action( 'current_screen', array( $this, 'reset_extended_task_list' ) ); }
/** * Update the help tab setup link to reset the onboarding profiler. */ public function add_help_tab() { if ( ! function_exists( 'wc_get_screen_ids' ) ) { return; }
$screen = get_current_screen();
if ( ! $screen || ! in_array( $screen->id, wc_get_screen_ids(), true ) ) { return; }
// Remove the old help tab if it exists. $help_tabs = $screen->get_help_tabs(); foreach ( $help_tabs as $help_tab ) { if ( 'woocommerce_onboard_tab' !== $help_tab['id'] ) { continue; }
$screen->remove_help_tab( 'woocommerce_onboard_tab' ); }
// Add the new help tab. $help_tab = array( 'title' => __( 'Setup wizard', 'woocommerce' ), 'id' => 'woocommerce_onboard_tab', );
$setup_list = TaskLists::get_list( 'setup' ); $extended_list = TaskLists::get_list( 'extended' );
if ( $setup_list ) { $help_tab['content'] = '<h2>' . __( 'WooCommerce Onboarding', 'woocommerce' ) . '</h2>';
$help_tab['content'] .= '<h3>' . __( 'Profile Setup Wizard', 'woocommerce' ) . '</h3>'; $help_tab['content'] .= '<p>' . __( 'If you need to access the setup wizard again, please click on the button below.', 'woocommerce' ) . '</p>' . '<p><a href="' . wc_admin_url( '&path=/setup-wizard' ) . '" class="button button-primary">' . __( 'Setup wizard', 'woocommerce' ) . '</a></p>';
if ( ! $setup_list->is_complete() ) { $help_tab['content'] .= '<h3>' . __( 'Task List', 'woocommerce' ) . '</h3>'; $help_tab['content'] .= '<p>' . __( 'If you need to enable or disable the task lists, please click on the button below.', 'woocommerce' ) . '</p>' . ( $setup_list->is_hidden() ? '<p><a href="' . wc_admin_url( '&reset_task_list=1' ) . '" class="button button-primary">' . __( 'Enable', 'woocommerce' ) . '</a></p>' : '<p><a href="' . wc_admin_url( '&reset_task_list=0' ) . '" class="button button-primary">' . __( 'Disable', 'woocommerce' ) . '</a></p>' ); } }
if ( $extended_list ) { $help_tab['content'] .= '<h3>' . __( 'Extended task List', 'woocommerce' ) . '</h3>'; $help_tab['content'] .= '<p>' . __( 'If you need to enable or disable the extended task lists, please click on the button below.', 'woocommerce' ) . '</p>' . ( $extended_list->is_hidden() ? '<p><a href="' . wc_admin_url( '&reset_extended_task_list=1' ) . '" class="button button-primary">' . __( 'Enable', 'woocommerce' ) . '</a></p>' : '<p><a href="' . wc_admin_url( '&reset_extended_task_list=0' ) . '" class="button button-primary">' . __( 'Disable', 'woocommerce' ) . '</a></p>' ); }
$screen->add_help_tab( $help_tab ); }
/** * Reset the onboarding task list and redirect to the dashboard. */ public function reset_task_list() { if ( ! PageController::is_admin_page() || ! isset( $_GET['reset_task_list'] ) // phpcs:ignore CSRF ok. ) { return; }
$task_list = TaskLists::get_list( 'setup' );
if ( ! $task_list ) { return; } $show = 1 === absint( $_GET['reset_task_list'] ); // phpcs:ignore CSRF ok. $update = $show ? $task_list->unhide() : $task_list->hide(); // phpcs:ignore CSRF ok.
if ( $update ) { wc_admin_record_tracks_event( 'tasklist_toggled', array( 'status' => $show ? 'enabled' : 'disabled', ) ); }
wp_safe_redirect( wc_admin_url() ); exit; }
/** * Reset the extended task list and redirect to the dashboard. */ public function reset_extended_task_list() { if ( ! PageController::is_admin_page() || ! isset( $_GET['reset_extended_task_list'] ) // phpcs:ignore CSRF ok. ) { return; }
$task_list = TaskLists::get_list( 'extended' );
if ( ! $task_list ) { return; } $show = 1 === absint( $_GET['reset_extended_task_list'] ); // phpcs:ignore CSRF ok. $update = $show ? $task_list->unhide() : $task_list->hide(); // phpcs:ignore CSRF ok.
if ( $update ) { wc_admin_record_tracks_event( 'extended_tasklist_toggled', array( 'status' => $show ? 'disabled' : 'enabled', ) ); }
wp_safe_redirect( wc_admin_url() ); exit; } }
|