Skip to content

Conversation

SebastianWiz
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/3062075880/88769?viewId=3808239

Summary

A new snippet to display a notice on top of the form when a saved draft is resumed from a different IP address and/or User-Agent than the one that created or last edited it.

image

Copy link

coderabbitai bot commented Sep 11, 2025

Walkthrough

Adds a Gravity Forms filter that, when a gf_token query param is present, looks up a draft by UUID, validates form_id, decodes the stored submission, compares stored IP and User‑Agent to current values, and prepends an escaped, contextual warning block to the form markup when changes are detected.

Changes

Cohort / File(s) Summary
Draft resume change notice filter
gravity-forms/gw-draft-resume-change-notice.php
New gform_get_form_filter callback: reads and sanitizes gf_token, queries drafts table by UUID with a prepared statement, validates form_id, json_decodes stored submission, compares stored IP and HTTP_USER_AGENT with current values (GFFormsModel::get_ip(), $_SERVER['HTTP_USER_AGENT']), constructs and escapes one of three contextual warning messages (IP changed, browser changed, or both), and prepends the notice to the form markup. Returns original markup when token missing, draft not found, or form_id mismatch. Uses safe JSON handling and prepared SQL.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User Browser
  participant WP as WordPress + Gravity Forms
  participant Filter as gform_get_form_filter
  participant DB as GF Drafts Table

  U->>WP: Request form page (may include gf_token)
  WP->>Filter: apply filter(form_markup, form)

  alt gf_token present
    Filter->>DB: SELECT * FROM drafts WHERE uuid = :token (prepared)
    DB-->>Filter: draft row or none
    alt Draft found && form_id matches
      Filter->>Filter: json_decode(submission) → stored_ip, stored_ua
      Filter->>WP: GFFormsModel::get_ip() and $_SERVER['HTTP_USER_AGENT']
      alt IP changed or UA changed
        Filter-->>WP: Build escaped contextual warning (IP / UA / both) and prepend to form_markup
      else No change
        Filter-->>WP: Return original form_markup
      end
    else Not found or form_id mismatch
      Filter-->>WP: Return original form_markup
    end
  else No token
    Filter-->>WP: Return original form_markup
  end

  WP-->>U: Rendered form (with or without warning)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title clearly summarizes the addition of a snippet that displays a notice when a draft is resumed from a different IP or user agent, reflecting the main purpose of the changeset without unnecessary detail.
Description Check ✅ Passed The pull request description adheres to the repository’s template by including a Context section with the HelpScout ticket link and a Summary section that succinctly describes the new snippet; unused template lines were appropriately removed and the information is clear and complete.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch SebastianWiz-patch-1

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 42a33c0 and ea46c47.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gravity-forms/gw-draft-resume-change-notice.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

github-actions bot commented Sep 11, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.
Messages
📖 Merlin would give this scroll the highest of praises. Cheers for adding this new snippet to the library! 🪄

Generated by 🚫 dangerJS against ea46c47

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (3)
gravity-forms/gw-draft-resume-change-notice.php (3)

15-23: Avoid duplicate DB lookups when multiple forms render on the page.

Cache the lookup per gf_token to prevent repeated queries on the same request.

Example (outside-selected lines for context only):

static $gw_notice_cache = array();
if ( isset( $gw_notice_cache[ $token ] ) ) {
	return $gw_notice_cache[ $token ] . $form_markup;
}
// ... compute $warning or '' ...
$gw_notice_cache[ $token ] = $warning;

32-37: More robust UA retrieval (fallback).

Some drafts store user_agent at the root. Add a fallback to reduce false negatives.

Apply:

-	$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
+	$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? ( $submission_data['user_agent'] ?? '' );

60-64: Minor a11y: announce the notice politely and add a class hook.

Expose a class and live region for screen readers.

Apply:

-	$warning  = '<div style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
+	$warning  = '<div role="status" aria-live="polite" class="gw-draft-resume-notice" style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 692c93e and c84ab52.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🧰 Additional context used
🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-draft-resume-change-notice.php

[failure] 51-51:
String "🔒 Your location and device have both changed since last editing this draft" does not require double quotes; use single quotes instead


[failure] 50-50:
String "💻 Your browser or device has changed since last editing this draft" does not require double quotes; use single quotes instead


[failure] 49-49:
String "🌍 Your location has changed since last editing this draft" does not require double quotes; use single quotes instead


[warning] 39-39:
Equals sign not aligned with surrounding assignments; expected 1 space but found 2 spaces


