Agentic
4 months ago
BlockTemplates
4 weeks ago
EmailImprovements
1 year ago
EmailPreview
4 weeks ago
Emails
1 year ago
ImportExport
1 year ago
Logging
1 year ago
Marketing
2 years ago
Notes
4 weeks ago
Onboarding
5 months ago
Orders
4 weeks ago
ProductForm
2 years ago
ProductReviews
4 weeks ago
RemoteFreeExtensions
4 weeks ago
Schedulers
4 weeks ago
Settings
2 weeks ago
Suggestions
4 weeks ago
WCPayPromotion
10 months ago
ActivityPanels.php
3 years ago
Analytics.php
4 weeks 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
1 month ago
Loader.php
4 weeks ago
Marketing.php
1 year ago
Marketplace.php
5 months ago
MobileAppBanner.php
4 years ago
OrderMilestoneEasterEgg.php
4 weeks ago
RemoteInboxNotifications.php
3 years ago
Settings.php
2 weeks ago
ShippingLabelBanner.php
1 year ago
ShippingLabelBannerDisplayRules.php
1 year ago
SiteHealth.php
3 years ago
Survey.php
4 years ago
SystemStatusReport.php
1 year ago
Translations.php
1 year ago
WCAdminAssets.php
2 weeks ago
WCAdminSharedSettings.php
1 year ago
WCAdminUser.php
9 months ago
WcPayWelcomePage.php
1 year ago
Loader.php
574 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( Reviews::class ); |
| 74 | wc_get_container()->get( ReviewsCommentsOverrides::class ); |
| 75 | |
| 76 | add_filter( 'admin_body_class', array( __CLASS__, 'add_admin_body_classes' ) ); |
| 77 | add_filter( 'admin_title', array( __CLASS__, 'update_admin_title' ) ); |
| 78 | add_action( 'in_admin_header', array( __CLASS__, 'embed_page_header' ) ); |
| 79 | add_action( 'admin_head', array( __CLASS__, 'remove_notices' ) ); |
| 80 | add_action( 'admin_head', array( __CLASS__, 'smart_app_banner' ) ); |
| 81 | add_action( 'admin_notices', array( __CLASS__, 'inject_before_notices' ), -9999 ); |
| 82 | add_action( 'admin_notices', array( __CLASS__, 'inject_after_notices' ), PHP_INT_MAX ); |
| 83 | |
| 84 | // Added this hook to delete the field woocommerce_onboarding_homepage_post_id when deleting the homepage. |
| 85 | add_action( 'trashed_post', array( __CLASS__, 'delete_homepage' ) ); |
| 86 | |
| 87 | /* |
| 88 | * Remove the emoji script as it always defaults to replacing emojis with Twemoji images. |
| 89 | * Gutenberg has also disabled emojis. More on that here -> https://github.com/WordPress/gutenberg/pull/6151 |
| 90 | */ |
| 91 | remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
| 92 | |
| 93 | add_action( 'load-themes.php', array( __CLASS__, 'add_appearance_theme_view_tracks_event' ) ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Returns breadcrumbs for the current page. |
| 98 | */ |
| 99 | private static function get_embed_breadcrumbs() { |
| 100 | return wc_admin_get_breadcrumbs(); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Outputs breadcrumbs via PHP for the initial load of an embedded page. |
| 105 | * |
| 106 | * @param array $section Section to create breadcrumb from. |
| 107 | */ |
| 108 | private static function output_heading( $section ) { |
| 109 | echo esc_html( $section ); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Set up a div for the header embed to render into. |
| 114 | * The initial contents here are meant as a place loader for when the PHP page initially loads. |
| 115 | */ |
| 116 | public static function embed_page_header() { |
| 117 | if ( ! PageController::is_admin_page() && ! PageController::is_embed_page() ) { |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | if ( ! PageController::is_embed_page() ) { |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | $sections = self::get_embed_breadcrumbs(); |
| 126 | $sections = is_array( $sections ) ? $sections : array( $sections ); |
| 127 | |
| 128 | $page_title = ''; |
| 129 | $pages_with_tabs = array( |
| 130 | 'admin.php?page=wc-settings', |
| 131 | 'admin.php?page=wc-reports', |
| 132 | 'admin.php?page=wc-status', |
| 133 | ); |
| 134 | |
| 135 | if ( |
| 136 | count( $sections ) > 2 && |
| 137 | is_array( $sections[1] ) && |
| 138 | in_array( $sections[1][0], $pages_with_tabs, true ) |
| 139 | ) { |
| 140 | $page_title = $sections[1][1]; |
| 141 | } else { |
| 142 | $page_title = end( $sections ); |
| 143 | } |
| 144 | ?> |
| 145 | <div id="woocommerce-embedded-root" class="is-embed-loading"> |
| 146 | <div class="woocommerce-layout"> |
| 147 | <div class="woocommerce-layout__header is-embed-loading"> |
| 148 | <h1 class="woocommerce-layout__header-heading"> |
| 149 | <?php self::output_heading( $page_title ); ?> |
| 150 | </h1> |
| 151 | </div> |
| 152 | </div> |
| 153 | </div> |
| 154 | <?php |
| 155 | } |
| 156 | |
| 157 | /** |
| 158 | * Adds body classes to the main wp-admin wrapper, allowing us to better target elements in specific scenarios. |
| 159 | * |
| 160 | * @param string $admin_body_class Body class to add. |
| 161 | */ |
| 162 | public static function add_admin_body_classes( $admin_body_class = '' ) { |
| 163 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 164 | return $admin_body_class; |
| 165 | } |
| 166 | |
| 167 | $classes = explode( ' ', trim( $admin_body_class ) ); |
| 168 | $classes[] = 'woocommerce-admin-page'; |
| 169 | if ( PageController::is_embed_page() ) { |
| 170 | $classes[] = 'woocommerce-embed-page'; |
| 171 | } |
| 172 | |
| 173 | // Add page ID as a class. |
| 174 | $page_id = PageController::get_instance()->get_current_screen_id(); |
| 175 | if ( $page_id ) { |
| 176 | $classes[] = $page_id; |
| 177 | } |
| 178 | |
| 179 | /** |
| 180 | * Some routes or features like onboarding hide the wp-admin navigation and masterbar. |
| 181 | * Setting `woocommerce_admin_is_loading` to true allows us to premeptively hide these |
| 182 | * elements while the JS app loads. |
| 183 | * This class needs to be removed by those feature components (like <ProfileWizard />). |
| 184 | * |
| 185 | * @param bool $is_loading If WooCommerce Admin is loading a fullscreen view. |
| 186 | * @since 6.5.0 |
| 187 | */ |
| 188 | $is_loading = apply_filters( 'woocommerce_admin_is_loading', false ); |
| 189 | |
| 190 | if ( PageController::is_admin_page() && $is_loading ) { |
| 191 | $classes[] = 'woocommerce-admin-is-loading'; |
| 192 | } |
| 193 | |
| 194 | $admin_body_class = implode( ' ', array_unique( $classes ) ); |
| 195 | return " $admin_body_class "; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Adds an iOS "Smart App Banner" for display on iOS Safari. |
| 200 | * See https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/PromotingAppswithAppBanners/PromotingAppswithAppBanners.html |
| 201 | */ |
| 202 | public static function smart_app_banner() { |
| 203 | $exclude_paths = array( |
| 204 | '/customize-store', |
| 205 | '/setup-wizard', |
| 206 | '/launch-your-store', |
| 207 | ); |
| 208 | |
| 209 | /* phpcs:ignore */ |
| 210 | $path = $_GET['path'] ?? ''; |
| 211 | |
| 212 | if ( PageController::is_admin_or_embed_page() && ! in_array( $path, $exclude_paths, true ) ) { |
| 213 | echo " |
| 214 | <meta name='apple-itunes-app' content='app-id=1389130815'> |
| 215 | "; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | |
| 220 | /** |
| 221 | * Removes notices that should not be displayed on WC Admin pages. |
| 222 | */ |
| 223 | public static function remove_notices() { |
| 224 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 225 | return; |
| 226 | } |
| 227 | |
| 228 | // Hello Dolly. |
| 229 | if ( function_exists( 'hello_dolly' ) ) { |
| 230 | remove_action( 'admin_notices', 'hello_dolly' ); |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | /** |
| 235 | * Runs before admin notices action and hides them. |
| 236 | */ |
| 237 | public static function inject_before_notices() { |
| 238 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 239 | return; |
| 240 | } |
| 241 | |
| 242 | // The JITMs won't be shown in the Onboarding Wizard. |
| 243 | $is_onboarding = isset( $_GET['path'] ) && '/setup-wizard' === wc_clean( wp_unslash( $_GET['path'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
| 244 | $maybe_hide_jitm = $is_onboarding ? '-hide' : ''; |
| 245 | |
| 246 | echo '<div class="woocommerce-layout__jitm' . sanitize_html_class( $maybe_hide_jitm ) . '" id="jp-admin-notices"></div>'; |
| 247 | |
| 248 | // Wrap the notices in a hidden div to prevent flickering before |
| 249 | // they are moved elsewhere in the page by WordPress Core. |
| 250 | echo '<div class="woocommerce-layout__notice-list-hide" id="wp__notice-list">'; |
| 251 | |
| 252 | if ( PageController::is_admin_page() ) { |
| 253 | // Capture all notices and hide them. WordPress Core looks for |
| 254 | // `.wp-header-end` and appends notices after it if found. |
| 255 | // https://github.com/WordPress/WordPress/blob/f6a37e7d39e2534d05b9e542045174498edfe536/wp-admin/js/common.js#L737 . |
| 256 | echo '<div class="wp-header-end" id="woocommerce-layout__notice-catcher"></div>'; |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | /** |
| 261 | * Runs after admin notices and closes div. |
| 262 | */ |
| 263 | public static function inject_after_notices() { |
| 264 | if ( ! PageController::is_admin_or_embed_page() ) { |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | // Close the hidden div used to prevent notices from flickering before |
| 269 | // they are inserted elsewhere in the page. |
| 270 | echo '</div>'; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Edits Admin title based on section of wc-admin. |
| 275 | * |
| 276 | * @param string $admin_title Modifies admin title. |
| 277 | * @todo Can we do some URL rewriting so we can figure out which page they are on server side? |
| 278 | */ |
| 279 | public static function update_admin_title( $admin_title ) { |
| 280 | if ( |
| 281 | ! did_action( 'current_screen' ) || |
| 282 | ! PageController::is_admin_page() |
| 283 | ) { |
| 284 | return $admin_title; |
| 285 | } |
| 286 | |
| 287 | $sections = self::get_embed_breadcrumbs(); |
| 288 | $pieces = array(); |
| 289 | |
| 290 | foreach ( $sections as $section ) { |
| 291 | $pieces[] = is_array( $section ) ? $section[1] : $section; |
| 292 | } |
| 293 | |
| 294 | $pieces = array_reverse( $pieces ); |
| 295 | $title = implode( ' ‹ ', $pieces ); |
| 296 | |
| 297 | /* translators: %1$s: updated title, %2$s: blog info name */ |
| 298 | return sprintf( __( '%1$s ‹ %2$s', 'woocommerce' ), $title, get_bloginfo( 'name' ) ); |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Set up a div for the app to render into. |
| 303 | */ |
| 304 | public static function page_wrapper() { |
| 305 | ?> |
| 306 | <div class="wrap"> |
| 307 | <div id="root"></div> |
| 308 | </div> |
| 309 | <?php |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * Hooks extra necessary data into the component settings array already set in WooCommerce core. |
| 314 | * |
| 315 | * @param array $settings Array of component settings. |
| 316 | * @return array Array of component settings. |
| 317 | */ |
| 318 | public static function add_component_settings( $settings ) { |
| 319 | if ( ! is_admin() ) { |
| 320 | return $settings; |
| 321 | } |
| 322 | |
| 323 | if ( ! function_exists( 'wc_blocks_container' ) ) { |
| 324 | global $wp_locale; |
| 325 | // inject data not available via older versions of wc_blocks/woo. |
| 326 | $settings['orderStatuses'] = Settings::get_order_statuses( wc_get_order_statuses() ); |
| 327 | $settings['stockStatuses'] = Settings::get_order_statuses( wc_get_product_stock_status_options() ); |
| 328 | $settings['currency'] = Settings::get_currency_settings(); |
| 329 | $settings['locale'] = array( |
| 330 | 'siteLocale' => isset( $settings['siteLocale'] ) |
| 331 | ? $settings['siteLocale'] |
| 332 | : get_locale(), |
| 333 | 'userLocale' => isset( $settings['l10n']['userLocale'] ) |
| 334 | ? $settings['l10n']['userLocale'] |
| 335 | : get_user_locale(), |
| 336 | 'weekdaysShort' => isset( $settings['l10n']['weekdaysShort'] ) |
| 337 | ? $settings['l10n']['weekdaysShort'] |
| 338 | : array_values( $wp_locale->weekday_abbrev ), |
| 339 | ); |
| 340 | } |
| 341 | |
| 342 | /** |
| 343 | * The woocommerce_component_settings_preload_endpoints filter |
| 344 | * |
| 345 | * @since 6.5.0 |
| 346 | */ |
| 347 | $preload_data_endpoints = apply_filters( 'woocommerce_component_settings_preload_endpoints', array() ); |
| 348 | |
| 349 | $preload_data_endpoints['jetpackStatus'] = '/jetpack/v4/connection'; |
| 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 | if ( ! empty( $preload_data_endpoints ) ) { |
| 425 | $settings['dataEndpoints'] = isset( $settings['dataEndpoints'] ) |
| 426 | ? $settings['dataEndpoints'] |
| 427 | : array(); |
| 428 | foreach ( $preload_data_endpoints as $key => $endpoint ) { |
| 429 | // Handle error case: rest_do_request() doesn't guarantee success. |
| 430 | if ( empty( $preload_data[ $endpoint ] ) ) { |
| 431 | $settings['dataEndpoints'][ $key ] = array(); |
| 432 | } else { |
| 433 | $settings['dataEndpoints'][ $key ] = $preload_data[ $endpoint ]['body']; |
| 434 | } |
| 435 | } |
| 436 | } |
| 437 | $settings = self::get_custom_settings( $settings ); |
| 438 | if ( PageController::is_embed_page() ) { |
| 439 | $settings['embedBreadcrumbs'] = self::get_embed_breadcrumbs(); |
| 440 | } |
| 441 | |
| 442 | $settings['allowMarketplaceSuggestions'] = WC_Marketplace_Suggestions::allow_suggestions(); |
| 443 | $settings['connectNonce'] = wp_create_nonce( 'connect' ); |
| 444 | $settings['wcpay_welcome_page_connect_nonce'] = wp_create_nonce( 'wcpay-connect' ); |
| 445 | |
| 446 | return $settings; |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Format order statuses by removing a leading 'wc-' if present. |
| 451 | * |
| 452 | * @param array $statuses Order statuses. |
| 453 | * @return array formatted statuses. |
| 454 | * |
| 455 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 456 | */ |
| 457 | public static function get_order_statuses( $statuses ) { |
| 458 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::get_order_statuses' ); |
| 459 | |
| 460 | return Settings::get_order_statuses( $statuses ); |
| 461 | } |
| 462 | |
| 463 | /** |
| 464 | * Get all order statuses present in analytics tables that aren't registered. |
| 465 | * |
| 466 | * @return array Unregistered order statuses. |
| 467 | * |
| 468 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 469 | */ |
| 470 | public static function get_unregistered_order_statuses() { |
| 471 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0' ); |
| 472 | |
| 473 | $registered_statuses = wc_get_order_statuses(); |
| 474 | $all_synced_statuses = OrdersDataStore::get_all_statuses(); |
| 475 | $unregistered_statuses = array_diff( $all_synced_statuses, array_keys( $registered_statuses ) ); |
| 476 | $formatted_status_keys = Settings::get_order_statuses( array_fill_keys( $unregistered_statuses, '' ) ); |
| 477 | $formatted_statuses = array_keys( $formatted_status_keys ); |
| 478 | |
| 479 | return array_combine( $formatted_statuses, $formatted_statuses ); |
| 480 | } |
| 481 | |
| 482 | /** |
| 483 | * Register the admin settings for use in the WC REST API |
| 484 | * |
| 485 | * @param array $groups Array of setting groups. |
| 486 | * @return array |
| 487 | * |
| 488 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 489 | */ |
| 490 | public static function add_settings_group( $groups ) { |
| 491 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::add_settings_group' ); |
| 492 | |
| 493 | return Settings::get_instance()->add_settings_group( $groups ); |
| 494 | } |
| 495 | |
| 496 | /** |
| 497 | * Add WC Admin specific settings |
| 498 | * |
| 499 | * @param array $settings Array of settings in wc admin group. |
| 500 | * @return array |
| 501 | * |
| 502 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 503 | */ |
| 504 | public static function add_settings( $settings ) { |
| 505 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::add_settings' ); |
| 506 | |
| 507 | return Settings::get_instance()->add_settings( $settings ); |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Gets custom settings used for WC Admin. |
| 512 | * |
| 513 | * @param array $settings Array of settings to merge into. |
| 514 | * @return array |
| 515 | * |
| 516 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 517 | */ |
| 518 | public static function get_custom_settings( $settings ) { |
| 519 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0' ); |
| 520 | |
| 521 | $wc_rest_settings_options_controller = new \WC_REST_Setting_Options_Controller(); |
| 522 | $wc_admin_group_settings = $wc_rest_settings_options_controller->get_group_settings( 'wc_admin' ); |
| 523 | $settings['wcAdminSettings'] = array(); |
| 524 | |
| 525 | foreach ( $wc_admin_group_settings as $setting ) { |
| 526 | if ( ! empty( $setting['id'] ) ) { |
| 527 | $settings['wcAdminSettings'][ $setting['id'] ] = $setting['value']; |
| 528 | } |
| 529 | } |
| 530 | return $settings; |
| 531 | } |
| 532 | |
| 533 | /** |
| 534 | * Return an object defining the currency options for the site's current currency |
| 535 | * |
| 536 | * @return array Settings for the current currency { |
| 537 | * Array of settings. |
| 538 | * |
| 539 | * @type string $code Currency code. |
| 540 | * @type string $precision Number of decimals. |
| 541 | * @type string $symbol Symbol for currency. |
| 542 | * } |
| 543 | * |
| 544 | * @deprecated migrate to \Automattic\WooCommerce\Internal\Admin\Settings instead. |
| 545 | */ |
| 546 | public static function get_currency_settings() { |
| 547 | wc_deprecated_function( __CLASS__ . '::' . __FUNCTION__, '9.9.0', '\Automattic\WooCommerce\Internal\Admin\Settings::get_currency_settings' ); |
| 548 | |
| 549 | return Settings::get_currency_settings(); |
| 550 | } |
| 551 | |
| 552 | /** |
| 553 | * Delete woocommerce_onboarding_homepage_post_id field when the homepage is deleted |
| 554 | * |
| 555 | * @param int $post_id The deleted post id. |
| 556 | */ |
| 557 | public static function delete_homepage( $post_id ) { |
| 558 | if ( 'page' !== get_post_type( $post_id ) ) { |
| 559 | return; |
| 560 | } |
| 561 | $homepage_id = intval( get_option( 'woocommerce_onboarding_homepage_post_id', false ) ); |
| 562 | if ( $homepage_id === $post_id ) { |
| 563 | delete_option( 'woocommerce_onboarding_homepage_post_id' ); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Adds the appearance_theme_view Tracks event. |
| 569 | */ |
| 570 | public static function add_appearance_theme_view_tracks_event() { |
| 571 | wc_admin_record_tracks_event( 'appearance_theme_view', array() ); |
| 572 | } |
| 573 | } |
| 574 |