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