← Back
Editing: receipt.php
<?php /** * @since 4.19.1 Escape output, replace short echo tags with escaped echo, and do not pass a variable to the translation function. */ use Give\Helpers\Form\Template; use Give\Receipt\DonationReceipt; use Give\Receipt\LineItem; use Give\Receipt\Section; use Give\Session\SessionDonation\DonationAccessor; use Give\Views\IframeContentView; use Give_Payment as Payment; if (!defined('ABSPATH')) { exit; } // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- template variables; this file is included inside a function, so they are not globals. $donationId = (new DonationAccessor())->getDonationId(); $template = Give()->templates->getTemplate(); $receipt = $template->getReceiptDetails($donationId); $donation = new Payment($donationId); $option = static function ($name) { static $options = []; if (empty($options)) { $options = Template::getOptions()['donation_receipt']; } if (isset($options[$name])) { return $options[$name]; } return ''; }; $hasDonationFailed = static function () use ($donation) { return $donation->post_status === 'failed'; }; $sharingInstructions = $option('sharing_instructions'); $donorDashboardUrl = get_permalink(give_get_option('donor_dashboard_page')); $data = $hasDonationFailed() ? [ 'badgeIcon' => '#give-icon-cross', 'badgeText' => esc_html__('Failed', 'give'), 'title' => esc_html__('Donation Failed', 'give'), 'description' => esc_html__('We\'re sorry, your donation failed to process. Please try again or contact site support.', 'give'), ] : [ 'badgeIcon' => '#give-icon-checkmark', 'badgeText' => esc_html__('Success', 'give'), 'title' => $receipt->heading, 'description' => $receipt->message, ]; ob_start(); ?> <?php include __DIR__ . '/icon-defs.php'; ?> <article class="give-receipt-classic"> <div class="give-form-header"> <div class="give-form-header-top-wrap"> <aside class="give-form-secure-badge"> <svg class="give-form-secure-icon"> <use href="<?php echo esc_attr($data['badgeIcon']); ?>"/> </svg> <?php echo esc_html($data['badgeText']); ?>! </aside> <h1 class="give-receipt-title"> <?php echo wp_kses_post($data['title']); ?> </h1> <p class="give-form-description"> <?php echo wp_kses_post($data['description']); ?> </p> </div> </div> <?php if ('enabled' === $option('social_sharing') && ! $hasDonationFailed()) : ?> <div class="social-sharing"> <p class="instruction"> <?php echo esc_html($sharingInstructions === 'Help spread the word by sharing your support with your friends and followers!' ? __('Help spread the word by sharing your support with your friends and followers!', 'give') : $sharingInstructions); ?> </p> <div class="btn-row"> <button class="give-btn social-btn facebook-btn" onclick="GiveClassicTemplate.share(this);"> <?php echo esc_html__('Share on Facebook', 'give'); ?> <i class="fab fa-facebook"></i> </button> <button class="give-btn social-btn twitter-btn" onclick="GiveClassicTemplate.share(this);"> <?php echo esc_html__('Share on Twitter', 'give'); ?> <i class="fab fa-twitter"></i> </button> </div> </div> <?php endif; ?> <div class="receipt-sections"> <?php foreach ($receipt as $section) : /* @var Section $section */ if (!$section->getLineItems() || 'PDFReceipt' === $section->id) { continue; } ?> <div class="details"> <?php if ($section->label) : ?> <h2 class="headline"> <?php echo esc_html($section->label); ?> </h2> <?php endif; ?> <dl class="details-table"> <?php foreach ($section as $lineItem) : /* @var LineItem $lineItem */ if (!$lineItem->value) { continue; } $class = ''; if (DonationReceipt::DONATIONSECTIONID === $section->id) { $class = 'totalAmount' === $lineItem->id ? 'total' : ''; } ?> <div class="details-row details-row--<?php echo esc_attr($lineItem->id); ?>"> <?php echo $lineItem->icon; /* phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- $lineItem->icon is developer-authored markup set via the public Section::addLineItem() API (PHP code, never request input); wp_kses_post() would strip a custom SVG icon. */ ?> <dt class="detail"><?php echo esc_html($lineItem->label); ?></dt> <dd class="value" data-value="<?php echo esc_attr($lineItem->value); ?>"><?php echo wp_kses_post($lineItem->value); ?></dd> </div> <?php endforeach; ?> </dl> </div> <?php endforeach; ?> </div> <div class="dashboard-link-container"> <a class="dashboard-link" href="<?php echo esc_url($donorDashboardUrl); ?>" target="_parent"> <?php echo esc_html__('Go to my Donor Dashboard', 'give'); ?><i class="fas fa-long-arrow-alt-right"></i> </a> <?php if (isset($section['receiptLink'])) : ?> <div class="give-btn download-btn"> <?php echo wp_kses_post($section['receiptLink']->value); ?> </div> <?php endif; ?> </div> </article> <?php $pageId = give_get_option('success_page'); $iframeContentView = (new IframeContentView())->setTitle(esc_html__('Donation Receipt', 'give'))->setPostId($pageId)->setBody(ob_get_clean()); echo $iframeContentView->renderBody(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- renderBody() returns the receipt markup captured above by ob_get_clean(), already escaped piece by piece; wp_kses_post() would strip the inline <svg>/<use> icons.
Save File
Cancel