Skip to content

Instantly share code, notes, and snippets.

@Shelob9
Last active September 18, 2020 08:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Shelob9/7daf0fd73c8f56f8fdaea81168974bf2 to your computer and use it in GitHub Desktop.
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/
<?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);
@robwilde
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment