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