Skip to content

Commit

Permalink
Options, Meta APIs: Expand $autoload parameter documentation.
Browse files Browse the repository at this point in the history
This changeset expands documentation of the `$autoload` parameter of the `add_option()` and `update_option()` functions, in order to provide more context on what autoloading is and which considerations should go into the decision whether to autoload an option.

Excessive autoloading of options can lead to severe performance problems on some sites, and lack of documentation is a partial cause for the issue.

Props rajinsharwar.
Fixes #58963.


git-svn-id: https://develop.svn.wordpress.org/trunk@56370 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
felixarntz committed Aug 7, 2023
1 parent 4ff71a6 commit 79a36de
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/wp-includes/option.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,13 @@ function wp_load_core_site_options( $network_id = null ) {
* @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,
* `$autoload` can only be updated using `update_option()` if `$value` is also changed.
* Accepts 'yes'|true to enable or 'no'|false to disable. For non-existent options,
* the default value is 'yes'. Default null.
* Accepts 'yes'|true to enable or 'no'|false to disable.
* Autoloading too many options can lead to performance problems, especially if the
* options are not frequently used. For options which are accessed across several places
* in the frontend, it is recommended to autoload them, by using 'yes'|true.
* For options which are accessed only on few specific URLs, it is recommended
* to not autoload them, by using 'no'|false. For non-existent options, the default value
* is 'yes'. Default null.
* @return bool True if the value was updated, false otherwise.
*/
function update_option( $option, $value, $autoload = null ) {
Expand Down Expand Up @@ -615,7 +620,12 @@ function update_option( $option, $value, $autoload = null ) {
* Expected to not be SQL-escaped.
* @param string $deprecated Optional. Description. Not used anymore.
* @param string|bool $autoload Optional. Whether to load the option when WordPress starts up.
* Default is enabled. Accepts 'no' to disable for legacy reasons.
* Accepts 'yes'|true to enable or 'no'|false to disable.
* Autoloading too many options can lead to performance problems, especially if the
* options are not frequently used. For options which are accessed across several places
* in the frontend, it is recommended to autoload them, by using 'yes'|true.
* For options which are accessed only on few specific URLs, it is recommended
* to not autoload them, by using 'no'|false. Default 'yes'.
* @return bool True if the option was added, false otherwise.
*/
function add_option( $option, $value = '', $deprecated = '', $autoload = 'yes' ) {
Expand Down

0 comments on commit 79a36de

Please sign in to comment.