Skip to content

Fix File Upload sync for Gravity Forms 2.10+ JSON storage format#16

Open
curtismchale wants to merge 2 commits into
udx:latestfrom
proudcity:fix/gf-2.10-json-storage
Open

Fix File Upload sync for Gravity Forms 2.10+ JSON storage format#16
curtismchale wants to merge 2 commits into
udx:latestfrom
proudcity:fix/gf-2.10-json-storage

Conversation

@curtismchale

@curtismchale curtismchale commented Jun 3, 2026

Copy link
Copy Markdown

Fixes #15

Summary

  • Detect the File Upload field's stored shape from its value (JSON array vs raw string) instead of from $field->multipleFiles. GF 2.10+ stores single-file fields as a JSON array too, so the old branch never decoded them and strpos('gravity_forms/') failed on the JSON-escaped slashes — the GCS sync action was never fired and the URL was never rewritten.
  • Re-encode in the original shape, so older GF releases that still store single-file values as a plain string keep the same DB layout.
  • modify_db(): fix a re-encode bug where the JSON branch wrote wp_json_encode($value) (the original raw string) instead of wp_json_encode($result) (the rewritten array), which silently dropped the Sync-tab URL rewrites. Also tighten the JSON validity check to require an array so a json_decode'd scalar does not trip a PHP 8 warning on foreach.
  • Bump version to 0.0.4 and add changelog entries.

The post_image branch is unchanged — that field type uses GF's legacy |:|-delimited string and was not affected by the 2.10 storage change.

Validation

Verified against a live production site running Gravity Forms 2.10.2 with WP-Stateless. After deploying the fix, new File Upload submissions are uploaded to GCS and the entry meta is rewritten to the storage.googleapis.com/<bucket>/gravity_forms/... URL. The "view file" link on the Entries screen serves the file correctly. Pre-existing entries created before the fix still hold the local URL (expected — the save filter only fires on submission).

Test plan

  • GF 2.10+: submit a form with a single File Upload field; entry meta contains a storage.googleapis.com/... URL and the file exists in the bucket.
  • GF 2.10+: same with a multi-file File Upload field.
  • GF < 2.10: submit a single-file upload; the meta value is still a plain string (not wrapped in JSON) and the URL is rewritten.
  • Run WP-Stateless Compatibility Files Sync against an entry that has a pre-existing local URL and confirm the URL is rewritten in wp_gf_entry_meta.

GF 2.10.0.1 standardized the File Upload field storage so single-file
fields are now stored as a JSON array (one element, with escaped slashes)
matching multi-file fields. The previous code only json_decoded when
$field->multipleFiles was true, so single-file values were treated as a
raw URL string and strpos('gravity_forms/') failed on the escaped slashes.
The GCS sync and URL rewrite were silently skipped, leaving entry meta
pointing at the local wp-content URL.

- Detect the field's storage shape from the value itself (JSON array vs
  raw string) rather than from $field->multipleFiles. Normalize to an
  array, run the existing sync loop, re-encode in the original shape so
  older GF releases keep storing single-file values as a plain string.
- modify_db(): the JSON branch re-encoded the original $value instead of
  the rewritten $result, silently dropping URL rewrites from the
  Compatibility Files Sync tool. Tighten the JSON validity check to
  require an array so json_decode'd scalars don't trip a PHP 8 warning
  on foreach.
- Bump to 0.0.4 and update readme/changelog.

Refs udx#15
Copilot AI review requested due to automatic review settings June 3, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the plugin for Gravity Forms 2.10+ File Upload JSON storage changes and fixes an encoding bug in DB rewrite logic, along with version/readme/changelog bumps.

Changes:

  • Update File Upload value handling to detect JSON array storage shape (GF 2.10+) and re-encode consistently.
  • Fix modify_db() to re-encode the rewritten JSON array (and require decoded JSON to be an array).
  • Bump stable tag and update readme/changelog notes for release 0.0.4.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
readme.txt Bumps stable tag to 0.0.4, updates “Tested with” note, adds 0.0.4 changelog entry.
class-gravity-forms.php Adds GF 2.10+ JSON-shape detection for file upload values; fixes JSON decode/encode flow in modify_db().
changelog.txt Adds 0.0.4 release notes mirroring the readme.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread class-gravity-forms.php Outdated
Comment on lines 90 to 97
$decoded = is_string($value) ? json_decode($value, true) : null;
$was_json = is_array($decoded);

if ($was_json) {
$value = $decoded;
} else {
$value = array($value);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. Added an is_array($value) short-circuit at the top so a pre-decoded array input is treated as JSON-shape directly instead of being wrapped. Pushed in 6307706.

Comment thread readme.txt Outdated
= Notes =

* Tested with Gravity Forms plugin version 2.9.16.1
* Tested with Gravity Forms plugin version 2.10.x

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Fair — pinned to 2.10.2 (the version this fix was validated against on a live ProudCity site). 6307706.

Address PR review feedback on udx#16:
- gform_save_field_value(): if an upstream filter already decoded the value
  to an array, treat it as JSON-shape instead of nesting it inside another
  array. The inner loop's is_string() guard already prevented breakage, but
  this keeps the re-encoded output in the expected shape.
- readme.txt: replace the vague 2.10.x compatibility note with the version
  the fix was validated against (2.10.2).
curtismchale added a commit to proudcity/wp-stateless-gravity-forms-addon that referenced this pull request Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File Upload field values not synced to GCS under Gravity Forms 2.10+

2 participants