2017 © Pedro Peláez
 

composer-plugin wp-downloader

A Composer plugin that downloads WordPress releases zip from official repo.

image

wecodemore/wp-downloader

A Composer plugin that downloads WordPress releases zip from official repo.

  • Monday, May 15, 2017
  • by gmazzap
  • Repository
  • 6 Watchers
  • 7 Stars
  • 121 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

wp-downloader

A Composer plugin that provides a zero effort way to solve a very specific issue for a very specific edge case: install WordPress plugins and themes, with Composer, inside WordPress /wp-content folder., (*1)


Why?

By using Composer to manage both WordPress core and plugins/themes and at same time to tell Composer to put plugins and themes inside WordPress default /wp-content folder is just not possible without issues., (*2)

Because, in short, every time WordPress is installed or updated, the whole WordPress folder (so including /wp-content dir) is deleted and so plugins and themes packages inside it are lost., (*3)

I have explored different ways to solve this issue, but it seems that the most simple way is just to avoid to treat WordPress as a regular Composer package, because - guess what - it is not a regular Composer package., (*4)

Thanks to many people effort, nowadays we have ways to use Composer to manage entire WordPress websites that works in the large majority of the cases., (*5)

This plugin comes for that specific case that does not belong to that "large majority". But:, (*6)

  • it is not designed as a "general usage" WordPress installer for Composer
  • it does not take into consideration (nor it will to take) other edge cases that is possible to encounter in all the crazy setups out there.

How it works?

WordPress will be downloaded from zip releases available at wordpress.org and unzipped in a folder of choice., (*7)

When Composer is ran to update WordPress, old installation files are deleted, but /wp-content dir and wp-config.php (if found in WP root folder) are not touched., (*8)

If Composer is setup to place plugins and themes inside /wp-content, they will be updated when needed, by Composer., (*9)


Usage

In the root composer.json require wecodemore/wp-downloader., (*10)

That's it., (*11)

There are few optional configurations, explained below., (*12)


Configuration

The plugin supports a wp-downloader object in composer.json (to be placed inside extra object in root package) that allows to configure:, (*13)

  • the WordPress target path
  • the WordPress desired version
  • if to download the "no content" version of WordPress archive or the full version

An example:, (*14)

{
  "name": "you/your-awesome-website",
  "type": "project",
  "require": {
    "wecodemore/wp-downloader": "^1.0"
  },
  "extra": {
    "wp-downloader": {
      "version": ">=4.5",
      "no-content": true,
      "target-dir": "public/wp"
    }
  }
}

None of the settings above are mandatory, in fact the wp-downloader object could not be there at all., (*15)

All settings have defaults and both target dir and WordPress version may be set in a different way., (*16)

Configure WordPress installation path

As you can see above, the target path can be set via the extra.wp-downloader.target-dir setting., (*17)

However, the plugin also supports the path to be set in extra.wordpress-install-dir (used, for example, also by johnpbloch/wordpress-core-installer)., (*18)

So if that settings is used, the path in there will be used, unless it is overridden by putting a different path in extra.wp-downloader.target-dir., (*19)

Configure WordPress version

In the example above, the WordPress version to download is set using extra.wp-downloader.version config., (*20)

You can put there anything that Composer understands., (*21)

Well, not really anything because this package only work with stable versions., (*22)

Additionally, it is possible to use the keyword latest that, as you can guess, will download the latest version of WordPress., (*23)

There's also another way to setup the WordPress version to download., (*24)

If the root composer.json requires any package of the type wordpress-core, the version used in that requirement will be "discovered" and used by this plugin., (*25)

For example, if a composer.json contains:, (*26)

{
  "name": "you/your-awesome-website",
  "type": "project",
  "require": {
    "wecodemore/wp-downloader": "^1.0",
    "johnpbloch/wordpress": ">=4.6"
  },
  "extra": {
    "wordpress-install-dir": "public/wp"
  }
}

