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

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