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 | templates/shortcode-form-grid.php +80 -55 2.30.04.16.9 View file →
@@ -2,13 +2,13 @@
2 2 /**
3 3 * This template is used to display the donation grid with [donation_grid]
4 4 */
5 5
6 -// Exit if accessed directly.
7 6 use Give\Helpers\Form\Template;
8 7 use Give\Helpers\Form\Utils as FormUtils;
9 8
10 -if ( ! defined('ABSPATH')) {
9 +// Exit if accessed directly.
10 +if (!defined('ABSPATH')) {
11 11 exit;
12 12 }
13 13
14 14 /**
@@ -13,8 +13,10 @@
13 13
14 14 /**
15 15 * List of changes
16 16 *
17 + * @since 4.14.2 Add aria-label to the wrapper link and aria-hidden to its inner elements
18 + * @since 3.16.0 Add filters to enable the async mode and to change the values of the "amount raised" and "donations count" on the progress bar
17 19 * @since 2.27.1 Use get_the_excerpt function to get short description of donation form to display in form grid.
18 20 */
19 21
20 22 $form_id = get_the_ID(); // Form ID.
@@ -31,19 +33,19 @@
31 33 /* @var \Give\Form\Template $formTemplate */
32 34 $formTemplate = Give()->templates->getTemplate($activeTemplate);
33 35
34 36 $renderTags = static function ($wrapper_class, $apply_styles = true) use ($form_id, $atts) {
35 - if ( ! taxonomy_exists('give_forms_tag')) {
37 + if (!taxonomy_exists('give_forms_tag')) {
36 38 return '';
37 39 }
38 40
39 41 $tags = wp_get_post_terms($form_id, 'give_forms_tag');
40 42
41 - $tag_bg_color = ! empty($atts['tag_background_color'])
43 + $tag_bg_color = !empty($atts['tag_background_color'])
42 44 ? $atts['tag_background_color']
43 45 : '#69b86b';
44 46
45 - $tag_text_color = ! empty($atts['tag_text_color'])
47 + $tag_text_color = !empty($atts['tag_text_color'])
46 48 ? $atts['tag_text_color']
47 49 : '#ffffff';
48 50
49 51 $tag_container_color = count($tags) >= 1
@@ -74,15 +76,22 @@
74 76 $tag_elements
75 77 </div>
76 78 ";
77 79 };
78 -
79 80 ?>
80 81
81 82 <div class="give-grid__item">
82 83 <?php
83 84 // Print the opening anchor tag based on display style.
84 - if ('redirect' === $atts['display_style']) {
85 + if ('modal_reveal' === $atts['display_style']) {
86 + printf(
87 + '<a id="give-card-%1$s" class="give-card js-give-grid-modal-launcher" data-effect="mfp-zoom-out" href="#give-modal-form-%1$s" aria-label="%2$s">',
88 + esc_attr($form_id),
89 + /* translators: %s: donation form title */
90 + esc_attr(sprintf(__('Open donation form: %s', 'give'), $formTemplate->getFormHeading($form_id)))
91 + );
92 + } else {
93 + // Default to redirect display style.
85 94 $form_grid_option = give_get_meta($form_id, '_give_form_grid_option', true);
86 95 $form_grid_redirect_url = esc_url(give_get_meta($form_id, '_give_form_grid_redirect_url', true));
87 96
88 97 $url = ($form_grid_option === 'custom' && filter_var($form_grid_redirect_url, FILTER_VALIDATE_URL))
@@ -89,20 +98,18 @@
89 98 ? $form_grid_redirect_url
90 99 : get_the_permalink();
91 100
92 101 printf(
93 - '<a id="give-card-%1$s" onclick="return !document.body.classList.contains( \'block-editor-page\' )" class="give-card" href="%2$s">',
102 + '<a id="give-card-%1$s" onclick="return !document.body.classList.contains( \'block-editor-page\' )" class="give-card" href="%2$s" aria-label="%3$s">',
94 103 esc_attr($form_id),
95 - esc_attr($url)
104 + esc_attr($url),
105 + /* translators: %s: donation form title */
106 + esc_attr(sprintf(__('View donation form: %s', 'give'), $formTemplate->getFormHeading($form_id)))
96 107 );
97 - } elseif ('modal_reveal' === $atts['display_style']) {
98 - printf(
99 - '<a id="give-card-%1$s" class="give-card js-give-grid-modal-launcher" data-effect="mfp-zoom-out" href="#give-modal-form-%1$s">',
100 - esc_attr($form_id)
101 - );
102 108 }
103 109 ?>
104 - <div class="give-form-grid" style="flex-direction:<?php echo esc_attr($flex_direction) ?>">
110 + <div class="give-form-grid" style="flex-direction:<?php
111 + echo esc_attr($flex_direction) ?>" aria-hidden="true">
105 112 <?php
106 113 // Maybe display the featured image.
107 114 if (
108 115 give_is_setting_enabled($give_settings['form_featured_img'])
@@ -152,9 +159,9 @@
152 159
153 160 <div class="give-form-grid-container">
154 161 <div class="give-form-grid-content">
155 162 <?php
156 - if ( ! $atts['show_featured_image']) {
163 + if (!$atts['show_featured_image']) {
157 164 echo "
158 165 <div class='give-form-grid-media'>
159 166 {$renderTags('give-form-grid-media__tags_no_image', false)}
160 167 </div>
@@ -181,9 +188,9 @@
181 188 } else {
182 189 // Get content from the form post's content field.
183 190 $raw_content = give_get_meta($form_id, '_give_form_content', true);
184 191
185 - if ( ! empty($raw_content)) {
192 + if (!empty($raw_content)) {
186 193 $stripped_content = wp_strip_all_tags(
187 194 strip_shortcodes($raw_content)
188 195 );
189 196 }
@@ -201,9 +208,9 @@
201 208 printf('<p class="give-form-grid-content__text">%s</p>', $excerpt);
202 209 }
203 210
204 211 if ($atts['show_donate_button']):
205 - $button_text = ! empty($atts['donate_button_text'])
212 + $button_text = !empty($atts['donate_button_text'])
206 213 ? $atts['donate_button_text']
207 214 : give_get_meta($form_id, '_give_form_grid_donate_button_text', true);
208 215
209 216 /**
@@ -208,21 +215,19 @@
208 215
209 216 /**
210 217 * @since 2.23.1 Updated the default text color for the donate button, see #6591.
211 218 */
212 - $button_text_color = ! empty($atts['donate_button_text_color'])
219 + $button_text_color = !empty($atts['donate_button_text_color'])
213 220 ? $atts['donate_button_text_color']
214 221 : '#000000';
215 222 ?>
216 - <button style="text-decoration-color: <?php
217 - echo esc_attr($button_text_color); ?>">
218 - <span style="color: <?php
219 - echo esc_attr($button_text_color); ?>">
220 - <?php
221 - echo esc_html($button_text) ?: __('Donate', 'give'); ?>
222 - </span>
223 - </button>
224 - <?php endif; ?>
223 + <span class="give-card__button" style="text-decoration-color: <?php
224 + echo esc_attr($button_text_color); ?>; color: <?php
225 + echo esc_attr($button_text_color); ?>" aria-hidden="true">
226 + <?php echo esc_html($button_text) ?: __('Donate', 'give'); ?>
227 + </span>
228 + <?php
229 + endif; ?>
225 230
226 231 </div>
227 232 <?php
228 233 $form = new Give_Donate_Form($form_id);
@@ -228,20 +233,27 @@
228 233 $form = new Give_Donate_Form($form_id);
229 234 $goal_option = give_get_meta($form->ID, '_give_goal_option', true);
230 235
231 236 // Sanity check - ensure form has pass all condition to show goal.
232 - $hide_goal = (isset($atts['show_goal']) && ! filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN))
233 - || empty($form->ID)
234 - || (is_singular('give_forms') && ! give_is_setting_enabled($goal_option))
235 - || ! give_is_setting_enabled($goal_option) || 0 === $form->goal;
237 + $hide_goal = (isset($atts['show_goal']) && !filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN))
238 + || empty($form->ID)
239 + || (is_singular('give_forms') && !give_is_setting_enabled($goal_option))
240 + || !give_is_setting_enabled($goal_option) || 0 === $form->goal;
236 241
237 242 // Maybe display the goal progress bar.
243 + if (!$hide_goal) :
238 244
239 - if ( ! $hide_goal) :
245 + do_action('give_form_grid_goal_progress_stats_before', $form_id);
246 +
240 247 $goal_progress_stats = give_goal_progress_stats($form);
241 248 $goal_format = $goal_progress_stats['format'];
242 249 $color = $atts['progress_bar_color'];
243 250 $show_goal = isset($atts['show_goal']) ? filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN) : true;
251 +
252 + /**
253 + * @since 3.16.0 Revert changes implemented on the 3.14.0 version
254 + * @since 3.14.0 Replace "$form->get_earnings()" with (new DonationQuery())->form($form->ID)->sumIntendedAmount()
255 + */
244 256 $shortcode_stats = apply_filters(
245 257 'give_goal_shortcode_stats',
246 258 [
247 259 'income' => $form->get_earnings(),
@@ -281,15 +293,13 @@
281 293 <div class="give-form-grid-progress">
282 294 <?php
283 295 $style = "width:$progress_bar_value%;";
284 296 $style .= "background: linear-gradient(180deg, {$color} 0%, {$color} 100%); background-blend-mode: multiply;";
285 - echo "
286 - <div class='give-form-grid-progress-bar'>
287 - <div class='give-progress-bar' role='progressbar' aria-valuemin='0' aria-valuemax='100' aria-valuenow='$progress_bar_value'>
288 - <span style='" . esc_attr($style) . "'></span>
289 - </div>
290 - </div>
291 - ";
297 + echo '<div class="give-form-grid-progress-bar">
298 + <div class="give-progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="' . $progress_bar_value . '" aria-label="' . esc_attr( sprintf( __( 'Form progress: %s%% toward goal', 'give' ), $progress_bar_value ) ) . '">
299 + <span style="' . esc_attr($style) . '"></span>
300 + </div>
301 + </div>';
292 302
293 303 ?>
294 304 <div class="form-grid-raised">
295 305 <div class="form-grid-raised__details">
@@ -342,9 +352,9 @@
342 352 *
343 353 * @since 2.5.4
344 354 *
345 355 * @param array $amounts List of goal amounts.
346 - * @param int $form_id Donation Form ID.
356 + * @param int $form_id Donation Form ID.
347 357 */
348 358 $goal_amounts = apply_filters(
349 359 'give_goal_amounts',
350 360 [
@@ -358,9 +368,9 @@
358 368 *
359 369 * @since 2.5.4
360 370 *
361 371 * @param array $amounts List of goal amounts.
362 - * @param int $form_id Donation Form ID.
372 + * @param int $form_id Donation Form ID.
363 373 */
364 374 $income_amounts = apply_filters(
365 375 'give_goal_raised_amounts',
366 376 [
@@ -399,9 +409,9 @@
399 409 <span class="goal" data-amounts="%3$s">of %4$s</span>',
400 410 'give'
401 411 ),
402 412 esc_attr(wp_json_encode($income_amounts, JSON_PRETTY_PRINT)),
403 - esc_attr($formatted_income),
413 + apply_filters('give_form_grid_progress_bar_amount_raised_value', esc_attr($formatted_income), $form_id),
404 414 esc_attr(wp_json_encode($goal_amounts, JSON_PRETTY_PRINT)),
405 415 esc_attr($formatted_goal)
406 416 );
407 417
@@ -419,40 +429,48 @@
419 429
420 430 elseif ('donation' === $goal_format) :?>
421 431
422 432 <span class="amount">
423 - <?php echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
433 + <?php
434 + echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
424 435 </span>
425 436
426 437 <span class="goal">
427 - <?php echo sprintf(
438 + <?php
439 + echo sprintf(
428 440 _n('of %s donation', 'of %s donations', $goal, 'give'),
429 441 give_format_amount($goal, ['decimal' => false])
430 442 ); ?>
431 443 </span>
432 444
433 - <?php elseif ('donors' === $goal_format) : ?>
445 + <?php
446 + elseif ('donors' === $goal_format) : ?>
434 447
435 - <span class="amount"> <?php echo give_get_form_donor_count($form->ID) ?> </span>
448 + <span class="amount"> <?php
449 + echo give_get_form_donor_count($form->ID) ?> </span>
436 450 <span class="goal">
437 - <?php echo sprintf(
451 + <?php
452 + echo sprintf(
438 453 _n('of %s donor', 'of %s donors', $goal, 'give'),
439 454 give_format_amount($goal, ['decimal' => false])
440 455 ); ?>
441 456 </span>
442 - <?php endif ?>
457 + <?php
458 + endif ?>
443 459 </div>
444 460
445 461 <div class="form-grid-raised__details">
446 462 <span class="amount form-grid-raised__details_donations">
447 - <?php echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
463 + <?php echo apply_filters('give_form_grid_progress_bar_donations_count_value', $form->get_sales(), $form_id) ?>
448 464 </span>
449 465 <span class="goal">
450 - <?php echo _n('donation', 'donations', $goal, 'give') ?> </span>
466 + <?php
467 + echo _n('donation', 'donations', $goal, 'give') ?> </span>
451 468 </div>
452 469 </div>
453 470 </div>
454 - <?php endif ?>
471 + <?php
472 + endif ?>
455 473 </div>
456 474 </div>
457 475 </a>
458 476 <?php
@@ -458,10 +476,10 @@
458 476 <?php
459 477 // If modal, print form in hidden container until it is time to be revealed.
460 478 if ('modal_reveal' === $atts['display_style']) {
461 479 if (
462 - ! isset($_GET['context']) // check if we are in block editor
463 - && ! FormUtils::isLegacyForm($form_id)
480 + !isset($_GET['context']) // check if we are in block editor
481 + && !FormUtils::isLegacyForm($form_id)
464 482 ) {
465 483 echo give_form_shortcode(
466 484 [
467 485 'id' => $form_id,
@@ -472,9 +490,16 @@
472 490 printf(
473 491 '<div id="give-modal-form-%1$s" class="give-donation-grid-item-form give-modal--slide mfp-hide">',
474 492 $form_id
475 493 );
476 - give_get_donation_form($form_id);
494 +
495 + echo give_form_shortcode(
496 + [
497 + 'id' => $form_id,
498 + 'display_style' => 'button',
499 + ]
500 + );
501 +
477 502 echo '</div>';
478 503 }
479 504 }
480 505 ?>