Skip to content

Instantly share code, notes, and snippets.

@austinginder
Last active April 4, 2020 13:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinginder/753b7c87a91070cde03c5cdc1800a0d2 to your computer and use it in GitHub Desktop.
Save austinginder/753b7c87a91070cde03c5cdc1800a0d2 to your computer and use it in GitHub Desktop.
Bash script template for deploying many keys and values to wp-config.php for WordPress sites.
keys_to_add=(
WPCOM_API_KEY
GF_LICENSE_KEY
RECOVERY_MODE_EMAIL
)
values_to_add=(
wordpress_akismet_license_goes_here
gravity_forms_license_goes_here
recovery_email_address_goes_here
)
wp plugin delete hello
i=0
for key in ${keys_to_add[@]}; do
value=${values_to_add[$i]}
wp config set $key $value --type=constant
# Check if added. If not then attempt to add at different location.
if ! $( wp config has $key ); then
wp config set $key $value --type=constant --anchor="# That's It. Pencils down"
fi
# Check if added. If not then attempt adding at different location.
if ! $( wp config has $key ); then
wp config set $key $value --type=constant --anchor="/* That's all, stop editing!"
fi
if ! $( wp config has $key ); then
COLOR_RED="\033[31m"
COLOR_NORMAL="\033[39m"
echo -e "${COLOR_RED}Error:${COLOR_NORMAL} Unable to add $key to wp-config.php"
fi
let i=${i}+1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment