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