/**
  * @ticket 28092
  */
 function test_remove_error()
 {
     $error = new WP_Error();
     $error->add('foo', 'This is the first error message', 'some error data');
     $error->add('foo', 'This is the second error message');
     $error->add('bar', 'This is another error');
     $error->remove('foo');
     // Check the error has been removed.
     $this->assertEmpty($error->get_error_data('foo'));
     $this->assertEmpty($error->get_error_messages('foo'));
     // The 'bar' error should now be the 'first' error retrieved.
     $this->assertEquals('bar', $error->get_error_code());
     $this->assertEmpty($error->get_error_data());
 }
 function wp_limit_login_auth_signon($user, $username, $password)
 {
     global $ip, $msg, $wpdb;
     $ip = getip();
     if (empty($username) || empty($password)) {
         // do_action( 'wp_login_failed' );
     }
     if ($_SESSION["popup_flag"] == "true_0152") {
         $tablename = $wpdb->prefix . "limit_login";
         $tablerows = $wpdb->get_results("SELECT `login_id`, `login_ip`,`login_attempts`,`attempt_time`,`locked_time` FROM  `{$tablename}`   WHERE `login_ip` =  '{$ip}'  ORDER BY `login_id` DESC LIMIT 1 ");
         if (count($tablerows) == 1) {
             $time_now = date_create(date('Y-m-d G:i:s'));
             $attempt_time = date_create($tablerows[0]->attempt_time);
             $interval = date_diff($attempt_time, $time_now);
             if ($interval->format("%s") <= 1) {
                 if ($tablerows[0]->login_attempts != 0) {
                     wp_redirect(home_url());
                     exit;
                 } else {
                     return $user;
                 }
             } else {
                 /*$url_first = "http://www.shroomery.org/ythan/proxycheck.php?ip=".$ip;
                   $url_second = "http://check.getipintel.net/check.php?ip=".$ip;
                   $response_first = wp_remote_get($url_first); 
                   $response_second = wp_remote_get($url_second);
                     
                     $ip_check = false;
                    
                    if(($response_first['body']=="N")|| ($response_second['body']<=0.99)){
                         $ip_check = true;
                     } */
                 $ip_check = true;
                 if ($tablerows[0]->login_attempts % 7 == 0) {
                     if ($tablerows[0]->login_attempts != 0) {
                         $attempts = $tablerows[0]->login_attempts;
                         $attempts = $attempts + 1;
                         $_SESSION["popup_flag"] = "first";
                         $update_table = array('login_id' => $tablerows[0]->login_id, 'login_attempts' => $attempts);
                         $wpdb->update($tablename, $update_table, array('login_id' => $tablerows[0]->login_id));
                     }
                 }
                 // proxy or not
                 if ($ip_check == true) {
                     if (!is_numeric($tablerows[0]->locked_time)) {
                         $locked_time = date_create($tablerows[0]->locked_time);
                         $time_now = date_create(date('Y-m-d G:i:s'));
                         $interval = date_diff($locked_time, $time_now);
                         if ($interval->format("%i") <= 10) {
                             $msg = "Sorry..! Please wait 10 minutes..!";
                             $error = new WP_Error();
                             $error->add('wp_to_many_try', $msg);
                             return $error;
                         } else {
                             $update_table = array('login_id' => $tablerows[0]->login_id, 'login_attempts' => 0, 'attempt_time' => date('Y-m-d G:i:s'), 'locked_time' => 0);
                             $wpdb->update($tablename, $update_table, array('login_id' => $tablerows[0]->login_id));
                             return $user;
                         }
                     } else {
                         return $user;
                     }
                 } else {
                     $_SESSION["popup_flag"] = "first";
                     $error = new WP_Error();
                     $error->add('wp_proxy_detection', "Sorry..! Proxy detected..!");
                     return $error;
                 }
             }
         } else {
             return $user;
         }
     } else {
         $_SESSION["popup_flag"] = "first";
         $error = new WP_Error();
         $error->remove('wp_captcha', "Sorry..! captcha");
         return $error;
     }
 }