PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.5
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.5
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 / forms / class-charitable-registration-form.php

class-charitable-registration-form.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.5, at includes/forms/class-charitable-registration-form.php

327 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class that manages the display and processing of the registration form.
4 *
5 * @package Charitable/Classes/Charitable_Registration_Form
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.0.0
10 * @version 1.6.51
11 */
12
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit;
16 }
17
18 if ( ! class_exists( 'Charitable_Registration_Form' ) ) :
19
20 /**
21 * Charitable_Registration_Form
22 *
23 * @since 1.0.0
24 */
25 class Charitable_Registration_Form extends Charitable_Form {
26
27 /**
28 * Shortcode parameters.
29 *
30 * @since 1.0.0
31 *
32 * @var array
33 */
34 protected $shortcode_args;
35
36 /**
37 * Nonce action.
38 *
39 * @since 1.0.0
40 *
41 * @var string
42 */
43 protected $nonce_action = 'charitable_user_registration';
44
45 /**
46 * Nonce name.
47 *
48 * @since 1.0.0
49 *
50 * @var string
51 */
52 protected $nonce_name = '_charitable_user_registration_nonce';
53
54 /**
55 * Action to be executed upon form submission.
56 *
57 * @since 1.0.0
58 *
59 * @var string
60 */
61 protected $form_action = 'save_registration';
62
63 /**
64 * The current donor.
65 *
66 * @since 1.0.0
67 *
68 * @var Charitable_Donor
69 */
70 protected $donor;
71
72 /**
73 * Create class object.
74 *
75 * @since 1.0.0
76 *
77 * @param array $args User-defined shortcode attributes.
78 */
79 public function __construct( $args = array() ) {
80 $this->id = uniqid();
81 $this->shortcode_args = $args;
82
83 /* For backwards-compatibility */
84 add_action( 'charitable_form_field', array( $this, 'render_field' ), 10, 6 );
85 }
86
87 /**
88 * Return the arguments passed to the shortcode.
89 *
90 * @since 1.4.0
91 *
92 * @return mixed[]
93 */
94 public function get_shortcode_args() {
95 return $this->shortcode_args;
96 }
97
98 /**
99 * Profile fields to be displayed.
100 *
101 * @since 1.0.0
102 *
103 * @return array
104 */
105 public function get_fields() {
106 $fields = array(
107 'user_email' => array(
108 'label' => __( 'Email', 'charitable' ),
109 'type' => 'email',
110 'required' => true,
111 'priority' => 4,
112 'value' => isset( $_POST['user_email'] ) ? $_POST['user_email'] : '',
113 ),
114 'user_login' => array(
115 'label' => __( 'Username', 'charitable' ),
116 'type' => 'text',
117 'priority' => 6,
118 'required' => true,
119 'value' => isset( $_POST['user_login'] ) ? $_POST['user_login'] : '',
120 ),
121 'user_pass' => array(
122 'label' => __( 'Password', 'charitable' ),
123 'type' => 'password',
124 'priority' => 8,
125 'required' => true,
126 'value' => isset( $_POST['user_pass'] ) ? $_POST['user_pass'] : '',
127 ),
128 );
129
130 $fields = $this->maybe_add_terms_conditions_fields( $fields );
131
132 /**
133 * Filter the user registration fields.
134 *
135 * @since 1.0.0
136 *
137 * @param array $fields The registered fields.
138 */
139 $fields = apply_filters( 'charitable_user_registration_fields', $fields );
140
141 uasort( $fields, 'charitable_priority_sort' );
142
143 return $fields;
144 }
145
146 /**
147 * Maybe add terms and conditions fields to the form.
148 *
149 * @since 1.6.2
150 *
151 * @param array $fields The registered form fields.
152 * @return array
153 */
154 public function maybe_add_terms_conditions_fields( $fields ) {
155 if ( charitable_is_privacy_policy_activated() ) {
156 $fields['privacy_policy_text'] = array(
157 'type' => 'content',
158 'content' => '<p class="charitable-privacy-policy-text">' . charitable_get_privacy_policy_field_text() . '</p>',
159 'priority' => 20,
160 );
161 }
162
163 if ( charitable_is_contact_consent_activated() ) {
164 $fields['contact_consent'] = array(
165 'type' => 'checkbox',
166 'label' => charitable_get_option( 'contact_consent_label', __( 'Yes, I am happy for you to contact me via email or phone.', 'charitable' ) ),
167 'priority' => 22,
168 'required' => false,
169 'checked' => array_key_exists( 'contact_consent', $_POST ) && $_POST['contact_consent'],
170 );
171 }
172
173 if ( charitable_is_terms_and_conditions_activated() ) {
174 $fields['terms_text'] = array(
175 'type' => 'content',
176 'content' => '<div class="charitable-terms-text">' . charitable_get_terms_and_conditions() . '</div>',
177 'priority' => 24,
178 );
179
180 $fields['accept_terms'] = array(
181 'type' => 'checkbox',
182 'label' => charitable_get_terms_and_conditions_field_label(),
183 'priority' => 28,
184 'required' => true,
185 'data_type' => 'meta',
186 );
187 }
188
189 return $fields;
190 }
191
192 /**
193 * Return the hidden fields for this form.
194 *
195 * @since 1.5.0
196 *
197 * @return array
198 */
199 public function get_hidden_fields() {
200 $fields = parent::get_hidden_fields();
201 $redirect = $this->get_redirect_url();
202
203 if ( false !== $redirect ) {
204 $fields['redirect_to'] = $redirect;
205 }
206
207 return $fields;
208 }
209
210 /**
211 * Update registration after form submission.
212 *
213 * @since 1.0.0
214 *
215 * @return void
216 */
217 public static function save_registration() {
218 $form = new Charitable_Registration_Form();
219
220 if ( ! $form->validate_nonce() || ! $form->validate_honeypot() ) {
221 charitable_get_notices()->add_error( __( 'Unfortunately, we were unable to verify your form submission. Please reload the page and try again.', 'charitable' ) );
222 return;
223 }
224
225 $fields = $form->get_fields();
226 $valid = $form->check_required_fields( $fields );
227
228 if ( ! $valid ) {
229 return;
230 }
231
232 $submitted = apply_filters( 'charitable_registration_values', $form->get_submitted_values(), $fields, $form );
233
234 if ( ! isset( $submitted['user_email'] ) || ! is_email( $submitted['user_email'] ) ) {
235 charitable_get_notices()->add_error(
236 sprintf(
237 /* translators: %s: submitted email address */
238 __( '%s is not a valid email address.', 'charitable' ),
239 $submitted['user_email']
240 )
241 );
242
243 return false;
244 }
245
246 $user = new Charitable_User();
247 $user_id = $user->update_profile( $submitted, array_keys( $fields ) );
248
249 /**
250 * If the user was successfully created, redirect to the login redirect URL.
251 * If there was a problem, this simply falls through and keeps the user on the
252 * registration page.
253 */
254 if ( $user_id ) {
255
256 /* Maybe send an email verification email. */
257 if ( charitable_get_option( array( 'emails_email_verification', 'send_after_registration' ), 1 ) ) {
258
259 /* If the confirmation link is generated correctly and the email is sent, set a notice. */
260 if ( Charitable_User_Management::get_instance()->send_verification_email( $user ) ) {
261 $message = sprintf(
262 /* translators: %s: email verification link */
263 __( 'We have sent you an email to confirm your email address. Haven\'t received the email? <a href="%s">Click here to send it again.</a>', 'charitable' ),
264 esc_url_raw( charitable_get_email_verification_link( $user, false, true ) )
265 );
266
267 charitable_get_notices()->add_success( $message );
268 charitable_get_session()->add_notices();
269 }
270 }
271
272 wp_safe_redirect( charitable_get_login_redirect_url() );
273 exit();
274 }
275 }
276
277 /**
278 * Return the link to the login page, or false if we are not going to display it.
279 *
280 * @since 1.4.2
281 *
282 * @return false|string
283 */
284 public function get_login_link() {
285 if ( false == $this->shortcode_args['login_link_text'] || 'false' == $this->shortcode_args['login_link_text'] ) {
286 return false;
287 }
288
289 $login_link = charitable_get_permalink( 'login_page' );
290
291 if ( charitable_get_permalink( 'registration_page' ) === $login_link ) {
292 return false;
293 }
294
295 if ( isset( $_GET['redirect_to'] ) ) {
296 $login_link = add_query_arg( 'redirect_to', $_GET['redirect_to'], $login_link );
297 }
298
299 return sprintf(
300 '<a href="%1$s">%2$s</a>',
301 esc_url( $login_link ),
302 $this->shortcode_args['login_link_text']
303 );
304 }
305
306 /**
307 * Get the redirect URL.
308 *
309 * @since 1.5.0
310 *
311 * @return string|false
312 */
313 protected function get_redirect_url() {
314 $redirect = false;
315
316 if ( isset( $_GET['redirect_to'] ) && strlen( $_GET['redirect_to'] ) ) {
317 $redirect = $_GET['redirect_to'];
318 } elseif ( isset( $this->shortcode_args['redirect'] ) && strlen( $this->shortcode_args['redirect'] ) ) {
319 $redirect = $this->shortcode_args['redirect'];
320 }
321
322 return $redirect;
323 }
324 }
325
326 endif;
327