wp_prime_network_option_caches()
Primes the specified network options into the object cache with one database query.
Only options that are not already cached are loaded.
Options that do not exist in the database are recorded separately so subsequent requests do not create unnecessary queries either.
If Multisite is disabled, the function passes the list to wp_prime_option_caches() and caches regular site options.
Use wp_prime_site_option_caches() when you need to load options for the current network.
Used By: wp_prime_site_option_caches()
No Hooks.
Returns
null.
void- does not return a value.
Usage
wp_prime_network_option_caches( $network_id, $options );
- $network_id(int|null) (required)
- Network ID.
Whennull, the current network ID is used. - $options(string[]) (required)
- An array of option names to load into the cache.
Examples
#1 Prime options for a specified network
After priming, calls to get_network_option() retrieve the values from the cache.
$network_id = 2; $options = [ 'my_plugin_api_url', 'my_plugin_api_key', 'my_plugin_enabled', ]; wp_prime_network_option_caches( $network_id, $options ); $api_url = get_network_option( $network_id, 'my_plugin_api_url' ); $api_key = get_network_option( $network_id, 'my_plugin_api_key' ); $enabled = get_network_option( $network_id, 'my_plugin_enabled' );
Notes
Global. wpdb. $wpdb WordPress database abstraction object. |
Changelog
| Since 6.6.0 | Introduced. |