gform_form_list_count

gform_form_list_count

DescriptionUsageParametersExamplesPlacementSinceSource Code

Description
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
1add_filter( 'gform_form_list_count', 'your_function_name', 10, 1 );

Parameters

$form_count array
The form count by filter name.

Examples
This example simply sets the active form count to 20.
12345add_filter( 'gform_form_list_count', 'change_list_count', 10, 1 );function change_list_count( $form_count ){  $form_count['active'] = 20;  return $form_count;}
This example reduces the form count by half and reflects the change in active or inactive. Trash is not counted in the total.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748add_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' :                //remove half of forms that are active, adjust total                $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' :                //remove half of forms that are inactive, adjust total                $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' :                //remove half of forms that are trash, do NOT adjust total because trash is not counted in total                $form_count['trash'] = round( $form_count['trash']/2 );                break;            default :                //all forms, remove half and adjust counts                $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'];                //active and inactive counts need to be modified since the form array will be removing active/inactive items                //remove active forms first, if there are less active forms than the new form total, need to remove from inactive as well                if ( $active_count < $number_to_remove ){                    //remove active                    $form_count['active'] = 0;                    //remove inactive                    $form_count['inactive'] = $inactive_count - ($number_to_remove - $active_count);                }                else{                    //just remove active                    $form_count['active'] = $active_count - $number_to_remove;                }    }    return $form_count;} Placement This code should be placed in the functions.php file of your active theme. Since This filter was added in Gravity Forms version 2.3. Source Code This filter is located in GF_Form_List_Table::get_views() in form_list.php.

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注