Skip to content

Instantly share code, notes, and snippets.

@Nav-Appaiya
Forked from morganestes/.readme.md
Created July 2, 2021 09:34
Show Gist options
  • Save Nav-Appaiya/03fa35ef7c64a696cfe8a0bfd29076ec to your computer and use it in GitHub Desktop.
Save Nav-Appaiya/03fa35ef7c64a696cfe8a0bfd29076ec to your computer and use it in GitHub Desktop.
Create multiple sites with wp-cli in WordPress multisite for testing.

These commands will install multiple dummy sites in a WordPress Multisite environment.

I wrote this to easily create an environment to work on https://core.trac.wordpress.org/ticket/15317.

Usage

Shell

In the terminal, inside your WordPress directory: simply copy, paste, and run the one-line command.

You can also add it to a location available in your $PATH and invoke the script from the shell.

WP-CLI

The easiest way to use this with WP-CLI is to include it in your commands directory and require it via config.

You may also choose to add the file to your local install and run this command, substituting your number of sites for {number}:

wp --require=wp-multisite-create-dummy-sites.php multisite install {number}
<?php
/**
* Bail if not a WP-CLI request
*/
if ( ! defined( 'WP_CLI' ) ) {
return;
}
class Setup_Command extends \WP_CLI_Command {
/**
* Install a number of test sites in a multisite environment.
*/
function install( $args, $assoc_args ) {
$number = absint( $assoc_args['number'] );
for ( $i = 0; $i <= $number; $i++ ) {
\WP_CLI::run_command( array( 'site', 'create' ),
array(
'slug' => "site-{$number}",
'title' => "Test Site $number",
)
);
}
\WP_CLI::success( "$number sites created." );
}
}
\WP_CLI::add_command( 'multisite', 'Setup_Command' );
for((i=1;i<=30;i++));do wp site create --slug="site-$i" --title="Test Site $i"; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment