Add export column for entry notes

This feature is now available within the Gravity Hopper plugin.

Entry notes can be a useful thing to investigate at times. The GFAPI class provides a method for querying these notes. The following script allows you to pull those notes along with your entry exports.

// Add export column for entry notes
add_filter( 'gform_export_fields', function( $form ) {
    
    // append our column
    array_push( $form['fields'], array( 'id' => 'entry_notes', 'label' => 'Entry Notes' ) );
    
    // set the header for the column
    add_filter( 'gform_entries_field_header_pre_export_entry_notes', function( $header, $form, $export_field ) {
        return 'Entry Notes';
    }, 10, 3 );
    
    // query and concatenate entry notes
    add_filter( 'gform_export_field_value', function( $value, $form_id, $field_id, $entry ) {
        
        if ( $field_id == 'entry_notes' ) {
            
            $value = '';
            $notes = GFAPI::get_notes( array( 'entry_id' => rgar( $entry, 'id' ) ) );
            
            foreach ( $notes as $note ) {
                $value .= "{$note->date_created}: {$note->value}\r";
            }
            
        }

        return $value;
        
    }, 10, 4 );

    return $form;
    
} );Code language: PHP (php)

How do you find this article?