I think that you have added bguru_options
option before. If bguru_options
already exists, add_option()
does nothing. To modify the value of existing options you should use update_option()
instead.
EDIT
I confirm what I thought. You are running add_option('bguru_options', $default_options);
in every admin_init
. bguru_options
option was added to database in the first run and subsequent calls to add_option('bguru_options', $default_options);
are doing nothing.
- Use
update_option()
to change the value of a existent option. If the option doesn’t exist, it will be created. - Use
add_option()
if you really need it. For example, if you need to setautoload=no
. This parameter is not accepted byupdate_option()
. Do this preferably during plugin/theme activation - If you need to use
add_option()
and you are not sure if the option already exists, usedelete_option()
before calladd_option()
.
EDIT 2
I’ve tested your code exactly as it is and I’ve tested it. The default logo URL is correctly added to database in the bguru_options
option and returned by get_option('bguru_options');
:
$options=get_option('bguru_options');
var_dump($options['bguru_logo']);
There is no problem at all. The only drawback is that if the you leave the URL field empty, the default logo URL is not set because, I repeat, add_option()
is doing nothing in subsequent calls because bguru_options
option already exists.
I’ve tested the code and it works. If it does not work for you I will need more information. Maybe some debug log?
Anyway, I wnat to show you how get_option()
support default values without the need of store default values in the database:
$default_options=array(
'bguru_logo'=>'http://templategraphy.com/demo/businessguru/images/logo.png',
'bguru_vimeo'=>'',
'bguru_skype'=>'',
'bguru_dribbble'=>'',
'bguru_slide_one_image'=>'',
'bguru_slide_one_heading'=>'',
'bguru_slide_one_text'=>''
);
$bguru_options = get_option('bguru_options', $bguru_options_defaults);
//Set defaults for unsaved subset in the array
$bguru_options = wp_parse_args( $bguru_options, $bguru_options_defaults );