WP_Script_Modules::print_script_moduleprivateWP 6.9.0

Prints the enqueued script module using script tags with type="module" attributes.

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

Хуков нет.

Возвращает

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

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

// private - только в коде основоного (родительского) класса
$result = $this->print_script_module( $id );
$id(строка) (обязательный)
The script module identifier.

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

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

Код WP_Script_Modules::print_script_module() WP 7.1

private function print_script_module( string $id ) {
	if ( in_array( $id, $this->done, true ) || ! in_array( $id, $this->queue, true ) ) {
		return;
	}

	$this->done[] = $id;

	$src = $this->get_src( $id );
	if ( '' === $src ) {
		return;
	}

	$attributes = array(
		'type' => 'module',
		'src'  => $src,
		'id'   => $id . '-js-module',
	);

	$script_module     = $this->registered[ $id ];
	$queued_dependents = array_intersect( $this->queue, $this->get_recursive_dependents( $id ) );
	$fetchpriority     = $this->get_highest_fetchpriority( array_merge( array( $id ), $queued_dependents ) );
	if ( 'auto' !== $fetchpriority ) {
		$attributes['fetchpriority'] = $fetchpriority;
	}
	if ( $fetchpriority !== $script_module['fetchpriority'] ) {
		$attributes['data-wp-fetchpriority'] = $script_module['fetchpriority'];
	}
	wp_print_script_tag( $attributes );
}