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

861 lines 24.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.4.18
7 * Author: WP Charitable
8 * Author URI: https://wpcharitable.com
9 * Requires at least: 4.1
10 * Tested up to: 4.8
11 *
12 * Text Domain: charitable
13 * Domain Path: /i18n/languages/
14 *
15 * @package Charitable
16 * @author Eric Daams
17 * @copyright Copyright (c) 2017, Studio 164a
18 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
19 */
20
21 // Exit if accessed directly.
22 if ( ! defined( 'ABSPATH' ) ) { exit; }
23
24 if ( ! class_exists( 'Charitable' ) ) :
25
26 /**
27 * Main Charitable class
28 *
29 * @class Charitable
30 * @version 1.4.0
31 */
32 class Charitable {
33
34 /**
35 * Plugin version.
36 *
37 * @var string
38 */
39 const VERSION = '1.4.18';
40
41 /**
42 * Version of database schema.
43 *
44 * @var string A date in the format: YYYYMMDD
45 */
46 const DB_VERSION = '20150615';
47
48 /**
49 * Campaign post type.
50 *
51 * @var string
52 */
53 const CAMPAIGN_POST_TYPE = 'campaign';
54
55 /**
56 * Donation post type.
57 *
58 * @var string
59 */
60 const DONATION_POST_TYPE = 'donation';
61
62 /**
63 * Single instance of this class.
64 *
65 * @var Charitable
66 * @access private
67 */
68 private static $instance = null;
69
70 /**
71 * The absolute path to this plugin's directory.
72 *
73 * @var string
74 * @access private
75 */
76 private $directory_path;
77
78 /**
79 * The URL of this plugin's directory.
80 *
81 * @var string
82 * @access private
83 */
84 private $directory_url;
85
86 /**
87 * Directory path for the includes folder of the plugin.
88 *
89 * @var string
90 * @access private
91 */
92 private $includes_path;
93
94 /**
95 * Store of registered objects.
96 *
97 * @var array
98 * @access private
99 */
100 private $registry;
101
102 /**
103 * Donation factory instance.
104 *
105 * @var Charitable_Donation_Factory
106 */
107 public $donation_factory = null;
108
109 /**
110 * Create class instance.
111 *
112 * @since 1.0.0
113 */
114 public function __construct() {
115 $this->directory_path = plugin_dir_path( __FILE__ );
116 $this->directory_url = plugin_dir_url( __FILE__ );
117 $this->includes_path = $this->directory_path . 'includes/';
118
119 $this->load_dependencies();
120
121 register_activation_hook( __FILE__, array( $this, 'activate' ) );
122 register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) );
123
124 add_action( 'plugins_loaded', array( $this, 'start' ), 1 );
125 }
126
127 /**
128 * Returns the original instance of this class.
129 *
130 * @return Charitable
131 * @since 1.0.0
132 */
133 public static function get_instance() {
134 return self::$instance;
135 }
136
137 /**
138 * Run the startup sequence.
139 *
140 * This is only ever executed once.
141 *
142 * @return void
143 * @access public
144 * @since 1.0.0
145 */
146 public function start() {
147 /* If we've already started (i.e. run this function once before), do not pass go. */
148 if ( $this->started() ) {
149 return;
150 }
151
152 /* Set static instance. */
153 self::$instance = $this;
154
155 /* Factory to create new donation instances. */
156 $this->donation_factory = new Charitable_Donation_Factory();
157
158 $this->maybe_start_ajax();
159
160 $this->attach_hooks_and_filters();
161
162 $this->maybe_start_admin();
163
164 $this->maybe_start_public();
165
166 Charitable_Addons::load( $this );
167 }
168
169 /**
170 * Include necessary files.
171 *
172 * @return void
173 * @access private
174 * @since 1.0.0
175 */
176 private function load_dependencies() {
177 $includes_path = $this->get_path( 'includes' );
178
179 /* Abstracts */
180 require_once( $includes_path . 'abstracts/class-charitable-form.php' );
181 require_once( $includes_path . 'abstracts/class-charitable-query.php' );
182 require_once( $includes_path . 'abstracts/class-charitable-start-object.php' );
183
184 /* Functions & Core Classes */
185 require_once( $includes_path . 'charitable-core-functions.php' );
186 require_once( $includes_path . 'charitable-utility-functions.php' );
187 require_once( $includes_path . 'class-charitable-locations.php' );
188 require_once( $includes_path . 'class-charitable-notices.php' );
189 require_once( $includes_path . 'class-charitable-post-types.php' );
190 require_once( $includes_path . 'class-charitable-request.php' );
191 require_once( $includes_path . 'class-charitable-cron.php' );
192 require_once( $includes_path . 'class-charitable-i18n.php' );
193
194 /* Addons */
195 require_once( $includes_path . 'addons/class-charitable-addons.php' );
196
197 /* Campaigns */
198 require_once( $includes_path . 'campaigns/charitable-campaign-functions.php' );
199 require_once( $includes_path . 'campaigns/class-charitable-campaign.php' );
200 require_once( $includes_path . 'campaigns/class-charitable-campaigns.php' );
201 require_once( $includes_path . 'campaigns/charitable-campaign-hooks.php' );
202
203 /* Currency */
204 require_once( $includes_path . 'currency/charitable-currency-functions.php' );
205 require_once( $includes_path . 'currency/class-charitable-currency.php' );
206
207 /* Donations */
208 require_once( $includes_path . 'donations/abstract-charitable-donation.php' );
209 require_once( $includes_path . 'donations/interface-charitable-donation-form.php' );
210 require_once( $includes_path . 'donations/class-charitable-donation-processor.php' );
211 require_once( $includes_path . 'donations/class-charitable-donation.php' );
212 require_once( $includes_path . 'donations/class-charitable-donation-factory.php' );
213 require_once( $includes_path . 'donations/class-charitable-donations.php' );
214 require_once( $includes_path . 'donations/class-charitable-donations-query.php' );
215 require_once( $includes_path . 'donations/class-charitable-donation-form.php' );
216 require_once( $includes_path . 'donations/class-charitable-donation-amount-form.php' );
217 require_once( $includes_path . 'donations/charitable-donation-hooks.php' );
218 require_once( $includes_path . 'donations/charitable-donation-functions.php' );
219
220 /* Users */
221 require_once( $includes_path . 'users/charitable-user-functions.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
227 /* Gateways */
228 require_once( $includes_path . 'gateways/interface-charitable-gateway.php' );
229 require_once( $includes_path . 'gateways/class-charitable-gateways.php' );
230 require_once( $includes_path . 'gateways/abstract-class-charitable-gateway.php' );
231 require_once( $includes_path . 'gateways/class-charitable-gateway-offline.php' );
232 require_once( $includes_path . 'gateways/class-charitable-gateway-paypal.php' );
233
234 /* Emails */
235 require_once( $includes_path . 'emails/interface-charitable-email.php' );
236 require_once( $includes_path . 'emails/class-charitable-emails.php' );
237 require_once( $includes_path . 'emails/abstract-class-charitable-email.php' );
238 require_once( $includes_path . 'emails/class-charitable-email-new-donation.php' );
239 require_once( $includes_path . 'emails/class-charitable-email-donation-receipt.php' );
240 require_once( $includes_path . 'emails/class-charitable-email-campaign-end.php' );
241 require_once( $includes_path . 'emails/class-charitable-email-password-reset.php' );
242 require_once( $includes_path . 'emails/charitable-email-hooks.php' );
243
244 /* Database */
245 require_once( $includes_path . 'db/abstract-class-charitable-db.php' );
246 require_once( $includes_path . 'db/class-charitable-campaign-donations-db.php' );
247 require_once( $includes_path . 'db/class-charitable-donors-db.php' );
248
249 /* Licensing */
250 require_once( $includes_path . 'licensing/class-charitable-licenses.php' );
251 require_once( $includes_path . 'licensing/class-charitable-plugin-updater.php' );
252
253 /* Public */
254 require_once( $includes_path . 'public/charitable-page-functions.php' );
255 require_once( $includes_path . 'public/charitable-template-helpers.php' );
256 require_once( $includes_path . 'public/class-charitable-session.php' );
257 require_once( $includes_path . 'public/class-charitable-template.php' );
258 require_once( $includes_path . 'public/class-charitable-template-part.php' );
259 require_once( $includes_path . 'public/class-charitable-templates.php' );
260 require_once( $includes_path . 'public/class-charitable-ghost-page.php' );
261 require_once( $includes_path . 'public/class-charitable-user-dashboard.php' );
262
263 /* Shortcodes */
264 require_once( $includes_path . 'shortcodes/class-charitable-campaigns-shortcode.php' );
265 require_once( $includes_path . 'shortcodes/class-charitable-my-donations-shortcode.php' );
266 require_once( $includes_path . 'shortcodes/class-charitable-donation-receipt-shortcode.php' );
267 require_once( $includes_path . 'shortcodes/class-charitable-login-shortcode.php' );
268 require_once( $includes_path . 'shortcodes/class-charitable-registration-shortcode.php' );
269 require_once( $includes_path . 'shortcodes/class-charitable-profile-shortcode.php' );
270 require_once( $includes_path . 'shortcodes/charitable-shortcodes-hooks.php' );
271
272 /* Widgets */
273 require_once( $includes_path . 'widgets/class-charitable-widgets.php' );
274 require_once( $includes_path . 'widgets/class-charitable-campaign-terms-widget.php' );
275 require_once( $includes_path . 'widgets/class-charitable-campaigns-widget.php' );
276 require_once( $includes_path . 'widgets/class-charitable-donors-widget.php' );
277 require_once( $includes_path . 'widgets/class-charitable-donate-widget.php' );
278 require_once( $includes_path . 'widgets/class-charitable-donation-stats-widget.php' );
279
280 /* User Management */
281 require_once( $includes_path . 'user-management/class-charitable-registration-form.php' );
282 require_once( $includes_path . 'user-management/class-charitable-profile-form.php' );
283 require_once( $includes_path . 'user-management/class-charitable-forgot-password-form.php' );
284 require_once( $includes_path . 'user-management/class-charitable-reset-password-form.php' );
285 require_once( $includes_path . 'user-management/class-charitable-user-management.php' );
286 require_once( $includes_path . 'user-management/charitable-user-management-hooks.php' );
287
288 /* Customizer */
289 require_once( $includes_path . 'admin/customizer/class-charitable-customizer.php' );
290
291 /* Deprecated */
292 require_once( $includes_path . 'deprecated/charitable-deprecated-functions.php' );
293
294 /**
295 * We are registering this object only for backwards compatibility. It
296 * will be removed in or after Charitable 1.3.
297 *
298 * @deprecated
299 */
300 $this->register_object( Charitable_Emails::get_instance() );
301 $this->register_object( Charitable_Request::get_instance() );
302 $this->register_object( Charitable_Gateways::get_instance() );
303 $this->register_object( Charitable_i18n::get_instance() );
304 $this->register_object( Charitable_Post_Types::get_instance() );
305 $this->register_object( Charitable_Cron::get_instance() );
306 $this->register_object( Charitable_Widgets::get_instance() );
307 $this->register_object( Charitable_Licenses::get_instance() );
308 $this->register_object( Charitable_User_Dashboard::get_instance() );
309 }
310
311 /**
312 * Set up hook and filter callback functions.
313 *
314 * @return void
315 * @access private
316 * @since 1.0.0
317 */
318 private function attach_hooks_and_filters() {
319 add_action( 'wpmu_new_blog', array( $this, 'maybe_activate_charitable_on_new_site' ) );
320 add_action( 'plugins_loaded', array( $this, 'charitable_install' ), 100 );
321 add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 );
322 add_action( 'plugins_loaded', array( $this, 'load_plugin_compat_files' ) );
323 add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) );
324 add_action( 'wp_enqueue_scripts', array( $this, 'maybe_start_qunit' ), 100 );
325
326 /**
327 * We do this on priority 20 so that any functionality that is loaded on init (such
328 * as addons) has a chance to run before the event.
329 */
330 add_action( 'init', array( $this, 'do_charitable_actions' ), 20 );
331 add_filter( 'charitable_sanitize_donation_meta', 'charitable_sanitize_donation_meta', 10, 2 );
332 }
333
334 /**
335 * Checks whether we're in the admin area and if so, loads the admin-only functionality.
336 *
337 * @return void
338 * @access private
339 * @since 1.0.0
340 */
341 private function maybe_start_admin() {
342 if ( ! is_admin() ) {
343 return;
344 }
345
346 require_once( $this->get_path( 'admin' ) . 'class-charitable-admin.php' );
347 require_once( $this->get_path( 'admin' ) . 'charitable-admin-hooks.php' );
348
349 /**
350 * We are registering this object only for backwards compatibility. It
351 * will be removed in or after Charitable 1.3.
352 *
353 * @deprecated
354 */
355 $this->register_object( Charitable_Admin::get_instance() );
356 }
357
358 /**
359 * Checks whether we're on the public-facing side and if so, loads the public-facing functionality.
360 *
361 * @return void
362 * @access private
363 * @since 1.0.0
364 */
365 private function maybe_start_public() {
366 if ( is_admin() ) {
367 return;
368 }
369
370 require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' );
371
372 /**
373 * We are registering this object only for backwards compatibility. It
374 * will be removed in or after Charitable 1.3.
375 *
376 * @deprecated
377 */
378 $this->register_object( Charitable_Public::get_instance() );
379 }
380
381 /**
382 * Load the QUnit tests if ?qunit is appended to the request.
383 *
384 * @return boolean
385 * @access public
386 * @since 1.4.17
387 */
388 public function maybe_start_qunit() {
389 /* Skip out early if ?qunit isn't included in the request. */
390 if ( ! array_key_exists( 'qunit', $_GET ) ) {
391 return false;
392 }
393
394 /* The unit tests have to exist. */
395 if ( ! file_exists( $this->get_path( 'directory' ) . 'tests/qunit/tests.js' ) ) {
396 return false;
397 }
398
399 wp_register_script( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.js', array(), '2.3.3', true );
400 /* Version: '20170615-15:44' */
401 wp_register_script( 'qunit-tests', $this->get_path( 'directory', false ) . 'tests/qunit/tests.js', array( 'jquery-core', 'qunit' ), time(), true );
402 wp_enqueue_script( 'qunit-tests' );
403
404 wp_register_style( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.css', array(), '2.3.3', 'all' );
405 wp_enqueue_style( 'qunit' );
406 }
407
408 /**
409 * Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality.
410 *
411 * @return void
412 * @access private
413 * @since 1.0.0
414 */
415 private function maybe_start_ajax() {
416 if ( false === ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
417 return;
418 }
419
420 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php' );
421 require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php' );
422
423 /**
424 * We are registering this object only for backwards compatibility. It
425 * will be removed in or after Charitable 1.3.
426 *
427 * @deprecated
428 */
429 $this->register_object( Charitable_Session::get_instance() );
430 }
431
432 /**
433 * This method is fired after all plugins are loaded and simply fires the charitable_start hook.
434 *
435 * Extensions can use the charitable_start event to load their own functionality.
436 *
437 * @return void
438 * @access public
439 * @since 1.0.0
440 */
441 public function charitable_start() {
442 do_action( 'charitable_start', $this );
443 }
444
445 /**
446 * Load plugin compatibility files on plugins_loaded hook.
447 *
448 * @return void
449 * @access public
450 * @since 1.4.18
451 */
452 public function load_plugin_compat_files() {
453 $includes_path = $this->get_path( 'includes' );
454
455 /* Divi */
456 if ( class_exists( 'ET_Builder_Plugin' ) || 'divi' == strtolower( wp_get_theme()->get_template() ) ) {
457 require_once( $includes_path . 'compat/charitable-divi-compat-functions.php' );
458 }
459
460 /* WP Super Cache */
461 if ( function_exists( 'wp_super_cache_text_domain' ) ) {
462 require_once( $includes_path . 'compat/charitable-wp-super-cache-compat-functions.php' );
463 }
464
465 /* W3TC */
466 if ( defined( 'W3TC' ) && W3TC ) {
467 require_once( $includes_path . 'compat/charitable-w3tc-compat-functions.php' );
468 }
469
470 /* WP Rocket */
471 if ( defined( 'WP_ROCKET_VERSION' ) ) {
472 require_once( $includes_path . 'compat/charitable-wp-rocket-compat-functions.php' );
473 }
474
475 /* WP Fastest Cache */
476 if ( class_exists( 'WpFastestCache' ) ) {
477 require_once( $includes_path . 'compat/charitable-wp-fastest-cache-compat-functions.php' );
478 }
479 }
480
481 /**
482 * Fires off an action right after Charitable is installed, allowing other
483 * plugins/themes to do something at this point.
484 *
485 * @return void
486 * @access public
487 * @since 1.0.1
488 */
489 public function charitable_install() {
490 $install = get_transient( 'charitable_install' );
491
492 if ( ! $install ) {
493 return;
494 }
495
496 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
497
498 Charitable_Install::finish_installing();
499
500 do_action( 'charitable_install' );
501
502 delete_transient( 'charitable_install' );
503 }
504
505 /**
506 * Returns whether we are currently in the start phase of the plugin.
507 *
508 * @return bool
509 * @access public
510 * @since 1.0.0
511 */
512 public function is_start() {
513 return current_filter() == 'charitable_start';
514 }
515
516 /**
517 * Returns whether the plugin has already started.
518 *
519 * @return bool
520 * @access public
521 * @since 1.0.0
522 */
523 public function started() {
524 return did_action( 'charitable_start' ) || current_filter() == 'charitable_start';
525 }
526
527 /**
528 * Returns whether the plugin is being activated.
529 *
530 * @return bool
531 * @access public
532 * @since 1.0.0
533 */
534 public function is_activation() {
535 return current_filter() == 'activate_charitable/charitable.php';
536 }
537
538 /**
539 * Returns whether the plugin is being deactivated.
540 *
541 * @return bool
542 * @access public
543 * @since 1.0.0
544 */
545 public function is_deactivation() {
546 return current_filter() == 'deactivate_charitable/charitable.php';
547 }
548
549 /**
550 * Stores an object in the plugin's registry.
551 *
552 * @param mixed $object Object to be registered.
553 * @return void
554 * @access public
555 * @since 1.0.0
556 */
557 public function register_object( $object ) {
558 if ( ! is_object( $object ) ) {
559 return;
560 }
561
562 $class = get_class( $object );
563
564 $this->registry[ $class ] = $object;
565 }
566
567 /**
568 * Returns a registered object.
569 *
570 * @param string $class The type of class you want to retrieve.
571 * @return mixed The object if its registered. Otherwise false.
572 * @access public
573 * @since 1.0.0
574 */
575 public function get_registered_object( $class ) {
576 return isset( $this->registry[ $class ] ) ? $this->registry[ $class ] : false;
577 }
578
579 /**
580 * Returns plugin paths.
581 *
582 * @param string $type If empty, returns the path to the plugin.
583 * @param boolean $absolute_path If true, returns the file system path. If false, returns it as a URL.
584 * @return string
585 * @since 1.0.0
586 */
587 public function get_path( $type = '', $absolute_path = true ) {
588 $base = $absolute_path ? $this->directory_path : $this->directory_url;
589
590 switch ( $type ) {
591 case 'includes' :
592 $path = $base . 'includes/';
593 break;
594
595 case 'admin' :
596 $path = $base . 'includes/admin/';
597 break;
598
599 case 'public' :
600 $path = $base . 'includes/public/';
601 break;
602
603 case 'assets' :
604 $path = $base . 'assets/';
605 break;
606
607 case 'templates' :
608 $path = $base . 'templates/';
609 break;
610
611 case 'directory' :
612 $path = $base;
613 break;
614
615 default :
616 $path = __FILE__;
617
618 }//end switch
619
620 return $path;
621 }
622
623 /**
624 * Returns the plugin's version number.
625 *
626 * @return string
627 * @access public
628 * @since 1.0.0
629 */
630 public function get_version() {
631 $version = self::VERSION;
632
633 if ( false !== strpos( $version, '-' ) ) {
634 $parts = explode( '-', $version );
635 $version = $parts[0];
636 }
637
638 return $version;
639 }
640
641 /**
642 * Returns the public class.
643 *
644 * @return Charitable_Public
645 * @access public
646 * @since 1.0.0
647 */
648 public function get_public() {
649 return $this->get_registered_object( 'Charitable_Public' );
650 }
651
652 /**
653 * Returns the admin class.
654 *
655 * @return Charitable_Admin
656 * @access public
657 * @since 1.0.0
658 */
659 public function get_admin() {
660 return $this->get_registered_object( 'Charitable_Admin' );
661 }
662
663 /**
664 * Return the current request object.
665 *
666 * @return Charitable_Request
667 * @access public
668 * @since 1.0.0
669 */
670 public function get_request() {
671 $request = $this->get_registered_object( 'Charitable_Request' );
672
673 if ( false === $request ) {
674 $request = new Charitable_Request();
675 $this->register_object( $request );
676 }
677
678 return $request;
679 }
680
681 /**
682 * Returns the model for one of Charitable's database tables.
683 *
684 * @param string $table The database table to retrieve.
685 * @return Charitable_DB
686 * @access public
687 * @since 1.0.0
688 */
689 public function get_db_table( $table ) {
690 $tables = $this->get_tables();
691
692 if ( ! isset( $tables[ $table ] ) ) {
693 charitable_get_deprecated()->doing_it_wrong(
694 __METHOD__,
695 sprintf( 'Invalid table %s passed', $table ),
696 '1.0.0'
697 );
698 return null;
699 }
700
701 $class_name = $tables[ $table ];
702
703 $db_table = $this->get_registered_object( $class_name );
704
705 if ( false === $db_table ) {
706 $db_table = new $class_name;
707 $this->register_object( $db_table );
708 }
709
710 return $db_table;
711 }
712
713 /**
714 * Return the filtered list of registered tables.
715 *
716 * @return string[]
717 * @access private
718 * @since 1.0.0
719 */
720 private function get_tables() {
721 $default_tables = array(
722 'campaign_donations' => 'Charitable_Campaign_Donations_DB',
723 'donors' => 'Charitable_Donors_DB',
724 );
725
726 return apply_filters( 'charitable_db_tables', $default_tables );
727 }
728
729 /**
730 * Maybe activate Charitable when a new site is added in a multisite network.
731 *
732 * @param int $blog_id
733 * @return boolean
734 * @access public
735 * @since 1.4.6
736 */
737 public function maybe_activate_charitable_on_new_site( $blog_id ) {
738
739 if ( is_plugin_active_for_network( basename( $this->directory_path ) . '/charitable.php' ) ) {
740
741 switch_to_blog( $blog_id );
742
743 $this->activate( false );
744
745 restore_current_blog();
746 }
747 }
748
749 /**
750 * Runs on plugin activation.
751 *
752 * @see register_activation_hook
753 *
754 * @param boolean $network_wide Whether to enable the plugin for all sites in the network
755 * or just the current site. Multisite only. Default is false.
756 * @return void
757 * @access public
758 * @since 1.0.0
759 */
760 public function activate( $network_wide = false ) {
761
762 require_once( $this->get_path( 'includes' ) . 'class-charitable-install.php' );
763
764 if ( is_multisite() && $network_wide ) {
765
766 global $wpdb;
767
768 foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) {
769
770 switch_to_blog( $blog_id );
771
772 new Charitable_Install();
773
774 restore_current_blog();
775 }
776 } else {
777
778 new Charitable_Install();
779
780 }
781 }
782
783 /**
784 * Runs on plugin deactivation.
785 *
786 * @see register_deactivation_hook
787 *
788 * @return void
789 * @access public
790 * @since 1.0.0
791 */
792 public function deactivate() {
793 require_once( $this->get_path( 'includes' ) . 'class-charitable-uninstall.php' );
794 new Charitable_Uninstall();
795 }
796
797 /**
798 * If a charitable_action event is triggered, delegate the event using do_action.
799 *
800 * @return void
801 * @access public
802 * @since 1.0.0
803 */
804 public function do_charitable_actions() {
805 if ( isset( $_REQUEST['charitable_action'] ) ) {
806
807 $action = $_REQUEST['charitable_action'];
808
809 do_action( 'charitable_' . $action, 20 );
810 }
811 }
812
813 /**
814 * Throw error on object clone.
815 *
816 * This class is specifically designed to be instantiated once. You can retrieve the instance using charitable()
817 *
818 * @since 1.0.0
819 * @access public
820 * @return void
821 */
822 public function __clone() {
823 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
824 }
825
826 /**
827 * Disable unserializing of the class.
828 *
829 * @since 1.0.0
830 * @access public
831 * @return void
832 */
833 public function __wakeup() {
834 _doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'charitable' ), '1.0.0' );
835 }
836
837 /**
838 * DEPRECATED METHODS
839 */
840
841 /**
842 * @deprecated
843 */
844 public function get_currency_helper() {
845 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.4.0', 'charitable_get_currency_helper' );
846 return charitable_get_currency_helper();
847 }
848
849 /**
850 * @deprecated
851 */
852 public function get_location_helper() {
853 charitable_get_deprecated()->deprecated_function( __METHOD__, '1.2.0', 'charitable_get_location_helper' );
854 return charitable_get_location_helper();
855 }
856 }
857
858 $charitable = new Charitable();
859
860 endif;
861