Skip to content

Instantly share code, notes, and snippets.

@danielcharrua
Forked from nicomollet/wp_auto_install.sh
Last active October 20, 2022 13:09
Show Gist options
  • Save danielcharrua/97b13874fa969d982ebf5a7e1ce315bf to your computer and use it in GitHub Desktop.
Save danielcharrua/97b13874fa969d982ebf5a7e1ce315bf to your computer and use it in GitHub Desktop.
WP-CLI auto install script
#!/bin/bash
# Default options
LOCALE="es_ES"
DB_HOST='localhost:3306'
printf "Name of the project? eg My Project: "
read PROJECT_NAME
printf "Slug of the project? eg myproject: "
read PROJECT_SLUG
printf "Shortname of the project? eg mp: "
read PROJECT_PREFIX
printf "WordPress admin user password: "
read ADMIN_PASSWORD
printf "Install ecommerce package? true or false: "
read INSTALL_ECOMMERCE
INSTALL_PATH=$PROJECT_SLUG
# Install WordPress and create the wp-config.php file...
wp core download --path=$INSTALL_PATH --locale=$LOCALE
wp core config --path=$INSTALL_PATH --dbname=$PROJECT_SLUG --dbuser=$PROJECT_SLUG --dbpass=$PROJECT_SLUG --dbhost=$DB_HOST --dbprefix=$PROJECT_PREFIX"_"
wp core install --path=$INSTALL_PATH --title='$PROJECT_NAME' --url="https://"$PROJECT_SLUG".l" --admin_user=$PROJECT_SLUG"_admin" --admin_email="admin@"$PROJECT_SLUG".com" --admin_password=$ADMIN_PASSWORD
# Go in the install directory
cd $INSTALL_PATH
# Update WordPress options
wp option update permalink_structure '/%postname%/'
wp option update default_ping_status 'closed'
wp option update default_pingback_flag '0'
wp option update default_comment_status 'closed'
wp option update show_comments_cookies_opt_in '0'
wp option update avatar_default 'monsterid'
wp option update blogdescription ''
wp option update timezone_string 'Europe/Madrid'
wp option update gmt_offset ''
# Install parent & child theme
wp theme install kadence
wp theme install https://www.kadencewp.com/wp-content/uploads/2020/07/kadence-child.zip --activate
# Install and activate defaults plugins
wp plugin install kadence-blocks svg-support wp-mail-smtp wp-comment-policy-checkbox --activate
# Install defaults plugins
wp plugin install regenerate-thumbnails seo-by-rank-math prevent-browser-caching wordfence wp-maintenance-mode honeypot-antispam code-snippets duplicate-post wp-smushit cookie-law-info broken-link-checker
# Install premium plugins
# wp-rocket gravityforms kadence-pro (from URL)
# Install ecommerce plugins
if [ $INSTALL_ECOMMERCE -eq true ]
then
wp plugin install woocommerce facebook-for-woocommerce woocommerce-pdf-invoices-packing-slips woo-redsys-gateway-light wc-apg-nifcifnie-field --activate
wp plugin install visual-hook-guide-for-kadence woocommerce-google-analytics-integration
# Maybe setup WooCommerce initial options
fi
# Update plugins & Core
wp update core
wp plugin update --all
# Delete comments
wp comment delete $(wp comment list --format=ids) --force
# Delete posts
wp post delete $(wp post list --post_type='post' --format=ids) --force
# Delete example page
wp post delete $(wp post list --post_type='page' --field="ID" --name="pagina-ejemplo") --force
# Create default pages
wp post create --post_type=page --post_title='Inicio' --post_content='<p>Home content</p>' --post_status=publish
wp post create --post_type=page --post_title='Contacto' --post_content='<p>Contact content</p>'
wp post create --post_type=page --post_title='Legal' --post_content='<p>Legal content</p>'
# Options for homepage
wp option update page_on_front $(wp post list --post_type='page' --field="ID" --name="inicio")
wp option update show_on_front page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment