nd added $handle argument. * @since 2.9.0 Made it so scripts are not loaded in admin pages. * @deprecated 4.5.0 Block types register the scripts themselves. * * @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 function register_block_script( $script_name, $handle = '', $dependencies = [] ) { _deprecated_function( 'register_block_script', '4.5.0' ); if ( is_admin() ) { return; } $relative_src = $this->get_block_asset_build_path( $script_name ); $handle = '' !== $handle ? 'wc-' . $handle : 'wc-' . $script_name; $this->register_script( $handle, $relative_src, $dependencies ); wp_enqueue_script( $handle ); } /** * Registers a style according to `wp_register_style`. * * @since 2.5.0 * @since 2.6.0 Change src to be relative source. * * @param string $handle Name of the stylesheet. Should be unique. * @param string $relative_src Relative source of the stylesheet to the plugin path. * @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)'. */ public function register_style( $handle, $relative_src, $deps = [], $media = 'all' ) { $filename = str_replace( plugins_url( '/', __DIR__ ), '', $relative_src ); $src = $this->get_asset_url( $relative_src ); $ver = $this->get_file_version( $filename ); wp_register_style( $handle, $src, $deps, $ver, $media ); } /** * Returns the appropriate asset path for loading either legacy builds or * current builds. * * @param string $filename Filename for asset path (without extension). * @param string $type File type (.css or .js). * * @return string The generated path. */ public function get_block_asset_build_path( $filename, $type = 'js' ) { global $wp_version; $suffix = version_compare( $wp_version, '5.3', '>=' ) ? '' : '-legacy'; return "build/$filename$suffix.$type"; } }