Skip to content

Instantly share code, notes, and snippets.

@rafaehlers
Created May 18, 2022 18:21
Show Gist options
  • Save rafaehlers/ff7b3b1d115356b1d4167e314564a323 to your computer and use it in GitHub Desktop.
Save rafaehlers/ff7b3b1d115356b1d4167e314564a323 to your computer and use it in GitHub Desktop.
Records a timestamp into a field when the entry approval status is changed
<?php // DO NOT COPY THIS LINE
add_action( 'gravityview/approve_entries/updated', 'gv_approval_timestamp', 10, 2 );
function gv_approval_timestamp($entry_id, $status){
if( !class_exists( 'GFAPI' ) ) {
gravityview()->log->error( 'GFAPI does not exist' );
return false;
}
if( !class_exists( 'GravityView_Entry_Approval_Status' ) ) {
gravityview()->log->error( 'GravityView Entry Approval class not loaded' );
return false;
}
$entry = GFAPI::get_entry( $entry_id );
$form = GFAPI::get_form( $entry['form_id'] );
if ( 23 !== (int) $form['id'] ) { // replace 23 with your form ID
return;
}
$input_id = 1; // replace 1 with the field ID where you want to store the information
$action = GravityView_Entry_Approval_Status::get_key( $status );
$updateDate = gmdate("Y-m-d H:i:s");
$value = $action.' on '.$updateDate;
$result = GFAPI::update_entry_field( $entry_id, $input_id, $value );
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment