Support Log in

28. Local JSON Workflow

Developer Guide
Prefer video? Watch the Field Forge tutorials 8 short guides covering every feature Watch

Local JSON saves field group definitions as .json files in the uploads folder, enabling version control and cross-environment deployment. Available in the free plugin: FIELDFORGE_Local_JSON::is_enabled() checks the fieldforge_settings['local_json'] setting only, with no license check.

This is Field Forge’s own Local JSON format and uses wp-content/uploads/fieldforge-json/ by default. The ACF migration tool also understands ACF’s Local JSON source files from acf-json/group_*.json, so a site can import ACF field groups even when the acf-field-group and acf-field database posts are absent.

Setup

  1. Enable Local JSON in Field Forge > Settings.
  2. Save a field group: Field Forge creates wp-content/uploads/fieldforge-json/ by itself, with a .htaccess that denies direct access and an index.php.
  3. From then on a field group is written to this folder when it is saved, and its file is deleted when the group is deleted.

Field Forge writes only here. To keep the files in a theme or plugin repository, add that folder to the places it reads with the fieldforge/local_json/load_paths filter.

bash
wp-content/uploads/
  fieldforge-json/
    group_1_product-fields.json
    group_2_hero-section.json
    .htaccess          # Auto-created: "Deny from all"
    index.php          # Auto-created: silence

Bidirectional Sync

On admin load, Field Forge checks the JSON files against the database (at most once every five minutes) and shows a notice when they differ. Nothing is imported by itself:

  • JSON to DB: new or modified JSON files are imported into the database when you click Sync JSON → DB (the file wins).
  • DB to JSON: a field group is written to its JSON file whenever it is saved, and Sync DB → JSON writes all of them.

Deployment Workflow

text
Development          Staging              Production
-----------          -------              ----------
1. Edit field        3. git pull          5. git pull
   groups in UI      4. Visit admin,      6. Visit admin,
2. git commit           click Sync           click Sync
   fieldforge-json/     JSON -> DB           JSON -> DB

Programmatic Sync

php
// Force export all groups to JSON
$local_json = FIELDFORGE_Local_JSON::instance();
$count = $local_json->save_all();

// Check for differences
$diff = $local_json->get_diff();
// Returns: ['new_in_json' => [...], 'new_in_db' => [...], 'modified' => [...], 'in_sync' => [1, 3]]

// Run sync (JSON wins)
$result = $local_json->sync( 'json_to_db' );

// Run sync (DB wins)
$result = $local_json->sync( 'db_to_json' );

—

Forge AI Assistant Online

Hi! I'm the Field Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs