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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 / Settings.php
woocommerce / src / Internal / Admin Last commit date
Agentic 4 months ago EmailImprovements 1 year ago EmailPreview 3 days ago Emails 1 year ago ImportExport 1 year ago Logging 3 days ago Marketing 2 years ago Notes 1 month ago Onboarding 5 months ago Orders 3 days ago ProductForm 2 years ago ProductReviews 1 month ago RemoteFreeExtensions 1 month ago Schedulers 3 days ago Settings 3 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 3 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 3 days ago ShippingLabelBanner.php 1 year ago ShippingLabelBannerDisplayRules.php 1 year ago SiteHealth.php 3 days ago Survey.php 4 years ago SystemStatusReport.php 1 year ago TaxSettingsRecommendations.php 3 days ago Translations.php 1 year ago WCAdminAssets.php 3 days ago WCAdminSharedSettings.php 1 year ago WCAdminUser.php 9 months ago WcPayWelcomePage.php 1 year ago
Settings.php
453 lines
1 <?php
2 /**
3 * WooCommerce Settings.
4 */
5
6 namespace Automattic\WooCommerce\Internal\Admin;
7
8 use Automattic\WooCommerce\Admin\API\Plugins;
9 use Automattic\WooCommerce\Admin\API\Reports\Orders\DataStore as OrdersDataStore;
10 use Automattic\WooCommerce\Admin\Features\Features;
11 use Automattic\WooCommerce\Admin\PageController;
12 use Automattic\WooCommerce\Admin\PluginsHelper;
13 use Automattic\WooCommerce\Internal\Admin\Settings\SettingsUIRequestContext;
14 use Automattic\WooCommerce\Utilities\FeaturesUtil;
15 use Automattic\WooCommerce\Utilities\OrderUtil;
16 use WC_Marketplace_Suggestions;
17
18 /**
19 * Contains logic in regards to WooCommerce Admin Settings.
20 */
21 class Settings {
22
23 /**
24 * Class instance.
25 *
26 * @var Settings instance
27 */
28 protected static $instance = null;
29
30 /**
31 * Get class instance.
32 */
33 public static function get_instance() {
34 if ( ! self::$instance ) {
35 self::$instance = new self();
36 }
37 return self::$instance;
38 }
39
40 /**
41 * Hook into WooCommerce.
42 */
43 public function __construct() {
44 // Old settings injection.
45 add_filter( 'woocommerce_components_settings', array( $this, 'add_component_settings' ) );
46 // New settings injection.
47 add_filter( 'woocommerce_admin_shared_settings', array( $this, 'add_component_settings' ) );
48 add_filter( 'woocommerce_settings_groups', array( $this, 'add_settings_group' ) );
49 add_filter( 'woocommerce_settings-wc_admin', array( $this, 'add_settings' ) );
50 }
51
52 /**
53 * Format order statuses by removing a leading 'wc-' if present.
54 *
55 * @param array $statuses Order statuses.
56 * @return array formatted statuses.
57 */
58 public static function get_order_statuses( $statuses ) {
59 $formatted_statuses = array();
60 foreach ( $statuses as $key => $value ) {
61 $formatted_key = preg_replace( '/^wc-/', '', $key );
62 $formatted_statuses[ $formatted_key ] = $value;
63 }
64 return $formatted_statuses;
65 }
66
67 /**
68 * Get all order statuses present in analytics tables that aren't registered.
69 *
70 * @return array Unregistered order statuses.
71 */
72 private function get_unregistered_order_statuses() {
73 $registered_statuses = wc_get_order_statuses();
74 $all_synced_statuses = OrdersDataStore::get_all_statuses();
75 $unregistered_statuses = array_diff( $all_synced_statuses, array_keys( $registered_statuses ) );
76 $formatted_status_keys = self::get_order_statuses( array_fill_keys( $unregistered_statuses, '' ) );
77 $formatted_statuses = array_keys( $formatted_status_keys );
78
79 return array_combine( $formatted_statuses, $formatted_statuses );
80 }
81
82 /**
83 * Return an object defining the currency options for the site's current currency
84 *
85 * @return array Settings for the current currency {
86 * Array of settings.
87 *
88 * @type string $code Currency code.
89 * @type string $precision Number of decimals.
90 * @type string $symbol Symbol for currency.
91 * }
92 */
93 public static function get_currency_settings() {
94 $code = get_woocommerce_currency();
95
96 /**
97 * The wc_currency_settings hook
98 *
99 * @since 6.5.0
100 */
101 return apply_filters(
102 'wc_currency_settings',
103 array(
104 'code' => $code,
105 'precision' => wc_get_price_decimals(),
106 'symbol' => html_entity_decode( get_woocommerce_currency_symbol( $code ) ),
107 'symbolPosition' => get_option( 'woocommerce_currency_pos' ),
108 'decimalSeparator' => wc_get_price_decimal_separator(),
109 'thousandSeparator' => wc_get_price_thousand_separator(),
110 'priceFormat' => html_entity_decode( get_woocommerce_price_format() ),
111 )
112 );
113 }
114
115 /**
116 * Hooks extra necessary data into the component settings array already set in WooCommerce core.
117 *
118 * @param array $settings Array of component settings.
119 * @return array Array of component settings.
120 */
121 public function add_component_settings( $settings ) {
122 if ( ! is_admin() ) {
123 return $settings;
124 }
125
126 if ( ! function_exists( 'wc_blocks_container' ) ) {
127 global $wp_locale;
128 // inject data not available via older versions of wc_blocks/woo.
129 $settings['orderStatuses'] = self::get_order_statuses( wc_get_order_statuses() );
130 $settings['stockStatuses'] = self::get_order_statuses( wc_get_product_stock_status_options() );
131 $settings['currency'] = self::get_currency_settings();
132 $settings['locale'] = array(
133 'siteLocale' => isset( $settings['siteLocale'] )
134 ? $settings['siteLocale']
135 : get_locale(),
136 'userLocale' => isset( $settings['l10n']['userLocale'] )
137 ? $settings['l10n']['userLocale']
138 : get_user_locale(),
139 'weekdaysShort' => isset( $settings['l10n']['weekdaysShort'] )
140 ? $settings['l10n']['weekdaysShort']
141 : array_values( $wp_locale->weekday_abbrev ),
142 );
143 }
144
145 //phpcs:ignore
146 $preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() );
147
148 if ( ! empty( $preload_data_endpoints ) ) {
149 $preload_data = array_reduce(
150 array_values( $preload_data_endpoints ),
151 'rest_preload_api_request'
152 );
153 }
154
155 //phpcs:ignore
156 $preload_options = apply_filters( 'woocommerce_admin_preload_options', array() );
157 if ( ! empty( $preload_options ) ) {
158 // Prime caches to reduce future queries.
159 wp_prime_option_caches( $preload_options );
160 foreach ( $preload_options as $option ) {
161 $settings['preloadOptions'][ $option ] = get_option( $option );
162 }
163 }
164
165 //phpcs:ignore
166 $preload_settings = apply_filters( 'woocommerce_admin_preload_settings', array() );
167 if ( ! empty( $preload_settings ) ) {
168 $setting_options = new \WC_REST_Setting_Options_V2_Controller();
169 foreach ( $preload_settings as $group ) {
170 $group_settings = $setting_options->get_group_settings( $group );
171 $preload_settings = array();
172 foreach ( $group_settings as $option ) {
173 if ( array_key_exists( 'id', $option ) && array_key_exists( 'value', $option ) ) {
174 $preload_settings[ $option['id'] ] = $option['value'];
175 }
176 }
177 $settings['preloadSettings'][ $group ] = $preload_settings;
178 }
179 }
180
181 $settings['currentUserData'] = WCAdminUser::get_user_data();
182 $settings['reviewsEnabled'] = get_option( 'woocommerce_enable_reviews' );
183 $settings['manageStock'] = get_option( 'woocommerce_manage_stock' );
184 $settings['commentModeration'] = get_option( 'comment_moderation' );
185 $settings['notifyLowStockAmount'] = get_option( 'woocommerce_notify_low_stock_amount' );
186
187 /**
188 * Deprecate wcAdminAssetUrl as we no longer need it after The Merge.
189 * Use wcAssetUrl instead.
190 *
191 * @deprecated 6.7.0
192 * @var string
193 */
194 $settings['wcAdminAssetUrl'] = WC_ADMIN_IMAGES_FOLDER_URL;
195 $settings['wcVersion'] = WC_VERSION;
196 $settings['siteUrl'] = site_url();
197 $settings['shopUrl'] = get_permalink( wc_get_page_id( 'shop' ) );
198 $settings['homeUrl'] = home_url();
199 $settings['dateFormat'] = get_option( 'date_format' );
200 $settings['timeZone'] = wc_timezone_string();
201 $settings['plugins'] = array(
202 'installedPlugins' => PluginsHelper::get_installed_plugin_slugs(),
203 'activePlugins' => Plugins::get_active_plugins(),
204 );
205
206 // DO NOT use outside of core, these can be removed without deprecation.
207 $settings['__experimentalFlags'] = array();
208
209 // Plugins that depend on changing the translation work on the server but not the client -
210 // WooCommerce Branding is an example of this - so pass through the translation of
211 // 'WooCommerce' to wcSettings.
212 $settings['woocommerceTranslation'] = __( 'WooCommerce', 'woocommerce' );
213
214 if ( PageController::is_admin_page() && Features::is_enabled( 'analytics' ) ) {
215 // We may have synced orders with a now-unregistered status.
216 // E.g. an extension that added statuses is now inactive or removed.
217 $settings['unregisteredOrderStatuses'] = $this->get_unregistered_order_statuses();
218 $settings['usesNewFullRefundData'] = OrderUtil::uses_new_full_refund_data();
219 }
220
221 // The separator used for attributes found in Variation titles.
222 //phpcs:ignore
223 $settings['variationTitleAttributesSeparator'] = apply_filters( 'woocommerce_product_variation_title_attributes_separator', ' - ', new \WC_Product() );
224
225 $settings = $this->add_settings_ui_schema( $settings );
226
227 // Performance note: refer back to https://github.com/woocommerce/woocommerce/pull/41092: unconditionally loading /jetpack/v4/connection.
228 // As automattic/jetpack-connection package is a direct dependency, we can return the Jetpack connection status via its public API.
229 $settings['dataEndpoints'] = $settings['dataEndpoints'] ?? array();
230 try {
231 $settings['dataEndpoints']['jetpackStatus'] = \Automattic\Jetpack\Connection\REST_Connector::connection_status( false );
232 } catch ( \Throwable $e ) {
233 $settings['dataEndpoints']['jetpackStatus'] = array();
234 }
235
236 if ( ! empty( $preload_data_endpoints ) ) {
237 foreach ( $preload_data_endpoints as $key => $endpoint ) {
238 // Handle error case: rest_do_request() doesn't guarantee success.
239 if ( empty( $preload_data[ $endpoint ] ) ) {
240 $settings['dataEndpoints'][ $key ] = array();
241 } else {
242 $settings['dataEndpoints'][ $key ] = $preload_data[ $endpoint ]['body'];
243 }
244 }
245 }
246 $settings = $this->get_custom_settings( $settings );
247 if ( PageController::is_embed_page() ) {
248 $settings['embedBreadcrumbs'] = wc_admin_get_breadcrumbs();
249 }
250
251 $settings['allowMarketplaceSuggestions'] = WC_Marketplace_Suggestions::allow_suggestions();
252 $settings['connectNonce'] = wp_create_nonce( 'connect' );
253 $settings['wcpay_welcome_page_connect_nonce'] = wp_create_nonce( 'wcpay-connect' );
254 $settings['email_preview_nonce'] = wp_create_nonce( 'email-preview-nonce' );
255 $settings['email_listing_nonce'] = wp_create_nonce( 'email-listing-nonce' );
256 $settings['wc_helper_nonces'] = array(
257 'refresh' => wp_create_nonce( 'refresh' ),
258 );
259
260 $settings['features'] = $this->get_features();
261
262 $has_gutenberg = is_plugin_active( 'gutenberg/gutenberg.php' );
263 $gutenberg_version = '';
264 if ( $has_gutenberg ) {
265 if ( defined( 'GUTENBERG_VERSION' ) ) {
266 $gutenberg_version = GUTENBERG_VERSION;
267 }
268
269 if ( ! $gutenberg_version ) {
270 $gutenberg_data = get_plugin_data( WP_PLUGIN_DIR . '/gutenberg/gutenberg.php' );
271 $gutenberg_version = $gutenberg_data['Version'];
272 }
273 }
274 $settings['gutenberg_version'] = $has_gutenberg ? $gutenberg_version : 0;
275
276 return $settings;
277 }
278
279 /**
280 * Removes non-necessary feature properties for the client side.
281 *
282 * @return array
283 */
284 public function get_features() {
285 $features = FeaturesUtil::get_features( true, true );
286 $new_features = array();
287
288 foreach ( array_keys( $features ) as $feature_id ) {
289 $new_features[ $feature_id ] = array(
290 'is_enabled' => $features[ $feature_id ]['is_enabled'],
291 'is_experimental' => $features[ $feature_id ]['is_experimental'] ?? false,
292 );
293 }
294
295 return $new_features;
296 }
297
298 /**
299 * Register the admin settings for use in the WC REST API
300 *
301 * @param array $groups Array of setting groups.
302 * @return array
303 */
304 public function add_settings_group( $groups ) {
305 $groups[] = array(
306 'id' => 'wc_admin',
307 'label' => __( 'WooCommerce Admin', 'woocommerce' ),
308 'description' => __( 'Settings for WooCommerce admin reporting.', 'woocommerce' ),
309 );
310 return $groups;
311 }
312
313 /**
314 * Add WC Admin specific settings
315 *
316 * @param array $settings Array of settings in wc admin group.
317 * @return array
318 */
319 public function add_settings( $settings ) {
320 $unregistered_statuses = $this->get_unregistered_order_statuses();
321 $registered_statuses = self::get_order_statuses( wc_get_order_statuses() );
322 $all_statuses = array_merge( $unregistered_statuses, $registered_statuses );
323
324 $settings[] = array(
325 'id' => 'woocommerce_excluded_report_order_statuses',
326 'option_key' => 'woocommerce_excluded_report_order_statuses',
327 'label' => __( 'Excluded report order statuses', 'woocommerce' ),
328 'description' => __( 'Statuses that should not be included when calculating report totals.', 'woocommerce' ),
329 'default' => array( 'pending', 'cancelled', 'failed' ),
330 'type' => 'multiselect',
331 'options' => $all_statuses,
332 );
333 $settings[] = array(
334 'id' => 'woocommerce_actionable_order_statuses',
335 'option_key' => 'woocommerce_actionable_order_statuses',
336 'label' => __( 'Actionable order statuses', 'woocommerce' ),
337 'description' => __( 'Statuses that require extra action on behalf of the store admin.', 'woocommerce' ),
338 'default' => array( 'processing', 'on-hold' ),
339 'type' => 'multiselect',
340 'options' => $all_statuses,
341 );
342 $settings[] = array(
343 'id' => 'woocommerce_default_date_range',
344 'option_key' => 'woocommerce_default_date_range',
345 'label' => __( 'Default Date Range', 'woocommerce' ),
346 'description' => __( 'Default Date Range', 'woocommerce' ),
347 'default' => 'period=month&compare=previous_year',
348 'type' => 'text',
349 );
350 $settings[] = array(
351 'id' => 'woocommerce_date_type',
352 'option_key' => 'woocommerce_date_type',
353 'label' => __( 'Date Type', 'woocommerce' ),
354 'description' => __( 'Database date field considered for Revenue and Orders reports', 'woocommerce' ),
355 'type' => 'select',
356 'options' => array(
357 'date_created' => 'date_created',
358 'date_paid' => 'date_paid',
359 'date_completed' => 'date_completed',
360 ),
361 );
362
363 if ( Features::is_enabled( 'analytics-scheduled-import' ) ) {
364 $settings[] = array(
365 'id' => 'woocommerce_analytics_scheduled_import',
366 'option_key' => 'woocommerce_analytics_scheduled_import',
367 'label' => __( 'Updates', 'woocommerce' ),
368 'description' => __( 'Controls how analytics data is imported from orders.', 'woocommerce' ),
369 'type' => 'radio',
370 'default' => null, // Default to null so we can know if it's a new site or an existing site. New sites will have the option set.
371 'options' => array(
372 'yes' => __( 'Scheduled (recommended)', 'woocommerce' ),
373 'no' => __( 'Immediately', 'woocommerce' ),
374 ),
375 );
376
377 // Add hidden setting for the import interval to display in the client side.
378 $import_interval = \Automattic\WooCommerce\Internal\Admin\Schedulers\OrdersScheduler::get_import_interval();
379 $import_interval = absint( $import_interval );
380 // Format the import interval to a human-readable string.
381 $import_interval_string = human_time_diff( 0, $import_interval );
382 $settings[] = array(
383 'id' => 'woocommerce_analytics_import_interval',
384 'option_key' => 'woocommerce_analytics_import_interval',
385 'type' => 'hidden',
386 'default' => $import_interval_string,
387 );
388 }
389
390 return $settings;
391 }
392
393 /**
394 * Gets custom settings used for WC Admin.
395 *
396 * @param array $settings Array of settings to merge into.
397 * @return array
398 */
399 private function get_custom_settings( $settings ) {
400 $wc_rest_settings_options_controller = new \WC_REST_Setting_Options_Controller();
401 $wc_admin_group_settings = $wc_rest_settings_options_controller->get_group_settings( 'wc_admin' );
402 $settings['wcAdminSettings'] = array();
403
404 foreach ( $wc_admin_group_settings as $setting ) {
405 if ( ! empty( $setting['id'] ) ) {
406 $settings['wcAdminSettings'][ $setting['id'] ] = $setting['value'];
407 }
408 }
409 return $settings;
410 }
411
412 /**
413 * Add the settings UI schema for the current classic settings page.
414 *
415 * @param array $settings Array of component settings.
416 * @return array
417 */
418 private function add_settings_ui_schema( array $settings ): array {
419 try {
420 if ( ! class_exists( SettingsUIRequestContext::class ) ) {
421 return $settings;
422 }
423
424 $context = SettingsUIRequestContext::get_current();
425 } catch ( \Throwable $e ) {
426 return $settings;
427 }
428
429 if ( ! $context ) {
430 return $settings;
431 }
432
433 $schema = $context->get_schema();
434 if ( ! is_array( $schema ) ) {
435 return $settings;
436 }
437
438 $page_id = $context->get_page_id();
439 $section_key = $context->get_current_section_key();
440
441 if ( ! isset( $settings['settingsUI'] ) || ! is_array( $settings['settingsUI'] ) ) {
442 $settings['settingsUI'] = array();
443 }
444 if ( ! isset( $settings['settingsUI'][ $page_id ] ) || ! is_array( $settings['settingsUI'][ $page_id ] ) ) {
445 $settings['settingsUI'][ $page_id ] = array();
446 }
447
448 $settings['settingsUI'][ $page_id ][ $section_key ] = $schema;
449
450 return $settings;
451 }
452 }
453