Skip to content

Instantly share code, notes, and snippets.

@pcfreak30
Forked from lukecav/functions.php
Last active December 13, 2018 01:02
Show Gist options
  • Save pcfreak30/ca01b9a0b89790a57a13526568191e75 to your computer and use it in GitHub Desktop.
Save pcfreak30/ca01b9a0b89790a57a13526568191e75 to your computer and use it in GitHub Desktop.
Fix a race condition in alloptions caching in WordPress
<?php
/**
* Fix a race condition in alloptions caching
*
* See https://core.trac.wordpress.org/ticket/31245
*/
function _wpcom_vip_maybe_clear_alloptions_cache( $option ) {
if ( ! wp_installing() ) {
$alloptions = wp_load_alloptions(); //alloptions should be cached at this point
if ( isset( $alloptions[ $option ] ) ) { //only if option is among alloptions
wp_cache_delete( 'alloptions', 'options' );
}
}
}
add_action( 'added_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
add_action( 'updated_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
add_action( 'deleted_option', '_wpcom_vip_maybe_clear_alloptions_cache' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment