2

So I can cache a wordpress installation with:

wp core download --version=4.5 --path=/tmp/wp45

Subsequent requests of version 4.5 will be pulled from wp-cli local cache.

I think that:

wp plugin install query-monitor

will also be cached, but the command only works after a successful wordpress installation (e.g. after database setup, config file setup, wp install).

Is there a way to pre-cache plugins, just like a wp core download with out having to do the setup?

3

WP CLI already caches things without needing to use wp core download, that's why your wp core download command works. You can skip the extraction step entirely by just downloading WP directly into its cache folder, as well as any plugins

By default WP CLI will store any files it requests via HTTP in ~/.wp-cli/cache, that includes plugins and themes:

vagrant@vvv:/srv/www/wordpress-three/public_html$ wp plugin install wordpress-seo
Installing Yoast SEO (11.9)
Downloading installation package from https://downloads.wordpress.org/plugin/wordpress-seo.11.9.zip...
Unpacking the package...
Installing the plugin...
Plugin installed successfully.
Success: Installed 1 of 1 plugins.
vagrant@vvv:/srv/www/wordpress-three/public_html$ ls -al ~/.wp-cli/cache/
core/   plugin/ 
vagrant@vvv:/srv/www/wordpress-three/public_html$ ls -al ~/.wp-cli/cache/plugin/
total 3592
drwxrwxr-x 2 vagrant vagrant    4096 Aug 28 12:44 .
drwxr-xr-x 4 vagrant vagrant    4096 Aug 28 12:44 ..
-rw-rw-r-- 1 vagrant vagrant 3666701 Aug 28 12:44 wordpress-seo-11.9.zip
vagrant@vvv:/srv/www/wordpress-three/public_html$ 

So if I did this:

mkdir -p ~/.wp-cli/cache/plugin
wget https://downloads.wordpress.org/plugin/wordpress-seo.11.9.zip ~/.wp-cli/cache/plugin/wordpress-seo-11.9.zip

Then that would have the same effect, as would dropping wordpress-5.2.2-en_US.tar.gz in ~/.wp-cli/cache/core

Notice also that the filename WP CLI uses has - hyphens rather than the . that .org uses. Compare wordpress-seo.11.9.zip with wordpress-seo-11.9.zip

As for how to do it entirely with WP CLI, you would have to create a temporary WP install then change into it and install the plugin there, but it's easier to just download without extracting

  • As I suspected, no way to do it without wordpress already setup/installed prior to installing the plugin with wp-cli. Thank you for the alternative solution of manually inserting into the cache. Perfect! – farinspace Aug 28 at 14:14
  • 1
    Gotcha-1: downloads.wordpress.org uses a . separator between plugin-name and plugin-version, wordpress-seo.11.9.zip but wp-cli will use a - hyphen, wordpress-seo-11.9.zip, this means after download with wget or curl you will have to rename – farinspace Sep 5 at 9:50
  • 1
    Thanks, I've made a note of it in my answer – Tom J Nowell Sep 5 at 9:55
  • Gotcha-2: downloads.wordpress.org uses plugin-version only when a plugin has been tagged, so the following WILL NOT work: https://downloads.wordpress.org/plugin/fakerpress.0.4.11.zip, however, the master version WILL work https://downloads.wordpress.org/plugin/fakerpress.zip .. keep this in mind in case you can't get a particular plugin-version to download, additionally remember wp-cli always attaches a version number. – farinspace Sep 5 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.