I wanted to automatically change the Security Keys/SALTS when provisioning a new WordPress site. WordPress.com has a service that spits back random values. (https://api.wordpress.org/secret-key/1.1/salt/). The script below CURLs the values and then modifies a wp-config.php file with the new random values.
SALTS=$(curl -s https://api.wordpress.org/secret-key/1.1/salt/) while read -r SALT; do SEARCH="define('$(echo "$SALT" | cut -d "'" -f 2)" REPLACE=$(echo "$SALT" | cut -d "'" -f 4) echo "... $SEARCH ... $SEARCH ..." sed -i "/^$SEARCH/s/put your unique phrase here/$(echo $REPLACE | sed -e 's/\\/\\\\/g' -e 's/\//\\\//g' -e 's/&/\\\&/g')/" /Path/To/Your/wp-config.php done <<< "$SALTS"
Don’t remember where I got the pieces of this, but here it is, I have been using it for a while and it seems to work well.
Hope that helps someone.
Comments are closed.