Support

Account

Home Forums ACF PRO Manually trigger acf-json sync

Solving

Manually trigger acf-json sync

  • Hey, we are using ACF in a team with git on so many sites. With version 5.3.1 and this thread the sync was improved but it’s still not perfect we think.

    If one of our teammembers commit some changes, all others have to manually sync before make any new changes.

    For us it would be perfect if we could trigger this sync with a function like acf_json_sync() or something. There are some plugins out there but it feels dirty because they all just copy large code blocks from the ACF source code because there is no standalone ACF api function for doing this.

    With such a function we could trigger this sync on every git pull for example. Alternatively an auto-sync mode would be nice to don’t need to sync at all.

    Cheers,
    Phil

  • Did some digging around in the code and it appears that could try

    acf_import_field_group($group_key);

    This is what is called by ACF if you click sync manually.

  • No, this is just a small part of the import functionality. Here is one of many examples of how to manually sync. There is much more than just call acf_import_field_group(). But unfortunately it’s 95% copied code from the ACF source and this feels unprofessional for me.

  • I hadn’t seen that and I didn’t dig that far. The second thread you pointed out might be the only way right now. I will mark this thread for the developer to look at if he finds time to get here. Maybe he’ll make an addition of create a hook to trigger it.

  • That would be perfect and an extremely timesaver for us! Thank you very much!

  • This is working well for me, with the option to make the loaded fields editable or not:

    /* Default ACF fields */
    function my_default_acf_fields() {
    	if ( ! acf_get_field_groups() ) {
    		$acf_json_data = @file_get_contents ( MY_PLUGIN_DIR . 'vendor/acf-json/my-acf-groups.json' );
    		if ( $acf_json_data && $custom_fields = json_decode( $acf_json_data, true ) ) {
    			foreach ( $custom_fields as $custom_field ) {
    				acf_import_field_group( $custom_field ); // editable
    				// acf_add_local_field_group( $custom_field ); // not editable
    			}
    		}
    	}
    }
    add_action( 'acf/init', 'my_default_acf_fields' );
  • I’m also in need for this …
    Please tell us
    I’m not fan of hacking code to do this, not sustainable.

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

You must be logged in to reply to this topic.