$value ) { $formatted_key = preg_replace( '/^wc-/', '', $key ); $formatted_statuses[ $formatted_key ] = $value; } return $formatted_statuses; } /** * Output the wcSettings global before printing any script tags. */ function wc_admin_print_script_settings() { global $wp_locale; $preload_data_endpoints = array( 'countries' => '/wc/v4/data/countries', 'performanceIndicators' => '/wc/v4/reports/performance-indicators/allowed', ); if ( function_exists( 'gutenberg_preload_api_request' ) ) { $preload_function = 'gutenberg_preload_api_request'; } else { $preload_function = 'rest_preload_api_request'; } $preload_data = array_reduce( array_values( $preload_data_endpoints ), $preload_function ); $current_user_data = array(); foreach ( wc_admin_get_user_data_fields() as $user_field ) { $current_user_data[ $user_field ] = json_decode( get_user_meta( get_current_user_id(), 'wc_admin_' . $user_field, true ) ); } /** * Settings and variables can be passed here for access in the app. * * @todo On merge, once plugin images are added to core WooCommerce, `wcAdminAssetUrl` can be retired, and * `wcAssetUrl` can be used in its place throughout the codebase. */ $settings = array( 'adminUrl' => admin_url(), 'wcAssetUrl' => plugins_url( 'assets/', WC_PLUGIN_FILE ), 'wcAdminAssetUrl' => plugins_url( 'images/', wc_admin_dir_path( 'wc-admin.php' ) ), // Temporary for plugin. See above. 'embedBreadcrumbs' => wc_admin_get_embed_breadcrumbs(), 'siteLocale' => esc_attr( get_bloginfo( 'language' ) ), 'currency' => wc_admin_currency_settings(), 'orderStatuses' => format_order_statuses( wc_get_order_statuses() ), 'stockStatuses' => wc_get_product_stock_status_options(), 'siteTitle' => get_bloginfo( 'name' ), 'dataEndpoints' => array(), 'l10n' => array( 'userLocale' => get_user_locale(), 'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ), ), 'currentUserData' => $current_user_data, ); $settings = wc_admin_add_custom_settings( $settings ); foreach ( $preload_data_endpoints as $key => $endpoint ) { $settings['dataEndpoints'][ $key ] = $preload_data[ $endpoint ]['body']; } $settings = apply_filters( 'wc_admin_wc_settings', $settings ); ?> get_group_settings( 'wc_admin' ); $settings['wcAdminSettings'] = array(); foreach ( $wc_admin_group_settings as $setting ) { $settings['wcAdminSettings'][ $setting['id'] ] = $setting['value']; } return $settings; } /** * Load plugin text domain for translations. */ function wc_admin_load_plugin_textdomain() { load_plugin_textdomain( 'wc-admin', false, basename( dirname( __FILE__ ) ) . '/languages' ); } add_action( 'plugins_loaded', 'wc_admin_load_plugin_textdomain' );