PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
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-campaign-endpoint.php

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

269 lines 7.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Campaign endpoint.
4 *
5 * @package Charitable/Classes/Charitable_Campaign_Endpoint
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, 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.55
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Campaign_Endpoint' ) ) :
18
19 /**
20 * Charitable_Campaign_Endpoint
21 *
22 * @since 1.5.0
23 */
24 class Charitable_Campaign_Endpoint extends Charitable_Endpoint {
25
26 /** Endpoint ID. */
27 const ID = 'campaign';
28
29 /**
30 * Endpoint class constructor.
31 *
32 * @since 1.6.36
33 */
34 public function __construct() {
35 $this->comments_disabled = false;
36 }
37
38 /**
39 * Return the endpoint ID.
40 *
41 * @since 1.5.0
42 *
43 * @return string
44 */
45 public static function get_endpoint_id() {
46 return self::ID;
47 }
48
49 /**
50 * Return the endpoint URL.
51 *
52 * @since 1.5.0
53 *
54 * @global WP_Rewrite $wp_rewrite
55 * @param array $args Mixed args.
56 * @return string
57 */
58 public function get_page_url( $args = array() ) {
59 $campaign_id = array_key_exists( 'campaign_id', $args ) ? $args['campaign_id'] : get_the_ID();
60
61 return get_permalink( $campaign_id );
62 }
63
64 /**
65 * Return whether we are currently viewing the endpoint.
66 *
67 * @since 1.5.0
68 *
69 * @global WP_Query $wp_query
70 * @param array $args Mixed arguments.
71 * @return boolean
72 */
73 public function is_page( $args = array() ) {
74 global $wp_query;
75
76 if ( is_null( $wp_query->get_queried_object() ) ) {
77 return false;
78 }
79
80 if ( ! $wp_query->is_singular( Charitable::CAMPAIGN_POST_TYPE ) ) {
81 return false;
82 }
83
84 return ! array_key_exists( 'donate', $wp_query->query_vars );
85 }
86
87 /**
88 * Prepare the template.
89 *
90 * @since 1.6.55
91 *
92 * @return void
93 */
94 public function setup_template() {
95 $donation_id = get_query_var( 'donation_id', false );
96
97 /* If a donation ID is included, make sure it belongs to the current user. */
98 if ( $donation_id && ! charitable_user_can_access_donation( $donation_id ) ) {
99 wp_safe_redirect( charitable_get_permalink( 'campaign_donation' ) );
100 exit();
101 }
102 }
103
104 /**
105 * Get the content to display for the endpoint.
106 *
107 * @since 1.5.0
108 *
109 * @param string $content Default content.
110 * @return string
111 */
112 public function get_content( $content ) {
113 if ( ! charitable_is_main_loop() ) {
114 return $content;
115 }
116
117 /**
118 * If this is the donation form, and it's showing on a separate page, return the content.
119 */
120 if ( charitable_is_page( 'campaign_donation_page' ) ) {
121 if ( 'separate_page' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
122 return $content;
123 }
124
125 if ( false !== get_query_var( 'donate', false ) ) {
126 return $content;
127 }
128 }
129
130 /**
131 * If you do not want to use the default campaign template, use this filter and return false.
132 *
133 * @uses charitable_use_campaign_template
134 */
135 if ( ! apply_filters( 'charitable_use_campaign_template', true ) ) {
136 return $content;
137 }
138
139 /**
140 * Remove ourselves as a filter to prevent eternal recursion if apply_filters( 'the_content' )
141 * is called by one of the templates.
142 */
143 remove_filter( 'the_content', array( charitable()->endpoints(), 'get_content' ) );
144
145 /**
146 * IF there is no campaign template, that means this is likely a legacy campaign (1.x) and fall back to the content-campaign template.
147 */
148 $campaign_template = charitable_get_current_campaign_template();
149
150 ob_start();
151
152 if ( ! $campaign_template ) {
153
154 charitable_template(
155 'content-campaign.php',
156 array(
157 'content' => $content,
158 'campaign' => charitable_get_current_campaign(),
159 )
160 );
161
162 } else {
163
164 charitable_template(
165 'campaign/builder/content.php',
166 array(
167 'content' => $content,
168 'template' => charitable_get_current_campaign_template(),
169 'campaign' => charitable_get_current_campaign(),
170 'campaign_data' => charitable_get_current_campaign_data(),
171
172 )
173 );
174
175 }
176
177 $this->prefix_add_footer_styles( charitable_get_current_campaign_template_id(), charitable_get_current_campaign_id() );
178
179 $content = ob_get_clean();
180
181 add_filter( 'the_content', array( charitable()->endpoints(), 'get_content' ) );
182
183 return $content;
184 }
185
186 /**
187 * Return the body class to add for the endpoint.
188 *
189 * @since 1.5.0
190 *
191 * @return string
192 */
193 public function get_body_class() {
194 return 'campaign-donation-page';
195 }
196
197 /**
198 * Load template specific CSS in the footer, primarily for showing off template in a preview.
199 *
200 * @since 1.8.0
201 * @since 1.8.1 Added $template_id blank check.
202 *
203 * @param string $template_id Template slug.
204 * @param object $campaign_id ID of campaign.
205 */
206 public function prefix_add_footer_styles( $template_id = 'basic', $campaign_id = false ) {
207
208 if ( '' === $template_id ) {
209 return;
210 }
211
212 $min = charitable_get_min_suffix();
213 $version = charitable_is_break_cache() ? charitable()->get_version() . '.' . time() : charitable()->get_version();
214 $assets_dir = charitable()->get_path( 'assets', false );
215 $campaign_data = ( false !== $campaign_id ) ? get_post_meta( intval( $campaign_id ), 'campaign_settings_v2', true ) : false;
216
217 if ( false === $campaign_data || '' === $campaign_data ) {
218 return;
219 }
220
221 // Pass along the theme color overides to the theme. Start by defining the base/default theme values as stored in settings.
222 $query_args = array(
223 'p' => ! empty( $campaign_data['color_base_primary'] ) ? charitable_sanitize_hex( $campaign_data['color_base_primary'], false ) : false,
224 's' => ! empty( $campaign_data['color_base_secondary'] ) ? charitable_sanitize_hex( $campaign_data['color_base_secondary'], false ) : false,
225 't' => ! empty( $campaign_data['color_base_tertiary'] ) ? charitable_sanitize_hex( $campaign_data['color_base_tertiary'], false ) : false,
226 'b' => ! empty( $campaign_data['color_base_button'] ) ? charitable_sanitize_hex( $campaign_data['color_base_button'], false ) : false,
227 );
228
229 // Now check for overrides in the settings.
230 $layout_theme_settings = ! empty( $campaign_data['layout']['advanced'] ) ? $campaign_data['layout']['advanced'] : array();
231
232 $query_args['p'] = ! empty( $layout_theme_settings['theme_color_primary'] ) ? charitable_sanitize_hex( $layout_theme_settings['theme_color_primary'], false ) : $query_args['p'];
233 $query_args['s'] = ! empty( $layout_theme_settings['theme_color_secondary'] ) ? charitable_sanitize_hex( $layout_theme_settings['theme_color_secondary'], false ) : $query_args['s'];
234 $query_args['t'] = ! empty( $layout_theme_settings['theme_color_tertiary'] ) ? charitable_sanitize_hex( $layout_theme_settings['theme_color_tertiary'], false ) : $query_args['t'];
235 $query_args['b'] = ! empty( $layout_theme_settings['theme_color_button'] ) ? charitable_sanitize_hex( $layout_theme_settings['theme_color_button'], false ) : $query_args['b'];
236
237 $template_frontend_css_url = add_query_arg(
238 apply_filters(
239 'charitable_builder_template_frontend_styles_' . $template_id,
240 $query_args,
241 $template_id,
242 $campaign_data
243 ),
244 rest_url( 'charitable/v1/campaign-css/' . $template_id )
245 );
246
247 wp_enqueue_style(
248 'charitable-campaign-theme-base',
249 apply_filters(
250 'charitable_builder_template_frontend_base_styles_' . $template_id,
251 $assets_dir . 'css/campaign-builder/themes/frontend/base' . $min . '.css',
252 $template_id,
253 $campaign_data
254 ),
255 array(),
256 $version
257 );
258
259 wp_enqueue_style(
260 'charitable-campaign-theme-' . $template_id,
261 $template_frontend_css_url,
262 array( 'charitable-campaign-theme-base' ),
263 $version
264 );
265 }
266 }
267
268 endif;
269