PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.7.0.1
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.7.0.1
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / endpoints / class-charitable-donation-receipt-endpoint.php

class-charitable-donation-receipt-endpoint.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.7.0.1, at includes/endpoints/class-charitable-donation-receipt-endpoint.php

200 lines 4.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Donation receipt endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Donation_Receipt_Endpoint
6 * @author David Bisset
7 * @copyright Copyright (c) 2022, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.5.0
10 * @version 1.6.56
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Donation_Receipt_Endpoint' ) ) :
18
19 /**
20 * Charitable_Donation_Receipt_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Donation_Receipt_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'donation_receipt';
28
29 /**
30 * Return the endpoint ID.
31 *
32 * @since 1.5.0
33 *
34 * @return string
35 */
36 public static function get_endpoint_id() {
37 return self::ID;
38 }
39
40 /**
41 * Add rewrite rules for the endpoint.
42 *
43 * @since 1.5.0
44 */
45 public function setup_rewrite_rules() {
46 add_rewrite_endpoint( 'donation_receipt', EP_ROOT );
47 add_rewrite_rule( 'donation-receipt/([0-9]+)/?$', 'index.php?donation_id=$matches[1]&donation_receipt=1', 'top' );
48 }
49
50 /**
51 * Return the endpoint URL.
52 *
53 * @since 1.5.0
54 *
55 * @global WP_Rewrite $wp_rewrite
56 * @param array $args Mixed page arguments.
57 * @return string
58 */
59 public function get_page_url( $args = array() ) {
60 global $wp_rewrite;
61
62 $receipt_page = charitable_get_option( 'donation_receipt_page', 'auto' );
63
64 $donation_id = isset( $args['donation_id'] ) ? $args['donation_id'] : get_the_ID();
65
66 if ( 'auto' !== $receipt_page ) {
67 return esc_url_raw( add_query_arg( array( 'donation_id' => $donation_id ), get_permalink( $receipt_page ) ) );
68 }
69
70 if ( $wp_rewrite->using_permalinks() ) {
71 $url = $this->sanitize_endpoint_url(
72 home_url(),
73 'donation-receipt/' . $donation_id
74 );
75 } else {
76 $url = esc_url_raw(
77 add_query_arg(
78 array(
79 'donation_receipt' => 1,
80 'donation_id' => $donation_id,
81 ),
82 home_url()
83 )
84 );
85 }
86
87 return $url;
88 }
89
90 /**
91 * Return whether we are currently viewing the endpoint.
92 *
93 * @since 1.5.0
94 *
95 * @global WP_Query $wp_query
96 * @param array $args Mixed arguments.
97 * @return boolean
98 */
99 public function is_page( $args = array() ) {
100 global $wp_query;
101
102 $receipt_page = charitable_get_option( 'donation_receipt_page', 'auto' );
103
104 if ( 'auto' !== $receipt_page ) {
105 return is_page( $receipt_page );
106 }
107
108 return is_main_query()
109 && isset( $wp_query->query_vars['donation_receipt'] )
110 && isset( $wp_query->query_vars['donation_id'] );
111 }
112
113 /**
114 * Whether the endpoint uses a custom template.
115 *
116 * @since 1.6.55
117 *
118 * @return boolean
119 */
120 public function uses_custom_template() {
121 if ( array_key_exists( 'print', $_GET ) ) {
122 return true;
123 }
124
125 return ! charitable_is_block_theme() && 'auto' === charitable_get_option( 'donation_receipt_page', 'auto' );
126 }
127
128 /**
129 * Prepare the template for the endpoint.
130 *
131 * @since 1.6.55
132 *
133 * @return void
134 */
135 public function setup_template() {
136 /**
137 * Filter the title of the donation receipt page.
138 *
139 * @since 1.4.0
140 *
141 * @param string $title The page title.
142 */
143 $donation_receipt_page_title = apply_filters( 'charitable_donation_receipt_page_title', __( 'Your Receipt', 'charitable' ) );
144
145 new Charitable_Ghost_Page(
146 'donation-receipt-page',
147 array(
148 'title' => $donation_receipt_page_title,
149 'content' => '<!-- ' . __( 'Silence is golden', 'charitable' ) . ' -->',
150 )
151 );
152 }
153
154 /**
155 * Return the default template for this endpoint.
156 *
157 * @since 1.5.0
158 *
159 * @param string $template The default template.
160 * @return array
161 */
162 public function get_template( $template ) {
163 return array( 'donation-receipt-page.php', 'page.php', 'singular.php', 'index.php' );
164 }
165
166 /**
167 * Get the content to display for the endpoint.
168 *
169 * @since 1.5.0
170 *
171 * @param string $content The default content to display.
172 * @return string
173 */
174 public function get_content( $content ) {
175 if ( ! in_the_loop() ) {
176 return $content;
177 }
178
179 /* If we are NOT using the automatic option, this is a static page with the shortcode, so don't filter again. */
180 if ( 'auto' !== charitable_get_option( 'donation_receipt_page', 'auto' ) ) {
181 return $content;
182 }
183
184 return charitable_template_donation_receipt_output( $content );
185 }
186
187 /**
188 * Return the body class to add for the endpoint.
189 *
190 * @since 1.5.0
191 *
192 * @return string
193 */
194 public function get_body_class() {
195 return 'campaign-donation-receipt';
196 }
197 }
198
199 endif;
200