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

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