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