#!/bin/bash
# Function to display usage instructions when the command is used incorrectly
function usage {
echo "usage: wc-site <name> [--master]"
echo "e.g. wc-site gradient will create a site at https://gradient.test"
echo "The \"--master\" switch will install the current WooCommerce master from Github"
exit 1
}
# If the wc-site command is run without the site name, display usage instructions
if [[ -z "$1" ]]; then
usage
else
# If only the site name is supplied, assume WordPress.org version of WooCommerce is wanted
if [[ -z "$2" ]]; then
woo="woocommerce"
# If master switch is used then current WooCommerce master from Github is wanted
elif [[ $2 = "--master" ]]; then
woo="https://github.com/woocommerce/woocommerce/archive/master.zip"
# If a second argument other than "--master" is supplied, teach the user how to do it
else
usage
fi
fi
# Change current directory to Sites
cd ~/www/sites/
# Create WordPress site. Set the database name to be the same as the site name.
# wp valet uses `wp_<name>` which I'm not keen on
wp valet new $1 --dbname=$1
# Make the site https if you're using Valet. Not necessary with Valet+
# valet secure $1
# Change current directory to the new site so you can work your WP-CLI magic
cd ~/www/sites/$1
# Install & Activate WooCommerce based on whether the master switch is used or not.
wp plugin install $woo --activate
# Install & Activate Storefront
wp theme install storefront --activate
# Install & Activate the WP-CLI Login Companion Plugin
wp login install --activate
# Update permalink structure
wp rewrite structure '/%year%/%monthnum%/%day%/%postname%/'
# Launch the site in your default browser
# valet open $1
# Launch the site's /wp-admin/ in your default browser
# wp admin
# Generate a Magic Link and Log in to the site in your default browser
# Luminus is the default admin username for my local sites
wp login as luminus --launch