How to log the user that modified the entry

If you wish to log the last user who modified an entry with GravityEdit, you just need to add a new single line text field to your form, and use the code below:

add_filter( 'gravityview-inline-edit/entry-updated', 'gravityedit_custom_who_changed', 10, 5 );

function gravityedit_custom_who_changed( $update_result, $entry = array(), $form_id = 0, $gf_field = null, $original_entry = array() ) { 
	
    if ( 124 !== (int) $form_id ) { // replace 124 with your form ID
		return $update_result;
	}
	
	$current_user = wp_get_current_user();
 	if ( ! ( $current_user instanceof WP_User ) ) {
		return $update_result;
	}
	
	$field_id = 3; // replace 3 with the ID of the field you want to store the username
    
	$update_result = GFAPI::update_entry_field( $entry['id'], $field_id, $current_user->user_login );
	
    return $update_result;
}

Screenshot of the form editor

Screenshot of the View with GravityEdit enabled

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us