Options API (settings) (tag)
Options API is a basic way to store or retrieve data from the DB. The API makes it easier to create/read/update/delete parameters. All data is stored in the wp_options table with the specified option name.
Note that functions whose name contains _site_ or _network_ do the same thing as their versions without that word. However, if Multisite mode is enabled, options are stored in the wp_sitemeta table and are used for the network of sites.
Options structure in Multisite mode
When installing Multisite, the options structure of sites is expanded.
In WordPress, there are four similar functions:
get_network_option()get_site_option()get_blog_option()get_option()
These functions can be grouped:
get_network_option() = get_site_option()
get_blog_option() = get_option()
Read more in the section: Site and blog structure.
Example
// Create a parameter in the database add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ); // Delete a parameter by name delete_option( $option ); // Get the saved parameter get_option( $option, $default = false ); // Update the value of an already added parameter update_option( $option, $newvalue );
| add_network_option() | Adds a network setting. Used in a multisite setup. |
| add_option() | Adds a new option. Does nothing if this option already exists. |
| delete_option() | Deletes settings (post from the wp_options table in the DB). |
| get_network_option() | Gets the value of the specified network option (the main site in a multisite network). |
| get_option() | Gets the value of the specified setting (option). |
| get_site_option() | Gets the specified option of the main site of the current network. |
| register_setting() | Registers a new option and a callback function to handle the option value when it is saved to the database. |
| update_option() | Updates the value of an option (setting) in the database. Expects an unescaped string. |
| update_site_option() | Updates or adds the specified option for the current site (current blog network). For multisite networks. |