Skip to content

Instantly share code, notes, and snippets.

@nathanieltubb
Last active December 11, 2018 04:35
Show Gist options
  • Save nathanieltubb/edac1dda958d42139e969781eb81820d to your computer and use it in GitHub Desktop.
Save nathanieltubb/edac1dda958d42139e969781eb81820d to your computer and use it in GitHub Desktop.
Install Blank WordPress with WP CLI
#!/bin/bash
# This Bash script requires WP CLI be installed and executeable as 'wp'.
# 1. Create your database and user as needed.
# 2. Create the directory you want WP to install in
# 3. 'cd' into that directory
# 4. Run this script
# IMPORTANT! This is a modified version of the base 5-minute install which removes
# and resets some of the default content and options. This is not meant to be used
# with existing WP installs or databases.
# Usage Message
PRINTUSAGE='installblankwp "DBNAME" "DBPASS" "DBPREFIX" "BLOGURL" "BLOGTITLE"'
# Variables
DBNAME=$1
DBUSER=$2
DBPASS=$3
DBPREFIX=$4
BLOGURL=$5
BLOGTITLE=$6
BLOGUSER="your_username"
BLOGUSEREMAIL="[email protected]"
BLOGADMINEMAIL="[email protected]"
BLOGUSERFIRSTNAME="First"
BLOGUSERLASTNAME="Last"
BLOGUSERNICKNAME="Nickname"
# Check for proper parameters
if [ $# -lt 2 ]; then
echo $PRINTUSAGE; exit 1;
fi
if ! [[ -n $DBNAME ]]; then
echo "Please Enter DBNAME"; exit 1;
fi
if ! [[ -n $DBUSER ]]; then
echo "Please Enter DBUSER"; exit 1;
fi
if ! [[ -n $DBPREFIX ]]; then
echo "Please Enter DBPREFIX"; exit 1;
fi
if ! [[ -n $BLOGURL ]]; then
echo "Please Enter http://BLOGURL"; exit 1;
fi
if ! [[ -n $BLOGTITLE ]]; then
echo "Please Enter BLOGTITLE"; exit 1;
fi
# Run the install WP CLI commands
# Download a Fresh WP Core without Plugins and Themes
wp core download --skip-content
# Create a wp-config File
wp config create --dbname="${DBNAME}" --dbuser="${DBUSER}" --dbpass="${DBPASS}" --dbhost=localhost --dbprefix="${DBPREFIX}"
# Run the Install and Collect the Admin Password to Output Later
BLOGUSERPASS=`wp core install --url="${BLOGURL}" --title="${BLOGTITLE}" --admin_user="${BLOGUSER}" --admin_email="${BLOGUSEREMAIL}" --skip-email`
# Update the Admin User Profile
wp user update 1 --first_name="${BLOGUSERFIRSTNAME}" --last_name="${BLOGUSERLASTNAME}" --nickname="${BLOGUSERNICKNAME}" --display_name="${BLOGUSERNICKNAME}"
# Install and Activate a Default WP Theme
wp theme install --activate twentynineteen
wp plugin install --activate acf-content-analysis-for-yoast-seo classic-editor php-enkoder wordpress-seo
wp plugin activate advanced-custom-fields-pro
# Remove the Blog Tagline
wp option set blogdescription ''
# Hide Site from Bots
wp option set blog_public 0
# Update Site Admin Email
wp option set admin_email "${BLOGADMINEMAIL}"
# Delete "Hello World" Post
wp post delete 1
# Delete "Hello World" Post Comment
wp comment delete 1 --force
# Rename "Sample Page" to "Home"
wp post update 2 --post_title="Home" --post_name="home"
# Set "Home" Page as Front Page
wp option set show_on_front 'page'
wp option set page_on_front 2
# Turn Off Pingbacks and Comments
wp option set default_pingback_flag ''
wp option set default_ping_status 'closed'
wp option set default_comment_status 'closed'
wp option set show_avatars ''
# Create and Set Blog Page
wp option set page_for_posts `wp post create --post_type="page" --post_title="Blog" --porcelain`
echo "//--//--//--//"
echo "DONE INSTALLING:"
echo "${BLOGUSERPASS}"
echo "//--//--//--//"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment