PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.13
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.13
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
← All changes | includes/public/class-charitable-public.php +234 -84 1.6.8 → 1.8.13 View file →
@@ -1,17 +1,20 @@
1 1 <?php
2 2 /**
3 3 * Charitable Public class.
4 4 *
5 - * @package Charitable/Classes/Charitable_Public
6 - * @version 1.0.0
7 - * @author Eric Daams
8 - * @copyright Copyright (c) 2019, Studio 164a
9 - * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
5 + * @package Charitable/Classes/Charitable_Public
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.0.0
10 + * @version 1.6.60
10 11 */
11 12
12 13 // Exit if accessed directly.
13 -if ( ! defined( 'ABSPATH' ) ) { exit; }
14 +if ( ! defined( 'ABSPATH' ) ) {
15 + exit;
16 +}
14 17
15 18 if ( ! class_exists( 'Charitable_Public' ) ) :
16 19
17 20 /**
@@ -16,10 +19,9 @@
16 19
17 20 /**
18 21 * Charitable Public class.
19 22 *
20 - * @final
21 - * @since 1.0.0
23 + * @since 1.0.0
22 24 */
23 25 final class Charitable_Public {
24 26
25 27 /**
@@ -51,33 +53,17 @@
51 53 *
52 54 * @since 1.0.0
53 55 */
54 56 private function __construct() {
55 - add_action( 'after_setup_theme', array( $this, 'load_template_files' ) );
56 57 add_action( 'wp_enqueue_scripts', array( $this, 'setup_scripts' ) );
57 58 add_action( 'wp_enqueue_scripts', array( $this, 'maybe_enqueue_donation_form_scripts' ), 11 );
58 59 add_action( 'charitable_campaign_loop_before', array( $this, 'maybe_enqueue_donation_form_scripts' ) );
59 60 add_filter( 'post_class', array( $this, 'campaign_post_class' ) );
60 - add_filter( 'comments_open', array( $this, 'disable_comments_on_application_pages' ) );
61 61
62 62 do_action( 'charitable_public_start', $this );
63 63 }
64 64
65 65 /**
66 - * Load the template functions after theme is loaded.
67 - *
68 - * This gives themes time to override the functions.
69 - *
70 - * @since 1.2.3
71 - *
72 - * @return void
73 - */
74 - public function load_template_files() {
75 - require_once( 'charitable-template-functions.php' );
76 - require_once( 'charitable-template-hooks.php' );
77 - }
78 -
79 - /**
80 66 * Loads public facing scripts and stylesheets.
81 67 *
82 68 * @since 1.0.0
83 69 *
@@ -83,33 +69,52 @@
83 69 *
84 70 * @return void
85 71 */
86 72 public function setup_scripts() {
87 - if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
88 - $suffix = '';
89 - $version = '';
90 - } else {
91 - $suffix = '.min';
92 - $version = charitable()->get_version();
93 - }
73 + $min = charitable_get_min_suffix();
74 + $version = charitable()->get_version();
94 75
95 76 $assets_dir = charitable()->get_path( 'assets', false );
96 77
97 78 /* Main Charitable script. */
98 - $minimum = charitable_get_minimum_donation_amount();
99 - $amount_msg = $minimum > 0
100 - ? sprintf(
79 + $currency = charitable_get_currency_helper();
80 + $minimum = charitable_get_minimum_donation_amount( charitable_get_current_campaign_id() );
81 +
82 + if ( $minimum > 0 ) {
83 + $amount_msg = sprintf(
101 84 /* Translators: %s: minimum donatino amount */
102 - __( 'You must donate at least %s.', 'charitable' ), charitable_format_money( $minimum )
103 - )
104 - : sprintf(
85 + __( 'You must donate at least %s.', 'charitable' ),
86 + $currency->get_monetary_amount( $minimum, false, true )
87 + );
88 + } else {
89 + $amount_msg = sprintf(
105 90 /* Translators: %s: minimum donatino amount */
106 - __( 'You must donate more than %s.', 'charitable' ), charitable_format_money( $minimum )
91 + __( 'You must donate more than %s.', 'charitable' ),
92 + $currency->get_monetary_amount( $minimum, false, true )
107 93 );
94 + }
108 95
109 - $currency = charitable_get_currency_helper();
96 + $maximum = charitable_get_maximum_donation_amount( charitable_get_current_campaign_id() );
97 + $max_exceeded_msg = $maximum
98 + ? sprintf(
99 + /* Translators: %s: maximum donation amount */
100 + __( 'The maximum donation amount permitted is %s.', 'charitable' ),
101 + $currency->get_monetary_amount( $maximum, false, true )
102 + )
103 + : '';
110 104
111 105 /**
106 + * Return whether $0 donations are permitted.
107 + *
108 + * Note that this filter is also called in Charitable_Donation_Form::validate_amount().
109 + *
110 + * @since 1.2.0
111 + *
112 + * @param boolean $permitted Whether $0 donations are permitted.
113 + */
114 + $permit_0_donation = apply_filters( 'charitable_permit_0_donation', false );
115 +
116 + /**
112 117 * Filter the Javascript vars array.
113 118 *
114 119 * @since 1.0.0
115 120 *
@@ -114,34 +119,45 @@
114 119 * @since 1.0.0
115 120 *
116 121 * @param array $vars The set of vars.
117 122 */
118 - $vars = apply_filters( 'charitable_javascript_vars', array(
119 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
120 - 'loading_gif' => $assets_dir . '/images/charitable-loading.gif',
121 - 'currency_symbol' => $currency->get_currency_symbol(),
122 - 'currency_format_num_decimals' => esc_attr( $currency->get_decimals() ),
123 - 'currency_format_decimal_sep' => esc_attr( $currency->get_decimal_separator() ),
124 - 'currency_format_thousand_sep' => esc_attr( $currency->get_thousands_separator() ),
125 - 'currency_format' => esc_attr( $currency->get_accounting_js_format() ), // For accounting.js.
126 - 'minimum_donation' => $minimum,
127 - 'error_invalid_amount' => $amount_msg,
128 - 'error_required_fields' => __( 'Please fill out all required fields.', 'charitable' ),
129 - 'error_unknown' => __( 'Your donation could not be processed. Please reload the page and try again.', 'charitable' ),
130 - 'error_invalid_cc_number' => __( 'The credit card passed is not valid.', 'charitable' ),
131 - 'error_invalid_cc_expiry' => __( 'The credit card expiry date is not valid.', 'charitable' ),
132 - ) );
123 + $vars = apply_filters(
124 + 'charitable_javascript_vars',
125 + array(
126 + 'ajaxurl' => admin_url( 'admin-ajax.php' ),
127 + 'loading_gif' => $assets_dir . 'images/charitable-loading.gif',
128 + 'country' => charitable_get_option( 'country' ),
129 + 'currency' => charitable_get_currency(),
130 + 'currency_symbol' => $currency->get_currency_symbol(),
131 + 'currency_format_num_decimals' => esc_attr( $currency->get_decimals() ),
132 + 'currency_format_decimal_sep' => esc_attr( $currency->get_decimal_separator() ),
133 + 'currency_format_thousand_sep' => esc_attr( $currency->get_thousands_separator() ),
134 + 'currency_format' => esc_attr( $currency->get_accounting_js_format() ), // For accounting.js.
135 + 'minimum_donation' => $minimum,
136 + 'maximum_donation' => $maximum,
137 + 'permit_0_donation' => $permit_0_donation,
138 + 'error_invalid_amount' => $amount_msg,
139 + 'error_max_exceeded' => $max_exceeded_msg,
140 + 'error_required_fields' => __( 'Please fill out all required fields.', 'charitable' ),
141 + 'error_unknown' => __( 'Your donation could not be processed. Please reload the page and try again.', 'charitable' ),
142 + 'error_invalid_cc_number' => __( 'The credit card passed is not valid.', 'charitable' ),
143 + 'error_invalid_cc_expiry' => __( 'The credit card expiry date is not valid.', 'charitable' ),
144 + 'version' => charitable()->get_version(),
145 + 'test_mode' => (int) charitable_get_option( 'test_mode' ),
146 + 'error_notice_donation_display' => esc_attr( charitable_get_option( 'donation_form_notices_display' ) ),
147 + )
148 + );
133 149
134 150 /* Accounting.js */
135 151 wp_register_script(
136 152 'accounting',
137 - $assets_dir . 'js/libraries/accounting' . $suffix . '.js',
138 - array( 'jquery-core' ),
153 + $assets_dir . 'js/libraries/accounting' . $min . '.js',
154 + array( 'jquery' ),
139 155 $version,
140 156 true
141 157 );
142 158
143 - $deps = array( 'accounting', 'jquery-core' );
159 + $deps = array( 'accounting', 'jquery' );
144 160
145 161 if ( wp_script_is( 'charitable-sessions', 'enqueued' ) ) {
146 162 array_unshift( $deps, 'charitable-sessions' );
147 163 }
@@ -147,9 +163,9 @@
147 163 }
148 164
149 165 wp_register_script(
150 166 'charitable-script',
151 - $assets_dir . 'js/charitable' . $suffix . '.js',
167 + $assets_dir . 'js/charitable' . $min . '.js',
152 168 $deps,
153 169 $version,
154 170 true
155 171 );
@@ -162,18 +178,36 @@
162 178
163 179 /* Credit card validation */
164 180 wp_register_script(
165 181 'charitable-credit-card',
166 - $assets_dir . 'js/charitable-credit-card' . $suffix . '.js',
182 + $assets_dir . 'js/charitable-credit-card' . $min . '.js',
167 183 array( 'charitable-script' ),
168 184 $version,
169 185 true
170 186 );
171 187
188 + /* URL sanitizer. */
189 + wp_register_script(
190 + 'charitable-url-sanitizer',
191 + $assets_dir . 'js/charitable-url-sanitizer' . $min . '.js',
192 + array( 'jquery' ),
193 + $version,
194 + true
195 + );
196 +
197 + /* General forms scripts. */
198 + wp_register_script(
199 + 'charitable-forms',
200 + $assets_dir . 'js/charitable-forms' . $min . '.js',
201 + array( 'jquery' ),
202 + $version,
203 + true
204 + );
205 +
172 206 /* Main styles */
173 207 wp_register_style(
174 208 'charitable-styles',
175 - $assets_dir . 'css/charitable' . $suffix . '.css',
209 + $assets_dir . 'css/charitable' . $min . '.css',
176 210 array(),
177 211 $version
178 212 );
179 213
@@ -178,21 +212,24 @@
178 212 );
179 213
180 214 wp_enqueue_style( 'charitable-styles' );
181 215
216 + // 1.8.4.5
217 + wp_enqueue_style( 'dashicons' );
218 +
182 219 /* Lean Modal is registered but NOT enqueued yet. */
183 220 if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
184 221
185 222 wp_register_script(
186 223 'lean-modal',
187 - $assets_dir . 'js/libraries/leanModal' . $suffix . '.js',
188 - array( 'jquery-core' ),
224 + $assets_dir . 'js/libraries/leanModal' . $min . '.js',
225 + array( 'jquery' ),
189 226 $version
190 227 );
191 228
192 229 wp_register_style(
193 230 'lean-modal-css',
194 - $assets_dir . 'css/modal' . $suffix .'.css',
231 + $assets_dir . 'css/modal' . $min . '.css',
195 232 array(),
196 233 $version
197 234 );
198 235
@@ -199,9 +236,9 @@
199 236 }
200 237
201 238 wp_register_style(
202 239 'charitable-datepicker',
203 - $assets_dir . 'css/charitable-datepicker' . $suffix .'.css',
240 + $assets_dir . 'css/charitable-datepicker' . $min . '.css',
204 241 array(),
205 242 $version
206 243 );
207 244
@@ -206,18 +243,18 @@
206 243 );
207 244
208 245 /* pupload Fields is also registered but NOT enqueued. */
209 246 $upload_vars = array(
210 - 'remove_image' => _x( 'Remove', 'remove image button text', 'charitable' ),
211 - 'max_file_uploads_single' => __( 'You can only upload %d file', 'charitable' ),
247 + 'remove_image' => _x( 'Remove', 'remove image button text', 'charitable' ),
248 + 'max_file_uploads_single' => /* translators: %d: number of files */ __( 'You can only upload %d file', 'charitable' ),
212 249 'max_file_uploads_plural' => __( 'You can only upload a maximum of %d files', 'charitable' ),
213 - 'max_file_size' => __( '%1$s exceeds the max upload size of %2$s', 'charitable' ),
214 - 'upload_problem' => __( '%s failed to upload. Please try again.', 'charitable' ),
250 + 'max_file_size' => /* translators: %1$s: file name; %2$s: max upload size */ __( '%1$s exceeds the max upload size of %2$s', 'charitable' ),
251 + 'upload_problem' => /* translators: %s: file name */ __( '%s failed to upload. Please try again.', 'charitable' ),
215 252 );
216 253
217 254 wp_register_script(
218 255 'charitable-plup-fields',
219 - $assets_dir . 'js/charitable-plupload-fields' . $suffix . '.js',
256 + $assets_dir . 'js/charitable-plupload-fields' . $min . '.js',
220 257 array( 'jquery-ui-sortable', 'wp-ajax-response', 'plupload-all' ),
221 258 $version,
222 259 true
223 260 );
@@ -229,20 +266,96 @@
229 266 );
230 267
231 268 wp_register_style(
232 269 'charitable-plup-styles',
233 - $assets_dir . 'css/charitable-plupload-fields' . $suffix . '.css',
270 + $assets_dir . 'css/charitable-plupload-fields' . $min . '.css',
234 271 array(),
235 272 $version
236 273 );
274 +
275 + if ( charitable()->load_core_stripe() && class_exists( 'Charitable_Gateway_Stripe_AM' ) ) :
276 +
277 + $gateway = new Charitable_Gateway_Stripe_AM();
278 + $keys = $gateway->get_keys();
279 + $settings = get_option( 'charitable_settings' );
280 +
281 + // If there is no public key, skip loading Stripe scripts but continue.
282 + if ( isset( $keys['public_key'] ) && ! empty( $keys['public_key'] ) ) {
283 +
284 + $cc_fields_format = ( ! empty( $settings['gateways_stripe']['cc_fields_format'] ) && '' !== $settings['gateways_stripe']['cc_fields_format'] ) ? $settings['gateways_stripe']['cc_fields_format'] : '';
285 +
286 + $stripe_vars = array(
287 + 'key' => $keys['public_key'],
288 + 'currency' => charitable_get_currency(),
289 + 'site_name' => get_option( 'blogname' ),
290 + 'zero_decimal' => Charitable_Gateway_Stripe_AM::is_zero_decimal_currency(),
291 + 'cc_fields_format' => esc_attr( $cc_fields_format ),
292 + );
293 +
294 + /* Register Stripe JS script. */
295 + wp_register_script(
296 + 'stripe-v3',
297 + 'https://js.stripe.com/v3/',
298 + array(),
299 + $version,
300 + true
301 + );
302 +
303 + $dependencies = array( 'charitable-script', 'stripe-v3', 'jquery' );
304 +
305 + if ( charitable_get_option( array( 'gateways_stripe', 'enable_stripe_checkout' ) ) ) {
306 + $stripe_vars['mode'] = 'checkout';
307 + } else {
308 + $stripe_vars['mode'] = 'payment-intents';
309 + }
310 +
311 + wp_register_script(
312 + 'charitable-stripe',
313 + $assets_dir . 'js/stripe/charitable-stripe' . $min . '.js',
314 + $dependencies,
315 + $version,
316 + true
317 + );
318 +
319 + wp_localize_script(
320 + 'charitable-stripe',
321 + 'CHARITABLE_STRIPE_VARS',
322 + $stripe_vars
323 + );
324 +
325 + if ( 'payment-intents' == $stripe_vars['mode'] ) {
326 + /**
327 + * Prevent the Stripe script from loading site-wide.
328 + *
329 + * @since 1.4.3
330 + *
331 + * @param boolean $load Whether to load the scripts sitewide. Defaults to true.
332 + */
333 + if ( apply_filters( 'charitable_stripe_load_stripe_scripts_sitewide', true ) ) {
334 + wp_enqueue_script( 'stripe-v3' );
335 + }
336 + }
337 + }
338 +
339 + endif;
340 +
341 + /* General forms scripts. */
342 + wp_register_script(
343 + 'charitable-frontend-v2',
344 + $assets_dir . 'js/charitable-frontend' . $min . '.js',
345 + array( 'jquery' ),
346 + $version,
347 + true
348 + );
349 + wp_enqueue_script( 'charitable-frontend-v2' );
237 350 }
238 351
239 352 /**
240 353 * Conditionally load the donation form scripts if we're viewing the donation form.
241 354 *
242 - * @since 1.4.0
355 + * @since 1.4.0
243 356 *
244 - * @return boolean True if scripts were loaded. False otherwise.
357 + * @return boolean True if scripts were loaded. False otherwise.
245 358 */
246 359 public function maybe_enqueue_donation_form_scripts() {
247 360 $load = charitable_is_page( 'campaign_donation_page' );
248 361
@@ -259,11 +372,11 @@
259 372
260 373 /**
261 374 * Enqueues the donation form scripts.
262 375 *
263 - * @since 1.4.6
376 + * @since 1.4.6
264 377 *
265 - * @return void
378 + * @return void
266 379 */
267 380 public function enqueue_donation_form_scripts() {
268 381 wp_enqueue_script( 'charitable-script' );
269 382
@@ -274,12 +387,12 @@
274 387
275 388 /**
276 389 * Adds custom post classes when viewing campaign.
277 390 *
278 - * @since 1.0.0
391 + * @since 1.0.0
279 392 *
280 - * @param string[] $classes List of classes to be added with post_class().
281 - * @return string[]
393 + * @param string[] $classes List of classes to be added with post_class().
394 + * @return string[]
282 395 */
283 396 public function campaign_post_class( $classes ) {
284 397 $campaign = charitable_get_current_campaign();
285 398
@@ -286,10 +399,22 @@
286 399 if ( ! $campaign ) {
287 400 return $classes;
288 401 }
289 402
290 - $classes[] = $campaign->has_goal() ? 'campaign-has-goal' : 'campaign-has-no-goal';
291 - $classes[] = $campaign->is_endless() ? 'campaign-is-endless' : 'campaign-has-end-date';
403 + if ( $campaign->has_goal() ) {
404 + $classes[] = 'campaign-has-goal';
405 + $classes[] = $campaign->has_achieved_goal() ? 'campaign-has-achieved-goal' : 'campaign-has-not-achieved-goal';
406 + } else {
407 + $classes[] = 'campaign-has-no-goal';
408 + }
409 +
410 + if ( $campaign->is_endless() ) {
411 + $classes[] = 'campaign-is-endless';
412 + } else {
413 + $classes[] = 'campaign-has-end-date';
414 + $classes[] = $campaign->has_ended() ? 'campaign-has-ended' : 'campaign-has-not-ended';
415 + }
416 +
292 417 return $classes;
293 418 }
294 419
295 420 /**
@@ -294,12 +419,15 @@
294 419
295 420 /**
296 421 * Disable comments on application pages like the donation page.
297 422 *
298 - * @since 1.3.0
299 - *
300 - * @param boolean $open Whether comments are open.
301 - * @return boolean
423 + * @deprecated 2.2.0
424 + *
425 + * @since 1.3.0
426 + * @since 1.6.36 Deprecated. This is now handled in Charitable_Endpoints.
427 + *
428 + * @param boolean $open Whether comments are open.
429 + * @return boolean
302 430 */
303 431 public function disable_comments_on_application_pages( $open ) {
304 432 /* If open is already false, just hit return. */
305 433 if ( ! $open ) {
@@ -309,12 +437,34 @@
309 437 if ( charitable_is_page( 'campaign_donation_page', array( 'strict' => true ) )
310 438 || charitable_is_page( 'campaign_widget_page' )
311 439 || charitable_is_page( 'donation_receipt_page' )
312 440 || charitable_is_page( 'donation_processing_page' ) ) {
313 - $open = false;
441 + $open = false;
314 442 }
315 443
316 444 return $open;
445 + }
446 +
447 + /**
448 + * Load the template functions after theme is loaded.
449 + *
450 + * This gives themes time to override the functions.
451 + *
452 + * @deprecated 2.0.0
453 + *
454 + * @since 1.2.3
455 + * @since 1.6.10 Deprecated
456 + *
457 + * @return void
458 + */
459 + public function load_template_files() {
460 + charitable_get_deprecated()->deprecated_function(
461 + __METHOD__,
462 + '1.6.10',
463 + 'charitable()->load_template_files()'
464 + );
465 +
466 + charitable()->load_template_files();
317 467 }
318 468 }
319 469
320 470 endif;