Automattic\WooCommerce\Internal\Admin
WCAdminAssets::register_scripts │ public │ WC 1.0
Registers all the necessary scripts and styles to show the admin experience.
Метод класса: WCAdminAssets{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$WCAdminAssets = new WCAdminAssets(); $WCAdminAssets->register_scripts();
Код WCAdminAssets::register_scripts() WCAdminAssets::register scripts WC 10.8.1
public function register_scripts() {
if ( ! function_exists( 'wp_set_script_translations' ) ) {
return;
}
// Register the JS scripts.
$scripts = array(
'wc-admin-layout',
'wc-explat',
'wc-experimental',
'wc-customer-effort-score',
// NOTE: This should be removed when Gutenberg is updated and the notices package is removed from WooCommerce Admin.
'wc-notices',
'wc-number',
'wc-tracks',
'wc-date',
'wc-components',
WC_ADMIN_APP,
'wc-csv',
'wc-store-data',
'wc-currency',
'wc-navigation',
'wc-block-templates',
'wc-experimental-products-app',
'wc-product-editor',
'wc-settings-editor',
'wc-remote-logging',
'wc-sanitize',
);
$scripts_map = array(
WC_ADMIN_APP => PageController::is_embed_page() ? 'embed' : 'app',
'wc-csv' => 'csv-export',
'wc-store-data' => 'data',
);
$translated_scripts = array(
'wc-currency',
'wc-date',
'wc-components',
'wc-customer-effort-score',
'wc-experimental-products-app',
'wc-experimental',
'wc-navigation',
'wc-product-editor',
WC_ADMIN_APP,
);
foreach ( $scripts as $script ) {
$script_path_name = isset( $scripts_map[ $script ] ) ? $scripts_map[ $script ] : str_replace( 'wc-', '', $script );
try {
$script_assets_filename = self::get_script_asset_filename( $script_path_name, 'index' );
$script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . $script_path_name . '/' . $script_assets_filename;
$script_version = self::get_file_version( 'js', $script_assets['version'] );
$script_dependencies = $this->modify_script_dependencies( $script_assets['dependencies'], $script, $script_path_name );
wp_register_script(
$script,
self::get_url( $script_path_name . '/index', 'js' ),
$script_dependencies,
$script_version,
true
);
if ( in_array( $script, $translated_scripts, true ) ) {
wp_set_script_translations( $script, 'woocommerce' );
}
if ( WC_ADMIN_APP === $script ) {
wp_localize_script(
WC_ADMIN_APP,
'wcAdminAssets',
array(
'path' => plugins_url( self::get_path( 'js' ), WC_ADMIN_PLUGIN_FILE ),
'version' => $script_version,
)
);
}
} catch ( \Exception $e ) {
// Avoid crashing WordPress if an asset file could not be loaded.
wc_caught_exception( $e, __CLASS__ . '::' . __FUNCTION__, $script_path_name );
}
}
// Register the CSS styles.
$styles = array(
array(
'handle' => 'wc-admin-layout',
),
array(
'handle' => 'wc-components',
),
array(
'handle' => 'wc-block-templates',
),
array(
'handle' => 'wc-experimental-products-app',
),
array(
'handle' => 'wc-product-editor',
),
array(
'handle' => 'wc-settings-editor',
),
array(
'handle' => 'wc-customer-effort-score',
),
array(
'handle' => 'wc-experimental',
),
array(
'handle' => WC_ADMIN_APP,
'dependencies' => array( 'wc-components', 'wc-admin-layout', 'wc-customer-effort-score', 'wp-components', 'wc-experimental' ),
),
array(
'handle' => 'wc-onboarding',
),
);
$css_file_version = self::get_file_version( 'css' );
foreach ( $styles as $style ) {
$handle = $style['handle'];
$style_path_name = isset( $scripts_map[ $handle ] ) ? $scripts_map[ $handle ] : str_replace( 'wc-', '', $handle );
try {
$style_assets_filename = self::get_script_asset_filename( $style_path_name, 'style' );
$style_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . $style_path_name . '/' . $style_assets_filename;
$version = $style_assets['version'];
} catch ( \Throwable $e ) {
// Use the default version if the asset file could not be loaded.
$version = $css_file_version;
}
$dependencies = isset( $style['dependencies'] ) ? $style['dependencies'] : array();
wp_register_style(
$handle,
self::get_url( $style_path_name . '/style', 'css' ),
$dependencies,
self::get_file_version( 'css', $version ),
);
wp_style_add_data( $handle, 'rtl', 'replace' );
}
}