wp_determine_option_autoload_value( string $option, mixed $value, mixed $serialized_value, bool|null $autoload ): string
- Since
- 6.6.0
- Source
wp-includes/option.php:1306
Description
This function checks the provided autoload value and returns a standardized value ('on', 'off', 'auto-on', 'auto-off', or 'auto') based on specific conditions.
If no explicit autoload value is provided, the function will check for certain heuristics around the given option.
It will return auto-on to indicate autoloading, auto-off to indicate not autoloading, or auto if no clear decision could be made.
Compatibility
- WordPress
- since 6.6.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$optionstring- The name of the option.
$valuemixed- The value of the option to check its autoload value.
$serialized_valuemixed- The serialized value of the option to check its autoload value.
$autoloadbool|null- The autoload value to check.
Accepts 'on'|true to enable or 'off'|false to disable, or 'auto-on', 'auto-off', or 'auto' for internal purposes.
Any other autoload value will be forced to either 'auto-on', 'auto-off', or 'auto'.
'yes' and 'no' are supported for backward compatibility.
Return value
string- Returns the original $autoload value if explicit, or 'auto-on', 'auto-off', or 'auto' depending on default heuristics.
Performance profile
How much work a call to wp_determine_option_autoload_value() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 8–28
- Plugin surface
- 1 hook
- Called by
- 2
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 35.
Third-party callbacks on 'wp_default_autoload_value' run inside this call, and their cost is not bounded by anything here.
2 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
What one call costs · 2 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_determine_option_autoload_value() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 8–16 | none |
!is_bool($autoload) | 18–28 | apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 35 | 8–28 | 9 | |
| 8.5 | 35 | 8–28 | 9 | |
| 8.4 | 35 | 8–28 | 9 | |
| 8.3 | 35 | 8–28 | 9 | |
| 8.2 | 35 | 8–28 | 9 | 1 more instruction than PHP 8.1 |
| 8.1 | 34 | 8–27 | 9 | |
| 7.4 | 34 | 8–27 | 9 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 1
One hook fires while wp_determine_option_autoload_value() runs, in this order:
- apply_filters( wp_default_autoload_value )filterline 1333 (+27 into the body)
Allows to determine the default autoload value for an option where no explicit value is passed.
Uses · 1
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 2
- add_option()Adds a new option.
- update_option()Updates the value of an option that was already added.
Source code
function wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload ) { // Check if autoload is a boolean. if ( is_bool( $autoload ) ) { return $autoload ? 'on' : 'off'; } switch ( $autoload ) { case 'on': case 'yes': return 'on'; case 'off': case 'no': return 'off'; } /** * Allows to determine the default autoload value for an option where no explicit value is passed. * * @since 6.6.0 * * @param bool|null $autoload The default autoload value to set. Returning true will be set as 'auto-on' in the * database, false will be set as 'auto-off', and null will be set as 'auto'. * @param string $option The passed option name. * @param mixed $value The passed option value to be saved. * @param mixed $serialized_value The passed option value to be saved, in serialized form. */ $autoload = apply_filters( 'wp_default_autoload_value', null, $option, $value, $serialized_value ); if ( is_bool( $autoload ) ) { return $autoload ? 'auto-on' : 'auto-off'; } return 'auto';}Changelog
Introduced in 6.6.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/option.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.