ACF Pro as a Composer dependency (without committing your license key unencrypted)

So it SHOULD be putting its plugin files in the site/web/app/plugins directory, not the theme directory. Can you confirm that the plugin files are not in the plugins directory?

If not, can you try a composer clear-cache, rm -rf vendor, and composer install from inside your site directory?

If that still doesn’t put Advanced Custom Fields into your plugins directory you might try a fresh Trellis install just to make sure nothing is weird about this one.

On a side note, I prefer JSON for ACF, and I actually maintain a library for keeping ACF JSON with Sage 9. The advantage for me is that I can use the ACF GUI to build fields and then commit them to version control without the additional step of exporting them to PHP.

So it SHOULD be putting its plugin files in the site/web/app/plugins directory, not the theme directory. Can you confirm that the plugin files are not in the plugins directory?

It’s putting the plugin files in the site/vendor directory.

If not, can you try a composer clear-cache, rm -rf vendor, and composer install from inside your site directory?

I’ve just done this. It’s still putting the files in the site/vendor directory and not the plugins directory.

I’ll have to try the fresh Trellis install later today and will report back.

Thanks again!

I’ve tried with a fresh Trellis install and the same things happens, plugin files go in the site/vendor directory.

Are you sure I shouldn’t be adding the ACF dependency into the theme’s composer.json? This would make sense to me. Isn’t it being added into site/vendor because I’m adding the dependency into the site’s composer.json?

I’m assuming that you’re using Bedrock, and that this isn’t your entire composer.json? You need to make sure that Bedrock’s composer.json (the one in /site) contains the following:

"extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "web/wp"
},

When Composer installs a dependency, by default it puts it in the vendor folder. This can be customized if the dependency requires composer/installers. The line in your composer.json that looks like this:

"web/app/plugins/{$name}/": ["type:wordpress-plugin"],

…tells Composer that if it encounters a dependency with the type wordpress-plugin while installing, it should not put that dependency in vendor, and should in fact put it in web/app/plugins/[name-of-the-dependency]. This is what allows us to use Composer to manage WordPress plugins.

If that’s not happening, one of the following things is happening:

  1. You’re using the wrong composer.json.
  2. Your composer.json does not have the about extras section with custom install paths.
  3. The dependency you’re trying to install does not properly declare itself with type: wordpress-plugin.

It can be easy to confuse the two major composer.json files used with Bedrock/Sage. I usually remember them this way:

  • site/composer.json - These are Bedrock’s dependencies, which means they are dependencies for your site, not your theme. Site dependencies are things like plugins, or mu-plugins.
  • site/web/app/themese/[theme-name]/composer.json - These are Sage’s dependencies, which means they are dependencies for your theme, not your site. Theme dependencies are things like soberwp/controller. They are not plugins.
1 Like

Hi,

Thank you, that’s really helpful.

Yes, I’m using Bedrock. My entire site/composer.json that I’ve used in my fresh Trellis install is:

{
  "name": "roots/bedrock",
  "type": "project",
  "license": "MIT",
  "description": "WordPress boilerplate with modern development tools, easier configuration, and an improved folder structure",
  "homepage": "https://roots.io/bedrock/",
  "authors": [
    {
      "name": "Scott Walkinshaw",
      "email": "scott.walkinshaw@gmail.com",
      "homepage": "https://github.com/swalkinshaw"
    },
    {
      "name": "Ben Word",
      "email": "ben@benword.com",
      "homepage": "https://github.com/retlehs"
    }
  ],
  "keywords": [
    "bedrock", "roots", "wordpress", "stack", "composer", "vagrant", "wp"
  ],
  "support": {
    "issues": "https://github.com/roots/bedrock/issues",
    "forum": "https://discourse.roots.io/category/bedrock"
  },
  "config": {
    "preferred-install": "dist"
  },
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": "advanced-custom-fields/advanced-custom-fields-pro",
      "version": "5.7.0",
      "type": "wordpress-muplugin",
      "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"
      }
    }
  ],
  "require": {
    "php": ">=5.6",
    "composer/installers": "^1.4",
    "vlucas/phpdotenv": "^2.0.1",
    "johnpbloch/wordpress": "4.9.7",
    "oscarotero/env": "^1.1.0",
    "roots/wp-password-bcrypt": "1.0.0",
    "roots/soil": "^3.7",
    "johnbillion/extended-cpts": "^4.2",
    "advanced-custom-fields/advanced-custom-fields-pro": "*",
    "wpackagist-plugin/imsanity": "^2.3",
    "wpackagist-plugin/ewww-image-optimizer": "^4.2",
    "wpackagist-plugin/redirection":"3.3.1",
    "wpackagist-plugin/google-sitemap-generator":"4.0.9"
  },
  "require-dev": {
    "squizlabs/php_codesniffer": "^3.0.2"
  },
  "extra": {
    "installer-paths": {
      "web/app/mu-plugins/{$name}/": ["type:wordpress-muplugin"],
      "web/app/plugins/{$name}/": ["type:wordpress-plugin"],
      "web/app/themes/{$name}/": ["type:wordpress-theme"]
    },
    "wordpress-install-dir": "web/wp"
  },
  "scripts": {
    "post-root-package-install": [
      "php -r \"copy('.env.example', '.env');\""
    ],
    "test": [
      "phpcs"
    ]
  }
}

The only difference between this composer.json and the one in my original Trellis install is that I’m trying to install ACF as a muplugin in this version rather than just a plugin.

