Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
Join us in building a kind, collaborative learning community via our updated Code of Conduct.

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.

15
votes
4answers
4k views

Running WP Cron on multisite the right way

I have WordPress Multisite with several sites. I set up DISABLE_WP_CRON to true in my wp-config.php. If we set up cron task with wget or curl we have 30 sec rule to execute PHP script. It's so small ...
13
votes
2answers
2k views

Detect if WP is running under WP-CLI

I use the wonderful WP-CLI tool. Due to dependence on Apache environment variables for a specific use case, I need to enable a bit of code to run only when running under WP-CLI. How can I detect if WP ...
12
votes
4answers
3k views

how to update serialized options programatically?

I want to automate updating plugin options. There are some things that I repeat a lot. With wp-cli I know I can update simple options like this: php wp-cli.phar option update blog_public 1 However, ...
10
votes
1answer
799 views

Fastest way (least amount of steps) to locally import a remote database using WP-CLI

I'd like to automate the task of importing a remote database using the WP-CLI. The current process is to ssh to the server, and run an export to file using WP-CLI, copy the file to a local directory ...
9
votes
1answer
785 views

Why is it important to deactivate a plugin before deleting it?

I stumbled across this page, where it says that wp plugin delete does this: Deletes plugin files without deactivating or uninstalling. Why is it important to deactivate a plugin before it is deleted? ...
8
votes
3answers
325 views

How I prevent a plugin to be loaded when doing WP-CLI?

I currently use this code in the main plugins file itself. But that plugin is not my own so I would prefer to be able to upgrade it normally without every time adding this code. if ( defined( 'WP_CLI'...
8
votes
4answers
2k views

Is there a drush equivalent for WordPress yet?

I'm working with Drupal on a project right now, and for all it's faults, having a commandline interface like drush to the Drupal framework is a godsend. Is there an equivalent for using Wordpress to ...
8
votes
2answers
8k views

How to change user password with wp-cli?

wp-cli is great. But it's not clear how I can quickly change a user password with it. How to change a user's password programatically can probably help to figure this out. Although wp user ...
8
votes
1answer
527 views

wp-cli 0.14.1 MySQL error

I just updated to wp-cli 0.14.1 today and once again having a MySQL issue. I'm on Windows, Wampserver, and Cygwin. When I first updated to the last rev (0.14.0) I had a similar problem and wound up ...
7
votes
4answers
2k views

WP-CLI Cannot Connect to Database due to Vagrant

I am running the most recent version of WP-CLI on my mac. I do all WordPress development within Vagrant, but would like to run WP-CLI commands in the host machine. I have a domain alias from "dev....
6
votes
1answer
1k views

Wordpress test environment on windows

I'm new to TDD and want to set up a test environment for my wordpress plugin. I was able to find a sample plugin from wp-cli with the very useful script. It was very easy to write the first test ...
5
votes
1answer
256 views

wp media regenerate unknown --image_size parameter

It is said in the documentation that we can set the --image_size parameter to regenerate all images for only this size. However, I am getting this for this command: Error: Parameter errors: unknown -...
5
votes
3answers
2k views

How to use command 'wp post create' in wp-cli properly?

I need to create a single post with title, content and excerpt with this command as it's described in the utility documentation. Could you please show me an example of how to use it? I couldn't find ...
5
votes
1answer
278 views

How to create a WP-CLI command with $_POST?

I would like to create a WP-CLI command for WordPress Database Reset plugin. In the main function it uses $_POST for the options but when running the command in cli they will not exist. How should ...
5
votes
2answers
404 views

Changing the WP CLI cache folder

As a highly concerned hosting company owner I am using WP-CLI to update plugins, themes and wp core of my clients. Updating WP-Core find /home/*/public_html -name "wp-admin" -execdir /home/wp core ...
5
votes
1answer
275 views

WP-CLI :: Cannot installing plugin as www-data

Just started using WP-CLI and instead of running with --allow-root, decided to run as www-data user. Things are good so far but cannot install any plugin that way at all: root@wp-ks320:/var/www/ks320#...
5
votes
1answer
350 views

WP-CLI not recognizing commercial plugin updates

I'm running into an issue I haven't encountered before where WP-CLI is not recognizing plugin updates for commercial plugins. The plugin updates appear in my WordPress dashboard, but running ../wp-...
4
votes
2answers
1k views

How to change user_login with wp-cli?

How to change the username with wp-cli? This does not work: wp user update old_login --user-login=new_login
4
votes
2answers
2k views

wp-cli Enabling Maintainance Mode

During theme or plugin upgrades, maintenance mode is enabled and then disabled once complete. Is it possible to manually enable / disable maintenance mode? Enabling Maintenance mode... Downloading ...
4
votes
1answer
2k views

How can I bulk delete media and attachments using WP-CLI?

I'm trying to mass delete 4000 images in a wordpress website. WP itself sets the max to 999, which would work fine and take a few minutes to delete them via the backend. However, I get REQUEST URI TOO ...
4
votes
3answers
109 views

Disable comment windows for all existing posts (pages/blogposts)

Is there a WP-CLI command to disable comment windows for all existing posts (pages/blogposts)? I ask this since when I change a theme for a site I have, all pages in that site getting their comment ...
4
votes
2answers
57 views

WPCLI - update plugins, themes, and core, all in one row, instead 3 rows?

Is there a way to update plugins, themes, and core, all in one row, instead 3 rows, in WPCLI? This is the current code I use in the crontab and that I'd like to improve: 0 0 * * * for dir in /var/...
4
votes
4answers
106 views

How do I setup a WordPress site on a server before the domain is ready?

I've completed my install using wp-cli. Right now the server is only available within my organization's VPN and the domain (say, foo.org) is being used by the existing (non-WordPress) site that will ...
4
votes
1answer
164 views

WP-CLI works on non WP-CLI installed Wordpress instance?

I came across WP-CLI via the tutorial at http://centminmod.com/nginx_configure_wordpress_ffpc_plugin.html and was wondering does WP-CLI work on Wordpress instances which were NOT initially installed ...
4
votes
1answer
1k views

How can I batch delete all unattached images with WP-CLI or other automated process?

After using WPML Media, a plugin that creates duplicates of each image for each language, we now have almost 100,000 duplicate images that we're not going to use and need to get rid of. We need to ...
4
votes
1answer
5k views

wp-cli doesn't find and wordpress installation

I wanted to try wp-cli, downloaded the phar and installed it by moving it to ~/bin which is in my path. Then wp --info works, but maybe shows insufficient information. (e.g. no php path, though it is ...
4
votes
1answer
28 views

What is the difference between the Package Language and the Site Language?

What is the difference between the Package Language and the Site Language? If I run: wp core language list I get: en_AU | English (Australia) | English (Australia) | active | available If I run: ...
4
votes
2answers
282 views

Unable to write test cases for a WordPress plugin using PHPUnit and WP-CLI

WordPress setup: Installed WordPress using VVV. PHPUnit setup: I have setup the testing suite as mentioned in Pippin's blog. And accessing PHPUnit after logging into the box machine by using vagrant ...
4
votes
3answers
2k views

wp-cli is not working properly. No response from commands

I am trying to make a copy of a live site on a test server. I installed wp-cli and wp-cli sometimes works and sometimes doesn't. When it doesn't work, it just returns nothing. Not one character of ...
4
votes
0answers
944 views

WP-CLI throwing PHP Fatal error: Call to undefined function apply_filters() [closed]

I have a migration script I'm using to copy my production environment to a dev server. Essentially it copies the files, exports/imports the MySQL database (using the wp db export and wp db import ...
4
votes
0answers
64 views

Wp-cli-ssh global installation problem [closed]

Global installation of wp-cli-ssh returns following error: $ composer global require x-team/wp-cli-ssh dev-master Changed current directory to /Users/name/.composer ./composer.json has been updated ...
3
votes
3answers
4k views

How to use wp-cli.yml file?

I am trying to set up a wp-cli.yml file but everytime I run the command, the file is ignored. Where should the file be located? And how should I call the command to use it? I tried having a file in ...
3
votes
2answers
376 views

Using Travis CI to run unit tests and running phpunit locally [closed]

Is there a difference between Travis CI running my PHPUnit tests and me using the WP-CLI to generate unit test files and running phpunit locally? I'm wondering if the duplicate effort is necessary or ...
3
votes
1answer
1k views

Using wp-cli to Update WP Networks / Multisite from 3.5.1 to 3.8

I've been handed a WP Networks site that is running WP (Networks) 3.5.1 on RHEL 5.8 with about 40 sites attached to it. I see the need to update to 3.8. By background, I'm more familiar with ...
3
votes
2answers
47 views

Revert WordPress default options after a PHPUnit test has run

tl;dr: is there a way to make changes to WordPress options during a PHPUnit test suite execution, and have the changes reverted to the WordPress defaults before the next test suite is executed, ...
3
votes
1answer
2k views

WP cli --path does not seem to work

WP-cli does not seem to work when adding a --path param me@host:~$ wp plugin status --path=`/home/me/domains/example.com/public_html` -bash: /home/me/domains/example.com/public_html: is a directory ...
3
votes
1answer
325 views

Listing posts with wp-cli

I use wp-cli to export some posts from my WordPress database. I'm trying to understand the differences in behavior that are exposed in the example below: $ wp post list --path=/var/www/home-web --...
3
votes
3answers
772 views

Is it possible just by using wp-cli to migrate one multisite instance to single site?

It took me great time today to convert one site from https://example.com to https://sub.example2.com from WordPress multiste installation to normal WordPress installation (read: singlesite). Since I ...
3
votes
3answers
4k views

wp-cli displays php notices when display errors off

I am using wp-cli and I am having php notices and errors show up when running wp-export. Some of these warnings and errors are ending up in the output file. How can I force errors to NOT show up. I ...
3
votes
1answer
117 views

WP-CLI alias: connect with ssh proxy

I have a wp-cli.yml file that defines an alias for a remote host: @origin: ssh: myserver.example.com path: /path/to/htdocs This would normally allow me to use wp @origin command to run remote ...
3
votes
1answer
1k views

Export WP database for import using WP-CLI on Vagrant Box

Problem Now that I have a new environment with WP-CLI db import / export I need to import a database from a website that never had WP-CLI installed. Question What's the best Non-WP-CLI export ...
3
votes
1answer
1k views

wp-cli with MAMP shows sh: mysql: command not found

I just installed wp-cli using homebrew and changed the PHP path in .bash_profile to below. export WP_CLI_PHP=/Applications/MAMP/bin/php/php5.6.10/bin/php export PATH=$PATH:/Applications/MAMP/Library/...
3
votes
2answers
1k views

How do I pass an array as an argument to a WP-CLI command?

I want to use WP-CLI to create some new posts with custom taxonomy terms assigned. The challenge is that wp_insert_post's tax_input argument only accepts arrays, which I would have to specify on the ...
3
votes
1answer
282 views

wp core update not working anymore

I have a strange issue. Trying to update core wp version from 4.7 to 4.7.2 but wp keeps saying I am already up to date. But when I run wp core version Then I see 4.7 and not 4.7.2 Any ideas on how ...
3
votes
1answer
229 views

Generate WP-CLI @alias for each site on multisite

I have a few multisites, each with several sites, that I want to auto-generate @aliases for. Is there way to sync those sites as aliases in my site list? I'd like to be able to target a single site ...
3
votes
0answers
189 views

Setting Up PHPUnit tests for WP development on Windows

I've been following the instructions in this article to try to set up some testing. I got as far as this instruction bash bin/install-wp-tests.sh wordpress_test root 'mypass' localhost latest before ...
3
votes
0answers
184 views

WP-CLI methods for get_current_blog_id, get_blog_details or $wpdb->prefix

I'm looking for some extra information about an mu site (--url) when attempting to export from a remote server to my local testing environment. One requirement for migration is the existing blog_id ...
3
votes
2answers
220 views

wp-cli: wp term generate xxxxx - Error: 'xxxxx' is not a registered taxonomy

I'm writing a WP CLI command which creates and updates taxonomies using wp_insert_term. Actions on my custom taxonomies are not accepted since they don't show up as registered. The wp-cli included ...
2
votes
3answers
1k views

WP-CLI - Selecting PHP version

On a development server I have a co-install of PHP 5.6 & 7; nginx is configured with PHP 5.6. When I type "wp" it returns several errors and at the end of the error is a message containing the ...
2
votes
1answer
522 views

How to update an 'array' option using wp-cli [duplicate]

I'm trying to write a bash script to automate the syncing of a live site to a dev site. I have the basics figured out, like exporting the production db and importing / updating urls in the dev site, ...