Created
July 24, 2014 14:11
-
-
Save westonruter/353a8d3871b7281df857 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Safely update an option which may not exist yet, doing add_option() with | |
* autoload=no if it doesn't. Prevent proliferation of autoloaded options. | |
* | |
* Note we check to see if the option exists so we get a chance to | |
* call add_option with the autoload argument. This is an ugly | |
* aspect of WordPress. This is a performance consideration, to | |
* prevent WordPress from needlessly querying these options with | |
* every request. | |
* See http://codex.wordpress.org/Function_Reference/update_option | |
* | |
* @param $option_name | |
* @param $option_value | |
* | |
* @return bool | |
*/ | |
function update_option_no_autoload( $option_name, $option_value ) { | |
$autoload = 'no'; | |
$not_exists = new stdClass(); | |
$existing_option = get_option( $option_name, $not_exists ); | |
if ( $existing_option === $not_exists ) { | |
return add_option( $option_name, $option_value, null, $autoload ); | |
} else { | |
return update_option( $option_name, $option_value ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment