Skip to content

Instantly share code, notes, and snippets.

@schlessera
Last active February 3, 2020 23:21
Show Gist options
  • Save schlessera/6c957a164d39a8a8f254119c60a685be to your computer and use it in GitHub Desktop.
Save schlessera/6c957a164d39a8a8f254119c60a685be to your computer and use it in GitHub Desktop.
Simple script to quickly create a fresh WordPress installation in a subfolder.

Site creation script

This simple Robo script let's you quickly pull up a new site via Valet+.

This was mention and demonstrated during Episode of my "Personal Home Page" livestream. More information about the livestream can be found at https://www.alainschlesser.com/streaming/.

Requirements:

Usage

robo create:empty <name> [<tld>] [<email>]

You can create a wrapper script for Robo, or install it as a local Composer dependency for convenience.

<?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