wp_get_speculation_rules_default_configuration(): array<string,

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Returns the default speculation rules configuration that the value ‘auto’ resolves to.

Description

WordPress Core defaults to a mode of ‘prefetch’ and an eagerness of ‘conservative’. Hosting providers can override either default by way of the WP_SPECULATIVE_LOADING_DEFAULT_MODE and WP_SPECULATIVE_LOADING_DEFAULT_EAGERNESS constants or environment variables. This only changes what the ‘auto’ value resolves to, so a plugin which supplies an explicit mode or eagerness via the ‘wp_speculation_rules_configuration’ filter continues to take precedence.

Note that an eagerness of ‘immediate’ is not permitted as a default, since WordPress does not allow it for the document-level rules that it generates.

Return

array<string, string> Associative array with 'mode' and 'eagerness' keys.

Source

function wp_get_speculation_rules_default_configuration(): array {
	$default_mode = 'prefetch';
	$mode         = wp_get_speculative_loading_override( 'WP_SPECULATIVE_LOADING_DEFAULT_MODE' );
	if ( WP_Speculation_Rules::is_valid_mode( $mode ) ) {
		$default_mode = $mode;
	}

	$default_eagerness = 'conservative';
	$eagerness         = wp_get_speculative_loading_override( 'WP_SPECULATIVE_LOADING_DEFAULT_EAGERNESS' );
	if (
		WP_Speculation_Rules::is_valid_eagerness( $eagerness ) &&
		// 'immediate' is a valid eagerness, but for safety WordPress does not allow it for document-level rules.
		'immediate' !== $eagerness
	) {
		$default_eagerness = $eagerness;
	}

	return array(
		'mode'      => $default_mode,
		'eagerness' => $default_eagerness,
	);
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.