At a recent WordPress meetup we were discussing WP CLI and the comment came up, “When setting up a site, it would be nice to install a bunch of plugins with a single command.”
Fortunately a WordPress meetup is a great place to bounce ideas off of smart people and find a solution.
Solution 1: Using a Text File
The first solution we crafted was to use a text file with each plugin slug on a separate line, like the following.
plugin-slugs.txt
stop-emails
modify-comment-parent
simple-google-analytics-tracking
Then we could run the following, which would install and activate each plugin.
wp plugin install --activate $(<plugin-slugs.txt)
Solution 2: A Long Command
While using a text file for the slugs is a great solution, we realized it would be even nicer if we didn’t need a separate file. Instead we wanted to provide a single line, even if it is a long line, to install multiple plugins.
The following will install and activate the listed plugins.
wp plugin install --activate stop-emails modify-comment-parent simple-google-analytics-tracking
Edited Thanks to Tim’s comment, I’ve removed the extraneous echo
that appeared in an earlier version of this command.
xargs throws root warning
Interestingly, I would expect the following to work as well
echo stop-emails modify-comment-parent simple-google-analytics-tracking | xargs wp plugin install --activate
however, it does not. Instead it displays an error.
Error: YIKES! It looks like you’re running this as root. You probably meant to run this as the user that your WordPress install exists under.
We are able to avoid this error and run the command but we have to use the --allow-root
flag, which seems like poor form.
Do not use this command, instead please use Solution 2: A Long Command
echo stop-emails modify-comment-parent simple-google-analytics-tracking | xargs wp plugin install --activate --allow-root
Hey Sal, this is a super time saver that I use all the time. I always run the command without ‘echo’, like so:
wp plugin install stop-emails modify-comment-parent simple-google-analytics-tracking –activate.
Is there a benefit to running the command with $(echo)?
Wow that is a great point Tim – thank you. I’ve updated this post from the original
to your much improved
Thanks.
Love the updated long command solution. Copy & paste reduces the keystrokes completely. Thanks Sal & Tim.
Just had to follow up on this with today’s real world use case.
– ssh’ed into local by flywheel site in one command window
– ssh’ed into client website on GoDaddy in another command window
– arrange side by side command windows
– “wp plugin list” in each command window to see what is installed locally and on staging
– entered the “long command” and watched 15 plug’s get installed and activated while I sipped my coffee
#lifeisgood
Rock on! Nice work.
Hey Sal,
I absolutely love this! It took me too long to find this article, thanks heaps!
Is there a way for us to install plugins using WP CLI that aren’t listed in the WordPress Repository?
Hi Markus,
I’m glad this post was helpful.
Yes, you can install a plugin from a zip file using WP CLI.
Is it possible to install multiple plugins, each with a specified version in one command?
Not that I’m aware of. Since version is specified with `–version=`, I don’t see a way to provide more than one value.
If you figure something else out, I’d love to hear about it.