How to tell if an option has been created vs an empty option?

Options that don’t exist get the fact of their non-existence cached in memory when you attempt to get them. So you can check that cache to determine the difference.

$value = get_option('example');
$notoptions = wp_cache_get( 'notoptions', 'options' );
if ( isset( $notoptions['example'] ) ) {
    // option does not exist
} else {
    // option exists, $value is legit
}

Leave a Comment