Using Gravity Forms ‘gform_include_bom_export_entries’ PHP filter

The gform_include_bom_export_entries filter in Gravity Forms allows you to include or exclude the BOM (Byte Order Mark) character from the beginning of entry export files.

On this pageJump to a section

Usage

To apply this filter to all forms, use the following code:

add_filter('gform_include_bom_export_entries', 'your_function_name');

Parameters

  • $include_bom (bool) – Whether or not to include the BOM character. Defaults to true.
  • $form (Form Object) – The current form.

More information

See Gravity Forms Docs: gform_include_bom_export_entries

Examples

Exclude the BOM character from all forms

To exclude the BOM character from all forms, use the following code:

add_filter('gform_include_bom_export_entries', 'exclude_bom', 10, 2);

function exclude_bom($include_bom, $form) {
    // Set the BOM to false
    return false;
}

Include the BOM character only for a specific form

To include the BOM character only for a specific form (e.g., form ID 5), use the following code:

add_filter('gform_include_bom_export_entries', 'include_bom_for_form_5', 10, 2);

function include_bom_for_form_5($include_bom, $form) {
    // Include the BOM for form ID 5
    if ($form['id'] == 5) {
        return true;
    }
    return false;
}

Exclude the BOM character based on form title

To exclude the BOM character for forms with a specific title (e.g., “Contact Us”), use the following code:

add_filter('gform_include_bom_export_entries', 'exclude_bom_for_contact_us', 10, 2);

function exclude_bom_for_contact_us($include_bom, $form) {
    // Exclude the BOM for forms with the title "Contact Us"
    if ($form['title'] == 'Contact Us') {
        return false;
    }
    return $include_bom;
}

Include the BOM character based on form settings

To include the BOM character only for forms with a specific setting (e.g., forms with a confirmation message), use the following code:

add_filter('gform_include_bom_export_entries', 'include_bom_for_confirmation_message_forms', 10, 2);

function include_bom_for_confirmation_message_forms($include_bom, $form) {
    // Include the BOM for forms with a confirmation message
    if (!empty($form['confirmation']['message'])) {
        return true;
    }
    return $include_bom;
}

Change the BOM character based on the user role

To change the BOM character based on the user role (e.g., include the BOM for administrators only), use the following code:

add_filter('gform_include_bom_export_entries', 'include_bom_for_administrators', 10, 2);

function include_bom_for_administrators($include_bom, $form) {
    // Get the current user
    $current_user = wp_get_current_user();

    // Include the BOM for administrators only
    if (in_array('administrator', $current_user->roles)) {
        return true;
    }
    return false;
}

Leave a Comment

Your email address will not be published. Required fields are marked *