WP_Script_Modules::set_fetchprioritypublicWP 6.9.0

Sets the fetch priority for a script module.

Method of the class: WP_Script_Modules{}

No Hooks.

Returns

true|false. Whether setting the fetchpriority was successful.

Usage

$WP_Script_Modules = new WP_Script_Modules();
$WP_Script_Modules->set_fetchpriority( $id, $priority ): bool;
$id(string) (required)
Script module identifier.
$priority('auto'|'low'|'high') (required)
Fetch priority for the script module.

Changelog

Since 6.9.0 Introduced.

WP_Script_Modules::set_fetchpriority() code WP 6.9.1

public function set_fetchpriority( string $id, string $priority ): bool {
	if ( ! isset( $this->registered[ $id ] ) ) {
		return false;
	}

	if ( '' === $priority ) {
		$priority = 'auto';
	}

	if ( ! $this->is_valid_fetchpriority( $priority ) ) {
		_doing_it_wrong(
			__METHOD__,
			/* translators: %s: Invalid fetchpriority. */
			sprintf( __( 'Invalid fetchpriority: %s' ), $priority ),
			'6.9.0'
		);
		return false;
	}

	$this->registered[ $id ]['fetchpriority'] = $priority;
	return true;
}