PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.9
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.9
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / emails / class-charitable-email-password-reset.php

class-charitable-email-password-reset.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.9, at includes/emails/class-charitable-email-password-reset.php

252 lines 5.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that models the Password Reset email.
4 *
5 * @package Charitable/Classes/Charitable_Email_Password_Reset
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.4.0
10 * @version 1.6.37
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Email_Password_Reset' ) ) :
18
19 /**
20 * Password Reset Email
21 *
22 * @since 1.4.0
23 */
24 class Charitable_Email_Password_Reset extends Charitable_Email {
25
26 /** Email ID */
27 const ID = 'password_reset';
28
29 /**
30 * Whether the email allows you to define the email recipients.
31 *
32 * @since 1.4.0
33 *
34 * @var boolean
35 */
36 protected $has_recipient_field = false;
37
38 /**
39 * The Password Reset email is required.
40 *
41 * @since 1.4.0
42 *
43 * @var boolean
44 */
45 protected $required = true;
46
47 /**
48 * The user data.
49 *
50 * @since 1.4.0
51 *
52 * @var WP_User
53 */
54 protected $user;
55
56 /**
57 * Array of supported object types (campaigns, donations, donors, etc).
58 *
59 * @since 1.4.0
60 *
61 * @var string[]
62 */
63 protected $object_types = array( 'user' );
64
65 /**
66 * The reset link.
67 *
68 * @since 1.4.0
69 *
70 * @var string|WP_Error
71 */
72 protected $reset_link;
73
74 /**
75 * Instantiate the email class, defining its key values.
76 *
77 * @since 1.4.0
78 *
79 * @param mixed[] $objects Array containing a user object,
80 * or nothing if this is a preview.
81 */
82 public function __construct( $objects = array() ) {
83 parent::__construct( $objects );
84
85 /**
86 * Filter the default email name.
87 *
88 * @since 1.4.0
89 *
90 * @param string $name The email name.
91 */
92 $this->name = apply_filters( 'charitable_email_password_reset_name', __( 'User: Password Reset', 'charitable' ) );
93
94 $this->user = array_key_exists( 'user', $objects ) ? $objects['user'] : false;
95 }
96
97 /**
98 * Returns the current email's ID.
99 *
100 * @since 1.4.0
101 *
102 * @return string
103 */
104 public static function get_email_id() {
105 return self::ID;
106 }
107
108 /**
109 * Return the recipient for the email.
110 *
111 * @since 1.4.0
112 *
113 * @return string
114 */
115 public function get_recipient() {
116 return $this->has_valid_user() ? $this->user->user_email : '';
117 }
118
119 /**
120 * Return the custom email fields for this email.
121 *
122 * @since 1.5.0
123 *
124 * @return array
125 */
126 public function email_fields() {
127 /* If we are using the default WordPress login process, return an empty array. */
128 if ( wp_login_url() == charitable_get_permalink( 'login_page' ) ) {
129 return array();
130 }
131
132 $fields = array(
133 'reset_link' => array(
134 'description' => __( 'The link the user needs to click to reset their password', 'charitable' ),
135 'preview' => add_query_arg( array(
136 'key' => '123123123',
137 'login' => 'adam123',
138 ), charitable_get_permalink( 'reset_password_page' ) ),
139 ),
140 );
141
142 if ( $this->has_valid_user() ) {
143 $fields = array_merge_recursive( $fields, array(
144 'reset_link' => array( 'callback' => array( $this, 'get_reset_link' ) ),
145 ) );
146 }
147
148 return $fields;
149 }
150
151 /**
152 * Return the reset link.
153 *
154 * @since 1.5.0
155 *
156 * @return string|WP_Error|false If the reset key could not be generated, an error is returned.
157 */
158 public function get_reset_link() {
159 if ( ! isset( $this->reset_link ) ) {
160 $base_url = charitable_get_permalink( 'reset_password_page' );
161 $key = get_password_reset_key( $this->user );
162
163 if ( is_wp_error( $key ) ) {
164 return $key;
165 }
166
167 $this->reset_link = esc_url_raw(
168 add_query_arg(
169 array(
170 'key' => $key,
171 'login' => rawurlencode( $this->user->user_login ),
172 'charitable' => true,
173 ),
174 $base_url
175 )
176 );
177 }
178
179 return $this->reset_link;
180 }
181
182 /**
183 * Return the default subject line for the email.
184 *
185 * @since 1.4.0
186 *
187 * @return string
188 */
189 protected function get_default_subject() {
190 return __( 'Password Reset for [charitable_email show=site_name]', 'charitable' );
191 }
192
193 /**
194 * Return the default headline for the email.
195 *
196 * @since 1.4.0
197 *
198 * @return string
199 */
200 protected function get_default_headline() {
201 /**
202 * Filter the default email headline.
203 *
204 * @since 1.4.0
205 *
206 * @param string $headline The default headline.
207 * @param Charitable_Email_Password_Reset $email This instance of `Charitable_Email_Password_Reset`.
208 */
209 return apply_filters( 'charitable_email_password_reset_default_headline', __( 'Reset your password', 'charitable' ), $this );
210 }
211
212 /**
213 * Return the default body for the email.
214 *
215 * @since 1.4.0
216 *
217 * @return string
218 */
219 protected function get_default_body() {
220 ob_start();
221 ?>
222 <p><?php _e( 'Someone requested that the password be reset for the following account:', 'charitable' ) ?></p>
223 <p><?php _e( 'Username: [charitable_email show=user_login]', 'charitable' ) ?></p>
224 <p><?php _e( 'If this was a mistake, just ignore this email and nothing will happen.', 'charitable' ) ?></p>
225 <p><?php _e( 'To reset your password, visit the following address:', 'charitable' ) ?></p>
226 <p><a href="[charitable_email show=reset_link]">[charitable_email show=reset_link]</a></p>
227 <?php
228 /**
229 * Filter the default email body.
230 *
231 * @since 1.4.0
232 *
233 * @param string $body The default body text.
234 * @param Charitable_Email_Password_Reset $email This instance of `Charitable_Email_Password_Reset`.
235 */
236 return apply_filters( 'charitable_email_password_reset_default_body', ob_get_clean(), $this );
237 }
238
239 /**
240 * Check whether a user is set for the object instance.
241 *
242 * @since 1.5.0
243 *
244 * @return boolean
245 */
246 protected function has_valid_user() {
247 return isset( $this->user ) && is_a( $this->user, 'WP_User' );
248 }
249 }
250
251 endif;
252