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 +235 -82 1.6.6 → 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) 2018, 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,31 +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
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 + : '';
104 +
109 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 + /**
110 117 * Filter the Javascript vars array.
111 118 *
112 119 * @since 1.0.0
113 120 *
@@ -112,33 +119,45 @@
112 119 * @since 1.0.0
113 120 *
114 121 * @param array $vars The set of vars.
115 122 */
116 - $vars = apply_filters( 'charitable_javascript_vars', array(
117 - 'ajaxurl' => admin_url( 'admin-ajax.php' ),
118 - 'loading_gif' => $assets_dir . '/images/charitable-loading.gif',
119 - 'currency_format_num_decimals' => esc_attr( charitable_get_currency_helper()->get_decimals() ),
120 - 'currency_format_decimal_sep' => esc_attr( charitable_get_currency_helper()->get_decimal_separator() ),
121 - 'currency_format_thousand_sep' => esc_attr( charitable_get_currency_helper()->get_thousands_separator() ),
122 - 'currency_format' => esc_attr( charitable_get_currency_helper()->get_accounting_js_format() ), // For accounting.js.
123 - 'minimum_donation' => $minimum,
124 - 'error_invalid_amount' => $amount_msg,
125 - 'error_required_fields' => __( 'Please fill out all required fields.', 'charitable' ),
126 - 'error_unknown' => __( 'Your donation could not be processed. Please reload the page and try again.', 'charitable' ),
127 - 'error_invalid_cc_number' => __( 'The credit card passed is not valid.', 'charitable' ),
128 - 'error_invalid_cc_expiry' => __( 'The credit card expiry date is not valid.', 'charitable' ),
129 - ) );
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 + );
130 149
131 150 /* Accounting.js */
132 151 wp_register_script(
133 152 'accounting',
134 - $assets_dir . 'js/libraries/accounting'. $suffix . '.js',
135 - array( 'jquery-core' ),
153 + $assets_dir . 'js/libraries/accounting' . $min . '.js',
154 + array( 'jquery' ),
136 155 $version,
137 156 true
138 157 );
139 158
140 - $deps = array( 'accounting', 'jquery-core' );
159 + $deps = array( 'accounting', 'jquery' );
141 160
142 161 if ( wp_script_is( 'charitable-sessions', 'enqueued' ) ) {
143 162 array_unshift( $deps, 'charitable-sessions' );
144 163 }
@@ -144,9 +163,9 @@
144 163 }
145 164
146 165 wp_register_script(
147 166 'charitable-script',
148 - $assets_dir . 'js/charitable'. $suffix . '.js',
167 + $assets_dir . 'js/charitable' . $min . '.js',
149 168 $deps,
150 169 $version,
151 170 true
152 171 );
@@ -159,18 +178,36 @@
159 178
160 179 /* Credit card validation */
161 180 wp_register_script(
162 181 'charitable-credit-card',
163 - $assets_dir . 'js/charitable-credit-card'. $suffix . '.js',
182 + $assets_dir . 'js/charitable-credit-card' . $min . '.js',
164 183 array( 'charitable-script' ),
165 184 $version,
166 185 true
167 186 );
168 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 +
169 206 /* Main styles */
170 207 wp_register_style(
171 208 'charitable-styles',
172 - $assets_dir . 'css/charitable' . $suffix .'.css',
209 + $assets_dir . 'css/charitable' . $min . '.css',
173 210 array(),
174 211 $version
175 212 );
176 213
@@ -175,21 +212,24 @@
175 212 );
176 213
177 214 wp_enqueue_style( 'charitable-styles' );
178 215
216 + // 1.8.4.5
217 + wp_enqueue_style( 'dashicons' );
218 +
179 219 /* Lean Modal is registered but NOT enqueued yet. */
180 220 if ( 'modal' == charitable_get_option( 'donation_form_display', 'separate_page' ) ) {
181 221
182 222 wp_register_script(
183 223 'lean-modal',
184 - $assets_dir . 'js/libraries/leanModal' . $suffix . '.js',
185 - array( 'jquery-core' ),
224 + $assets_dir . 'js/libraries/leanModal' . $min . '.js',
225 + array( 'jquery' ),
186 226 $version
187 227 );
188 228
189 229 wp_register_style(
190 230 'lean-modal-css',
191 - $assets_dir . 'css/modal' . $suffix .'.css',
231 + $assets_dir . 'css/modal' . $min . '.css',
192 232 array(),
193 233 $version
194 234 );
195 235
@@ -196,9 +236,9 @@
196 236 }
197 237
198 238 wp_register_style(
199 239 'charitable-datepicker',
200 - $assets_dir . 'css/charitable-datepicker' . $suffix .'.css',
240 + $assets_dir . 'css/charitable-datepicker' . $min . '.css',
201 241 array(),
202 242 $version
203 243 );
204 244
@@ -203,18 +243,18 @@
203 243 );
204 244
205 245 /* pupload Fields is also registered but NOT enqueued. */
206 246 $upload_vars = array(
207 - 'remove_image' => _x( 'Remove', 'remove image button text', 'charitable' ),
208 - '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' ),
209 249 'max_file_uploads_plural' => __( 'You can only upload a maximum of %d files', 'charitable' ),
210 - 'max_file_size' => __( '%1$s exceeds the max upload size of %2$s', 'charitable' ),
211 - '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' ),
212 252 );
213 253
214 254 wp_register_script(
215 255 'charitable-plup-fields',
216 - $assets_dir . 'js/charitable-plupload-fields' . $suffix . '.js',
256 + $assets_dir . 'js/charitable-plupload-fields' . $min . '.js',
217 257 array( 'jquery-ui-sortable', 'wp-ajax-response', 'plupload-all' ),
218 258 $version,
219 259 true
220 260 );
@@ -226,20 +266,96 @@
226 266 );
227 267
228 268 wp_register_style(
229 269 'charitable-plup-styles',
230 - $assets_dir . 'css/charitable-plupload-fields' . $suffix . '.css',
270 + $assets_dir . 'css/charitable-plupload-fields' . $min . '.css',
231 271 array(),
232 272 $version
233 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' );
234 350 }
235 351
236 352 /**
237 353 * Conditionally load the donation form scripts if we're viewing the donation form.
238 354 *
239 - * @since 1.4.0
355 + * @since 1.4.0
240 356 *
241 - * @return boolean True if scripts were loaded. False otherwise.
357 + * @return boolean True if scripts were loaded. False otherwise.
242 358 */
243 359 public function maybe_enqueue_donation_form_scripts() {
244 360 $load = charitable_is_page( 'campaign_donation_page' );
245 361
@@ -256,11 +372,11 @@
256 372
257 373 /**
258 374 * Enqueues the donation form scripts.
259 375 *
260 - * @since 1.4.6
376 + * @since 1.4.6
261 377 *
262 - * @return void
378 + * @return void
263 379 */
264 380 public function enqueue_donation_form_scripts() {
265 381 wp_enqueue_script( 'charitable-script' );
266 382
@@ -271,12 +387,12 @@
271 387
272 388 /**
273 389 * Adds custom post classes when viewing campaign.
274 390 *
275 - * @since 1.0.0
391 + * @since 1.0.0
276 392 *
277 - * @param string[] $classes List of classes to be added with post_class().
278 - * @return string[]
393 + * @param string[] $classes List of classes to be added with post_class().
394 + * @return string[]
279 395 */
280 396 public function campaign_post_class( $classes ) {
281 397 $campaign = charitable_get_current_campaign();
282 398
@@ -283,10 +399,22 @@
283 399 if ( ! $campaign ) {
284 400 return $classes;
285 401 }
286 402
287 - $classes[] = $campaign->has_goal() ? 'campaign-has-goal' : 'campaign-has-no-goal';
288 - $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 +
289 417 return $classes;
290 418 }
291 419
292 420 /**
@@ -291,12 +419,15 @@
291 419
292 420 /**
293 421 * Disable comments on application pages like the donation page.
294 422 *
295 - * @since 1.3.0
296 - *
297 - * @param boolean $open Whether comments are open.
298 - * @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
299 430 */
300 431 public function disable_comments_on_application_pages( $open ) {
301 432 /* If open is already false, just hit return. */
302 433 if ( ! $open ) {
@@ -306,12 +437,34 @@
306 437 if ( charitable_is_page( 'campaign_donation_page', array( 'strict' => true ) )
307 438 || charitable_is_page( 'campaign_widget_page' )
308 439 || charitable_is_page( 'donation_receipt_page' )
309 440 || charitable_is_page( 'donation_processing_page' ) ) {
310 - $open = false;
441 + $open = false;
311 442 }
312 443
313 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();
314 467 }
315 468 }
316 469
317 470 endif;