Consider the mechanisms of working with options
Having considered a simple example of working with options, let's consider the remaining functions for processing and outputting options.:
add_option($name, $value, $deprecated, $auto load) – adds a new option and does nothing if the option already exists.
$name – Required parameter (string type). Setting name.
$value – Optional parameter (string type), default is an empty string. Meaning options.
$deprecated – Optional parameter (string type), no longer used by wordpress. You can pass an empty string or null, to use the following parameter $autoload.
$auto load – Optional, default is "yes" (enum: "Yes or no"). If set to "yes", settings are automatically retrieved by the function get_alloptions (loaded on all pages even if the option was not called, can slow down the site if there is a lot of data stored in this option).
get_option(‘my_option_first’) – displays the contents of the option by its name.
update_option($option_name, $newvalue) – updates or creates a setting value in the database (may not be called add_option, if you don't need a parameter $auto load).
- $option_name – Required parameter (string data type). The name of the setting to update.
- $newvalue – Required parameter. New option value.
delete_option( ‘option_name’ ) – safe way to remove named option/value pair from table options in the database.
- $option_name – Required parameter (string data type). Name of setting to delete.
Usage example:
1 |
<?php delete_option( 'my_option' ); ?> |
This article was written as a supplement to the article “Storing data in wordpress“.
/*
- Basic web design course;
- Site layout;
- General course on CMS WordPress and continuation of the course on template development;
- Website development in PHP.