Roots Discourse

Advanced Custom Fields with composer


#1

HI Guys!

Very new to Sage so i apologise, I have edited my composer.json file to have the following:

And when I run a composer update , the wp-content folder pops into the Root dir:

Is this right? When I go into the wp-admin I can’t find it.

Can some one help me out? I also tried adding in a setting for it in my app/helpers.php with the following:
//add_filter('wp-content/plugins/advanced-custom-fields/settings/show_admin', '__return_false');
So i can hide it in the admin when I want to put it live…


#2

You want to install ACF free or PRO?

For using wpackagist repository you just have to declare it once,
then you can require with the wpackagist-plugin/ prefix.

For ACF free (wpackagist):

{
  [...]
  "repositories": [
    {
      "type": "composer",
      "url": "https://wpackagist.org"
    }
  ],
  "require": {
    [...]
    "wpackagist-plugin/advanced-custom-fields": "4.4.11"
  }
}

Include Advanced Custom Fields in Sage 9
#3

You can’t use the composer.json file in the theme for this. You need to use something like Bedrock if you want to manage WordPress plugins via Composer


#4

If you need something like ACF and are insistent on it being a theme dependency, Carbon Fields offers a lot of the same functionality and can be included through your theme’s composer.json.

See: https://carbonfields.net/docs/carbon-fields-quickstart/


#5

Thanks for all your help guys! will work in the Bedrock install :slight_smile:


#6

Carbon Fields looks great, are you using it?

Tempted to switch from ACF.


#7

I used it on a couple projects, although I’ve gone back to using ACF lately, partly because it’s what everyone else at the agency where I work uses. It works on a slightly different paradigm, and isn’t quite as “plug-and-play” as ACF, but it’s very flexible and pretty nice to work with once you get the hang of it. The biggest thing I missed from ACF when I was using it was “flexible” fields, which it didn’t really have an analog for at the time. I’d recommend checking it out, though.


#8

Yeah, I’ve used the ACF flexible fields a few times but have gone off using them now.

I decided that the main content is best off stored in the content field as much as possible. For now I’m keeping things simple.

I do use repeater fields occasionally but seeing as Carbon has those, I’m going to dive in.


#9

I use this: https://github.com/PhilippBaschke/acf-pro-installer
Which downloads ACF in my theme dir, then with build script I copy ACF to ‘/lib/acf’ dir in my theme folder and I load ACF from there.
Works well for me this way.


#10

Carbon Fields has both repeater & flexible content fields, they are called ‘complex fields’. CF has just about everything ACF does and is way more efficient to work with.


#11
...
"repositories":[
 {
 "type":"composer",
 "url":"https://wpackagist.org"
 }
],
"require": {
 "php": ">=7.1",
 "johnpbloch/wordpress": "^4.9",
 "wpackagist-plugin/advanced-custom-fields": "5.6.7"
},
"extra": {
 "installer-paths": {
 "wordpress/wp-content/plugins/{$name}": ["wpackagist-plugin/advanced-custom-fields"]
 }
},
...