Json Force Sync

The Json Force Sync module allows developers to always keep Json files synchronized with the Field Groups in the database.

This new logic is particularly useful for developers working with version control since everytime a json file is updated, the changed are automatically saved in the database.

Enable the module

The Force Sync module is disabled by default. It can be enabled and disabled in the Settings UIPRO or with the following code:

// Using acf/init
add_action('acf/init', 'my_acfe_modules');
function my_acfe_modules(){

    // Enable Force Sync
    acf_update_setting('acfe/modules/force_sync', true);
    
}

// Or using acfe/init
add_action('acfe/init', 'my_acfe_modules');
function my_acfe_modules(){
    
    // Enable Force Sync
    acfe_update_setting('modules/force_sync', true);
    
}

Screen Rule

By default the synchronization will be triggered when a user visits the Admin Dashboard or the ACF Field Groups UI. This behavior can be changed using the acfe/modules/force_sync/rule hook. Usage example:

/*
 * Force Sync Screen Rule
 * 
 * @bool    $rule    Trigger field groups sync
 * @object  $screen  WP Current Screen Object
 */
filter('acfe/modules/force_sync/rule', $rule, $screen);
add_filter('acfe/modules/force_sync/rule', 'my_acfe_force_sync_screen', 10, 2);
function my_acfe_force_sync_screen($rule, $screen){

    // Enable on Dahboard, Posts List & Pages List
    if(acf_is_screen('dashboard', 'edit-post', 'edit-page'))
        return true;
    
    // Disable other rules
    return false;

}

Exclude Field Group

It is possible to exclude specific Field Groups from the automatic synchronization using the acfe/modules/force_sync/exclude hook. Usage example:

/*
 * Force Sync Exclude Field Group
 * 
 * @array  $exclude  List of excluded field groups keys
 */
filter('acfe/modules/force_sync/exclude', $exclude);
add_filter('acfe/modules/force_sync/exclude', 'my_acfe_force_sync_exclude');
function my_acfe_force_sync_exclude($exclude){

    // Exclude
    $exclude[] = 'group_608abf9d03cb3';
    
    return $exclude;

}

Manually Trigger Sync

Developers can manually trigger the Force Sync using the acfe_force_sync()helper. Please note that this function has to be called after the ACF & ACF Extended initialization. The init hook is a safe starting point.