Skip to content

Instantly share code, notes, and snippets.

@lordspace
Created March 16, 2013 04:36
Show Gist options
  • Select an option

  • Save lordspace/5175010 to your computer and use it in GitHub Desktop.

Select an option

Save lordspace/5175010 to your computer and use it in GitHub Desktop.

Revisions

  1. lordspace created this gist Mar 16, 2013.
    40 changes: 40 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,40 @@
    add_filter('login_head', create_function('$a', "wp_enqueue_script('jquery');"));
    add_filter('login_errors', 'login_error_message');
    add_action('login_footer', 'login_error_message_hide_empty_error_container');

    /**
    * Removes an error message shown by Limit Login Attempts plugin.
    * NN attempts remaining. We don't need to give info to the attacker.
    * Making error null solves half of the problem. There is a wrapper with
    * a red border which we will remove with : login_error_message_hide_empty_error_container
    *
    * @param string $error
    * @return string
    * @see http://orbisius.com
    */
    function login_error_message($error) {
    $error_fmt = strip_tags($error);

    // what about other languages other than english ?
    if (preg_match('#\d+\s+attempts?\s+remaining\.?#si', $error_fmt)) {
    $error = null;
    }

    return $error;
    }

    /**
    * This removes the error container if it doens't have tags in it.
    */
    function login_error_message_hide_empty_error_container() {
    echo <<<BUFF_EOF
    <script>
    try {
    if (jQuery.trim(jQuery('#login_error').text()) == '') {
    jQuery('#login_error').remove();
    }
    } catch (e) {
    }
    </script>
    BUFF_EOF;
    }