filter_default_option() WordPress Function

This function allows you to override the default option for a specified filter. This is useful if you want to change the default behavior of a filter for your entire site.

filter_default_option( mixed $default, string $option, bool $passed_default ) #

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}.


Top ↑

Parameters

$default

(mixed)(Required)Existing default value to return.

$option

(string)(Required)Option name.

$passed_default

(bool)(Required)Was get_option() passed a default value?


Top ↑

Return

(mixed) Filtered default value.


Top ↑

Source

File: wp-includes/option.php

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

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

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


Top ↑

Changelog

Changelog
VersionDescription
4.7.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More