Last active
September 18, 2020 08:24
-
-
Save Shelob9/7daf0fd73c8f56f8fdaea81168974bf2 to your computer and use it in GitHub Desktop.
Track Caldera Forms entry ID in user meta so form can be used as editor for previous submission https://calderaforms.com/doc/edit-caldera-forms-entries/
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 | |
/** | |
* On form load, check for a saved entry for current user | |
*/ | |
add_filter( 'caldera_forms_render_entry_id', function ( $entry_id, $form ){ | |
//change form ID to match your form | |
if( 'CF1234567' == $form[ 'ID' ] && get_current_user_id() ){ | |
$saved_entry_id = get_user_meta( get_current_user_id(), 'form_entry_id' ); | |
if( 0 < absint( $saved_entry_id ) ){ | |
$entry_id = $saved_entry_id; | |
} | |
} | |
return $entry_id; | |
}, 10, 2); | |
/** | |
* On form submit, save the entry ID as user meta | |
*/ | |
add_action( 'caldera_forms_submit_complete', function( $form, $form_link_array, $process_id, $entry_id ){ | |
//change form ID to match your form | |
if( 'CF1234567' == $form[ 'ID' ] && get_current_user_id() ){ | |
update_user_meta( get_current_user_id(), 'form_entry_id', $entry_id ); | |
} | |
}, 10, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, the first closure "caldera_forms_render_entry_id" is missing the number of arguments witch will cause a warning and be a little difficult to pinpoint off the bat.