检查是否勾选了“向新用户发送有关其帐户的电子邮件”

时间:2017-05-15 作者:ahmed

我试图超越wp\\u new\\u user\\u notification()函数,但我在检查用户是否已获得批准或是否选中“向新用户发送有关其帐户的电子邮件”时遇到问题。

我需要执行这些检查的原因是,我注意到Override会忽略用户是否获得批准,也会忽略是否勾选了“向新用户发送有关其帐户的电子邮件”复选框。

if ( !function_exists(\'wp_new_user_notification\') ) {
    function wp_new_user_notification( $user_id, $plaintext_pass = \'\' ) {

        $user = new WP_User($user_id);
        $plaintext_pass = wp_generate_password();
        wp_set_password( $plaintext_pass, $user_id );

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);

        if ( empty($plaintext_pass) )
        return;


        if(get_user_meta($current_user->ID,\'active\',true) == 1){
          $subject = "Thank you for registering for ".get_option(\'blogname\')."";
          $message = "Thank you for registering for ".get_option(\'blogname\')."\\n";
          $message .= "Your registration for ".get_option(\'blogname\')." has been approved.\\n\\n";
          $message .= "Your registration information is below.\\n";
          $message .= "You may wish to retain a copy for your records.\\n\\n";
          $message .= "username: ".$user_login."\\n";
          $message .= "password:  ".$plaintext_pass."\\n\\n";
          $message .= "You may log in here:\\n";
          $message .= site_url( \'/\')."\\n\\n";
          $message .= "----------------------------------\\n";
          $message .= "This is an automated message from ".get_option(\'blogname\')."\\n";
          $message .= "Please do not reply to this address\\n";

          wp_mail($user_email, sprintf(__(\'[%s] Your username and password\'), get_option(\'blogname\')), $message);
        }


    }
}

1 个回复
SO网友:ahmed

我相信我找到了解决办法。不确定这是否是最佳解决方案,但至少可以达到以下目的:

if ( !function_exists(\'wp_new_user_notification\') ) {
  function wp_new_user_notification( $user_id, $plaintext_pass = \'\' ) {

    if($_POST[\'action\'] == \'createuser\'){

      if($_POST[\'send_user_notification\'] == 1){

        $user = new WP_User($user_id);
        $plaintext_pass = $_POST[\'pass1\'];
        wp_set_password( $plaintext_pass, $user_id );

        $user_login = stripslashes($user->user_login);
        $user_email = stripslashes($user->user_email);

        if ( empty($plaintext_pass) )
        return;

        if($_POST[\'activate_user\'] == 1){
          $headers = "From: xxxxxx <[email protected]>\\r\\n";
          $subject = "Thank you for registering for ".get_option(\'blogname\')."";
          $message = "Thank you for registering here are your log in details keep them safe, your account is now active\\n\\n";
          $message .= "username: ".$user_login."\\n";
          $message .= "password:  ".$plaintext_pass."\\n\\n";
          $message .= "Click here to log in:\\n";
          $message .= site_url( \'/\')."\\n\\n";
          $message .= "----------------------------------\\n";
          $message .= "This is an automated message from ".get_option(\'blogname\')."\\n";
          $message .= "Please do not reply to this address\\n";

          wp_mail($user_email, $subject, $message, $headers);

        }else{

          $headers = "From: xxxxxx <[email protected]>\\r\\n";
          $subject = "Thank you for registering for ".get_option(\'blogname\')."";
          $message = "Thank you for registering here are your log in details keep them safe, your account is pending so we will be in touch shortly\\n\\n";
          $message .= "username: ".$user_login."\\n";
          $message .= "password:  ".$plaintext_pass."\\n\\n";
          $message .= "----------------------------------\\n";
          $message .= "This is an automated message from ".get_option(\'blogname\')."\\n";
          $message .= "Please do not reply to this address\\n";

          wp_mail($user_email, $subject, $message, $headers);

        }

      }

    }
  }
}

结束

相关推荐

Activation Account Email

我使用betnami托管的wordpress多站点,当用户在该站点注册时,他应该会收到一封带有激活链接的电子邮件,但它不起作用!那么,如何让它发挥作用呢?如果可行,如何定制用户收到的电子邮件。顺致敬意,