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. Ничего (null).

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

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

Код MiniCart::append_script_and_deps_src() WC 9.3.3

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 ) || wp_script_is( $script->handle, 'enqueued' ) ) {
		return;
	}

	if ( is_countable( $script->deps ) && 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();

	if ( Utils::wp_version_compare( '6.3', '>=' ) ) {
		$script_before = $wp_scripts->get_inline_script_data( $script->handle, 'before' );
		$script_after  = $wp_scripts->get_inline_script_data( $script->handle, 'after' );
	} else {
		$script_before = $wp_scripts->print_inline_script( $script->handle, 'before', false );
		$script_after  = $wp_scripts->print_inline_script( $script->handle, 'after', false );
	}

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