Created
          January 31, 2017 19:01 
        
      - 
      
 - 
        
Save davidwolfpaw/3f1d431071196f61c753e572700e7cbe to your computer and use it in GitHub Desktop.  
Revisions
- 
        
David created this gist
Jan 31, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,119 @@ #!/bin/bash -e # Ideas, Drawbacks, and Suggestions: https://davidlaietta.com/bash-scripting-to-automate-site-builds-with-wp-cli/ # Set up some defaults wpuser='USERNAME' email='[email protected]' blueprint='BLUEPRINT-NAME' clear echo "===================================" echo " ▄▀ ▄▀ David's Site Starter" echo " ▀ ▀ " echo "█▀▀▀▀▀█▄ Save Lots of Time!" echo "█░░░░░█ █ " echo "▀▄▄▄▄▄▀▀ Go Get a Coffee!" echo "===================================" echo "" echo "Site Slug: ${1}" # read -e name name=${1} # Generate a random 20 alphanumeric character password for the default user password=$(env LC_CTYPE=C tr -dc "A-Za-z0-9" < /dev/urandom | head -c 20) # Copy the password to the clipboard echo $password | pbcopy # Generate a random three lowercase letter prefix for the database and append an underscore prefix=$(env LC_CTYPE=C tr -dc "a-z" < /dev/urandom | head -c 3) prefix=$prefix'_' # Create a new VVV site and skip confirmation of selections # The name and domain are the user input name # The blueprint used is $blueprint # The default username is $wpuser # The password is $password, generated via lastpass-cli (Must be system installed to use) # The default admin email is $email # The prefix for the database is the one that we generated above # We're removing the default themes and plugins # All other defaults of vv create are kept yes | vv create -n $name -d $name.dev --username $wpuser --password $password --email $email --prefix $prefix -x -b $blueprint --defaults # Head over to the install that we just created cd "/LINK/YOUR/VVV/DIRECTORY/www/$name" # Delete the default plugins and themes that we don't need vassh wp plugin delete hello vassh wp theme delete twentyfifteen vassh wp theme delete twentysixteen # Activate the premium plugins and themes that we installed vassh wp theme activate THEME vassh wp plugin activate PLUGIN # delete sample post vassh wp post delete $(vassh wp post list --post_type=post --posts_per_page=1 --post_status=publish --postname="hello-world" --field=ID --format=ids) --force # wp post delete $(wp post list --post_type=post --posts_per_page=1 --post_status=publish --postname="hello-world" --field=ID --format=ids) --force # delete sample page, and create homepage vassh wp post delete $(vassh wp post list --post_type=page --posts_per_page=1 --post_status=publish --pagename="sample-page" --field=ID --format=ids) --force vassh wp post create --post_type=page --post_title=Home --post_status=publish --post_author=$(vassh wp user get $wpuser --field=ID) # Add a comma separated list of pages allpages="About,Contact,Blog" # create all of the pages IFS="," for page in $allpages do vassh wp post create --post_type=page --post_status=publish --post_author=$(vassh wp user get $wpuser --field=ID) --post_title="$(echo $page | sed -e 's/^ *//' -e 's/ *$//')" done # set page as front page vassh wp option update show_on_front 'page' # set "Home" to be the new page vassh wp option update page_on_front $(vassh wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=home --field=ID) # set "Blog" to be the new blogpage vassh wp option update page_for_posts $(vassh wp post list --post_type=page --post_status=publish --posts_per_page=1 --pagename=blog --field=ID) # # Set permalinks to postname # vassh wp rewrite structure '/%postname%/' --hard # vassh wp rewrite flush --hard # Create a navigation bar vassh wp menu create "Main\ Navigation" # Add pages to navigation IFS=" " for pageid in $(vassh wp post list --order="ASC" --orderby="date" --post_type=page --post_status=publish --posts_per_page=-1 --field=ID --format=ids); do vassh wp menu item add-post main-navigation $pageid done # Assign navigation to primary location vassh wp menu location assign main-navigation primary # Remove default widgets from sidebar widgetids=$(vassh wp widget list header-right --format=ids) vassh wp widget delete $widgetids # Create a category called "News" and set it as default vassh wp term create category News vassh wp option update default_category $(vassh wp term list category --name=news --field=id) echo "You Did It!" # Open the new website with Google Chrome open -a /Applications/Google\ Chrome.app http://$name.dev/wp-admin