The pre_cache_alloptions filter allows you to modify all WordPress options before they are cached, helping you to adjust settings as needed without directly altering the database.
Usage
add_filter('pre_cache_alloptions', 'your_custom_function');
function your_custom_function($alloptions) {
// your custom code here
return $alloptions;
}
Parameters
$alloptions(array): An array containing all WordPress options.
More information
See WordPress Developer Resources: pre_cache_alloptions
Examples
Update Site Title
Update the site title before it is cached.
add_filter('pre_cache_alloptions', 'update_site_title');
function update_site_title($alloptions) {
$alloptions['blogname'] = 'New Site Title';
return $alloptions;
}
Disable Comments
Disable comments site-wide before options are cached.
add_filter('pre_cache_alloptions', 'disable_comments');
function disable_comments($alloptions) {
$alloptions['default_comment_status'] = 'closed';
return $alloptions;
}
Change Admin Email
Change the admin email address before caching options.
add_filter('pre_cache_alloptions', 'change_admin_email');
function change_admin_email($alloptions) {
$alloptions['admin_email'] = '[email protected]';
return $alloptions;
}
Enable Debug Mode
Enable WordPress debug mode by modifying the cached options.
add_filter('pre_cache_alloptions', 'enable_debug_mode');
function enable_debug_mode($alloptions) {
$alloptions['wp_debug'] = true;
return $alloptions;
}
Change Timezone
Change the site’s timezone before caching options.
add_filter('pre_cache_alloptions', 'change_timezone');
function change_timezone($alloptions) {
$alloptions['timezone_string'] = 'America/New_York';
return $alloptions;
}