PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.4.0
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.4.0
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.0, at charitable.php

731 lines 21.2 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.0
7 * Author: WP Charitable
8 * Author URI: https://wpcharitable.com
9 * Requires at least: 4.1
10 * Tested up to: 4.5.2
11 *
12 * Text Domain: charitable
13 * Domain Path: /i18n/languages/
14 *
15 * @package Charitable
16 * @author Eric Daams
17 * @copyright Copyright (c) 2015, 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.0';
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( 'plugins_loaded', array( $this, 'charitable_install' ), 100 );
301 add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 );
302 add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) );
303
304 /**
305 * We do this on priority 20 so that any functionality that is loaded on init (such
306 * as addons) has a chance to run before the event.
307 */
308 add_action( 'init', array( $this, 'do_charitable_actions' ), 20 );
309 add_filter( 'charitable_sanitize_donation_meta', 'charitable_sanitize_donation_meta', 10, 2 );
310 }
311
312 /**
313 * Checks whether we're in the admin area and if so, loads the admin-only functionality.
314 *
315 * @return void
316 * @access private
317 * @since 1.0.0
318 */
319 private function maybe_start_admin() {
320 if ( ! is_admin() ) {
321 return;
322 }
323
324 require_once( $this->get_path( 'admin' ) . 'class-charitable-admin.php' );
325 require_once( $this->get_path( 'admin' ) . 'charitable-admin-hooks.php' );
326
327 /**
328 * We are registering this object only for backwards compatibility. It
329 * will be removed in or after Charitable 1.3.
330 *
331 * @deprecated
332 */
333 $this->register_object( Charitable_Admin::get_instance() );
334 }
335
336 /**
337 * Checks whether we're on the public-facing side and if so, loads the public-facing functionality.
338 *
339 * @return void
340 * @access private
341 * @since 1.0.0
342 */
343 private function maybe_start_public() {
344 if ( is_admin() ) {
345 return;
346 }
347
348 require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' );
349
350 /**
351 * We are registering this object only for backwards compatibility. It
352 * will be removed in or after Charitable 1.3.
353 *
354 * @deprecated
355 */
356 $this->register_object( Charitable_Public::get_instance() );
357 }
358
359 /**
360 * Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality.
361 *
362 * @return void
363 * @access private
364 * @since 1.0.0
365 */
366 private function maybe_start_ajax() {
367 if ( false === ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
368 return;
369 }
370
371 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php' );
372 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php' );
373
374 /**
375 * We are registering this object only for backwards compatibility. It
376 * will be removed in or after Charitable 1.3.
377 *
378 * @deprecated
379 */
380 $this->register_object( Charitable_Session::get_instance() );
381 }
382
383 /**
384 * This method is fired after all plugins are loaded and simply fires the charitable_start hook.
385 *
386 * Extensions can use the charitable_start event to load their own functionality.
387 *
388 * @return void
389 * @access public
390 * @since 1.0.0
391 */
392 public function charitable_start() {
393 do_action( 'charitable_start', $this );
394 }
395
396 /**
397 * Fires off an action right after Charitable is installed, allowing other
398 * plugins/themes to do something at this point.
399 *
400 * @return void
401 * @access public
402 * @since 1.0.1
403 */
404 public function charitable_install() {
405 $install = get_transient( 'charitable_install' );
406
407 if ( ! $install ) {
408 return;
409 }
410
411 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
412
413 Charitable_Install::finish_installing();
414
415 do_action( 'charitable_install' );
416
417 delete_transient( 'charitable_install' );
418 }
419
420 /**
421 * Returns whether we are currently in the start phase of the plugin.
422 *
423 * @return bool
424 * @access public
425 * @since 1.0.0
426 */
427 public function is_start() {
428 return current_filter() == 'charitable_start';
429 }
430
431 /**
432 * Returns whether the plugin has already started.
433 *
434 * @return bool
435 * @access public
436 * @since 1.0.0
437 */
438 public function started() {
439 return did_action( 'charitable_start' ) || current_filter() == 'charitable_start';
440 }
441
442 /**
443 * Returns whether the plugin is being activated.
444 *
445 * @return bool
446 * @access public
447 * @since 1.0.0
448 */
449 public function is_activation() {
450 return current_filter() == 'activate_charitable/charitable.php';
451 }
452
453 /**
454 * Returns whether the plugin is being deactivated.
455 *
456 * @return bool
457 * @access public
458 * @since 1.0.0
459 */
460 public function is_deactivation() {
461 return current_filter() == 'deactivate_charitable/charitable.php';
462 }
463
464 /**
465 * Stores an object in the plugin's registry.
466 *
467 * @param mixed $object
468 * @return void
469 * @access public
470 * @since 1.0.0
471 */
472 public function register_object( $object ) {
473 if ( ! is_object( $object ) ) {
474 return;
475 }
476
477 $class = get_class( $object );
478
479 $this->registry[ $class ] = $object;
480 }
481
482 /**
483 * Returns a registered object.
484 *
485 * @param string $class The type of class you want to retrieve.
486 * @return mixed The object if its registered. Otherwise false.
487 * @access public
488 * @since 1.0.0
489 */
490 public function get_registered_object( $class ) {
491 return isset( $this->registry[ $class ] ) ? $this->registry[ $class ] : false;
492 }
493
494 /**
495 * Returns plugin paths.
496 *
497 * @param string $type If empty, returns the path to the plugin.
498 * @param bool $absolute_path If true, returns the file system path. If false, returns it as a URL.
499 * @return string
500 * @since 1.0.0
501 */
502 public function get_path( $type = '', $absolute_path = true ) {
503 $base = $absolute_path ? $this->directory_path : $this->directory_url;
504
505 switch ( $type ) {
506 case 'includes' :
507 $path = $base . 'includes/';
508 break;
509
510 case 'admin' :
511 $path = $base . 'includes/admin/';
512 break;
513
514 case 'public' :
515 $path = $base . 'includes/public/';
516 break;
517
518 case 'assets' :
519 $path = $base . 'assets/';
520 break;
521
522 case 'templates' :
523 $path = $base . 'templates/';
524 break;
525
526 case 'directory' :
527 $path = $base;
528 break;
529
530 default :
531 $path = __FILE__;
532 }
533
534 return $path;
535 }
536
537 /**
538 * Returns the plugin's version number.
539 *
540 * @return string
541 * @access public
542 * @since 1.0.0
543 */
544 public function get_version() {
545 $version = self::VERSION;
546
547 if ( false !== strpos( $version, '-' ) ) {
548 $parts = explode( '-', $version );
549 $version = $parts[0];
550 }
551
552 return $version;
553 }
554
555 /**
556 * Returns the public class.
557 *
558 * @return Charitable_Public
559 * @access public
560 * @since 1.0.0
561 */
562 public function get_public() {
563 return $this->get_registered_object( 'Charitable_Public' );
564 }
565
566 /**
567 * Returns the admin class.
568 *
569 * @return Charitable_Admin
570 * @access public
571 * @since 1.0.0
572 */
573 public function get_admin() {
574 return $this->get_registered_object( 'Charitable_Admin' );
575 }
576
577 /**
578 * Return the current request object.
579 *
580 * @return Charitable_Request
581 * @access public
582 * @since 1.0.0
583 */
584 public function get_request() {
585 $request = $this->get_registered_object( 'Charitable_Request' );
586
587 if ( false === $request ) {
588 $request = new Charitable_Request();
589 $this->register_object( $request );
590 }
591
592 return $request;
593 }
594
595 /**
596 * Returns the model for one of Charitable's database tables.
597 *
598 * @param string $table
599 * @return Charitable_DB
600 * @access public
601 * @since 1.0.0
602 */
603 public function get_db_table( $table ) {
604 $tables = $this->get_tables();
605
606 if ( ! isset( $tables[ $table ] ) ) {
607 _doing_it_wrong( __METHOD__, sprintf( 'Invalid table %s passed', $table ), '1.0.0' );
608 return null;
609 }
610
611 $class_name = $tables[ $table ];
612
613 $db_table = $this->get_registered_object( $class_name );
614
615 if ( false === $db_table ) {
616 $db_table = new $class_name;
617 $this->register_object( $db_table );
618 }
619
620 return $db_table;
621 }
622
623 /**
624 * Return the filtered list of registered tables.
625 *
626 * @return string[]
627 * @access private
628 * @since 1.0.0
629 */
630 private function get_tables() {
631 $default_tables = array(
632 'campaign_donations' => 'Charitable_Campaign_Donations_DB',
633 'donors' => 'Charitable_Donors_DB',
634 );
635
636 return apply_filters( 'charitable_db_tables', $default_tables );
637 }
638
639 /**
640 * Runs on plugin activation.
641 *
642 * @see register_activation_hook
643 *
644 * @return void
645 * @access public
646 * @since 1.0.0
647 */
648 public function activate() {
649 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
650 new Charitable_Install();
651 }
652
653 /**
654 * Runs on plugin deactivation.
655 *
656 * @see register_deactivation_hook
657 *
658 * @return void
659 * @access public
660 * @since 1.0.0
661 */
662 public function deactivate() {
663 require_once( $this->get_path( 'includes' ) . 'class-charitable-uninstall.php' );
664 new Charitable_Uninstall();
665 }
666
667 /**
668 * If a charitable_action event is triggered, delegate the event using do_action.
669 *
670 * @return void
671 * @access public
672 * @since 1.0.0
673 */
674 public function do_charitable_actions() {
675 if ( isset( $_REQUEST['charitable_action'] ) ) {
676
677 $action = $_REQUEST['charitable_action'];
678
679 do_action( 'charitable_' . $action, 20 );
680 }
681 }
682
683 /**
684 * Throw error on object clone.
685 *
686 * This class is specifically designed to be instantiated once. You can retrieve the instance using charitable()
687 *
688 * @since 1.0.0
689 * @access public
690 * @return void
691 */
692 public function __clone() {
693 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
694 }
695
696 /**
697 * Disable unserializing of the class.
698 *
699 * @since 1.0.0
700 * @access public
701 * @return void
702 */
703 public function __wakeup() {
704 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
705 }
706
707 /**
708 * DEPRECATED METHODS
709 */
710
711 /**
712 * @deprecated
713 */
714 public function get_currency_helper() {
715 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.4.0', 'charitable_get_currency_helper' );
716 return charitable_get_currency_helper();
717 }
718
719 /**
720 * @deprecated
721 */
722 public function get_location_helper() {
723 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.2.0', 'charitable_get_location_helper' );
724 return charitable_get_location_helper();
725 }
726 }
727
728 $charitable = new Charitable();
729
730 endif; // End if class_exists check
731