I'm developing new version of my wordpress plugin (http://wordpress.org/extend/plugins/facebook-send-like-button/) .
New options (add_option()
) coming with new version. But i can't register this new options automatically.
For example there is fgb_single option in new version.
Where should i put add_option('fgb_single', 'on');
code in my plugin's file?
The Options API is using the global $wpdb
, make sure you have that declared before using any function like add_option or get_option.
Also acording to the WordPress Codex, you will see no changes when you use add_option($option, $value, $deprecated, $autoload)
if you already have a value for that option:
Note:
add_option
uses get_option to determine whether the option already exists, and sinceget_option
returns false as the default value, if you set an option to false in the database (e.g. viaupdate_option($option_name, false))
, then a subsequent call toadd_option
will change the value, because it will seem toadd_option
that the option does not exist.
You can use the Options API anywhere in your plugin as log as you load $wpdb
.
Also I'd recommend using update_option instead of add_option as it is able to create new options but won't return false in case an option already exists, it will simply overwrite it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With