Last active
February 20, 2020 16:17
-
-
Save nunesbeto/105d1d68642385b4d46c1b8d92dc5e11 to your computer and use it in GitHub Desktop.
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 | |
if ! $(wp core is-installed); | |
then | |
echo "[ERROR] Wordpress is not installed." | |
exit 1 | |
fi | |
# Get configuration file | |
if [[ ! -f w3-total-cache-v1.json ]]; | |
then | |
curl -s -L -O https://hostoo.io/files/w3-total-cache-v1.json | |
fi | |
if [[ ! -f w3-total-cache-v1.json ]]; | |
then | |
echo "[ERROR] Configuration file could not be downloaded." | |
exit 1 | |
fi | |
# Check for other cache plugins | |
PLUGINS=( "litespeed-cache" "wp-super-cache" "wp-fastest-cache" "wp-fastest-cache-premium" "wp-rocket" ) | |
for item in ${PLUGINS[*]} | |
do | |
if $(wp plugin is-active $item); | |
then | |
wp plugin deactivate $item | |
if [ $? -eq 1 ]; | |
then | |
echo "[ERROR] Unable to deactivate $item." | |
exit 1 | |
fi | |
fi | |
done | |
# Install W3TC | |
if ! $(wp plugin is-installed w3-total-cache); | |
then | |
wp plugin install w3-total-cache | |
if [ $? -eq 1 ]; | |
then | |
echo "[ERROR] W3 Total Cache plugin could not be installed." | |
exit 1 | |
fi | |
fi | |
# Activate W3TC | |
if ! $(wp plugin is-active w3-total-cache); | |
then | |
wp plugin activate w3-total-cache | |
if [ $? -eq 1 ]; | |
then | |
echo "[ERROR] W3 Total Cache plugin could not be activated." | |
exit 1 | |
fi | |
fi | |
# Import configuration file | |
wp w3-total-cache import w3-total-cache-v1.json | |
if [ $? -eq 1 ]; | |
then | |
echo "[ERROR] Configuration file could not be imported." | |
exit 1 | |
fi | |
# Fix environment files | |
wp w3-total-cache fix_environment | |
# Clear caches | |
wp w3-total-cache flush all | |
wp w3-total-cache pgcache_cleanup | |
# Remove configuration file | |
rm -f w3-total-cache-v1.json | |
echo "W3TC configuration finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment