Roots Discourse

How to: Install Wordpress dropins to correct paths with Composer

#koodimonni/composer-dropin-installer
I built dropin installer to help install Wordpress translation files from http://languages.koodimonni.fi.

But I realised it can be used to install and to keep Wordpress dropins such as object-cache.php andsunrise.php up to date.

Notices:

  • All files inside package will be moved if you don’t specify anything after selector.
  • This works for mu-plugins as well but wpackagist is automatically using composer/installers for them and mu-plugins are already working in bedrock.

##How it works
The plugin hooks into post-install-package and post-update-package Composer events and moves selected files into correct paths.

##Syntax
This works like composer/installers. First define path where to install files and then use some selector (vendor,type,package) and after that single file (or comma separated list of files) to move from the installed package.

{
  "extra": {
    "dropin-paths": {
      "{relative/path/to/install/files}": [
        "package:{vendor/package-name}:file1,file2,dir/file3",
        "type:{any-valid-type}:example.php",
        "vendor:{any-vendor-but-please-be-specific-because-this-can-lead-to-madness}:your_file.php",
      ]
    }
  }
}

##Typical example:

{
  "repositories": [
      {
        "type": "composer",
        "url": "http://wpackagist.org"
      }
  ],
  "require": {
    "koodimonni/composer-dropin-installer": "*",

    "wpackagist-plugin/wp-redis": "*",
    "wpackagist-plugin/wordpress-mu-domain-mapping": "*"
  },
  "extra": {
    "installer-paths": {
      "htdocs/wp-content/plugins/{$name}": ["type:wordpress-plugin"],
      "htdocs/wp-content/themes/{$name}": ["type:wordpress-theme"],
      "htdocs/wp-content/mu-plugins/{$name}": ["type:wordpress-muplugin"]
    },
    "dropin-paths": {
      "htdocs/wp-content/": [
        "package:wpackagist-plugin/wp-redis:object-cache.php",
        "package:wpackagist-plugin/wordpress-mu-domain-mapping:sunrise.php"
      ]
    }
  }
}
1 Like

This looks great. I’m going to test it out since I’ve always been annoyed with the lack of integration between Composer and these “drop-ins”.