Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Auto-create a Save and Continue link every time the Partial Entry add-on triggers a save. This ensures the partial entry can always be resumed from the admin with up to date info.
add_action( 'gform_partialentries_post_entry_saved', 'force_save_and_continue_partial_entry_post_save', 10, 2 );
add_action( 'gform_partialentries_post_entry_updated', 'force_save_and_continue_partial_entry_post_save', 10, 2 );
function force_save_and_continue_partial_entry_post_save( $partial_entry, $form ) {
if ( ! rgars( $form, 'save/enabled' ) ) {
return;
}
/* Generate a new save and continue link */
$field_values = \GFForms::post( 'gform_field_values' );
$page_number = \GFFormDisplay::get_source_page( $form['id'] );
$files = \GFFormsModel::set_uploaded_files( $form['id'] );
$form_unique_id = GFFormsModel::get_form_unique_id( $form['id'] );
$ip = rgars( $form, 'personalData/preventIP' ) ? '' : \GFFormsModel::get_ip();
$source_url = esc_url_raw( \GFFormsModel::get_current_page_url() );
$resume_token = sanitize_key( rgpost( 'gform_resume_token' ) );
$resume_token = \GFFormsModel::save_draft_submission( $form, $partial_entry, $field_values, $page_number, $files, $form_unique_id, $ip, $source_url, $resume_token );
/* Store data so Partial Entry plugin can read it */
$partial_entry['resume_token'] = $resume_token;
$source_url = add_query_arg( [ 'gf_token' => $resume_token ], $source_url );
$resume_url = esc_url_raw( $source_url );
$partial_entry['resume_url'] = $resume_url;
$partial_entry['date_saved'] = current_time( 'mysql', true );
/* Update Partial Entry */
\GFAPI::update_entry( $partial_entry );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment