Skip to content

WordPress Plugin Update Checker

Dear Reader,

A quick one here for those writing WordPress plugins. I’m experimenting with something here and thought I’d share. One thing that bugs me about writing plugins is when I make a new version, I have to go to several places and announce that there’s an update available. So I’m toying with the idea of having the plugin check every x days to see of there has been an update.

The way I do this is in the plugin’s option page (the only place I would ever do this) I put the following code at the bottom of this post.

Currently, this one is hard coded to check every 7 days. I’m thinking about changing that to like 3 and maybe making it an option so the user can set it to 0 and never have it execute.

I’m throwing it out here for others to review. My question is, it is ok to have a plug in ‘phone home’? I know I’m not collecting any stats but this could easily get out of hand if some reasonable guidelines aren’t set.

Until next time,



* Version Check code.
* This is a bit verbose. I'd like to cut it down a bit. I know this works
* in almost all cases. Some places may not have curl installed. I could do
* it in AJAX calling the plugin itself with a parameter and firing off a
* call but that's basically the same as what I'm doing here. So why bother.
if (($notable_settings['last_version_check']+(86400*7))<mktime()) {
$elements = parse_url('
$current_version = 0.00;
$line = '';

if ($fp = @fsockopen($elements['host'],80)) {
fputs($fp, sprintf("GET %s HTTP/1.0\r\n" . "Host: %s\r\n\r\n", $elements['path'] .
(isset ($elements['query']) ? '?'. $elements['query'] : ''), $elements['host']));
while (!feof($fp)) $line .= fgets($fp, 4096);

$line = urldecode(trim(strtr($line,"\n\r\t\0"," ")));
$work_array = explode(" ",$line);
* This does not allow for any additional messages to be passed. It
* assumes that the last time coming in is the version #.
$current_version = $work_array[count($work_array)-1];
} // if ($fp)
if ($version!=$current_version) {
<div class="wrap" style="border:solid 1px red;">This is version <?=$version;?>. The current version
of the plugin is <?=$current_version;?>. Click <a href=""
target="_NEW" title="Opens a new window.">here</a> to go to the project page to find out more.
} else {
<div class="wrap">This is plugin is up to date.<br />
} // if ($version!=$current_version)
} else {
<div class="wrap" >
} // if ($notable_settings['last_version_check']!=(mktime()+(86400*7)))

One thought on “WordPress Plugin Update Checker

  1. You are right. Sorry, I threw this entry together and didn’t discuss that it was a function I’m considering in my BlogBling plugins and not a plugin in itself.

    This version is pretty bare bones and is included in wp-notable as is. In the next version I’m thinking about a little AJAX method to allow the plugin not only to tell if the version has been updated but to return a diff of the change log since the version the user is running. My goal here is to allow the user to decide if the update is worth it. Mainly because a lot of times updates are little things and aren’t really necessary.

    Thanks for stopping by.


    p.s. check back next week. I’ve got a series of articles I’m preparing that prove that you blog is necessary to the blogosphere and won’t be replaced by my phone-home-ability. :)

Comments are closed.