Jump to content

Sending email on admin login


Stefany93

Recommended Posts

Howdy colleagues,


Please help! I am writing a WP plugin the boss of the website to be notified when an admin logs in. So far so good, but I can't make the damn code to send the email when the user logs in. If I change the add_action to "admin_notices" the email is being sent, but if I put "wp_login" it does not :( Please help, here is the code so far...



function _emnoti_get_time_of_login(){
$time_of_login = date('l F Y');
return $time_of_login;
}
# Get the IP of the user that logged themselves as admin

function _emnoti_get_ip(){
$sources = array(
'REMOTE_ADDR',
'HTTP_X_FORWARDED_FOR',
'HTTP_CLIENT_IP',
);
foreach ($sources as $source) {
if(!empty($_SERVER[$source])){
$ip = $_SERVER[$source];
}
}
return $ip;
}

# Email all the info above to a pointed email address
function emnoti_send_email($user_login, $user){
if(_emnoti_check_if_admin() === true){
// print _emnoti_get_time_of_login();
// print _emnoti_get_ip();
wp_mail("MY EMAIL!", "Test subject", 'test body');
}
}

add_action('wp_login', 'emnoti_send_email', 10, 2);

?>

Link to comment
https://forums.phpfreaks.com/topic/289794-sending-email-on-admin-login/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.