Using Gravity Forms ‘gform_disable_custom_field_names_query’ PHP filter

The gform_disable_custom_field_names_query filter allows you to disable the postmeta query which retrieves custom field names (meta keys) in Gravity Forms. This can help improve editor performance on some sites.

Usage

add_filter('gform_disable_custom_field_names_query', 'your_function_name', 10, 1);

Parameters

  • $disable_query (boolean): Indicates if the custom field names query should be disabled. Default is false.

More information

See Gravity Forms Docs: gform_disable_custom_field_names_query

Examples

Disable Custom Field Names Query

Disable the custom field names query to improve editor performance.

add_filter('gform_disable_custom_field_names_query', 'disable_query', 10, 1);

function disable_query($disable_query) {
    // Disable the custom field names query
    return true;
}

Enable Custom Field Names Query

Explicitly enable the custom field names query.

add_filter('gform_disable_custom_field_names_query', 'enable_query', 10, 1);

function enable_query($disable_query) {
    // Enable the custom field names query
    return false;
}

Disable Custom Field Names Query for a Specific Form

Disable the custom field names query only for a specific form.

add_filter('gform_disable_custom_field_names_query', 'disable_query_for_form', 10, 2);

function disable_query_for_form($disable_query, $form_id) {
    // Check if the form ID matches the target form
    if ($form_id == 5) {
        return true;
    }
    return $disable_query;
}

Enable Custom Field Names Query for a Specific Form

Enable the custom field names query only for a specific form.

add_filter('gform_disable_custom_field_names_query', 'enable_query_for_form', 10, 2);

function enable_query_for_form($disable_query, $form_id) {
    // Check if the form ID matches the target form
    if ($form_id == 5) {
        return false;
    }
    return $disable_query;
}

Disable Custom Field Names Query Based on User Role

Disable the custom field names query for users with the ‘editor’ role.

add_filter('gform_disable_custom_field_names_query', 'disable_query_for_role', 10, 1);

function disable_query_for_role($disable_query) {
    // Check if the current user has the 'editor' role
    if (current_user_can('editor')) {
        return true;
    }
    return $disable_query;
}