WP_Customize_Manager::set_post_value() WordPress Method
The WP_Customize_Manager::set_post_value() method is used to set the value of a specific Customizer setting for a specific post. This method is typically used when a Customizer setting needs to be updated based on a change made to a post via the Wordpress admin interface. This method accepts two parameters: the first is the post ID of the post for which the Customizer setting value should be updated, and the second is the new value for the Customizer setting. For example, suppose you have a Customizer setting named 'my_setting' whose value is 'foo'. If you want to update the value of 'my_setting' to 'bar' for the post with ID '123', you would use the following code: $wp_customize_manager->set_post_value( 'my_setting', '123', 'bar' );
WP_Customize_Manager::set_post_value( string $setting_id, mixed $value ) #
Overrides a setting’s value in the current customized state.
Description
The name "post_value" is a carry-over from when the customized state was exclusively sourced from $_POST['customized']
.
Parameters
- $setting_id
(string)(Required)ID for the WP_Customize_Setting instance.
- $value
(mixed)(Required)Post value.
Source
File: wp-includes/class-wp-customize-manager.php
public function set_post_value( $setting_id, $value ) { $this->unsanitized_post_values(); // Populate _post_values from $_POST['customized']. $this->_post_values[ $setting_id ] = $value; /** * Announces when a specific setting's unsanitized post value has been set. * * Fires when the WP_Customize_Manager::set_post_value() method is called. * * The dynamic portion of the hook name, `$setting_id`, refers to the setting ID. * * @since 4.4.0 * * @param mixed $value Unsanitized setting post value. * @param WP_Customize_Manager $manager WP_Customize_Manager instance. */ do_action( "customize_post_value_set_{$setting_id}", $value, $this ); /** * Announces when any setting's unsanitized post value has been set. * * Fires when the WP_Customize_Manager::set_post_value() method is called. * * This is useful for `WP_Customize_Setting` instances to watch * in order to update a cached previewed value. * * @since 4.4.0 * * @param string $setting_id Setting ID. * @param mixed $value Unsanitized setting post value. * @param WP_Customize_Manager $manager WP_Customize_Manager instance. */ do_action( 'customize_post_value_set', $setting_id, $value, $this ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
4.2.0 | Introduced. |