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2.0-rc.1 3.0.9 6.2.0-rc.2 3.1.0 6.2.1 3.1.1 6.2.2 3.1.2 6.2.3 3.2.0 6.3.0 3.2.1 6.3.0-beta.1 3.2.2 6.3.0-rc.1 3.2.3 6.3.0-rc.2 3.2.4 6.3.1 3.2.5 6.3.2 3.2.6 6.4.0 3.3.0 6.4.0-beta.1 3.3.1 6.4.0-rc.1 3.3.2 6.4.1 3.3.2-rc.1 6.4.2 3.3.3 6.5.0 3.3.4 6.5.0-beta.1 3.3.5 6.5.0-rc.1 3.3.6 6.5.0-rc.2 3.4.0 6.5.1 3.4.0-beta.1 6.5.2 3.4.0-rc.2 6.6.0 3.4.1 6.6.0-beta.1 3.4.2 6.6.0-rc.1 3.4.3 6.6.0-rc.2 3.4.4 6.6.1 3.4.5 6.6.2 3.4.6 6.7.0 3.4.7 6.7.0-beta.1 3.4.8 6.7.0-beta.2 3.5.0 6.7.0-rc.1 3.5.0-beta.1 6.7.1 3.5.0-rc.1 6.8.0 3.5.0-rc.2 6.8.0-beta.1 3.5.1 6.8.0-beta.2 3.5.10 6.8.0-rc.1 3.5.2 6.8.1 3.5.3 6.8.2 3.5.4 6.8.3 3.5.5 6.9.0 3.5.6 6.9.0-beta.1 3.5.7 6.9.0-beta.2 3.5.8 6.9.0-rc.1 3.5.9 6.9.1 3.6.0 6.9.2 3.6.0-beta.1 6.9.3 3.6.0-rc.1 6.9.4 3.6.0-rc.2 6.9.5 3.6.0-rc.3 7.0.0 3.6.1 7.0.0-beta.1 3.6.2 7.0.0-beta.2 3.6.3 7.0.0-beta.3 3.6.4 7.0.0-rc.1 3.6.5 7.0.0-rc.2 3.6.6 7.0.1 3.6.7 7.0.2 3.7.0 7.1.0 3.7.0-beta.1 7.1.0-beta.1 3.7.0-rc.1 7.1.0-beta.2 3.7.0-rc.2 7.1.0-rc.1 3.7.1 7.1.0-rc.2 3.7.2 7.1.1
woocommerce / src / Admin / Features / LaunchYourStore.php
woocommerce / src / Admin / Features Last commit date
Blueprint 4 days ago Fulfillments 1 month ago MarketingRecommendations 3 months ago Navigation 1 year ago OnboardingTasks 4 days ago PaymentGatewaySuggestions 1 year ago ProductBlockEditor 4 days ago ProductDataViews 4 days ago ShippingPartnerSuggestions 2 months ago Features.php 1 month ago LaunchYourStore.php 4 days ago Onboarding.php 1 year ago ProductVariationsClassicRedesign.php 1 month ago TransientNotices.php 3 years ago
LaunchYourStore.php
269 lines
1 <?php declare( strict_types = 1 );
2
3 namespace Automattic\WooCommerce\Admin\Features;
4
5 use Automattic\WooCommerce\Admin\WCAdminHelper;
6 use Automattic\WooCommerce\Internal\Admin\WCAdminUser;
7
8
9 /**
10 * Takes care of Launch Your Store related actions.
11 */
12 class LaunchYourStore {
13 const BANNER_DISMISS_USER_META_KEY = 'coming_soon_banner_dismissed';
14 /**
15 * Constructor.
16 */
17 public function __construct() {
18 add_action( 'woocommerce_update_options_site-visibility', array( $this, 'save_site_visibility_options' ) );
19 add_filter( 'woocommerce_admin_shared_settings', array( $this, 'preload_settings' ) );
20 add_action( 'wp_footer', array( $this, 'maybe_add_coming_soon_banner_on_frontend' ) );
21 add_action( 'init', array( $this, 'register_launch_your_store_user_meta_fields' ) );
22 add_filter( 'woocommerce_tracks_event_properties', array( $this, 'append_coming_soon_global_tracks' ), 10, 2 );
23 add_action( 'wp_login', array( $this, 'reset_woocommerce_coming_soon_banner_dismissed' ), 10, 2 );
24 add_filter( 'woocommerce_admin_get_user_data_fields', array( $this, 'add_user_data_fields' ) );
25 }
26
27 /**
28 * Save values submitted from WooCommerce -> Settings -> General.
29 *
30 * @return void
31 */
32 public function save_site_visibility_options() {
33 $nonce = isset( $_REQUEST['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_wpnonce'] ) ) : '';
34 if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'woocommerce-settings' ) ) {
35 return;
36 }
37
38 // options to allowed update and their allowed values.
39 $options = array(
40 'woocommerce_coming_soon' => array( 'yes', 'no' ),
41 'woocommerce_store_pages_only' => array( 'yes', 'no' ),
42 'woocommerce_private_link' => array( 'yes', 'no' ),
43 'woocommerce_feature_site_visibility_badge_enabled' => array( 'yes', 'no' ),
44 );
45
46 $event_data = array();
47
48 foreach ( $options as $name => $allowed_values ) {
49 $current_value = get_option( $name, 'not set' );
50 $new_value = $current_value;
51
52 if ( isset( $_POST[ $name ] ) ) {
53 $input_value = sanitize_text_field( wp_unslash( $_POST[ $name ] ) );
54
55 // no-op if input value is invalid.
56 if ( in_array( $input_value, $allowed_values, true ) ) {
57 update_option( $name, $input_value );
58 $new_value = $input_value;
59
60 // log the transition if there is one.
61 if ( $current_value !== $new_value ) {
62 $enabled_or_disabled = 'yes' === $new_value ? 'enabled' : 'disabled';
63 $event_data[ $name . '_toggled' ] = $enabled_or_disabled;
64 }
65 }
66 }
67 $event_data[ $name ] = $new_value;
68 }
69 wc_admin_record_tracks_event( 'site_visibility_saved', $event_data );
70 }
71
72 /**
73 * Append coming soon prop tracks globally.
74 *
75 * @param array $event_properties Event properties array.
76 *
77 * @return array
78 */
79 public function append_coming_soon_global_tracks( $event_properties ) {
80 if ( is_array( $event_properties ) ) {
81 $coming_soon = 'no';
82 if ( 'yes' === get_option( 'woocommerce_coming_soon', 'no' ) ) {
83 if ( 'yes' === get_option( 'woocommerce_store_pages_only', 'no' ) ) {
84 $coming_soon = 'store';
85 } else {
86 $coming_soon = 'site';
87 }
88 }
89 $event_properties['coming_soon'] = $coming_soon;
90 }
91 return $event_properties;
92 }
93
94
95 /**
96 * Preload settings for Site Visibility.
97 *
98 * @param array $settings settings array.
99 *
100 * @return mixed
101 */
102 public function preload_settings( $settings ) {
103 if ( ! is_admin() ) {
104 return $settings;
105 }
106
107 $current_screen = get_current_screen();
108 $is_setting_page = $current_screen && 'woocommerce_page_wc-settings' === $current_screen->id;
109
110 // phpcs:disable WordPress.Security.NonceVerification.Recommended
111 $is_woopayments_connect = isset( $_GET['path'] ) &&
112 isset( $_GET['page'] ) &&
113 ( '/payments/connect' === sanitize_text_field( wp_unslash( $_GET['path'] ) ) || '/payments/onboarding' === sanitize_text_field( wp_unslash( $_GET['path'] ) ) ) &&
114 'wc-admin' === $_GET['page'];
115 // phpcs:enable
116
117 if ( $is_setting_page || $is_woopayments_connect ) {
118 // Regnerate the share key if it's not set.
119 add_option( 'woocommerce_share_key', wp_generate_password( 32, false ) );
120
121 $settings['siteVisibilitySettings'] = array(
122 'shop_permalink' => get_permalink( wc_get_page_id( 'shop' ) ),
123 'woocommerce_coming_soon' => get_option( 'woocommerce_coming_soon' ),
124 'woocommerce_store_pages_only' => get_option( 'woocommerce_store_pages_only' ),
125 'woocommerce_private_link' => get_option( 'woocommerce_private_link' ),
126 'woocommerce_share_key' => get_option( 'woocommerce_share_key' ),
127 'woocommerce_feature_site_visibility_badge_enabled' => get_option( 'woocommerce_feature_site_visibility_badge_enabled', 'yes' ),
128 );
129 }
130
131 return $settings;
132 }
133
134 /**
135 * User must be an admin or editor.
136 *
137 * @return bool
138 */
139 private function is_manager_or_admin() {
140 // phpcs:ignore
141 if ( ! current_user_can( 'shop_manager' ) && ! current_user_can( 'administrator' ) ) {
142 return false;
143 }
144
145 return true;
146 }
147
148 /**
149 * Add 'coming soon' banner on the frontend when the following conditions met.
150 *
151 * - User must be either an admin or store editor (must be logged in).
152 * - 'woocommerce_coming_soon' option value must be 'yes'
153 * - The page must not be the Coming soon page itself.
154 */
155 public function maybe_add_coming_soon_banner_on_frontend() {
156 // Do not show the banner if the site is being previewed.
157 if ( isset( $_GET['site-preview'] ) ) { // @phpcs:ignore
158 return false;
159 }
160
161 $current_user_id = get_current_user_id();
162 if ( ! $current_user_id ) {
163 return false;
164 }
165
166 $has_dismissed_banner = WCAdminUser::get_user_data_field( $current_user_id, self::BANNER_DISMISS_USER_META_KEY )
167 // Remove this check in WC 9.4.
168 || get_user_meta( $current_user_id, 'woocommerce_' . self::BANNER_DISMISS_USER_META_KEY, true ) === 'yes';
169 if ( $has_dismissed_banner ) {
170 return false;
171 }
172
173 if ( ! $this->is_manager_or_admin() ) {
174 return false;
175 }
176
177 // 'woocommerce_coming_soon' must be 'yes'
178 if ( get_option( 'woocommerce_coming_soon', 'no' ) !== 'yes' ) {
179 return false;
180 }
181
182 $store_pages_only = get_option( 'woocommerce_store_pages_only' ) === 'yes';
183 if ( $store_pages_only && ! WCAdminHelper::is_current_page_store_page() ) {
184 return false;
185 }
186
187 $link = admin_url( 'admin.php?page=wc-settings&tab=site-visibility' );
188 $rest_url = rest_url( 'wp/v2/users/' . $current_user_id );
189 $rest_nonce = wp_create_nonce( 'wp_rest' );
190
191 $text = sprintf(
192 // translators: no need to translate it. It's a link.
193 __(
194 "
195 This page is in \"Coming soon\" mode and is only visible to you and those who have permission. To make it public to everyone,&nbsp;<a href='%s'>change visibility settings</a>.
196 ",
197 'woocommerce'
198 ),
199 $link
200 );
201 // phpcs:ignore
202 echo "<div id='coming-soon-footer-banner'><div class='coming-soon-footer-banner__content'>$text</div><a class='coming-soon-footer-banner-dismiss' data-rest-url='$rest_url' data-rest-nonce='$rest_nonce'></a></div>";
203 }
204
205 /**
206 * Register user meta fields for Launch Your Store.
207 *
208 * This should be removed in WC 9.4.
209 */
210 public function register_launch_your_store_user_meta_fields() {
211 if ( ! $this->is_manager_or_admin() ) {
212 return;
213 }
214
215 register_meta(
216 'user',
217 'woocommerce_launch_your_store_tour_hidden',
218 array(
219 'type' => 'string',
220 'description' => 'Indicate whether the user has dismissed the site visibility tour on the home screen.',
221 'single' => true,
222 'show_in_rest' => true,
223 )
224 );
225
226 register_meta(
227 'user',
228 'woocommerce_coming_soon_banner_dismissed',
229 array(
230 'type' => 'string',
231 'description' => 'Indicate whether the user has dismissed the coming soon notice or not.',
232 'single' => true,
233 'show_in_rest' => true,
234 )
235 );
236 }
237
238 /**
239 * Register user meta fields for Launch Your Store.
240 *
241 * @param array $user_data_fields user data fields.
242 * @return array
243 */
244 public function add_user_data_fields( $user_data_fields ) {
245 return array_merge(
246 $user_data_fields,
247 array(
248 'launch_your_store_tour_hidden',
249 self::BANNER_DISMISS_USER_META_KEY,
250 )
251 );
252 }
253
254 /**
255 * Reset 'woocommerce_coming_soon_banner_dismissed' user meta to 'no'.
256 *
257 * Runs when a user logs-in successfully.
258 *
259 * @param string $user_login user login.
260 * @param object $user user object.
261 */
262 public function reset_woocommerce_coming_soon_banner_dismissed( $user_login, $user ) {
263 $existing_meta = WCAdminUser::get_user_data_field( $user->ID, self::BANNER_DISMISS_USER_META_KEY );
264 if ( 'yes' === $existing_meta ) {
265 WCAdminUser::update_user_data_field( $user->ID, self::BANNER_DISMISS_USER_META_KEY, 'no' );
266 }
267 }
268 }
269