Created
August 6, 2014 15:31
-
-
Save petenelson/912817d2ca8c7d36379c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: GGA - git branches | |
Description: Dashboard Widget | |
Author: Pete Nelson | |
Version: 1.0 | |
*/ | |
if (!defined( 'ABSPATH' )) exit('restricted access'); | |
add_action('wp_dashboard_setup', 'gga_add_git_dashboard_widget'); | |
if (!function_exists('gga_add_git_dashboard_widget')) { | |
function gga_add_git_dashboard_widget() { | |
wp_add_dashboard_widget( | |
'gga-git-branches-widget', | |
'git branches', | |
'gga_dashboard_widget_git_branches' | |
); | |
} | |
} | |
if (!function_exists('gga_dashboard_widget_git_branches')) { | |
function gga_dashboard_widget_git_branches() { | |
// this plugin is used in our WordPress environment to display the list of branches | |
// we use the wp_content dir as our repo's root | |
chdir(WP_CONTENT_DIR); | |
$output = array(); | |
$results = exec('git branch', $output); | |
if (!empty($output) && is_array($output)) { | |
?> | |
<style> | |
#gga-git-branches-widget .gga-git-branch-current { color: #009900; } | |
</style> | |
<ul class="gga-git-branches"> | |
<?php foreach ($output as $branch) { | |
$classes = array('gga-git-branch'); | |
if (0 === stripos($branch, '* ')) | |
$classes[] = 'gga-git-branch-current'; | |
?> | |
<li class="<?php echo implode(' ', $classes) ?>"><?php echo esc_attr($branch) ?></li> | |
<?php } ?> | |
</ul> | |
<?php } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment