Automattic\WooCommerce\Internal\Admin

WCAdminAssets::output_header_preload_tags_for_type()privateWC 1.0

Output a preload link tag for dependencies (and their sub dependencies) with an optional allowlist.

See: https://macarthur.me/posts/preloading-javascript-in-wordpress

Метод класса: WCAdminAssets{}

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->output_header_preload_tags_for_type( $type, $allowlist );
$type(строка) (обязательный)
Dependency type - 'script' or 'style'.
$allowlist(массив)
List of allowed dependency handles.
По умолчанию: array()

Код WCAdminAssets::output_header_preload_tags_for_type() WC 8.7.0

private function output_header_preload_tags_for_type( $type, $allowlist = array() ) {
	if ( $type === 'script' ) {
		$dependencies_of_type = wp_scripts();
	} elseif ( $type === 'style' ) {
		$dependencies_of_type = wp_styles();
	} else {
		return;
	}

	foreach ( $dependencies_of_type->queue as $dependency_handle ) {
		$dependency = $dependencies_of_type->query( $dependency_handle, 'registered' );

		if ( $dependency === false ) {
			continue;
		}

		// Preload the subdependencies first.
		foreach ( $dependency->deps as $sub_dependency_handle ) {
			$sub_dependency = $dependencies_of_type->query( $sub_dependency_handle, 'registered' );

			if ( $sub_dependency ) {
				$this->maybe_output_preload_link_tag( $sub_dependency, $type, $allowlist );
			}
		}

		$this->maybe_output_preload_link_tag( $dependency, $type, $allowlist );
	}
}