| 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.6.56 |
| 7 |
* Author: WP Charitable |
| 8 |
* Author URI: https://wpcharitable.com |
| 9 |
* Requires at least: 4.1 |
| 10 |
* Tested up to: 5.9 |
| 11 |
* |
| 12 |
* Text Domain: charitable |
| 13 |
* Domain Path: /i18n/languages/ |
| 14 |
* |
| 15 |
* @package Charitable |
| 16 |
* @author Eric Daams |
| 17 |
* @copyright Copyright (c) 2022, 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' ) ) { |
| 23 |
exit; |
| 24 |
} |
| 25 |
|
| 26 |
if ( ! class_exists( 'Charitable' ) ) : |
| 27 |
|
| 28 |
/** |
| 29 |
* Main Charitable class. |
| 30 |
*/ |
| 31 |
class Charitable { |
| 32 |
|
| 33 |
/* Plugin version. */ |
| 34 |
const VERSION = '1.6.56'; |
| 35 |
|
| 36 |
/* Version of database schema. */ |
| 37 |
const DB_VERSION = '20180522'; |
| 38 |
|
| 39 |
/* Campaign post type. */ |
| 40 |
const CAMPAIGN_POST_TYPE = 'campaign'; |
| 41 |
|
| 42 |
/* Donation post type. */ |
| 43 |
const DONATION_POST_TYPE = 'donation'; |
| 44 |
|
| 45 |
/** |
| 46 |
* Single instance of this class. |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
* |
| 50 |
* @var Charitable |
| 51 |
*/ |
| 52 |
private static $instance = null; |
| 53 |
|
| 54 |
/** |
| 55 |
* The absolute path to this plugin's directory. |
| 56 |
* |
| 57 |
* @since 1.0.0 |
| 58 |
* |
| 59 |
* @var string |
| 60 |
*/ |
| 61 |
private $directory_path; |
| 62 |
|
| 63 |
/** |
| 64 |
* The URL of this plugin's directory. |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
* |
| 68 |
* @var string |
| 69 |
*/ |
| 70 |
private $directory_url; |
| 71 |
|
| 72 |
/** |
| 73 |
* Directory path for the includes folder of the plugin. |
| 74 |
* |
| 75 |
* @since 1.0.0 |
| 76 |
* |
| 77 |
* @var string |
| 78 |
*/ |
| 79 |
private $includes_path; |
| 80 |
|
| 81 |
/** |
| 82 |
* Store of registered objects. |
| 83 |
* |
| 84 |
* @since 1.0.0 |
| 85 |
* @since 1.5.0 Changed to Charitable_Registry object. Previously it was an array. |
| 86 |
* |
| 87 |
* @var Charitable_Registry |
| 88 |
*/ |
| 89 |
private $registry; |
| 90 |
|
| 91 |
/** |
| 92 |
* Classmap. |
| 93 |
* |
| 94 |
* @since 1.5.0 |
| 95 |
* |
| 96 |
* @var array |
| 97 |
*/ |
| 98 |
private $classmap; |
| 99 |
|
| 100 |
/** |
| 101 |
* Create class instance. |
| 102 |
* |
| 103 |
* @since 1.0.0 |
| 104 |
*/ |
| 105 |
public function __construct() { |
| 106 |
$this->directory_path = plugin_dir_path( __FILE__ ); |
| 107 |
$this->directory_url = plugin_dir_url( __FILE__ ); |
| 108 |
$this->includes_path = $this->directory_path . 'includes/'; |
| 109 |
|
| 110 |
spl_autoload_register( array( $this, 'autoloader' ) ); |
| 111 |
|
| 112 |
$this->load_dependencies(); |
| 113 |
|
| 114 |
register_activation_hook( __FILE__, array( $this, 'activate' ) ); |
| 115 |
register_deactivation_hook( __FILE__, array( $this, 'deactivate' ) ); |
| 116 |
|
| 117 |
add_action( 'plugins_loaded', array( $this, 'start' ), 1 ); |
| 118 |
} |
| 119 |
|
| 120 |
/** |
| 121 |
* Returns the original instance of this class. |
| 122 |
* |
| 123 |
* @since 1.0.0 |
| 124 |
* |
| 125 |
* @return Charitable |
| 126 |
*/ |
| 127 |
public static function get_instance() { |
| 128 |
return self::$instance; |
| 129 |
} |
| 130 |
|
| 131 |
/** |
| 132 |
* Run the startup sequence. |
| 133 |
* |
| 134 |
* This is only ever executed once. |
| 135 |
* |
| 136 |
* @since 1.0.0 |
| 137 |
* |
| 138 |
* @return void |
| 139 |
*/ |
| 140 |
public function start() { |
| 141 |
/* If we've already started (i.e. run this function once before), do not pass go. */ |
| 142 |
if ( $this->started() ) { |
| 143 |
return; |
| 144 |
} |
| 145 |
|
| 146 |
/* Set static instance. */ |
| 147 |
self::$instance = $this; |
| 148 |
|
| 149 |
/* Set up the registry and instantiate objects we need straight away. */ |
| 150 |
$this->registry(); |
| 151 |
|
| 152 |
$this->maybe_start_ajax(); |
| 153 |
|
| 154 |
$this->attach_hooks_and_filters(); |
| 155 |
|
| 156 |
$this->maybe_start_admin(); |
| 157 |
|
| 158 |
$this->maybe_start_public(); |
| 159 |
|
| 160 |
Charitable_Addons::load( $this ); |
| 161 |
} |
| 162 |
|
| 163 |
/** |
| 164 |
* Include necessary files. |
| 165 |
* |
| 166 |
* @since 1.0.0 |
| 167 |
* |
| 168 |
* @return void |
| 169 |
*/ |
| 170 |
private function load_dependencies() { |
| 171 |
$includes_path = $this->get_path( 'includes' ); |
| 172 |
|
| 173 |
/* Load files with hooks & functions. Classes are autoloaded. */ |
| 174 |
require_once( $includes_path . 'charitable-core-functions.php' ); |
| 175 |
require_once( $includes_path . 'api/charitable-api-functions.php' ); |
| 176 |
require_once( $includes_path . 'campaigns/charitable-campaign-functions.php' ); |
| 177 |
require_once( $includes_path . 'campaigns/charitable-campaign-hooks.php' ); |
| 178 |
require_once( $includes_path . 'compat/charitable-compat-functions.php' ); |
| 179 |
require_once( $includes_path . 'currency/charitable-currency-functions.php' ); |
| 180 |
require_once( $includes_path . 'deprecated/charitable-deprecated-functions.php' ); |
| 181 |
require_once( $includes_path . 'donations/charitable-donation-hooks.php' ); |
| 182 |
require_once( $includes_path . 'donations/charitable-donation-functions.php' ); |
| 183 |
require_once( $includes_path . 'emails/charitable-email-hooks.php' ); |
| 184 |
require_once( $includes_path . 'endpoints/charitable-endpoints-functions.php' ); |
| 185 |
require_once( $includes_path . 'privacy/charitable-privacy-functions.php' ); |
| 186 |
require_once( $includes_path . 'public/charitable-template-helpers.php' ); |
| 187 |
require_once( $includes_path . 'shortcodes/charitable-shortcodes-hooks.php' ); |
| 188 |
require_once( $includes_path . 'upgrades/charitable-upgrade-hooks.php' ); |
| 189 |
require_once( $includes_path . 'users/charitable-user-functions.php' ); |
| 190 |
require_once( $includes_path . 'user-management/charitable-user-management-hooks.php' ); |
| 191 |
require_once( $includes_path . 'utilities/charitable-utility-functions.php' ); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Load the template functions after theme is loaded. |
| 196 |
* |
| 197 |
* This gives themes time to override the functions. |
| 198 |
* |
| 199 |
* @since 1.6.10 |
| 200 |
* |
| 201 |
* @return void |
| 202 |
*/ |
| 203 |
public function load_template_files() { |
| 204 |
$includes_path = $this->get_path( 'includes' ); |
| 205 |
|
| 206 |
require_once( $includes_path . 'public/charitable-template-functions.php' ); |
| 207 |
require_once( $includes_path . 'public/charitable-template-hooks.php' ); |
| 208 |
} |
| 209 |
|
| 210 |
/** |
| 211 |
* Dynamically loads the class attempting to be instantiated elsewhere in the |
| 212 |
* plugin by looking at the $class_name parameter being passed as an argument. |
| 213 |
* |
| 214 |
* @since 1.5.0 |
| 215 |
* |
| 216 |
* @param string $class_name The fully-qualified name of the class to load. |
| 217 |
* @return boolean |
| 218 |
*/ |
| 219 |
public function autoloader( $class_name ) { |
| 220 |
/* If the specified $class_name already exists, bail. */ |
| 221 |
if ( class_exists( $class_name ) ) { |
| 222 |
return false; |
| 223 |
} |
| 224 |
|
| 225 |
/* If the specified $class_name does not include our namespace, duck out. */ |
| 226 |
if ( false === strpos( $class_name, 'Charitable_' ) ) { |
| 227 |
return false; |
| 228 |
} |
| 229 |
|
| 230 |
/* Autogenerated class map. */ |
| 231 |
if ( ! isset( $this->classmap ) ) { |
| 232 |
$this->classmap = include( 'includes/autoloader/charitable-class-map.php' ); |
| 233 |
} |
| 234 |
|
| 235 |
$file_path = isset( $this->classmap[ $class_name ] ) ? $this->get_path( 'includes' ) . $this->classmap[ $class_name ] : false; |
| 236 |
|
| 237 |
if ( false !== $file_path && file_exists( $file_path ) && is_file( $file_path ) ) { |
| 238 |
require_once( $file_path ); |
| 239 |
return true; |
| 240 |
} |
| 241 |
|
| 242 |
return false; |
| 243 |
} |
| 244 |
|
| 245 |
/** |
| 246 |
* Returns a registered class object. |
| 247 |
* |
| 248 |
* @since 1.5.0 |
| 249 |
* |
| 250 |
* @return Charitable_Registry |
| 251 |
*/ |
| 252 |
public function registry() { |
| 253 |
if ( ! isset( $this->registry ) ) { |
| 254 |
$this->registry = new Charitable_Registry(); |
| 255 |
$this->registry->register_object( Charitable_Emails::get_instance() ); |
| 256 |
$this->registry->register_object( Charitable_Request::get_instance() ); |
| 257 |
$this->registry->register_object( Charitable_Gateways::get_instance() ); |
| 258 |
$this->registry->register_object( Charitable_i18n::get_instance() ); |
| 259 |
$this->registry->register_object( Charitable_Post_Types::get_instance() ); |
| 260 |
$this->registry->register_object( Charitable_Cron::get_instance() ); |
| 261 |
$this->registry->register_object( Charitable_Widgets::get_instance() ); |
| 262 |
$this->registry->register_object( Charitable_Licenses::get_instance() ); |
| 263 |
$this->registry->register_object( Charitable_User_Dashboard::get_instance() ); |
| 264 |
$this->registry->register_object( Charitable_Locations::get_instance() ); |
| 265 |
$this->registry->register_object( Charitable_Currency::get_instance() ); |
| 266 |
|
| 267 |
$this->registry->register_object( new Charitable_Privacy ); |
| 268 |
$this->registry->register_object( new Charitable_Debugging ); |
| 269 |
$this->registry->register_object( new Charitable_Locale ); |
| 270 |
} |
| 271 |
|
| 272 |
return $this->registry; |
| 273 |
} |
| 274 |
|
| 275 |
/** |
| 276 |
* Set up hook and filter callback functions. |
| 277 |
* |
| 278 |
* @since 1.0.0 |
| 279 |
* |
| 280 |
* @return void |
| 281 |
*/ |
| 282 |
private function attach_hooks_and_filters() { |
| 283 |
add_action( 'wpmu_new_blog', array( $this, 'maybe_activate_charitable_on_new_site' ) ); |
| 284 |
add_action( 'plugins_loaded', array( $this, 'charitable_install' ), 100 ); |
| 285 |
add_action( 'plugins_loaded', array( $this, 'charitable_start' ), 100 ); |
| 286 |
add_action( 'plugins_loaded', array( $this, 'endpoints' ), 100 ); |
| 287 |
add_action( 'plugins_loaded', array( $this, 'donation_fields' ), 100 ); |
| 288 |
add_action( 'plugins_loaded', array( $this, 'campaign_fields' ), 100 ); |
| 289 |
add_action( 'plugins_loaded', array( $this, 'register_donormeta_table' ) ); |
| 290 |
add_action( 'plugins_loaded', 'charitable_load_compat_functions' ); |
| 291 |
add_action( 'setup_theme', array( 'Charitable_Customizer', 'start' ) ); |
| 292 |
add_action( 'after_setup_theme', array( $this, 'load_template_files' ) ); |
| 293 |
add_action( 'wp_enqueue_scripts', array( $this, 'maybe_start_qunit' ), 100 ); |
| 294 |
add_action( 'rest_api_init', 'charitable_register_api_routes' ); |
| 295 |
|
| 296 |
/** |
| 297 |
* We do this on priority 20 so that any functionality that is loaded on init (such |
| 298 |
* as addons) has a chance to run before the event. |
| 299 |
*/ |
| 300 |
add_action( 'init', array( $this, 'do_charitable_actions' ), 20 ); |
| 301 |
} |
| 302 |
|
| 303 |
/** |
| 304 |
* Checks whether we're in the admin area and if so, loads the admin-only functionality. |
| 305 |
* |
| 306 |
* @since 1.0.0 |
| 307 |
* |
| 308 |
* @return Charitable_Admin|false |
| 309 |
*/ |
| 310 |
private function maybe_start_admin() { |
| 311 |
if ( ! is_admin() ) { |
| 312 |
return false; |
| 313 |
} |
| 314 |
|
| 315 |
require_once( $this->get_path( 'admin' ) . 'class-charitable-admin.php' ); |
| 316 |
require_once( $this->get_path( 'admin' ) . 'charitable-admin-hooks.php' ); |
| 317 |
|
| 318 |
$admin = Charitable_Admin::get_instance(); |
| 319 |
|
| 320 |
$this->registry->register_object( $admin ); |
| 321 |
|
| 322 |
return $admin; |
| 323 |
} |
| 324 |
|
| 325 |
/** |
| 326 |
* Checks whether we're on the public-facing side and if so, loads the public-facing functionality. |
| 327 |
* |
| 328 |
* @since 1.0.0 |
| 329 |
* |
| 330 |
* @return Charitable_Public|false |
| 331 |
*/ |
| 332 |
private function maybe_start_public() { |
| 333 |
if ( is_admin() && ! $this->is_ajax() ) { |
| 334 |
return false; |
| 335 |
} |
| 336 |
|
| 337 |
require_once( $this->get_path( 'public' ) . 'class-charitable-public.php' ); |
| 338 |
|
| 339 |
$public = Charitable_Public::get_instance(); |
| 340 |
|
| 341 |
$this->registry->register_object( $public ); |
| 342 |
|
| 343 |
return $public; |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Load the QUnit tests if ?qunit is appended to the request. |
| 348 |
* |
| 349 |
* @since 1.4.17 |
| 350 |
* |
| 351 |
* @return boolean |
| 352 |
*/ |
| 353 |
public function maybe_start_qunit() { |
| 354 |
/* Skip out early if ?qunit isn't included in the request. */ |
| 355 |
if ( ! array_key_exists( 'qunit', $_GET ) ) { |
| 356 |
return false; |
| 357 |
} |
| 358 |
|
| 359 |
/* The unit tests have to exist. */ |
| 360 |
if ( ! file_exists( $this->get_path( 'directory' ) . 'tests/qunit/tests.js' ) ) { |
| 361 |
return false; |
| 362 |
} |
| 363 |
|
| 364 |
wp_register_script( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.js', array(), '2.3.3', true ); |
| 365 |
/* Version: '20170615-15:44' */ |
| 366 |
wp_register_script( 'qunit-tests', $this->get_path( 'directory', false ) . 'tests/qunit/tests.js', array( 'jquery', 'qunit' ), time(), true ); |
| 367 |
wp_enqueue_script( 'qunit-tests' ); |
| 368 |
|
| 369 |
wp_register_style( 'qunit', 'https://code.jquery.com/qunit/qunit-2.3.3.css', array(), '2.3.3', 'all' ); |
| 370 |
wp_enqueue_style( 'qunit' ); |
| 371 |
} |
| 372 |
|
| 373 |
/** |
| 374 |
* Checks whether the current request is an AJAX request. |
| 375 |
* |
| 376 |
* @since 1.5.0 |
| 377 |
* |
| 378 |
* @return boolean |
| 379 |
*/ |
| 380 |
private function is_ajax() { |
| 381 |
return false !== ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
| 382 |
} |
| 383 |
|
| 384 |
/** |
| 385 |
* Checks whether we're executing an AJAX hook and if so, loads some AJAX functionality. |
| 386 |
* |
| 387 |
* @since 1.0.0 |
| 388 |
* |
| 389 |
* @return void |
| 390 |
*/ |
| 391 |
private function maybe_start_ajax() { |
| 392 |
if ( ! $this->is_ajax() ) { |
| 393 |
return; |
| 394 |
} |
| 395 |
|
| 396 |
require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-functions.php' ); |
| 397 |
require_once( $this->get_path( 'includes' ) . 'ajax/charitable-ajax-hooks.php' ); |
| 398 |
} |
| 399 |
|
| 400 |
/** |
| 401 |
* This method is fired after all plugins are loaded and simply fires the charitable_start hook. |
| 402 |
* |
| 403 |
* Extensions can use the charitable_start event to load their own functionality. |
| 404 |
* |
| 405 |
* @since 1.0.0 |
| 406 |
* |
| 407 |
* @return void |
| 408 |
*/ |
| 409 |
public function charitable_start() { |
| 410 |
do_action( 'charitable_start', $this ); |
| 411 |
} |
| 412 |
|
| 413 |
/** |
| 414 |
* Fires off an action right after Charitable is installed, allowing other |
| 415 |
* plugins/themes to do something at this point. |
| 416 |
* |
| 417 |
* @since 1.0.1 |
| 418 |
* |
| 419 |
* @return void |
| 420 |
*/ |
| 421 |
public function charitable_install() { |
| 422 |
$install = get_transient( 'charitable_install' ); |
| 423 |
|
| 424 |
if ( ! $install ) { |
| 425 |
return; |
| 426 |
} |
| 427 |
|
| 428 |
require_once( $this->get_path( 'includes' ) . 'plugin/class-charitable-install.php' ); |
| 429 |
|
| 430 |
Charitable_Install::finish_installing(); |
| 431 |
|
| 432 |
do_action( 'charitable_install' ); |
| 433 |
|
| 434 |
delete_transient( 'charitable_install' ); |
| 435 |
} |
| 436 |
|
| 437 |
/** |
| 438 |
* Returns whether we are currently in the start phase of the plugin. |
| 439 |
* |
| 440 |
* @since 1.0.0 |
| 441 |
* |
| 442 |
* @return boolean |
| 443 |
*/ |
| 444 |
public function is_start() { |
| 445 |
return current_filter() == 'charitable_start'; |
| 446 |
} |
| 447 |
|
| 448 |
/** |
| 449 |
* Returns whether the plugin has already started. |
| 450 |
* |
| 451 |
* @since 1.0.0 |
| 452 |
* |
| 453 |
* @return boolean |
| 454 |
*/ |
| 455 |
public function started() { |
| 456 |
return did_action( 'charitable_start' ) || current_filter() == 'charitable_start'; |
| 457 |
} |
| 458 |
|
| 459 |
/** |
| 460 |
* Returns whether the plugin is being activated. |
| 461 |
* |
| 462 |
* @since 1.0.0 |
| 463 |
* |
| 464 |
* @return boolean |
| 465 |
*/ |
| 466 |
public function is_activation() { |
| 467 |
return current_filter() == 'activate_charitable/charitable.php'; |
| 468 |
} |
| 469 |
|
| 470 |
/** |
| 471 |
* Returns whether the plugin is being deactivated. |
| 472 |
* |
| 473 |
* @since 1.0.0 |
| 474 |
* |
| 475 |
* @return boolean |
| 476 |
*/ |
| 477 |
public function is_deactivation() { |
| 478 |
return current_filter() == 'deactivate_charitable/charitable.php'; |
| 479 |
} |
| 480 |
|
| 481 |
/** |
| 482 |
* Returns plugin paths. |
| 483 |
* |
| 484 |
* @since 1.0.0 |
| 485 |
* |
| 486 |
* @param string $type If empty, returns the path to the plugin. |
| 487 |
* @param boolean $absolute_path If true, returns the file system path. If false, returns it as a URL. |
| 488 |
* @return string |
| 489 |
*/ |
| 490 |
public function get_path( $type = '', $absolute_path = true ) { |
| 491 |
$base = $absolute_path ? $this->directory_path : $this->directory_url; |
| 492 |
|
| 493 |
switch ( $type ) { |
| 494 |
case 'includes': |
| 495 |
$path = $base . 'includes/'; |
| 496 |
break; |
| 497 |
|
| 498 |
case 'admin': |
| 499 |
$path = $base . 'includes/admin/'; |
| 500 |
break; |
| 501 |
|
| 502 |
case 'public': |
| 503 |
$path = $base . 'includes/public/'; |
| 504 |
break; |
| 505 |
|
| 506 |
case 'assets': |
| 507 |
$path = $base . 'assets/'; |
| 508 |
break; |
| 509 |
|
| 510 |
case 'templates': |
| 511 |
$path = $base . 'templates/'; |
| 512 |
break; |
| 513 |
|
| 514 |
case 'directory': |
| 515 |
$path = $base; |
| 516 |
break; |
| 517 |
|
| 518 |
default: |
| 519 |
$path = __FILE__; |
| 520 |
|
| 521 |
}//end switch |
| 522 |
|
| 523 |
return $path; |
| 524 |
} |
| 525 |
|
| 526 |
/** |
| 527 |
* Returns the plugin's version number. |
| 528 |
* |
| 529 |
* @since 1.0.0 |
| 530 |
* |
| 531 |
* @return string |
| 532 |
*/ |
| 533 |
public function get_version() { |
| 534 |
$version = self::VERSION; |
| 535 |
|
| 536 |
if ( false !== strpos( $version, '-' ) ) { |
| 537 |
$parts = explode( '-', $version ); |
| 538 |
$version = $parts[0]; |
| 539 |
} |
| 540 |
|
| 541 |
return $version; |
| 542 |
} |
| 543 |
|
| 544 |
/** |
| 545 |
* Get the campaign fields registry |
| 546 |
* |
| 547 |
* If the registry has not been set up yet, this will also |
| 548 |
* perform the task of setting it up initially. |
| 549 |
* |
| 550 |
* This method is called on the plugins_loaded hook. |
| 551 |
* |
| 552 |
* @since 1.6.0 |
| 553 |
* |
| 554 |
* @return Charitable_Campaign_Field_Registry |
| 555 |
*/ |
| 556 |
public function campaign_fields() { |
| 557 |
if ( ! $this->registry->has( 'campaign_field_registry' ) ) { |
| 558 |
$campaign_fields = new Charitable_Campaign_Field_Registry(); |
| 559 |
|
| 560 |
/* Register it immediately to avoid endless recursion. */ |
| 561 |
$this->registry->register_object( $campaign_fields ); |
| 562 |
|
| 563 |
$fields = include( $this->get_path( 'includes' ) . 'fields/default-fields/campaign-fields.php' ); |
| 564 |
|
| 565 |
foreach ( $fields as $key => $args ) { |
| 566 |
$campaign_fields->register_field( new Charitable_Campaign_Field( $key, $args ) ); |
| 567 |
} |
| 568 |
} |
| 569 |
|
| 570 |
return $this->registry->get( 'campaign_field_registry' ); |
| 571 |
} |
| 572 |
|
| 573 |
/** |
| 574 |
* Get the donation fields registry |
| 575 |
* |
| 576 |
* If the registry has not been set up yet, this will also |
| 577 |
* perform the task of setting it up initially. |
| 578 |
* |
| 579 |
* This method is called on the plugins_loaded hook. |
| 580 |
* |
| 581 |
* @since 1.5.0 |
| 582 |
* |
| 583 |
* @return Charitable_Donation_Field_Registry |
| 584 |
*/ |
| 585 |
public function donation_fields() { |
| 586 |
if ( ! $this->registry->has( 'donation_field_registry' ) ) { |
| 587 |
$donation_fields = new Charitable_Donation_Field_Registry(); |
| 588 |
|
| 589 |
/* Register it immediately to avoid endless recursion. */ |
| 590 |
$this->registry->register_object( $donation_fields ); |
| 591 |
|
| 592 |
$fields = include( $this->get_path( 'includes' ) . 'fields/default-fields/donation-fields.php' ); |
| 593 |
|
| 594 |
foreach ( $fields as $key => $args ) { |
| 595 |
$donation_fields->register_field( new Charitable_Donation_Field( $key, $args ) ); |
| 596 |
} |
| 597 |
} |
| 598 |
|
| 599 |
return $this->registry->get( 'donation_field_registry' ); |
| 600 |
} |
| 601 |
|
| 602 |
/** |
| 603 |
* Return the Endpoints API object. |
| 604 |
* |
| 605 |
* If the Endpoints API has not been set up yet, this will also |
| 606 |
* perform the task of setting it up initially. |
| 607 |
* |
| 608 |
* This method is called on the plugins_loaded hook. |
| 609 |
* |
| 610 |
* @since 1.5.0 |
| 611 |
* |
| 612 |
* @return Charitable_Endpoints |
| 613 |
*/ |
| 614 |
public function endpoints() { |
| 615 |
if ( ! $this->registry->has( 'endpoints' ) ) { |
| 616 |
/** |
| 617 |
* The order in which we register endpoints is important, because |
| 618 |
* it determines the order in which the endpoints are checked to |
| 619 |
* find whether they are the current page. |
| 620 |
* |
| 621 |
* Any endpoint that builds on another endpoint should be registered |
| 622 |
* BEFORE the endpoint it builds on. In other words, move from |
| 623 |
* most specific to least specific. |
| 624 |
*/ |
| 625 |
$endpoints = new Charitable_Endpoints(); |
| 626 |
$endpoints->register( new Charitable_Campaign_Donation_Endpoint ); |
| 627 |
$endpoints->register( new Charitable_Campaign_Widget_Endpoint ); |
| 628 |
$endpoints->register( new Charitable_Campaign_Endpoint ); |
| 629 |
$endpoints->register( new Charitable_Donation_Cancellation_Endpoint ); |
| 630 |
$endpoints->register( new Charitable_Donation_Processing_Endpoint ); |
| 631 |
$endpoints->register( new Charitable_Donation_Receipt_Endpoint ); |
| 632 |
$endpoints->register( new Charitable_Email_Preview_Endpoint ); |
| 633 |
$endpoints->register( new Charitable_Email_Verification_Endpoint ); |
| 634 |
$endpoints->register( new Charitable_Forgot_Password_Endpoint ); |
| 635 |
$endpoints->register( new Charitable_Reset_Password_Endpoint ); |
| 636 |
$endpoints->register( new Charitable_Registration_Endpoint ); |
| 637 |
$endpoints->register( new Charitable_Login_Endpoint ); |
| 638 |
$endpoints->register( new Charitable_Profile_Endpoint ); |
| 639 |
$endpoints->register( new Charitable_Webhook_Listener_Endpoint ); |
| 640 |
|
| 641 |
$this->registry->register_object( $endpoints ); |
| 642 |
} |
| 643 |
|
| 644 |
return $this->registry->get( 'endpoints' ); |
| 645 |
} |
| 646 |
|
| 647 |
/** |
| 648 |
* Returns a registered object. |
| 649 |
* |
| 650 |
* @since 1.0.0 |
| 651 |
* |
| 652 |
* @param string $class The type of class to be retrieved. |
| 653 |
* @return object |
| 654 |
*/ |
| 655 |
public function get_registered_object( $class ) { |
| 656 |
return $this->registry->get( $class ); |
| 657 |
} |
| 658 |
|
| 659 |
/** |
| 660 |
* Registers our donormeta table as a meta data table. |
| 661 |
* |
| 662 |
* @since 1.6.0 |
| 663 |
* |
| 664 |
* @global WPDB $wpdb |
| 665 |
* @return void |
| 666 |
*/ |
| 667 |
public function register_donormeta_table() { |
| 668 |
global $wpdb; |
| 669 |
|
| 670 |
$wpdb->donormeta = $wpdb->prefix . 'charitable_donormeta'; |
| 671 |
} |
| 672 |
|
| 673 |
/** |
| 674 |
* Returns the model for one of Charitable's database tables. |
| 675 |
* |
| 676 |
* @since 1.0.0 |
| 677 |
* |
| 678 |
* @param string $table The database table to retrieve. |
| 679 |
* @return Charitable_DB |
| 680 |
*/ |
| 681 |
public function get_db_table( $table ) { |
| 682 |
$tables = $this->get_tables(); |
| 683 |
|
| 684 |
if ( ! isset( $tables[ $table ] ) ) { |
| 685 |
charitable_get_deprecated()->doing_it_wrong( |
| 686 |
__METHOD__, |
| 687 |
sprintf( 'Invalid table %s passed', $table ), |
| 688 |
'1.0.0' |
| 689 |
); |
| 690 |
return null; |
| 691 |
} |
| 692 |
|
| 693 |
return $this->registry->get( $tables[ $table ] ); |
| 694 |
} |
| 695 |
|
| 696 |
/** |
| 697 |
* Return the filtered list of registered tables. |
| 698 |
* |
| 699 |
* @since 1.0.0 |
| 700 |
* |
| 701 |
* @return string[] |
| 702 |
*/ |
| 703 |
private function get_tables() { |
| 704 |
/** |
| 705 |
* Filter the array of available Charitable table classes. |
| 706 |
* |
| 707 |
* @since 1.0.0 |
| 708 |
* |
| 709 |
* @param array $tables List of tables as a key=>value array. |
| 710 |
*/ |
| 711 |
return apply_filters( |
| 712 |
'charitable_db_tables', |
| 713 |
array( |
| 714 |
'campaign_donations' => 'Charitable_Campaign_Donations_DB', |
| 715 |
'donors' => 'Charitable_Donors_DB', |
| 716 |
'donormeta' => 'Charitable_Donormeta_DB', |
| 717 |
) |
| 718 |
); |
| 719 |
} |
| 720 |
|
| 721 |
/** |
| 722 |
* Maybe activate Charitable when a new site is added in a multisite network. |
| 723 |
* |
| 724 |
* @since 1.4.6 |
| 725 |
* |
| 726 |
* @param int $blog_id The blog to activate Charitable on. |
| 727 |
* @return void |
| 728 |
*/ |
| 729 |
public function maybe_activate_charitable_on_new_site( $blog_id ) { |
| 730 |
if ( is_plugin_active_for_network( basename( $this->directory_path ) . '/charitable.php' ) ) { |
| 731 |
switch_to_blog( $blog_id ); |
| 732 |
$this->activate( false ); |
| 733 |
restore_current_blog(); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Runs on plugin activation. |
| 739 |
* |
| 740 |
* @see register_activation_hook |
| 741 |
* |
| 742 |
* @since 1.0.0 |
| 743 |
* |
| 744 |
* @param boolean $network_wide Whether to enable the plugin for all sites in the network |
| 745 |
* or just the current site. Multisite only. Default is false. |
| 746 |
* @return void |
| 747 |
*/ |
| 748 |
public function activate( $network_wide = false ) { |
| 749 |
require_once( $this->get_path( 'includes' ) . 'plugin/class-charitable-install.php' ); |
| 750 |
|
| 751 |
if ( is_multisite() && $network_wide ) { |
| 752 |
global $wpdb; |
| 753 |
|
| 754 |
foreach ( $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) as $blog_id ) { |
| 755 |
switch_to_blog( $blog_id ); |
| 756 |
new Charitable_Install( $this->includes_path ); |
| 757 |
restore_current_blog(); |
| 758 |
} |
| 759 |
} else { |
| 760 |
new Charitable_Install( $this->includes_path ); |
| 761 |
} |
| 762 |
} |
| 763 |
|
| 764 |
/** |
| 765 |
* Runs on plugin deactivation. |
| 766 |
* |
| 767 |
* @see register_deactivation_hook |
| 768 |
* |
| 769 |
* @since 1.0.0 |
| 770 |
* |
| 771 |
* @return void |
| 772 |
*/ |
| 773 |
public function deactivate() { |
| 774 |
require_once( $this->get_path( 'includes' ) . 'plugin/class-charitable-uninstall.php' ); |
| 775 |
new Charitable_Uninstall(); |
| 776 |
} |
| 777 |
|
| 778 |
/** |
| 779 |
* If a charitable_action event is triggered, delegate the event using do_action. |
| 780 |
* |
| 781 |
* @since 1.0.0 |
| 782 |
* |
| 783 |
* @return void |
| 784 |
*/ |
| 785 |
public function do_charitable_actions() { |
| 786 |
if ( isset( $_REQUEST['charitable_action'] ) ) { |
| 787 |
|
| 788 |
$action = $_REQUEST['charitable_action']; |
| 789 |
|
| 790 |
/** |
| 791 |
* Handle Charitable action. |
| 792 |
* |
| 793 |
* @since 1.0.0 |
| 794 |
*/ |
| 795 |
do_action( 'charitable_' . $action ); |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
/** |
| 800 |
* Throw error on object clone. |
| 801 |
* |
| 802 |
* This class is specifically designed to be instantiated once. You can retrieve the instance using charitable() |
| 803 |
* |
| 804 |
* @since 1.0.0 |
| 805 |
* |
| 806 |
* @return void |
| 807 |
*/ |
| 808 |
public function __clone() { |
| 809 |
charitable_get_deprecated()->doing_it_wrong( |
| 810 |
__FUNCTION__, |
| 811 |
__( 'Cloning this object is forbidden.', 'charitable' ), |
| 812 |
'1.0.0' |
| 813 |
); |
| 814 |
} |
| 815 |
|
| 816 |
/** |
| 817 |
* Disable unserializing of the class. |
| 818 |
* |
| 819 |
* @since 1.0.0 |
| 820 |
* |
| 821 |
* @return void |
| 822 |
*/ |
| 823 |
public function __wakeup() { |
| 824 |
charitable_get_deprecated()->doing_it_wrong( |
| 825 |
__FUNCTION__, |
| 826 |
__( 'Unserializing instances of this class is forbidden.', 'charitable' ), |
| 827 |
'1.0.0' |
| 828 |
); |
| 829 |
} |
| 830 |
|
| 831 |
/** |
| 832 |
* DEPRECATED METHODS |
| 833 |
*/ |
| 834 |
|
| 835 |
/** |
| 836 |
* Load plugin compatibility files on plugins_loaded hook. |
| 837 |
* |
| 838 |
* @deprecated 1.8.0 |
| 839 |
* |
| 840 |
* @since 1.4.18 |
| 841 |
* @since 1.5.0 Deprecated. |
| 842 |
* |
| 843 |
* @return void |
| 844 |
*/ |
| 845 |
public function load_plugin_compat_files() { |
| 846 |
charitable_get_deprecated()->deprecated_function( |
| 847 |
__METHOD__, |
| 848 |
'1.5.0.', |
| 849 |
'charitable_load_compat_functions' |
| 850 |
); |
| 851 |
|
| 852 |
charitable_load_compat_functions(); |
| 853 |
} |
| 854 |
|
| 855 |
/** |
| 856 |
* Stores an object in the plugin's registry. |
| 857 |
* |
| 858 |
* @deprecated 1.8.0 |
| 859 |
* |
| 860 |
* @since 1.0.0 |
| 861 |
* @since 1.5.0 Deprecated. |
| 862 |
* |
| 863 |
* @param mixed $object Object to be registered. |
| 864 |
* @return void |
| 865 |
*/ |
| 866 |
public function register_object( $object ) { |
| 867 |
charitable_get_deprecated()->deprecated_function( |
| 868 |
__METHOD__, |
| 869 |
'1.5.0', |
| 870 |
'charitable()->registry()->register_object()' |
| 871 |
); |
| 872 |
|
| 873 |
$this->registry->register_object( $object ); |
| 874 |
} |
| 875 |
|
| 876 |
/** |
| 877 |
* Returns the public class. |
| 878 |
* |
| 879 |
* @deprecated 1.8.0 |
| 880 |
* |
| 881 |
* @since 1.0.0 |
| 882 |
* @since 1.5.0 Deprecated. |
| 883 |
* |
| 884 |
* @return Charitable_Public |
| 885 |
*/ |
| 886 |
public function get_public() { |
| 887 |
charitable_get_deprecated()->deprecated_function( |
| 888 |
__METHOD__, |
| 889 |
'1.5.0', |
| 890 |
'charitable_get_helper' |
| 891 |
); |
| 892 |
|
| 893 |
return $this->registry->get( 'Charitable_Public' ); |
| 894 |
} |
| 895 |
|
| 896 |
/** |
| 897 |
* Returns the admin class. |
| 898 |
* |
| 899 |
* @deprecated 1.8.0 |
| 900 |
* |
| 901 |
* @since 1.0.0 |
| 902 |
* @since 1.5.0 Deprecated. |
| 903 |
* |
| 904 |
* @return Charitable_Admin |
| 905 |
*/ |
| 906 |
public function get_admin() { |
| 907 |
charitable_get_deprecated()->deprecated_function( |
| 908 |
__METHOD__, |
| 909 |
'1.5.0', |
| 910 |
'charitable_get_helper' |
| 911 |
); |
| 912 |
|
| 913 |
return $this->registry->get( 'Charitable_Admin' ); |
| 914 |
} |
| 915 |
|
| 916 |
/** |
| 917 |
* Return the current request object. |
| 918 |
* |
| 919 |
* @deprecated 1.8.0 |
| 920 |
* |
| 921 |
* @since 1.0.0 |
| 922 |
* @since 1.5.0 Deprecated. |
| 923 |
* |
| 924 |
* @return Charitable_Request |
| 925 |
*/ |
| 926 |
public function get_request() { |
| 927 |
charitable_get_deprecated()->deprecated_function( |
| 928 |
__METHOD__, |
| 929 |
'1.5.0', |
| 930 |
'charitable_get_helper' |
| 931 |
); |
| 932 |
|
| 933 |
return $this->registry->get( 'Charitable_Request' ); |
| 934 |
} |
| 935 |
|
| 936 |
/** |
| 937 |
* Returns the instance of Charitable_Currency. |
| 938 |
* |
| 939 |
* @deprecated 1.7.0 |
| 940 |
* |
| 941 |
* @since 1.4.0 Deprecated. |
| 942 |
*/ |
| 943 |
public function get_currency_helper() { |
| 944 |
charitable_get_deprecated()->deprecated_function( __METHOD__, '1.4.0', 'charitable_get_currency_helper' ); |
| 945 |
return charitable_get_currency_helper(); |
| 946 |
} |
| 947 |
|
| 948 |
/** |
| 949 |
* Returns the instance of Charitable_Locations. |
| 950 |
* |
| 951 |
* @deprecated 1.6.0 |
| 952 |
* |
| 953 |
* @since 1.2.0 Deprecated. |
| 954 |
*/ |
| 955 |
public function get_location_helper() { |
| 956 |
charitable_get_deprecated()->deprecated_function( __METHOD__, '1.2.0', 'charitable_get_location_helper' ); |
| 957 |
return charitable_get_location_helper(); |
| 958 |
} |
| 959 |
} |
| 960 |
|
| 961 |
$charitable = new Charitable(); |
| 962 |
|
| 963 |
endif; |
| 964 |
|