Overview of Advanced Custom Fields on IBE
This covers specific information about how ACF is used on the IBE site. General information about ACF can be found in the ACF Documentation which is very good.
Advanced Custom Fields is used on the IBE site for a bunch of reasons:
Custom Post Types: It is used to add custom meta fields to custom post types.
The ACF data can be found in the /public/assets/acf folder of the custom post type plugin. In that folder, there is a PHP file that loads the fields and a JSON export that is needed when updating the fields.
Gutenberg Blocks: Some of the custom Gutenberg blocks on the site use the ACF blocks functionality.
IBE Flow Block
Impact Block
Theme: The PHP and JSON files for these fields can be found in understap/inc/acf. They are used for a few things:
Theme options including the alert bar settings.
Custom widgets used for the sidebars on custom post types.
How are the field groups stored?
Out of the box, ACF is built to store the field groups in the database. Obviously, that poses some challenges when you are developing a site with multiple environments. There are a couple options for solving this problem, the one that works best for multisite is registering the fields in PHP. (The other option is local json, but that would require touching every site when you make an update.)
What I have been doing is building the field groups in the dashboard (Custom Fields in the left side menu) and then exporting them to PHP and JSON. The PHP is put into a file which is loaded with the plugin/theme.
Saving the JSON makes it possible to re-import the field group into the database to edit in the future. It is also possible to edit the PHP directly, but then your JSON is out of sync, so I don’t recommend that. If you have a very small change, you could possibly manually edit both the JSON and the PHP file.
Process for updating a field group
Find the field group’s PHP and JSON in the code (see above).
Import the JSON field group into the site. (Custom Fields > Tools > Import)
Edit the field group.
You will now find your field group(s) in the list at Custom Fields > Field Groups.
Edit the Group and update the fields as required.
Export your updated field group.
Navigate to Custom Fields > Tools > Export.
Select the groups in your export. Note that some exports include multiple groups. Even if you only edited one group, you should export all the same groups that were in the import. (For example, the theme has multiple groups, one for each widget, etc, but they are all imported/exported together for convenience. Otherwise, I found it got really confusing.)
Select the Generate PHP button.
Copy the PHP over the old PHP in the PHP file with the field group load.
Back in the dashboard on the Export page, re-select the field groups you want to update and choose the Export File button.
Save the updated json file to the code base and delete the old json file.
Delete the field group from your database. To keep your local environment the same as other environments, delete the imported/edited field group from the field groups list in the dashboard. In general, there shouldn’t be any field groups in this list.