Читать книгу Professional WordPress Plugin Development - Brad Williams - Страница 79
Updating Options
ОглавлениеNow that you know how to create a new option for your plugin, let's look at updating that option value. To handle this, you'll use the update_option()
function. As an example, let's update the color of your new plugin setting from red to blue.
<?php update_option( 'pdev_plugin_color', 'blue' ); ?>
The update_option()
function accepts the following parameters:
option: Name of the option to update
value: Value of the option you are updating
autoload: Whether to load the option when WordPress starts
The difference between add_option()
and update_option()
is that the first function does nothing if the option name already exists, whereas update_option()
checks if the option already exists before updating its value and creates it if needed.