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:

This article was written as a supplement to the article “Storing data in wordpress“.


Купить хостинг WordPress
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Let's consider the mechanisms of working with options

Having considered a simple example of working with options, we will consider other options processing and output functions:

add_option($name, $value, $deprecated, $auto load) – adds a new option and does nothing, if the option already exists.

$name – Required parameter (term type). The name of the setting.
$value – Optional parameter (term type), the default is an empty string. The value of the option.
$deprecated – Optional parameter (term type) WordPress is no longer used. An empty string or null can be passed, to use the $autoload option.
$auto load – Optional, Default – "So" (enum: yes or no). If set to yes, settings are automatically removed by the get_alloptions function (loads on all pages even if the option is not called, may slow down the site, if a lot of data is stored in such an option).

get_option(‘my_option_first’) – displays the contents of the option by name.

update_option($option_name, $newvalue) – updates or creates a setting value in the database (add_option may not be called, if you don't need the $autoload parameter).

  • $option_name – Required parameter (string data type). Name of the installation to update.
  • $newvalue – Required parameter. New option value.

delete_option( ‘option_name’ ) – a safe way to remove a named option/value pair from a table options in the database.

  • $option_name – Required parameter (string data type). The name of the installation to remove.

Example of use:

This article was written as an appendix to the article “Data storage in WordPress“.


Купить хостинг WordPress
WordPress tutor
Online tutoring services. List of courses I teach
  • Basic web design course;
  • Site layout;
  • General course on CMS WordPress and continuation of the course on template development;
  • Website development in PHP.
Read more on the page WordPress tutor
*/

Nikolaenko Maxim

Director of web studies ProGrafika. I am developing, website design and promotion. Always glad to new blog readers and good clients.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Templates for WordPress
The best hosting in Ukraine
Stable hosting for Drupal