[warning] 38-38:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 3 spaces


[warning] 35-35:
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space


[failure] 19-19:
Use placeholders and $wpdb->prepare(); found interpolated variable $table at "SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s"


[failure] 13-13:
Tabs must be used to indent lines; spaces are not allowed

🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-draft-resume-change-notice.php

[error] 13-13: PHPCS: Tabs must be used to indent lines; spaces are not allowed. (Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed)

🔇 Additional comments (1)
gravity-forms/gw-draft-resume-change-notice.php (1)

10-12: Good early-bail and sanitization.

The token gate and use of wp_unslash() + sanitize_text_field() look solid.

@SebastianWiz
Copy link
Contributor Author

I realize this snippet would make more sense under the GPASC category since it was created to try and mitigate potential data loss when using the auto-save feature.

@SebastianWiz SebastianWiz deleted the SebastianWiz-patch-1 branch September 11, 2025 23:45
@SebastianWiz SebastianWiz restored the SebastianWiz-patch-1 branch September 15, 2025 16:45
…a notice when a user resumes draft from a new IP/UA.
@SebastianWiz
Copy link
Contributor Author

Reopening PR

@SebastianWiz SebastianWiz reopened this Sep 15, 2025
…a notice when a user resumes draft from a new IP/UA.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (3)
gravity-forms/gw-draft-resume-change-notice.php (3)

55-61: Expose the final message via a filter for customization.

Lets site owners tweak copy without editing the snippet.

 	if ( $ip_changed && ! $browser_changed ) {
 		$message = $ip_changed_message;
 	} elseif ( $browser_changed && ! $ip_changed ) {
 		$message = $browser_changed_message;
 	}
+
+	// Allow customization of the final message.
+	$message = apply_filters( 'gw_draft_resume_change_notice_message', $message, $ip_changed, $browser_changed, $form, $draft );

13-13: Fix tab indentation (CI blocker).

PHPCS fails on these lines due to leading spaces. Replace with tabs.

-    $token = sanitize_text_field( wp_unslash( $_GET['gf_token'] ) );
+	$token = sanitize_text_field( wp_unslash( $_GET['gf_token'] ) );
@@
-    // Configure Messages
+	// Configure Messages

Also applies to: 50-50


16-21: Silence WPCS false-positive for table identifier + trim stray whitespace.

Add NotPrepared to the ignore and convert leading spaces to a tab; also remove trailing whitespace on the blank line above.

