1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
4
|
|
|
exit; // Exit if accessed directly |
5
|
|
|
} |
6
|
|
|
|
7
|
|
|
if ( ! class_exists( 'WC_Email_Customer_Reset_Password' ) ) : |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Customer Reset Password. |
11
|
|
|
* |
12
|
|
|
* An email sent to the customer when they reset their password. |
13
|
|
|
* |
14
|
|
|
* @class WC_Email_Customer_Reset_Password |
15
|
|
|
* @version 2.3.0 |
16
|
|
|
* @package WooCommerce/Classes/Emails |
17
|
|
|
* @author WooThemes |
18
|
|
|
* @extends WC_Email |
19
|
|
|
*/ |
20
|
|
|
class WC_Email_Customer_Reset_Password extends WC_Email { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* User login name. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
public $user_login; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* User email. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
public $user_email; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Reset key. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
public $reset_key; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Constructor. |
45
|
|
|
*/ |
46
|
|
|
public function __construct() { |
47
|
|
|
|
48
|
|
|
$this->id = 'customer_reset_password'; |
49
|
|
|
$this->title = __( 'Reset password', 'woocommerce' ); |
50
|
|
|
$this->description = __( 'Customer "reset password" emails are sent when customers reset their passwords.', 'woocommerce' ); |
51
|
|
|
$this->customer_email = true; |
52
|
|
|
|
53
|
|
|
$this->template_html = 'emails/customer-reset-password.php'; |
54
|
|
|
$this->template_plain = 'emails/plain/customer-reset-password.php'; |
55
|
|
|
|
56
|
|
|
$this->subject = __( 'Password Reset for {site_title}', 'woocommerce'); |
57
|
|
|
$this->heading = __( 'Password Reset Instructions', 'woocommerce'); |
58
|
|
|
|
59
|
|
|
// Trigger |
60
|
|
|
add_action( 'woocommerce_reset_password_notification', array( $this, 'trigger' ), 10, 2 ); |
61
|
|
|
|
62
|
|
|
// Call parent constructor |
63
|
|
|
parent::__construct(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Trigger. |
68
|
|
|
* |
69
|
|
|
* @param string $user_login |
70
|
|
|
* @param string $reset_key |
71
|
|
|
*/ |
72
|
|
|
public function trigger( $user_login = '', $reset_key = '' ) { |
73
|
|
|
if ( $user_login && $reset_key ) { |
74
|
|
|
$this->object = get_user_by( 'login', $user_login ); |
75
|
|
|
|
76
|
|
|
$this->user_login = $user_login; |
77
|
|
|
$this->reset_key = $reset_key; |
78
|
|
|
$this->user_email = stripslashes( $this->object->user_email ); |
79
|
|
|
$this->recipient = $this->user_email; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if ( ! $this->is_enabled() || ! $this->get_recipient() ) { |
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$this->send( $this->get_recipient(), $this->get_subject(), $this->get_content(), $this->get_headers(), $this->get_attachments() ); |
87
|
|
|
|
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Get content html. |
92
|
|
|
* |
93
|
|
|
* @access public |
94
|
|
|
* @return string |
95
|
|
|
*/ |
96
|
|
|
public function get_content_html() { |
97
|
|
|
return wc_get_template_html( $this->template_html, array( |
98
|
|
|
'email_heading' => $this->get_heading(), |
99
|
|
|
'user_login' => $this->user_login, |
100
|
|
|
'reset_key' => $this->reset_key, |
101
|
|
|
'blogname' => $this->get_blogname(), |
102
|
|
|
'sent_to_admin' => false, |
103
|
|
|
'plain_text' => false, |
104
|
|
|
'email' => $this |
105
|
|
|
) ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* Get content plain. |
110
|
|
|
* |
111
|
|
|
* @access public |
112
|
|
|
* @return string |
113
|
|
|
*/ |
114
|
|
View Code Duplication |
public function get_content_plain() { |
|
|
|
|
115
|
|
|
return wc_get_template_html( $this->template_plain, array( |
116
|
|
|
'email_heading' => $this->get_heading(), |
117
|
|
|
'user_login' => $this->user_login, |
118
|
|
|
'reset_key' => $this->reset_key, |
119
|
|
|
'blogname' => $this->get_blogname(), |
120
|
|
|
'sent_to_admin' => false, |
121
|
|
|
'plain_text' => true, |
122
|
|
|
'email' => $this |
123
|
|
|
) ); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
endif; |
128
|
|
|
|
129
|
|
|
return new WC_Email_Customer_Reset_Password(); |
130
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.