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

734 lines 23.5 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.1
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.1
30 */
31 class Charitable {
32
33 /**
34 * @var string
35 */
36 const VERSION = '1.1.1';
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
196 /* Addons */
197 require_once( $includes_path . 'addons/class-charitable-addons.php' );
198
199 /* Campaigns */
200 require_once( $includes_path . 'campaigns/charitable-campaign-functions.php' );
201 require_once( $includes_path . 'campaigns/class-charitable-campaign.php' );
202 require_once( $includes_path . 'campaigns/class-charitable-campaigns.php' );
203
204 /* Currency */
205 require_once( $includes_path . 'currency/charitable-currency-functions.php' );
206 require_once( $includes_path . 'currency/class-charitable-currency.php' );
207
208 /* Donations */
209 require_once( $includes_path . 'donations/interface-charitable-donation-form.php' );
210 require_once( $includes_path . 'donations/class-charitable-donation-processor.php' );
211 require_once( $includes_path . 'donations/class-charitable-donation.php' );
212 require_once( $includes_path . 'donations/class-charitable-donations.php' );
213 require_once( $includes_path . 'donations/class-charitable-donation-form.php' );
214 require_once( $includes_path . 'donations/class-charitable-donation-amount-form.php' );
215 require_once( $includes_path . 'donations/charitable-donation-hooks.php' );
216 require_once( $includes_path . 'donations/charitable-donation-functions.php' );
217
218 /* Users */
219 require_once( $includes_path . 'users/charitable-user-functions.php' );
220 require_once( $includes_path . 'users/charitable-user-hooks.php' );
221 require_once( $includes_path . 'users/class-charitable-user.php' );
222 require_once( $includes_path . 'users/class-charitable-roles.php' );
223 require_once( $includes_path . 'users/class-charitable-donor.php' );
224 require_once( $includes_path . 'users/class-charitable-donor-query.php' );
225 require_once( $includes_path . 'users/class-charitable-registration-form.php' );
226 require_once( $includes_path . 'users/class-charitable-profile-form.php' );
227
228 /* Gateways */
229 require_once( $includes_path . 'gateways/class-charitable-gateways.php' );
230 include_once( $includes_path . 'gateways/abstract-class-charitable-gateway.php' );
231 include_once( $includes_path . 'gateways/class-charitable-gateway-offline.php' );
232 include_once( $includes_path . 'gateways/class-charitable-gateway-paypal.php' );
233
234 /* Emails */
235 include_once( $includes_path . 'emails/charitable-email-hooks.php' );
236 require_once( $includes_path . 'emails/class-charitable-emails.php' );
237 include_once( $includes_path . 'emails/abstract-class-charitable-email.php' );
238 include_once( $includes_path . 'emails/class-charitable-email-new-donation.php' );
239 include_once( $includes_path . 'emails/class-charitable-email-donation-receipt.php' );
240 include_once( $includes_path . 'emails/class-charitable-email-campaign-end.php' );
241
242 /* Database */
243 require_once( $includes_path . 'db/abstract-class-charitable-db.php' );
244 require_once( $includes_path . 'db/class-charitable-campaign-donations-db.php' );
245 require_once( $includes_path . 'db/class-charitable-donors-db.php' );
246
247 /* Licensing */
248 require_once( $includes_path . 'licensing/class-charitable-licenses.php' );
249 require_once( $includes_path . 'licensing/class-charitable-plugin-updater.php' );
250
251 /* Public */
252 require_once( $includes_path . 'public/charitable-page-functions.php' );
253 require_once( $includes_path . 'public/charitable-template-functions.php' );
254 require_once( $includes_path . 'public/charitable-template-hooks.php' );
255 require_once( $includes_path . 'public/class-charitable-session.php' );
256 require_once( $includes_path . 'public/class-charitable-template.php' );
257 require_once( $includes_path . 'public/class-charitable-template-part.php' );
258 require_once( $includes_path . 'public/class-charitable-templates.php' );
259 require_once( $includes_path . 'public/class-charitable-ghost-page.php' );
260 require_once( $includes_path . 'public/class-charitable-user-dashboard.php' );
261
262 /* Shortcodes */
263 require_once( $includes_path . 'shortcodes/class-charitable-shortcodes.php' );
264 require_once( $includes_path . 'shortcodes/class-charitable-campaigns-shortcode.php' );
265 require_once( $includes_path . 'shortcodes/class-charitable-my-donations-shortcode.php' );
266 require_once( $includes_path . 'shortcodes/class-charitable-login-shortcode.php' );
267 require_once( $includes_path . 'shortcodes/class-charitable-registration-shortcode.php' );
268 require_once( $includes_path . 'shortcodes/class-charitable-profile-shortcode.php' );
269
270 /* Widgets */
271 require_once( $includes_path . 'widgets/class-charitable-widgets.php' );
272 require_once( $includes_path . 'widgets/class-charitable-campaign-terms-widget.php' );
273 require_once( $includes_path . 'widgets/class-charitable-campaigns-widget.php' );
274 require_once( $includes_path . 'widgets/class-charitable-donors-widget.php' );
275 require_once( $includes_path . 'widgets/class-charitable-donate-widget.php' );
276 require_once( $includes_path . 'widgets/class-charitable-donation-stats-widget.php' );
277
278 /* Deprecated */
279 require_once( $includes_path . 'deprecated/charitable-deprecated-functions.php' );
280 }
281
282 /**
283 * Set up hook and filter callback functions.
284 *
285 * @return void
286 * @access private
287 * @since 1.0.0
288 */
289 private function attach_hooks_and_filters() {
290 add_action('plugins_loaded', array( $this, 'charitable_install' ), 100 );
291 add_action('plugins_loaded', array( $this, 'charitable_start' ), 100 );
292 add_action('charitable_start', array( 'Charitable_Licenses', 'charitable_start' ), 3 );
293 add_action('charitable_start', array( 'Charitable_Post_Types', 'charitable_start' ), 3 );
294 add_action('charitable_start', array( 'Charitable_Widgets', 'charitable_start' ), 3 );
295 add_action('charitable_start', array( 'Charitable_Gateways', 'charitable_start' ), 3 );
296 add_action('charitable_start', array( 'Charitable_Emails', 'charitable_start' ), 3 );
297 add_action('charitable_start', array( 'Charitable_Request', 'charitable_start' ), 3 );
298 add_action('charitable_start', array( 'Charitable_Shortcodes', 'charitable_start' ), 3 );
299 add_action('charitable_start', array( 'Charitable_User_Dashboard', 'charitable_start' ), 3 );
300 add_action('charitable_start', array( 'Charitable_Cron', 'charitable_start' ), 3 );
301
302 /**
303 * We do this on priority 20 so that any functionality that is loaded on init (such
304 * as addons) has a chance to run before the event.
305 */
306 add_action('init', array( $this, 'do_charitable_actions' ), 20 );
307
308 add_filter('charitable_sanitize_campaign_meta', array( 'Charitable_Campaign', 'sanitize_meta' ), 10, 3 );
309 add_filter('charitable_sanitize_donation_meta', array( 'Charitable_Donation', 'sanitize_meta' ), 10, 2 );
310 add_filter('charitable_after_insert_user', array( 'Charitable_User', 'signon' ), 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
327 add_action('charitable_start', array( 'Charitable_Admin', 'charitable_start' ), 3 );
328 }
329
330 /**
331 * Checks whether we're on the public-facing side and if so, loads the public-facing functionality.
332 *
333 * @return void
334 * @access private
335 * @since 1.0.0
336 */
337 private function maybe_start_public() {
338 if ( is_admin() ) {
339 return;
340 }
341
342 require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' );
343
344 add_action('charitable_start', array( 'Charitable_Public', 'charitable_start' ), 3 );
345 }
346
347 /**
348 * Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality.
349 *
350 * @return void
351 * @access private
352 * @since 1.0.0
353 */
354 private function maybe_start_ajax() {
355 if ( false === ( defined('DOING_AJAX') && DOING_AJAX ) ) {
356 return;
357 }
358
359 add_action('charitable_start', array( 'Charitable_Session', 'charitable_start' ), 1 );
360 }
361
362 /**
363 * This method is fired after all plugins are loaded and simply fires the charitable_start hook.
364 *
365 * Extensions can use the charitable_start event to load their own functionality.
366 *
367 * @return void
368 * @access public
369 * @since 1.0.0
370 */
371 public function charitable_start() {
372 do_action( 'charitable_start', $this );
373 }
374
375 /**
376 * Fires off an action right after Charitable is installed, allowing other
377 * plugins/themes to do something at this point.
378 *
379 * @return void
380 * @access public
381 * @since 1.0.1
382 */
383 public function charitable_install() {
384 $install = get_transient( 'charitable_install' );
385
386 if ( ! $install ) {
387 return;
388 }
389
390 // add_action( 'init', 'flush_rewrite_rules' );
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