Last active
July 12, 2021 20:38
-
-
Save Web-Assembler/85a854bdf58814ea324c606cf86a9208 to your computer and use it in GitHub Desktop.
WP CLI Project Setup - Development
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Issues to fix
posts are set to scheduled because they need to be created in the pastonly install plugins if no composer.json is in the folder