i tried to create a simple function to receive a email when a specify user is logged, i tried with $current_user->ID and also with wp_get_current_user() but not working. This is my code:
function InvioMail() {
global $current_user;
$ID = $current_user->ID;
$user = wp_get_current_user();
$name = $user->user_login;
if ($name == 'piero') {
$to = '[email protected]';
$subject = 'test su action hook wp_login';
$body = 'test su action hook pwp_login';
$headers = array('Content-Type: text/html; charset=UTF-8','From: My Site Name <[email protected]');
wp_mail( $to, $subject, $body, $headers );
}
}
add_action( 'wp_login', 'InvioMail');
Without if condition work property but when i try with IF nothing.
Where I'm wrong?