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

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