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

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