Using WordPress ‘customize_control_active’ PHP filter

The customize_control_active WordPress PHP filter is used to modify whether a Customizer control is active or not.

Usage

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

function your_custom_function($active, $control) {
  // your custom code here
  return $active;
}

Parameters

  • $active (bool): Whether the Customizer control is active.
  • $control (WP_Customize_Control): The WP_Customize_Control instance.

More information

See WordPress Developer Resources: customize_control_active

Examples

Deactivate a specific Customizer control

Deactivate the control with the ID ‘my_control_id’.

add_filter('customize_control_active', 'deactivate_specific_control', 10, 2);

function deactivate_specific_control($active, $control) {
  if ('my_control_id' === $control->id) {
    return false;
  }
  return $active;
}

Deactivate all text controls

Deactivate all controls of type ‘text’.

add_filter('customize_control_active', 'deactivate_text_controls', 10, 2);

function deactivate_text_controls($active, $control) {
  if ('text' === $control->type) {
    return false;
  }
  return $active;
}

Activate controls only for specific users

Activate controls only for users with the ‘editor’ role.

add_filter('customize_control_active', 'activate_controls_for_editors', 10, 2);

function activate_controls_for_editors($active, $control) {
  if (current_user_can('editor')) {
    return true;
  }
  return $active;
}

Deactivate controls based on another control’s value

Deactivate a control if another control has a specific value.

add_filter('customize_control_active', 'deactivate_control_based_on_other', 10, 2);

function deactivate_control_based_on_other($active, $control) {
  if ('dependent_control_id' === $control->id) {
    $other_control_value = $control->manager->get_setting('other_control_id')->value();
    if ('specific_value' === $other_control_value) {
      return false;
    }
  }
  return $active;
}

Activate controls only on specific pages

Activate controls only if the current page is a specific page.

add_filter('customize_control_active', 'activate_controls_on_specific_page', 10, 2);

function activate_controls_on_specific_page($active, $control) {
  if (is_page('specific-page-slug')) {
    return true;
  }
  return $active;
}