Wordpress Plugin Upgrade Hook Function Wordpress Plugin Upgrade Hook Function wordpress wordpress

Wordpress Plugin Upgrade Hook Function


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.