Last active
July 28, 2025 23:59
-
-
Save rafaehlers/77e77ca8a8f6c69122fa124fdebcb57f to your computer and use it in GitHub Desktop.
Store the username of the user that last modified the entry
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
<?php // DO NOT COPY THIS LINE | |
add_action( 'gravityview/edit_entry/after_update', 'gv_custom_function', 10, 3 ); | |
function gv_custom_function( $form = array(), $entry_id = array(), $object ){ | |
$run_on_views = [4049]; //Change this to the IDs of the Views you'd like to run this code | |
$view_id = GravityView_View::getInstance()->getViewId(); | |
if( !in_array( $view_id, $run_on_views ) ){ | |
return false; | |
} | |
$current_user = wp_get_current_user(); | |
if ( ! ( $current_user instanceof WP_User ) ) { | |
return; | |
} | |
$field_id_user = 4; // replace 3 with the ID of the field you want to store the username | |
$update_result = GFAPI::update_entry_field( $entry_id, $field_id_user, $current_user->user_login ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment