You can pass defaults to get_option
. The second parameter is a fallback.
$default
(mixed) (optional) The default value to return if no value is returned (ie. the option is not in the database).Default: false
So, for example, instead of:
$options = get_option('plugin_options');
You’d want:
$options = get_option('plugin_options',array('display_sidebar' => true));
Or you can insert your default options with add_option
, which is “A safe way of adding a named option/value pair to the options database table. It does nothing if the option already exists.”
I’d do the latter. It should be easier.