Wordpress Upgrade Plugin Capture Feature

I am developing a new version of the plugin us wordpress ( http://wordpress.org/extend/plugins/facebook-send-like-button/ ).

New parameters ( add_option() ) supplied with the new version. But I can not automatically register new parameters.

For example, the new version has the fgb_single option. Where should I put the code add_option('fgb_single', 'on'); to my plugin file?

+6
source share
1 answer

The API uses the global $wpdb , make sure you have this declaration before using any function like add_option or get_option .
Also, according to the WordPress Codex, you will not see any changes when using add_option($option, $value, $deprecated, $autoload) if you already have a value for this option:

Note: add_option uses get_option, to determine whether this option is selected, and as get_option returns false as a default, if you set to false in the database (for example, through update_option($option_name, false)) ), then calls add_option will change the value since add_option will look like the option does not exist.

You can use the API API anywhere in your plugin as a log when loading $wpdb .

I would also recommend using update_option instead of add_option , since it can create new parameters, but will not return false, if the option already exists, it will simply overwrite it.

+7
source

Source: https://habr.com/ru/post/887402/


All Articles