function mytheme_setup_options()
{
    if (function_exists('acf_add_local_field_group')) {
        $_FILES['acf_import_file'] = array('name' => 'fields.json', 'tmp_name' => get_template_directory() . '/fields.json');
        include_once get_stylesheet_directory() . '/plugins/advanced-custom-fields-pro/admin/settings-tools.php';
        $acfSettings = new acf_settings_tools();
        $acfSettings->import();
    }
}
Example #2
0
 /**
  * Use an ACF function to export field groups
  * @return null
  */
 public function export()
 {
     // include ACF file needed for export
     acf_include("admin/settings-tools.php");
     $tools = new \acf_settings_tools();
     // create post variable for ACF function
     $_POST["acf_export_keys"] = $this->getFieldGroupNames();
     $data = $tools->get_json();
     $this->saveConfig($data);
 }
Example #3
0
 /**
  * Search for ACF json exports with naming convention "acf-{name}.json"
  * Create field groups for matches
  * @return array Found/added field groups
  */
 public function importAcf()
 {
     $directory = new RecursiveDirectoryIterator(MODULARITY_PATH . 'source/acf-json/');
     $iterator = new RecursiveIteratorIterator($directory);
     $matches = new RegexIterator($iterator, '/acf-.+\\.json$/i', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
     $fieldgroups = array();
     $acfImport = new \acf_settings_tools();
     foreach ($matches as $path => $match) {
         $_FILES['acf_import_file'] = array('name' => $match[0][0], 'type' => 'application/json', 'size' => filesize($path), 'tmp_name' => $path);
         $acfImport->import();
     }
     unset($acfImport);
     return $fieldgroups;
 }