As some of you know, there’s an Easter Egg hidden in the WordPress post revision system that will display a message from the movie The Matrix if you perform a specific action (if you don’t know, I won’t spoil the surprise … poke around with post revisions and see if you can find it). I love Easter Eggs, and this one was a thrilling find when I stumbled upon it.
Some people, it seems, aren’t really fans, though. I had a client recently discover this Easter Egg go into a panic attack because they thought someone had hacked their blog. They freaked out, flooded my inbox with panicked messages, and maxed out my voice mail quota with “please help!” messages.
This leads me to believe that some Easter Eggs should be turned off when WordPress is deployed in certain situations – i.e. for high-maintenance clients. Enter my idea for the first ever WordPress Answers code challenge.
The winner of this challenge will be awarded an extra 150 reputation points!!!
Let’s see how skilled you all are at coding … what would you recommend as the simplest way to remove this Easter Egg from WordPress without hacking core? In other words, using only action hooks, filters, and custom enqueued JavaScript, how would you remove the Matrix Easter Egg?
I’ll select the “best” answer on October 31st based on:
- The completeness of the answer (a description of the code + example code + screenshots if applicable)
- The simplicity of the code (but remember, shorter isn’t always better)
- Full descriptions of how you would install the code on a client site
BTW, anyone who merely copy-pastes the solution I already posted on the WP-Hackers mailing list will be automatically disqualified. Let the games begin!
The following plugin dynamically hides the two offending radios using jQuery, and kills revision self-comparisons.
My solution works in two ways: it disables selection of two identical revisions by modifying the
list-revisions
Javascript file, and if by some means two identical revisions do get selected, it offers a real error message.This screenshot gives you a quick overview of the error message, and the effect of the new Javascript. As you can see, it is no longer possible to select the same revision twice. If you want to see the effect you either have to disable the Javascript (comment out the
add_action(('wp_default_scripts', ...
line) or manually change the URL.It is written as a plugin. For a multisite installation you could maybe drop it in
mu-plugins
, and let the initialization depend on a database configuration option. That way you can enable or disable it for different clients.Comments on my plugin writing style are welcome, I tried to separate the code into three logical blocks.
Main plugin file. This file switches the
list-revisions
Javascript file with a “safer” version that prevents the selection of the same revision twice. It also checks theadmin_action_diff
action and shortcuts to an own page with an error message if the two revisions are equal. The new page is written inui-identical.php
to separate code and layout.File
ui-identical.php
, in the plugin directory. This creates the page to show if the two revisions are the same. The revision list is shown again.File
safe-list-revisions.dev.js
, in the plugin directory. The logic is split up in two loops: one to read the current checked buttons, and one to hide and show the others. This is might simpler than the original version, and allows some tweaking in the middle.I adore how code goes extra mile to include easter egg in obfuscated and inflexible way. 🙁
I suck with admin area, so here is my code that spawned way more questions in my head than answered:
No idea why encoded ampersand breaks redirect… Had no idea about
admin_action_
hook that this should really use instead of messily hooking into harmlessget_edit_post_link
…I tried to redirect to revision view, but that doesn’t seem possible for latest revision.