Draft Groups by Query Parameter

Create draft groups where only drafts saved from a URL with the same group ID (specified by a query parameter) will be displayed when that query parameter is present.

Instructions

Code

Filename: gpasc-draft-groups.php

<?php
/**
 * Gravity Perks // Advanced Save & Continue // Draft Groups by Query Parameter
 * https://gravitywiz.com/documentation/gravity-forms-advanced-save-continue/
 *
 * Instruction Video: https://www.loom.com/share/d8fae1209023492f8a163401b934b052
 *
 * Create draft groups where only drafts saved from a URL with the same group ID
 * (specified by a query parameter) will be displayed when that query parameter is
 * present.
 */
add_filter( 'gpasc_form_resume_tokens', function( $tokens, $form_id ) {
	// Update "order_id" to your desired query parameter.
	$target_parameter = 'order_id';
	$target_value     = rgget( $target_parameter );
	if ( ! $target_value ) {
		return $tokens;
	}
	foreach ( $tokens as &$token ) {
		// If token is specifically passed via parameter, don't interfere.
		$query_token = rgget( 'gf_token' );
		if ( $query_token && $query_token === $token['token'] ) {
			continue;
		}
		$path = parse_url( $token['form_path'], PHP_URL_QUERY );
		parse_str( $path, $params );
		if ( ! isset( $params[ $target_parameter ] ) || $params[ $target_parameter ] != $target_value ) {
			$token = null;
		}
		unset( $token );
	}
	return array_filter( $tokens );
}, 10, 2 );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.