Frederick Townes is both the CTO of Mashable and a friend of mine. He’s always doing new and cool things with WordPress. One of his latest and greatest creations is W3 Total Cache, which we utilize here on WP Vibe. Here’s a little something he did recently that is really cool.
He added the “changelog” right below the plugin upgrade to explain why you should upgrade. People are lazy and often will not check the changelog to see if there is anything cool worth upgrading for, or people just forget. This way, it’s in your face and easy to view.
Here’s how he did it.
He first built his function,
function in_plugin_update_message()
{
$data = w3_url_get(W3TC_README_URL);
if ($data) {
$matches = null;
if (preg_match('~==s*Changelogs*==s*=s*[0-9.]+s*=(.*)(=s*[0-9.]+s*=|$)~Uis', $data, $matches)) {
$changelog = (array) preg_split('~[rn]+~', trim($matches[1]));
echo '<div style="color: #f00;">Take a minute to update, here's why:</div><div style="font-weight: normal;">';
$ul = false;
foreach ($changelog as $index => $line) {
if (preg_match('~^s**s*~', $line)) {
if (! $ul) {
echo '<ul style="list-style: disc; margin-left: 20px;">';
$ul = true;
}
$line = preg_replace('~^s**s*~', '', htmlspecialchars($line));
echo '<li style="width: 50%; margin: 0; float: left; ' . ($index % 2 == 0 ? 'clear: left;' : '') . '">' . $line . '</li>';
} else {
if ($ul) {
echo '</ul><div style="clear: left;"></div>';
$ul = false;
}
echo '<p style="margin: 5px 0;">' . htmlspecialchars($line) . '</p>';
}
}
if ($ul) {
echo '</ul><div style="clear: left;"></div>';
}
echo '</div>';
}
}
}Then he hooked it into the function
in_plugin_update_message()
which has existed since 2.8:
add_action('in_plugin_update_message-' . W3TC_FILE, array(
&$this,
'in_plugin_update_message'
));It’s a pretty simple process and it’s built into WordPress already, but not many people are aware of it.
Here is what the final result looks like:












Alternatively just use http://wordpress.org/extend/plugins/changelogger/ that works with any plugin that has a changelog section in its readme file.