function create_field($field)
 {
     // Find custom widget field group
     $field_group_class = new acf_field_group();
     $field_groups = $field_group_class->get_field_groups(array());
     $group = false;
     foreach ($field_groups as $field_group) {
         if ($field_group['title'] === $this->_custom_widget_title) {
             $group = $field_group;
             break;
         }
     }
     // Get Field Data
     $field_functions = new acf_field_functions();
     $group = $field_functions->load_field(false, CUSTOM_WIDGETS_FIELD_KEY, $group['id']);
     // Check if the group was found
     if (!$group) {
         echo 'No custom widgets group found.';
         return false;
     }
     // Get template data
     $widgets = $group['layouts'];
     $templates = $this->get_page_templates();
     // Display relationship container
     ob_start();
     require_once get_template_directory() . '/fields/templates/widget_template_relationship.php';
     $template = ob_get_contents();
     ob_end_clean();
     echo $template;
 }
    function create_options($field)
    {
        // defaults
        $field = array_merge($this->defaults, $field);
        // key is needed in the field names to correctly save the data
        $key = $field['name'];
        $value = isset($field['field_group']) ? $field['field_group'] : NULL;
        $field_groups = acf_field_group::get_field_groups(array());
        $field_group_choices = array();
        foreach ($field_groups as $field_group) {
            // we *don't* want to include this field group, that'd cause an infinite loop
            if (isset($_GET['post']) && $_GET['post'] == $field_group['id']) {
                continue;
            }
            $field_group_choices[$field_group['id']] = $field_group['title'];
        }
        // Create Field Options HTML
        ?>

		<tr class="field_option field_option_<?php 
        echo $this->name;
        ?>
">
			<td class="label">
				<label>Field Group</label>
				<p class="description">Select a field group in which to inherit fields from</p>
			</td>
			<td>
				<?php 
        do_action('acf/create_field', array('type' => 'select', 'name' => 'fields[' . $key . '][field_group_id]', 'required' => TRUE, 'choices' => $field_group_choices, 'value' => $field['field_group_id']));
        ?>
			</td>
		</tr>

		<?php 
    }
 function export($args, $assoc_args)
 {
     include 'bin/helpers.php';
     // if empty it will show export all fields
     $export_field = '';
     if (is_multisite()) {
         $choice = $this->select_blog();
         switch_to_blog($choice);
     }
     //if export all is used skip the question popup
     if (empty($args) || $args[0] != 'all') {
         $export_field = $this->select_acf_field();
     }
     if (empty($export_field)) {
         WP_CLI::success("Exporting all fieldgroups \n");
     } else {
         WP_CLI::success("Exporting fieldgroup: " . $choices[$choice] . " \n");
     }
     $field_groups = get_posts(array('numberposts' => -1, 'post_type' => 'acf', 'sort_column' => 'menu_order', 'order' => 'ASC', 'include' => $export_field));
     if ($field_groups) {
         if (substr(get_option('acf_version'), 0, 1) > 3) {
             $acf_fld_grp = new acf_field_group();
         } else {
             $acf = new Acf();
         }
         $path = get_stylesheet_directory() . '/field-groups/';
         if (!is_dir($path) && !mkdir($path, 0755, false)) {
             WP_CLI::line('fieldgroup directory exists or cant be created!');
         }
         foreach ($field_groups as $group) {
             $title = get_the_title($group->ID);
             $sanitized_title = sanitize_title($title);
             $subpath = $path . $sanitized_title;
             $uniquid_path = $subpath . '/uniqid';
             // retrieve the uniquid from the file if it exists else we make a new one
             $uniqid = file_exists($uniquid_path) ? file_get_contents($uniquid_path) : uniqid();
             if (substr(get_option('acf_version'), 0, 1) > 3) {
                 $field_group_array = array('id' => $uniqid, 'title' => $title, 'fields' => $acf_fld_grp->get_fields(array(), $group->ID), 'location' => $acf_fld_grp->get_location(array(), $group->ID), 'options' => $acf_fld_grp->get_options(array(), $group->ID), 'menu_order' => $group->menu_order);
             } else {
                 $field_group_array = array('id' => $uniqid, 'title' => $title, 'fields' => $acf->get_acf_fields($group->ID), 'location' => $acf->get_acf_location($group->ID), 'options' => $acf->get_acf_options($group->ID), 'menu_order' => $group->menu_order);
             }
             // each field_group gets it's own folder by field_group name
             if (!is_dir($subpath) && !mkdir($subpath, 0755, false)) {
                 WP_CLI::line('fieldgroup subdirectory exists or cant be created!');
             } else {
                 // let's write the array to a data.php file so it can be used later on
                 $fp = fopen($subpath . '/' . "data.php", "w");
                 $output = "<?php \n\$group = " . var_export($field_group_array, true) . ';';
                 fwrite($fp, $output);
                 fclose($fp);
                 // write the xml
                 include 'bin/xml_export.php';
                 // write the uniquid file if it doesn't exist
                 if (!file_exists($uniquid_path)) {
                     $fp = fopen($subpath . '/' . "uniqid", "w");
                     $output = $uniqid;
                     fwrite($fp, $output);
                     fclose($fp);
                 }
                 WP_CLI::success("Fieldgroup " . $title . " exported ");
             }
         }
     } else {
         //error seems to be returning and break out of my loop
         //WP_CLI::error( 'No field groups were found in the database' );
         echo 'No field groups were found in the database';
         echo ' ';
     }
     if (is_multisite()) {
         restore_current_blog();
     }
 }