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

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