On this page
WP_Customize_Manager::post_value( WP_Customize_Setting $setting, mixed $default_value = null ): string|mixed
Returns the sanitized value for a given setting from the current customized state.
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
Parameters
$settingWP_Customize_Setting Required-
A WP_Customize_Setting derived object.
$default_valuemixed Optional-
Value returned if
$settinghas no post value (added in 4.2.0) or the post value is invalid (added in 4.6.0).Default:
null
Return
string|mixed Sanitized value or the $default_value provided.
Source
File: wp-includes/class-wp-customize-manager.php. View all references
public function post_value( $setting, $default_value = null ) {
$post_values = $this->unsanitized_post_values();
if ( ! array_key_exists( $setting->id, $post_values ) ) {
return $default_value;
}
$value = $post_values[ $setting->id ];
$valid = $setting->validate( $value );
if ( is_wp_error( $valid ) ) {
return $default_value;
}
$value = $setting->sanitize( $value );
if ( is_null( $value ) || is_wp_error( $value ) ) {
return $default_value;
}
return $value;
}
Related
Uses
| Uses | Description |
|---|---|
| WP_Customize_Manager::unsanitized_post_values() wp-includes/class-wp-customize-manager.php | Gets dirty pre-sanitized setting values in the current customized state. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_customize_manager/post_value