class-wc-email-customer-new-account.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_New_Account file.
  4. *
  5. * @package WooCommerce\Emails
  6. */
  7. if ( ! defined( 'ABSPATH' ) ) {
  8. exit; // Exit if accessed directly.
  9. }
  10. if ( ! class_exists( 'WC_Email_Customer_New_Account', false ) ) :
  11. /**
  12. * Customer New Account.
  13. *
  14. * An email sent to the customer when they create an account.
  15. *
  16. * @class WC_Email_Customer_New_Account
  17. * @version 2.3.0
  18. * @package WooCommerce/Classes/Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_New_Account extends WC_Email {
  22. /**
  23. * User login name.
  24. *
  25. * @var string
  26. */
  27. public $user_login;
  28. /**
  29. * User email.
  30. *
  31. * @var string
  32. */
  33. public $user_email;
  34. /**
  35. * User password.
  36. *
  37. * @var string
  38. */
  39. public $user_pass;
  40. /**
  41. * Is the password generated?
  42. *
  43. * @var bool
  44. */
  45. public $password_generated;
  46. /**
  47. * Constructor.
  48. */
  49. public function __construct() {
  50. $this->id = 'customer_new_account';
  51. $this->customer_email = true;
  52. $this->title = __( 'New account', 'woocommerce' );
  53. $this->description = __( 'Customer "new account" emails are sent to the customer when a customer signs up via checkout or account pages.', 'woocommerce' );
  54. $this->template_html = 'emails/customer-new-account.php';
  55. $this->template_plain = 'emails/plain/customer-new-account.php';
  56. // Call parent constructor.
  57. parent::__construct();
  58. }
  59. /**
  60. * Get email subject.
  61. *
  62. * @since 3.1.0
  63. * @return string
  64. */
  65. public function get_default_subject() {
  66. return __( 'Your account on {site_title}', 'woocommerce' );
  67. }
  68. /**
  69. * Get email heading.
  70. *
  71. * @since 3.1.0
  72. * @return string
  73. */
  74. public function get_default_heading() {
  75. return __( 'Welcome to {site_title}', 'woocommerce' );
  76. }
  77. /**
  78. * Trigger.
  79. *
  80. * @param int $user_id User ID.
  81. * @param string $user_pass User password.
  82. * @param bool $password_generated Whether the password was generated automatically or not.
  83. */
  84. public function trigger( $user_id, $user_pass = '', $password_generated = false ) {
  85. $this->setup_locale();
  86. if ( $user_id ) {
  87. $this->object = new WP_User( $user_id );
  88. $this->user_pass = $user_pass;
  89. $this->user_login = stripslashes( $this->object->user_login );
  90. $this->user_email = stripslashes( $this->object->user_email );
  91. $this->recipient = $this->user_email;
  92. $this->password_generated = $password_generated;
  93. }
  94. if ( $this->is_enabled() && $this->get_recipient() ) {
  95. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  96. }
  97. $this->restore_locale();
  98. }
  99. /**
  100. * Get content html.
  101. *
  102. * @access public
  103. * @return string
  104. */
  105. public function get_content_html() {
  106. return wc_get_template_html(
  107. $this->template_html, array(
  108. 'email_heading' => $this->get_heading(),
  109. 'user_login' => $this->user_login,
  110. 'user_pass' => $this->user_pass,
  111. 'blogname' => $this->get_blogname(),
  112. 'password_generated' => $this->password_generated,
  113. 'sent_to_admin' => false,
  114. 'plain_text' => false,
  115. 'email' => $this,
  116. )
  117. );
  118. }
  119. /**
  120. * Get content plain.
  121. *
  122. * @access public
  123. * @return string
  124. */
  125. public function get_content_plain() {
  126. return wc_get_template_html(
  127. $this->template_plain, array(
  128. 'email_heading' => $this->get_heading(),
  129. 'user_login' => $this->user_login,
  130. 'user_pass' => $this->user_pass,
  131. 'blogname' => $this->get_blogname(),
  132. 'password_generated' => $this->password_generated,
  133. 'sent_to_admin' => false,
  134. 'plain_text' => true,
  135. 'email' => $this,
  136. )
  137. );
  138. }
  139. }
  140. endif;
  141. return new WC_Email_Customer_New_Account();