WP CLI
WP-CLI is a set of command-line tools for managing WordPress installations. You can update plugins, set up multisite installs and much more, without using a web browser. It is very handy, don't be afraid of the command line.
Requirements:
- UNIX-like environment (OS X, Linux, FreeBSD, Cygwin)
- PHP 5.3.2 or later
- WordPress 3.5.2 or later
Installing (and upgrading)
First, download wp-cli.phar using wget
or curl
. For example:
curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
Then, check if it works:
php wp-cli.phar --info
Output should be something like
PHP binary: /usr/bin/php
PHP version: 5.4.30
php.ini used:
WP-CLI root dir: phar://wp-cli.phar
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 0.18.0
To be able to type just wp
, instead of php wp-cli.phar
, you need to make the file executable and move it to somewhere in your PATH. For example:
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
Now try running wp --info
.
Upgrade using the same procedure.
MAMP
If you’re using MAMP, you will probably get a MySQL error, because the php
found in your PATH is not the same as the PHP used by MAMP. Add this to your .[bash_]profile (make sure the path is correct).
export MAMP_PHP=/Applications/MAMP/bin/php/phpx.x.x/bin
export PATH="$MAMP_PHP:$PATH"
If you get a mysql connection error Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
try executing this command sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock
Using
Go into a WordPress root folder:
cd /var/www/wp/
Typing wp
should show you output similar to this:
Available commands:
wp blog create|delete
wp cache add|decr|delete|flush|get|incr|replace|set|type
wp comment create|delete|trash|untrash|spam|unspam|approve|unapprove|count|status|last
wp core download|config|is-installed|install|install-network|version|update|update-db
wp db create|drop|reset|optimize|repair|connect|cli|query|export|import
wp eval-file
...
See 'wp help <command>' for more information on a specific command. Also check out the global parameters you can use for the commands, e.g. `wp plugin update --all` to update all plugins.
See all commands here: http://wp-cli.org/commands/ Also see the list of community commands.
Examples
Installing a plugin:
Let’s try to install the Hello Dolly plugin from wordpress.org and activate immediately after install:
wp plugin install hello-dolly --activate
Output:
```shell
Installing Hello Dolly (1.5)
Downloading install package from http://downloads.WordPress.org/plugin/hello-dolly.1.5.zip ...
Unpacking the package ...
Installing the plugin ...
Plugin installed successfully.
Update plugins:
Single plugin
wp plugin update hello-dolly
All plugins
wp plugin update --all
Add a new user and add capablities
# Add a new user with
wp user create redaktor [email protected] --role=editor --user_pass=pass --display_name=Redaktør --first_name=Kjell --last_name=Redaktør
# Add an extra capability for a the user - access the appearance menu (widgets, menu, ..)
wp user add-cap redaktor edit_theme_options
Relevant links:
- WP CLI commands
- Alternative Install Methods
- Getting Started with WP-CLI (includes video)