开发者

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 since get_option returns false as the default value, if you set an option to false in the database (e.g. via update_option($option_name, false)), then a subsequent call to add_option will change the value, because it will seem to add_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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