It’s amazing how much WordPress code is available on github. Many developers choose not to place their plugins on WordPress.org for one reason or another, but this makes their code less convenient for others to find. Using a plugin from github traditionally requires you to visit github, search for the plugin, download the zip file and upload it to your site to install.
An Easier Way to Find and Install WordPress Plugins Hosted on github
Paul Clark has created a plugin called Github Plugin Search that will allow you to access and install WordPress plugins directly from your dashboard. He found a way to connect the github code search API to the WordPress plugin installer API. Here’s a quick demo of how this works:
How does the plugin detect WordPress plugins hosted on github?
Intrigued by the idea, I tested the plugin and checked in with Paul to find out how the plugin is able to detect WordPress plugins hosted on github. He replied:
Github’s code search API is fairly new (like… it’s still in preview. You have to send a special header just to access it.). They don’t *exactly* provide enough power in their search to truly query for WordPress plugins or to aggressively search the contents of each individual plugin.
To get around their limitations (limits on number of queries, no ability to match exact text like “Plugin Name”), I’m using a combination of two searches, comparing the results, and then filtering down to repositories I’m confident are installable WordPress plugins.
Paul outlined three requirements a repository must meet in order to be found by his github search plugin:
- Be a PHP file
- Be in the top level of the repository
- Have a comment block at the top of the file that matches a WordPress plugin header, with “Plugin Name:” and “Plugin URI:” in a comment block at the top. (This plugin header format is pretty unique — no other PHP systems I know of follow the same format.)
Right now, the plugin full-on replaces the search with results from github. It’s not such a big deal because of the github wp-plugins mirror, but Paul would like to add an option to toggle between wordpress.org and github results in the future.
Currently, the results returned are very basic, but Paul said that this is due to working within the confines of the API in preview:
When the Github API comes out of preview, I expect to be able to make results more accurate. Right now, logged in users can only make 20 queries every few minutes. All their other APIs allow 5000. I expect they’ll change it over when it’s final. When they do, the plugin could go crazy getting exact details on plugin files, running checks, and providing richer data from the readme and screenshots.
How Can Users Get Updates For New Stable Versions of Plugins Hosted on github?
I asked Paul if users would still be able to get updates for their plugins if they install from github. This is imperative, because a user wouldn’t want to unknowingly exclude himself from future updates. “The WordPress update API works based on the plugin name, not the source,” Paul explained. “So, if a user were to *install* wp-seo from Github right now, updates from wordpress.org would still work.”
Paul wrote a plugin a year or so ago that updates plugins from Github, Bitbucket, or generic Git repositories (public or private), if the URL is mentioned in the plugin header. It works nicely for him on client sites but in the current version of the Github Plugin Search he has it turned off. He outlines his concerns and the reasons why:
- In the current update plugin, the Git URL is set in the header. If all plugins are going to update, I need to generate and store that information for each plugin installed.
- The current updater updates when a new version is tagged in Github. Many WordPress developers aren’t in the habit of doing that (it’s the Git way of marking a new version, not the WordPress way), so to work with all plugins, I’d need to modify it to get the version number from the remote readme file. It’s possible to do that, just takes some time.
- If the update system is going to be replaced, users should also probably get a user interface to show them which plugins that’s happening for, and allow them to enable or disable it. There’s no reason, other than time, that those concerns couldn’t be resolved in the future.
The Future of Github Plugin Search
So as you can see, the plugin is still a work in progress but a very solid proof of concept so far. Paul plans to continue improvements to the plugin. In the future he may add in the fork and star count for the github repos in order to provide more data for users when selecting plugins. He’s created a list of enhancements that may come further down the road.
If you’d like to fork the Github Search Plugin or suggest changes, check it out on github or get in touch with Paul via Twitter.
What a great idea for a plugin, and it seems pretty solid. Why can’t I think of these things!?