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