-	$table = GFFormsModel::get_draft_submissions_table_name();
-    
-    // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+	$table = GFFormsModel::get_draft_submissions_table_name();
+
+	// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF table; values use $wpdb->prepare().
 	$draft = $wpdb->get_row(
 		$wpdb->prepare(
 			"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
🧹 Nitpick comments (2)
gravity-forms/gw-draft-resume-change-notice.php (2)

62-66: Allow overriding the wrapper markup; inline styles are hard to theme.

Offer a filter so themes can swap styles/classes (e.g., GF notice classes) without forking the snippet.

 	$warning  = '<div style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
 	$warning .= '<strong style="color:#856404;">' . esc_html( $message ) . '</strong>';
 	$warning .= '</div>';
+
+	// Allow customization of the warning markup/container.
+	$warning = apply_filters( 'gw_draft_resume_change_notice_markup', $warning, $message, $form, $draft );

37-45: Minor: normalize UA strings before comparison.

Trim to avoid false positives from incidental whitespace.

-	$stored_user_agent  = $submission_data['partial_entry']['user_agent'] ?? '';
-	$current_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
+	$stored_user_agent  = isset( $submission_data['partial_entry']['user_agent'] ) ? trim( (string) $submission_data['partial_entry']['user_agent'] ) : '';
+	$current_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? trim( (string) $_SERVER['HTTP_USER_AGENT'] ) : '';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c84ab52 and 3018ec3.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🧰 Additional context used
🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-draft-resume-change-notice.php

[failure] 50-50:
Tabs must be used to indent lines; spaces are not allowed


[failure] 21-21:
Use placeholders and $wpdb->prepare(); found interpolated variable $table at "SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s"


[failure] 17-17:
Whitespace found at end of line


[failure] 17-17:
Tabs must be used to indent lines; spaces are not allowed


[failure] 13-13:
Tabs must be used to indent lines; spaces are not allowed

🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-draft-resume-change-notice.php

[error] 13-13: PHPCS: Tabs must be used to indent lines; spaces are not allowed. (Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed)

🔇 Additional comments (1)
gravity-forms/gw-draft-resume-change-notice.php (1)

10-12: LGTM: sensible early‑exit guards.

Bailouts on missing token, form_id mismatch, and unchanged IP/UA look correct and keep render fast.

Also applies to: 30-32, 46-48

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
gravity-forms/gw-draft-resume-change-notice.php (1)

1-69: Fix space indentation (use tabs) and remove whitespace-only lines so PHPCS passes.

  • gravity-forms/gw-draft-resume-change-notice.php — replace leading spaces with tabs on lines 3, 4, 5, 6, 7, 18, 50; remove the whitespace-only line 17. Re-run PHPCS and confirm clean.
♻️ Duplicate comments (3)
gravity-forms/gw-draft-resume-change-notice.php (3)

55-61: Expose the final message via a filter.

Allows sites to customize copy without editing the snippet.

Apply:

 	if ( $ip_changed && ! $browser_changed ) {
 		$message = $ip_changed_message;
 	} elseif ( $browser_changed && ! $ip_changed ) {
 		$message = $browser_changed_message;
 	}
 
+	// Allow customization of the final message.
+	$message = apply_filters( 'gw_draft_resume_change_notice_message', $message, $ip_changed, $browser_changed, $form, $draft );

18-24: WPCS: broaden ignore and place it precisely on the SQL line.

The interpolated $table triggers both InterpolatedNotPrepared and NotPrepared. Put the ignore directly above the SQL string line and include both codes; also fix indentation to tabs.

Apply:

-    // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
-	$draft = $wpdb->get_row(
-		$wpdb->prepare(
-			"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
-			$token
-		)
-	);
+	$draft = $wpdb->get_row(
+		// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF table; placeholder used for value.
+		$wpdb->prepare(
+			"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
+			$token
+		)
+	);

50-53: Fix tab indentation (PHPCS blocker).

Replace leading spaces with a tab.

Apply:

-    // Configure Messages
+	// Configure Messages
🧹 Nitpick comments (2)
gravity-forms/gw-draft-resume-change-notice.php (2)

30-32: Use rgar() for resilience (minor).

Avoid direct array access in case $form lacks 'id'.

Apply:

-	if ( (int) $form['id'] !== (int) $draft->form_id ) {
+	if ( (int) rgar( $form, 'id' ) !== (int) $draft->form_id ) {

62-66: A11y + extensibility: add role/class and a markup filter.

Improve screen reader support and let implementers override the HTML.

Apply:

-	$warning  = '<div style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
+	$warning  = '<div class="gw-draft-resume-change-notice" role="alert" aria-live="polite" style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
 	$warning .= '<strong style="color:#856404;">' . esc_html( $message ) . '</strong>';
 	$warning .= '</div>';
+
+	// Allow customization of the full notice markup.
+	$warning = apply_filters( 'gw_draft_resume_change_notice_markup', $warning, $message, $ip_changed, $browser_changed, $form, $draft );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3018ec3 and ba8fb22.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🧰 Additional context used
🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-draft-resume-change-notice.php

[failure] 50-50:
Tabs must be used to indent lines; spaces are not allowed


[failure] 21-21:
Use placeholders and $wpdb->prepare(); found interpolated variable $table at "SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s"


[failure] 17-17:
Whitespace found at end of line


[failure] 17-17:
Tabs must be used to indent lines; spaces are not allowed

🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-draft-resume-change-notice.php

[error] 17-17: PHPCS check failed (thenabeel/action-phpcs@v8): Tabs must be used to indent lines; spaces are not allowed. (Generic.WhiteSpace.DisallowSpaceIndent.SpacesUsed)

🔇 Additional comments (2)
gravity-forms/gw-draft-resume-change-notice.php (2)

10-14: Input handling + early return look good.

Token presence check, sanitization, and bailout paths are correct.


37-45: Change detection logic is solid.

Null‑coalesce and strict inequality keep it safe and predictable.

…a notice when a user resumes draft from a new IP/UA.
…a notice when a user resumes draft from a new IP/UA.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
gravity-forms/gw-draft-resume-change-notice.php (1)

53-63: Consider adding a filter for message customization.

The message selection logic is correct. As suggested in a previous review, you could expose a filter to allow customization of the final message for different use cases.

Apply this diff to add the filter:

 	$message = $both_changed_message;
 	if ( $ip_changed && ! $browser_changed ) {
 		$message = $ip_changed_message;
 	} elseif ( $browser_changed && ! $ip_changed ) {
 		$message = $browser_changed_message;
 	}
+
+	// Allow customization of the notice message.
+	$message = apply_filters( 'gw_draft_resume_change_notice_message', $message, $ip_changed, $browser_changed, $form, $draft );
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ba8fb22 and aad73a5.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-draft-resume-change-notice.php

[warning] 20-20: Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.


[error] 22-22: String "SELECT form_id, ip, submission FROM %s WHERE uuid = %%s" does not require double quotes; use single quotes instead

🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-draft-resume-change-notice.php

[failure] 22-22:
String "SELECT form_id, ip, submission FROM %s WHERE uuid = %%s" does not require double quotes; use single quotes instead


[warning] 20-20:
Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

🔇 Additional comments (3)
gravity-forms/gw-draft-resume-change-notice.php (3)

8-13: LGTM! Token handling is secure.

The early return pattern and sanitization using sanitize_text_field( wp_unslash() ) properly handles the token input from the query string.


37-47: LGTM! Data extraction and comparison logic is sound.

The defensive handling of JSON decoding, null coalescing for missing keys, and truthy checks before comparison properly prevent false positives when values are empty.


65-69: LGTM! Output is properly escaped.

The warning HTML uses inline styles (avoiding external dependencies) and properly escapes the message with esc_html() before output.

Comment on lines 18 to 27
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$draft = $wpdb->get_row(
$wpdb->prepare(
sprintf(
"SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s",
esc_sql( $table )
),
$uuid
)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Critical: undefined variable and incorrect prepare() usage.

Line 25 references $uuid but the variable is defined as $token on Line 13. This will cause a fatal error.

Additionally, the current sprintf/esc_sql/prepare combination is incorrect:

  • sprintf consumes the %s placeholder, leaving %%s (which becomes %s after sprintf)
  • $wpdb->prepare then expects a placeholder but the string already has the table name interpolated
  • This causes the "incorrect number of replacements" warning from PHPCS and the pipeline

Table names are identifiers and cannot be prepared with $wpdb->prepare. The correct approach is direct interpolation with a comprehensive phpcs:ignore comment.

Apply this diff to fix both issues:

-    // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+	// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF identifier; token is prepared.
 	$draft = $wpdb->get_row(
 		$wpdb->prepare(
-			sprintf(
-				"SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s",
-				esc_sql( $table )
-			),
-			$uuid
+			"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
+			$token
 		)
 	);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$draft = $wpdb->get_row(
$wpdb->prepare(
sprintf(
"SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s",
esc_sql( $table )
),
$uuid
)
);
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF identifier; token is prepared.
$draft = $wpdb->get_row(
$wpdb->prepare(
"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
$token
)
);
🧰 Tools
🪛 GitHub Actions: PHP Lint (PR)

[warning] 20-20: Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.


[error] 22-22: String "SELECT form_id, ip, submission FROM %s WHERE uuid = %%s" does not require double quotes; use single quotes instead

🪛 GitHub Check: PHPCS (Files Changed)

[failure] 22-22:
String "SELECT form_id, ip, submission FROM %s WHERE uuid = %%s" does not require double quotes; use single quotes instead


[warning] 20-20:
Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

🤖 Prompt for AI Agents
In gravity-forms/gw-draft-resume-change-notice.php around lines 18 to 27, the
query uses an undefined $uuid and misuses sprintf/esc_sql with $wpdb->prepare
causing replacement/count errors; change the variable to $token (the defined
name), stop using sprintf to insert the table name into the prepared statement,
instead build the SQL string by interpolating the esc_sql($table) directly (with
a phpcs:ignore comment for table name interpolation), and call $wpdb->prepare
with a SQL string that contains a single %s placeholder for the token and pass
$token as the parameter so only the token is prepared.

…a notice when a user resumes draft from a new IP/UA.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (2)
gravity-forms/gw-draft-resume-change-notice.php (2)

53-63: Consider adding a filter for message customization.

The messages are well-structured, but exposing them through a filter would allow developers to customize the text without modifying the snippet.

Add this after line 63:

 		$message = $browser_changed_message;
 	}
+
+	// Allow customization of the message.
+	$message = apply_filters( 'gw_draft_resume_change_notice_message', $message, $ip_changed, $browser_changed, $form, $draft );

65-67: Consider allowing style customization.

The inline styles work well, but exposing them through a filter would provide greater flexibility for developers who want to match their site's design.

Replace the hardcoded styles with a filterable variable:

-	$warning  = '<div style="background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;">';
-	$warning .= '<strong style="color:#856404;">' . esc_html( $message ) . '</strong>';
+	$default_styles = array(
+		'container' => 'background:#fff3cd;border:1px solid #ffc107;padding:15px;margin-bottom:15px;',
+		'text'      => 'color:#856404;',
+	);
+	$styles         = apply_filters( 'gw_draft_resume_change_notice_styles', $default_styles, $form );
+
+	$warning  = '<div style="' . esc_attr( $styles['container'] ) . '">';
+	$warning .= '<strong style="' . esc_attr( $styles['text'] ) . '">' . esc_html( $message ) . '</strong>';
 	$warning .= '</div>';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aad73a5 and 42a33c0.

📒 Files selected for processing (1)
  • gravity-forms/gw-draft-resume-change-notice.php (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: PHP Lint (PR)
gravity-forms/gw-draft-resume-change-notice.php

[warning] 20-20: Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

🪛 GitHub Check: PHPCS (Files Changed)
gravity-forms/gw-draft-resume-change-notice.php

[warning] 20-20:
Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

Comment on lines 18 to 27
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$draft = $wpdb->get_row(
$wpdb->prepare(
sprintf(
'SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s',
esc_sql( $table )
),
$token
)
);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Fix the database query construction (pipeline blocker).

The current sprintf + esc_sql + $wpdb->prepare combination is incorrect and causes the PHPCS warning. After sprintf processes the table name, %%s becomes %s, but the table is already interpolated, causing a mismatch in replacement count.

Table names are identifiers and cannot be prepared with placeholders. Use direct interpolation with a comprehensive phpcs:ignore comment.

Apply this diff:

-    // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
+	// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF identifier; token is prepared.
 	$draft = $wpdb->get_row(
 		$wpdb->prepare(
-			sprintf(
-				'SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s',
-				esc_sql( $table )
-			),
+			"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
 			$token
 		)
 	);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared
$draft = $wpdb->get_row(
$wpdb->prepare(
sprintf(
'SELECT form_id, ip, submission FROM `%s` WHERE uuid = %%s',
esc_sql( $table )
),
$token
)
);
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared,WordPress.DB.PreparedSQL.NotPrepared -- $table is a trusted GF identifier; token is prepared.
$draft = $wpdb->get_row(
$wpdb->prepare(
"SELECT form_id, ip, submission FROM {$table} WHERE uuid = %s",
$token
)
);
🧰 Tools
🪛 GitHub Actions: PHP Lint (PR)

[warning] 20-20: Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

🪛 GitHub Check: PHPCS (Files Changed)

[warning] 20-20:
Incorrect number of replacements passed to $wpdb->prepare(). Found 1 replacement parameters, expected 0.

🤖 Prompt for AI Agents
In gravity-forms/gw-draft-resume-change-notice.php around lines 18 to 27, the
query builds the SQL using sprintf+esc_sql then passes it to $wpdb->prepare
which corrupts the placeholder count; instead interpolate the validated table
name directly into the query string and call $wpdb->prepare only for the %s
placeholder for uuid, and add a targeted phpcs:ignore comment
(WordPress.DB.PreparedSQL.InterpolatedNotPrepared) on the line that interpolates
the table name so PHPCS accepts the direct identifier interpolation.

Comment on lines +40 to +41
$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
$current_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Consider sanitizing the current User-Agent.

While the current User-Agent is only used for comparison and not stored or displayed, sanitizing external input is a best practice. Consider using sanitize_text_field() for consistency.

Apply this diff:

 	$stored_user_agent  = $submission_data['partial_entry']['user_agent'] ?? '';
-	$current_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
+	$current_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) ) : '';
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
$current_user_agent = $_SERVER['HTTP_USER_AGENT'] ?? '';
$stored_user_agent = $submission_data['partial_entry']['user_agent'] ?? '';
$current_user_agent = isset( $_SERVER['HTTP_USER_AGENT'] )
? sanitize_text_field( wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) )
: '';
🤖 Prompt for AI Agents
In gravity-forms/gw-draft-resume-change-notice.php around lines 40 to 41, the
current User-Agent from $_SERVER['HTTP_USER_AGENT'] is used raw for comparison;
sanitize it before use by passing the value through sanitize_text_field() (e.g.,
assign $current_user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] ??
'' );) so comparisons use a sanitized string while leaving the stored_user_agent
unchanged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant