Roots Discourse

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


#42

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.


#43

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!


#44

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?


#45

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.

#46

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.


#47

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.


#48

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.


#49

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


#50

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].

#51

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


#52

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