Using Gravity Forms ‘gform_form_list_count’ PHP action

The gform_form_list_count filter in Gravity Forms allows the form list count array to be modified. This is useful when filtering the form count list. This filter should be used with the gform_form_list_forms hook.

Usage

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

Parameters

  • $form_count (array): The form count by filter name.

More information

See Gravity Forms Docs: gform_form_list_count

Examples

Set the active form count to 20

add_filter('gform_form_list_count', 'change_list_count', 10, 1);

function change_list_count($form_count) {
    $form_count['active'] = 20;
    return $form_count;
}

Reduce the form count by half and reflect the change in active or inactive

add_filter('gform_form_list_count', 'change_list_count', 10, 1);

function change_list_count($form_count) {
    if (!isset($_GET['filter'])) {
        $filter = '';
    } else {
        $filter = $_GET['filter'];
    }

    switch ($filter) {
        case 'active':
            $orig_count = $form_count['active'];
            $form_count['active'] = round($form_count['active'] / 2);
            $form_count['total'] = $form_count['total'] - ($orig_count - $form_count['active']);
            break;
        case 'inactive':
            $orig_count = $form_count['inactive'];
            $form_count['inactive'] = round($form_count['inactive'] / 2);
            $form_count['total'] = $form_count['total'] - ($orig_count - $form_count['inactive']);
            break;
        case 'trash':
            $form_count['trash'] = round($form_count['trash'] / 2);
            break;
        default:
            $orig_count = $form_count['total'];
            $active_count = $form_count['active'];
            $inactive_count = $form_count['inactive'];
            $form_count['total'] = round($form_count['total'] / 2);
            $number_to_remove = $orig_count - $form_count['total'];

            if ($active_count < $number_to_remove) {
                $form_count['active'] = 0;
                $form_count['inactive'] = $inactive_count - ($number_to_remove - $active_count);
            } else {
                $form_count['active'] = $active_count - $number_to_remove;
            }
    }

    return $form_count;
}

Note: This code should be placed in the functions.php file of your active theme.