Fuck me running!
I’m a software developer by trade. I know, I know, you’d never guess that from my handle, thecodepounder, right? Well, be that as it may, I write software for a living (I wouldn’t presume to describe my job in resume’-terms on this blog, e.g. “conceive, design, write and implement world-class solutions, the brilliance of which tend to make other developers crap their pants, blah, blah, blah” — you get the point).
So, I have this little plugin I wrote for the purpose of centralizing some code and to save myself some time as I play around with my WordPress theme. No big deal. This plugin has been working flawlessly for several months. I’ve updated it fairly regularly and never had a problem. Never a problem, that is, until yesterday…
I was tweaking the theme this weekend and, in so doing, added about a half dozen functions to the plugin in question. Again, no big deal by any stretch of the imagination. I tested the new code on my test site, and when I was satisfied that it was working properly, I moved the code into the plugin file on this site. Cool, or so I thought.
Last night just before I went to bed, however, I noticed that the “Write Post” page was not displaying properly. The “post box” was displaying the “Visual” and “HTML” tabs with the “Visual” tab selected, but the “HTML” button were being displayed. Weird. I took a stab at diagnosing the problem and didn’t see anything obvious, so I went to bed, since the site was still displaying properly…
Well, all told, between last night and this afternoon after work, I have spent about two hours diagnosing the problem. I have removed code from the plugin — function by function, removed calls into the plugin from my theme, jumping back and forth to the “Write Post” page (and verifying that the site was loading properly) after each and every change. Eventually I got all my code back to the state it was in on Friday afternoon, before this weekend’s work, and I still had the problem on the “Write Post” page!
Fuck! Even with all the weekend’s changes backed out of the plugin and theme files, I was still screwed Deactivate the plugin and “Write Post” page works, activate plugin and it doesn’t. Crap! Clearly a problem with this particular plugin, but what the hell it could be now that it was back to last working state I hadn’t a clue.
Well, it’s been my experience, in the realm of software, that when you find yourself saying anything along the lines of “it couldn’t possibly be that — that has been working for <insert appropriate period of time>” you should definitely check that thoroughly! So, I began removing all calls into the plugin from my theme. This took a little while, but I got my test site to the point where I could deactivate the plugin and the site would display without a “call to undefined function” error (but missing the content contained in the plugin).
At this point, I activated the plugin and started removing code — maybe I inadvertently fat-fingered something in the existing code that wasn’t readily apparent. Remove a function, check the “Write Post” page. Function by function, I deleted everything, to no avail. My plugin looked like this:
<?php
/*
Plugin Name, etc.
*/?>
and still the “Write Post” page wouldn’t work right with the plugin activated.
Which is when I noticed something that really made me say, “well, it couldn’t be that…”
“What was that“, you ask?
Well, that was a CR/LF following the php-close tag: ?> (as you can now see in the blockquote above). That’s right, somehow I managed to insert a couple CR/LF characters after the ?> tag at the end of the plugin file!
Remove the extra CR/LF at the end of the file so that the plugin looked like this:
<?php
/*
Plugin Name, etc.
*/?>
and everything is fine. Insert even a single CR/LF after the ?> tag and it’s shitsville all over again!
So, problem solved, at least for me. It won’t take that long to put things back the way they were. I only hope that this tale of woe might help someone else who’s having a really shitty problem with a plugin (though, regrettably, most plugin problems have nothing to do with this situation, and will not be easily solved).
The bigger questions are: why is a fucking CR/LF a problem in this situation? Is this situation really so unforeseeable that it can’t be solved programmatically in the first place? But, that’s a topic for another day…
Good luck.










