Advanced Custom Fields Pro is one of the most useful WordPress plugins around but maintaining it as a dependency with Composer is a challenge without including your ACF license key unencrypted in your Git repository.
Fortuntely there’s a quick-and-easy way to include your license key in your (hopefully encrypted) Trellis vault.yml
file(s):
Full credit to PhillippBaschke who developed this composer repository. I just adapted it for use with Trellis:
Add your ACF key to your vault.yml
files
In each of your vault.yml
files, add the acf_pro_key
value:
trellis/group_vars/[environment]/vault
# Documentation: https://roots.io/trellis/docs/vault/
vault_mysql_root_password: devpw
# Variables to accompany `group_vars/development/wordpress_sites.yml`
# Note: the site name (`example.com`) must match up with the site name in the above file.
vault_wordpress_sites:
example.com:
admin_password: admin
env:
acf_pro_key: YOUR_KEY_HERE
db_password: example_dbpassword
IMPORTANT: Once this key is added, you must re-create your .env
file in each environment to include this new value. For remote environments, performing a deploy will accomplish this.
Add the ACF repository to your composer.json
In the repositories
section of your Bedrock or Trellis project’s composer.json
, add the ACF repository:
composer.json
...
"repositories": [
...
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
"version": "5.6.8",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
"url": "https://connect.advancedcustomfields.com/index.php?p=pro&a=download"
},
"require": {
"philippbaschke/acf-pro-installer": "^1.0",
"composer/installers": "^1.0"
}
}
}
...
]
...
Note: The version number above will be the maximum version number Composer will install.
Bonus: To install ACF as an mu-plugin, simply change "type": "wordpress-plugin"
to "type": "wordpress-muplugin"
Require Advanced Custom Fields
Still in composer.json
, add ACF to the require
section:
composer.json
"require": {
...
"advanced-custom-fields/advanced-custom-fields-pro": "^5.0.0",
...
}
Update your Composer dependencies
Run the following from your Trellis site
directory:
$ composer update
That’s it!
ACF should download and install itself.