PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 4.13.0
GiveWP – Donation Plugin and Fundraising Platform v4.13.0
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 / templates / shortcode-form-grid.php
give / templates Last commit date
emails 2 years ago global 6 years ago receipt 7 years ago single-give-form 6 years ago email-login-form.php 6 years ago history-donations.php 4 years ago payment-processing.php 6 years ago shortcode-donor-wall.php 1 year ago shortcode-form-grid.php 1 year ago shortcode-goal.php 10 months ago shortcode-login.php 6 years ago shortcode-profile-editor.php 6 years ago shortcode-receipt.php 2 years ago shortcode-register.php 8 years ago shortcode-totals-progress.php 6 years ago single-give-form.php 6 years ago
shortcode-form-grid.php
505 lines
1 <?php
2 /**
3 * This template is used to display the donation grid with [donation_grid]
4 */
5
6 use Give\Helpers\Form\Template;
7 use Give\Helpers\Form\Utils as FormUtils;
8
9 // Exit if accessed directly.
10 if (!defined('ABSPATH')) {
11 exit;
12 }
13
14 /**
15 * List of changes
16 *
17 * @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
18 * @since 2.27.1 Use get_the_excerpt function to get short description of donation form to display in form grid.
19 */
20
21 $form_id = get_the_ID(); // Form ID.
22 $give_settings = $args[0]; // Give settings.
23 $atts = $args[1]; // Shortcode attributes.
24 $raw_content = ''; // Raw form content.
25 $stripped_content = ''; // Form content stripped of HTML tags and shortcodes.
26 $excerpt = ''; // Trimmed form excerpt ready for display.
27
28 $flex_direction = $atts['columns'] === '1' ? "row" : "column";
29
30 $activeTemplate = FormUtils::isLegacyForm($form_id) ? 'legacy' : Template::getActiveID($form_id);
31
32 /* @var \Give\Form\Template $formTemplate */
33 $formTemplate = Give()->templates->getTemplate($activeTemplate);
34
35 $renderTags = static function ($wrapper_class, $apply_styles = true) use ($form_id, $atts) {
36 if (!taxonomy_exists('give_forms_tag')) {
37 return '';
38 }
39
40 $tags = wp_get_post_terms($form_id, 'give_forms_tag');
41
42 $tag_bg_color = !empty($atts['tag_background_color'])
43 ? $atts['tag_background_color']
44 : '#69b86b';
45
46 $tag_text_color = !empty($atts['tag_text_color'])
47 ? $atts['tag_text_color']
48 : '#ffffff';
49
50 $tag_container_color = count($tags) >= 1
51 ? 'rgba(0, 0, 0, 0.35)'
52 : 'none';
53
54 $tag_elements = array_map(
55 static function ($term) use ($tag_text_color, $tag_bg_color) {
56 $style = sprintf(
57 'color: %s; background-color: %s;',
58 esc_attr($tag_text_color),
59 esc_attr($tag_bg_color)
60 );
61
62 return "<span style='$style'>$term->name</span>";
63 },
64 $tags
65 );
66
67 $tag_elements = implode('', $tag_elements);
68 $styles = sprintf(
69 "background-color: %s;",
70 $apply_styles ? esc_attr($tag_container_color) : ''
71 );
72
73 return "
74 <div class='$wrapper_class' style='$styles' >
75 $tag_elements
76 </div>
77 ";
78 };
79 ?>
80
81 <div class="give-grid__item">
82 <?php
83 // Print the opening anchor tag based on display style.
84 if ('redirect' === $atts['display_style']) {
85 $form_grid_option = give_get_meta($form_id, '_give_form_grid_option', true);
86 $form_grid_redirect_url = esc_url(give_get_meta($form_id, '_give_form_grid_redirect_url', true));
87
88 $url = ($form_grid_option === 'custom' && filter_var($form_grid_redirect_url, FILTER_VALIDATE_URL))
89 ? $form_grid_redirect_url
90 : get_the_permalink();
91
92 printf(
93 '<a id="give-card-%1$s" onclick="return !document.body.classList.contains( \'block-editor-page\' )" class="give-card" href="%2$s">',
94 esc_attr($form_id),
95 esc_attr($url)
96 );
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 }
103 ?>
104 <div class="give-form-grid" style="flex-direction:<?php
105 echo esc_attr($flex_direction) ?>">
106 <?php
107 // Maybe display the featured image.
108 if (
109 give_is_setting_enabled($give_settings['form_featured_img'])
110 && ($imageSrc = $formTemplate->getFormFeaturedImage($form_id))
111 && $atts['show_featured_image']
112 && $atts['columns'] !== '1'
113 ) {
114 /*
115 * Filters the image size used in card layouts.
116 *
117 * @param string The image size.
118 * @param array Form grid attributes.
119 */
120 $image_size = apply_filters('give_form_grid_image_size', $atts['image_size'], $atts);
121 $image_attr = '';
122
123 if ('auto' !== $atts['image_height']) {
124 $image_attr = [
125 'style' => 'height: ' . $atts['image_height'],
126 ];
127 }
128
129 $image = wp_get_attachment_image(attachment_url_to_postid($imageSrc), $image_size, false, $image_attr);
130
131
132 echo "
133 <div class='give-form-grid-media'>
134 <div class='give-card__media'> $image </div>
135
136 {$renderTags('give-form-grid-media__tags')}
137 </div>
138 ";
139 } elseif (
140 give_is_setting_enabled($give_settings['form_featured_img'])
141 && ($imageSrc = $formTemplate->getFormFeaturedImage($form_id))
142 && $atts['show_featured_image']
143 && $atts['columns'] === '1') {
144 echo "
145 <div id='row-media' class='give-form-grid-media'>
146 <img class='give-form-grid-media' src='" . esc_url($imageSrc) . "' alt='' />
147
148 {$renderTags('give-form-grid-media__tags')}
149 </div>
150 ";
151 }
152 ?>
153
154 <div class="give-form-grid-container">
155 <div class="give-form-grid-content">
156 <?php
157 if (!$atts['show_featured_image']) {
158 echo "
159 <div class='give-form-grid-media'>
160 {$renderTags('give-form-grid-media__tags_no_image', false)}
161 </div>
162 ";
163 }
164 ?>
165
166 <?php
167
168 // Maybe display the form title.
169 if (true === $atts['show_title']) {
170 printf(
171 '<h3 class="give-form-grid-content__title">%1$s</h3>',
172 $formTemplate->getFormHeading($form_id)
173 );
174 }
175
176 // Maybe display the form excerpt.
177 if (true === $atts['show_excerpt']) {
178 if ($raw_content = get_the_excerpt($form_id)) {
179 $stripped_content = wp_strip_all_tags(
180 strip_shortcodes($raw_content)
181 );
182 } else {
183 // Get content from the form post's content field.
184 $raw_content = give_get_meta($form_id, '_give_form_content', true);
185
186 if (!empty($raw_content)) {
187 $stripped_content = wp_strip_all_tags(
188 strip_shortcodes($raw_content)
189 );
190 }
191 }
192
193 // Maybe truncate excerpt.
194 if (0 < $atts['excerpt_length']) {
195 $excerpt = wp_trim_words($stripped_content, $atts['excerpt_length']);
196 } else {
197 $excerpt = $stripped_content;
198 }
199
200 $excerpt = ($excerpt === '[]') ? '' : $excerpt;
201
202 printf('<p class="give-form-grid-content__text">%s</p>', $excerpt);
203 }
204
205 if ($atts['show_donate_button']):
206 $button_text = !empty($atts['donate_button_text'])
207 ? $atts['donate_button_text']
208 : give_get_meta($form_id, '_give_form_grid_donate_button_text', true);
209
210 /**
211 * @since 2.23.1 Updated the default text color for the donate button, see #6591.
212 */
213 $button_text_color = !empty($atts['donate_button_text_color'])
214 ? $atts['donate_button_text_color']
215 : '#000000';
216 ?>
217 <button style="text-decoration-color: <?php
218 echo esc_attr($button_text_color); ?>">
219 <span style="color: <?php
220 echo esc_attr($button_text_color); ?>">
221 <?php
222 echo esc_html($button_text) ?: __('Donate', 'give'); ?>
223 </span>
224 </button>
225 <?php
226 endif; ?>
227
228 </div>
229 <?php
230 $form = new Give_Donate_Form($form_id);
231 $goal_option = give_get_meta($form->ID, '_give_goal_option', true);
232
233 // Sanity check - ensure form has pass all condition to show goal.
234 $hide_goal = (isset($atts['show_goal']) && !filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN))
235 || empty($form->ID)
236 || (is_singular('give_forms') && !give_is_setting_enabled($goal_option))
237 || !give_is_setting_enabled($goal_option) || 0 === $form->goal;
238
239 // Maybe display the goal progress bar.
240 if (!$hide_goal) :
241
242 do_action('give_form_grid_goal_progress_stats_before', $form_id);
243
244 $goal_progress_stats = give_goal_progress_stats($form);
245 $goal_format = $goal_progress_stats['format'];
246 $color = $atts['progress_bar_color'];
247 $show_goal = isset($atts['show_goal']) ? filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN) : true;
248
249 /**
250 * @since 3.16.0 Revert changes implemented on the 3.14.0 version
251 * @since 3.14.0 Replace "$form->get_earnings()" with (new DonationQuery())->form($form->ID)->sumIntendedAmount()
252 */
253 $shortcode_stats = apply_filters(
254 'give_goal_shortcode_stats',
255 [
256 'income' => $form->get_earnings(),
257 'goal' => $goal_progress_stats['raw_goal'],
258 ],
259 $form_id,
260 $goal_progress_stats,
261 $args
262 );
263
264 $income = $shortcode_stats['income'];
265 $goal = $shortcode_stats['goal'];
266
267 switch ($goal_format) {
268 case 'donation':
269 $progress = $goal ? round(($form->get_sales() / $goal) * 100, 2) : 0;
270 $progress_bar_value = $form->get_sales() >= $goal ? 100 : $progress;
271 break;
272
273 case 'donors':
274 $progress = $goal ? round((give_get_form_donor_count($form->ID) / $goal) * 100, 2) : 0;
275 $progress_bar_value = give_get_form_donor_count($form->ID) >= $goal ? 100 : $progress;
276 break;
277
278 case 'percentage':
279 $progress = $goal ? round(($income / $goal) * 100, 2) : 0;
280 $progress_bar_value = $income >= $goal ? 100 : $progress;
281 break;
282
283 default:
284 $progress = $goal ? round(($income / $goal) * 100, 2) : 0;
285 $progress_bar_value = $income >= $goal ? 100 : $progress;
286 break;
287 }
288
289 ?>
290 <div class="give-form-grid-progress">
291 <?php
292 $style = "width:$progress_bar_value%;";
293 $style .= "background: linear-gradient(180deg, {$color} 0%, {$color} 100%); background-blend-mode: multiply;";
294 echo '<div class="give-form-grid-progress-bar">
295 <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 ) ) . '">
296 <span style="' . esc_attr($style) . '"></span>
297 </div>
298 </div>';
299
300 ?>
301 <div class="form-grid-raised">
302 <div class="form-grid-raised__details">
303 <?php
304 if ('amount' === $goal_format) :
305
306 /**
307 * Filter the give currency.
308 *
309 * @since 1.8.17
310 */
311 $form_currency = apply_filters(
312 'give_goal_form_currency',
313 give_get_currency($form_id),
314 $form_id
315 );
316
317 /**
318 * Filter the income formatting arguments.
319 *
320 * @since 1.8.17
321 */
322 $income_format_args = apply_filters(
323 'give_goal_income_format_args',
324 [
325 'sanitize' => false,
326 'currency' => $form_currency,
327 'decimal' => false,
328 ],
329 $form_id
330 );
331
332 /**
333 * Filter the goal formatting arguments.
334 *
335 * @since 1.8.17
336 */
337 $goal_format_args = apply_filters(
338 'give_goal_amount_format_args',
339 [
340 'sanitize' => false,
341 'currency' => $form_currency,
342 'decimal' => false,
343 ],
344 $form_id
345 );
346
347 /**
348 * This filter will be used to convert the goal amounts to different currencies.
349 *
350 * @since 2.5.4
351 *
352 * @param array $amounts List of goal amounts.
353 * @param int $form_id Donation Form ID.
354 */
355 $goal_amounts = apply_filters(
356 'give_goal_amounts',
357 [
358 $form_currency => $goal,
359 ],
360 $form_id
361 );
362
363 /**
364 * This filter will be used to convert the income amounts to different currencies.
365 *
366 * @since 2.5.4
367 *
368 * @param array $amounts List of goal amounts.
369 * @param int $form_id Donation Form ID.
370 */
371 $income_amounts = apply_filters(
372 'give_goal_raised_amounts',
373 [
374 $form_currency => $income,
375 ],
376 $form_id
377 );
378
379 // Get human readable donation amount.
380 $income = give_human_format_large_amount(
381 give_format_amount($income, $income_format_args), ['currency' => $form_currency]
382 );
383 $goal = give_human_format_large_amount(
384 give_format_amount($goal, $goal_format_args),
385 ['currency' => $form_currency]
386 );
387
388 // Format the human readable donation amount.
389 $formatted_income = give_currency_filter(
390 $income,
391 [
392 'form_id' => $form_id,
393 ]
394 );
395
396 $formatted_goal = give_currency_filter(
397 $goal,
398 [
399 'form_id' => $form_id,
400 ]
401 );
402 echo sprintf(
403 /* translators: 1: amount of income raised 2: goal target amount. */
404 __(
405 '<span class="amount" data-amounts="%1$s">%2$s</span>
406 <span class="goal" data-amounts="%3$s">of %4$s</span>',
407 'give'
408 ),
409 esc_attr(wp_json_encode($income_amounts, JSON_PRETTY_PRINT)),
410 apply_filters('give_form_grid_progress_bar_amount_raised_value', esc_attr($formatted_income), $form_id),
411 esc_attr(wp_json_encode($goal_amounts, JSON_PRETTY_PRINT)),
412 esc_attr($formatted_goal)
413 );
414
415 elseif ('percentage' === $goal_format) :
416
417 echo sprintf( /* translators: %s: percentage of the amount raised compared to the goal target */
418 __(
419 '
420 <span class="amount">%s%%</span>
421 <span class="goal">of 100&#37;</span>',
422 'give'
423 ),
424 round($progress)
425 );
426
427 elseif ('donation' === $goal_format) :?>
428
429 <span class="amount">
430 <?php
431 echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
432 </span>
433
434 <span class="goal">
435 <?php
436 echo sprintf(
437 _n('of %s donation', 'of %s donations', $goal, 'give'),
438 give_format_amount($goal, ['decimal' => false])
439 ); ?>
440 </span>
441
442 <?php
443 elseif ('donors' === $goal_format) : ?>
444
445 <span class="amount"> <?php
446 echo give_get_form_donor_count($form->ID) ?> </span>
447 <span class="goal">
448 <?php
449 echo sprintf(
450 _n('of %s donor', 'of %s donors', $goal, 'give'),
451 give_format_amount($goal, ['decimal' => false])
452 ); ?>
453 </span>
454 <?php
455 endif ?>
456 </div>
457
458 <div class="form-grid-raised__details">
459 <span class="amount form-grid-raised__details_donations">
460 <?php echo apply_filters('give_form_grid_progress_bar_donations_count_value', $form->get_sales(), $form_id) ?>
461 </span>
462 <span class="goal">
463 <?php
464 echo _n('donation', 'donations', $goal, 'give') ?> </span>
465 </div>
466 </div>
467 </div>
468 <?php
469 endif ?>
470 </div>
471 </div>
472 </a>
473 <?php
474 // If modal, print form in hidden container until it is time to be revealed.
475 if ('modal_reveal' === $atts['display_style']) {
476 if (
477 !isset($_GET['context']) // check if we are in block editor
478 && !FormUtils::isLegacyForm($form_id)
479 ) {
480 echo give_form_shortcode(
481 [
482 'id' => $form_id,
483 'display_style' => 'button',
484 ]
485 );
486 } else {
487 printf(
488 '<div id="give-modal-form-%1$s" class="give-donation-grid-item-form give-modal--slide mfp-hide">',
489 $form_id
490 );
491
492 echo give_form_shortcode(
493 [
494 'id' => $form_id,
495 'display_style' => 'button',
496 ]
497 );
498
499 echo '</div>';
500 }
501 }
502 ?>
503 </div>
504
505