Using WordPress ‘customize_update_{$this->type}’ PHP action

The customize_update_{$this->type} WordPress PHP action fires when the WP_Customize_Setting::update() method is called for settings not handled as theme_mods or options.

Usage

add_action('customize_update_example_type', 'my_custom_function', 10, 2);

function my_custom_function($value, $setting) {
  // your custom code here
  return $value;
}

Parameters

  • $value (mixed) – Value of the setting.
  • $setting (WP_Customize_Setting) – WP_Customize_Setting instance.

More information

See WordPress Developer Resources: customize_update_{$this->type}

Examples

Update a custom post type setting

Update a custom post type setting named ‘my_post_type_setting’.

add_action('customize_update_my_post_type_setting', 'update_my_post_type_setting', 10, 2);

function update_my_post_type_setting($value, $setting) {
  // Update the custom post type setting
  update_post_meta(get_the_ID(), 'my_post_type_setting', $value);
}

Sanitize and update a custom text setting

Sanitize and update a custom text setting named ‘my_text_setting’.

add_action('customize_update_my_text_setting', 'sanitize_and_update_my_text_setting', 10, 2);

function sanitize_and_update_my_text_setting($value, $setting) {
  // Sanitize the value
  $sanitized_value = sanitize_text_field($value);

  // Update the custom text setting
  update_option('my_text_setting', $sanitized_value);
}

Update a custom color setting

Update a custom color setting named ‘my_color_setting’.

add_action('customize_update_my_color_setting', 'update_my_color_setting', 10, 2);

function update_my_color_setting($value, $setting) {
  // Update the custom color setting
  update_option('my_color_setting', $value);
}

Update a custom image setting

Update a custom image setting named ‘my_image_setting’.

add_action('customize_update_my_image_setting', 'update_my_image_setting', 10, 2);

function update_my_image_setting($value, $setting) {
  // Update the custom image setting
  update_option('my_image_setting', $value);
}

Update a custom font size setting

Update a custom font size setting named ‘my_font_size_setting’.

add_action('customize_update_my_font_size_setting', 'update_my_font_size_setting', 10, 2);

function update_my_font_size_setting($value, $setting) {
  // Update the custom font size setting
  update_option('my_font_size_setting', $value);
}