Eray
Eray

Reputation: 7128

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 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?

Upvotes: 7

Views: 1494

Answers (1)

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.

Upvotes: 7

Related Questions