Automattic\WooCommerce\Blocks\BlockTypes

MiniCart::append_script_and_deps_src()protectedWC 1.0

Recursively appends a scripts and its dependencies into the scripts_to_lazy_load array.

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

Хуков нет.

Возвращает

null. Ничего.

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

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->append_script_and_deps_src( $script );
$script(\_WP_Dependency) (обязательный)
Object containing script data.

Код MiniCart::append_script_and_deps_src() WC 6.9.4

protected function append_script_and_deps_src( $script ) {
	$wp_scripts = wp_scripts();

	// This script and its dependencies have already been appended.
	if ( ! $script || array_key_exists( $script->handle, $this->scripts_to_lazy_load ) ) {
		return;
	}

	if ( count( $script->deps ) ) {
		foreach ( $script->deps as $dep ) {
			if ( ! array_key_exists( $dep, $this->scripts_to_lazy_load ) ) {
				$dep_script = $this->get_script_from_handle( $dep );

				if ( ! is_null( $dep_script ) ) {
					$this->append_script_and_deps_src( $dep_script );
				}
			}
		}
	}
	if ( ! $script->src ) {
		return;
	}

	$site_url = site_url() ?? wp_guess_url();

	$this->scripts_to_lazy_load[ $script->handle ] = array(
		'src'          => preg_match( '|^(https?:)?//|', $script->src ) ? $script->src : $site_url . $script->src,
		'version'      => $script->ver,
		'before'       => $wp_scripts->print_inline_script( $script->handle, 'before', false ),
		'after'        => $wp_scripts->print_inline_script( $script->handle, 'after', false ),
		'translations' => $wp_scripts->print_translations( $script->handle, false ),
	);
}