MacBook avec code sur un bureau

Install WordPress and plugins with Composer

Installing WordPress via Composer has often been difficult, fortunately there is now a solution!

WordPress

On GitHub there is a project that is updated every 15 minutes with the latest version of WordPress. It is also the most used. https://github.com/johnpbloch/wordpress

In the composer.json just indicate the project name. In this example, we can also indicate which folder WordPress will be installed in.

{
  "require":
    "php": "5.4"
    "johnpbloch/wordpress": "4.2"
  },
  "extra":
    "wordpress-install-dir": "wp"
  }
}

Then just use the Composer install command

composer install

Our “wp” folder now contains WordPress. Now when other plugins want to be installed, by default these end up in the /vendor folder. To install the plugins directly in the desired folder, we will have to get help from composer-installers.

This allows you to use package types and install them in the right place.

Composer Installers

composer-installs lets a package specify its type and a custom install location. They have a few types already included that we care about:

  • wordpress-plugin => wp-content/plugins/{$name}/
  • wordpress-theme => wp-content/themes/{$name}/
  • wordpress-muplugin => wp-content/mu-plugins/{$name}/

So any package with the “wordpress-plugin” type will automatically install in “wp-content/plugins/{$name}” by default.

WordPress Packagist

Outlandish has created a repository containing all WordPress plugins in composer mode. This is found under WordPress Packagist.

Just add the desired package to install the desired plugin.

{
"repositories": [
    {
      "type": "compose"
      "url": "http://wpackagist.org"
    }
  ],
  "require":
    "php": "5.4"
    "johnpbloch/wordpress": "4.2"
    "wpackagist-plugin/advanced-custom-fields": "O"
  },
  "extra":
    "wordpress-install-dir": "cms"
  }
}

except that…

The Plugins

The problem is that WordPress was previously installed in the cms folder. So we are going to have to rewrite that. To do it, we add an “extra” entry with the desired solution

{
"repositories": [
    {
      "type": "compose"
      "url": "http://wpackagist.org"
    }
  ],
  "require":
    "php": "5.4"
    "johnpbloch/wordpress": "4.2"
    "wpackagist-plugin/advanced-custom-fields": "O"
  },
  "extra":
    "wordpress-install-dir": "cms"
    "install-paths":
      "cms/wp-content/plugins/$name":["type:wordpress-plugin"]
    }
  }
}

So you will end up with the plugins installed in the right place and can activate them as you wish in the administration console

Leave a comment