When I create new sites in WordPress I usually start of by installing Bedrock by Roots. This is a great development stack that makes it easier to manage dependencies while keeping a clear structure. However, I often use Advanced Custom Fields PRO which is not available on wpackagist.org as it is a paid plugin. So I made a search on Google and found the solution to add the package via Composer. Here is how to…
EDIT: You can also use this plugin https://github.com/PhilippBaschke/acf-pro-installer as an alternative to the below as per Philipps comment.
Add Advanced Custom Fields PRO to composer.json
Open composer.json and in the repositories array add the following object.
{ "type": "package", "package": { "name": "advanced-custom-fields/advanced-custom-fields-pro", "version": "5.3.9.2", "type": "wordpress-plugin", "dist": { "type": "zip", "url": "[REPLACE_WITH_YOUR_UNIQUE_URL]" } } }
You can find your unique URL on your account. Just copy the download link as shown below.
In composer.json you also want to add the following line to the require object
"advanced-custom-fields/advanced-custom-fields-pro": "^5.3.9.2"
Remember to match the version number.
Save the file and run composer install or composer update depending on your situation.
Upgrading to newer version
When I upgraded from Advanced Custom Fields PRO from version 5.3.8.1 to version 5.3.9.2 by updating the version in composer nothing really happened. It just installed the same outdated version. This seemed to be due to some caching issue with composer. So I had to go back to Google and see how this could be solved. It turns out that it was quite simple. Just run the following command to clear Composer’s local cache.
composer clear-cache
You might also have to go to your plugins folder and remove the Advanced Custom Fields PRO plugin before you run composer update again. This should install the correct version of Advanced Custom Fields PRO.
You could give my composer plugin (https://github.com/PhilippBaschke/acf-pro-installer) a try. You do not have to commit your license key this way. Some user even wrote an adaption if you use Trellis by Roots (https://discourse.roots.io/t/acf-pro-as-a-composer-dependency-without-committing-your-license-key/6690).
Hope you like it! 🙂
That works like a charm. I have added the solution to the article. Thanks.
Thanks for the article. I used your composer plugin (https://github.com/PhilippBaschke/acf-pro-installer) and installed it to the ./vendor. How do make this plugin from the vendor folder then? Thanks for your advise.
Extremely helpful! Thank you for publishing this.