PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.4.12
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.4.12
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 1.7.0.9 1.8.0 All 210 releases
charitable / charitable.php

charitable.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.4.12, at charitable.php

772 lines 22.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Charitable
4 * Plugin URI: https://www.wpcharitable.com
5 * Description: The WordPress fundraising alternative for non-profits, created to help non-profits raise money on their own website.
6 * Version: 1.4.12
7 * Author: WP Charitable
8 * Author URI: https://wpcharitable.com
9 * Requires at least: 4.1
10 * Tested up to: 4.7.2
11 *
12 * Text Domain: charitable
13 * Domain Path: /i18n/languages/
14 *
15 * @package Charitable
16 * @author Eric Daams
17 * @copyright Copyright (c) 2017, Studio 164a
18 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
19 */
20
21 if ( ! defined( 'ABSPATH' ) ) { exit; } // Exit if accessed directly
22
23 if ( ! class_exists( 'Charitable' ) ) :
24
25 /**
26 * Main Charitable class
27 *
28 * @class Charitable
29 * @version 1.4.0
30 */
31 class Charitable {
32
33 /**
34 * @var string
35 */
36 const VERSION = '1.4.12';
37
38 /**
39 * @var string A date in the format: YYYYMMDD
40 */
41 const DB_VERSION = '20150615';
42
43 /**
44 * @var string The Campaign post type.
45 */
46 const CAMPAIGN_POST_TYPE = 'campaign';
47
48 /**
49 * @var string The Donation post type.
50 */
51 const DONATION_POST_TYPE = 'donation';
52
53 /**
54 * @var Charitable
55 * @access private
56 */
57 private static $instance = null;
58
59 /**
60 * @var string Directory path for the plugin.
61 * @access private
62 */
63 private $directory_path;
64
65 /**
66 * @var string Directory url for the plugin.
67 * @access private
68 */
69 private $directory_url;
70
71 /**
72 * @var string Directory path for the includes folder of the plugin.
73 * @access private
74 */
75 private $includes_path;
76
77 /**
78 * @var array Store of registered objects.
79 * @access private
80 */
81 private $registry;
82
83 /**
84 * Donation factory instance.
85 *
86 * @var Charitable_Donation_Factory
87 */
88 public $donation_factory = null;
89
90 /**
91 * Create class instance.
92 *
93 * @since 1.0.0
94 */
95 public function __construct() {
96 $this->directory_path = plugin_dir_path( __FILE__ );
97 $this->directory_url = plugin_dir_url( __FILE__ );
98 $this->includes_path = $this->directory_path . 'includes/';
99
100 $this->load_dependencies();
101
102 register_activation_hook( __FILE__, array( $this, 'activate' ) );
103 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
104
105 add_action( 'plugins_loaded', array( $this, 'start' ), 1 );
106 }
107
108 /**
109 * Returns the original instance of this class.
110 *
111 * @return Charitable
112 * @since 1.0.0
113 */
114 public static function get_instance() {
115 return self::$instance;
116 }
117
118 /**
119 * Run the startup sequence.
120 *
121 * This is only ever executed once.
122 *
123 * @return void
124 * @access public
125 * @since 1.0.0
126 */
127 public function start() {
128 // If we've already started (i.e. run this function once before), do not pass go.
129 if ( $this->started() ) {
130 return;
131 }
132
133 // Set static instance
134 self::$instance = $this;
135
136 // Factory to create new donation instances
137 $this->donation_factory = new Charitable_Donation_Factory();
138
139 $this->maybe_start_ajax();
140
141 $this->attach_hooks_and_filters();
142
143 $this->maybe_start_admin();
144
145 $this->maybe_start_public();
146
147 Charitable_Addons::load( $this );
148 }
149
150 /**
151 * Include necessary files.
152 *
153 * @return void
154 * @access private
155 * @since 1.0.0
156 */
157 private function load_dependencies() {
158 $includes_path = $this->get_path( 'includes' );
159
160 /* Abstracts */
161 require_once( $includes_path . 'abstracts/class-charitable-form.php' );
162 require_once( $includes_path . 'abstracts/class-charitable-query.php' );
163 require_once( $includes_path . 'abstracts/class-charitable-start-object.php' );
164
165 /* Functions & Core Classes */
166 require_once( $includes_path . 'charitable-core-functions.php' );
167 require_once( $includes_path . 'charitable-utility-functions.php' );
168 require_once( $includes_path . 'class-charitable-locations.php' );
169 require_once( $includes_path . 'class-charitable-notices.php' );
170 require_once( $includes_path . 'class-charitable-post-types.php' );
171 require_once( $includes_path . 'class-charitable-request.php' );
172 require_once( $includes_path . 'class-charitable-cron.php' );
173 require_once( $includes_path . 'class-charitable-i18n.php' );
174
175 /* Addons */
176 require_once( $includes_path . 'addons/class-charitable-addons.php' );
177
178 /* Campaigns */
179 require_once( $includes_path . 'campaigns/charitable-campaign-functions.php' );
180 require_once( $includes_path . 'campaigns/class-charitable-campaign.php' );
181 require_once( $includes_path . 'campaigns/class-charitable-campaigns.php' );
182 require_once( $includes_path . 'campaigns/charitable-campaign-hooks.php' );
183
184 /* Currency */
185 require_once( $includes_path . 'currency/charitable-currency-functions.php' );
186 require_once( $includes_path . 'currency/class-charitable-currency.php' );
187
188 /* Donations */
189 require_once( $includes_path . 'donations/abstract-charitable-donation.php' );
190 require_once( $includes_path . 'donations/interface-charitable-donation-form.php' );
191 require_once( $includes_path . 'donations/class-charitable-donation-processor.php' );
192 require_once( $includes_path . 'donations/class-charitable-donation.php' );
193 require_once( $includes_path . 'donations/class-charitable-donation-factory.php' );
194 require_once( $includes_path . 'donations/class-charitable-donations.php' );
195 require_once( $includes_path . 'donations/class-charitable-donations-query.php' );
196 require_once( $includes_path . 'donations/class-charitable-donation-form.php' );
197 require_once( $includes_path . 'donations/class-charitable-donation-amount-form.php' );
198 require_once( $includes_path . 'donations/charitable-donation-hooks.php' );
199 require_once( $includes_path . 'donations/charitable-donation-functions.php' );
200
201 /* Users */
202 require_once( $includes_path . 'users/charitable-user-functions.php' );
203 require_once( $includes_path . 'users/class-charitable-user.php' );
204 require_once( $includes_path . 'users/class-charitable-roles.php' );
205 require_once( $includes_path . 'users/class-charitable-donor.php' );
206 require_once( $includes_path . 'users/class-charitable-donor-query.php' );
207
208 /* Gateways */
209 require_once( $includes_path . 'gateways/interface-charitable-gateway.php' );
210 require_once( $includes_path . 'gateways/class-charitable-gateways.php' );
211 require_once( $includes_path . 'gateways/abstract-class-charitable-gateway.php' );
212 require_once( $includes_path . 'gateways/class-charitable-gateway-offline.php' );
213 require_once( $includes_path . 'gateways/class-charitable-gateway-paypal.php' );
214
215 /* Emails */
216 require_once( $includes_path . 'emails/interface-charitable-email.php' );
217 require_once( $includes_path . 'emails/class-charitable-emails.php' );
218 require_once( $includes_path . 'emails/abstract-class-charitable-email.php' );
219 require_once( $includes_path . 'emails/class-charitable-email-new-donation.php' );
220 require_once( $includes_path . 'emails/class-charitable-email-donation-receipt.php' );
221 require_once( $includes_path . 'emails/class-charitable-email-campaign-end.php' );
222 require_once( $includes_path . 'emails/class-charitable-email-password-reset.php' );
223 require_once( $includes_path . 'emails/charitable-email-hooks.php' );
224
225 /* Database */
226 require_once( $includes_path . 'db/abstract-class-charitable-db.php' );
227 require_once( $includes_path . 'db/class-charitable-campaign-donations-db.php' );
228 require_once( $includes_path . 'db/class-charitable-donors-db.php' );
229
230 /* Licensing */
231 require_once( $includes_path . 'licensing/class-charitable-licenses.php' );
232 require_once( $includes_path . 'licensing/class-charitable-plugin-updater.php' );
233
234 /* Public */
235 require_once( $includes_path . 'public/charitable-page-functions.php' );
236 require_once( $includes_path . 'public/charitable-template-helpers.php' );
237 require_once( $includes_path . 'public/class-charitable-session.php' );
238 require_once( $includes_path . 'public/class-charitable-template.php' );
239 require_once( $includes_path . 'public/class-charitable-template-part.php' );
240 require_once( $includes_path . 'public/class-charitable-templates.php' );
241 require_once( $includes_path . 'public/class-charitable-ghost-page.php' );
242 require_once( $includes_path . 'public/class-charitable-user-dashboard.php' );
243
244 /* Shortcodes */
245 require_once( $includes_path . 'shortcodes/class-charitable-campaigns-shortcode.php' );
246 require_once( $includes_path . 'shortcodes/class-charitable-my-donations-shortcode.php' );
247 require_once( $includes_path . 'shortcodes/class-charitable-donation-receipt-shortcode.php' );
248 require_once( $includes_path . 'shortcodes/class-charitable-login-shortcode.php' );
249 require_once( $includes_path . 'shortcodes/class-charitable-registration-shortcode.php' );
250 require_once( $includes_path . 'shortcodes/class-charitable-profile-shortcode.php' );
251 require_once( $includes_path . 'shortcodes/charitable-shortcodes-hooks.php' );
252
253 /* Widgets */
254 require_once( $includes_path . 'widgets/class-charitable-widgets.php' );
255 require_once( $includes_path . 'widgets/class-charitable-campaign-terms-widget.php' );
256 require_once( $includes_path . 'widgets/class-charitable-campaigns-widget.php' );
257 require_once( $includes_path . 'widgets/class-charitable-donors-widget.php' );
258 require_once( $includes_path . 'widgets/class-charitable-donate-widget.php' );
259 require_once( $includes_path . 'widgets/class-charitable-donation-stats-widget.php' );
260
261 /* User Management */
262 require_once( $includes_path . 'user-management/class-charitable-registration-form.php' );
263 require_once( $includes_path . 'user-management/class-charitable-profile-form.php' );
264 require_once( $includes_path . 'user-management/class-charitable-forgot-password-form.php' );
265 require_once( $includes_path . 'user-management/class-charitable-reset-password-form.php' );
266 require_once( $includes_path . 'user-management/class-charitable-user-management.php' );
267 require_once( $includes_path . 'user-management/charitable-user-management-hooks.php' );
268
269 /* Customizer */
270 require_once( $includes_path . 'admin/customizer/class-charitable-customizer.php' );
271
272 /* Deprecated */
273 require_once( $includes_path . 'deprecated/charitable-deprecated-functions.php' );
274
275 /**
276 * We are registering this object only for backwards compatibility. It
277 * will be removed in or after Charitable 1.3.
278 *
279 * @deprecated
280 */
281 $this->register_object( Charitable_Emails::get_instance() );
282 $this->register_object( Charitable_Request::get_instance() );
283 $this->register_object( Charitable_Gateways::get_instance() );
284 $this->register_object( Charitable_i18n::get_instance() );
285 $this->register_object( Charitable_Post_Types::get_instance() );
286 $this->register_object( Charitable_Cron::get_instance() );
287 $this->register_object( Charitable_Widgets::get_instance() );
288 $this->register_object( Charitable_Licenses::get_instance() );
289 $this->register_object( Charitable_User_Dashboard::get_instance() );
290 }
291
292 /**
293 * Set up hook and filter callback functions.
294 *
295 * @return void
296 * @access private
297 * @since 1.0.0
298 */
299 private function attach_hooks_and_filters() {
300 add_action( 'wpmu_new_blog', array( $this, 'maybe_activate_charitable_on_new_site' ) );
301 add_action( 'plugins_loaded', array( $this, 'charitable_install' ), 100 );
302 add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 );
303 add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) );
304
305 /**
306 * We do this on priority 20 so that any functionality that is loaded on init (such
307 * as addons) has a chance to run before the event.
308 */
309 add_action( 'init', array( $this, 'do_charitable_actions' ), 20 );
310 add_filter( 'charitable_sanitize_donation_meta', 'charitable_sanitize_donation_meta', 10, 2 );
311 }
312
313 /**
314 * Checks whether we're in the admin area and if so, loads the admin-only functionality.
315 *
316 * @return void
317 * @access private
318 * @since 1.0.0
319 */
320 private function maybe_start_admin() {
321 if ( ! is_admin() ) {
322 return;
323 }
324
325 require_once( $this->get_path( 'admin' ) . 'class-charitable-admin.php' );
326 require_once( $this->get_path( 'admin' ) . 'charitable-admin-hooks.php' );
327
328 /**
329 * We are registering this object only for backwards compatibility. It
330 * will be removed in or after Charitable 1.3.
331 *
332 * @deprecated
333 */
334 $this->register_object( Charitable_Admin::get_instance() );
335 }
336
337 /**
338 * Checks whether we're on the public-facing side and if so, loads the public-facing functionality.
339 *
340 * @return void
341 * @access private
342 * @since 1.0.0
343 */
344 private function maybe_start_public() {
345 if ( is_admin() ) {
346 return;
347 }
348
349 require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' );
350
351 /**
352 * We are registering this object only for backwards compatibility. It
353 * will be removed in or after Charitable 1.3.
354 *
355 * @deprecated
356 */
357 $this->register_object( Charitable_Public::get_instance() );
358 }
359
360 /**
361 * Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality.
362 *
363 * @return void
364 * @access private
365 * @since 1.0.0
366 */
367 private function maybe_start_ajax() {
368 if ( false === ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
369 return;
370 }
371
372 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php' );
373 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php' );
374
375 /**
376 * We are registering this object only for backwards compatibility. It
377 * will be removed in or after Charitable 1.3.
378 *
379 * @deprecated
380 */
381 $this->register_object( Charitable_Session::get_instance() );
382 }
383
384 /**
385 * This method is fired after all plugins are loaded and simply fires the charitable_start hook.
386 *
387 * Extensions can use the charitable_start event to load their own functionality.
388 *
389 * @return void
390 * @access public
391 * @since 1.0.0
392 */
393 public function charitable_start() {
394 do_action( 'charitable_start', $this );
395 }
396
397 /**
398 * Fires off an action right after Charitable is installed, allowing other
399 * plugins/themes to do something at this point.
400 *
401 * @return void
402 * @access public
403 * @since 1.0.1
404 */
405 public function charitable_install() {
406 $install = get_transient( 'charitable_install' );
407
408 if ( ! $install ) {
409 return;
410 }
411
412 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
413
414 Charitable_Install::finish_installing();
415
416 do_action( 'charitable_install' );
417
418 delete_transient( 'charitable_install' );
419 }
420
421 /**
422 * Returns whether we are currently in the start phase of the plugin.
423 *
424 * @return bool
425 * @access public
426 * @since 1.0.0
427 */
428 public function is_start() {
429 return current_filter() == 'charitable_start';
430 }
431
432 /**
433 * Returns whether the plugin has already started.
434 *
435 * @return bool
436 * @access public
437 * @since 1.0.0
438 */
439 public function started() {
440 return did_action( 'charitable_start' ) || current_filter() == 'charitable_start';
441 }
442
443 /**
444 * Returns whether the plugin is being activated.
445 *
446 * @return bool
447 * @access public
448 * @since 1.0.0
449 */
450 public function is_activation() {
451 return current_filter() == 'activate_charitable/charitable.php';
452 }
453
454 /**
455 * Returns whether the plugin is being deactivated.
456 *
457 * @return bool
458 * @access public
459 * @since 1.0.0
460 */
461 public function is_deactivation() {
462 return current_filter() == 'deactivate_charitable/charitable.php';
463 }
464
465 /**
466 * Stores an object in the plugin's registry.
467 *
468 * @param mixed $object
469 * @return void
470 * @access public
471 * @since 1.0.0
472 */
473 public function register_object( $object ) {
474 if ( ! is_object( $object ) ) {
475 return;
476 }
477
478 $class = get_class( $object );
479
480 $this->registry[ $class ] = $object;
481 }
482
483 /**
484 * Returns a registered object.
485 *
486 * @param string $class The type of class you want to retrieve.
487 * @return mixed The object if its registered. Otherwise false.
488 * @access public
489 * @since 1.0.0
490 */
491 public function get_registered_object( $class ) {
492 return isset( $this->registry[ $class ] ) ? $this->registry[ $class ] : false;
493 }
494
495 /**
496 * Returns plugin paths.
497 *
498 * @param string $type If empty, returns the path to the plugin.
499 * @param bool $absolute_path If true, returns the file system path. If false, returns it as a URL.
500 * @return string
501 * @since 1.0.0
502 */
503 public function get_path( $type = '', $absolute_path = true ) {
504 $base = $absolute_path ? $this->directory_path : $this->directory_url;
505
506 switch ( $type ) {
507 case 'includes' :
508 $path = $base . 'includes/';
509 break;
510
511 case 'admin' :
512 $path = $base . 'includes/admin/';
513 break;
514
515 case 'public' :
516 $path = $base . 'includes/public/';
517 break;
518
519 case 'assets' :
520 $path = $base . 'assets/';
521 break;
522
523 case 'templates' :
524 $path = $base . 'templates/';
525 break;
526
527 case 'directory' :
528 $path = $base;
529 break;
530
531 default :
532 $path = __FILE__;
533 }
534
535 return $path;
536 }
537
538 /**
539 * Returns the plugin's version number.
540 *
541 * @return string
542 * @access public
543 * @since 1.0.0
544 */
545 public function get_version() {
546 $version = self::VERSION;
547
548 if ( false !== strpos( $version, '-' ) ) {
549 $parts = explode( '-', $version );
550 $version = $parts[0];
551 }
552
553 return $version;
554 }
555
556 /**
557 * Returns the public class.
558 *
559 * @return Charitable_Public
560 * @access public
561 * @since 1.0.0
562 */
563 public function get_public() {
564 return $this->get_registered_object( 'Charitable_Public' );
565 }
566
567 /**
568 * Returns the admin class.
569 *
570 * @return Charitable_Admin
571 * @access public
572 * @since 1.0.0
573 */
574 public function get_admin() {
575 return $this->get_registered_object( 'Charitable_Admin' );
576 }
577
578 /**
579 * Return the current request object.
580 *
581 * @return Charitable_Request
582 * @access public
583 * @since 1.0.0
584 */
585 public function get_request() {
586 $request = $this->get_registered_object( 'Charitable_Request' );
587
588 if ( false === $request ) {
589 $request = new Charitable_Request();
590 $this->register_object( $request );
591 }
592
593 return $request;
594 }
595
596 /**
597 * Returns the model for one of Charitable's database tables.
598 *
599 * @param string $table
600 * @return Charitable_DB
601 * @access public
602 * @since 1.0.0
603 */
604 public function get_db_table( $table ) {
605 $tables = $this->get_tables();
606
607 if ( ! isset( $tables[ $table ] ) ) {
608 _doing_it_wrong( __METHOD__, sprintf( 'Invalid table %s passed', $table ), '1.0.0' );
609 return null;
610 }
611
612 $class_name = $tables[ $table ];
613
614 $db_table = $this->get_registered_object( $class_name );
615
616 if ( false === $db_table ) {
617 $db_table = new $class_name;
618 $this->register_object( $db_table );
619 }
620
621 return $db_table;
622 }
623
624 /**
625 * Return the filtered list of registered tables.
626 *
627 * @return string[]
628 * @access private
629 * @since 1.0.0
630 */
631 private function get_tables() {
632 $default_tables = array(
633 'campaign_donations' => 'Charitable_Campaign_Donations_DB',
634 'donors' => 'Charitable_Donors_DB',
635 );
636
637 return apply_filters( 'charitable_db_tables', $default_tables );
638 }
639
640 /**
641 * Maybe activate Charitable when a new site is added in a multisite network.
642 *
643 * @param int $blog_id
644 * @return boolean
645 * @access public
646 * @since 1.4.6
647 */
648 public function maybe_activate_charitable_on_new_site( $blog_id ) {
649
650 if ( is_plugin_active_for_network( basename( $this->directory_path ) . '/charitable.php' ) ) {
651
652 switch_to_blog( $blog_id );
653
654 $this->activate( false );
655
656 restore_current_blog();
657 }
658 }
659
660 /**
661 * Runs on plugin activation.
662 *
663 * @see register_activation_hook
664 *
665 * @param boolean $network_wide Whether to enable the plugin for all sites in the network
666 * or just the current site. Multisite only. Default is false.
667 * @return void
668 * @access public
669 * @since 1.0.0
670 */
671 public function activate( $network_wide = false ) {
672
673 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
674
675 if ( is_multisite() && $network_wide ) {
676
677 global $wpdb;
678
679 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
680
681 switch_to_blog( $blog_id );
682
683 new Charitable_Install();
684
685 restore_current_blog();
686 }
687 } else {
688
689 new Charitable_Install();
690
691 }
692 }
693
694 /**
695 * Runs on plugin deactivation.
696 *
697 * @see register_deactivation_hook
698 *
699 * @return void
700 * @access public
701 * @since 1.0.0
702 */
703 public function deactivate() {
704 require_once( $this->get_path( 'includes' ) . 'class-charitable-uninstall.php' );
705 new Charitable_Uninstall();
706 }
707
708 /**
709 * If a charitable_action event is triggered, delegate the event using do_action.
710 *
711 * @return void
712 * @access public
713 * @since 1.0.0
714 */
715 public function do_charitable_actions() {
716 if ( isset( $_REQUEST['charitable_action'] ) ) {
717
718 $action = $_REQUEST['charitable_action'];
719
720 do_action( 'charitable_' . $action, 20 );
721 }
722 }
723
724 /**
725 * Throw error on object clone.
726 *
727 * This class is specifically designed to be instantiated once. You can retrieve the instance using charitable()
728 *
729 * @since 1.0.0
730 * @access public
731 * @return void
732 */
733 public function __clone() {
734 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
735 }
736
737 /**
738 * Disable unserializing of the class.
739 *
740 * @since 1.0.0
741 * @access public
742 * @return void
743 */
744 public function __wakeup() {
745 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
746 }
747
748 /**
749 * DEPRECATED METHODS
750 */
751
752 /**
753 * @deprecated
754 */
755 public function get_currency_helper() {
756 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.4.0', 'charitable_get_currency_helper' );
757 return charitable_get_currency_helper();
758 }
759
760 /**
761 * @deprecated
762 */
763 public function get_location_helper() {
764 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.2.0', 'charitable_get_location_helper' );
765 return charitable_get_location_helper();
766 }
767 }
768
769 $charitable = new Charitable();
770
771 endif; // End if class_exists check
772