It’s putting the ACF files in site/vendor and not web/app/mu-plugins.

Your custom repository is formatted incorrectly. You define type twice, so it’s probably ignoring the second one. It should be formatted like this:

  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    },
    {
      "type": "package",
      "package": {
         "package": "advanced-custom-fields/advanced-custom-fields-pro",
         "version": "5.7.0",
         "type": "wordpress-muplugin",
         "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"
         }
      }
    }
  ]

So you were running into issue #3 in my list.

1 Like

OMG, I have ACF installed in the plugins folder! :grinning:

I now have a 500 Internal Server Error instead but I can try to get to the bottom of this tomorrow.

Thank you so much for your infinite patience! I am trying to figure it out for myself but can get in so far and then can’t see the wood for the trees.

I’ve just re-run everything and no 500 Internal Server Error now. I’m so happy! Thank you again.

Bump.

Anyone getting an issue now with this installer because phpdotenv has been bumped to 3.0?

  Problem 1
    - philippbaschke/acf-pro-installer v1.0.2 requires vlucas/phpdotenv ^2.2 -> satisfiable by vlucas/phpdotenv[2.2.x-dev, 2.3.x-dev, 2.4.x-dev, 2.5.x-dev, 2.6.x-dev, v2.2.0, v2.2.1, v2.3.0, v2.4.0, v2.5.0, v2.5.1, v2.5.2, v2.6.0, v2.6.1] but these conflict with your requirements or minimum-stability.
    - philippbaschke/acf-pro-installer v1.0.1 requires vlucas/phpdotenv ^2.2 -> satisfiable by vlucas/phpdotenv[2.2.x-dev, 2.3.x-dev, 2.4.x-dev, 2.5.x-dev, 2.6.x-dev, v2.2.0, v2.2.1, v2.3.0, v2.4.0, v2.5.0, v2.5.1, v2.5.2, v2.6.0, v2.6.1] but these conflict with your requirements or minimum-stability.
    - philippbaschke/acf-pro-installer v1.0.0 requires vlucas/phpdotenv ^2.2 -> satisfiable by vlucas/phpdotenv[2.2.x-dev, 2.3.x-dev, 2.4.x-dev, 2.5.x-dev, 2.6.x-dev, v2.2.0, v2.2.1, v2.3.0, v2.4.0, v2.5.0, v2.5.1, v2.5.2, v2.6.0, v2.6.1] but these conflict with your requirements or minimum-stability.
    - advanced-custom-fields/advanced-custom-fields-pro 5.7.10 requires philippbaschke/acf-pro-installer ^1.0 -> satisfiable by philippbaschke/acf-pro-installer[v1.0.0, v1.0.1, v1.0.2].
    - Installation request for advanced-custom-fields/advanced-custom-fields-pro ^5.0.0 -> satisfiable by advanced-custom-fields/advanced-custom-fields-pro[5.7.10].
1 Like

Huh! Good catch. I’ll see if I can make a pull request for @philippbaschke today or tomorrow.

4 Likes

In the meantime this drop-in replacement could be used:

4 Likes

Hi!

Just chiming in here. I got tired of custom solutions for all different premium plugins i needed when developing WordPress with Bedrock. After some research i found Release Belt, nice way to setup an own private Composer repo. I wrote up a tutorial about it in a blog post if anyone is interested, a way to not only handle ACF, but all premium plugins.

Best regards
Samuel Horn

This means having a zip file for each version yeah? To me that doesn’t seem to alleviate the pain point of logging in to each premium plugin’s “my account” page and downloading the latest version. SatisPress works much better imo. I wrote about it.

I am a bit confused as I assumed that adding env variables in #trellis to /group_vars/all/vault.yml such as

vault_wordpress_sites:
  example.com:
    env:
      ACF_PRO_KEY: A-UNIQUE-KEY-AJHDIUHDW/Z/(ADIHDSAJK

would add the key to the .env at provision as it does for the environment specific vault.yml.
Just tried it for a couple of times but the variables from /group_vars/all/vault.yml are not added to .env. Don’t you agree that this would be very useful, as you do not have to set the same variable three times for development, staging and production. Or do I someting wrong?

Cheers and best regards

You can use vault_wordpress_env_defaults (introduced by @TangRufus in https://github.com/roots/trellis/pull/1048)

2 Likes

Very useful hint! :slight_smile: Thanks!

I followed the guide > ACF Pro as a Composer dependency (without committing your license key unencrypted) - trellis - Roots Discourse on my staging environment ACF Pro is installed without problems when I deploy, but on my development environment I receive this error when I run composer update

[FFraenz\PrivateComposerInstaller\Exception\MissingEnvException]
  Can't resolve placeholder {%ACF_PRO_KEY}. Environment variable 'ACF_PRO_KEY' is not set.

I added the acf_pro_key: “xxxx” in the trellis/group_vars/development/vault.yml (as i did for the staging vault file) but on development environment it doesn’t work.

I suppose that the problem is this one:

how can i re-create my .env file in the development environment?

thanks

Run vagrant up --provision or just add it manually

thanks @Twansparant, it is ok now, I run vagrant reload --provision
I noted for the next time, thanks again :wink:

1 Like

Hello all,

I am excited to start working with Bedrock and came across this article. Very helpful but it assumes you are using Trellis. Is there an alternative approach for being able to use ACF Pro without Trellis? Thank you