Web Development eventually involves dealing with a wordpress site (or multiple), and if you’re like me - you have a bunch of private git repos that all lack wp-config.php files.
And if you’re also like me, you probably have a custom git command for hard resets and cleans (I call mine <code>git bleach</code>
) - which means you do a lot of rebuilding, and probably waste a lot of time creating your configs over and over again. So I automated that ish.
This post assumes you know some basic node/bash behavior. I also prefer to use Sage
for Wordpress theme development.
I use two files (specific to each repo) for bootstrapping
#!/usr/bin/env bash
function install_dependencies(){echo -e "\033[32m Installing needed Node Modules on OSX"
yarn
}function setup_wp_config(){if[ ! -e wp-config.php ];thenecho"setting up your wp-config";
cp wp-config-sample.php wp-config.php
sed -i "/DB_HOST/s/'[^']*'/'localhost'/2" wp-config.php
sed -i "/DB_NAME/s/'[^']*'/'YOUR_DB_NAME_HERE'/2" wp-config.php
sed -i "/DB_USER/s/'[^']*'/'vagrant'/2" wp-config.php
sed -i "/DB_PASSWORD/s/'[^']*'/'vagrant'/2" wp-config.php
sed -i "s/define('WP_DEBUG'.*/define('WP_DEBUG', true);/g" wp-config.php
SECRETKEYS=$(curl -L https://api.wordpress.org/secret-key/1.1/salt/)EXISTINGKEYS='put your unique phrase here'printf'%s\n'"g/$EXISTINGKEYS/d" a "$SECRETKEYS" . w | ed -s wp-config.php
fi}function is_osx(){[["$OSTYPE"=~ ^darwin ]]||return1}
is_osx ||return1
install_dependencies
setup_wp_config
now just run source bootstrap.sh from your project root and you’re ready to gulp and get to work debugging whatever the fuck is broken. Make sure to update YOUR_DB_NAME_HERE and my default vagrant db username/password if you have different mysql users.