[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> option.php (summary)

Option API

File Size: 2341 lines (71 kb)
Included or required: 1 time
Referenced: 0 times
Includes or requires: 0 files

Defines 35 functions

  get_option()
  wp_protect_special_option()
  form_option()
  wp_load_alloptions()
  wp_load_core_site_options()
  update_option()
  add_option()
  delete_option()
  delete_transient()
  get_transient()
  set_transient()
  delete_expired_transients()
  wp_user_settings()
  get_user_setting()
  set_user_setting()
  delete_user_setting()
  get_all_user_settings()
  wp_set_all_user_settings()
  delete_all_user_settings()
  get_site_option()
  add_site_option()
  delete_site_option()
  update_site_option()
  get_network_option()
  add_network_option()
  delete_network_option()
  update_network_option()
  delete_site_transient()
  get_site_transient()
  set_site_transient()
  register_initial_settings()
  register_setting()
  unregister_setting()
  get_registered_settings()
  filter_default_option()

Functions
Functions that are not part of a class:

get_option( $option, $default = false )   X-Ref
Retrieves an option value based on an option name.

If the option does not exist or does not have a value, then the return value
will be false. This is useful to check whether you need to install an option
and is commonly used during installation of plugin options and to test
whether upgrading is required.

If the option was serialized then it will be unserialized when it is returned.

Any scalar values will be returned as strings. You may coerce the return type of
a given option by registering an {@see 'option_$option'} filter callback.

param: string $option  Name of option to retrieve. Expected to not be SQL-escaped.
param: mixed  $default Optional. Default value to return if the option does not exist.
return: mixed Value set for the option.
since: 1.5.0

wp_protect_special_option( $option )   X-Ref
Protects WordPress special option from being modified.

Will die if $option is in protected list. Protected options are 'alloptions'
and 'notoptions' options.

param: string $option Option name.
since: 2.2.0

form_option( $option )   X-Ref
Prints option value after sanitizing for forms.

param: string $option Option name.
since: 1.5.0

wp_load_alloptions( $force_cache = false )   X-Ref
Loads and caches all autoloaded options, if available or all options.

param: bool $force_cache Optional. Whether to force an update of the local cache
return: array List of all options.
since: 2.2.0
since: 5.3.1 The `$force_cache` parameter was added.

wp_load_core_site_options( $network_id = null )   X-Ref
Loads and caches certain often requested site options if is_multisite() and a persistent cache is not being used.

param: int $network_id Optional site ID for which to query the options. Defaults to the current site.
since: 3.0.0

update_option( $option, $value, $autoload = null )   X-Ref
Updates the value of an option that was already added.

You do not need to serialize values. If the value needs to be serialized,
then it will be serialized before it is inserted into the database.
Remember, resources cannot be serialized or added as an option.

If the option does not exist, it will be created.
This function is designed to work with or without a logged-in user. In terms of security,
plugin developers should check the current user's capabilities before updating any options.

param: string      $option   Option name. Expected to not be SQL-escaped.
param: mixed       $value    Option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
param: string|bool $autoload Optional. Whether to load the option when WordPress starts up. For existing options,
return: bool False if value was not updated and true if value was updated.
since: 1.0.0
since: 4.2.0 The `$autoload` parameter was added.

add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' )   X-Ref
Adds a new option.

You do not need to serialize values. If the value needs to be serialized,
then it will be serialized before it is inserted into the database.
Remember, resources cannot be serialized or added as an option.

You can create options without values and then update the values later.
Existing options will not be updated and checks are performed to ensure that you
aren't adding a protected WordPress option. Care should be taken to not name
options the same as the ones which are protected.

param: string         $option      Name of option to add. Expected to not be SQL-escaped.
param: mixed          $value       Optional. Option value. Must be serializable if non-scalar.
param: string         $deprecated  Optional. Description. Not used anymore.
param: string|bool    $autoload    Optional. Whether to load the option when WordPress starts up.
return: bool False if option was not added and true if option was added.
since: 1.0.0

delete_option( $option )   X-Ref
Removes option by name. Prevents removal of protected WordPress options.

param: string $option Name of option to remove. Expected to not be SQL-escaped.
return: bool True, if option is successfully deleted. False on failure.
since: 1.2.0

delete_transient( $transient )   X-Ref
Deletes a transient.

param: string $transient Transient name. Expected to not be SQL-escaped.
return: bool true if successful, false otherwise
since: 2.8.0

get_transient( $transient )   X-Ref
Retrieves the value of a transient.

If the transient does not exist, does not have a value, or has expired,
then the return value will be false.

param: string $transient Transient name. Expected to not be SQL-escaped.
return: mixed Value of transient.
since: 2.8.0

set_transient( $transient, $value, $expiration = 0 )   X-Ref
Sets/updates the value of a transient.

You do not need to serialize values. If the value needs to be serialized,
then it will be serialized before it is set.

param: string $transient  Transient name. Expected to not be SQL-escaped.
param: mixed  $value      Transient value. Must be serializable if non-scalar.
param: int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
return: bool False if value was not set and true if value was set.
since: 2.8.0

delete_expired_transients( $force_db = false )   X-Ref
Deletes all expired transients.

The multi-table delete syntax is used to delete the transient record
from table a, and the corresponding transient_timeout record from table b.

param: bool $force_db Optional. Force cleanup to run against the database even when an external object cache is used.
since: 4.9.0

wp_user_settings()   X-Ref
Saves and restores user interface settings stored in a cookie.

Checks if the current user-settings cookie is updated and stores it. When no
cookie exists (different browser used), adds the last saved cookie restoring
the settings.

since: 2.7.0

get_user_setting( $name, $default = false )   X-Ref
Retrieves user interface setting value based on setting name.

param: string $name    The name of the setting.
param: string $default Optional default value to return when $name is not set.
return: mixed the last saved user setting or the default value/false if it doesn't exist.
since: 2.7.0

set_user_setting( $name, $value )   X-Ref
Adds or updates user interface setting.

Both $name and $value can contain only ASCII letters, numbers, hyphens, and underscores.

This function has to be used before any output has started as it calls setcookie().

param: string $name  The name of the setting.
param: string $value The value for the setting.
return: bool|null True if set successfully, false if not. Null if the current user can't be established.
since: 2.8.0

delete_user_setting( $names )   X-Ref
Deletes user interface settings.

Deleting settings would reset them to the defaults.

This function has to be used before any output has started as it calls setcookie().

param: string $names The name or array of names of the setting to be deleted.
return: bool|null True if deleted successfully, false if not. Null if the current user can't be established.
since: 2.7.0

get_all_user_settings()   X-Ref
Retrieves all user interface settings.

return: array the last saved user settings or empty array.
since: 2.7.0

wp_set_all_user_settings( $user_settings )   X-Ref
Private. Sets all user interface settings.

param: array $user_settings User settings.
return: bool|null False if the current user can't be found, null if the current
since: 2.8.0

delete_all_user_settings()   X-Ref
Deletes the user settings of the current user.

since: 2.7.0

get_site_option( $option, $default = false, $deprecated = true )   X-Ref
Retrieve an option value for the current network based on name of option.

param: string $option     Name of option to retrieve. Expected to not be SQL-escaped.
param: mixed  $default    Optional value to return if option doesn't exist. Default false.
param: bool   $deprecated Whether to use cache. Multisite only. Always set to true.
return: mixed Value set for the option.
since: 2.8.0
since: 4.4.0 The `$use_cache` parameter was deprecated.
since: 4.4.0 Modified into wrapper for get_network_option()

add_site_option( $option, $value )   X-Ref
Adds a new option for the current network.

Existing options will not be updated. Note that prior to 3.3 this wasn't the case.

param: string $option Name of option to add. Expected to not be SQL-escaped.
param: mixed  $value  Option value, can be anything. Expected to not be SQL-escaped.
return: bool False if the option was not added. True if the option was added.
since: 2.8.0
since: 4.4.0 Modified into wrapper for add_network_option()

delete_site_option( $option )   X-Ref
Removes a option by name for the current network.

param: string $option Name of option to remove. Expected to not be SQL-escaped.
return: bool True, if succeed. False, if failure.
since: 2.8.0
since: 4.4.0 Modified into wrapper for delete_network_option()

update_site_option( $option, $value )   X-Ref
Updates the value of an option that was already added for the current network.

param: string $option Name of option. Expected to not be SQL-escaped.
param: mixed  $value  Option value. Expected to not be SQL-escaped.
return: bool False if value was not updated. True if value was updated.
since: 2.8.0
since: 4.4.0 Modified into wrapper for update_network_option()

get_network_option( $network_id, $option, $default = false )   X-Ref
Retrieves a network's option value based on the option name.

param: int      $network_id ID of the network. Can be null to default to the current network ID.
param: string   $option     Name of option to retrieve. Expected to not be SQL-escaped.
param: mixed    $default    Optional. Value to return if the option doesn't exist. Default false.
return: mixed Value set for the option.
since: 4.4.0

add_network_option( $network_id, $option, $value )   X-Ref
Adds a new network option.

Existing options will not be updated.

param: int    $network_id ID of the network. Can be null to default to the current network ID.
param: string $option     Name of option to add. Expected to not be SQL-escaped.
param: mixed  $value      Option value, can be anything. Expected to not be SQL-escaped.
return: bool False if option was not added and true if option was added.
since: 4.4.0

delete_network_option( $network_id, $option )   X-Ref
Removes a network option by name.

param: int    $network_id ID of the network. Can be null to default to the current network ID.
param: string $option     Name of option to remove. Expected to not be SQL-escaped.
return: bool True, if succeed. False, if failure.
since: 4.4.0

update_network_option( $network_id, $option, $value )   X-Ref
Updates the value of a network option that was already added.

param: int      $network_id ID of the network. Can be null to default to the current network ID.
param: string   $option     Name of option. Expected to not be SQL-escaped.
param: mixed    $value      Option value. Expected to not be SQL-escaped.
return: bool False if value was not updated and true if value was updated.
since: 4.4.0

delete_site_transient( $transient )   X-Ref
Deletes a site transient.

param: string $transient Transient name. Expected to not be SQL-escaped.
return: bool True if successful, false otherwise
since: 2.9.0

get_site_transient( $transient )   X-Ref
Retrieves the value of a site transient.

If the transient does not exist, does not have a value, or has expired,
then the return value will be false.

param: string $transient Transient name. Expected to not be SQL-escaped.
return: mixed Value of transient.
since: 2.9.0

set_site_transient( $transient, $value, $expiration = 0 )   X-Ref
Sets/updates the value of a site transient.

You do not need to serialize values. If the value needs to be serialized,
then it will be serialized before it is set.

param: string $transient  Transient name. Expected to not be SQL-escaped. Must be
param: mixed  $value      Transient value. Expected to not be SQL-escaped.
param: int    $expiration Optional. Time until expiration in seconds. Default 0 (no expiration).
return: bool False if value was not set and true if value was set.
since: 2.9.0

register_initial_settings()   X-Ref
Registers default settings available in WordPress.

The settings registered here are primarily useful for the REST API, so this
does not encompass all settings available in WordPress.

since: 4.7.0

register_setting( $option_group, $option_name, $args = array()   X-Ref
Registers a setting and its data.

param: string $option_group A settings group name. Should correspond to an allowed option key name.
param: string $option_name The name of an option to sanitize and save.
param: array  $args {
since: 2.7.0
since: 4.7.0 `$args` can be passed to set flags on the setting, similar to `register_meta()`.

unregister_setting( $option_group, $option_name, $deprecated = '' )   X-Ref
Unregisters a setting.

param: string   $option_group      The settings group name used during registration.
param: string   $option_name       The name of the option to unregister.
param: callable $deprecated        Deprecated.
since: 2.7.0
since: 4.7.0 `$sanitize_callback` was deprecated. The callback from `register_setting()` is now used instead.

get_registered_settings()   X-Ref
Retrieves an array of registered settings.

return: array List of registered settings, keyed by option name.
since: 4.7.0

filter_default_option( $default, $option, $passed_default )   X-Ref
Filters the default value for the option.

For settings which register a default setting in `register_setting()`, this
function is added as a filter to `default_option_{$option}`.

param: mixed $default Existing default value to return.
param: string $option Option name.
param: bool $passed_default Was `get_option()` passed a default value?
return: mixed Filtered default value.
since: 4.7.0



Generated: Fri Jul 3 01:00:03 2020 Cross-referenced by PHPXref 0.7.1