Support

Account

Home Forums ACF PRO Save local-json file to load_json location

Helping

Save local-json file to load_json location

  • We use ACF across many of our sites, and have recently started using the Local JSON/Synced JSON functionality which has greatly improved our collaboration and efficiency when collaborating via git.

    We’re at the point now where we are migrating our custom plugin meta boxes to ACF field groups, and loading the JSON content via the acf/settings/load_json filter. Our issue is that it’s an arduous and error-prone process to make changes to these custom field groups once they’re saved in the individual plugin folders. Here’s our current process to update plugin field groups:

    1. Change private field to false in plugin JSON file
    2. Sync plugin JSON file to the database via JSON Sync
    3. Make changes to the Field Group, save changes
    4. Copy file from /theme/acf-json/ to /plugin/acf-json/, overwriting the previous version
    5. Delete file from /theme/acf-json
    6. Delete Field Group from database so someone doesn’t try to make changes and have them saved in the /theme/acf-json/
    7. Change private field to true in plugin JSON file

    What would make the process easier is if ACF would, when saving a local JSON file, check to see if the field group key exists in any of the load_json locations and save it directly there, rather than in the single save_json save point. This would eliminate the above steps 4, 5 and 6 from our workflow.

    I think this logic could be made to happen in advanced-custom-fields-pro/core/json.php in the acf_write_json_field_group function. Even if this functionality isn’t desired by default, passing the $path on line 194 through apply_filters like $path = apply_filters( 'acf/settings/pre_save_json', $path, $field_group ); would allow me to do the check myself and alter the save location dynamically if desired.

    My questions (finally, I know) are:

    • Does there already exist an option to do what I’m asking that I’m missing?
    • Could either the functionality by default or a pre_save_json filter be added to the plugin?
    • Is there any way for me to contribute to the plugin and submit this change as a pull request for review/feedback/eventual integration?

    Thanks much!

  • Hi @sblomberg

    If you want to use ACF in your project but doesn’t want it to be changed from the backend, I suggest you register the fields trough PHP code instead. That way the field group won’t shows up on the editor page so the other collaborator won’t accidentally changed it. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/register-fields-via-php/. It will be a little bit difficult when you need to modify it, though.

    If that doesn’t fit your needs, you can always submit a feature request by opening a new ticket here: https://support.advancedcustomfields.com/new-ticket. This will make sure that your request is passed directly to the plugin author.

    Thanks 🙂

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Save local-json file to load_json location’ is closed to new replies.