2018-04-17 23:51:48 +00:00
|
|
|
<?php
|
2018-08-20 21:18:13 +00:00
|
|
|
/**
|
|
|
|
* Register javascript & css files.
|
|
|
|
*
|
|
|
|
* @package WC_Admin
|
|
|
|
*/
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
/**
|
2018-07-10 12:48:06 +00:00
|
|
|
* Registers the JS & CSS for the admin and admin embed
|
2018-04-17 23:51:48 +00:00
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_register_script() {
|
2018-06-26 14:49:42 +00:00
|
|
|
// Are we displaying the full React app or just embedding the header on a classic screen?
|
2018-07-10 12:48:06 +00:00
|
|
|
$screen_id = wc_admin_get_current_screen_id();
|
2018-06-26 14:49:42 +00:00
|
|
|
|
2018-07-10 12:48:06 +00:00
|
|
|
if ( in_array( $screen_id, wc_admin_get_embed_enabled_screen_ids() ) ) {
|
2018-07-30 17:41:14 +00:00
|
|
|
$js_entry = 'dist/embedded.js';
|
2018-06-26 14:49:42 +00:00
|
|
|
$css_entry = 'dist/css/embedded.css';
|
|
|
|
} else {
|
2018-07-30 17:41:14 +00:00
|
|
|
$js_entry = 'dist/index.js';
|
2018-06-26 14:49:42 +00:00
|
|
|
$css_entry = 'dist/css/index.css';
|
|
|
|
}
|
|
|
|
|
2018-08-20 21:18:13 +00:00
|
|
|
wp_register_script(
|
|
|
|
'wc-components',
|
|
|
|
wc_admin_url( 'dist/components.js' ),
|
|
|
|
[ 'wp-components', 'wp-data', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-keycodes' ],
|
|
|
|
filemtime( wc_admin_dir_path( 'dist/components.js' ) ),
|
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_register_style(
|
|
|
|
'wc-components',
|
|
|
|
wc_admin_url( 'dist/css/components.css' ),
|
|
|
|
[ 'wp-edit-blocks' ],
|
|
|
|
filemtime( wc_admin_dir_path( 'dist/css/components.css' ) )
|
|
|
|
);
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
wp_register_script(
|
2018-07-10 12:48:06 +00:00
|
|
|
WC_ADMIN_APP,
|
|
|
|
wc_admin_url( $js_entry ),
|
2018-08-20 21:18:13 +00:00
|
|
|
[ 'wc-components', 'wp-date', 'wp-html-entities', 'wp-keycodes' ],
|
2018-07-10 12:48:06 +00:00
|
|
|
filemtime( wc_admin_dir_path( $js_entry ) ),
|
2018-04-17 23:51:48 +00:00
|
|
|
true
|
|
|
|
);
|
|
|
|
|
|
|
|
wp_register_style(
|
2018-07-10 12:48:06 +00:00
|
|
|
WC_ADMIN_APP,
|
|
|
|
wc_admin_url( $css_entry ),
|
2018-08-20 21:18:13 +00:00
|
|
|
[ 'wc-components' ],
|
2018-07-10 12:48:06 +00:00
|
|
|
filemtime( wc_admin_dir_path( $css_entry ) )
|
2018-04-17 23:51:48 +00:00
|
|
|
);
|
|
|
|
|
2018-08-20 21:18:13 +00:00
|
|
|
// Set up the text domain and translations.
|
2018-07-10 12:48:06 +00:00
|
|
|
$locale_data = gutenberg_get_jed_locale_data( 'wc-admin' );
|
2018-08-20 21:18:13 +00:00
|
|
|
$content = 'wp.i18n.setLocaleData( ' . json_encode( $locale_data ) . ', "wc-admin" );';
|
|
|
|
wp_add_inline_script( 'wc-components', $content, 'before' );
|
2018-05-03 14:15:36 +00:00
|
|
|
|
2018-09-11 19:48:43 +00:00
|
|
|
// Add Tracks script to the DOM if tracking is opted in.
|
2018-09-07 14:36:20 +00:00
|
|
|
$tracking_enabled = 'yes' === get_option( 'woocommerce_allow_tracking', 'no' );
|
2018-09-11 19:48:43 +00:00
|
|
|
if ( $tracking_enabled ) {
|
2018-09-07 14:36:20 +00:00
|
|
|
$tracking_script = "var wc_tracking_script = document.createElement( 'script' );\n";
|
2018-09-11 19:48:43 +00:00
|
|
|
$tracking_script .= "wc_tracking_script.src = '//stats.wp.com/w.js';\n"; // TODO Version/cache buster.
|
2018-09-07 14:36:20 +00:00
|
|
|
$tracking_script .= "wc_tracking_script.type = 'text/javascript';\n";
|
|
|
|
$tracking_script .= "wc_tracking_script.async = true;\n";
|
|
|
|
$tracking_script .= "wc_tracking_script.defer = true;\n";
|
|
|
|
$tracking_script .= "window._tkq = window._tkq || [];\n";
|
|
|
|
$tracking_script .= "document.head.appendChild( wc_tracking_script );\n";
|
|
|
|
wp_add_inline_script( 'wc-components', $tracking_script, 'before' );
|
|
|
|
}
|
|
|
|
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
/**
|
2018-09-11 19:48:43 +00:00
|
|
|
* TODO: On merge, once plugin images are added to core WooCommerce, `wcAdminAssetUrl` can be retired, and
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
* `wcAssetUrl` can be used in its place throughout the codebase.
|
|
|
|
*/
|
|
|
|
|
2018-08-20 21:18:13 +00:00
|
|
|
// Settings and variables can be passed here for access in the app.
|
2018-05-10 18:35:55 +00:00
|
|
|
$settings = array(
|
2018-08-20 21:18:13 +00:00
|
|
|
'adminUrl' => admin_url(),
|
|
|
|
'wcAssetUrl' => plugins_url( 'assets/', WC_PLUGIN_FILE ),
|
Add loading indicators, error state, and EmptyContent to the revenue report. (#347, woocommerce/woocommerce-admin#348)
* Add loading indiciators for the revenue report.
* Improve accessibility, and fix up some documentation comments.
* Fix top border on mobile
* Add EmptyContent Component and revenue error/empty states. (https://github.com/woocommerce/woocommerce-admin/pull/348)
* Add EmptyContent Component and revenue error/empty states.
* Move relative image handling to ImageAsset, combine secondary and primary action rendering, add some missing isRequired proptypes, add empty error handling.
* Handle PR Feedback: Clean up button css, set a default for illustration, fix deprecation typo, some code cleanup.
2018-09-05 16:45:49 +00:00
|
|
|
'wcAdminAssetUrl' => plugins_url( 'images/', wc_admin_dir_path( 'wc-admin.php' ) ), // Temporary for plugin. See above.
|
2018-08-20 21:18:13 +00:00
|
|
|
'embedBreadcrumbs' => wc_admin_get_embed_breadcrumbs(),
|
|
|
|
'siteLocale' => esc_attr( get_bloginfo( 'language' ) ),
|
|
|
|
'currency' => wc_admin_currency_settings(),
|
|
|
|
'date' => array(
|
2018-07-04 01:50:12 +00:00
|
|
|
'dow' => get_option( 'start_of_week', 0 ),
|
|
|
|
),
|
2018-08-20 21:18:13 +00:00
|
|
|
'orderStatuses' => wc_get_order_statuses(),
|
|
|
|
'siteTitle' => get_bloginfo( 'name' ),
|
2018-09-07 14:36:20 +00:00
|
|
|
'trackingEnabled' => $tracking_enabled,
|
2018-05-10 18:35:55 +00:00
|
|
|
);
|
2018-06-26 14:49:42 +00:00
|
|
|
|
2018-05-10 18:35:55 +00:00
|
|
|
wp_add_inline_script(
|
2018-08-20 21:18:13 +00:00
|
|
|
'wc-components',
|
|
|
|
'var wcSettings = ' . json_encode( $settings ) . ';',
|
2018-05-10 18:35:55 +00:00
|
|
|
'before'
|
|
|
|
);
|
2018-05-23 16:40:10 +00:00
|
|
|
|
2018-08-20 21:18:13 +00:00
|
|
|
// Resets lodash to wp-admin's version of lodash.
|
2018-05-23 16:40:10 +00:00
|
|
|
wp_add_inline_script(
|
2018-07-10 12:48:06 +00:00
|
|
|
WC_ADMIN_APP,
|
2018-05-23 16:40:10 +00:00
|
|
|
'_.noConflict();',
|
|
|
|
'after'
|
|
|
|
);
|
|
|
|
|
2018-04-17 23:51:48 +00:00
|
|
|
}
|
2018-07-10 12:48:06 +00:00
|
|
|
add_action( 'admin_enqueue_scripts', 'wc_admin_register_script' );
|
2018-04-17 23:51:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load plugin text domain for translations.
|
|
|
|
*/
|
2018-07-10 12:48:06 +00:00
|
|
|
function wc_admin_load_plugin_textdomain() {
|
|
|
|
load_plugin_textdomain( 'wc-admin', false, basename( dirname( __FILE__ ) ) . '/languages' );
|
2018-04-17 23:51:48 +00:00
|
|
|
}
|
2018-07-10 12:48:06 +00:00
|
|
|
add_action( 'plugins_loaded', 'wc_admin_load_plugin_textdomain' );
|