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