Using WordPress ‘customize_changeset_save_data’ PHP filter

The customize_changeset_save_data WordPress PHP filter allows you to modify the settings’ data that will be stored in a changeset. Plugins can use this filter to add extra data, such as metadata for settings, into the changeset.

Usage

add_filter('customize_changeset_save_data', 'your_function_name', 10, 2);

function your_function_name($data, $context) {
    // your custom code here
    return $data;
}

Parameters

  • $data (array) – The updated changeset data, mapping setting IDs to arrays containing a $value item and optionally other metadata.
  • $context (array) – Filter context including uuid, title, status, date_gmt, post_id, previous_data, and manager (WP_Customize_Manager instance).

More information

See WordPress Developer Resources: customize_changeset_save_data

Examples

Add metadata to a changeset

Add extra metadata to a specific setting in the changeset.

add_filter('customize_changeset_save_data', 'add_metadata_to_changeset', 10, 2);

function add_metadata_to_changeset($data, $context) {
    $data['your_setting_id']['metadata'] = 'your_metadata_value';
    return $data;
}

Update a setting value

Modify the value of a specific setting in the changeset.

add_filter('customize_changeset_save_data', 'update_setting_value', 10, 2);

function update_setting_value($data, $context) {
    $data['your_setting_id']['value'] = 'new_value';
    return $data;
}

Remove a setting from the changeset

Remove a specific setting from the changeset.

add_filter('customize_changeset_save_data', 'remove_setting_from_changeset', 10, 2);

function remove_setting_from_changeset($data, $context) {
    unset($data['your_setting_id']);
    return $data;
}

Set a custom status for the changeset

Change the status of the changeset.

add_filter('customize_changeset_save_data', 'set_changeset_status', 10, 2);

function set_changeset_status($data, $context) {
    $context['status'] = 'your_custom_status';
    return $data;
}

Add a prefix to the changeset title

Add a prefix to the title of the changeset.

add_filter('customize_changeset_save_data', 'add_prefix_to_changeset_title', 10, 2);

function add_prefix_to_changeset_title($data, $context) {
    $context['title'] = 'Prefix - ' . $context['title'];
    return $data;
}