Already Used Variable Names in WordPress

Last week I handed over a somewhat completed plugin over to Kyjen, and I was pretty proud of it. I knew it wasn’t 100% done; however, it was a good first step. Earlier today, I got an email from them with a screenshot of a very weird bug:

All of the messages in my plugin were showing up in the admin/user-new.php within the WordPress Admin… Pretty weird, right?

After a lot of investigating, and trying to figure out where the hell my custom messages were being called, I came across this part within the admin/user-new.php:

if (!empty($messages)) 
     foreach ( $messages as $msg ) {
     echo '<div id="message">' . $msg . '</div>';

Turns out, in the custom messages in my plugin, I had declared the array that held all of my messages as $messages, thus overriding the WordPress core.

Now I know to be more careful in my plugin variable naming. Previously, I had been careful with just my function names, but I guess it can’t hurt to be as explicit as possible.