Skip to content

Instantly share code, notes, and snippets.

@clifgriffin
Created July 26, 2013 21:39
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 clifgriffin/6092443 to your computer and use it in GitHub Desktop.
Save clifgriffin/6092443 to your computer and use it in GitHub Desktop.
Parse current branch name from Git repository and conditionally set WordPress database name.
<?php
$git_head = file('.git/HEAD', FILE_USE_INCLUDE_PATH);
$git_head = $git_head[0]; //get the string from the array
$git_head = explode("/", $git_head); //separate out by the "/" in the string
$branch_name = trim($git_head[2]); //get the one that is always the branch name
if($branch_name == "master")
{
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress_local');
}
else
{
define('DB_NAME', 'wordpress_new');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment