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(); } }
/** * 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; }