WP_Script_Modules::print_script_moduleprivateWP 6.9.0

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

Method of the class: WP_Script_Modules{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->print_script_module( $id );
$id(string) (required)
The script module identifier.

Changelog

Since 6.9.0 Introduced.

WP_Script_Modules::print_script_module() code WP 6.9

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 ];
	$dependents    = $this->get_recursive_dependents( $id );
	$fetchpriority = $this->get_highest_fetchpriority( array_merge( array( $id ), $dependents ) );
	if ( 'auto' !== $fetchpriority ) {
		$attributes['fetchpriority'] = $fetchpriority;
	}
	if ( $fetchpriority !== $script_module['fetchpriority'] ) {
		$attributes['data-wp-fetchpriority'] = $script_module['fetchpriority'];
	}
	wp_print_script_tag( $attributes );
}