Automattic\WooCommerce\Admin
Loader::output_header_preload_tags_for_type() public WC 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
{} Это метод класса: Loader{}
Хуков нет.
Возвращает
null
. Null. Ничего.
Использование
$result = Loader::output_header_preload_tags_for_type( $type, $allowlist );
- $type(строка) (обязательный)
- Dependency type - 'script' or 'style'.
- $allowlist(массив)
- List of allowed dependency handles.
Код Loader::output_header_preload_tags_for_type() Loader::output header preload tags for type WC 5.2.0
public static function output_header_preload_tags_for_type( $type, $allowlist = array() ) {
if ( 'script' === $type ) {
$dependencies_of_type = wp_scripts();
} elseif ( 'style' === $type ) {
$dependencies_of_type = wp_styles();
} else {
return;
}
foreach ( $dependencies_of_type->queue as $dependency_handle ) {
$dependency = $dependencies_of_type->query( $dependency_handle, 'registered' );
if ( false === $dependency ) {
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 ) {
self::maybe_output_preload_link_tag( $sub_dependency, $type, $allowlist );
}
}
self::maybe_output_preload_link_tag( $dependency, $type, $allowlist );
}
}