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