Convert PHP fields to JSON

No PHP field group configuration found. Nothing to convert.

'; return; } else { echo sprintf('

%d field groups will be converted from PHP to JSON configuration.

', count($groups)); echo 'Convert Field Groups'; } } /** * Convert the field groups and output the conversion page */ function admin_page_convert() { $groups = get_groups_to_convert(); echo sprintf('

Converting %d field groups from PHP to JSON configuration...

', count($groups)); echo '
    '; foreach ($groups as $group) { if (convert_group($group)) { echo sprintf('
  1. Converted: %s (%s)
  2. ', $group['title'], $group['key']); } else { echo sprintf('
  3. Failed to convert: %s (%s)
  4. ', $group['title'], $group['key']); } } echo '
'; echo '

Done. Now remove the PHP field group configuration.

'; } /** * Get the PHP field groups which will be converted. * * @return array */ function get_groups_to_convert() { $groups = acf_get_local_field_groups(); if (!$groups) return []; return array_filter($groups, function($group) { return $group['local'] == 'php'; }); } /** * Convert a field group to JSON * * @param array $group * @return bool */ function convert_group($group) { $group['fields'] = acf_get_local_fields($group['key']); return acf_write_json_field_group($group); }