wp-downloader will read the version of johnpbloch/wordpress and will download a version compatible with the requirements of that package (in example above the version 4.6 or higher)., (*27)

This works only if a WordPress core package is required in the root composer.json: core packages required as secondary dependencies will not be read, and if no version is provided (neither by package nor via wp-downloader object) the latest WordPress version will be downloaded., (*28)

Also note that using example above the WP installation folder will be public/wp, being it read from the wordpress-install-dir setting., (*29)

Please note: using a composer.json like the one right above will not install WordPress from the required package (johnpbloch/wordpress)., (*30)

In fact, wp-downloader prevents packages of type wordpress-core to be installed by Composer, or the unique reason to exists of this plugin would be defeated., (*31)

No-content setting

By default wp-downloader downloads the "no-content" version of WordPress archives., (*32)

This is usually fine when using Composer to manage the entire website, as the themes and plugins are pulled with Composer., (*33)

However, if someone wants to use a default theme, it needs to be pulled separately using Composer, or maybe, wp-downloader can be instructed to download a full WordPress archive of by setting extra.wp-downloader.no-content setting to false., (*34)


Gotchas

Even if wp-downloader could be used when WP plugins and themes are placed outside of WordPress folder, there's actually no benefit on using it in those cases., (*35)

Usage of this plugin is suggested only when plugins and themes really need to be inside WordPress folder., (*36)

Main plugin gotchas are:, (*37)

  • Downloaded WordPress zips does not go into Composer cache, so it needs to be downloaded from the repo anytime is needed.
  • Not being a Composer package, WordPress version is not written into the composer.lock file. So the only way to do ensure exact same WP version among servers is to use an exact version requirement.
  • This package does not work with trunk or WordPress development versions. If you need to develop for WordPress core or test things against trunk, and you want to use Composer... then use Composer, and not this plugin, to download WordPress.

FAQ

How do I tell Composer to place my plugin / themes inside WordPress /wp-content folder?, (*38)

  • That's something that does not depends on this plugin. Change the path of specific plugin themes is something provided by an official Composer plugin named "Composer installers". It can be installed by requiring "composer/installers" and it needs an "installer-paths" setting in composer.json. See plugin docs

I required this plugin, now the website show just WSOD!, (*39)

  • By default this plugin downloads the "no content" version of WordPress archive. It means that no default themes are downloaded. If you use a default theme (or maybe a child theme of one of them), you won't be able to see the frontend of the website. See "No-content setting" section above.

Do you wish to support [insert crazy edge case here]?, (*40)

  • No, I don't.

Do you wish to implement [feature here]?, (*41)

  • Probably no.

I found a bug, can you fix it?, (*42)

  • I can, but no warranty on when. Consider that contributions are welcome and PR open.

I used a fixed required version for WP and it does not work. Why?, (*43)

  • Check that the URL https://downloads.wordpress.org/release/wordpress-{$version}-no-content.zip is there. If it is not, but https://downloads.wordpress.org/release/wordpress-{$version}.zip is, then set no-content setting to false.

The package [package here] I am using requires WordPress package, but the plugin does not auto-discover which WP version to download, and always download latest version., (*44)

  • This plugin auto-discovers WordPress version from required WordPress packages that are required only from root composer.json. If WordPress is required from a package you require, that won't work.

Does this work with WP Starter?, (*45)

  • Yes, it does.

License

MIT., (*46)

The Versions

15/05 2017

dev-master

9999999-dev

A Composer plugin that downloads WordPress releases zip from official repo.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • composer-plugin-api ^1.1

 

15/05 2017

1.1.0

1.1.0.0

A Composer plugin that downloads WordPress releases zip from official repo.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • composer-plugin-api ^1.1

 

30/09 2016

1.0.0

1.0.0.0

A Composer plugin that downloads WordPress releases zip from official repo.

  Sources   Download

MIT

The Requires

  • php >=5.4
  • composer-plugin-api ^1.1