Skip to content

Instantly share code, notes, and snippets.

@schlessera
Created December 14, 2019 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlessera/189179a4f9f7f08561a3d293f607f43a to your computer and use it in GitHub Desktop.
Save schlessera/189179a4f9f7f08561a3d293f607f43a to your computer and use it in GitHub Desktop.
Simple script to quickly create a fresh WordPress installation in a subfolder.
<?php declare( strict_types=1 );
final class RoboFile extends \Robo\Tasks {
public function createEmpty( string $name, string $tld = 'localhost', string $email = 'alain.schlesser@gmail.com' ) {
$io = $this->io();
$root = __DIR__;
$io->title( 'Creating an empty local WordPress site' );
$this->collectionBuilder()
->addTask(
$this->taskExec( "mkdir {$root}/{$name}" )
)
->rollback(
$this->taskDeleteDir( "{$root}/{$name}" )
)
->addTaskList( [
$this->taskExec( "cd {$root}/{$name}" ),
$this->taskExec( 'valet secure' )
->arg( $name ),
$this->taskExec( 'wp core download' )
->option( "path={$root}/{$name}" ),
$this->taskExec( 'wp core config' )
->option( "path={$root}/{$name}" )
->option( "dbname={$name}" )
->option( 'dbuser=root' )
->option( 'dbpass=root' ),
$this->taskExec( 'wp db create' )
->option( "path={$root}/{$name}" ),
$this->taskExec( 'wp core install' )
->option( "path={$root}/{$name}" )
->option( "url=https://{$name}.{$tld}" )
->option( "title={$name}" )
->option( 'admin_user=admin' )
->option( 'admin_password=password' )
->option( "admin_email={$email}" ),
] )
->completion(
$this->taskOpenBrowser( "https://{$name}.{$tld}" )
)
->run();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment