gform_entry_meta

Description

Use this hook to add custom properties to the Entry object. Allows entry meta data to be added as sortable columns to the entry list and export entries file.

Usage

add_filter( 'gform_entry_meta', 'custom_entry_meta', 10, 2);

Parameters

  • $entry_meta array

    Entry meta array.

  • $form_id integer

    The ID of the form from which the entry value was submitted.

Examples

1. Basic meta column

add_filter( 'gform_entry_meta', 'custom_entry_meta', 10, 2 );
function custom_entry_meta( $entry_meta, $form_id ) {
    // data will be stored with the meta key named score
    // label - entry list will use Score as the column header
    // is_numeric - used when sorting the entry list, indicates whether the data should be treated as numeric when sorting
    // is_default_column - when set to true automatically adds the column to the entry list, without having to edit and add the column for display
    // update_entry_meta_callback - indicates what function to call to update the entry meta upon form submission or editing an entry
    $entry_meta['score'] = array(
        'label' => 'Score',
        'is_numeric' => true,
        'update_entry_meta_callback' => 'update_entry_meta',
        'is_default_column' => true
    );

    return $entry_meta;
}

function update_entry_meta( $key, $lead, $form ) {
    //update score
    $value = "5";
    return $value;
}

2. Meta column with filters

add_filter( 'gform_entry_meta', function ( $entry_meta, $form_id ) {
	$entry_meta['test'] = array(
		'label'                      => 'Test',
		'is_numeric'                 => false,
		'update_entry_meta_callback' => 'update_entry_meta_test',
		'is_default_column'          => false,
		'filter'                     => array(
			'key'       => 'test',
			'text'      => 'Test',
			'operators' => array(
				'is',
				'isnot',
			)
		),
	);

	return $entry_meta;
}, 10, 2 );

function update_entry_meta_test( $key, $entry, $form ){
    //update test
    $value = "thisisatest";
    return $value;
}

3. Quiz Add-On Meta

add_filter( 'gform_entry_meta', array( 'GFQuiz', 'entry_meta' ), 10, 2);
		public static function entry_meta($entry_meta, $form_id){
            $form = RGFormsModel::get_form_meta($form_id);
            $quiz_fields = GFCommon::get_fields_by_type( $form, array( 'quiz' ) );
            if ( false === empty ( $quiz_fields ) ) {
                 $entry_meta['gquiz_score'] = array(
                    'label' => 'Quiz Score Total',
                    'is_numeric' => true,
                    'update_entry_meta_callback' => array('GFQuiz', 'update_entry_meta')
                    );
                 $entry_meta['gquiz_grade'] = array(
                    'label' => 'Quiz Grade',
                    'is_numeric' => false,
                    'update_entry_meta_callback' => array('GFQuiz', 'update_entry_meta')
                    );
                 $entry_meta['gquiz_percent'] = array(
                    'label' => 'Quiz Percentage',
                    'is_numeric' => true,
                    'update_entry_meta_callback' => array('GFQuiz', 'update_entry_meta')
                    );
                 $entry_meta['gquiz_is_pass'] = array(
                    'label' => 'Quiz Pass/Fail',
                    'is_numeric' => false,
                    'update_entry_meta_callback' => array('GFQuiz', 'update_entry_meta')
                    );
            }
            return $entry_meta;
        }
        public static function update_entry_meta($key, $lead, $form){
            $value = "";
            $results = self::get_quiz_results( $form, $lead, false );
            if ( $key == "gquiz_score" )
                $value = $results["score"];
            elseif ( $key == "gquiz_percent" )
                $value = $results["percent"];
            elseif ( $key == "gquiz_grade" )
                $value = $results["grade"];
            elseif ( $key == "gquiz_is_pass" )
                $value = $results["is_pass"] ? "1" : "0";
            return $value;
        }

Placement

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

Since

This filter was added in Gravity Forms version 1.7.

Source Code

This action hook is located in GFFormsModel::get_entry_meta() in forms_model.php.