SyntaxHighlighter Evolved – Devolved!
WP Multi-Network Plugin Fix for WordPress received a comment from David that said:
Completed code had errors.. I had to find and replace ? > with ?>
David was absolutely correct! On the other hand, I have 30 sites running this code with no problems at all! When I had written the article I had just cut and pasted it into WordPress, so I knew it was the same as I was using.
But when I cut and pasted it from the site, there was a problem, just as David described!
What had happened is that I had removed a number of plugins, and did some conversions and made things a lot more streamlined, and ended up breaking some stuff that should have been fixed long ago.
The story starts with a probe by some bad bot pretending to be a human and looking for a security hole. It kept banging away at one small TuKod site that had an ajax plugin, at the rate of about 10,000 hits a hour. All those 404 errors sent them emails and their shared host decided to take down any of their active ajax scripts. That effectively took down about 540 domains and, filled their inbox with 35,000 emails … and made them think! They needed to do something!
Up to then, I and the TuKod Team had pretty much ignored probes, spiders and bad bots, due to the nature of the websites they run. All but about 30 are catalogs for clients, and not the kind of target most people have problems with. But it got us thinking about the evil in the world, and we discovered that there is no really good, comprehensive bot control.
That is actually another story, I am turning it over to the Tukod Team to develop a Tukod BotNaught, sort of an Astronaut for the web. That bot terminated our servers, so to paraphrase the Terminator 3 movie, what we need is an anti-terminator-terminator! “So Bots with come to Naught!” A BotNaught!
As I was looking at this WP Multi-Network Plugin by John James Jacoby, I went to his site and read a post titled, Don’t Make Me Think. The post is about a book, Don’t Make Me Think by Steve Krug! Boy did that make me think…
Don’t Make Me Think
I think I want to find and buy this book! In the mean time, I read just about every blog post and review of this book I could find!
Resist the impulse to add things. When it’s obvious in testing that users aren’t getting something, most people’s first reaction is to add something, like an explanation or some instructions.
Very often, the right solution is to take something (or things) away that are obscuring the meaning, rather than adding yet another distraction.
Wow! Like a light bulb turning on, it came to light! He was talking about webpage design, but it applies to everything. For example, coding or plugins. How often do I see people talking about how slow their site is, and the reason, they have 25 plugins! Someone should have told then to not use any plugins, unless they absolutely need them. Plugins slow your website down.
Suddenly I had a plan… I started to make a spread sheet of all the plugins I was using, across all the sites I have access/control of. I also started listing how I was using the plugin and what for. I realized two of my sites actually had two plugins doing the same thing. I saw ways to make very minor changes, that would result in being able to eliminate whole plugins from the plugins folder!
By the end of the day I had cut my plugins in half! The sites looked as good and perhaps looked better. One of the plugins I deleted was SyntaxHighlighter Evolved. It was nice, it was pretty, and it was used on 6% of my websites. Other than one tiny post, that means this website was the only one I actually took the pain and effort to use this.
On the other hand, on the TAIT Styles website, I had already determined NOT to use it, but to just write the examples in <pre></pre> tags! So I took it out and changed the [php][/php] tags to <pre></pre>! That is where the trouble started…
Ternary Operations
The WP Multi-Network Plugin was written or modified by a string of people, me and the TuKod Team as well as at lease three others I can see. The code is sort of a pieced together thing… Sometimes using curly brackets, sometimes not. And sometimes using Ternary Operations too!
That is what I first noticed, most of the errors were in the else statement of a ternary operation. It was in the working code as:
else :?>
most of the time!
However, without taking extra care, it displays like this…
else :?>
Now carefully notice that WordPress added a space after the smiley!
WordPress took the original:
>
and turned it into:
>
And because of the space before the colon, WordPress thought the:
😕
Was actually the smiley:
😕
Everything would have been ok, except for the space it added after the smiley.
This:
else :?>
Was converted to this:
else :?>
And when it is copied back you get this added space:
else 😕 >
Note the added space that David was talking about. Actually this happened when SyntaxHighlighter Evolved was deactivated…
The easy solution is really rewriting the WP Multi-Network Code to have a better or standard coding.
For example, instead of this:
else :?>
The code should have put a space (for readability) before the closing php, like this:
else : ?>
Interestingly this last code does not fail in the double conversion!
More Evil Smilies!
Besides the Ternary Operation “else” statements that were the most obvious, there were other statements that had a likewise failure:
if ( $network->id != $myNetwork->id ) :?>
case ‘path’ :?>
Converted to being:
if ( $network->id != $myNetwork->id ) :?>
case ‘path’ :?>
And winded up being:
if ( $network->id != $myNetwork->id ) 😕 >
case ‘path’ 😕 >
TAIT Styles!
The good news is that the working draft of the TAIT Styles solves all these problems!
TuKod Multi-Network
Another good news is that the TuKod Team is going to completely fork the WP Multi-Network Plugin and update it with new hooks and better coding. It will be written in TAIT Styles and released as TuKod Multi-Network!
Rather than fork WP Multi Network and fragment the support and labor, why not contribute back to WP Multi Network? I’m happy to add someone as a committer to the plugin on the WordPress.org repository.
Hey John, we agree! I think the team was just a bit frustrated because WP Multi Network has been broken since WP 3.1 and many months the ticket was open… Just add the TuKod Team.
http://wordpress.org/extend/plugins/profile/tukod
We would be happy to contribute, this lightweight multi-network plugin is important to us. I’m sure the team would love to write some how to for beginners. Provide documentation and some support. Their focus is on multi-site, multi-network in simple, basic, but elegant terms.
With low bandwidth, low memory and low cpu resources, it is important in countries like this to have plugins that are really efficient (for some reason local Philippine host do not like ajax – this has been a few people’s experience). Which is why we liked WP Multi-Network – it was not bloated like the rest.
The team version removes all JavaScript and is for WP3.1 and above only. It uses some hooks that are not supported in versions 2.x and 3.0.x
However, I know their goal is simply something that works in our environment and making WP Multi Network better is keeping withing that goal.