WP_Customize_Manager::post_value( WP_Customize_Setting $setting, mixed $default = null )

Returns the sanitized value for a given setting from the current customized state.


Description Description

The name "post_value" is a carry-over from when the customized state was exclusively sourced from $_POST['customized']. Nevertheless, the value returned will come from the current changeset post and from the incoming post data.

See also See also


Top ↑

Parameters Parameters

$setting

(WP_Customize_Setting) (Required) A WP_Customize_Setting derived object.

$default

(mixed) (Optional) Value returned $setting has no post value (added in 4.2.0) or the post value is invalid (added in 4.6.0).

Default value: null


Top ↑

Return Return

(string|mixed) $post_value Sanitized value or the $default provided.



Top ↑

Source Source

File: wp-includes/class-wp-customize-manager.php

	public function post_value( $setting, $default = null ) {
		$post_values = $this->unsanitized_post_values();
		if ( ! array_key_exists( $setting->id, $post_values ) ) {
			return $default;
		}
		$value = $post_values[ $setting->id ];
		$valid = $setting->validate( $value );
		if ( is_wp_error( $valid ) ) {
			return $default;
		}
		$value = $setting->sanitize( $value );
		if ( is_null( $value ) || is_wp_error( $value ) ) {
			return $default;
		}
		return $value;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
4.6.0 $default is now returned early when the setting post value is invalid.
4.1.1 Introduced the $default parameter.
3.4.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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