wp_determine_option_autoload_value()
Determines the appropriate autoload value for an option based on input.
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.
@since 6.6.0 @access private
@param string $option The name of the option. @param mixed $value The value of the option to check its autoload value. @param mixed $serialized_value The serialized value of the option to check its autoload value. @param bool|null $autoload 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 string Returns the original $autoload value if explicit, or 'auto-on', 'auto-off', or 'auto' depending on default heuristics.
Hooks from the function
Returns
null. Nothing (null).
Usage
wp_determine_option_autoload_value( $option, $value, $serialized_value, $autoload );
- $option(required)
- .
- $value(required)
- .
- $serialized_value(required)
- .
- $autoload(required)
- .
wp_determine_option_autoload_value() wp determine option autoload value code WP 7.0
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';
}