Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Customized wordpress install script with WP CLI
#!/bin/bash
# Install Wordpress with Square Candy default using WP CLI
read -p 'Site URL (example.com): ' url
read -p 'Site Title: ' title
read -p 'WP Admin username: ' admin_user
read -sp 'WP Admin password: ' admin_password
read -p '
WP Admin email: ' admin_email
read -p 'Database name: ' dbname
read -p 'Database user: ' dbuser
read -sp 'Database password: ' dbpass
read -p '
Database prefix (wp_): ' dbprefix
read -p 'Theme Slug: ' themeslug
read -p 'Theme Full Name: ' themename
echo Ok. Starting installation of $title on $url.
# download, configure and install
wp core download
wp core config --dbname=$dbname --dbuser=$dbuser --dbpass=$dbpass --dbprefix=$dbprefix
wp core install --url=$url --title="$title" --admin_user=$admin_user --admin_password=$admin_password --admin_email=$admin_email
# delete default installed plugins and themes we don't need
wp plugin delete hello-dolly akismet
wp theme delete twentyfourteen twentyfifteen
# install our favorite plugins - activate the ones usually used in development
wp plugin install square-candy-tinymce-reboot acf-field-date-time-picker disable-comments ajax-thumbnail-rebuild custom-post-type-ui post-thumbnail-editor wordfence wp-super-cache wordpress-seo
wp plugin activate square-candy-tinymce-reboot disable-comments ajax-thumbnail-rebuild custom-post-type-ui post-thumbnail-editor wordpress-seo
# download and install ACF pro
wget -O acfpro.zip "http://connect.advancedcustomfields.com/index.php?p=pro&a=download&k=[REDACTED]"
wp plugin install acfpro.zip
rm acfpro.zip
# generate a new underscores (_s) theme
wp scaffold _s $themeslug --theme_name="$themename" --author="Square Candy" --author_uri="http://squarecandy.net"
wp theme activate $themeslug
# delete all the default sidebar widgets
wp widget delete search-2 recent-posts-2 archives-2 categories-2 meta-2
# delete the example post and example page
wp post delete 1 2 --force
# make a new page for the homepage and blog page
wp post create --post_type=page --post_title='Home' --post_status='publish'
wp post create --post_type=page --post_title='News' --post_status='publish'
# make those two pages the default for Home and Blog
wp option update show_on_front "page"
wp option update page_on_front "4"
wp option update page_for_posts "5"
# clear out "Just Another WordPress Blog" BS
wp option delete blogdescription
# set the timezone
wp option update timezone_string "America/New_York"
# we're usually starting with a development site - hide it from search engines
wp option update blog_public "on"
# update the permalink structure
wp rewrite structure '/news/%postname%/' --hard
# make all comments disabled
wp option update disable_comments_options --format=json '{"disabled_post_types":["post","page","attachment"],"remove_everywhere":true,"permanent":false,"extra_post_types":false,"db_version":6}'
# create the main menu and assign it to the primary menu slot
wp menu create "Main Menu"
wp menu location assign main-menu primary
wp menu item add-post main-menu 4 --title="Home"
wp menu item add-post main-menu 5 --title="News"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.