Skip to content

Instantly share code, notes, and snippets.

@petenelson
Created August 6, 2014 15:31
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 petenelson/912817d2ca8c7d36379c to your computer and use it in GitHub Desktop.
Save petenelson/912817d2ca8c7d36379c to your computer and use it in GitHub Desktop.
<?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