class-wc-email-customer-reset-password.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * Class WC_Email_Customer_Reset_Password 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_Reset_Password', false ) ) :
  11. /**
  12. * Customer Reset Password.
  13. *
  14. * An email sent to the customer when they reset their password.
  15. *
  16. * @class WC_Email_Customer_Reset_Password
  17. * @version 2.3.0
  18. * @package WooCommerce/Classes/Emails
  19. * @extends WC_Email
  20. */
  21. class WC_Email_Customer_Reset_Password extends WC_Email {
  22. /**
  23. * User ID.
  24. *
  25. * @var integer
  26. */
  27. public $user_id;
  28. /**
  29. * User login name.
  30. *
  31. * @var string
  32. */
  33. public $user_login;
  34. /**
  35. * User email.
  36. *
  37. * @var string
  38. */
  39. public $user_email;
  40. /**
  41. * Reset key.
  42. *
  43. * @var string
  44. */
  45. public $reset_key;
  46. /**
  47. * Constructor.
  48. */
  49. public function __construct() {
  50. $this->id = 'customer_reset_password';
  51. $this->customer_email = true;
  52. $this->title = __( 'Reset password', 'woocommerce' );
  53. $this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' );
  54. $this->template_html = 'emails/customer-reset-password.php';
  55. $this->template_plain = 'emails/plain/customer-reset-password.php';
  56. // Trigger.
  57. add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 );
  58. // Call parent constructor.
  59. parent::__construct();
  60. }
  61. /**
  62. * Get email subject.
  63. *
  64. * @since 3.1.0
  65. * @return string
  66. */
  67. public function get_default_subject() {
  68. return __( 'Password reset for {site_title}', 'woocommerce' );
  69. }
  70. /**
  71. * Get email heading.
  72. *
  73. * @since 3.1.0
  74. * @return string
  75. */
  76. public function get_default_heading() {
  77. return __( 'Password reset instructions', 'woocommerce' );
  78. }
  79. /**
  80. * Trigger.
  81. *
  82. * @param string $user_login User login.
  83. * @param string $reset_key Password reset key.
  84. */
  85. public function trigger( $user_login = '', $reset_key = '' ) {
  86. $this->setup_locale();
  87. if ( $user_login && $reset_key ) {
  88. $this->object = get_user_by( 'login', $user_login );
  89. $this->user_id = $this->object->ID;
  90. $this->user_login = $user_login;
  91. $this->reset_key = $reset_key;
  92. $this->user_email = stripslashes( $this->object->user_email );
  93. $this->recipient = $this->user_email;
  94. }
  95. if ( $this->is_enabled() && $this->get_recipient() ) {
  96. $this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() );
  97. }
  98. $this->restore_locale();
  99. }
  100. /**
  101. * Get content html.
  102. *
  103. * @access public
  104. * @return string
  105. */
  106. public function get_content_html() {
  107. return wc_get_template_html(
  108. $this->template_html, array(
  109. 'email_heading' => $this->get_heading(),
  110. 'user_id' => $this->user_id,
  111. 'user_login' => $this->user_login,
  112. 'reset_key' => $this->reset_key,
  113. 'blogname' => $this->get_blogname(),
  114. 'sent_to_admin' => false,
  115. 'plain_text' => false,
  116. 'email' => $this,
  117. )
  118. );
  119. }
  120. /**
  121. * Get content plain.
  122. *
  123. * @access public
  124. * @return string
  125. */
  126. public function get_content_plain() {
  127. return wc_get_template_html(
  128. $this->template_plain, array(
  129. 'email_heading' => $this->get_heading(),
  130. 'user_id' => $this->user_id,
  131. 'user_login' => $this->user_login,
  132. 'reset_key' => $this->reset_key,
  133. 'blogname' => $this->get_blogname(),
  134. 'sent_to_admin' => false,
  135. 'plain_text' => true,
  136. 'email' => $this,
  137. )
  138. );
  139. }
  140. }
  141. endif;
  142. return new WC_Email_Customer_Reset_Password();