Wordpress email new user

0

I am customizing the password setting email that is sent to the user when he registers, however when I try to create the password setting link he is not getting the user login, I am using the code below in functions.php

function handle_wp_mail($args) {
  if ($args['subject'] == '[SBACV - GO - Sociedade Goiana de Angiologia e Cirurgia Vascular] Seu nome de usuário e senha') {
    $wpdb = $GLOBALS['wpdb'];
    $email = $args['to'][0];
    $user = get_user_by('email', $email);

    $key = wp_generate_password(20, false);
    require_once(ABSPATH . WPINC . '/class-phpass.php');
    $hasher = new PasswordHash(8, true);
    $hashed = time() . ':' . $hasher->HashPassword($key);
    $wpdb->update($wpdb->users, ['user_activation_key' => $hashed], ['user_login' => $user->user_login]);

    $regUrl = network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login');
    $newMessage = <<<EOT

<h2>Bem vindo a SBACV-GO</h2>
<p></p>
<p>Obrigado por se registrar!</p>
<p><a href="$regUrl">Clique aqui para definir sua senha de acesso.</a></p>
EOT;

    $newMail = [
      'to' => $args['to'],
      'subject' => 'Bem vindo a SBACV-GO',
      'headers' => $args['headers'],
      'attachments' => $args['attachments'],
      'message' => $newMessage,
    ];
    
    return $newMail;
  }
}

add_filter('wp_mail', 'handle_wp_mail');
    
asked by anonymous 21.02.2018 / 20:22

0 answers