Skip to content

Instantly share code, notes, and snippets.

@webdados
Created November 13, 2020 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webdados/b8a2a039d8418f9ac26a804250d49bb4 to your computer and use it in GitHub Desktop.
Save webdados/b8a2a039d8418f9ac26a804250d49bb4 to your computer and use it in GitHub Desktop.
Email to admin when WordPress lost password is requested
<?php
/* Email to admin when WordPress lost password is requested */
add_action( 'lostpassword_post', 'my_lostpassword_post', 10, 2 );
function my_lostpassword_post( $errors, $user_data ) {
if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
//check ip from share internet
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
//to check ip is pass from proxy
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ip = $_SERVER['REMOTE_ADDR'];
}
wp_mail(
get_option( 'admin_email' ),
'Someone tried to retrieve the password for '.$_POST['user_login'].' - '.date_i18n( 'Y-m-d H:i:s)' ),
'IP: '.$ip
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment