filter_default_option( mixed $default_value, string $option, bool $passed_default ): mixed

Filters the default value for the option.

Description

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

Parameters

$default_valuemixedrequired
Existing default value to return.
$optionstringrequired
Option name.
$passed_defaultboolrequired
Was get_option() passed a default value?

Return

mixed Filtered default value.

Source

function filter_default_option( $default_value, $option, $passed_default ) {
	if ( $passed_default ) {
		return $default_value;
	}

	$registered = get_registered_settings();
	if ( empty( $registered[ $option ] ) ) {
		return $default_value;
	}

	return $registered[ $option ]['default'];
}

Changelog

VersionDescription
4.7.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.