Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.