WP CLI - markhowellsmead/helpers GitHub Wiki
See Vagrant#wp-cli.
wp core download
wp core config --dbname=PROJECT_WP --dbuser=DATABASEUSER --prompt=dbpass --locale=de_CH
wp core install
If you get a socket error on the live server, first check that you're using the appropriate value for DB_HOST
.
define('DB_HOST', 'SERVERUSER.mysql.db.internal');
/** Tell WP-CLI to use TCP instead of socket connection */
if ( defined( 'WP_CLI' ) && WP_CLI ) {
define('DB_HOST', '127.0.0.1:3306');
} else {
define('DB_HOST', 'localhost:3306');
}
…to the local dev environment. Connect to the server via SSH and create a GZIP file of the database content.
wp db export - | gzip > ~/example.org.sql.gz
Exit SSH and download the file into the local webroot.
cd path/to/webroot/
scp -r [email protected]:~/example.org.sql.gz example.org.sql.gz
gunzip example.org.sql.gz
If you're running a Vagrant environment, vagrant ssh
into the VM and then navigate to the webroot. Otherwise, remain in the local webroot.
Then import the database file.
wp db import example.org.sql
Replace the live domain with the development domain by using wp search-replace
. This is an intelligent search-and-replace, so serialised data won't break.
wp search-replace example.org example.dev --dry-run
wp search-replace example.org example.dev
The same function, but for a multisite installation:
wp search-replace example.org example.dev --network
The same function, but with an SSL live site and a non-SSL development site:
wp search-replace https://example.org http://example.dev
The same but for a Multisite installation:
wp search-replace https://example.org http://example.dev --network
Convert a single domain in a Multisite installation to run using SSL:
wp search-replace http://example.org https://example.dev --network
wp post delete --force $(wp post list --post_type=product --format=ids)
This isn't WP CLI. Backup your uploads folder first and only use if you know what you're doing! Run this in your uploads folder.
find . -regextype posix-extended -regex ".*-[[:digit:]]{2,4}x[[:digit:]]{2,4}(@2x)?.(jpg|jpeg|png|eps|gif)" -type f -exec rm {} \;
Using the MU-Migration package for WP CLI, by 10up.
Install the package. Using Local by Flywheel, you need to force a higher php.ini value.
php -d memory_limit=512M "$(which wp)" package install 10up/mu-migration --allow-root
Use the package in the multisite installation.
wp mu-migration export all subsite.zip --blog_id=3 --uploads --plugins --themes
Download the ZIP and import it to the new single-site installation.
wp mu-migration import all subsite.zip --new_url=newdomain.hello
Run a search-replace
on the new database to be sure.
wp search-replace olddomain.ch newdomain.hello