Wordpress Plugin Upgrade Hook Function
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 开发者_StackOverflow社区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.
精彩评论