Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Last active October 15, 2024 23:54
Show Gist options
  • Save rafaehlers/76b77eee723cb8ec69ab6639326b2db2 to your computer and use it in GitHub Desktop.
Save rafaehlers/76b77eee723cb8ec69ab6639326b2db2 to your computer and use it in GitHub Desktop.
Store the username and the date of the entry approval
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/approve_entries/updated', 'gv_custom_function', 10, 1 );
add_action( 'gravityview/approve_entries/approved', 'gv_custom_function', 10, 1 );
function gv_custom_function( $entry_id ){
$entry = GFAPI::get_entry( $entry_id );
$form = GFAPI::get_form( $entry['form_id'] );
$run_on_views = [100,200]; //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 = 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_user, $current_user->user_login );
$field_id_date = 4; // replace 4 with the ID of the field that you want to store the date of the modification
$updateDate = gmdate("Y-m-d H:i:s");
$update_result = GFAPI::update_entry_field( $entry['id'], $field_id_date, $updateDate );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment