Support

Account

Home Forums ACF PRO Installing ACF5 via Composer

Solving

Installing ACF5 via Composer

  • Our WordPress setup is based off Bedrock, which uses Composer to manage php dependencies, including plugins. I know this was talked about before:

    http://support.advancedcustomfields.com/forums/topic/composer-support/

    The upshot of this is that we can lock down plugins to a specific version. This is great for us and means we can always be certain the version in git will work (even if we don’t touch it for 9 months).

    The issue is that we are unable to bring in ACF pro via composer because it’s not in the WordPress Plugin directory. There is a work around / hack, but it uses the connect.advancedcustomfields.com url.

    https://gist.github.com/fThues/705da4c6574a4441b488

    This hack as 3 problems:

    • We have to commit our paid for licence key to our git repo, which we don’t want to do
    • There isn’t a tag for the latest version, so we can only ever get the 2nd newest version
    • The url is volatile to change (e.g. not versioned), so if anything changes to this url it could stop composer from updating the package

    Are there any plans or other work arounds for this?

    Some sort of versioned & documented API that lets you download a version would be an improvement. Ideally, ACF 5 would replace ACF 4 in the plugins directory and we can use composer to install it.

    • James

    • April 8, 2016 at 1:34 am

    Hi @adamtomat

    This is quite an important feature and the developer is well aware of it.

    Hopefully it should be possible soon 🙂

    • Bobz

    • April 15, 2016 at 9:52 pm

    +1 for composer 🙂

  • For anyone else landing here, looking to install ACF Pro via composer – check out acf-pro-installer.

    A good stop-gap until it gets supported out the box.

  • @adamtomat Thank you for promoting acf-pro-installer.

    If anyone has questions about it, feel free to ask them here. I will try to help you as good as I can 🙂

  • I had the license key added in a different way (not using dotENV).

    But I still don’t know what to do exactly when there’s a new version: which number should I change? the one specified in the version, one in the URL, or the one in the require?

  • It depends how you set everything up. I assume you have the following repository added:

    
    { 
      "type": "package", 
      "package": {  
        "name": "advanced-custom-fields/advanced-custom-fields-pro",
        "version": "5.4.1", 
        "type": "wordpress-plugin",
        "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"
        } 
      } 
    }
    

    Please notice that package.dist.url does not contain the version number (acf-pro-installer will add it automatically).

    You definitely need to update the package.version field to the new desired version.

    If you require an exact version like this:

    
    "require": {
        "advanced-custom-fields/advanced-custom-fields-pro": "5.4.1"
      }
    

    then you need to update the version there as well.

    If you just require any version like this:

    
    "require": {
        "advanced-custom-fields/advanced-custom-fields-pro": "*"
      }
    

    you can just leave it like this.

    ACF PRO should be updated when you run composer update now.

    Please let me know if you have any problems when you use this procedure. Please provide the content of your composer.json file to make debugging easier. 🙂

  • Thanks for making that helper @philippbaschke

    Super easy to install ACF now

  • Thank you @analogmemory. Glad you like it! ?

    • macxim

    • October 19, 2017 at 7:27 am

    Hi,

    This may be a dumb question but what about installing the basic version (not PRO) with Composer?

    Thanks

  • Not dumb at all! Since it’s in the WP plugin repo you can grab it from WordPress Packagist here. Or drop this into your composer.json file:

    "wpackagist-plugin/advanced-custom-fields": "5.6.3"

  • This case might help to implement composer for advanced custom fields pro:
    https://deliciousbrains.com/composer-premium-wordpress-plugins/

  • Dear ACF Support, any action on this? Would love to see something à la Delicious Brains.

    • hcj

    • August 4, 2018 at 9:06 am

    Note that some current problems may have arisen. Seemingly caused by the most recent Composer update: Github issue

  • @philippbaschke the installer works great when I install as "type": "wordpress-plugin", but the admin menu doesn’t show up when I install as "type": "library". It seems like it’s not autoloading and/or enabling.

    • pionect

    • October 22, 2018 at 7:47 pm

    I got a reply from Elliot on this topic 🙂

    Delicious brains did a fantastic job on integrating a premium plugin into composer. I remember when this blog post was first published and I was very impressed with their solution.

    Unfortunately, we don’t have a similar setup just yet, but this is definitely something I would like to address next year.

    Let’s keep our fingers crossed.

  • In case someone lands here, couple updates as of early 2019:

  • @bigskillet if you’re installing it as a “library”, it will be installed in vendor dir. The ACF plugin itself doesn’t utilize namespaces and autoloading so it’ll just sit there, doing nothing.

    It won’t be activated as a WordPress plugin, you need to load the library yourself and hook it into WordPress’ lifecycle + configure some internal ACF settings. You can do it in a form of plugin / mu-plugin or in functions.php. I prefer using muplugins_loaded hook instead of plugins_loaded to make sure ACF Pro is loaded before any plugins that rely on it:

    
    define( 'ACF_PATH', 'vendor/advanced-custom-fields/advanced-custom-fields-pro/' );
    define( 'ACF_ABSPATH', '/absolute/path/to/project/' . ACF_PATH );
    
    /**
     * Load ACF plugin as library managed by Composer.
     */
    function load_acf_library()
    {
        require_once ACF_ABSPATH . '/acf.php';
    }
    add_action( 'muplugins_loaded', 'load_acf_library' );
    
    /**
     * Configure ACF Settings in bulk.
     */
    function acf_settings()
    {
        // Absolute path to ACF plugin folder including trailing slash
        acf_update_setting( 'path', ACF_ABSPATH );
        // URL to ACF plugin folder including trailing slash
        acf_update_setting( 'dir', home_url( '/' ) . ACF_PATH );
    }
    add_filter( 'acf/init', 'acf_settings' );
    
  • Thank you for your response, @ihorvorotnov.

    Since I last posted, I’ve decided to not load plugins via Composer, since from what I understand, plugins are not updatable through the admin if they’re installed via Composer.

  • @bigskillet Well, yes and no. They are updatable, unless you’ve disabled plugin updates via wp-config constant or have incorrect user:group settings on the server. However, if you have an automated deployment routine that runs composer install – those admin updates will be overwritten.

    • Bobz

    • February 10, 2019 at 11:50 pm

    @ihorvorotnov Well, for some reason this ain’t working to me as you described.
    Like muplugins_loaded hook is never fired at all, I place a wrong path inside and no error.
    I also tried to ‘update_option(‘dummy’, 123)’, but that ain’t added to database either.
    It’s on my localhost and I have a WPMS installed, but can’t see a reason why this wouldn’t work.
    Any ideas?

  • @bobz I’m assuming WPMS means Multisite? Not a fan personally and not using it for years, but AFAIK it should work the same way, added once on a network level, activated for all sites. If muplugins_loaded doesn’t work for you for some reason, try plugins_loaded instead.

    However, muplugins_loaded should run. See here: https://core.trac.wordpress.org/browser/tags/5.0.3/src/wp-settings.php#L295

    Does you mu-plugin have a proper plugin header comment? If add_option() doesn’t work as well, I suspect your code isn’t running at all.

    • Bobz

    • February 11, 2019 at 2:00 am

    Right @ihorvorotnov I think problem is I’m including ACF in theme folder and trying to load it from there, but that’s too early. So the only proper way to load it from theme folder is if I install it as a ‘wordpress-plugin’.

    • alicam

    • February 11, 2019 at 9:24 am

    This is a little elaborate, but I’ve setup my own WP website as a composer repository using SatisPress:

    https://github.com/cedaro/satispress

    All my premium plugins – and I use a few – are installed and maintained there. Then I pull them down from there as standard composer packages to my own/client sites.

    I don’t have any security on that repository, but it’s an obscure URL and that’s good enough for me.

    It has proven an effective and easy way to do it.

    Who knew a WordPress site could double as a composer repo!?

    In the default SatisPress approach, a plugin that would normally be referenced in composer as:

    composer install wpackagist-plugin/advanced-custom-fields

    …is instead referenced as:

    composer install satispress/advanced-custom-fields-pro

    The SatisPress plugin lets you change that repo name if you so desire.

    All in all, reliable and great, because it’s one approach for all my premium plugins.

    FINALLY… one other benefit. I can create my own custom plugins for this and that, and also have them automatically available as composer packages, just by installing them on that WP site. Nothing more to do. No need to put them on a public composer repo.

    So I like it 🙂

Viewing 24 posts - 1 through 24 (of 24 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.