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
6 years ago
payment-processing.php
6 years ago
shortcode-donor-wall.php
5 years ago
shortcode-form-grid.php
6 years ago
shortcode-goal.php
6 years ago
shortcode-login.php
6 years ago
shortcode-profile-editor.php
6 years ago
shortcode-receipt.php
6 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
145 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 | |
| 22 | $activeTemplate = FormUtils::isLegacyForm( $form_id ) ? 'legacy' : Template::getActiveID( $form_id ); |
| 23 | |
| 24 | /* @var \Give\Form\Template $formTemplate */ |
| 25 | $formTemplate = Give()->templates->getTemplate( $activeTemplate ); |
| 26 | ?> |
| 27 | |
| 28 | <div class="give-grid__item"> |
| 29 | <?php |
| 30 | // Print the opening anchor tag based on display style. |
| 31 | if ( 'redirect' === $atts['display_style'] ) { |
| 32 | printf( |
| 33 | '<a id="give-card-%1$s" class="give-card" href="%2$s">', |
| 34 | esc_attr( $form_id ), |
| 35 | esc_attr( get_the_permalink() ) |
| 36 | ); |
| 37 | } elseif ( 'modal_reveal' === $atts['display_style'] ) { |
| 38 | printf( |
| 39 | '<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">', |
| 40 | esc_attr( $form_id ) |
| 41 | ); |
| 42 | } |
| 43 | ?> |
| 44 | |
| 45 | <div class="give-card__body"> |
| 46 | <?php |
| 47 | // Maybe display the form title. |
| 48 | if ( true === $atts['show_title'] ) { |
| 49 | printf( |
| 50 | '<h3 class="give-card__title">%1$s</h3>', |
| 51 | $formTemplate->getFormHeading( $form_id ) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | // Maybe display the form excerpt. |
| 56 | if ( true === $atts['show_excerpt'] ) { |
| 57 | if ( $raw_content = $formTemplate->getFormExcerpt( $form_id ) ) { |
| 58 | $stripped_content = wp_strip_all_tags( |
| 59 | strip_shortcodes( $raw_content ) |
| 60 | ); |
| 61 | } else { |
| 62 | // Get content from the form post's content field. |
| 63 | $raw_content = give_get_meta( $form_id, '_give_form_content', true ); |
| 64 | |
| 65 | if ( ! empty( $raw_content ) ) { |
| 66 | $stripped_content = wp_strip_all_tags( |
| 67 | strip_shortcodes( $raw_content ) |
| 68 | ); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | // Maybe truncate excerpt. |
| 73 | if ( 0 < $atts['excerpt_length'] ) { |
| 74 | $excerpt = wp_trim_words( $stripped_content, $atts['excerpt_length'] ); |
| 75 | } else { |
| 76 | $excerpt = $stripped_content; |
| 77 | } |
| 78 | |
| 79 | printf( '<p class="give-card__text">%s</p>', $excerpt ); |
| 80 | } |
| 81 | |
| 82 | // Maybe display the goal progess bar. |
| 83 | if ( |
| 84 | give_is_setting_enabled( get_post_meta( $form_id, '_give_goal_option', true ) ) |
| 85 | && true === $atts['show_goal'] |
| 86 | ) { |
| 87 | echo '<div class="give-card__progress">'; |
| 88 | give_show_goal_progress( $form_id ); |
| 89 | echo '</div>'; |
| 90 | } |
| 91 | ?> |
| 92 | </div> |
| 93 | |
| 94 | <?php |
| 95 | // Maybe display the featured image. |
| 96 | if ( |
| 97 | give_is_setting_enabled( $give_settings['form_featured_img'] ) |
| 98 | && ( $imageSrc = $formTemplate->getFormFeaturedImage( $form_id ) ) |
| 99 | && true === $atts['show_featured_image'] |
| 100 | ) { |
| 101 | /* |
| 102 | * Filters the image size used in card layouts. |
| 103 | * |
| 104 | * @param string The image size. |
| 105 | * @param array Form grid attributes. |
| 106 | */ |
| 107 | $image_size = apply_filters( 'give_form_grid_image_size', $atts['image_size'], $atts ); |
| 108 | $image_attr = ''; |
| 109 | |
| 110 | if ( 'auto' !== $atts['image_height'] ) { |
| 111 | $image_attr = [ |
| 112 | 'style' => 'height: ' . $atts['image_height'], |
| 113 | ]; |
| 114 | } |
| 115 | |
| 116 | printf( |
| 117 | '<div class="give-card__media">%1$s</div>', |
| 118 | wp_get_attachment_image( attachment_url_to_postid( $imageSrc ), $image_size, false, $image_attr ) |
| 119 | ); |
| 120 | } |
| 121 | ?> |
| 122 | </a> |
| 123 | <?php |
| 124 | // If modal, print form in hidden container until it is time to be revealed. |
| 125 | if ( 'modal_reveal' === $atts['display_style'] ) { |
| 126 | if ( ! FormUtils::isLegacyForm( $form_id ) ) { |
| 127 | echo give_form_shortcode( |
| 128 | [ |
| 129 | 'id' => $form_id, |
| 130 | 'display_style' => 'button', |
| 131 | ] |
| 132 | ); |
| 133 | |
| 134 | } else { |
| 135 | printf( |
| 136 | '<div id="give-modal-form-%1$s" class="give-donation-grid-item-form give-modal--slide mfp-hide">', |
| 137 | $form_id |
| 138 | ); |
| 139 | give_get_donation_form( $form_id ); |
| 140 | echo '</div>'; |
| 141 | } |
| 142 | } |
| 143 | ?> |
| 144 | </div> |
| 145 |