wp_prime_option_caches_by_group()
Loads all options registered in the specified group through register_setting() into the cache.
The function checks which options are already cached and loads the missing ones with one database query. It does not return option values.
Uses: wp_prime_option_caches()
No Hooks.
Returns
null.
void- returns nothing.
Usage
wp_prime_option_caches_by_group( $option_group );
- $option_group(string) (required)
- Name of the group from the first parameter of register_setting(). The group must be registered before this function is called. If it is not registered, the function does nothing.
Examples
#1 Loading options from the settings page into cache
We register the options of the group, and then load them into cache only when the plugin settings page is opened.
add_action( 'admin_init', 'myplugin_register_settings' );
add_action( 'load-settings_page_myplugin', 'myplugin_prime_settings_cache' );
function myplugin_register_settings() {
register_setting( 'myplugin_settings', 'myplugin_api_url' );
register_setting( 'myplugin_settings', 'myplugin_api_key' );
}
function myplugin_prime_settings_cache() {
wp_prime_option_caches_by_group( 'myplugin_settings' );
}Notes
Global. Array. $new_allowed_options |
Changelog
| Since 6.4.0 | Introduced. |
wp_prime_option_caches_by_group() wp prime option caches by group code WP 7.1
function wp_prime_option_caches_by_group( $option_group ) {
global $new_allowed_options;
if ( isset( $new_allowed_options[ $option_group ] ) ) {
wp_prime_option_caches( $new_allowed_options[ $option_group ] );
}
}