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

720 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://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.4
7 * Author: WP Charitable
8 * Author URI: https://wpcharitable.com
9 * Requires at least: 4.1
10 * Tested up to: 4.4
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.3
30 */
31 class Charitable {
32
33 /**
34 * @var string
35 */
36 const VERSION = '1.2.4';
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-helpers.php' );
227 require_once( $includes_path . 'public/charitable-template-hooks.php' );
228 require_once( $includes_path . 'public/class-charitable-session.php' );
229 require_once( $includes_path . 'public/class-charitable-template.php' );
230 require_once( $includes_path . 'public/class-charitable-template-part.php' );
231 require_once( $includes_path . 'public/class-charitable-templates.php' );
232 require_once( $includes_path . 'public/class-charitable-ghost-page.php' );
233 require_once( $includes_path . 'public/class-charitable-user-dashboard.php' );
234
235 /* Shortcodes */
236 require_once( $includes_path . 'shortcodes/class-charitable-campaigns-shortcode.php' );
237 require_once( $includes_path . 'shortcodes/class-charitable-my-donations-shortcode.php' );
238 require_once( $includes_path . 'shortcodes/class-charitable-donation-receipt-shortcode.php' );
239 require_once( $includes_path . 'shortcodes/class-charitable-login-shortcode.php' );
240 require_once( $includes_path . 'shortcodes/class-charitable-registration-shortcode.php' );
241 require_once( $includes_path . 'shortcodes/class-charitable-profile-shortcode.php' );
242 require_once( $includes_path . 'shortcodes/charitable-shortcodes-hooks.php' );
243
244 /* Widgets */
245 require_once( $includes_path . 'widgets/class-charitable-widgets.php' );
246 require_once( $includes_path . 'widgets/class-charitable-campaign-terms-widget.php' );
247 require_once( $includes_path . 'widgets/class-charitable-campaigns-widget.php' );
248 require_once( $includes_path . 'widgets/class-charitable-donors-widget.php' );
249 require_once( $includes_path . 'widgets/class-charitable-donate-widget.php' );
250 require_once( $includes_path . 'widgets/class-charitable-donation-stats-widget.php' );
251
252 /* Customizer */
253 require_once( $includes_path . 'admin/customizer/class-charitable-customizer.php' );
254
255 /* Deprecated */
256 require_once( $includes_path . 'deprecated/charitable-deprecated-functions.php' );
257
258 /**
259 * We are registering this object only for backwards compatibility. It
260 * will be removed in or after Charitable 1.3.
261 *
262 * @deprecated
263 */
264 $this->register_object( Charitable_Emails::get_instance() );
265 $this->register_object( Charitable_Request::get_instance() );
266 $this->register_object( Charitable_Gateways::get_instance() );
267 $this->register_object( Charitable_i18n::get_instance() );
268 $this->register_object( Charitable_Post_Types::get_instance() );
269 $this->register_object( Charitable_Cron::get_instance() );
270 $this->register_object( Charitable_Widgets::get_instance() );
271 $this->register_object( Charitable_Licenses::get_instance() );
272 $this->register_object( Charitable_User_Dashboard::get_instance() );
273 }
274
275 /**
276 * Set up hook and filter callback functions.
277 *
278 * @return void
279 * @access private
280 * @since 1.0.0
281 */
282 private function attach_hooks_and_filters() {
283 add_action( 'plugins_loaded', array( $this, 'charitable_install' ), 100 );
284 add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 );
285 add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) );
286
287 /**
288 * We do this on priority 20 so that any functionality that is loaded on init (such
289 * as addons) has a chance to run before the event.
290 */
291 add_action( 'init', array( $this, 'do_charitable_actions' ), 20 );
292
293 add_filter( 'charitable_sanitize_campaign_meta', array( 'Charitable_Campaign', 'sanitize_meta' ), 10, 3 );
294 add_filter( 'charitable_sanitize_donation_meta', array( 'Charitable_Donation', 'sanitize_meta' ), 10, 2 );
295 add_filter( 'charitable_after_insert_user', array( 'Charitable_User', 'signon' ), 10, 2 );
296 }
297
298 /**
299 * Checks whether we're in the admin area and if so, loads the admin-only functionality.
300 *
301 * @return void
302 * @access private
303 * @since 1.0.0
304 */
305 private function maybe_start_admin() {
306 if ( ! is_admin() ) {
307 return;
308 }
309
310 require_once( $this->get_path( 'admin' ) . 'class-charitable-admin.php' );
311
312 /**
313 * We are registering this object only for backwards compatibility. It
314 * will be removed in or after Charitable 1.3.
315 *
316 * @deprecated
317 */
318 $this->register_object( Charitable_Admin::get_instance() );
319 }
320
321 /**
322 * Checks whether we're on the public-facing side and if so, loads the public-facing functionality.
323 *
324 * @return void
325 * @access private
326 * @since 1.0.0
327 */
328 private function maybe_start_public() {
329 if ( is_admin() ) {
330 return;
331 }
332
333 require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' );
334
335 /**
336 * We are registering this object only for backwards compatibility. It
337 * will be removed in or after Charitable 1.3.
338 *
339 * @deprecated
340 */
341 $this->register_object( Charitable_Public::get_instance() );
342 }
343
344 /**
345 * Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality.
346 *
347 * @return void
348 * @access private
349 * @since 1.0.0
350 */
351 private function maybe_start_ajax() {
352 if ( false === ( defined('DOING_AJAX') && DOING_AJAX ) ) {
353 return;
354 }
355
356 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php' );
357 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php' );
358
359 /**
360 * We are registering this object only for backwards compatibility. It
361 * will be removed in or after Charitable 1.3.
362 *
363 * @deprecated
364 */
365 $this->register_object( Charitable_Session::get_instance() );
366 }
367
368 /**
369 * This method is fired after all plugins are loaded and simply fires the charitable_start hook.
370 *
371 * Extensions can use the charitable_start event to load their own functionality.
372 *
373 * @return void
374 * @access public
375 * @since 1.0.0
376 */
377 public function charitable_start() {
378 do_action( 'charitable_start', $this );
379 }
380
381 /**
382 * Fires off an action right after Charitable is installed, allowing other
383 * plugins/themes to do something at this point.
384 *
385 * @return void
386 * @access public
387 * @since 1.0.1
388 */
389 public function charitable_install() {
390 $install = get_transient( 'charitable_install' );
391
392 if ( ! $install ) {
393 return;
394 }
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 return self::VERSION;
527 }
528
529 /**
530 * Returns the public class.
531 *
532 * @return Charitable_Public
533 * @access public
534 * @since 1.0.0
535 */
536 public function get_public() {
537 return $this->get_registered_object( 'Charitable_Public' );
538 }
539
540 /**
541 * Returns the admin class.
542 *
543 * @return Charitable_Admin
544 * @access public
545 * @since 1.0.0
546 */
547 public function get_admin() {
548 return $this->get_registered_object( 'Charitable_Admin' );
549 }
550
551 /**
552 * Return the current request object.
553 *
554 * @return Charitable_Request
555 * @access public
556 * @since 1.0.0
557 */
558 public function get_request() {
559 $request = $this->get_registered_object('Charitable_Request');
560
561 if ( $request === false ) {
562 $request = new Charitable_Request();
563 $this->register_object( $request );
564 }
565
566 return $request;
567 }
568
569 /**
570 * Return an instance of the currency helper.
571 *
572 * @return Charitable_Currency
573 * @access public
574 * @since 1.0.0
575 */
576 public function get_currency_helper() {
577 return Charitable_Currency::get_instance();
578 }
579
580 /**
581 * Returns the model for one of Charitable's database tables.
582 *
583 * @param string $table
584 * @return Charitable_DB
585 * @access public
586 * @since 1.0.0
587 */
588 public function get_db_table( $table ) {
589 $tables = $this->get_tables();
590
591 if ( ! isset( $tables[ $table ] ) ) {
592 _doing_it_wrong( __METHOD__, sprintf( 'Invalid table %s passed', $table ), '1.0.0' );
593 return null;
594 }
595
596 $class_name = $tables[ $table ];
597
598 $db_table = $this->get_registered_object( $class_name );
599
600 if ( false === $db_table ) {
601 $db_table = new $class_name;
602 $this->register_object( $db_table );
603 }
604
605 return $db_table;
606 }
607
608 /**
609 * Return the filtered list of registered tables.
610 *
611 * @return string[]
612 * @access private
613 * @since 1.0.0
614 */
615 private function get_tables() {
616 $default_tables = array(
617 'campaign_donations' => 'Charitable_Campaign_Donations_DB',
618 'donors' => 'Charitable_Donors_DB'
619 );
620
621 return apply_filters( 'charitable_db_tables', $default_tables );
622 }
623
624 /**
625 * Runs on plugin activation.
626 *
627 * @see register_activation_hook
628 *
629 * @return void
630 * @access public
631 * @since 1.0.0
632 */
633 public function activate() {
634 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
635 new Charitable_Install();
636 }
637
638 /**
639 * Runs on plugin deactivation.
640 *
641 * @see register_deactivation_hook
642 *
643 * @return void
644 * @access public
645 * @since 1.0.0
646 */
647 public function deactivate() {
648 require_once( $this->get_path( 'includes' ) . 'class-charitable-uninstall.php' );
649 new Charitable_Uninstall();
650 }
651
652 /**
653 * Perform upgrade routine if necessary.
654 *
655 * @return void
656 * @access private
657 * @since 1.0.0
658 */
659 private function maybe_upgrade() {
660 $db_version = get_option( 'charitable_version' );
661
662 if ( $db_version !== self::VERSION ) {
663
664 require_once( $this->get_path( 'includes' ) . 'class-charitable-upgrade.php' );
665
666 Charitable_Upgrade::upgrade_from( $db_version, self::VERSION );
667 }
668 }
669
670 /**
671 * If a charitable_action event is triggered, delegate the event using do_action.
672 *
673 * @return void
674 * @access public
675 * @since 1.0.0
676 */
677 public function do_charitable_actions() {
678 if ( isset( $_REQUEST['charitable_action'] ) ) {
679
680 $action = $_REQUEST[ 'charitable_action' ];
681
682 do_action( 'charitable_' . $action, 20 );
683 }
684 }
685
686 /**
687 * Throw error on object clone.
688 *
689 * This class is specifically designed to be instantiated once. You can retrieve the instance using charitable()
690 *
691 * @since 1.0.0
692 * @access public
693 * @return void
694 */
695 public function __clone() {
696 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
697 }
698
699 /**
700 * Disable unserializing of the class.
701 *
702 * @since 1.0.0
703 * @access public
704 * @return void
705 */
706 public function __wakeup() {
707 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
708 }
709
710 /**
711 * @deprecated
712 */
713 public function get_location_helper() {
714 return charitable_get_location_helper();
715 }
716 }
717
718 $charitable = new Charitable();
719
720 endif; // End if class_exists check