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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 / Internal / Admin / Loader.php
woocommerce / src / Internal / Admin Last commit date
Agentic 4 months ago EmailImprovements 1 year ago EmailPreview 5 days ago Emails 1 year ago ImportExport 1 year ago Logging 5 days ago Marketing 2 years ago Notes 1 month ago Onboarding 5 months ago Orders 5 days ago ProductForm 2 years ago ProductReviews 1 month ago RemoteFreeExtensions 1 month ago Schedulers 5 days ago Settings 5 days ago Suggestions 1 month ago WCPayPromotion 11 months ago ActivityPanels.php 3 years ago Analytics.php 1 month ago CategoryLookup.php 4 years ago Coupons.php 1 year ago CouponsMovedTrait.php 5 months ago CustomerEffortScoreTracks.php 7 months ago Events.php 2 months ago FeaturePlugin.php 4 months ago Homescreen.php 2 months ago Loader.php 5 days ago Marketing.php 1 year ago Marketplace.php 5 months ago MobileAppBanner.php 4 years ago OrderMilestoneEasterEgg.php 1 month ago RemoteInboxNotifications.php 3 years ago Settings.php 5 days ago ShippingLabelBanner.php 1 year ago ShippingLabelBannerDisplayRules.php 1 year ago SiteHealth.php 5 days ago Survey.php 4 years ago SystemStatusReport.php 1 year ago TaxSettingsRecommendations.php 5 days ago Translations.php 1 year ago WCAdminAssets.php 5 days ago WCAdminSharedSettings.php 1 year ago WCAdminUser.php 9 months ago WcPayWelcomePage.php 1 year ago
Loader.php
580 lines
1 <?php
2 /**
3 * Register the scripts, styles, and includes needed for pieces of the WooCommerce Admin experience.
4 */
5
6 namespace Automattic\WooCommerce\Internal\Admin;
7
8 use Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore as OrdersDataStore;
9 use Automattic\WooCommerce\Admin\Features\Features;
10 use Automattic\WooCommerce\Admin\PageController;
11 use Automattic\WooCommerce\Admin\PluginsHelper;
12 use Automattic\WooCommerce\Internal\Admin\ProductReviews\Reviews;
13 use Automattic\WooCommerce\Internal\Admin\ProductReviews\ReviewsCommentsOverrides;
14
15 /**
16 * Loader Class.
17 */
18 class Loader {
19 /**
20 * Class instance.
21 *
22 * @var Loader instance
23 */
24 protected static $instance = null;
25
26 /**
27 * An array of classes to load from the includes folder.
28 *
29 * @var array
30 */
31 protected static $classes = array();
32
33 /**
34 * WordPress capability required to use analytics features.
35 *
36 * @var string
37 */
38 protected static $required_capability = null;
39
40 /**
41 * An array of dependencies that have been preloaded (to avoid duplicates).
42 *
43 * @var array
44 */
45 protected $preloaded_dependencies = array(
46 'script' => array(),
47 'style' => array(),
48 );
49
50 /**
51 * Get class instance.
52 */
53 public static function get_instance() {
54 if ( ! self::$instance ) {
55 self::$instance = new self();
56 }
57 return self::$instance;
58 }
59
60 /**
61 * Constructor.
62 * Hooks added here should be removed in `wc_admin_initialize` via the feature plugin.
63 */
64 public function __construct() {
65 Features::get_instance();
66 WCAdminSharedSettings::get_instance();
67 Translations::get_instance();
68 WCAdminUser::get_instance();
69 Settings::get_instance();
70 SiteHealth::get_instance();
71 SystemStatusReport::get_instance();
72
73 wc_get_container()->get( TaxSettingsRecommendations::class );
74 wc_get_container()->get( Reviews::class );
75 wc_get_container()->get( ReviewsCommentsOverrides::class );
76
77 add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_classes' ) );
78 add_filter( 'admin_title', array( __CLASS__, 'update_admin_title' ) );
79 add_action( 'in_admin_header', array( __CLASS__, 'embed_page_header' ) );
80 add_action( 'admin_head', array( __CLASS__, 'remove_notices' ) );
81 add_action( 'admin_head', array( __CLASS__, 'smart_app_banner' ) );
82 add_action( 'admin_notices', array( __CLASS__, 'inject_before_notices' ), -9999 );
83 add_action( 'admin_notices', array( __CLASS__, 'inject_after_notices' ), PHP_INT_MAX );
84
85 // Added this hook to delete the field woocommerce_onboarding_homepage_post_id when deleting the homepage.
86 add_action( 'trashed_post', array( __CLASS__, 'delete_homepage' ) );
87
88 /*
89 * Remove the emoji script as it always defaults to replacing emojis with Twemoji images.
90 * Gutenberg has also disabled emojis. More on that here -> https://github.com/WordPress/gutenberg/pull/6151
91 */
92 remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
93
94 add_action( 'load-themes.php', array( __CLASS__, 'add_appearance_theme_view_tracks_event' ) );
95 }
96
97 /**
98 * Returns breadcrumbs for the current page.
99 */
100 private static function get_embed_breadcrumbs() {
101 return wc_admin_get_breadcrumbs();
102 }
103
104 /**
105 * Outputs breadcrumbs via PHP for the initial load of an embedded page.
106 *
107 * @param array $section Section to create breadcrumb from.
108 */
109 private static function output_heading( $section ) {
110 echo esc_html( $section );
111 }
112
113 /**
114 * Set up a div for the header embed to render into.
115 * The initial contents here are meant as a place loader for when the PHP page initially loads.
116 */
117 public static function embed_page_header() {
118 if ( ! PageController::is_admin_page() && ! PageController::is_embed_page() ) {
119 return;
120 }
121
122 if ( ! PageController::is_embed_page() ) {
123 return;
124 }
125
126 $sections = self::get_embed_breadcrumbs();
127 $sections = is_array( $sections ) ? $sections : array( $sections );
128
129 $page_title = '';
130 $pages_with_tabs = array(
131 'admin.php?page=wc-settings',
132 'admin.php?page=wc-reports',
133 'admin.php?page=wc-status',
134 );
135
136 if (
137 count( $sections ) > 2 &&
138 is_array( $sections[1] ) &&
139 in_array( $sections[1][0], $pages_with_tabs, true )
140 ) {
141 $page_title = $sections[1][1];
142 } else {
143 $page_title = end( $sections );
144 }
145 ?>
146 <div id="woocommerce-embedded-root" class="is-embed-loading">
147 <div class="woocommerce-layout">
148 <div class="woocommerce-layout__header is-embed-loading">
149 <h1 class="woocommerce-layout__header-heading">
150 <?php self::output_heading( $page_title ); ?>
151 </h1>
152 </div>
153 </div>
154 </div>
155 <?php
156 }
157
158 /**
159 * Adds body classes to the main wp-admin wrapper, allowing us to better target elements in specific scenarios.
160 *
161 * @param string $admin_body_class Body class to add.
162 */
163 public static function add_admin_body_classes( $admin_body_class = '' ) {
164 if ( ! PageController::is_admin_or_embed_page() ) {
165 return $admin_body_class;
166 }
167
168 $classes = explode( ' ', trim( $admin_body_class ) );
169 $classes[] = 'woocommerce-admin-page';
170 if ( PageController::is_embed_page() ) {
171 $classes[] = 'woocommerce-embed-page';
172 }
173
174 // Add page ID as a class.
175 $page_id = PageController::get_instance()->get_current_screen_id();
176 if ( $page_id ) {
177 $classes[] = $page_id;
178 }
179
180 /**
181 * Some routes or features like onboarding hide the wp-admin navigation and masterbar.
182 * Setting `woocommerce_admin_is_loading` to true allows us to premeptively hide these
183 * elements while the JS app loads.
184 * This class needs to be removed by those feature components (like <ProfileWizard />).
185 *
186 * @param bool $is_loading If WooCommerce Admin is loading a fullscreen view.
187 * @since 6.5.0
188 */
189 $is_loading = apply_filters( 'woocommerce_admin_is_loading', false );
190
191 if ( PageController::is_admin_page() && $is_loading ) {
192 $classes[] = 'woocommerce-admin-is-loading';
193 }
194
195 $admin_body_class = implode( ' ', array_unique( $classes ) );
196 return " $admin_body_class ";
197 }
198
199 /**
200 * Adds an iOS "Smart App Banner" for display on iOS Safari.
201 * See https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html
202 */
203 public static function smart_app_banner() {
204 $exclude_paths = array(
205 '/customize-store',
206 '/setup-wizard',
207 '/launch-your-store',
208 );
209
210 /* phpcs:ignore */
211 $path = $_GET['path'] ?? '';
212
213 if ( PageController::is_admin_or_embed_page() && ! in_array( $path, $exclude_paths, true ) ) {
214 echo "
215 <meta name='apple-itunes-app' content='app-id=1389130815'>
216 ";
217 }
218 }
219
220
221 /**
222 * Removes notices that should not be displayed on WC Admin pages.
223 */
224 public static function remove_notices() {
225 if ( ! PageController::is_admin_or_embed_page() ) {
226 return;
227 }
228
229 // Hello Dolly.
230 if ( function_exists( 'hello_dolly' ) ) {
231 remove_action( 'admin_notices', 'hello_dolly' );
232 }
233 }
234
235 /**
236 * Runs before admin notices action and hides them.
237 */
238 public static function inject_before_notices() {
239 if ( ! PageController::is_admin_or_embed_page() ) {
240 return;
241 }
242
243 // The JITMs won't be shown in the Onboarding Wizard.
244 $is_onboarding = isset( $_GET['path'] ) && '/setup-wizard' === wc_clean( wp_unslash( $_GET['path'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
245 $maybe_hide_jitm = $is_onboarding ? '-hide' : '';
246
247 echo '<div class="woocommerce-layout__jitm' . sanitize_html_class( $maybe_hide_jitm ) . '" id="jp-admin-notices"></div>';
248
249 // Wrap the notices in a hidden div to prevent flickering before
250 // they are moved elsewhere in the page by WordPress Core.
251 echo '<div class="woocommerce-layout__notice-list-hide" id="wp__notice-list">';
252
253 if ( PageController::is_admin_page() ) {
254 // Capture all notices and hide them. WordPress Core looks for
255 // `.wp-header-end` and appends notices after it if found.
256 // https://github.com/WordPress/WordPress/blob/f6a37e7d39e2534d05b9e542045174498edfe536/wp-admin/js/common.js#L737 .
257 echo '<div class="wp-header-end" id="woocommerce-layout__notice-catcher"></div>';
258 }
259 }
260
261 /**
262 * Runs after admin notices and closes div.
263 */
264 public static function inject_after_notices() {
265 if ( ! PageController::is_admin_or_embed_page() ) {
266 return;
267 }
268
269 // Close the hidden div used to prevent notices from flickering before
270 // they are inserted elsewhere in the page.
271 echo '</div>';
272 }
273
274 /**
275 * Edits Admin title based on section of wc-admin.
276 *
277 * @param string $admin_title Modifies admin title.
278 * @todo Can we do some URL rewriting so we can figure out which page they are on server side?
279 */
280 public static function update_admin_title( $admin_title ) {
281 if (
282 ! did_action( 'current_screen' ) ||
283 ! PageController::is_admin_page()
284 ) {
285 return $admin_title;
286 }
287
288 $sections = self::get_embed_breadcrumbs();
289 $pieces = array();
290
291 foreach ( $sections as $section ) {
292 $pieces[] = is_array( $section ) ? $section[1] : $section;
293 }
294
295 $pieces = array_reverse( $pieces );
296 $title = implode( ' &lsaquo; ', $pieces );
297
298 /* translators: %1$s: updated title, %2$s: blog info name */
299 return sprintf( __( '%1$s &lsaquo; %2$s', 'woocommerce' ), $title, get_bloginfo( 'name' ) );
300 }
301
302 /**
303 * Set up a div for the app to render into.
304 */
305 public static function page_wrapper() {
306 ?>
307 <div class="wrap">
308 <div id="root"></div>
309 </div>
310 <?php
311 }
312
313 /**
314 * Hooks extra necessary data into the component settings array already set in WooCommerce core.
315 *
316 * @param array $settings Array of component settings.
317 * @return array Array of component settings.
318 */
319 public static function add_component_settings( $settings ) {
320 if ( ! is_admin() ) {
321 return $settings;
322 }
323
324 if ( ! function_exists( 'wc_blocks_container' ) ) {
325 global $wp_locale;
326 // inject data not available via older versions of wc_blocks/woo.
327 $settings['orderStatuses'] = Settings::get_order_statuses( wc_get_order_statuses() );
328 $settings['stockStatuses'] = Settings::get_order_statuses( wc_get_product_stock_status_options() );
329 $settings['currency'] = Settings::get_currency_settings();
330 $settings['locale'] = array(
331 'siteLocale' => isset( $settings['siteLocale'] )
332 ? $settings['siteLocale']
333 : get_locale(),
334 'userLocale' => isset( $settings['l10n']['userLocale'] )
335 ? $settings['l10n']['userLocale']
336 : get_user_locale(),
337 'weekdaysShort' => isset( $settings['l10n']['weekdaysShort'] )
338 ? $settings['l10n']['weekdaysShort']
339 : array_values( $wp_locale->weekday_abbrev ),
340 );
341 }
342
343 /**
344 * The woocommerce_component_settings_preload_endpoints filter
345 *
346 * @since 6.5.0
347 */
348 $preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() );
349
350 if ( ! empty( $preload_data_endpoints ) ) {
351 $preload_data = array_reduce(
352 array_values( $preload_data_endpoints ),
353 'rest_preload_api_request'
354 );
355 }
356
357 /**
358 * The woocommerce_admin_preload_options filter
359 *
360 * @since 6.5.0
361 */
362 $preload_options = apply_filters( 'woocommerce_admin_preload_options', array() );
363 if ( ! empty( $preload_options ) ) {
364 foreach ( $preload_options as $option ) {
365 $settings['preloadOptions'][ $option ] = get_option( $option );
366 }
367 }
368
369 /**
370 * The woocommerce_admin_preload_settings filter
371 *
372 * @since 6.5.0
373 */
374 $preload_settings = apply_filters( 'woocommerce_admin_preload_settings', array() );
375 if ( ! empty( $preload_settings ) ) {
376 $setting_options = new \WC_REST_Setting_Options_V2_Controller();
377 foreach ( $preload_settings as $group ) {
378 $group_settings = $setting_options->get_group_settings( $group );
379 $preload_settings = array();
380 foreach ( $group_settings as $option ) {
381 if ( array_key_exists( 'id', $option ) && array_key_exists( 'value', $option ) ) {
382 $preload_settings[ $option['id'] ] = $option['value'];
383 }
384 }
385 $settings['preloadSettings'][ $group ] = $preload_settings;
386 }
387 }
388
389 $user_controller = new \WP_REST_Users_Controller();
390 $request = new \WP_REST_Request();
391 $request->set_query_params( array( 'context' => 'edit' ) );
392 $user_response = $user_controller->get_current_item( $request );
393 $current_user_data = is_wp_error( $user_response ) ? (object) array() : $user_response->get_data();
394
395 $settings['currentUserData'] = $current_user_data;
396 $settings['reviewsEnabled'] = get_option( 'woocommerce_enable_reviews' );
397 $settings['manageStock'] = get_option( 'woocommerce_manage_stock' );
398 $settings['commentModeration'] = get_option( 'comment_moderation' );
399 $settings['notifyLowStockAmount'] = get_option( 'woocommerce_notify_low_stock_amount' );
400 // @todo On merge, once plugin images are added to core WooCommerce, `wcAdminAssetUrl` can be retired,
401 // and `wcAssetUrl` can be used in its place throughout the codebase.
402 $settings['wcAdminAssetUrl'] = WC_ADMIN_IMAGES_FOLDER_URL;
403 $settings['wcVersion'] = WC_VERSION;
404 $settings['siteUrl'] = site_url();
405 $settings['shopUrl'] = get_permalink( wc_get_page_id( 'shop' ) );
406 $settings['homeUrl'] = home_url();
407 $settings['dateFormat'] = get_option( 'date_format' );
408 $settings['timeZone'] = wc_timezone_string();
409 $settings['plugins'] = array(
410 'installedPlugins' => PluginsHelper::get_installed_plugin_slugs(),
411 'activePlugins' => Plugins::get_active_plugins(),
412 );
413 // Plugins that depend on changing the translation work on the server but not the client -
414 // WooCommerce Branding is an example of this - so pass through the translation of
415 // 'WooCommerce' to wcSettings.
416 $settings['woocommerceTranslation'] = __( 'WooCommerce', 'woocommerce' );
417 // We may have synced orders with a now-unregistered status.
418 // E.g An extension that added statuses is now inactive or removed.
419 $settings['unregisteredOrderStatuses'] = self::get_unregistered_order_statuses();
420 // The separator used for attributes found in Variation titles.
421 /* phpcs:ignore */
422 $settings['variationTitleAttributesSeparator'] = apply_filters( 'woocommerce_product_variation_title_attributes_separator', ' - ', new \WC_Product() );
423
424 // Performance note: refer back to https://github.com/woocommerce/woocommerce/pull/41092: unconditionally loading /jetpack/v4/connection.
425 // As automattic/jetpack-connection package is a direct dependency, we can return the Jetpack connection status via its public API.
426 $settings['dataEndpoints'] = $settings['dataEndpoints'] ?? array();
427 try {
428 $settings['dataEndpoints']['jetpackStatus'] = \Automattic\Jetpack\Connection\REST_Connector::connection_status( false );
429 } catch ( \Throwable $e ) {
430 $settings['dataEndpoints']['jetpackStatus'] = array();
431 }
432
433 if ( ! empty( $preload_data_endpoints ) ) {
434 foreach ( $preload_data_endpoints as $key => $endpoint ) {
435 // Handle error case: rest_do_request() doesn't guarantee success.
436 if ( empty( $preload_data[ $endpoint ] ) ) {
437 $settings['dataEndpoints'][ $key ] = array();
438 } else {
439 $settings['dataEndpoints'][ $key ] = $preload_data[ $endpoint ]['body'];
440 }
441 }
442 }
443 $settings = self::get_custom_settings( $settings );
444 if ( PageController::is_embed_page() ) {
445 $settings['embedBreadcrumbs'] = self::get_embed_breadcrumbs();
446 }
447
448 $settings['allowMarketplaceSuggestions'] = WC_Marketplace_Suggestions::allow_suggestions();
449 $settings['connectNonce'] = wp_create_nonce( 'connect' );
450 $settings['wcpay_welcome_page_connect_nonce'] = wp_create_nonce( 'wcpay-connect' );
451
452 return $settings;
453 }
454
455 /**
456 * Format order statuses by removing a leading 'wc-' if present.
457 *
458 * @param array $statuses Order statuses.
459 * @return array formatted statuses.
460 *
461 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
462 */
463 public static function get_order_statuses( $statuses ) {
464 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::get_order_statuses' );
465
466 return Settings::get_order_statuses( $statuses );
467 }
468
469 /**
470 * Get all order statuses present in analytics tables that aren't registered.
471 *
472 * @return array Unregistered order statuses.
473 *
474 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
475 */
476 public static function get_unregistered_order_statuses() {
477 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0' );
478
479 $registered_statuses = wc_get_order_statuses();
480 $all_synced_statuses = OrdersDataStore::get_all_statuses();
481 $unregistered_statuses = array_diff( $all_synced_statuses, array_keys( $registered_statuses ) );
482 $formatted_status_keys = Settings::get_order_statuses( array_fill_keys( $unregistered_statuses, '' ) );
483 $formatted_statuses = array_keys( $formatted_status_keys );
484
485 return array_combine( $formatted_statuses, $formatted_statuses );
486 }
487
488 /**
489 * Register the admin settings for use in the WC REST API
490 *
491 * @param array $groups Array of setting groups.
492 * @return array
493 *
494 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
495 */
496 public static function add_settings_group( $groups ) {
497 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::add_settings_group' );
498
499 return Settings::get_instance()->add_settings_group( $groups );
500 }
501
502 /**
503 * Add WC Admin specific settings
504 *
505 * @param array $settings Array of settings in wc admin group.
506 * @return array
507 *
508 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
509 */
510 public static function add_settings( $settings ) {
511 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::add_settings' );
512
513 return Settings::get_instance()->add_settings( $settings );
514 }
515
516 /**
517 * Gets custom settings used for WC Admin.
518 *
519 * @param array $settings Array of settings to merge into.
520 * @return array
521 *
522 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
523 */
524 public static function get_custom_settings( $settings ) {
525 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0' );
526
527 $wc_rest_settings_options_controller = new \WC_REST_Setting_Options_Controller();
528 $wc_admin_group_settings = $wc_rest_settings_options_controller->get_group_settings( 'wc_admin' );
529 $settings['wcAdminSettings'] = array();
530
531 foreach ( $wc_admin_group_settings as $setting ) {
532 if ( ! empty( $setting['id'] ) ) {
533 $settings['wcAdminSettings'][ $setting['id'] ] = $setting['value'];
534 }
535 }
536 return $settings;
537 }
538
539 /**
540 * Return an object defining the currency options for the site's current currency
541 *
542 * @return array Settings for the current currency {
543 * Array of settings.
544 *
545 * @type string $code Currency code.
546 * @type string $precision Number of decimals.
547 * @type string $symbol Symbol for currency.
548 * }
549 *
550 * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead.
551 */
552 public static function get_currency_settings() {
553 wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::get_currency_settings' );
554
555 return Settings::get_currency_settings();
556 }
557
558 /**
559 * Delete woocommerce_onboarding_homepage_post_id field when the homepage is deleted
560 *
561 * @param int $post_id The deleted post id.
562 */
563 public static function delete_homepage( $post_id ) {
564 if ( 'page' !== get_post_type( $post_id ) ) {
565 return;
566 }
567 $homepage_id = intval( get_option( 'woocommerce_onboarding_homepage_post_id', false ) );
568 if ( $homepage_id === $post_id ) {
569 delete_option( 'woocommerce_onboarding_homepage_post_id' );
570 }
571 }
572
573 /**
574 * Adds the appearance_theme_view Tracks event.
575 */
576 public static function add_appearance_theme_view_tracks_event() {
577 wc_admin_record_tracks_event( 'appearance_theme_view', array() );
578 }
579 }
580