Support

Account

Home Forums ACF PRO Manually trigger acf-json sync Reply To: Manually trigger acf-json sync

  • 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' );