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