Using Gravity Forms ‘gform_is_valid_conditional_logic_operator’ PHP action

The gform_is_valid_conditional_logic_operator filter checks if the operator is valid and allows custom operators to be validated.

Usage

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

Parameters

  • $is_valid (bool): Whether the operator is valid or not.
  • $operator (string): The conditional logic operator.

More information

See Gravity Forms Docs: gform_is_valid_conditional_logic_operator

Examples

Validate custom operator

This example checks if the custom operator “custom_operator” is valid.

function validate_custom_operator($is_valid, $operator) {
  if ($operator == 'custom_operator') {
    // your custom code here
    return true;
  }
  return $is_valid;
}
add_filter('gform_is_valid_conditional_logic_operator', 'validate_custom_operator', 10, 2);

Invalidate a standard operator

This example invalidates the standard “contains” operator.

function invalidate_contains_operator($is_valid, $operator) {
  if ($operator == 'contains') {
    return false;
  }
  return $is_valid;
}
add_filter('gform_is_valid_conditional_logic_operator', 'invalidate_contains_operator', 10, 2);

Validate multiple custom operators

This example checks if multiple custom operators are valid.

function validate_multiple_custom_operators($is_valid, $operator) {
  $custom_operators = array('custom_operator1', 'custom_operator2');

  if (in_array($operator, $custom_operators)) {
    // your custom code here
    return true;
  }
  return $is_valid;
}
add_filter('gform_is_valid_conditional_logic_operator', 'validate_multiple_custom_operators', 10, 2);

Validate custom operator based on user role

This example checks if the custom operator “custom_operator” is valid for users with the “editor” role.

function validate_custom_operator_for_editor($is_valid, $operator) {
  if ($operator == 'custom_operator' && current_user_can('editor')) {
    // your custom code here
    return true;
  }
  return $is_valid;
}
add_filter('gform_is_valid_conditional_logic_operator', 'validate_custom_operator_for_editor', 10, 2);

Invalidate all operators

This example invalidates all conditional logic operators.

function invalidate_all_operators($is_valid, $operator) {
  return false;
}
add_filter('gform_is_valid_conditional_logic_operator', 'invalidate_all_operators', 10, 2);