Skip to content

Instantly share code, notes, and snippets.

@eksiscloud
Last active March 19, 2021 12:06
Show Gist options
  • Save eksiscloud/8a131e993842e1edf0d735309fea5303 to your computer and use it in GitHub Desktop.
Save eksiscloud/8a131e993842e1edf0d735309fea5303 to your computer and use it in GitHub Desktop.
WP CLI + Bash: Batch installer of Wordpress plugins
#!/usr/bin/env bash
## WordPress Plugin Installer using BASH and WP-CLI
# Make executable: chmod u+x wp-plugins
# remember change WPPATH
# array of plugin slugs to install
WPPLUGINS=(
advanced-database-cleaner basepress categorytinymce classic-editor code-snippets change-last-modified-date disqus-comment-system
disqus-conditional-load easy-google-adsense easy-table-of-contents ewww-image-optimizer font-awesome header-footer host-analyticsjs-local
host-webfonts-local loco-translate mailster mailster-amazonses mailster-email-verify mailster-google-analytics mailster-recaptch
posts-in-sidebar relevanssi seo-by-rank-math tablepress tinymce-advanced updraftplus wp-crontrol advanced-database-cleaner
wp-ses wp-gdpr-compliance
)
# path to WordPress
WPPATH=/var/www/html
#loop through array, install and activate the plugins
for WPPLUGIN in "${WPPLUGINS[@]}"; do
#check if plugin is installed, sets exit status to 1 if not found
wp plugin is-installed $WPPLUGIN --path=$WPPATH --allow-root
#install plugin if not present based on exit code value
if [ $? -eq 1 ]; then
wp plugin install $WPPLUGIN --activate --path=$WPPATH --allow-root
fi
done
# Fix permissions
sudo chown -R www-data:www-data $WPPATH
sudo find $WPPATH -type f -exec chmod 644 {} +
sudo find $WPPATH -type d -exec chmod 755 {} +
@eksiscloud
Copy link
Author

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