Support

Account

Home Forums General Issues Load fields from PHP exported file by default Reply To: Load fields from PHP exported file by default

  • Here is my solution:

    /*****************************************************************/
    /* LOADING SWITCH FOR ACF FIELD GROUPS FROM PHP OR JSON FILE */
    /*****************************************************************/
    
    add_filter('acf/settings/load_json', function( $paths ) {
        
        $dev_mode = get_field('mode_custom_fields_json', 'option');
        
        // load basic [ MAIN THEME ] field groups from the [ MAIN THEME JSON ] folder
        $paths = array( get_template_directory() . '/inc/acf-json' );
        
        // load custom additional [ CHILD THEME ] field groups from the [ CHILD THEME JSON ] folder
        if( is_child_theme() && $dev_mode ) {
            $paths[] = get_stylesheet_directory() . '/acf-json';
        }
    
        // WITHOUT ACTIVATED DEV MODE --> load all fields from PHP file by the [ MAIN THEME ]
        if( ! $dev_mode ) {
            // load all field groups from PHP exported file for theme users
            include_once( get_template_directory() . '/inc/acf-field-groups.php' );
        }
    
        return $paths;
        
    });