Eric Nagel

Eric Nagel

CTO, PHP Programmer, Affiliate Marketer & IT Consultant

WordPress Version Checker

I have been, or can be if you click on a link and make a purchase, compensated via a cash payment, gift, or something else of value for writing this post. Regardless, I only recommend products or services I use personally and believe will be good for my readers.

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.

	set_time_limit(0);

	// What's the current WordPress version?
	$cHTML = file_get_contents('http://wordpress.org/download/');
	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)) {
		echo("$cMsg");
		mail('eric@ericnagel.com', 'WordPress needs update', $cMsg, "From: eric@ericnagel.com");
	} // 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:

/var/www/vhosts/domain01.com/httpdocs/wp-config.php
/var/www/vhosts/domain02.com/httpdocs/wp-config.php
/var/www/vhosts/domain03.com/httpdocs/wp-config.php
/var/www/vhosts/domain04.com/httpdocs/wp-config.php
/var/www/vhosts/domain05.com/httpdocs/wp-config.php
/var/www/vhosts/domain06.com/httpdocs/wp-config.php
/var/www/vhosts/domain07.tv/httpdocs/wp-config.php
/var/www/vhosts/domain08.us/httpdocs/blog/wp-config.php
/var/www/vhosts/domain09.com/httpdocs/blog/wp-config.php
/var/www/vhosts/domain10.com/httpdocs/wp-config.php
/var/www/vhosts/domain11.com/httpdocs/wp-config.php

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.

Comments
  • Eric Nagel
    Posted October 22, 2009 8:10 am 0Likes

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

    WARNING!
    WordPress 2.8.4 != WordPress 2.8.5

    Glad to see it’s working 😀

  • AcquarioMarinho
    Posted January 30, 2011 6:59 pm 0Likes

    Have any way to check wordpress version just looking site?

    thanks

    • Eric Nagel
      Posted January 31, 2011 8:16 am 0Likes

      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

Your email address will not be published. Required fields are marked *

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