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