Coding Challenge – JavaScript Easter Egg

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();
?>

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)