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