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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 / includes / admin / class-wc-admin-notices.php
woocommerce / includes / admin Last commit date
helper 2 months ago importers 1 year ago list-tables 1 month ago marketplace-suggestions 11 months ago meta-boxes 1 month ago notes 2 months ago plugin-updates 2 years ago reports 3 months ago settings 6 days ago views 1 month ago class-wc-admin-addons.php 9 months ago class-wc-admin-api-keys-table-list.php 2 years ago class-wc-admin-api-keys.php 11 months ago class-wc-admin-assets.php 1 month ago class-wc-admin-attributes.php 1 month ago class-wc-admin-brands.php 4 months ago class-wc-admin-customize.php 5 years ago class-wc-admin-dashboard-setup.php 1 month ago class-wc-admin-dashboard.php 4 months ago class-wc-admin-duplicate-product.php 5 months ago class-wc-admin-exporters.php 1 year ago class-wc-admin-help.php 2 years ago class-wc-admin-importers.php 11 months ago class-wc-admin-log-table-list.php 4 months ago class-wc-admin-marketplace-promotions.php 4 months ago class-wc-admin-menus.php 1 month ago class-wc-admin-meta-boxes.php 1 month ago class-wc-admin-notices.php 1 month ago class-wc-admin-permalink-settings.php 5 years ago class-wc-admin-pointers.php 3 years ago class-wc-admin-post-types.php 1 year ago class-wc-admin-profile.php 1 year ago class-wc-admin-reports.php 4 months ago class-wc-admin-settings.php 3 months ago class-wc-admin-setup-wizard.php 1 month ago class-wc-admin-status.php 1 year ago class-wc-admin-taxonomies.php 1 month ago class-wc-admin-upload-downloadable-product.php 2 years ago class-wc-admin-webhooks-table-list.php 1 month ago class-wc-admin-webhooks.php 1 month ago class-wc-admin.php 3 months ago wc-admin-functions.php 7 months ago wc-meta-box-functions.php 1 year ago woocommerce-legacy-reports.php 1 year ago
class-wc-admin-notices.php
780 lines
1 <?php
2 /**
3 * Display notices in admin
4 *
5 * @package WooCommerce\Admin
6 * @version 3.4.0
7 */
8
9 use Automattic\Jetpack\Constants;
10 use Automattic\WooCommerce\Enums\DefaultCustomerAddress;
11 use Automattic\WooCommerce\Internal\Utilities\Users;
12
13 defined( 'ABSPATH' ) || exit;
14
15 /**
16 * WC_Admin_Notices Class.
17 */
18 class WC_Admin_Notices {
19
20 /**
21 * Local notices cache.
22 *
23 * DON'T manipulate this field directly!
24 * Always use get_notices and set_notices instead.
25 *
26 * @var array
27 */
28 private static $notices = array();
29
30 /**
31 * Array of notices - name => callback.
32 *
33 * @var array
34 */
35 private static $core_notices = array(
36 'update' => 'update_notice',
37 'template_files' => 'template_file_check_notice',
38 'legacy_shipping' => 'legacy_shipping_notice',
39 'no_shipping_methods' => 'no_shipping_methods_notice',
40 'regenerating_thumbnails' => 'regenerating_thumbnails_notice',
41 'regenerating_lookup_table' => 'regenerating_lookup_table_notice',
42 'no_secure_connection' => 'secure_connection_notice',
43 'maxmind_license_key' => 'maxmind_missing_license_key_notice',
44 'redirect_download_method' => 'redirect_download_method_notice',
45 'uploads_directory_is_unprotected' => 'uploads_directory_is_unprotected_notice',
46 'base_tables_missing' => 'base_tables_missing_notice',
47 'download_directories_sync_complete' => 'download_directories_sync_complete',
48 'hpos_sync_on_read_disabled' => 'sync_on_read_disabled_notice',
49 );
50
51 /**
52 * Stores a flag indicating if the code is running in a multisite setup.
53 *
54 * @var bool
55 */
56 private static bool $is_multisite;
57
58 /**
59 * Initializes the class.
60 *
61 * @return void
62 */
63 public static function init() {
64 self::$is_multisite = is_multisite();
65 self::set_notices( get_option( 'woocommerce_admin_notices', array() ) );
66
67 add_action( 'switch_theme', array( __CLASS__, 'reset_admin_notices' ) );
68 add_action( 'woocommerce_installed', array( __CLASS__, 'reset_admin_notices' ) );
69 add_action( 'update_option_woocommerce_file_download_method', array( __CLASS__, 'add_redirect_download_method_notice' ) );
70 add_action( 'admin_init', array( __CLASS__, 'hide_notices' ), 20 );
71
72 // @TODO: This prevents Action Scheduler async jobs from storing empty list of notices during WC installation.
73 // That could lead to OBW not starting and 'Run setup wizard' notice not appearing in WP admin, which we want
74 // to avoid.
75 if ( ! WC_Install::is_new_install() || ! wc_is_running_from_async_action_scheduler() ) {
76 add_action( 'shutdown', array( __CLASS__, 'store_notices' ) );
77 }
78
79 if ( current_user_can( 'manage_woocommerce' ) ) {
80 add_action( 'admin_print_styles', array( __CLASS__, 'add_notices' ) );
81 }
82 }
83
84 /**
85 * Parses query to create nonces when available.
86 *
87 * @deprecated 5.4.0
88 * @param object $response The WP_REST_Response we're working with.
89 * @return object $response The prepared WP_REST_Response object.
90 */
91 public static function prepare_note_with_nonce( $response ) {
92 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '5.4.0' );
93
94 return $response;
95 }
96
97 /**
98 * Store the locally cached notices to DB.
99 *
100 * @return void
101 */
102 public static function store_notices() {
103 $current_notices = self::get_notices();
104 $prev_notices = get_option( 'woocommerce_admin_notices', array() );
105
106 // Store notices.
107 update_option( 'woocommerce_admin_notices', $current_notices );
108
109 // Clean up removed notices.
110 foreach ( array_diff( $prev_notices, $current_notices ) as $notice ) {
111 if ( isset( self::$core_notices[ $notice ] ) ) {
112 continue;
113 }
114
115 delete_option( 'woocommerce_admin_notice_' . $notice );
116 }
117 }
118
119 /**
120 * Get the value of the locally cached notices array for the current site.
121 *
122 * @return array
123 */
124 public static function get_notices() {
125 if ( ! self::$is_multisite ) {
126 return self::$notices;
127 }
128
129 $blog_id = get_current_blog_id();
130 $notices = self::$notices[ $blog_id ] ?? null;
131 if ( ! is_null( $notices ) ) {
132 return $notices;
133 }
134
135 self::$notices[ $blog_id ] = get_option( 'woocommerce_admin_notices', array() );
136 return self::$notices[ $blog_id ];
137 }
138
139 /**
140 * Set the locally cached notices array for the current site.
141 *
142 * @param array $notices New value for the locally cached notices array.
143 * @return void
144 */
145 private static function set_notices( array $notices ) {
146 if ( self::$is_multisite ) {
147 self::$notices[ get_current_blog_id() ] = $notices;
148 } else {
149 self::$notices = $notices;
150 }
151 }
152
153 /**
154 * Remove all notices from the locally cached notices array.
155 *
156 * @return void
157 */
158 public static function remove_all_notices() {
159 self::set_notices( array() );
160 }
161
162 /**
163 * Reset notices for themes when switched or a new version of WC is installed.
164 *
165 * @return void
166 */
167 public static function reset_admin_notices() {
168 if ( ! self::is_ssl() ) {
169 self::add_notice( 'no_secure_connection' );
170 }
171 if ( ! self::is_uploads_directory_protected() ) {
172 self::add_notice( 'uploads_directory_is_unprotected' );
173 }
174 self::add_notice( 'template_files' );
175 self::add_min_version_notice();
176 self::add_maxmind_missing_license_key_notice();
177 }
178
179 /**
180 * Show a notice.
181 *
182 * @param string $name Notice name.
183 * @param bool $force_save Force saving inside this method instead of at the 'shutdown'.
184 * @return void
185 */
186 public static function add_notice( $name, $force_save = false ) {
187 self::set_notices( array_unique( array_merge( self::get_notices(), array( $name ) ) ) );
188
189 if ( $force_save ) {
190 // Adding early save to prevent more race conditions with notices.
191 self::store_notices();
192 }
193 }
194
195 /**
196 * Remove a notice from being displayed.
197 *
198 * @param string $name Notice name.
199 * @param bool $force_save Force saving inside this method instead of at the 'shutdown'.
200 * @return void
201 */
202 public static function remove_notice( $name, $force_save = false ) {
203 if ( self::has_notice( $name ) ) {
204 self::set_notices( array_diff( self::get_notices(), array( $name ) ) );
205 }
206
207 if ( $force_save ) {
208 // Adding early save to prevent more race conditions with notices.
209 self::store_notices();
210 }
211 }
212
213 /**
214 * Remove a given set of notices.
215 *
216 * An array of notice names or a regular expression string can be passed, in the later case
217 * all the notices whose name matches the regular expression will be removed.
218 *
219 * @param array|string $names_array_or_regex An array of notice names, or a string representing a regular expression.
220 * @param bool $force_save Force saving inside this method instead of at the 'shutdown'.
221 * @return void
222 */
223 public static function remove_notices( $names_array_or_regex, $force_save = false ) {
224 if ( ! is_array( $names_array_or_regex ) ) {
225 $names_array_or_regex = array_filter( self::get_notices(), fn( $notice_name ) => 1 === preg_match( $names_array_or_regex, $notice_name ) );
226 }
227 self::set_notices( array_diff( self::get_notices(), $names_array_or_regex ) );
228
229 if ( $force_save ) {
230 // Adding early save to prevent more race conditions with notices.
231 self::store_notices();
232 }
233 }
234
235 /**
236 * See if a notice is being shown.
237 *
238 * @param string $name Notice name.
239 *
240 * @return boolean
241 */
242 public static function has_notice( $name ) {
243 return in_array( $name, self::get_notices(), true );
244 }
245
246 /**
247 * Hide a notice if the GET variable is set.
248 *
249 * @return void
250 */
251 public static function hide_notices() {
252 if ( isset( $_GET['wc-hide-notice'] ) && isset( $_GET['_wc_notice_nonce'] ) ) {
253 if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_GET['_wc_notice_nonce'] ) ), 'woocommerce_hide_notices_nonce' ) ) {
254 wp_die( esc_html__( 'Action failed. Please refresh the page and retry.', 'woocommerce' ) );
255 }
256
257 $notice_name = sanitize_text_field( wp_unslash( $_GET['wc-hide-notice'] ) );
258
259 /**
260 * Filter the capability required to dismiss a given notice.
261 *
262 * @since 6.7.0
263 *
264 * @param string $default_capability The default required capability.
265 * @param string $notice_name The notice name.
266 */
267 $required_capability = apply_filters( 'woocommerce_dismiss_admin_notice_capability', 'manage_woocommerce', $notice_name );
268
269 if ( ! current_user_can( $required_capability ) ) {
270 wp_die( esc_html__( 'You don&#8217;t have permission to do this.', 'woocommerce' ) );
271 }
272
273 self::hide_notice( $notice_name );
274 }
275 }
276
277 /**
278 * Hide a single notice.
279 *
280 * @param string $name Notice name.
281 * @return void
282 */
283 private static function hide_notice( $name ) {
284 self::remove_notice( $name );
285
286 update_user_meta( get_current_user_id(), 'dismissed_' . $name . '_notice', true );
287
288 do_action( 'woocommerce_hide_' . $name . '_notice' );
289 }
290
291 /**
292 * Check if a given user has dismissed a given admin notice.
293 *
294 * @since 8.5.0
295 *
296 * @param string $name The name of the admin notice to check.
297 * @param int|null $user_id User id, or null for the current user.
298 * @return bool True if the user has dismissed the notice.
299 */
300 public static function user_has_dismissed_notice( string $name, ?int $user_id = null ): bool {
301 return (bool) get_user_meta( $user_id ?? get_current_user_id(), "dismissed_{$name}_notice", true );
302 }
303
304 /**
305 * Add notices + styles if needed.
306 *
307 * @return void
308 */
309 public static function add_notices() {
310 $notices = self::get_notices();
311
312 if ( empty( $notices ) ) {
313 return;
314 }
315
316 require_once WC_ABSPATH . 'includes/admin/wc-admin-functions.php';
317
318 $screen = get_current_screen();
319 $screen_id = $screen ? $screen->id : '';
320 $show_on_screens = array(
321 'dashboard',
322 'plugins',
323 );
324
325 // Notices should only show on WooCommerce screens, the main dashboard, and on the plugins screen.
326 if ( ! in_array( $screen_id, wc_get_screen_ids(), true ) && ! in_array( $screen_id, $show_on_screens, true ) ) {
327 return;
328 }
329
330 wp_enqueue_style( 'woocommerce-activation', plugins_url( '/assets/css/activation.css', WC_PLUGIN_FILE ), array(), Constants::get_constant( 'WC_VERSION' ) );
331
332 // Add RTL support.
333 wp_style_add_data( 'woocommerce-activation', 'rtl', 'replace' );
334
335 foreach ( $notices as $notice ) {
336 if ( ! empty( self::$core_notices[ $notice ] ) && apply_filters( 'woocommerce_show_admin_notice', true, $notice ) ) {
337 add_action( 'admin_notices', array( __CLASS__, self::$core_notices[ $notice ] ) );
338 } else {
339 add_action( 'admin_notices', array( __CLASS__, 'output_custom_notices' ) );
340 }
341 }
342 }
343
344 /**
345 * Add a custom notice.
346 *
347 * @param string $name Notice name.
348 * @param string $notice_html Notice HTML.
349 * @return void
350 */
351 public static function add_custom_notice( $name, $notice_html ) {
352 self::add_notice( $name );
353 update_option( 'woocommerce_admin_notice_' . $name, wp_kses_post( $notice_html ) );
354 }
355
356 /**
357 * Output any stored custom notices.
358 *
359 * @return void
360 */
361 public static function output_custom_notices() {
362 $notices = self::get_notices();
363
364 if ( ! empty( $notices ) ) {
365 foreach ( $notices as $notice ) {
366 if ( empty( self::$core_notices[ $notice ] ) ) {
367 $notice_html = get_option( 'woocommerce_admin_notice_' . $notice );
368
369 if ( $notice_html ) {
370 include __DIR__ . '/views/html-notice-custom.php';
371 }
372 }
373 }
374 }
375 }
376
377 /**
378 * If we need to update the database, include a message with the DB update button.
379 *
380 * @return void
381 */
382 public static function update_notice() {
383 $screen = get_current_screen();
384 $screen_id = $screen ? $screen->id : '';
385 if ( WC()->is_wc_admin_active() && in_array( $screen_id, wc_get_screen_ids(), true ) ) {
386 return;
387 }
388
389 if ( WC_Install::needs_db_update() ) {
390 $next_scheduled_date = WC()->queue()->get_next( 'woocommerce_run_update_callback', null, 'woocommerce-db-updates' );
391
392 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
393 if ( $next_scheduled_date || ! empty( $_GET['do_update_woocommerce'] ) ) {
394 include __DIR__ . '/views/html-notice-updating.php';
395 } else {
396 include __DIR__ . '/views/html-notice-update.php';
397 }
398 } else {
399 include __DIR__ . '/views/html-notice-updated.php';
400 }
401 }
402
403 /**
404 * If we have just installed, show a message with the install pages button.
405 *
406 * @deprecated 4.6.0
407 * @return void
408 */
409 public static function install_notice() {
410 _deprecated_function( __CLASS__ . '::' . __FUNCTION__, '4.6.0', esc_html__( 'Onboarding is maintained in WooCommerce Admin.', 'woocommerce' ) );
411 }
412
413 /**
414 * Show a notice highlighting bad template files.
415 *
416 * @return void
417 */
418 public static function template_file_check_notice() {
419 $core_templates = WC_Admin_Status::scan_template_files( WC()->plugin_path() . '/templates' );
420 $outdated = false;
421
422 foreach ( $core_templates as $file ) {
423
424 $theme_file = false;
425 if ( file_exists( get_stylesheet_directory() . '/' . $file ) ) {
426 $theme_file = get_stylesheet_directory() . '/' . $file;
427 } elseif ( file_exists( get_stylesheet_directory() . '/' . WC()->template_path() . $file ) ) {
428 $theme_file = get_stylesheet_directory() . '/' . WC()->template_path() . $file;
429 } elseif ( file_exists( get_template_directory() . '/' . $file ) ) {
430 $theme_file = get_template_directory() . '/' . $file;
431 } elseif ( file_exists( get_template_directory() . '/' . WC()->template_path() . $file ) ) {
432 $theme_file = get_template_directory() . '/' . WC()->template_path() . $file;
433 }
434
435 if ( false !== $theme_file ) {
436 $core_version = WC_Admin_Status::get_file_version( WC()->plugin_path() . '/templates/' . $file );
437 $theme_version = WC_Admin_Status::get_file_version( $theme_file );
438
439 if ( $core_version && $theme_version && version_compare( $theme_version, $core_version, '<' ) ) {
440 $outdated = true;
441 break;
442 }
443 }
444 }
445
446 if ( $outdated ) {
447 include __DIR__ . '/views/html-notice-template-check.php';
448 } else {
449 self::remove_notice( 'template_files' );
450 }
451 }
452
453 /**
454 * Show a notice asking users to convert to shipping zones.
455 *
456 * @todo remove in 4.0.0
457 * @return void
458 */
459 public static function legacy_shipping_notice() {
460 $maybe_load_legacy_methods = array( 'flat_rate', 'free_shipping', 'international_delivery', 'local_delivery', 'local_pickup' );
461 $enabled = false;
462
463 foreach ( $maybe_load_legacy_methods as $method ) {
464 $options = get_option( 'woocommerce_' . $method . '_settings' );
465 if ( $options && isset( $options['enabled'] ) && 'yes' === $options['enabled'] ) {
466 $enabled = true;
467 }
468 }
469
470 if ( $enabled ) {
471 include __DIR__ . '/views/html-notice-legacy-shipping.php';
472 } else {
473 self::remove_notice( 'legacy_shipping' );
474 }
475 }
476
477 /**
478 * No shipping methods.
479 *
480 * @return void
481 */
482 public static function no_shipping_methods_notice() {
483 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
484 if ( wc_shipping_enabled() && ( ! is_wc_admin_settings_page() || empty( $_GET['tab'] ) || 'shipping' !== $_GET['tab'] ) ) {
485 $product_count = wp_count_posts( 'product' );
486 $method_count = wc_get_shipping_method_count();
487
488 if ( $product_count->publish > 0 && 0 === $method_count ) {
489 include __DIR__ . '/views/html-notice-no-shipping-methods.php';
490 }
491
492 if ( $method_count > 0 ) {
493 self::remove_notice( 'no_shipping_methods' );
494 }
495 }
496 }
497
498 /**
499 * Notice shown when regenerating thumbnails background process is running.
500 *
501 * @return void
502 */
503 public static function regenerating_thumbnails_notice() {
504 include __DIR__ . '/views/html-notice-regenerating-thumbnails.php';
505 }
506
507 /**
508 * Notice about secure connection.
509 *
510 * @return void
511 */
512 public static function secure_connection_notice() {
513 if ( self::is_ssl() || get_user_meta( get_current_user_id(), 'dismissed_no_secure_connection_notice', true ) ) {
514 return;
515 }
516
517 include __DIR__ . '/views/html-notice-secure-connection.php';
518 }
519
520 /**
521 * Notice shown when regenerating thumbnails background process is running.
522 *
523 * @since 3.6.0
524 * @return void
525 */
526 public static function regenerating_lookup_table_notice() {
527 // See if this is still relevant.
528 if ( ! wc_update_product_lookup_tables_is_running() ) {
529 self::remove_notice( 'regenerating_lookup_table' );
530 return;
531 }
532
533 include __DIR__ . '/views/html-notice-regenerating-lookup-table.php';
534 }
535
536 /**
537 * Add notice about minimum PHP and WordPress requirement.
538 *
539 * @since 3.6.5
540 * @return void
541 */
542 public static function add_min_version_notice() {
543 if ( version_compare( phpversion(), WC_NOTICE_MIN_PHP_VERSION, '<' ) || version_compare( get_bloginfo( 'version' ), WC_NOTICE_MIN_WP_VERSION, '<' ) ) {
544 self::add_notice( WC_PHP_MIN_REQUIREMENTS_NOTICE );
545 }
546 }
547
548 /**
549 * Notice about WordPress and PHP minimum requirements.
550 *
551 * @deprecated 8.2.0 WordPress and PHP minimum requirements notices are no longer shown.
552 *
553 * @since 3.6.5
554 * @return void
555 */
556 public static function wp_php_min_requirements_notice() {
557 }
558
559 /**
560 * Add MaxMind missing license key notice.
561 *
562 * @since 3.9.0
563 * @return void
564 */
565 public static function add_maxmind_missing_license_key_notice() {
566 $default_address = get_option( 'woocommerce_default_customer_address' );
567
568 if ( ! in_array( $default_address, array( DefaultCustomerAddress::GEOLOCATION, DefaultCustomerAddress::GEOLOCATION_AJAX ), true ) ) {
569 return;
570 }
571
572 $integration_options = get_option( 'woocommerce_maxmind_geolocation_settings' );
573 if ( empty( $integration_options['license_key'] ) ) {
574 self::add_notice( 'maxmind_license_key' );
575
576 }
577 }
578
579 /**
580 * Add notice about Redirect-only download method, nudging user to switch to a different method instead.
581 *
582 * @return void
583 */
584 public static function add_redirect_download_method_notice() {
585 if ( 'redirect' === get_option( 'woocommerce_file_download_method' ) ) {
586 self::add_notice( 'redirect_download_method' );
587 } else {
588 self::remove_notice( 'redirect_download_method' );
589 }
590 }
591
592 /**
593 * Notice about the completion of the product downloads sync, with further advice for the site operator.
594 *
595 * @return void
596 */
597 public static function download_directories_sync_complete() {
598 $notice_dismissed = apply_filters(
599 'woocommerce_hide_download_directories_sync_complete',
600 get_user_meta( get_current_user_id(), 'download_directories_sync_complete', true )
601 );
602
603 if ( $notice_dismissed ) {
604 self::remove_notice( 'download_directories_sync_complete' );
605 }
606
607 if ( Users::is_site_administrator() ) {
608 include __DIR__ . '/views/html-notice-download-dir-sync-complete.php';
609 }
610 }
611
612 /**
613 * Display MaxMind missing license key notice.
614 *
615 * @since 3.9.0
616 * @return void
617 */
618 public static function maxmind_missing_license_key_notice() {
619 $user_dismissed_notice = get_user_meta( get_current_user_id(), 'dismissed_maxmind_license_key_notice', true );
620 $filter_dismissed_notice = ! apply_filters( 'woocommerce_maxmind_geolocation_display_notices', true );
621
622 if ( $user_dismissed_notice || $filter_dismissed_notice ) {
623 self::remove_notice( 'maxmind_license_key' );
624 return;
625 }
626
627 include __DIR__ . '/views/html-notice-maxmind-license-key.php';
628 }
629
630 /**
631 * Notice about Redirect-Only download method.
632 *
633 * @since 4.0
634 * @return void
635 */
636 public static function redirect_download_method_notice() {
637 if ( apply_filters( 'woocommerce_hide_redirect_method_nag', get_user_meta( get_current_user_id(), 'dismissed_redirect_download_method_notice', true ) ) ) {
638 self::remove_notice( 'redirect_download_method' );
639 return;
640 }
641
642 include __DIR__ . '/views/html-notice-redirect-only-download.php';
643 }
644
645 /**
646 * Notice about uploads directory begin unprotected.
647 *
648 * @since 4.2.0
649 * @return void
650 */
651 public static function uploads_directory_is_unprotected_notice() {
652 if ( get_user_meta( get_current_user_id(), 'dismissed_uploads_directory_is_unprotected_notice', true ) || self::is_uploads_directory_protected() ) {
653 self::remove_notice( 'uploads_directory_is_unprotected' );
654 return;
655 }
656
657 include __DIR__ . '/views/html-notice-uploads-directory-is-unprotected.php';
658 }
659
660 /**
661 * Notice about base tables missing.
662 *
663 * @return void
664 */
665 public static function base_tables_missing_notice() {
666 $notice_dismissed = apply_filters(
667 'woocommerce_hide_base_tables_missing_nag',
668 get_user_meta( get_current_user_id(), 'dismissed_base_tables_missing_notice', true )
669 );
670 if ( $notice_dismissed ) {
671 self::remove_notice( 'base_tables_missing' );
672 }
673
674 include __DIR__ . '/views/html-notice-base-table-missing.php';
675 }
676
677 /**
678 * Notice about HPOS sync-on-read being disabled by default.
679 *
680 * @since 10.7.0
681 * @return void
682 */
683 public static function sync_on_read_disabled_notice() {
684 $dismiss =
685 ! \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled()
686 || ! wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\DataSynchronizer::class )->data_sync_is_enabled()
687 || get_user_meta( get_current_user_id(), 'dismissed_hpos_sync_on_read_disabled_notice', true );
688
689 if ( $dismiss ) {
690 self::remove_notice( 'hpos_sync_on_read_disabled' );
691 return;
692 }
693
694 include __DIR__ . '/views/html-notice-sync-on-read-disabled.php';
695 }
696
697 /**
698 * Determine if the store is running SSL.
699 *
700 * @return bool Flag SSL enabled.
701 * @since 3.5.1
702 */
703 protected static function is_ssl() {
704 $shop_page = wc_get_page_permalink( 'shop' );
705
706 return ( is_ssl() && 'https' === substr( $shop_page, 0, 5 ) );
707 }
708
709 /**
710 * Wrapper for is_plugin_active.
711 *
712 * @param string $plugin Plugin to check.
713 * @return boolean
714 */
715 protected static function is_plugin_active( $plugin ) {
716 if ( ! function_exists( 'is_plugin_active' ) ) {
717 include_once ABSPATH . 'wp-admin/includes/plugin.php';
718 }
719 return is_plugin_active( $plugin );
720 }
721
722 /**
723 * Simplify Commerce is no longer in core.
724 *
725 * @deprecated 3.6.0 No longer shown.
726 * @return void
727 */
728 public static function simplify_commerce_notice() {
729 wc_deprecated_function( 'WC_Admin_Notices::simplify_commerce_notice', '3.6.0' );
730 }
731
732 /**
733 * Show the Theme Check notice.
734 *
735 * @deprecated 3.3.0 No longer shown.
736 * @return void
737 */
738 public static function theme_check_notice() {
739 wc_deprecated_function( 'WC_Admin_Notices::theme_check_notice', '3.3.0' );
740 }
741
742 /**
743 * Check if uploads directory is protected.
744 *
745 * @since 4.2.0
746 * @return bool
747 */
748 protected static function is_uploads_directory_protected() {
749 $cache_key = '_woocommerce_upload_directory_status';
750 $status = get_transient( $cache_key );
751
752 // Check for cache.
753 if ( false !== $status ) {
754 return 'protected' === $status;
755 }
756
757 // Get only data from the uploads directory.
758 $uploads = wp_get_upload_dir();
759
760 // Check for the "uploads/woocommerce_uploads" directory.
761 $response = wp_safe_remote_get(
762 esc_url_raw( $uploads['baseurl'] . '/woocommerce_uploads/' ),
763 array(
764 'redirection' => 0,
765 )
766 );
767 $response_code = intval( wp_remote_retrieve_response_code( $response ) );
768 $response_content = wp_remote_retrieve_body( $response );
769
770 // Check if returns 200 with empty content in case can open an index.html file,
771 // and check for non-200 codes in case the directory is protected.
772 $is_protected = ( 200 === $response_code && empty( $response_content ) ) || ( 200 !== $response_code );
773 set_transient( $cache_key, $is_protected ? 'protected' : 'unprotected', 1 * DAY_IN_SECONDS );
774
775 return $is_protected;
776 }
777 }
778
779 WC_Admin_Notices::init();
780