• Bedrock
  • Trellis

ACF Pro as a Composer Dependency with Encrypted License Key

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.

Fortunately, 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 acf-pro-installer. I just adapted it for use with Trellis:

Add your ACF key to your vault.yml files

In each of your trellis/group_vars/[environment]/vault.yml files, add the acf_pro_key value:

# 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 project’s composer.json, add the ACF repository:

  ...
  "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:

  "require": {
    ...
    "advanced-custom-fields/advanced-custom-fields-pro": "^5.0.0",
    ...
  }

Update your Composer dependencies

Run the following from your site directory:

$ composer update

That’s it!

ACF should download and install itself.

Join the discussion on Roots Discourse

Join over 5,700 subscribers on our newsletter to get the latest Roots updates, along with occasional tips on building better WordPress sites.

Looking for WordPress plugin recommendations, the newest modern WordPress projects, and general web development tips and articles?

“Easily the best WordPress email I get.” Colin OBrien

Ready to checkout?