Wordpress - Add Option if Not Exists

I highly disrecommend to use if (!(get_option("XXXX")) approach to check for existence, as it fails with false/null/0/empty legitimate value.

I suggest:

if (!option_exists("XXXX"){
     add_option("XXXX", "valueee");
}

code:

public function option_exists($name, $site_wide=false){
    global $wpdb; return $wpdb->query("SELECT * FROM ". ($site_wide ? $wpdb->base_prefix : $wpdb->prefix). "options WHERE option_name ='$name' LIMIT 1");
}

(I had also submitted this feature as CORE request)

Tags:

Options

Codex