Using WordPress ‘customize_changeset_branching’ PHP filter

The customize_changeset_branching WordPress PHP filter allows you to control if changeset branching is permitted or not.

Usage

add_filter('customize_changeset_branching', 'your_custom_function', 10, 2);

function your_custom_function($allow_branching, $wp_customize) {
    // Your custom code here
    return $allow_branching;
}

Parameters

  • $allow_branching (bool): Indicates whether branching is allowed. If false, which is the default, only one saved changeset exists at a time.
  • $wp_customize (WP_Customize_Manager): The manager instance.

More information

See WordPress Developer Resources: customize_changeset_branching

Examples

Enable changeset branching

Enable changeset branching to allow multiple users to work on different changesets simultaneously.

add_filter('customize_changeset_branching', 'enable_changeset_branching', 10, 2);

function enable_changeset_branching($allow_branching, $wp_customize) {
    return true;
}

Disable changeset branching for specific users

Disable changeset branching for users with the ‘editor’ role.

add_filter('customize_changeset_branching', 'disable_branching_for_editors', 10, 2);

function disable_branching_for_editors($allow_branching, $wp_customize) {
    if (current_user_can('editor')) {
        return false;
    }
    return $allow_branching;
}

Enable changeset branching only for administrators

Allow only administrators to use changeset branching.

add_filter('customize_changeset_branching', 'enable_branching_for_admins', 10, 2);

function enable_branching_for_admins($allow_branching, $wp_customize) {
    if (current_user_can('administrator')) {
        return true;
    }
    return $allow_branching;
}

Disable changeset branching on weekends

Prevent changeset branching on weekends.

add_filter('customize_changeset_branching', 'disable_branching_on_weekends', 10, 2);

function disable_branching_on_weekends($allow_branching, $wp_customize) {
    $current_day = date('w');
    if ($current_day == 0 || $current_day == 6) {
        return false;
    }
    return $allow_branching;
}

Enable changeset branching for specific customizer sections

Enable changeset branching only for specific customizer sections like ‘colors’ and ‘header_image’.

add_filter('customize_changeset_branching', 'enable_branching_for_specific_sections', 10, 2);

function enable_branching_for_specific_sections($allow_branching, $wp_customize) {
    $current_section = $wp_customize->get_section('colors');
    if ($current_section || $wp_customize->get_section('header_image')) {
        return true;
    }
    return $allow_branching;
}