Skip to content

ACF Integration – WordPress Plugin Boilerplate

This integration provides patterns for working with Advanced Custom Fields (ACF) in your WordPress plugin.

All ACF field group JSON files should be stored in acf-json/ at the plugin root level. This enables version control of your field groups and automatic synchronization across environments.

  1. Create the acf-json directory at the plugin root
  2. Add the following code to your load_dependencies() method in the main Demo_Plugin class

The code examples are based on ACF’s documentation for local JSON.

src/Demo_Plugin.php
/**
* Load the required dependencies for this plugin.
*
* @since 1.0.0
* @access private
*/
private function load_dependencies(): void {
$this->loader = new Loader();
// ACF JSON Support
add_filter(
'acf/settings/save_json',
function () {
if ( wp_get_environment_type() !== 'production' ) {
return DEMO_PLUGIN_PATH . 'acf-json';
}
return '';
}
);
add_filter(
'acf/settings/load_json',
function ( $paths ) {
$paths[] = DEMO_PLUGIN_PATH . 'acf-json';
return $paths;
}
);
}
  • JSON files should be committed to your repository so field groups sync across environments
  • Disable saving in production to prevent accidental field group modifications
  • Use separate classes for complex integrations to keep your main plugin class clean
  • PHP67%
  • JavaScript33%