Settings'; array_unshift($links, $settings_link); return $links; } $plugin = plugin_basename(__FILE__); add_filter("plugin_action_links_$plugin", 'antihacker_plugin_settings_link' ); require_once (plugin_dir_path(__file__) . "settings/load-plugin.php"); require_once (plugin_dir_path(__file__) . "settings/options/plugin_options_tabbed.php"); add_filter('contextual_help', 'wptuts_contextual_help', 10, 3); function wptuts_contextual_help($contextual_help, $screen_id, $screen) { $myhelp = '
Improve system security and help prevent unauthorized access to your account by '; $myhelp .= 'restrict access to login page to whitelisted IP addresses.'; $screen->add_help_tab(array( 'id' => 'wptuts-overview-tab', 'title' => __('Overview', 'plugin_domain'), 'content' => '

' . $myhelp . '

', )); return $contextual_help; } $my_whitelist = trim(get_option('my_whitelist')); $my_whitelist = explode(PHP_EOL, $my_whitelist); $ip = trim(findip()); $admin_email = get_option( 'my_email_to' ); if (! whitelisted($ip, $my_whitelist)) { if(isset($_POST['myemail'])) { $myemail = strtolower(trim($_POST['myemail'])); } else { $myemail = ''; } add_action('login_form', 'email_display'); add_action('wp_authenticate_user', 'validate_email_field', 10, 2); function validate_email_field($user, $password) { global $myemail; if (!is_email($myemail)) return new WP_Error('wrong_email', 'Please, fill out the email field!'); else { $args = array( ); // The Query $user_query = new WP_User_Query( array ( 'orderby' => 'registered', 'order' => 'ASC' ) ); // User Loop if ( ! empty( $user_query->results ) ) { foreach ( $user_query->results as $user ) { // echo '

' . $user->user_email . '

'; if(strtolower(trim($user->user_email)) == $myemail ) return $user; } } else { // echo 'No users found.'; } return new WP_Error( 'wrong_email', 'email not found!'); } return $user; } function email_display() { ?> My Wordpress user email:

'; $msg .= 'Date : ' . $dt . '
'; $msg .= 'Ip: ' . $ip . '
'; $msg .= 'Domain: ' . $dom . '
'; $msg .= 'Role: ' . $user_login; $msg .= '
'; $msg .= 'Add this IP to your withelist to stop this email'; $email_from = 'wordpress@'.$dom; // To send HTML mail, the Content-type header must be set $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Create email headers $headers .= "From: ".$email_from. "\r\n" . 'Reply-To: ' . $user_login . "\r\n" . 'X-Mailer: PHP/' . phpversion(); $to = $admin_email; $subject = 'Login at: '.$dom; if ( ! whitelisted($ip, $my_whitelist)) { wp_mail( $to, $subject, $msg, $headers, '' ); } return 1; } function whitelisted($ip, $my_whitelist) { for ($i = 0; $i < count($my_whitelist); $i++) { if (trim($my_whitelist[$i]) == $ip) return 1; } return 0; } function findip() { $ip = ''; if (!empty($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) { $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; } else { $ip = $_SERVER['REMOTE_ADDR']; } $ip = trim($ip); if (!empty($ip)) return $ip; else return 'unknow'; } ?>