WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru
функция не описана

Automattic\WooCommerce\Blocks\Assets

Api::register_script() public WC 2.5.0

Registers a script according to wp_register_script, adding the correct prefix, and additionally loading translations.

When creating script assets, the following rules should be followed:

  1. All asset handles should have a wc- prefix.
  2. If the asset handle is for a Block (in editor context) use the -block suffix.
  3. If the asset handle is for a Block (in frontend context) use the -block-frontend suffix.
  4. If the asset is for any other script being consumed or enqueued by the blocks plugin, use the wc-blocks- prefix.

{} Это метод класса: Api{}

Возвращает

null. Ничего.

Использование

$Api = new Api();
$Api->register_script( $handle, $relative_src, $dependencies, $has_i18n );
$handle(строка) (обязательный)
Unique name of the script.
$relative_src(строка) (обязательный)
Relative url for the script to the path from plugin root.
$dependencies(массив)
An array of registered script handles this script depends on.
По умолчанию: empty array
$has_i18n(true|false)
Whether to add a script translation call to this file.
По умолчанию: true

Список изменений

С версии 2.5.0 Введена.

Код Api::register_script() WC 5.7.0

public function register_script( $handle, $relative_src, $dependencies = [], $has_i18n = true ) {
	$src     = '';
	$version = '1';

	if ( $relative_src ) {
		$src        = $this->get_asset_url( $relative_src );
		$asset_path = $this->package->get_path(
			str_replace( '.js', '.asset.php', $relative_src )
		);

		if ( file_exists( $asset_path ) ) {
			$asset        = require $asset_path;
			$dependencies = isset( $asset['dependencies'] ) ? array_merge( $asset['dependencies'], $dependencies ) : $dependencies;
			$version      = ! empty( $asset['version'] ) ? $asset['version'] : $this->get_file_version( $relative_src );
		} else {
			$version = $this->get_file_version( $relative_src );
		}
	}

	if ( in_array( $handle, $dependencies, true ) ) {
		if ( $this->package->feature()->is_development_environment() ) {
			$dependencies = array_diff( $dependencies, [ $handle ] );
				add_action(
					'admin_notices',
					function() use ( $handle ) {
							echo '<div class="error"><p>';
							/* translators: %s file handle name. */
							printf( esc_html__( 'Script with handle %s had a dependency on itself which has been removed. This is an indicator that your JS code has a circular dependency that can cause bugs.', 'woocommerce' ), esc_html( $handle ) );
							echo '</p></div>';
					}
				);
		} else {
			throw new Exception( sprintf( 'Script with handle %s had a dependency on itself. This is an indicator that your JS code has a circular dependency that can cause bugs.', $handle ) );
		}
	}

	wp_register_script( $handle, $src, apply_filters( 'woocommerce_blocks_register_script_dependencies', $dependencies, $handle ), $version, true );

	if ( $has_i18n && function_exists( 'wp_set_script_translations' ) ) {
		wp_set_script_translations( $handle, 'woocommerce', $this->package->get_path( 'languages' ) );
	}
}