This should work for you, make sure that the user_login
or user_id
matches to the string you’re using in the condition. Try to do a var_dump($user_login);
And about the function you’re using, you don’t need to grab the global
or call get_current_user();
, because the action you’re calling already pass two parameters to your function, the first is a string
with the $user_login
, and the second is a WP_User object
the current logged in user.
To use it, just change your code to this:
function InvioMail($user_login, $user) {
if ($user_login == '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', 10, 2);
To learn more about this hook, check the Docs.