Use the latest user entry to replace merge tag

Code

Filename: gpls-use-entry-for-each-user-rule-message.php

<?php
/**
 * Gravity Perks // Limit Submissions // Use the latest user entry to replace merge tag
 * variable for the limit message, when rule is set to `Each User`.
 * https://gravitywiz.com/documentation/gravity-forms-limit-submissions/
 */

//Update string `45` to your form ID.
add_filter( 'gpls_limit_message_45', function( $message, $form ) {
	if ( ! rgpost( 'gform_submit' ) ) {
		$search_criteria['field_filters'] = array(
			array(
				'key'   => 'created_by',
				'value' => get_current_user_id(),
			),
		);
		$total_count                      = 0;
		$results                          = GFAPI::get_entries( $form['id'], $search_criteria, array(), array(), $total_count );
		if ( $total_count > 0 ) {
			$message = GFCommon::replace_variables( $message, $form, $results[0], false, false, false, 'html' );
		}
	}

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