Ignore Empty Save & Continue Values

By default, Populate Anything will honor empty values saved for a field via Save & Continue. Use this snippet if you would like to ignore empty Save & Continue values and use GPPA-populated values.

Code

Filename: gppa-ignore-empty-save-and-continue-values.php

<?php
/**
 * Gravity Perks // Populate Anything // Ignore Empty Save & Continue Values
 * https://gravitywiz.com/documentation/gravity-forms-populate-anything/
 *
 * By default, Populate Anything will honor empty values saved for a field via Save & Continue. Use this snippet if you
 * would like to ignore empty Save & Continue values and use GPPA-populated values.
 */
add_filter( 'gppa_should_force_use_field_value', function( $should_use_field_value, $field ) {

	if ( ! rgar( $_REQUEST, 'gf_token' ) ) {
		return $should_use_field_value;
	}

	$save_and_continue_values = gp_populate_anything()->get_save_and_continue_values( rgar( $_REQUEST, 'gf_token' ) );
	if ( empty( $save_and_continue_values ) ) {
		return $should_use_field_value;
	}

	foreach ( $save_and_continue_values as $input_id => $value ) {
		if ( absint( $field->id ) === absint( $input_id ) ) {
			if ( is_array( $value ) ) {
				$value = array_filter( $value );
			}
			if ( empty( $value ) ) {
				$should_use_field_value = false;
			}
			break;
		}
	}

	return $should_use_field_value;
}, 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.