Automattic\WooCommerce\Internal\Admin
WCAdminAssets::register_script()
Loads a script
Method of the class: WCAdminAssets{}
No Hooks.
Return
null
. Nothing (null).
Usage
$result = WCAdminAssets::register_script( $script_path_name, $script_name, $need_translation, $dependencies );
- $script_path_name(string) (required)
- The script path name.
- $script_name(string) (required)
- Filename of the script to load.
- $need_translation(true|false)
- Whether the script need translations.
Default: false - $dependencies(array)
- Array of any extra dependencies. Note wc-admin and any application JS dependencies are automatically added by Dependency Extraction Webpack Plugin. Use this parameter to designate any extra dependencies.
Default: array()
WCAdminAssets::register_script() WCAdminAssets::register script code WC 9.5.1
public static function register_script( $script_path_name, $script_name, $need_translation = false, $dependencies = array() ) { $script_assets_filename = self::get_script_asset_filename( $script_path_name, $script_name ); $script_assets = require WC_ADMIN_ABSPATH . WC_ADMIN_DIST_JS_FOLDER . $script_path_name . '/' . $script_assets_filename; wp_enqueue_script( 'wc-admin-' . $script_name, self::get_url( $script_path_name . '/' . $script_name, 'js' ), array_merge( array( WC_ADMIN_APP ), $script_assets ['dependencies'], $dependencies ), self::get_file_version( 'js', $script_assets['version'] ), true ); if ( $need_translation ) { wp_set_script_translations( 'wc-admin-' . $script_name, 'woocommerce' ); } }