ng $file Local path to the file. * @return string The cache buster value to use for the given file. */ protected static function get_file_version( $file ) { if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && file_exists( \Automattic\WooCommerce\Blocks\Package::get_path() . $file ) ) { return filemtime( \Automattic\WooCommerce\Blocks\Package::get_path() . $file ); } return \Automattic\WooCommerce\Blocks\Package::get_version(); } /** * Queues a block script in the frontend. * * @since 2.3.0 * @since 2.6.0 Changed $name to $script_name and added $handle argument. * @since 2.9.0 Made it so scripts are not loaded in admin pages. * * @param string $script_name Name of the script used to identify the file inside build folder. * @param string $handle Optional. Provided if the handle should be different than the script name. `wc-` prefix automatically added. * @param array $dependencies Optional. An array of registered script handles this script depends on. Default empty array. */ public static function register_block_script( $script_name, $handle = '', $dependencies = [] ) { $asset_api = Package::container()->get( AssetApi::class ); $asset_api->register_block_script( $script_name, $handle, $dependencies ); } /** * Registers a style according to `wp_register_style`. * * @since 2.0.0 * * @param string $handle Name of the stylesheet. Should be unique. * @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory. * @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array. * @param string $media Optional. The media for which this stylesheet has been defined. Default 'all'. Accepts media types like * 'all', 'print' and 'screen', or media queries like '(orientation: portrait)' and '(max-width: 640px)'. */ protected static function register_style( $handle, $src, $deps = [], $media = 'all' ) { $filename = str_replace( plugins_url( '/', __DIR__ ), '', $src ); $ver = self::get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); } }