New class added to the template theme: ACF-Handler!

There’s a new class in town called the ACF_Handler! It exists to do one thing: make registering ACF fields across environments less of a pain.

Check it out on Github

What it does

According to ACF’s docs, this small collection of filters allows ACF to store fields, post types, options pages and taxonomy registrations with JSON files, and (more importantly) loads the fields from the JSON files as well. This speeds up page speed loading for our content team and reduces database calls on the server (which is a performance win for everyone).

Getting Started

If you’ve got a theme with some version of class-theme-init.php, simply add it to the array in the load_required_files method and include the class name as the value.

$utility_files = array(
			'allow-svg'             => 'Allow_SVG',
			'role-editor'           => 'Role_Editor',
			'gravity-forms-handler' => null,
			'bootstrap-pagination'  => null,
			'post-override'         => null,
			'acf-handler'           => 'ACF_Handler',

		);

Otherwise, require the file and instantiate the class in the theme-functions.php file.

Make sure you add the file into the inc/theme folder first! It should be named class-acf-handler.php

How it works

All you really need to do in order to make it work is save an ACF field in the ACF panel! You’ll then notice that a new json file is added to the appropriate sub-directory.

A new column should also appear next to the rest of the fields/post types/taxonomies/options.

As you merge branches and make changes, ACF will now handle the field edits and registrations across the environments.

You’ll still need to update the fields’ values manually, but at least this way you don’t have to download/upload json fields manually across all the environments!

See something inaccurate?