PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.4
GiveWP – Donation Plugin and Fundraising Platform v2.0.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / shortcodes.php
give / includes Last commit date
admin 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-roles.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 9 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago scripts.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
shortcodes.php
546 lines
1 <?php
2 /**
3 * Give Shortcodes
4 *
5 * @package Give
6 * @subpackage Shortcodes
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Donation History Shortcode
19 *
20 * Displays a user's donation history.
21 *
22 * @since 1.0
23 *
24 * @return string|bool
25 */
26 function give_donation_history( $atts ) {
27
28 $donation_history_args = shortcode_atts( array(
29 'id' => true,
30 'date' => true,
31 'donor' => false,
32 'amount' => true,
33 'status' => false,
34 'payment_method' => false,
35 ), $atts, 'donation_history' );
36
37 // Always show receipt link.
38 $donation_history_args['details'] = true;
39
40 // Set Donation History Shortcode Arguments in session variable.
41 Give()->session->set( 'give_donation_history_args', $donation_history_args );
42
43 // If payment_key query arg exists, return receipt instead of donation history.
44 if ( isset( $_GET['payment_key'] ) ) {
45 ob_start();
46
47 echo give_receipt_shortcode( array() );
48
49 // Display donation history link only if Receipt Access Session is available.
50 if ( give_get_receipt_session() ) {
51 echo sprintf(
52 '<a href="%s">%s</a>',
53 esc_url( give_get_history_page_uri() ),
54 __( '&laquo; Return to All Donations', 'give' )
55 );
56 }
57 return ob_get_clean();
58 }
59
60 $email_access = give_get_option( 'email_access' );
61
62 /**
63 * Determine access
64 *
65 * a. Check if a user is logged in or does a session exists
66 * b. Does an email-access token exist?
67 */
68 if (
69 is_user_logged_in() ||
70 false !== Give()->session->get_session_expiration() ||
71 ( give_is_setting_enabled( $email_access ) && Give()->email_access->token_exists ) ||
72 true === give_get_history_session()
73 ) {
74 ob_start();
75 give_get_template_part( 'history', 'donations' );
76
77 return ob_get_clean();
78
79 } elseif ( give_is_setting_enabled( $email_access ) ) {
80 // Is Email-based access enabled?
81 ob_start();
82 give_get_template_part( 'email', 'login-form' );
83
84 return ob_get_clean();
85
86 } else {
87
88 $output = apply_filters( 'give_donation_history_nonuser_message', Give()->notices->print_frontend_notice( __( 'You must be logged in to view your donation history. Please login using your account or create an account using the same email you used to donate with.', 'give' ), false ) );
89 $output .= do_shortcode( '[give_login]' );
90
91 return $output;
92 }
93 }
94
95 add_shortcode( 'donation_history', 'give_donation_history' );
96
97 /**
98 * Donation Form Shortcode
99 *
100 * Show the Give donation form.
101 *
102 * @since 1.0
103 *
104 * @param array $atts Shortcode attributes
105 *
106 * @return string
107 */
108 function give_form_shortcode( $atts ) {
109 $atts = shortcode_atts( array(
110 'id' => '',
111 'show_title' => true,
112 'show_goal' => true,
113 'show_content' => '',
114 'float_labels' => '',
115 'display_style' => '',
116 'continue_button_title' => '',
117 ), $atts, 'give_form' );
118
119 // Convert string to bool.
120 $atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN );
121 $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN );
122
123 // get the Give Form
124 ob_start();
125 give_get_donation_form( $atts );
126 $final_output = ob_get_clean();
127
128 return apply_filters( 'give_donate_form', $final_output, $atts );
129 }
130
131 add_shortcode( 'give_form', 'give_form_shortcode' );
132
133 /**
134 * Donation Form Goal Shortcode.
135 *
136 * Show the Give donation form goals.
137 *
138 * @since 1.0
139 *
140 * @param array $atts Shortcode attributes.
141 *
142 * @return string
143 */
144 function give_goal_shortcode( $atts ) {
145 $atts = shortcode_atts( array(
146 'id' => '',
147 'show_text' => true,
148 'show_bar' => true,
149 ), $atts, 'give_goal' );
150
151 // get the Give Form.
152 ob_start();
153
154 // Sanity check 1: ensure there is an ID Provided.
155 if ( empty( $atts['id'] ) ) {
156 Give()->notices->print_frontend_notice( __( 'The shortcode is missing Donation Form ID attribute.', 'give' ), true );
157 }
158
159 // Sanity check 2: Check the form even has Goals enabled.
160 if ( ! give_is_setting_enabled( give_get_meta( $atts['id'], '_give_goal_option', true ) ) ) {
161
162 Give()->notices->print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true );
163 } else {
164 // Passed all sanity checks: output Goal.
165 give_show_goal_progress( $atts['id'], $atts );
166 }
167
168 $final_output = ob_get_clean();
169
170 return apply_filters( 'give_goal_shortcode_output', $final_output, $atts );
171 }
172
173 add_shortcode( 'give_goal', 'give_goal_shortcode' );
174
175
176 /**
177 * Login Shortcode.
178 *
179 * Shows a login form allowing users to users to log in. This function simply
180 * calls the give_login_form function to display the login form.
181 *
182 * @since 1.0
183 *
184 * @param array $atts Shortcode attributes.
185 *
186 * @uses give_login_form()
187 *
188 * @return string
189 */
190 function give_login_form_shortcode( $atts ) {
191
192 $atts = shortcode_atts( array(
193 // Add backward compatibility for redirect attribute.
194 'redirect' => '',
195 'login-redirect' => '',
196 'logout-redirect' => '',
197 ), $atts, 'give_login' );
198
199 // Check login-redirect attribute first, if it empty or not found then check for redirect attribute and add value of this to login-redirect attribute.
200 $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect'] ) ? $atts['redirect'] : '' );
201
202 return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] );
203 }
204
205 add_shortcode( 'give_login', 'give_login_form_shortcode' );
206
207 /**
208 * Register Shortcode.
209 *
210 * Shows a registration form allowing users to users to register for the site.
211 *
212 * @since 1.0
213 *
214 * @param array $atts Shortcode attributes.
215 *
216 * @uses give_register_form()
217 *
218 * @return string
219 */
220 function give_register_form_shortcode( $atts ) {
221 $atts = shortcode_atts( array(
222 'redirect' => '',
223 ), $atts, 'give_register' );
224
225 return give_register_form( $atts['redirect'] );
226 }
227
228 add_shortcode( 'give_register', 'give_register_form_shortcode' );
229
230 /**
231 * Receipt Shortcode.
232 *
233 * Shows a donation receipt.
234 *
235 * @since 1.0
236 *
237 * @param array $atts Shortcode attributes.
238 *
239 * @return string
240 */
241 function give_receipt_shortcode( $atts ) {
242
243 global $give_receipt_args;
244
245 $give_receipt_args = shortcode_atts( array(
246 'error' => __( 'You are missing the payment key to view this donation receipt.', 'give' ),
247 'price' => true,
248 'donor' => true,
249 'date' => true,
250 'payment_key' => false,
251 'payment_method' => true,
252 'payment_id' => true,
253 'payment_status' => false,
254 'status_notice' => true,
255 ), $atts, 'give_receipt' );
256
257 // set $session var
258 $session = give_get_purchase_session();
259
260 // set payment key var
261 if ( isset( $_GET['payment_key'] ) ) {
262 $payment_key = urldecode( $_GET['payment_key'] );
263 } elseif ( $session ) {
264 $payment_key = $session['purchase_key'];
265 } elseif ( $give_receipt_args['payment_key'] ) {
266 $payment_key = $give_receipt_args['payment_key'];
267 }
268
269 $email_access = give_get_option( 'email_access' );
270
271 // No payment_key found & Email Access is Turned on.
272 if ( ! isset( $payment_key ) && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) {
273
274 ob_start();
275
276 give_get_template_part( 'email-login-form' );
277
278 return ob_get_clean();
279
280 } elseif ( ! isset( $payment_key ) ) {
281
282 return Give()->notices->print_frontend_notice( $give_receipt_args['error'], false, 'error' );
283
284 }
285
286 $user_can_view = give_can_view_receipt( $payment_key );
287
288 // Key was provided, but user is logged out. Offer them the ability to login and view the receipt.
289 if ( ! $user_can_view && give_is_setting_enabled( $email_access ) && ! Give()->email_access->token_exists ) {
290
291 ob_start();
292
293 give_get_template_part( 'email-login-form' );
294
295 return ob_get_clean();
296
297 } elseif ( ! $user_can_view ) {
298
299 global $give_login_redirect;
300
301 $give_login_redirect = give_get_current_page_url();
302
303 ob_start();
304
305 Give()->notices->print_frontend_notice( apply_filters( 'give_must_be_logged_in_error_message', __( 'You must be logged in to view this donation receipt.', 'give' ) ) );
306
307 give_get_template_part( 'shortcode', 'login' );
308
309 $login_form = ob_get_clean();
310
311 return $login_form;
312 }
313
314 /**
315 * Check if the user has permission to view the receipt.
316 *
317 * If user is logged in, user ID is compared to user ID of ID stored in payment meta
318 * or if user is logged out and donation was made as a guest, the donation session is checked for
319 * or if user is logged in and the user can view sensitive shop data.
320 */
321 if ( ! apply_filters( 'give_user_can_view_receipt', $user_can_view, $give_receipt_args ) ) {
322 return Give()->notices->print_frontend_notice( $give_receipt_args['error'], false, 'error' );
323 }
324
325 ob_start();
326
327 give_get_template_part( 'shortcode', 'receipt' );
328
329 $display = ob_get_clean();
330
331 return $display;
332 }
333
334 add_shortcode( 'give_receipt', 'give_receipt_shortcode' );
335
336 /**
337 * Profile Editor Shortcode.
338 *
339 * Outputs the Give Profile Editor to allow users to amend their details from the
340 * front-end. This function uses the Give templating system allowing users to
341 * override the default profile editor template. The profile editor template is located
342 * under templates/profile-editor.php, however, it can be altered by creating a
343 * file called profile-editor.php in the give_template directory in your active theme's
344 * folder. Please visit the Give Documentation for more information on how the
345 * templating system is used.
346 *
347 * @since 1.0
348 *
349 * @param array $atts Shortcode attributes.
350 *
351 * @return string Output generated from the profile editor
352 */
353 function give_profile_editor_shortcode( $atts ) {
354
355 ob_start();
356
357 // Restrict access to donor profile, if donor and user are disconnected.
358 $is_donor_disconnected = get_user_meta( get_current_user_id(), '_give_is_donor_disconnected', true );
359 if ( is_user_logged_in() && $is_donor_disconnected ) {
360 Give()->notices->print_frontend_notice( __( 'Your Donor and User profile are no longer connected. Please contact the site administrator.', 'give' ), true, 'error' );
361 return false;
362 }
363
364 give_get_template_part( 'shortcode', 'profile-editor' );
365
366 $display = ob_get_clean();
367
368 return $display;
369 }
370
371 add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' );
372
373 /**
374 * Process Profile Updater Form.
375 *
376 * Processes the profile updater form by updating the necessary fields.
377 *
378 * @since 1.0
379 *
380 * @param array $data Data sent from the profile editor.
381 *
382 * @return bool
383 */
384 function give_process_profile_editor_updates( $data ) {
385 // Profile field change request.
386 if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) {
387 return false;
388 }
389
390 // Nonce security.
391 if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) {
392 return false;
393 }
394
395 $user_id = get_current_user_id();
396 $old_user_data = get_userdata( $user_id );
397
398 /* @var Give_Donor $donor */
399 $donor = new Give_Donor( $user_id, true );
400
401 $display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name;
402 $first_name = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name;
403 $last_name = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name;
404 $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email;
405 $password = ! empty( $data['give_new_user_pass1'] ) ? $data['give_new_user_pass1'] : '';
406 $confirm_password = ! empty( $data['give_new_user_pass2'] ) ? $data['give_new_user_pass2'] : '';
407
408 $userdata = array(
409 'ID' => $user_id,
410 'first_name' => $first_name,
411 'last_name' => $last_name,
412 'display_name' => $display_name,
413 'user_email' => $email,
414 'user_pass' => $password,
415 );
416
417 /**
418 * Fires before updating user profile.
419 *
420 * @since 1.0
421 *
422 * @param int $user_id The ID of the user.
423 * @param array $userdata User info, including ID, first name, last name, display name and email.
424 */
425 do_action( 'give_pre_update_user_profile', $user_id, $userdata );
426
427 // Make sure to validate first name of existing donors.
428 if ( empty( $first_name ) ) {
429 // Empty First Name.
430 give_set_error( 'empty_first_name', __( 'Please enter your first name.', 'give' ) );
431 }
432
433 // Make sure to validate passwords for existing Donors.
434 give_validate_user_password( $password, $confirm_password );
435
436 if ( empty( $email ) ) {
437 // Make sure email should not be empty.
438 give_set_error( 'email_empty', __( 'The email you entered is empty.', 'give' ) );
439
440 } elseif ( ! is_email( $email ) ) {
441 // Make sure email should be valid.
442 give_set_error( 'email_not_valid', __( 'The email you entered is not valid. Please use another', 'give' ) );
443
444 } elseif ( $email != $old_user_data->user_email ) {
445 // Make sure the new email doesn't belong to another user.
446 if ( email_exists( $email ) ) {
447 give_set_error( 'user_email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) );
448 } elseif ( Give()->donors->get_donor_by( 'email', $email ) ) {
449 // Make sure the new email doesn't belong to another user.
450 give_set_error( 'donor_email_exists', __( 'The email you entered belongs to another donor. Please use another.', 'give' ) );
451 }
452 }
453
454 // Check for errors.
455 $errors = give_get_errors();
456
457 if ( $errors ) {
458 // Send back to the profile editor if there are errors.
459 wp_redirect( $data['give_redirect'] );
460 give_die();
461 }
462
463 // Update Donor First Name and Last Name.
464 Give()->donors->update( $donor->id, array(
465 'name' => trim( "{$first_name} {$last_name}" ),
466 ) );
467 Give()->donor_meta->update_meta( $donor->id, '_give_donor_first_name', $first_name );
468 Give()->donor_meta->update_meta( $donor->id, '_give_donor_last_name', $last_name );
469
470 $current_user = wp_get_current_user();
471
472 // Compares new values with old values to detect change in values.
473 $email_update = ( $email !== $current_user->user_email ) ? true : false;
474 $display_name_update = ( $display_name !== $current_user->display_name ) ? true : false;
475 $first_name_update = ( $first_name !== $current_user->first_name ) ? true : false;
476 $last_name_update = ( $last_name !== $current_user->last_name ) ? true : false;
477 $update_code = 0;
478
479 /**
480 * True if update is done in display name, first name, last name or email.
481 *
482 * @var boolean
483 */
484 $profile_update = ( $email_update || $display_name_update || $first_name_update || $last_name_update );
485
486 /**
487 * True if password fields are filled.
488 *
489 * @var boolean
490 */
491 $password_update = ( ! empty( $password ) && ! empty( $confirm_password ) );
492
493 if ( $profile_update ) {
494
495 // If only profile fields are updated.
496 $update_code = '1';
497
498 if ( $password_update ) {
499
500 // If profile fields AND password both are updated.
501 $update_code = '2';
502 }
503 } elseif ( $password_update ) {
504
505 // If only password is updated.
506 $update_code = '3';
507 }
508
509 // Update the user.
510 $updated = wp_update_user( $userdata );
511
512 if ( $updated ) {
513
514 /**
515 * Fires after updating user profile.
516 *
517 * @since 1.0
518 *
519 * @param int $user_id The ID of the user.
520 * @param array $userdata User info, including ID, first name, last name, display name and email.
521 */
522 do_action( 'give_user_profile_updated', $user_id, $userdata );
523
524 $profile_edit_redirect_args = array(
525 'updated' => 'true',
526 'update_code' => $update_code,
527 );
528
529 /**
530 * Update codes '2' and '3' indicate a password change.
531 * If the password is changed, then logout and redirect to the same page.
532 */
533 if ( '2' === $update_code || '3' === $update_code ) {
534 wp_logout( wp_redirect( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) ) );
535 } else {
536 wp_redirect( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) );
537 }
538
539 give_die();
540 }
541
542 return false;
543 }
544
545 add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' );
546