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.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.