Skip to content

Commit 3018ec3

Browse files
authored
gw-draft-resume-change-notice.php: Added new snippet that displays a notice when a user resumes draft from a new IP/UA.
1 parent c84ab52 commit 3018ec3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

gravity-forms/gw-draft-resume-change-notice.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Gravity Wiz // Gravity Forms // Draft Resume Change Notice
44
* https://gravitywiz.com/
55
*
6-
* Use this snippet to display a notice when the user resumes a draft from a different location, browser or device.
6+
* Use this snippet to display a notice when the user resumes draft from a different location, browser or device.
77
*/
88
add_filter( 'gform_get_form_filter', function( $form_markup, $form ) {
99

@@ -14,6 +14,8 @@
1414

1515
global $wpdb;
1616
$table = GFFormsModel::get_draft_submissions_table_name();
17+
18+
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
1719
$draft = $wpdb->get_row(
1820
$wpdb->prepare(
1921
"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
@@ -32,11 +34,11 @@
3234
$submission_data = json_decode( $draft->submission, true );
3335
$submission_data = is_array( $submission_data ) ? $submission_data : array();
3436

35-
$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
37+
$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
3638
$current_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
3739

38-
$stored_ip = $draft->ip ?? '';
39-
$current_ip = GFFormsModel::get_ip();
40+
$stored_ip = $draft->ip ?? '';
41+
$current_ip = GFFormsModel::get_ip();
4042

4143
$ip_changed = ( $stored_ip && $current_ip && $stored_ip !== $current_ip );
4244
$browser_changed = ( $stored_user_agent && $current_user_agent && $stored_user_agent !== $current_user_agent );
@@ -45,10 +47,10 @@
4547
return $form_markup;
4648
}
4749

48-
// Configure Messages
49-
$ip_changed_message = "🌍 Your location has changed since last editing this draft";
50-
$browser_changed_message = "💻 Your browser or device has changed since last editing this draft";
51-
$both_changed_message = "🔒 Your location and device have both changed since last editing this draft";
50+
// Configure Messages
51+
$ip_changed_message = '🌍 Your location has changed since last editing this draft';
52+
$browser_changed_message = '💻 Your browser or device has changed since last editing this draft';
53+
$both_changed_message = '🔒 Your location AND device have both changed since last editing this draft';
5254

5355
$message = $both_changed_message;
5456
if ( $ip_changed && ! $browser_changed ) {

0 commit comments

Comments
 (0)