PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.30.0
GiveWP – Donation Plugin and Fundraising Platform v2.30.0
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / templates / shortcode-form-grid.php
give / templates Last commit date
emails 6 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 3 years ago shortcode-form-grid.php 2 years ago shortcode-goal.php 3 years ago shortcode-login.php 6 years ago shortcode-profile-editor.php 6 years ago shortcode-receipt.php 5 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
483 lines
1 <?php
2 /**
3 * This template is used to display the donation grid with [donation_grid]
4 */
5
6 // Exit if accessed directly.
7 use Give\Helpers\Form\Template;
8 use Give\Helpers\Form\Utils as FormUtils;
9
10 if ( ! defined('ABSPATH')) {
11 exit;
12 }
13
14 /**
15 * List of changes
16 *
17 * @since 2.27.1 Use get_the_excerpt function to get short description of donation form to display in form grid.
18 */
19
20 $form_id = get_the_ID(); // Form ID.
21 $give_settings = $args[0]; // Give settings.
22 $atts = $args[1]; // Shortcode attributes.
23 $raw_content = ''; // Raw form content.
24 $stripped_content = ''; // Form content stripped of HTML tags and shortcodes.
25 $excerpt = ''; // Trimmed form excerpt ready for display.
26
27 $flex_direction = $atts['columns'] === '1' ? "row" : "column";
28
29 $activeTemplate = FormUtils::isLegacyForm($form_id) ? 'legacy' : Template::getActiveID($form_id);
30
31 /* @var \Give\Form\Template $formTemplate */
32 $formTemplate = Give()->templates->getTemplate($activeTemplate);
33
34 $renderTags = static function ($wrapper_class, $apply_styles = true) use ($form_id, $atts) {
35 if ( ! taxonomy_exists('give_forms_tag')) {
36 return '';
37 }
38
39 $tags = wp_get_post_terms($form_id, 'give_forms_tag');
40
41 $tag_bg_color = ! empty($atts['tag_background_color'])
42 ? $atts['tag_background_color']
43 : '#69b86b';
44
45 $tag_text_color = ! empty($atts['tag_text_color'])
46 ? $atts['tag_text_color']
47 : '#ffffff';
48
49 $tag_container_color = count($tags) >= 1
50 ? 'rgba(0, 0, 0, 0.35)'
51 : 'none';
52
53 $tag_elements = array_map(
54 static function ($term) use ($tag_text_color, $tag_bg_color) {
55 $style = sprintf(
56 'color: %s; background-color: %s;',
57 esc_attr($tag_text_color),
58 esc_attr($tag_bg_color)
59 );
60
61 return "<span style='$style'>$term->name</span>";
62 },
63 $tags
64 );
65
66 $tag_elements = implode('', $tag_elements);
67 $styles = sprintf(
68 "background-color: %s;",
69 $apply_styles ? esc_attr($tag_container_color) : ''
70 );
71
72 return "
73 <div class='$wrapper_class' style='$styles' >
74 $tag_elements
75 </div>
76 ";
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 echo esc_attr($flex_direction) ?>">
105 <?php
106 // Maybe display the featured image.
107 if (
108 give_is_setting_enabled($give_settings['form_featured_img'])
109 && ($imageSrc = $formTemplate->getFormFeaturedImage($form_id))
110 && $atts['show_featured_image']
111 && $atts['columns'] !== '1'
112 ) {
113 /*
114 * Filters the image size used in card layouts.
115 *
116 * @param string The image size.
117 * @param array Form grid attributes.
118 */
119 $image_size = apply_filters('give_form_grid_image_size', $atts['image_size'], $atts);
120 $image_attr = '';
121
122 if ('auto' !== $atts['image_height']) {
123 $image_attr = [
124 'style' => 'height: ' . $atts['image_height'],
125 ];
126 }
127
128 $image = wp_get_attachment_image(attachment_url_to_postid($imageSrc), $image_size, false, $image_attr);
129
130
131 echo "
132 <div class='give-form-grid-media'>
133 <div class='give-card__media'> $image </div>
134
135 {$renderTags('give-form-grid-media__tags')}
136 </div>
137 ";
138 } elseif (
139 give_is_setting_enabled($give_settings['form_featured_img'])
140 && ($imageSrc = $formTemplate->getFormFeaturedImage($form_id))
141 && $atts['show_featured_image']
142 && $atts['columns'] === '1') {
143 echo "
144 <div id='row-media' class='give-form-grid-media'>
145 <img class='give-form-grid-media' src='" . esc_url($imageSrc) . "' alt='' />
146
147 {$renderTags('give-form-grid-media__tags')}
148 </div>
149 ";
150 }
151 ?>
152
153 <div class="give-form-grid-container">
154 <div class="give-form-grid-content">
155 <?php
156 if ( ! $atts['show_featured_image']) {
157 echo "
158 <div class='give-form-grid-media'>
159 {$renderTags('give-form-grid-media__tags_no_image', false)}
160 </div>
161 ";
162 }
163 ?>
164
165 <?php
166
167 // Maybe display the form title.
168 if (true === $atts['show_title']) {
169 printf(
170 '<h3 class="give-form-grid-content__title">%1$s</h3>',
171 $formTemplate->getFormHeading($form_id)
172 );
173 }
174
175 // Maybe display the form excerpt.
176 if (true === $atts['show_excerpt']) {
177 if ($raw_content = get_the_excerpt($form_id)) {
178 $stripped_content = wp_strip_all_tags(
179 strip_shortcodes($raw_content)
180 );
181 } else {
182 // Get content from the form post's content field.
183 $raw_content = give_get_meta($form_id, '_give_form_content', true);
184
185 if ( ! empty($raw_content)) {
186 $stripped_content = wp_strip_all_tags(
187 strip_shortcodes($raw_content)
188 );
189 }
190 }
191
192 // Maybe truncate excerpt.
193 if (0 < $atts['excerpt_length']) {
194 $excerpt = wp_trim_words($stripped_content, $atts['excerpt_length']);
195 } else {
196 $excerpt = $stripped_content;
197 }
198
199 $excerpt = ($excerpt === '[]') ? '' : $excerpt;
200
201 printf('<p class="give-form-grid-content__text">%s</p>', $excerpt);
202 }
203
204 if ($atts['show_donate_button']):
205 $button_text = ! empty($atts['donate_button_text'])
206 ? $atts['donate_button_text']
207 : give_get_meta($form_id, '_give_form_grid_donate_button_text', true);
208
209 /**
210 * @since 2.23.1 Updated the default text color for the donate button, see #6591.
211 */
212 $button_text_color = ! empty($atts['donate_button_text_color'])
213 ? $atts['donate_button_text_color']
214 : '#000000';
215 ?>
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; ?>
225
226 </div>
227 <?php
228 $form = new Give_Donate_Form($form_id);
229 $goal_option = give_get_meta($form->ID, '_give_goal_option', true);
230
231 // 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;
236
237 // Maybe display the goal progress bar.
238
239 if ( ! $hide_goal) :
240 $goal_progress_stats = give_goal_progress_stats($form);
241 $goal_format = $goal_progress_stats['format'];
242 $color = $atts['progress_bar_color'];
243 $show_goal = isset($atts['show_goal']) ? filter_var($atts['show_goal'], FILTER_VALIDATE_BOOLEAN) : true;
244 $shortcode_stats = apply_filters(
245 'give_goal_shortcode_stats',
246 [
247 'income' => $form->get_earnings(),
248 'goal' => $goal_progress_stats['raw_goal'],
249 ],
250 $form_id,
251 $goal_progress_stats,
252 $args
253 );
254
255 $income = $shortcode_stats['income'];
256 $goal = $shortcode_stats['goal'];
257
258 switch ($goal_format) {
259 case 'donation':
260 $progress = $goal ? round(($form->get_sales() / $goal) * 100, 2) : 0;
261 $progress_bar_value = $form->get_sales() >= $goal ? 100 : $progress;
262 break;
263
264 case 'donors':
265 $progress = $goal ? round((give_get_form_donor_count($form->ID) / $goal) * 100, 2) : 0;
266 $progress_bar_value = give_get_form_donor_count($form->ID) >= $goal ? 100 : $progress;
267 break;
268
269 case 'percentage':
270 $progress = $goal ? round(($income / $goal) * 100, 2) : 0;
271 $progress_bar_value = $income >= $goal ? 100 : $progress;
272 break;
273
274 default:
275 $progress = $goal ? round(($income / $goal) * 100, 2) : 0;
276 $progress_bar_value = $income >= $goal ? 100 : $progress;
277 break;
278 }
279
280 ?>
281 <div class="give-form-grid-progress">
282 <?php
283 $style = "width:$progress_bar_value%;";
284 $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 ";
292
293 ?>
294 <div class="form-grid-raised">
295 <div class="form-grid-raised__details">
296 <?php
297 if ('amount' === $goal_format) :
298
299 /**
300 * Filter the give currency.
301 *
302 * @since 1.8.17
303 */
304 $form_currency = apply_filters(
305 'give_goal_form_currency',
306 give_get_currency($form_id),
307 $form_id
308 );
309
310 /**
311 * Filter the income formatting arguments.
312 *
313 * @since 1.8.17
314 */
315 $income_format_args = apply_filters(
316 'give_goal_income_format_args',
317 [
318 'sanitize' => false,
319 'currency' => $form_currency,
320 'decimal' => false,
321 ],
322 $form_id
323 );
324
325 /**
326 * Filter the goal formatting arguments.
327 *
328 * @since 1.8.17
329 */
330 $goal_format_args = apply_filters(
331 'give_goal_amount_format_args',
332 [
333 'sanitize' => false,
334 'currency' => $form_currency,
335 'decimal' => false,
336 ],
337 $form_id
338 );
339
340 /**
341 * This filter will be used to convert the goal amounts to different currencies.
342 *
343 * @since 2.5.4
344 *
345 * @param array $amounts List of goal amounts.
346 * @param int $form_id Donation Form ID.
347 */
348 $goal_amounts = apply_filters(
349 'give_goal_amounts',
350 [
351 $form_currency => $goal,
352 ],
353 $form_id
354 );
355
356 /**
357 * This filter will be used to convert the income amounts to different currencies.
358 *
359 * @since 2.5.4
360 *
361 * @param array $amounts List of goal amounts.
362 * @param int $form_id Donation Form ID.
363 */
364 $income_amounts = apply_filters(
365 'give_goal_raised_amounts',
366 [
367 $form_currency => $income,
368 ],
369 $form_id
370 );
371
372 // Get human readable donation amount.
373 $income = give_human_format_large_amount(
374 give_format_amount($income, $income_format_args), ['currency' => $form_currency]
375 );
376 $goal = give_human_format_large_amount(
377 give_format_amount($goal, $goal_format_args),
378 ['currency' => $form_currency]
379 );
380
381 // Format the human readable donation amount.
382 $formatted_income = give_currency_filter(
383 $income,
384 [
385 'form_id' => $form_id,
386 ]
387 );
388
389 $formatted_goal = give_currency_filter(
390 $goal,
391 [
392 'form_id' => $form_id,
393 ]
394 );
395 echo sprintf(
396 /* translators: 1: amount of income raised 2: goal target amount. */
397 __(
398 '<span class="amount" data-amounts="%1$s">%2$s</span>
399 <span class="goal" data-amounts="%3$s">of %4$s</span>',
400 'give'
401 ),
402 esc_attr(wp_json_encode($income_amounts, JSON_PRETTY_PRINT)),
403 esc_attr($formatted_income),
404 esc_attr(wp_json_encode($goal_amounts, JSON_PRETTY_PRINT)),
405 esc_attr($formatted_goal)
406 );
407
408 elseif ('percentage' === $goal_format) :
409
410 echo sprintf( /* translators: %s: percentage of the amount raised compared to the goal target */
411 __(
412 '
413 <span class="amount">%s%%</span>
414 <span class="goal">of 100&#37;</span>',
415 'give'
416 ),
417 round($progress)
418 );
419
420 elseif ('donation' === $goal_format) :?>
421
422 <span class="amount">
423 <?php echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
424 </span>
425
426 <span class="goal">
427 <?php echo sprintf(
428 _n('of %s donation', 'of %s donations', $goal, 'give'),
429 give_format_amount($goal, ['decimal' => false])
430 ); ?>
431 </span>
432
433 <?php elseif ('donors' === $goal_format) : ?>
434
435 <span class="amount"> <?php echo give_get_form_donor_count($form->ID) ?> </span>
436 <span class="goal">
437 <?php echo sprintf(
438 _n('of %s donor', 'of %s donors', $goal, 'give'),
439 give_format_amount($goal, ['decimal' => false])
440 ); ?>
441 </span>
442 <?php endif ?>
443 </div>
444
445 <div class="form-grid-raised__details">
446 <span class="amount form-grid-raised__details_donations">
447 <?php echo give_format_amount($form->get_sales(), ['decimal' => false]) ?>
448 </span>
449 <span class="goal">
450 <?php echo _n('donation', 'donations', $goal, 'give') ?> </span>
451 </div>
452 </div>
453 </div>
454 <?php endif ?>
455 </div>
456 </div>
457 </a>
458 <?php
459 // If modal, print form in hidden container until it is time to be revealed.
460 if ('modal_reveal' === $atts['display_style']) {
461 if (
462 ! isset($_GET['context']) // check if we are in block editor
463 && ! FormUtils::isLegacyForm($form_id)
464 ) {
465 echo give_form_shortcode(
466 [
467 'id' => $form_id,
468 'display_style' => 'button',
469 ]
470 );
471 } else {
472 printf(
473 '<div id="give-modal-form-%1$s" class="give-donation-grid-item-form give-modal--slide mfp-hide">',
474 $form_id
475 );
476 give_get_donation_form($form_id);
477 echo '</div>';
478 }
479 }
480 ?>
481 </div>
482
483