WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

vi:Tham Khảo Các Hàm/add option

Bản Nháp

Trang này được đánh dấu là bản nháp. Bạn có thể giúp đỡ WordPressVN bằng cách hoàn thiện trang này.

Description

A safe way of adding a named option/value pair to the options database table. It does nothing if the option already exists. After the option is saved, it can be accessed with get_option(), changed with update_option(), and deleted with delete_option().

The data is escaped with $wpdb->escape before the INSERT statement.

Usage for wp 2.3.X or newer

In the lasts versions of WordPress (2.3.X) the parameter $description is deprecated and remove the values from the wp_options table. The usage is the same but the second parameter its unused.

See below for older version of this reference

<?php add_option($name, $value = '', $deprecated = '', $autoload = 'yes'); ?>

Example for wp 2.3.X or newer

<?php add_option("myhack_extraction_length", '255', '', 'yes'); ?>

Parameters for wp 2.3.X or newer

$name
(string) (required) Name of the option to be added. Use underscores to separate words, and do not use uppercase—this is going to be placed into the database.
Default: None
$value
(string) (optional) Value for this option name.
Default: Empty
$deprecated
(string) (optional) Unused.
Default: Empty
$autoload
(string) (optional) Should this option be automatically loaded by the function wp_load_alloptions (puts options into object cache on each page load)? Valid values: yes or no.
Default: yes

Usage before $description deprecated

In the last versions of wordpress (2.3.X) the parameter $description is deprecated and remove the values from the wp_options table.
The usage its the same but the seccond parameter its unused.
WP 2.3.X or newer 
<?php add_option($name, $value = '', $deprecated = '', $autoload = 'yes'); ?>


<?php add_option($name, $value = '', $description = '', $autoload = 'yes'); ?>

Example

<?php add_option("myhack_extraction_length", '255', 
'Max length of extracted text in characters.', 'yes'); ?>

Parameters before $description deprecated

$name
(string) (required) Name of the option to be added. Use underscores to separate words, and do not use uppercase—this is going to be placed into the database.
Default: None
$value
(string) (optional) Value for this option name.
Default: Empty
$description
(string) (optional) Descriptive text for the option. The description can be used in backend labels.
Default: Empty
$autoload
(string) (optional) Should this option be automatically loaded? Valid values: yes or no.
Default: yes
This article is marked as in need of editing. You can help Codex by editing it.