Last active
May 6, 2017 10:56
-
-
Save alpha1/2cb3b79a8874bd182afc to your computer and use it in GitHub Desktop.
Gravity Forms Add Comment for Edited Entry Values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Gravity Forms 1.9.12.9 and above. Needs the 3rd arg on gform_after_update_entry | |
Compares values from the previous entry to the current (updated) entry, and adds a comment marking the user, time, field, and previous to current values that was changes - one comment per change. | |
*/ | |
function gf_add_note($entry_id, $note){ | |
RGFormsModel::add_note($entry_id, 0, __('gravity Forms'), $note); | |
} | |
add_action( 'gform_after_update_entry', 'magx_add_comment_for_changes_details', 10, 3 ); | |
function magx_add_comment_for_changes_details($form, $entry_id, $original_entry){ | |
$entry = GFAPI::get_entry( $entry_id ); | |
$updated_fields = array_diff_assoc($entry, $original_entry); | |
$removed = array_diff_assoc($original_entry,$entry); | |
$updated_fields = array_intersect_key($removed,$updated_fields); | |
foreach($updated_fields as $field_id=>$previous_value){ | |
$field = gf_get_field_by_id($form, $field_id); | |
$previous_value = (!empty($previous_value) ? $previous_value : '(no value)'); | |
$updated_value = (!empty($entry[$field_id]) ? $entry[$field_id] : '(no value)' ); | |
gf_add_note($entry_id, wp_get_current_user()->display_name ." updated <i>{$field->label}</i> (Field ID {$field_id}) from <i>{$previous_value}</i> to <i>{$updated_value}</i> on ". date('F j, Y, g:i a T',time())); | |
} | |
} | |
function gf_get_field_by_id($form, $field_id){ | |
if(!empty($form['fields'])){ | |
foreach($form['fields'] as $field_count=>$field){ | |
if($field_id == $field['id']){ | |
return $form['fields'][$field_count]; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I tried this
function gf_add_note($entry_id, $note){
RGFormsModel::add_note($entry_id, 0, __('System'), $note);
}
add_action( 'gform_after_email', 'log_notifiche', 10, 12 );
function log_notifiche($entry_id, $subject) {
gf_add_note($entry_id, wp_get_current_user()->display_name ." ha inviato una notifica dal titolo {$subject}");
}
but the problem is that I don't get the entry_id and instead of $subject I get the recipient email address...
Any advice pls?