Created
          May 18, 2022 18:21 
        
      - 
      
- 
        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
  
        
  
    
      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/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