WordPress Bedrock Advanced Custom Field as dependency

1k views Asked by At

I am setting up a WordPress site with BedRock and was thinking if there is a way to "require" the ACF plugin in my composer.

So the plan is to have clean and simple repo where you do a git pull and composer install and then everything gets installed (including plugins)

But I don't find any documentation on the ACF site on how to do this.

Is this even possible? lol

I found this package but it's for ACF Pro and I just need the free version.

https://github.com/PhilippBaschke/acf-pro-installer

If anyone has any experience with BedRock and can help me out that would be greatly appreciated :)

Many thanks in advance!

2

There are 2 answers

3
csknk On BEST ANSWER

If you add the wpackagist repository to Composer's "repositories", you can then require the ACF free version.

In Bedrock's composer.json add the wp-packagist repo:

"repositories": [
    {
        "type": "composer",
        "url": "https://wpackagist.org"
    }
],
...

Then in the same file, require the plugin:

"require": {
    "php": ">=5.6",
    "composer/installers": "~1.0.12",
    "vlucas/phpdotenv": "^2.0.1",
    "johnpbloch/wordpress": "4.7.2",
    "oscarotero/env": "^1.0",
    "roots/wp-password-bcrypt": "1.0.0",
    "roots/soil": "3.7.1",
    "wpackagist-plugin/advanced-custom-fields" : "4.1.*"
},
...

Run composer update and it should fetch the plugin.

2
Marsellus On

Side note, the https://github.com/PhilippBaschke/acf-pro-installer tool is no longer supported and doesn't work with Composer 2 or ACF versions > 5.10.x

To fix the second issue with ACF versions, in src/ACFProInstaller/Plugin.php edit line 187 to:

$major_minor_patch_optional = '/\A\d\.\d{1,2}\.\d{1,2}(?:\.\d)?\Z/';

For Composer 2 compatibility, see https://github.com/pivvenit/acf-pro-installer and https://github.com/ffraenz/private-composer-installer are two options for replacements.

https://github.com/PhilippBaschke/acf-pro-installer/issues/44 describes the differences concisely.