PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.15.3
GiveWP – Donation Plugin and Fundraising Platform v4.15.3
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 1 month ago api 3 years ago database 5 months ago deprecated 1 month ago donors 5 months ago emails 9 months ago forms 9 months ago frontend 6 years ago gateways 9 months ago libraries 9 months ago payments 2 months ago actions.php 9 months ago ajax-functions.php 9 months ago class-give-async-process.php 1 year ago class-give-background-updater.php 9 months ago class-give-cache-setting.php 1 year ago class-give-cache.php 9 months ago class-give-cli-commands.php 1 year ago class-give-comment.php 9 months ago class-give-cron.php 9 months ago class-give-donate-form.php 1 year ago class-give-donor.php 2 years ago class-give-email-access.php 5 years ago class-give-license-handler.php 1 month ago class-give-logging.php 9 months ago class-give-readme-parser.php 4 years ago class-give-roles.php 5 months ago class-give-scripts.php 8 months ago class-give-session.php 9 months ago class-give-stats.php 6 years ago class-give-template-loader.php 6 years ago class-give-tooltips.php 6 years ago class-give-translation.php 4 years ago class-notices.php 9 months ago country-functions.php 7 months ago currencies-list.php 7 months ago currency-functions.php 3 years ago error-tracking.php 6 years ago filters.php 9 months ago formatting.php 9 months ago install.php 9 months ago login-register.php 2 years ago misc-functions.php 1 month ago plugin-compatibility.php 6 years ago post-types.php 1 year ago price-functions.php 6 years ago process-donation.php 1 year ago setting-functions.php 6 years ago shortcodes.php 1 year ago template-functions.php 1 year ago user-functions.php 3 years ago
shortcodes.php
1129 lines
1 <?php
2 /**
3 * Give Shortcodes
4 *
5 * @package Give
6 * @subpackage Shortcodes
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 use Give\DonationForms\DonationQuery;
14 use Give\Helpers\Form\Template\Utils\Frontend as FrontendFormTemplateUtils;
15 use Give\Helpers\Form\Utils as FormUtils;
16 use Give\Helpers\Frontend\ConfirmDonation;
17 use Give\Helpers\Frontend\Shortcode as ShortcodeUtils;
18 use Give\Views\IframeView;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * Donation History Shortcode
26 *
27 * Displays a user's donation history.
28 *
29 * @since 3.7.0 Sanitize attributes
30 * @since 3.1.0 pass form id by reference in give_totals shortcode.
31 * @since 1.0
32 *
33 * @param array $atts
34 * @param string|bool $content
35 *
36 * @return string|bool
37 */
38 function give_donation_history( $atts, $content = false ) {
39 $atts = give_clean($atts);
40 $donation_history_args = shortcode_atts(
41 [
42 'id' => true,
43 'date' => true,
44 'donor' => false,
45 'amount' => true,
46 'status' => false,
47 'payment_method' => false,
48 ],
49 $atts,
50 'donation_history'
51 );
52
53 // Always show receipt link.
54 $donation_history_args['details'] = true;
55
56 // Set Donation History Shortcode Arguments in session variable.
57 Give()->session->set( 'give_donation_history_args', $donation_history_args );
58
59 $get_data = give_clean( filter_input_array( INPUT_GET ) );
60
61 // If payment_key query arg exists, return receipt instead of donation history.
62 if (
63 ! empty( $get_data['donation_id'] ) ||
64 (
65 ! empty( $get_data['action'] ) &&
66 'view_in_browser' === $get_data['action']
67 )
68 ) {
69 ob_start();
70
71 echo do_shortcode( ShortcodeUtils::getReceiptShortcodeFromConfirmationPage() );
72
73 // Display donation history link only if Receipt Access Session is available.
74 if ( give_get_receipt_session() || is_user_logged_in() ) {
75 echo sprintf(
76 '<a href="%s">%s</a>',
77 esc_url($_SERVER['HTTP_REFERER'] ),
78 __( '&laquo; Return to All Donations', 'give' )
79 );
80 }
81
82 return ob_get_clean();
83 }
84
85 $email_access = give_get_option( 'email_access' );
86
87 ob_start();
88
89 /**
90 * Determine access
91 *
92 * A. Check if a user is logged in or does a session exists.
93 * B. Does an email-access token exist?
94 */
95 if (
96 is_user_logged_in()
97 || false !== Give()->session->get_session_expiration()
98 || ( give_is_setting_enabled( $email_access ) && Give()->email_access->token_exists )
99 || true === give_get_history_session()
100 ) {
101 give_get_template_part( 'history', 'donations' );
102
103 if ( ! empty( $content ) ) {
104 echo do_shortcode( $content );
105 }
106 } elseif ( give_is_setting_enabled( $email_access ) ) {
107 // Is Email-based access enabled?
108 give_get_template_part( 'email', 'login-form' );
109
110 } else {
111
112 echo 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 ) );
113 echo do_shortcode( '[give_login]' );
114 }
115
116 /**
117 * Filter to modify donation history HTMl
118 *
119 * @since 2.1
120 *
121 * @param string HTML content
122 * @param array $atts
123 * @param string $content content pass between enclose content
124 *
125 * @return string HTML content
126 */
127 return apply_filters( 'give_donation_history_shortcode_html', ob_get_clean(), $atts, $content );
128 }
129
130 add_shortcode( 'donation_history', 'give_donation_history' );
131
132 /**
133 * Donation Form Shortcode
134 *
135 * Show the Give donation form.
136 *
137 * @since 4.3.0 Add check for 'modal' in display_style to allow v2 forms to be shown in a modal.
138 * @since 3.7.0 Sanitize attributes
139 * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status.
140 * @since 2.30.0 Add short-circuit filter to allow for custom output.
141 * @since 1.0
142 *
143
144 * @param array $atts Shortcode attributes
145 *
146 * @return string
147 */
148 function give_form_shortcode( $atts ) {
149 $atts = give_clean($atts);
150 $atts = shortcode_atts( give_get_default_form_shortcode_args(), $atts, 'give_form' );
151
152 if('fullForm' === $atts['display_style']) {
153 $atts['display_style'] = 'onpage';
154 }
155
156 // Convert string to bool.
157 $atts['show_title'] = filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN );
158 $atts['show_goal'] = filter_var( $atts['show_goal'], FILTER_VALIDATE_BOOLEAN );
159
160 // Set form id.
161 $atts['id'] = $atts['id'] ?: FrontendFormTemplateUtils::getFormId();
162 $formId = absint($atts['id']);
163
164 if ( ! ShortcodeUtils::isValidForm($formId)) {
165 ob_start();
166 Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'),
167 true);
168
169 return ob_get_clean();
170 }
171
172 if ( ! ShortcodeUtils::isPublishedForm($formId)) {
173 ob_start();
174 Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true);
175
176 return ob_get_clean();
177 }
178
179 _give_redirect_form_id($formId, $atts['id']);
180
181 // Short-circuit the shortcode output if the filter returns a non-empty string.
182 $output = apply_filters('givewp_form_shortcode_output', '', $atts);
183
184 if ($output) {
185 return $output;
186 }
187
188 // Fetch the Give Form.
189 ob_start();
190
191 if ( ! FormUtils::isLegacyForm( $formId ) ) {
192 $showIframeInModal = 'button' === $atts['display_style'] || 'modal' === $atts['display_style'];
193 $iframeView = new IframeView();
194
195 ConfirmDonation::storePostedDataInDonationSession();
196
197 echo $iframeView->setFormId( $formId )
198 ->showInModal( $showIframeInModal )
199 ->setButtonTitle( $atts['continue_button_title'] )
200 ->setButtonColor( $atts['button_color'] )
201 ->render();
202 } else {
203 give_get_donation_form( $atts );
204 }
205
206 $final_output = ob_get_clean();
207
208 return apply_filters( 'give_donate_form', $final_output, $atts );
209 }
210
211 add_shortcode( 'give_form', 'give_form_shortcode' );
212
213 /**
214 * Donation Form Goal Shortcode.
215 *
216 * Show the Give donation form goals.
217 *
218 * @since 3.12.0 add start_date and end_date attributes
219 * @since 3.7.0 Sanitize attributes
220 * @since 3.4.0 Add additional validations to check if the form is valid and has the 'published' status.
221 * @since 1.0
222 *
223 * @param array $atts Shortcode attributes.
224 *
225 * @return string
226 */
227 function give_goal_shortcode( $atts ) {
228 $atts = give_clean($atts);
229 $atts = shortcode_atts(
230 [
231 'id' => '',
232 'show_text' => true,
233 'show_bar' => true,
234 'color' => '#66BB6A',
235 'start_date' => '',
236 'end_date' => '',
237 ],
238 $atts,
239 'give_goal'
240 );
241
242 _give_redirect_form_id($atts['id']);
243
244 // get the Give Form.
245 ob_start();
246
247 $formId = (int)$atts['id'];
248
249 // Sanity check 1: ensure there is an ID Provided.
250 if ( ! ShortcodeUtils::isValidForm($formId)) {
251 Give_Notices::print_frontend_notice(__('The shortcode is missing a valid Donation Form ID attribute.', 'give'),
252 true);
253 } elseif // Sanity check 2: ensure the form is published.
254 ( ! ShortcodeUtils::isPublishedForm($formId)) {
255 Give_Notices::print_frontend_notice(__('The form is not published.', 'give'), true);
256 } elseif // Sanity check 3: Check the form even has Goals enabled.
257 ( ! give_is_setting_enabled(give_get_meta($atts['id'], '_give_goal_option', true))) {
258
259 Give_Notices::print_frontend_notice( __( 'The form does not have Goals enabled.', 'give' ), true );
260 } else {
261 // Passed all sanity checks: output Goal.
262 give_show_goal_progress( $atts['id'], $atts );
263 }
264
265 $final_output = ob_get_clean();
266
267 return apply_filters( 'give_goal_shortcode_output', $final_output, $atts );
268 }
269
270 add_shortcode( 'give_goal', 'give_goal_shortcode' );
271
272
273 /**
274 * Login Shortcode.
275 *
276 * Shows a login form allowing users to users to log in. This function simply
277 * calls the give_login_form function to display the login form.
278 *
279 * @since 3.7.0 Sanitize attributes
280 * @since 1.0
281 *
282 * @param array $atts Shortcode attributes.
283 *
284 * @uses give_login_form()
285 *
286 * @return string
287 */
288 function give_login_form_shortcode( $atts ) {
289 $atts = give_clean($atts);
290 $atts = shortcode_atts(
291 [
292 // Add backward compatibility for redirect attribute.
293 'redirect' => '',
294 'login-redirect' => '',
295 'logout-redirect' => '',
296 ],
297 $atts,
298 'give_login'
299 );
300
301 // 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.
302 $atts['login-redirect'] = ! empty( $atts['login-redirect'] ) ? $atts['login-redirect'] : ( ! empty( $atts['redirect'] ) ? $atts['redirect'] : '' );
303
304 return give_login_form( $atts['login-redirect'], $atts['logout-redirect'] );
305 }
306
307 add_shortcode( 'give_login', 'give_login_form_shortcode' );
308
309 /**
310 * Register Shortcode.
311 *
312 * Shows a registration form allowing users to users to register for the site.
313 *
314 * @since 3.7.0 Sanitize attributes
315 * @since 1.0
316 *
317 * @param array $atts Shortcode attributes.
318 *
319 * @uses give_register_form()
320 *
321 * @return string
322 */
323 function give_register_form_shortcode( $atts ) {
324 $atts = give_clean($atts);
325 $atts = shortcode_atts(
326 [
327 'redirect' => '',
328 ],
329 $atts,
330 'give_register'
331 );
332
333 return give_register_form( $atts['redirect'] );
334 }
335
336 add_shortcode( 'give_register', 'give_register_form_shortcode' );
337
338 /**
339 * Receipt Shortcode.
340 *
341 * Shows a donation receipt.
342 *
343 * @since 3.16.0 add give_donation_confirmation_page_enqueue_scripts
344 * @since 3.7.0 Sanitize and escape attributes
345 * @since 1.0
346 *
347 * @param array $atts Shortcode attributes.
348 *
349 * @return string
350 */
351 function give_receipt_shortcode( $atts ) {
352
353 global $give_receipt_args;
354
355 $atts = give_clean($atts);
356
357 $give_receipt_args = shortcode_atts(
358 [
359 'error' => __( 'You are missing the donation id to view this donation receipt.', 'give' ),
360 'price' => true,
361 'donor' => true,
362 'date' => true,
363 'payment_method' => true,
364 'payment_id' => true,
365 'payment_status' => false,
366 'company_name' => false,
367 'status_notice' => true,
368 ],
369 $atts,
370 'give_receipt'
371 );
372
373 ob_start();
374
375 $donation_id = false;
376 $receipt_type = false;
377 $get_data = give_clean( filter_input_array( INPUT_GET ) );
378 $session = give_get_purchase_session();
379
380 if ( ! empty( $get_data['donation_id'] ) ) {
381 $donation_id = $get_data['donation_id'];
382 } elseif ( ! empty( $get_data['action'] ) && 'view_in_browser' === $get_data['action'] ) {
383 $receipt_type = 'view_in_browser';
384 $donation_id = $get_data['_give_hash'];
385 } elseif ( isset( $session['donation_id'] ) ) {
386 $donation_id = $session['donation_id'];
387 } elseif ( ! empty( $give_receipt_args['id'] ) ) {
388 $donation_id = $give_receipt_args['id'];
389 }
390
391 // Display donation receipt placeholder while loading receipt via AJAX.
392 if ( ! wp_doing_ajax() ) {
393 give_get_template_part( 'receipt/placeholder' );
394
395 do_action('give_donation_confirmation_page_enqueue_scripts');
396
397 return apply_filters('give_receipt_shortcode_output', sprintf(
398 '<div id="give-receipt" data-shortcode="%1$s" data-receipt-type="%2$s" data-donation-key="%3$s" >%4$s</div>',
399 htmlspecialchars( wp_json_encode( $give_receipt_args ) ),
400 esc_attr($receipt_type),
401 esc_attr($donation_id),
402 ob_get_clean()
403 ));
404 }
405
406 return give_display_donation_receipt( $atts );
407 }
408
409 add_shortcode( 'give_receipt', 'give_receipt_shortcode' );
410
411 /**
412 * Profile Editor Shortcode.
413 *
414 * Outputs the Give Profile Editor to allow users to amend their details from the
415 * front-end. This function uses the Give templating system allowing users to
416 * override the default profile editor template. The profile editor template is located
417 * under templates/shortcode-profile-editor.php, however, it can be altered by creating a
418 * file called shortcode-profile-editor.php in the give_template directory in your active theme's
419 * folder. Please visit the Give Documentation for more information on how the
420 * templating system is used.
421 *
422 * @since 3.7.0 Sanitize attributes
423 * @since 1.0
424 *
425 * @param array $atts Shortcode attributes.
426 *
427 * @return string Output generated from the profile editor
428 */
429 function give_profile_editor_shortcode( $atts ) {
430
431 $atts = give_clean($atts);
432
433 ob_start();
434
435 // Restrict access to donor profile, if donor and user are disconnected.
436 $is_donor_disconnected = get_user_meta( get_current_user_id(), '_give_is_donor_disconnected', true );
437 if ( is_user_logged_in() && $is_donor_disconnected ) {
438 Give_Notices::print_frontend_notice( __( 'Your Donor and User profile are no longer connected. Please contact the site administrator.', 'give' ), true, 'error' );
439
440 return false;
441 }
442
443 give_get_template_part( 'shortcode', 'profile-editor' );
444
445 return ob_get_clean();
446 }
447
448 add_shortcode( 'give_profile_editor', 'give_profile_editor_shortcode' );
449
450 /**
451 * Process Profile Updater Form.
452 *
453 * Processes the profile updater form by updating the necessary fields.
454 *
455 * @since 1.0
456 *
457 * @param array $data Data sent from the profile editor.
458 *
459 * @return bool
460 */
461 function give_process_profile_editor_updates( $data ) {
462 // Profile field change request.
463 if ( empty( $_POST['give_profile_editor_submit'] ) && ! is_user_logged_in() ) {
464 return false;
465 }
466
467 // Nonce security.
468 if ( ! wp_verify_nonce( $data['give_profile_editor_nonce'], 'give-profile-editor-nonce' ) ) {
469 return false;
470 }
471
472 $user_id = get_current_user_id();
473 $old_user_data = get_userdata( $user_id );
474
475 /* @var Give_Donor $donor */
476 $donor = new Give_Donor( $user_id, true );
477 $old_company_name = $donor->get_company_name();
478
479 $display_name = isset( $data['give_display_name'] ) ? sanitize_text_field( $data['give_display_name'] ) : $old_user_data->display_name;
480 $first_name = isset( $data['give_first_name'] ) ? sanitize_text_field( $data['give_first_name'] ) : $old_user_data->first_name;
481 $last_name = isset( $data['give_last_name'] ) ? sanitize_text_field( $data['give_last_name'] ) : $old_user_data->last_name;
482 $company_name = ! empty( $data['give_company_name'] ) ? sanitize_text_field( $data['give_company_name'] ) : $old_company_name;
483 $email = isset( $data['give_email'] ) ? sanitize_email( $data['give_email'] ) : $old_user_data->user_email;
484 $password = ! empty( $data['give_new_user_pass1'] ) ? $data['give_new_user_pass1'] : '';
485 $confirm_password = ! empty( $data['give_new_user_pass2'] ) ? $data['give_new_user_pass2'] : '';
486
487 $userdata = [
488 'ID' => $user_id,
489 'first_name' => $first_name,
490 'last_name' => $last_name,
491 'display_name' => $display_name,
492 'user_email' => $email,
493 'user_pass' => $password,
494 'company_name' => $company_name,
495 ];
496
497 /**
498 * Fires before updating user profile.
499 *
500 * @since 1.0
501 *
502 * @param int $user_id The ID of the user.
503 * @param array $userdata User info, including ID, first name, last name, display name and email.
504 */
505 do_action( 'give_pre_update_user_profile', $user_id, $userdata );
506
507 // Make sure to validate first name of existing donors.
508 if ( empty( $first_name ) ) {
509 // Empty First Name.
510 give_set_error( 'empty_first_name', __( 'Please enter your first name.', 'give' ) );
511 }
512
513 // Make sure to validate passwords for existing Donors.
514 give_validate_user_password( $password, $confirm_password );
515
516 if ( empty( $email ) ) {
517 // Make sure email should not be empty.
518 give_set_error( 'email_empty', __( 'The email you entered is empty.', 'give' ) );
519
520 } elseif ( ! is_email( $email ) ) {
521 // Make sure email should be valid.
522 give_set_error( 'email_not_valid', __( 'The email you entered is not valid. Please use another', 'give' ) );
523
524 } elseif ( $email !== $old_user_data->user_email ) {
525 // Make sure the new email doesn't belong to another user.
526 if ( email_exists( $email ) ) {
527 give_set_error( 'user_email_exists', __( 'The email you entered belongs to another user. Please use another.', 'give' ) );
528 } elseif ( Give()->donors->get_donor_by( 'email', $email ) ) {
529 // Make sure the new email doesn't belong to another user.
530 give_set_error( 'donor_email_exists', __( 'The email you entered belongs to another donor. Please use another.', 'give' ) );
531 }
532 }
533
534 // Check for errors.
535 $errors = give_get_errors();
536
537 if ( $errors ) {
538 // Send back to the profile editor if there are errors.
539 wp_redirect( $data['give_redirect'] );
540 give_die();
541 }
542
543 // Update Donor First Name and Last Name.
544 Give()->donors->update(
545 $donor->id,
546 [
547 'name' => trim( "{$first_name} {$last_name}" ),
548 ]
549 );
550 Give()->donor_meta->update_meta( $donor->id, '_give_donor_first_name', $first_name );
551 Give()->donor_meta->update_meta( $donor->id, '_give_donor_last_name', $last_name );
552 Give()->donor_meta->update_meta( $donor->id, '_give_donor_company', $company_name );
553
554 $current_user = wp_get_current_user();
555
556 // Compares new values with old values to detect change in values.
557 $email_update = ( $email !== $current_user->user_email ) ? true : false;
558 $display_name_update = ( $display_name !== $current_user->display_name ) ? true : false;
559 $first_name_update = ( $first_name !== $current_user->first_name ) ? true : false;
560 $last_name_update = ( $last_name !== $current_user->last_name ) ? true : false;
561 $company_name_update = ( $company_name !== $old_company_name ) ? true : false;
562 $update_code = 0;
563
564 /**
565 * True if update is done in display name, first name, last name or email.
566 *
567 * @var boolean
568 */
569 $profile_update = ( $email_update || $display_name_update || $first_name_update || $last_name_update || $company_name_update );
570
571 /**
572 * True if password fields are filled.
573 *
574 * @var boolean
575 */
576 $password_update = ( ! empty( $password ) && ! empty( $confirm_password ) );
577
578 if ( $profile_update ) {
579
580 // If only profile fields are updated.
581 $update_code = '1';
582
583 if ( $password_update ) {
584
585 // If profile fields AND password both are updated.
586 $update_code = '2';
587 }
588 } elseif ( $password_update ) {
589
590 // If only password is updated.
591 $update_code = '3';
592 }
593
594 // Update the user.
595 $updated = wp_update_user( $userdata );
596
597 if ( $updated ) {
598
599 /**
600 * Fires after updating user profile.
601 *
602 * @since 1.0
603 *
604 * @param int $user_id The ID of the user.
605 * @param array $userdata User info, including ID, first name, last name, display name and email.
606 */
607 do_action( 'give_user_profile_updated', $user_id, $userdata );
608
609 $profile_edit_redirect_args = [
610 'updated' => 'true',
611 'update_code' => $update_code,
612 ];
613
614 /**
615 * Update codes '2' and '3' indicate a password change.
616 * If the password is changed, then logout and redirect to the same page.
617 */
618 if ( '2' === $update_code || '3' === $update_code ) {
619 wp_logout();
620 } else {
621 wp_redirect( esc_url_raw( add_query_arg( $profile_edit_redirect_args, $data['give_redirect'] ) ) );
622 }
623
624 give_die();
625 }
626
627 return false;
628 }
629
630 add_action( 'give_edit_user_profile', 'give_process_profile_editor_updates' );
631
632 /**
633 * Give totals Shortcode.
634 *
635 * Shows a donation total.
636 *
637 * @since 3.14.0 Replace "_give_form_earnings" form meta with $query->form($post)->sumAmount()
638 * @since 3.7.0 Sanitize attributes
639 * @since 2.1
640 *
641 * @param array $atts Shortcode attributes.
642 *
643 * @return string
644 */
645 function give_totals_shortcode( $atts ) {
646 $total = get_option( 'give_earnings_total', false );
647
648 $message = apply_filters( 'give_totals_message', __( 'Hey! We\'ve raised {total} of the {total_goal} we are trying to raise for this campaign!', 'give' ) );
649
650 $atts = shortcode_atts(
651 [
652 'total_goal' => 0, // integer.
653 'ids' => 0, // integer|array.
654 'cats' => 0, // integer|array.
655 'tags' => 0, // integer|array.
656 'message' => $message,
657 'link' => '', // URL.
658 'link_text' => __( 'Donate Now', 'give' ), // string,
659 'progress_bar' => true, // boolean.
660 ],
661 $atts,
662 'give_totals'
663 );
664
665 // Total Goal.
666 $total_goal = give_maybe_sanitize_amount( $atts['total_goal'] );
667
668 $atts = give_clean($atts);
669
670 /**
671 * Give Action fire before the shortcode is rendering is started.
672 *
673 * @since 3.1.0 Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
674 * @since 2.1.4
675 *
676 * @param array $atts shortcode attribute.
677 */
678 do_action( 'give_totals_goal_shortcode_before_render', $atts );
679
680 // Build query based on cat, tag and Form ids.
681 if ( ! empty( $atts['cats'] ) || ! empty( $atts['tags'] ) || ! empty( $atts['ids'] ) ) {
682
683 $form_ids = [];
684 if ( ! empty( $atts['ids'] ) ) {
685 $form_ids = array_filter( array_map( 'trim', explode( ',', $atts['ids'] ) ) );
686 }
687
688 $form_ids = array_map(
689 static function ($id) {
690 _give_redirect_form_id($id);
691
692 return $id;
693 },
694 $form_ids
695 );
696
697 /**
698 * Filter to modify WP Query for Total Goal.
699 *
700 * @since 2.1.4
701 *
702 * @param array WP query argument for Total Goal.
703 */
704 $form_args = [
705 'post_type' => 'give_forms',
706 'post_status' => 'publish',
707 'post__in' => $form_ids,
708 'posts_per_page' => - 1,
709 'fields' => 'ids',
710 'tax_query' => [
711 'relation' => 'AND',
712 ],
713 ];
714
715 if ( ! empty( $atts['cats'] ) ) {
716 $cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) );
717 $form_args['tax_query'][] = [
718 'taxonomy' => 'give_forms_category',
719 'terms' => $cats,
720 ];
721 }
722
723 if ( ! empty( $atts['tags'] ) ) {
724 $tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) );
725 $form_args['tax_query'][] = [
726 'taxonomy' => 'give_forms_tag',
727 'terms' => $tags,
728 ];
729 }
730
731 /**
732 * Filter to modify WP Query for Total Goal.
733 *
734 * @since 2.1.4
735 *
736 * @param array $form_args WP query argument for Total Goal.
737 *
738 * @return array $form_args WP query argument for Total Goal.
739 */
740 $form_args = (array) apply_filters( 'give_totals_goal_shortcode_query_args', $form_args );
741
742 $forms = new WP_Query( $form_args );
743
744 if ( isset( $forms->posts ) ) {
745 $total = 0;
746 foreach ( $forms->posts as $post ) {
747 $query = new DonationQuery();
748 $form_earning = $query->form($post)->sumAmount();
749 $form_earning = ! empty( $form_earning ) ? $form_earning : 0;
750
751 /**
752 * Update Form earnings.
753 *
754 * @since 2.1
755 *
756 * @param int $post Form ID.
757 * @param string $form_earning Total earning of Form.
758 * @param array $atts shortcode attributes.
759 */
760 $total += apply_filters( 'give_totals_form_earning', $form_earning, $post, $atts );
761 }
762 }
763 } // End if().
764
765 // Append link with text.
766 $donate_link = '';
767 if ( ! empty( $atts['link'] ) ) {
768 $donate_link = sprintf( ' <a class="give-totals-text-link" href="%1$s">%2$s</a>', esc_url( $atts['link'] ), esc_html( $atts['link_text'] ) );
769 }
770
771 // Replace {total} in message.
772 $message = str_replace(
773 '{total}',
774 give_currency_filter(
775 give_format_amount(
776 $total,
777 [ 'sanitize' => false ]
778 )
779 ),
780 esc_html( $atts['message'] )
781 );
782
783 // Replace {total_goal} in message.
784 $message = str_replace(
785 '{total_goal}',
786 give_currency_filter(
787 give_format_amount(
788 $total_goal,
789 [ 'sanitize' => true ]
790 )
791 ),
792 $message
793 );
794
795 /**
796 * Update Give totals shortcode output.
797 *
798 * @since 2.1
799 *
800 * @param string $message Shortcode Message.
801 * @param array $atts ShortCode attributes.
802 */
803 $message = apply_filters( 'give_totals_shortcode_message', $message, $atts );
804
805 ob_start();
806 ?>
807 <div class="give-totals-shortcode-wrap">
808 <?php
809 // Show Progress Bar if progress_bar set true.
810 $show_progress_bar = isset( $atts['progress_bar'] ) ? filter_var( $atts['progress_bar'], FILTER_VALIDATE_BOOLEAN ) : true;
811 if ( $show_progress_bar ) {
812 give_show_goal_totals_progress( $total, $total_goal );
813 }
814
815 echo sprintf( $message ) . $donate_link;
816 ?>
817 </div>
818 <?php
819 $give_totals_output = ob_get_clean();
820
821 /**
822 * Give Action fire after the total goal shortcode rendering is end.
823 *
824 * @since 2.1.4
825 *
826 * @param array $atts shortcode attribute.
827 * @param string $give_totals_output shortcode output.
828 */
829 do_action( 'give_totals_goal_shortcode_after_render', $atts, $give_totals_output );
830
831 /**
832 * Give Totals Shortcode output.
833 *
834 * @since 2.1
835 *
836 * @param string $give_totals_output
837 */
838 return apply_filters( 'give_totals_shortcode_output', $give_totals_output );
839
840 }
841
842 add_shortcode( 'give_totals', 'give_totals_shortcode' );
843
844
845 /**
846 * Displays donation forms in a grid layout.
847 *
848 * @since 3.7.0 Sanitize attributes
849 * @since 2.1.0
850 *
851 * @since 3.1.0 Use static function on array_map callback to pass the id as reference for _give_redirect_form_id to prevent warnings on PHP 8.0.1 or plus
852 * @since 2.23.1 Updated the default text color for the donate button, see #6591.
853 * @since 2.21.2 change tag_background_color, progress_bar_color to official green color #69b868.
854 * change tag_text_color color to #333333.
855 * @since 2.20.0 $show_donate_button Option to show donate button
856 * @since 2.20.0 $donate_button_text Default Donate
857 * @since 2.20.0 $donate_button_background_color Default #66bb6a
858 * @since 2.20.0 $donate_button_text_color Default #fff
859 * @since 2.20.0 $show_bar Default false
860 * @since 2.22.2 remove $show_bar attribute in favor of show_goal
861 *
862 * @param array $atts {
863 * Optional. Attributes of the form grid shortcode.
864 *
865 * @type int $forms_per_page Number of forms per page. Default '12'.
866 * @type bool $paged Whether to paginate forms. Default 'true'.
867 * @type string $ids A comma-separated list of form IDs to display. Default empty.
868 * @type string exclude A comma-separated list of form IDs to exclude from display. Default empty.
869 * @type string $cats A comma-separated list of form categories to display. Default empty.
870 * @type string $tags A comma-separated list of form tags to display. Default empty.
871 * @type string $columns Maximum columns to display. Default 'best-fit'.
872 * Accepts 'best-fit', '1', '2', '3', '4'.
873 * @type bool $show_title Whether to display form title. Default 'true'.
874 * @type bool $show_goal Whether to display form goal. Default 'true'.
875 * @type bool $show_excerpt Whether to display form excerpt. Default 'true'.
876 * @type bool $show_featured_image Whether to display featured image. Default 'true'.
877 * @type string $image_size Featured image size. Default 'medium'. Accepts WordPress image sizes.
878 * @type string $image_height Featured image height. Default 'auto'. Accepts valid CSS heights.
879 * @type int $excerpt_length Number of words before excerpt is truncated. Default '16'.
880 * @type string $display_style How the form is displayed, either in new page or modal popup.
881 * Default 'redirect'. Accepts 'redirect', 'modal'.
882 *
883 * @return string|bool The markup of the form grid or false.
884 */
885 function give_form_grid_shortcode( $atts ) {
886 $atts = give_clean($atts);
887 $give_settings = give_get_settings();
888
889 $atts = shortcode_atts(
890 [
891 'forms_per_page' => 12,
892 'paged' => true,
893 'ids' => '',
894 'exclude' => '',
895 'orderby' => 'date',
896 'order' => 'DESC',
897 'cats' => '',
898 'tags' => '',
899 'columns' => '1',
900 'show_title' => true,
901 'show_goal' => true,
902 'show_excerpt' => true,
903 'show_featured_image' => true,
904 'show_donate_button' => true,
905 'donate_button_text' => '',
906 'tag_background_color' => '#69b868',
907 'tag_text_color' => '#333333',
908 'donate_button_text_color' => '#000000',
909 'image_size' => 'medium',
910 'image_height' => 'auto',
911 'excerpt_length' => 16,
912 'display_style' => 'modal_reveal',
913 'progress_bar_color' => '#69b868',
914 'status' => '', // open or closed.
915 ],
916 $atts
917 );
918
919 // Validate integer attributes.
920 $atts['forms_per_page'] = intval( $atts['forms_per_page'] );
921 $atts['excerpt_length'] = intval( $atts['excerpt_length'] );
922
923 // Validate boolean attributes.
924 $boolean_attributes = [
925 'paged',
926 'show_title',
927 'show_goal',
928 'show_excerpt',
929 'show_featured_image',
930 ];
931
932 foreach ( $boolean_attributes as $att ) {
933 $atts[ $att ] = filter_var( $atts[ $att ], FILTER_VALIDATE_BOOLEAN );
934 }
935
936 // Set default form query args.
937 $form_args = [
938 'post_type' => 'give_forms',
939 'post_status' => 'publish',
940 'posts_per_page' => $atts['forms_per_page'],
941 'orderby' => $atts['orderby'],
942 'order' => $atts['order'],
943 'paged' => $atts['paged'],
944 'tax_query' => [
945 'relation' => 'AND',
946 ],
947 ];
948
949 // Filter results of form grid based on form status.
950 $form_closed_status = trim( $atts['status'] );
951
952 if ( ! empty( $form_closed_status ) ) {
953 $form_args['meta_query'] = [
954 [
955 'key' => '_give_form_status',
956 'value' => $form_closed_status,
957 ],
958 ];
959 }
960
961 // Maybe add pagination.
962 if ( true === $atts['paged'] ) {
963 $form_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
964 }
965
966 // Maybe filter forms by IDs.
967 if ( ! empty( $atts['ids'] ) ) {
968 $form_args['post__in'] = array_map(
969 static function ($id) {
970 _give_redirect_form_id($id);
971
972 return $id;
973 }, array_filter(array_map('trim', explode(',', $atts['ids'])))
974 );
975 }
976
977 // Convert comma-separated form IDs into array.
978 if ( ! empty( $atts['exclude'] ) ) {
979 $form_args['post__not_in'] = array_filter(
980 array_map(
981 function( $item ) {
982 return intval( trim( $item ) );
983 },
984 explode( ',', $atts['exclude'] )
985 )
986 );
987 }
988
989 // Maybe filter by form category.
990 if ( ! empty( $atts['cats'] ) ) {
991 $cats = array_filter( array_map( 'trim', explode( ',', $atts['cats'] ) ) );
992
993 // Backward compatibility for term_ids.
994 $term_ids = array_unique( array_filter( $cats, 'is_numeric' ) );
995 if ( $term_ids ) {
996 $form_args['tax_query'][] = [
997 'taxonomy' => 'give_forms_category',
998 'terms' => $term_ids,
999 ];
1000
1001 }
1002
1003 $term_slug = array_unique( array_filter( array_diff( $cats, $term_ids ) ) );
1004 if ( $term_slug ) {
1005 $form_args['tax_query'][] = [
1006 'taxonomy' => 'give_forms_category',
1007 'field' => 'slug',
1008 'terms' => $term_slug,
1009 ];
1010
1011 }
1012 }
1013
1014 // Maybe filter by form tag.
1015 if ( ! empty( $atts['tags'] ) ) {
1016 $tags = array_filter( array_map( 'trim', explode( ',', $atts['tags'] ) ) );
1017
1018 // Backward compatibility for term_ids.
1019 $tag_ids = array_unique( array_filter( $tags, 'is_numeric' ) );
1020 if ( $tag_ids ) {
1021 $form_args['tax_query'][] = [
1022 'taxonomy' => 'give_forms_tag',
1023 'terms' => $tag_ids,
1024 ];
1025
1026 }
1027
1028 $tag_slug = array_unique( array_filter( array_diff( $tags, $tag_ids ) ) );
1029 if ( $tag_slug ) {
1030 $form_args['tax_query'][] = [
1031 'taxonomy' => 'give_forms_tag',
1032 'field' => 'slug',
1033 'terms' => $tag_slug,
1034 ];
1035
1036 }
1037 }
1038
1039 /**
1040 * Filter to modify WP Query for Total Goal.
1041 *
1042 * @since 2.1.4
1043 *
1044 * @param array $form_args WP query argument for Grid.
1045 *
1046 * @return array $form_args WP query argument for Grid.
1047 */
1048 $form_args = (array) apply_filters( 'give_form_grid_shortcode_query_args', $form_args );
1049
1050 // Maybe filter by form Amount Donated or Number of Donations.
1051 switch ( $atts['orderby'] ) {
1052 case 'amount_donated':
1053 $form_args['meta_key'] = '_give_form_earnings';
1054 $form_args['orderby'] = 'meta_value_num';
1055 break;
1056 case 'number_donations':
1057 $form_args['meta_key'] = '_give_form_sales';
1058 $form_args['orderby'] = 'meta_value_num';
1059 break;
1060 case 'random':
1061 $form_args['orderby'] = 'rand';
1062 break;
1063 case 'closest_to_goal':
1064 if ( give_has_upgrade_completed( 'v240_update_form_goal_progress' ) ) {
1065 $form_args['meta_key'] = '_give_form_goal_progress';
1066 $form_args['orderby'] = 'meta_value_num';
1067 }
1068 break;
1069 }
1070
1071 // Query to output donation forms.
1072 $form_query = new WP_Query( $form_args );
1073
1074 if ( $form_query->have_posts() ) {
1075 ob_start();
1076
1077 add_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class', 10, 1 );
1078 add_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class', 10, 1 );
1079 add_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10, 3 );
1080 add_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10, 3 );
1081
1082 echo '<div class="give-wrap">';
1083 echo '<div class="give-grid give-grid--' . esc_attr( $atts['columns'] ) . '">';
1084
1085 while ( $form_query->have_posts() ) {
1086 $form_query->the_post();
1087
1088 // Give/templates/shortcode-form-grid.php.
1089 give_get_template( 'shortcode-form-grid', [ $give_settings, $atts ] );
1090
1091 }
1092
1093 wp_reset_postdata();
1094
1095 echo '</div><!-- .give-grid -->';
1096
1097 remove_filter( 'add_give_goal_progress_class', 'add_give_goal_progress_class' );
1098 remove_filter( 'add_give_goal_progress_bar_class', 'add_give_goal_progress_bar_class' );
1099 remove_filter( 'give_form_wrap_classes', 'add_class_for_form_grid', 10 );
1100 remove_action( 'give_donation_form_top', 'give_is_form_grid_page_hidden_field', 10 );
1101
1102 if ( false !== $atts['paged'] ) {
1103 $paginate_args = [
1104 'current' => max( 1, get_query_var( 'paged' ) ),
1105 'total' => $form_query->max_num_pages,
1106 'show_all' => false,
1107 'end_size' => 1,
1108 'mid_size' => 2,
1109 'prev_next' => true,
1110 'prev_text' => __( '&laquo; Previous', 'give' ),
1111 'next_text' => __( 'Next &raquo;', 'give' ),
1112 'type' => 'plain',
1113 'add_args' => false,
1114 ];
1115
1116 printf(
1117 '<div class="give-page-numbers">%s</div>',
1118 paginate_links( $paginate_args )
1119 );
1120 }
1121 echo '</div><!-- .give-wrap -->';
1122
1123 return ob_get_clean();
1124 } // End if().
1125 }
1126
1127 add_shortcode( 'give_form_grid', 'give_form_grid_shortcode' );
1128
1129