Skip to content

Instantly share code, notes, and snippets.

@Web-Assembler
Last active July 12, 2021 20:38
Show Gist options
  • Save Web-Assembler/85a854bdf58814ea324c606cf86a9208 to your computer and use it in GitHub Desktop.
Save Web-Assembler/85a854bdf58814ea324c606cf86a9208 to your computer and use it in GitHub Desktop.
WP CLI Project Setup - Development
#!/bin/bash
## WP CLI Project Setup
# Options documentation here:
# https://codex.wordpress.org/User:HEngel/Option_Reference#Reading
##############
# Instructions
##############
# 1. If the CLI returns an error "error establishing a database connection", change `localhost` in wp-config.php to `127.0.0.1`
admin_username="admin"
# 2. Set true or false if composer is installed in the project. This will skip installing plugins with WPCLI
composer_installed=true
# 3. Sets a timestamp for creating posts in the past so they are not scheduled
post_timestamp="`TZ=GMT+5 date +%Y-%m-%d` 07:00:00"
# 4. Set the project domain
project_url="mysite.test"
echo ""
echo "##############"
echo "# Core"
echo "##############"
echo ""
echo "๐Ÿ”ธ Updating all Themes"
sh -c "wp theme update --all"
echo ""
echo "##############"
echo "# Settings"
echo "##############"
echo ""
echo "# 1. General"
echo "๐Ÿ”ธ Removing default Blog Description"
sh -c "wp option update blogdescription ''"
echo ""
echo "# 2. Writing"
echo "๐Ÿ”ธ Creating blog categories"
sh -c "wp term create category Design --description='Posts about design.' --porcelain | xargs -I % wp term create category Illustration --parent=%"
sh -c "wp term create category Technology --description='Posts about technology.' --porcelain"
sh -c "wp term create category Lifestyle --description='Posts about lifestyle.' --porcelain"
sh -c "wp term create category Food --description='Posts about food.' --porcelain"
sh -c "wp term create category Drink --description='Posts about drink.' --porcelain"
sh -c "wp term create category Fashion --description='Posts about fashion.' --porcelain"
echo ""
echo "# 3. Reading"
echo "๐Ÿ”ธ Setting 8 posts per page (inc. RSS)"
sh -c "wp option update posts_per_page 8"
sh -c "wp option update posts_per_rss 8"
echo ""
echo "# 4. Discussion"
echo ""
echo "# 5. Media"
echo ""
echo "# 6. Permalinks"
echo "๐Ÿ”ธ Setting pretty permalinks"
sh -c "wp option update permalink_structure '/%postname%/' --quiet"
# Only install plugins if composer is not in project (bool)
if ! $composer_installed
then
echo ""
echo "##############"
echo "# Plugins"
echo "##############"
echo ""
echo "๐Ÿ”ธ Deleting Hello Dolly Plugin"
sh -c "wp plugin delete hello"
echo ""
echo "๐Ÿ”ธ Deleting Akismet Plugin"
sh -c "wp plugin delete akismet"
echo ""
echo "๐Ÿ”ธ Installing Yoast SEO Plugin"
sh -c "wp plugin install wordpress-seo"
echo ""
echo "๐Ÿ”ธ Installing Contact Form 7 Plugin"
sh -c "wp plugin install contact-form-7"
echo ""
echo "๐Ÿ”ธ Installing Redirection Plugin"
sh -c "wp plugin install redirection"
fi
echo ""
echo "##############"
echo "# Users"
echo "##############"
echo ""
echo "๐Ÿ”ธ Creating User: Subscriber"
sh -c "wp user create user_subscriber user_subscriber@$project_url --role=subscriber --user_pass=user_subscriber"
echo "๐Ÿ”ธ Creating User: Contributor"
sh -c "wp user create user_contributor user_contributor@$project_url --role=contributor --user_pass=user_contributor"
echo "๐Ÿ”ธ Creating User: Author"
sh -c "wp user create user_author user_author@$project_url --role=author --user_pass=user_author"
echo "๐Ÿ”ธ Creating User: Editor"
sh -c "wp user create user_editor user_editor@$project_url --role=editor --user_pass=user_editor"
echo "๐Ÿ”ธ Creating User: Administrator"
sh -c "wp user create user_administrator user_administrator@$project_url --role=administrator --user_pass=user_administrator"
echo ""
echo "##############"
echo "# Pages"
echo "##############"
echo ""
echo "๐Ÿ”ธ Creating and Setting Home and News pages"
# Set the "your homepage displays" setting to "A static page" in Settings > Reading
sh -c "wp option update show_on_front page"
# Create 'Home' Page and set it as the static home page in Settings > Reading
sh -c "wp post create --post_type=page --post_title='Home' --post_status=publish --post_author=$admin_username --porcelain | xargs -I % wp option update page_on_front %"
# Create 'News' Page and set it as the static Posts page in Settings > Reading
sh -c "wp post create --post_type=page --post_title='News' --post_status=publish --post_author=$admin_username --porcelain | xargs -I % wp option update page_for_posts %"
# Create 'Contact' Page
echo ""
echo "๐Ÿ”ธ Creating Contact page"
sh -c "wp post create --post_type=page --post_title='Contact Us' --post_status=publish --post_author=$admin_username --quiet "
echo ""
echo "##############"
echo "# Posts"
echo "##############"
echo ""
echo "๐Ÿ”ธ Creating 16 Posts"
sh -c "wp post generate --count=16 --post_date='$post_timestamp'"
@Web-Assembler
Copy link
Author

Web-Assembler commented Apr 29, 2021

Issues to fix

  • need to add instructions in readme to install WP CLI and change mod to plus x
  • posts are set to scheduled because they need to be created in the past
  • only install plugins if no composer.json is in the folder
  • remove update all themes
  • still need to disable full screen mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment