WordPress Version Checker

With the big security release last week, I had a hard time remembering all of my WordPress sites. Some, like my blog, are obvious. But I also use WordPress to build affiliate sites (like WNY Wine Tastings), and even I don’t recognize they’re WordPress sites. So I figured I could write a script to not only find all of the WordPress installations on my GoDaddy server, but also tell me which are outdated.

This script isn’t commented as nicely as some of my other ones, but it’s only 40 lines long, so I’m sure you can figure it out.


	// What's the current WordPress version?
	$cHTML = file_get_contents('');
	list( , $cHTML) = explode('latest stable release of WordPress (Version ', $cHTML);
	list($fVersion, ) = explode(')', $cHTML);
	$fVersion = trim($fVersion);

	// echo("Current version:\t$fVersion\n");
	$cMsg = '';

	// Get a list of the sites
	$aResults = explode("\n", shell_exec('find /var/www/vhosts -name "wp-config.php"'));
	array_pop($aResults);	// Blank

	foreach ($aResults as $cSite) {
		$cSite = str_replace('/var/www/vhosts/', 'http://www.', $cSite);
		$cSite = str_replace('httpdocs/', '', $cSite);
		$cSite = str_replace('wp-config.php', '', $cSite);

		$rsMeta = get_meta_tags($cSite);

		if ($rsMeta['generator'] != 'WordPress ' . $fVersion) {
			$cMsg .= "**********************************************************************\n";
			$cMsg .= "WARNING!\n";
			$cMsg .= $rsMeta['generator'] . ' != WordPress ' . $fVersion . "\n";
			$cMsg .= "$cSite\n";
			$cMsg .= "**********************************************************************\n";
		} // ends
	} // ends

	if (!empty($cMsg)) {
		mail('', 'WordPress needs update', $cMsg, "From:");
	} // ends

First, I check for the current version of WordPress. I have no better way to do this than pull the text off the WordPress download page. I’m sure there’s a better method, but after looking for almost 20 minutes, I gave up.

Then, I run the find command to get a list of all of my sites. This works nicely on my server:


Next, I hit each of the sites & get the meta “generator” tag. If the version doesn’t line up, then a warning is appended to a variable. At the end of the script, if the variable isn’t empty, then an email is sent to me.

The “find” command will throw errors if you don’t have permission to search a folder, so when you set-up the daily cron, suppress error messages:

/usr/bin/php -q /home/esnagel/wp-check/wp-check.php 2>/dev/null

It’s not the prettiest, but it gets the job done.

How To & Tips
Share this Story:
  • facebook
  • twitter
  • gplus


  1. Eric Nagel
    3314 days ago

    WordPress was updated to version 2.8.5 the other day, and I’ve been getting my emails (because I haven’t upgraded yet)

    WordPress 2.8.4 != WordPress 2.8.5

    Glad to see it’s working 😀

  2. AcquarioMarinho
    2849 days ago

    Have any way to check wordpress version just looking site?


    • Eric Nagel
      2848 days ago

      Look at the “generator” meta tag. You’ll see something like:
      <meta name=”generator” content=”WordPress 3.0.4″/>

      Some themes may strip this out, but this is what I’m using for the script above.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.