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!

3 Answers
3

The following plugin dynamically hides the two offending radios using jQuery, and kills revision self-comparisons.

<?php
# Plugin Name: Pest Control
# Plugin URI: http://www.semiologic.com/
# Description: Kills the Easter Bunny
# Version: 1.0
# Author: Denis de Bernardy
# License: Public Domain

class PestControl {
    public static function bootstrap() {
        add_action('admin_head-revision.php', array(__CLASS__, 'mixomatosis'));
        add_action('load-revision.php', array(__CLASS__, 'plague'));
    }

    public static function mixomatosis() {
        echo <<<EOD
<script type="text/javascript">
// <![CDATA[
jQuery(document).ready(function($) {
    var mixomatosis = function() {
        var left = $(':radio[name=left]:checked').val(),
            right = $(':radio[name=right]:checked').val();
        $(':radio[name=left], :radio[name=right]').each(function() {
            var t = $(this);
            switch (true) {
                case t.attr('name') == 'left' && t.attr('value') == right:
                case t.attr('name') == 'right' && t.attr('value') == left:
                    t.css('display', 'none');
                    break;
                default:
                    t.css('display', '');
            }
        });
    };

    mixomatosis();
    $(':radio[name=left], :radio[name=right]').change(mixomatosis);
});
// ]]>
</script>
EOD;
    }

    public static function plague() {
        if ($_GET['action'] == 'diff' && $_GET['left'] == $_GET['right']) {
            wp_die("Can't compare a revision with itself.");
        }
    }
}

PestControl::bootstrap();
?>

Tags:

Leave a Reply

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