wp_prime_site_option_caches() │ WP 6.6.0

Loads the specified network options for the current network into the object cache with one database query.

Only options that are not already cached are loaded.

This means subsequent calls to get_site_option() do not run a separate database query.

Options that do not exist in the database are recorded separately so subsequent calls do not create unnecessary queries.

If Multisite is disabled, the function passes the list to wp_prime_option_caches() and caches regular site options.

Use wp_prime_network_option_caches() when you need to specify the ID of the network whose options should be loaded.

No Hooks.

Returns

null.

  • void - does not return a value.

Usage

wp_prime_site_option_caches( $options );
$options(string[]) (required)
An array of option names to load into the cache.

Examples

#1 Prime several network options

The options are loaded with one query. Subsequent calls to get_site_option() retrieve them from the cache.

$options = [
	'my_plugin_api_url',
	'my_plugin_api_key',
	'my_plugin_enabled',
];

wp_prime_site_option_caches( $options );

$api_url = get_site_option( 'my_plugin_api_url' );
$api_key = get_site_option( 'my_plugin_api_key' );
$enabled = get_site_option( 'my_plugin_enabled' );

Notes

See: wp_prime_network_option_caches()

Changelog

Since 6.6.0 Introduced.

wp_prime_site_option_caches() code WP 7.1.2

function wp_prime_site_option_caches( array $options ) {
	wp_prime_network_option_caches( null, $options );
}