Including ACF Pro in fork of sage theme: where to store key?

I have a full Trellis/Bedrock/Sage setup, where I have forked the Sage theme to customize it to our needs.

The theme is so dependent on ACF Pro, that it makes more sense for me to include it in the theme. My first thought was that the theme composer.json might be able to read the .env file in the site directory but so far, I haven’t found a way to load that from a different folder.

Is my only other option to include the ACF code in my fork and manually update it in the fork anytime ?

Ideally id like to work out an env solution that doesn’t require me to bundle the code with the theme. Does anyone have any smart ideas on how I might do this?

For development I store the ACF PRO key in the .env file (WordPress roots.io Bedrock setup),
for production I store the ACF PRO in vault.yml (roots.io Trellis system).

For installing ACF PRO vis composer (independent from environment) I use
ffraenz/private-composer-installer.

I appreciate the reply, but I think you have missed my point.

I understand (and use often) the env file for the ACF key when bundling ACF pro in the site folder composer.json.

What I want to do, is move ACF from being a dependency of the Bedrock setup, to being a dependency of the theme itself. And the theme composer.json cannot reach back up to read the .env file in the site folder.

Do you want to sell the theme with ACF PRO (or bundle it)?
See this post from the ACF site:


Section How to include plugin files.

Yes, i have explored that, and thats easy to do, but not what im trying to achieve.

Ill try to clarify: I want to avoid bundling the acf plugin code in the repo itself, and would prefer to use composer to install, but inside the theme and not from the site folder.

Looks like i may have to just bundle it, or let bedrock handle it.

This would be a build step then. For trellis deploy, by default a deploy hook runs and invokes composer install for the bedrock site (composer.json with the plugins).
In your case with the theme you would also want to invoke composer install in the theme directory,
so you add an invocation to composer install to the deploy hook, but with the theme directory as cwd.

If your theme is never going to be used outside of the Roots stack, I’m not sure why it matters whether ACF is a dependency of your theme or your site. If your site is going to be used outside of the scope of the Roots stack, you have a different problem to solve in terms of where your key will be stored so you can either distribute or reliably deploy the theme.

AFAIK you should be able to put a .env file in your theme root and then use ffraenz/private-composer-installer in your theme as you would in your site. Obviously you don’t want to commit that .env to your theme, so if you’re deploying w/ Trellis you could use use deploy-hooks/build-before.yml to generate a new .env in your theme folder, ala:

- name: Create theme .env
  template:
    src: "{{ playbook_dir }}/deploy-hooks/.env.j2"
    dest: "{{ deploy_helper.new_release_path }}//web/app/themes/your-theme/.env"
    mode: "0600"

Another approach would be to fork ffraenz/private-composer-installer and point it to your site .env. Changing this would probably do it: https://github.com/ffraenz/private-composer-installer/blob/296dae1d51e826978008962fd6ece1612c2eaeb7/src/PrivateComposerInstaller/Plugin.php#L36-L39 It seems a little weird to me to have your theme dependency dependant on the existance of something (the .env) in the site, though.

This topic was automatically closed after 42 days. New replies are no longer allowed.