A small fix for the better-github-widget plugin

This WordPress plugin is an awesome little widget that displays your github projects. It does have two small markup errors that I had to fix to make it pass W3C validation.

 

The two very small problems include:

  1. required attribute “alt” not specified – This is found on the octocat image it has no ALT value which is required to be valid. It’s also good to have in case the image really can’t be found! a simple fix was to just add alt=”github Octocat”
  2. end tag for element “a” which is not open – This one seems to be more like a typo than a bug but its still present in the current release of the plugin.  What I found was that  link was accidentally closed prior to displaying the username text

 

I have reported these two small problems to the authors github and hope he will push a fixed version. However I have also included source with fixes already implemented right here for anyone that needs.

 

<?php
/*
Plugin Name: Better GitHub Widget
Plugin URI: http://github.com/fracek/better-github-widget
Description: Display your GitHub projects
Author: Francesco Ceccon
Version: 0.5
Author URI: http://francesco-cek.com
*/
 
/**
* Adds Foo_Widget widget.
*/
class Better_GitHub_Widget extends WP_Widget {
 
    /**
* PHP 4 constructor
*/
    function Better_GitHub_Widget() {
        Better_GitHub_Widget::__construct();
    }
 
    /**
* PHP 5 constructor
*/
    function __construct() {
        $widget_ops = array('classname' => 'better-gh-widget', 'description' => __('Display your GitHub projects'));
        parent::__construct(
'better-gh-widget', // Base ID
'Better GitHub Widget', // Name
            $widget_ops
);
    }
 
    /**
* Front-end display of widget.
*
* @see WP_Widget::widget()
*
* @param array $args Widget arguments.
* @param array $instance Saved values from database.
*/
    public function widget( $args, $instance ) {
        extract($args);
        $username = $instance['username'];
        $count = $instance['count'];
        $title = 'GitHub';
 
        echo $before_widget;
        echo $before_title . $title . $after_title;
 
        // Octocat image
        echo '<img width="128px" src="' . plugins_url('octocat.png', __FILE__) . '"';
       echo ' style="display: block; margin: 0px auto;" alt="github Octocat"/>';
 
        // username @ GitHub
        echo '<p style="text-align: center; ">';
        echo '';
        echo $username . ' @ GitHub</p>';
 
        // the list of repos
        echo '<ul id="gh-repos">';
        echo '<li id="gh-loading">Status updating...</li>';
        echo '</ul>';
        echo '<script src="' . plugins_url('github.js', __FILE__) . '" type="text/javascript"> </script>';
?>
<script type="text/javascript">
github.showRepos({
user: '<?php echo $username; ?>',
count: <?php echo $count; ?>,
skip_forks: true,
});
</script>
<?php
        echo $after_widget;
    }
 
    /**
* Sanitize widget form values as they are saved.
*
* @see WP_Widget::update()
*
* @param array $new_instance Values just sent to be saved.
* @param array $old_instance Previously saved values from database.
*
* @return array Updated safe values to be saved.
*/
    public function update( $new_instance, $old_instance ) {
        $instance = array();
        $instance['username'] = strip_tags($new_instance['username']);
        $instance['count'] = strip_tags($new_instance['count']);
 
        return $instance;
    }
 
    /**
* Back-end widget form.
*
* @see WP_Widget::form()
*
* @param array $instance Previously saved values from database.
*/
    public function form( $instance ) {
        // Assigns values
        $instance = wp_parse_args( (array) $instance, array( 'username' => '', 'count' => ''));
        $username = strip_tags($instance['username']);
        $count = strip_tags($instance['count']);
 
        echo '<p><label for="'. $this->get_field_id('username') . '">' . __('Username') . ':';
        echo '<input class="widefat" id="' . $this->get_field_id('username') . '" ';
        echo 'name="' . $this->get_field_name('username') . '" type="text" ';
        echo 'value="' . attribute_escape($username) . '" />';
        echo '</label></p>';
 
        echo '<p><label for="' . $this->get_field_id('count') . '">' . __('Number of projects to show') . ':';
        echo '<input class="widefat" id="' . $this->get_field_id('count') . '" ';
        echo 'name="' . $this->get_field_name('count') . '" type="number" ';
        echo 'value="' . attribute_escape($count) . '" />';
        echo '<br><small>' . __('Set to 0 to display all your projects</small>');
        echo '</label></p>';
    }
 
} // class Foo_Widget
add_action( 'widgets_init', create_function( '', 'register_widget( "better_github_widget" );' ) );
?>

One Response to A small fix for the better-github-widget plugin

  1. Silabsoft says:

    Just a heads up the author replied to my message about the issue and has released an updated version.

Leave a Reply

*



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">