Skip to content

Instantly share code, notes, and snippets.

@nathan-roberts
Created November 8, 2023 23:27
Show Gist options
  • Save nathan-roberts/ad9f984bf421edb3657ff7cc171f3f2c to your computer and use it in GitHub Desktop.
Save nathan-roberts/ad9f984bf421edb3657ff7cc171f3f2c to your computer and use it in GitHub Desktop.
ACF JSON - Save Specific Groups within Plugin
// Save ACF JSON for specific field groups only
add_filter('acf/update_field_group', 'hof_acf_json_save_for_specific_groups', 10, 1);
function hof_acf_json_save_for_specific_groups($field_group)
{
// Define your allowed field groups
$allowed_field_groups = array('group_650da9580c565'); // Replace with your actual field group keys
// Check if the current field group is allowed
if (in_array($field_group['key'], $allowed_field_groups)) {
// Set the save path only for allowed field groups
add_filter('acf/settings/save_json', 'hof_acf_json_save_point');
}
return $field_group;
}
// Custom save point for ACF JSON
function hof_acf_json_save_point($path)
{
// update path
$path = plugin_dir_path(__FILE__) . 'acf-json';
// return
return $path;
}
// Load ACF JSON for specific field groups only
add_filter('acf/settings/load_json', 'hof_acf_json_load_point');
function hof_acf_json_load_point($paths)
{
// Your custom load logic here if needed
$paths[] = plugin_dir_path(__FILE__) . 'acf-json';
return $paths;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment