| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: Give - Donation Plugin |
| 5 |
* Plugin URI: https://givewp.com |
| 6 |
* Description: The most robust, flexible, and intuitive way to accept donations on WordPress. |
| 7 |
* Author: GiveWP |
| 8 |
* Author URI: https://givewp.com/ |
| 9 |
* Version: 2.21.4 |
| 10 |
* Requires at least: 5.0 |
| 11 |
* Requires PHP: 7.0 |
| 12 |
* Text Domain: give |
| 13 |
* Domain Path: /languages |
| 14 |
* |
| 15 |
* Give is free software: you can redistribute it and/or modify |
| 16 |
* it under the terms of the GNU General Public License as published by |
| 17 |
* the Free Software Foundation, either version 3 of the License, or |
| 18 |
* any later version. |
| 19 |
* |
| 20 |
* Give is distributed in the hope that it will be useful, |
| 21 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 |
* GNU General Public License for more details. |
| 24 |
* |
| 25 |
* You should have received a copy of the GNU General Public License |
| 26 |
* along with Give. If not, see <https://www.gnu.org/licenses/>. |
| 27 |
* |
| 28 |
* A Tribute to Open Source: |
| 29 |
* |
| 30 |
* "Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by |
| 31 |
* anyone. Open source software is made by many people, and distributed under licenses that comply with the Open Source |
| 32 |
* Definition." |
| 33 |
* |
| 34 |
* -- The Open Source Initiative |
| 35 |
* |
| 36 |
* Give is a tribute to the spirit and philosophy of Open Source. We at GiveWP gladly embrace the Open Source |
| 37 |
* philosophy both in how Give itself was developed, and how we hope to see others build more from our code base. |
| 38 |
* |
| 39 |
* Give would not have been possible without the tireless efforts of WordPress and the surrounding Open Source projects |
| 40 |
* and their talented developers. Thank you all for your contribution to WordPress. |
| 41 |
* |
| 42 |
* - The GiveWP Team |
| 43 |
*/ |
| 44 |
|
| 45 |
use Give\Container\Container; |
| 46 |
use Give\DonationForms\Repositories\DonationFormsRepository; |
| 47 |
use Give\DonationForms\ServiceProvider as DonationFormsServiceProvider; |
| 48 |
use Give\Donations\Repositories\DonationRepository; |
| 49 |
use Give\Donations\ServiceProvider as DonationServiceProvider; |
| 50 |
use Give\DonationSummary\ServiceProvider as DonationSummaryServiceProvider; |
| 51 |
use Give\DonorDashboards\Profile; |
| 52 |
use Give\DonorDashboards\ServiceProvider as DonorDashboardsServiceProvider; |
| 53 |
use Give\DonorDashboards\Tabs\TabsRegister; |
| 54 |
use Give\Donors\Repositories\DonorRepositoryProxy; |
| 55 |
use Give\Donors\ServiceProvider as DonorsServiceProvider; |
| 56 |
use Give\Form\LegacyConsumer\ServiceProvider as FormLegacyConsumerServiceProvider; |
| 57 |
use Give\Form\Templates; |
| 58 |
use Give\Framework\Exceptions\UncaughtExceptionLogger; |
| 59 |
use Give\Framework\Migrations\MigrationsServiceProvider; |
| 60 |
use Give\Framework\PaymentGateways\PaymentGatewayRegister; |
| 61 |
use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider; |
| 62 |
use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider; |
| 63 |
use Give\License\LicenseServiceProvider; |
| 64 |
use Give\Log\LogServiceProvider; |
| 65 |
use Give\MigrationLog\MigrationLogServiceProvider; |
| 66 |
use Give\MultiFormGoals\ServiceProvider as MultiFormGoalsServiceProvider; |
| 67 |
use Give\PaymentGateways\ServiceProvider as PaymentGatewaysServiceProvider; |
| 68 |
use Give\Promotions\ServiceProvider as PromotionsServiceProvider; |
| 69 |
use Give\Revenue\RevenueServiceProvider; |
| 70 |
use Give\Route\Form as FormRoute; |
| 71 |
use Give\ServiceProviders\LegacyServiceProvider; |
| 72 |
use Give\ServiceProviders\Onboarding; |
| 73 |
use Give\ServiceProviders\PaymentGateways; |
| 74 |
use Give\ServiceProviders\RestAPI; |
| 75 |
use Give\ServiceProviders\Routes; |
| 76 |
use Give\ServiceProviders\ServiceProvider; |
| 77 |
use Give\Subscriptions\Repositories\SubscriptionRepository; |
| 78 |
use Give\Subscriptions\ServiceProvider as SubscriptionServiceProvider; |
| 79 |
use Give\TestData\ServiceProvider as TestDataServiceProvider; |
| 80 |
use Give\Tracking\TrackingServiceProvider; |
| 81 |
|
| 82 |
// Exit if accessed directly. |
| 83 |
if (!defined('ABSPATH')) { |
| 84 |
exit; |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Main Give Class |
| 89 |
* |
| 90 |
* @since 2.21.0 Remove php dependency validation logic and constant |
| 91 |
* @since 2.19.6 add $donations, $subscriptions, and replace $donors class with DonorRepositoryProxy |
| 92 |
* @since 2.8.0 build in a service container |
| 93 |
* @since 1.0 |
| 94 |
* |
| 95 |
* @property-read Give_API $api |
| 96 |
* @property-read Give_Async_Process $async_process |
| 97 |
* @property-read Give_Comment $comment |
| 98 |
* @property-read Give_DB_Donor_Meta $donor_meta |
| 99 |
* @property-read Give_Emails $emails |
| 100 |
* @property-read Give_Email_Template_Tags $email_tags |
| 101 |
* @property-read Give_DB_Form_Meta $form_meta |
| 102 |
* @property-read Give_Admin_Settings $give_settings |
| 103 |
* @property-read Give_HTML_Elements $html |
| 104 |
* @property-read Give_Logging $logs |
| 105 |
* @property-read Give_Notices $notices |
| 106 |
* @property-read Give_DB_Payment_Meta $payment_meta |
| 107 |
* @property-read Give_Roles $roles |
| 108 |
* @property-read FormRoute $routeForm |
| 109 |
* @property-read Templates $templates |
| 110 |
* @property-read Give_Scripts $scripts |
| 111 |
* @property-read Give_DB_Sequential_Ordering $sequential_donation_db |
| 112 |
* @property-read Give_Sequential_Donation_Number $seq_donation_number |
| 113 |
* @property-read Give_Session $session |
| 114 |
* @property-read Give_DB_Sessions $session_db |
| 115 |
* @property-read Give_Tooltips $tooltips |
| 116 |
* @property-read PaymentGatewayRegister $gateways |
| 117 |
* @property-read DonationRepository $donations |
| 118 |
* @property-read DonorRepositoryProxy $donors |
| 119 |
* @property-read SubscriptionRepository $subscriptions |
| 120 |
* @property-read DonationFormsRepository $donationFormsRepository |
| 121 |
* @property-read Profile $donorDashboard |
| 122 |
* @property-read TabsRegister $donorDashboardTabs |
| 123 |
* @property-read Give_Recurring_DB_Subscription_Meta $subscription_meta |
| 124 |
* |
| 125 |
* @mixin Container |
| 126 |
*/ |
| 127 |
final class Give |
| 128 |
{ |
| 129 |
/** |
| 130 |
* Give Template Loader Object |
| 131 |
* |
| 132 |
* @since 1.0 |
| 133 |
* @access public |
| 134 |
* |
| 135 |
* @var Give_Template_Loader object |
| 136 |
*/ |
| 137 |
public $template_loader; |
| 138 |
|
| 139 |
/** |
| 140 |
* Give No Login Object |
| 141 |
* |
| 142 |
* @since 1.0 |
| 143 |
* @access public |
| 144 |
* |
| 145 |
* @var Give_Email_Access object |
| 146 |
*/ |
| 147 |
public $email_access; |
| 148 |
|
| 149 |
/** |
| 150 |
* Give_Stripe Object. |
| 151 |
* |
| 152 |
* @since 2.5.0 |
| 153 |
* @access public |
| 154 |
* |
| 155 |
* @var Give_Stripe |
| 156 |
*/ |
| 157 |
public $stripe; |
| 158 |
|
| 159 |
/** |
| 160 |
* @since 2.8.0 |
| 161 |
* |
| 162 |
* @var Container |
| 163 |
*/ |
| 164 |
private $container; |
| 165 |
|
| 166 |
/** |
| 167 |
* @since 2.19.6 added Donors, Donations, and Subscriptions |
| 168 |
* @since 2.8.0 |
| 169 |
* |
| 170 |
* @var array Array of Service Providers to load |
| 171 |
*/ |
| 172 |
private $serviceProviders = [ |
| 173 |
LegacyServiceProvider::class, |
| 174 |
RestAPI::class, |
| 175 |
Routes::class, |
| 176 |
PaymentGateways::class, |
| 177 |
Onboarding::class, |
| 178 |
MigrationsServiceProvider::class, |
| 179 |
RevenueServiceProvider::class, |
| 180 |
MultiFormGoalsServiceProvider::class, |
| 181 |
DonorDashboardsServiceProvider::class, |
| 182 |
TrackingServiceProvider::class, |
| 183 |
TestDataServiceProvider::class, |
| 184 |
MigrationLogServiceProvider::class, |
| 185 |
LogServiceProvider::class, |
| 186 |
FormLegacyConsumerServiceProvider::class, |
| 187 |
LicenseServiceProvider::class, |
| 188 |
Give\Email\ServiceProvider::class, |
| 189 |
DonationSummaryServiceProvider::class, |
| 190 |
PaymentGatewaysServiceProvider::class, |
| 191 |
LegacySubscriptionsServiceProvider::class, |
| 192 |
Give\Exports\ServiceProvider::class, |
| 193 |
DonationServiceProvider::class, |
| 194 |
DonorsServiceProvider::class, |
| 195 |
SubscriptionServiceProvider::class, |
| 196 |
DonationFormsServiceProvider::class, |
| 197 |
PromotionsServiceProvider::class, |
| 198 |
LegacySubscriptionsServiceProvider::class, |
| 199 |
WordPressShimsServiceProvider::class, |
| 200 |
]; |
| 201 |
|
| 202 |
/** |
| 203 |
* @since 2.8.0 |
| 204 |
* |
| 205 |
* @var bool Make sure the providers are loaded only once |
| 206 |
*/ |
| 207 |
private $providersLoaded = false; |
| 208 |
|
| 209 |
/** |
| 210 |
* Give constructor. |
| 211 |
* |
| 212 |
* Sets up the Container to be used for managing all other instances and data |
| 213 |
* |
| 214 |
* @since 2.8.0 |
| 215 |
*/ |
| 216 |
public function __construct() |
| 217 |
{ |
| 218 |
$this->container = new Container(); |
| 219 |
} |
| 220 |
|
| 221 |
/** |
| 222 |
* Bootstraps the Give Plugin |
| 223 |
* |
| 224 |
* @since 2.8.0 |
| 225 |
*/ |
| 226 |
public function boot() |
| 227 |
{ |
| 228 |
$this->setup_constants(); |
| 229 |
|
| 230 |
// Add compatibility notice for recurring and stripe support with Give 2.5.0. |
| 231 |
add_action('admin_notices', [$this, 'display_old_recurring_compatibility_notice']); |
| 232 |
|
| 233 |
add_action('plugins_loaded', [$this, 'init'], 0); |
| 234 |
|
| 235 |
register_activation_hook(GIVE_PLUGIN_FILE, [$this, 'install']); |
| 236 |
|
| 237 |
do_action('give_loaded'); |
| 238 |
} |
| 239 |
|
| 240 |
/** |
| 241 |
* Init Give when WordPress Initializes. |
| 242 |
* |
| 243 |
* @since 1.8.9 |
| 244 |
*/ |
| 245 |
public function init() |
| 246 |
{ |
| 247 |
/** |
| 248 |
* Fires before the Give core is initialized. |
| 249 |
* |
| 250 |
* @since 1.8.9 |
| 251 |
*/ |
| 252 |
do_action('before_give_init'); |
| 253 |
|
| 254 |
// Set up localization. |
| 255 |
$this->load_textdomain(); |
| 256 |
|
| 257 |
$this->bindClasses(); |
| 258 |
|
| 259 |
$this->setupExceptionHandler(); |
| 260 |
|
| 261 |
$this->loadServiceProviders(); |
| 262 |
|
| 263 |
// Load form template |
| 264 |
$this->templates->load(); |
| 265 |
|
| 266 |
// Load routes. |
| 267 |
$this->routeForm->init(); |
| 268 |
|
| 269 |
/** |
| 270 |
* Fire the action after Give core loads. |
| 271 |
* |
| 272 |
* @since 1.8.7 |
| 273 |
* |
| 274 |
* @param Give class instance. |
| 275 |
* |
| 276 |
*/ |
| 277 |
do_action('give_init', $this); |
| 278 |
} |
| 279 |
|
| 280 |
/** |
| 281 |
* Binds the initial classes to the service provider. |
| 282 |
* |
| 283 |
* @since 2.8.0 |
| 284 |
*/ |
| 285 |
private function bindClasses() |
| 286 |
{ |
| 287 |
$this->container->singleton('templates', Templates::class); |
| 288 |
$this->container->singleton('routeForm', FormRoute::class); |
| 289 |
} |
| 290 |
|
| 291 |
/** |
| 292 |
* Setup plugin constants |
| 293 |
* |
| 294 |
* @since 1.0 |
| 295 |
* @access private |
| 296 |
* |
| 297 |
* @return void |
| 298 |
*/ |
| 299 |
private function setup_constants() |
| 300 |
{ |
| 301 |
// Plugin version. |
| 302 |
if (!defined('GIVE_VERSION')) { |
| 303 |
define('GIVE_VERSION', '2.21.4'); |
| 304 |
} |
| 305 |
|
| 306 |
// Plugin Root File. |
| 307 |
if (!defined('GIVE_PLUGIN_FILE')) { |
| 308 |
define('GIVE_PLUGIN_FILE', __FILE__); |
| 309 |
} |
| 310 |
|
| 311 |
// Plugin Folder Path. |
| 312 |
if (!defined('GIVE_PLUGIN_DIR')) { |
| 313 |
define('GIVE_PLUGIN_DIR', plugin_dir_path(GIVE_PLUGIN_FILE)); |
| 314 |
} |
| 315 |
|
| 316 |
// Plugin Folder URL. |
| 317 |
if (!defined('GIVE_PLUGIN_URL')) { |
| 318 |
define('GIVE_PLUGIN_URL', plugin_dir_url(GIVE_PLUGIN_FILE)); |
| 319 |
} |
| 320 |
|
| 321 |
// Plugin Basename aka: "give/give.php". |
| 322 |
if (!defined('GIVE_PLUGIN_BASENAME')) { |
| 323 |
define('GIVE_PLUGIN_BASENAME', plugin_basename(GIVE_PLUGIN_FILE)); |
| 324 |
} |
| 325 |
|
| 326 |
// Make sure CAL_GREGORIAN is defined. |
| 327 |
if (!defined('CAL_GREGORIAN')) { |
| 328 |
define('CAL_GREGORIAN', 1); |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
/** |
| 333 |
* Loads the plugin language files. |
| 334 |
* |
| 335 |
* @since 1.0 |
| 336 |
* @access public |
| 337 |
* |
| 338 |
* @return void |
| 339 |
*/ |
| 340 |
public function load_textdomain() |
| 341 |
{ |
| 342 |
// Set filter for Give's languages directory |
| 343 |
$give_lang_dir = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/'; |
| 344 |
$give_lang_dir = apply_filters('give_languages_directory', $give_lang_dir); |
| 345 |
|
| 346 |
// Traditional WordPress plugin locale filter. |
| 347 |
$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
| 348 |
$locale = apply_filters('plugin_locale', $locale, 'give'); |
| 349 |
|
| 350 |
unload_textdomain('give'); |
| 351 |
load_textdomain('give', WP_LANG_DIR . '/give/give-' . $locale . '.mo'); |
| 352 |
load_plugin_textdomain('give', false, $give_lang_dir); |
| 353 |
} |
| 354 |
|
| 355 |
/** |
| 356 |
* Display compatibility notice for Give 2.5.0 and Recurring 1.8.13 when Stripe premium is not active. |
| 357 |
* |
| 358 |
* @since 2.5.0 |
| 359 |
* |
| 360 |
* @return void |
| 361 |
*/ |
| 362 |
public function display_old_recurring_compatibility_notice() |
| 363 |
{ |
| 364 |
// Show notice, if incompatibility found. |
| 365 |
if ( |
| 366 |
defined('GIVE_RECURRING_VERSION') |
| 367 |
&& version_compare(GIVE_RECURRING_VERSION, '1.9.0', '<') |
| 368 |
&& defined('GIVE_STRIPE_VERSION') |
| 369 |
&& version_compare(GIVE_STRIPE_VERSION, '2.2.0', '<') |
| 370 |
) { |
| 371 |
$message = sprintf( |
| 372 |
__( |
| 373 |
'<strong>Attention:</strong> GiveWP 2.5.0+ requires the latest version of the Recurring Donations add-on to process payments properly with Stripe. Please update to the latest version add-on to resolve compatibility issues. If your license is active, you should see the update available in WordPress. Otherwise, you can access the latest version by <a href="%1$s" target="_blank">logging into your account</a> and visiting <a href="%1$s" target="_blank">your downloads</a> page on the GiveWP website.', |
| 374 |
'give' |
| 375 |
), |
| 376 |
esc_url('https://givewp.com/wp-login.php'), |
| 377 |
esc_url('https://givewp.com/my-account/#tab_downloads') |
| 378 |
); |
| 379 |
|
| 380 |
Give()->notices->register_notice( |
| 381 |
[ |
| 382 |
'id' => 'give-compatibility-with-old-recurring', |
| 383 |
'description' => $message, |
| 384 |
'dismissible_type' => 'user', |
| 385 |
'dismiss_interval' => 'shortly', |
| 386 |
] |
| 387 |
); |
| 388 |
} |
| 389 |
} |
| 390 |
|
| 391 |
public function install() |
| 392 |
{ |
| 393 |
$this->loadServiceProviders(); |
| 394 |
give_install(); |
| 395 |
} |
| 396 |
|
| 397 |
/** |
| 398 |
* Load all the service providers to bootstrap the various parts of the application. |
| 399 |
* |
| 400 |
* @since 2.8.0 |
| 401 |
*/ |
| 402 |
private function loadServiceProviders() |
| 403 |
{ |
| 404 |
if ($this->providersLoaded) { |
| 405 |
return; |
| 406 |
} |
| 407 |
|
| 408 |
$providers = []; |
| 409 |
|
| 410 |
foreach ($this->serviceProviders as $serviceProvider) { |
| 411 |
if (!is_subclass_of($serviceProvider, ServiceProvider::class)) { |
| 412 |
throw new InvalidArgumentException( |
| 413 |
"$serviceProvider class must implement the ServiceProvider interface" |
| 414 |
); |
| 415 |
} |
| 416 |
|
| 417 |
/** @var ServiceProvider $serviceProvider */ |
| 418 |
$serviceProvider = new $serviceProvider(); |
| 419 |
|
| 420 |
$serviceProvider->register(); |
| 421 |
|
| 422 |
$providers[] = $serviceProvider; |
| 423 |
} |
| 424 |
|
| 425 |
foreach ($providers as $serviceProvider) { |
| 426 |
$serviceProvider->boot(); |
| 427 |
} |
| 428 |
|
| 429 |
$this->providersLoaded = true; |
| 430 |
} |
| 431 |
|
| 432 |
/** |
| 433 |
* Register a Service Provider for bootstrapping |
| 434 |
* |
| 435 |
* @since 2.8.0 |
| 436 |
* |
| 437 |
* @param string $serviceProvider |
| 438 |
*/ |
| 439 |
public function registerServiceProvider($serviceProvider) |
| 440 |
{ |
| 441 |
$this->serviceProviders[] = $serviceProvider; |
| 442 |
} |
| 443 |
|
| 444 |
/** |
| 445 |
* Magic properties are passed to the service container to retrieve the data. |
| 446 |
* |
| 447 |
* @since 2.8.0 retrieve from the service container |
| 448 |
* @since 2.7.0 |
| 449 |
* |
| 450 |
* @param string $propertyName |
| 451 |
* |
| 452 |
* @return mixed |
| 453 |
* @throws Exception |
| 454 |
*/ |
| 455 |
public function __get($propertyName) |
| 456 |
{ |
| 457 |
return $this->container->get($propertyName); |
| 458 |
} |
| 459 |
|
| 460 |
/** |
| 461 |
* Magic methods are passed to the service container. |
| 462 |
* |
| 463 |
* @since 2.8.0 |
| 464 |
* |
| 465 |
* @param $arguments |
| 466 |
* |
| 467 |
* @param $name |
| 468 |
* |
| 469 |
* @return mixed |
| 470 |
*/ |
| 471 |
public function __call($name, $arguments) |
| 472 |
{ |
| 473 |
return call_user_func_array([$this->container, $name], $arguments); |
| 474 |
} |
| 475 |
|
| 476 |
/** |
| 477 |
* Sets up the Exception Handler to catch and handle uncaught exceptions |
| 478 |
* |
| 479 |
* @since 2.11.1 |
| 480 |
*/ |
| 481 |
private function setupExceptionHandler() |
| 482 |
{ |
| 483 |
$handler = new UncaughtExceptionLogger(); |
| 484 |
$handler->setupExceptionHandler(); |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
/** |
| 489 |
* Start Give |
| 490 |
* |
| 491 |
* The main function responsible for returning the one true Give instance to functions everywhere. |
| 492 |
* |
| 493 |
* Use this function like you would a global variable, except without needing |
| 494 |
* to declare the global. |
| 495 |
* |
| 496 |
* Example: <?php $give = Give(); ?> |
| 497 |
* |
| 498 |
* @since 2.8.0 add parameter for quick retrieval from container |
| 499 |
* @since 1.0 |
| 500 |
* |
| 501 |
* @param null $abstract Selector for data to retrieve from the service container |
| 502 |
* |
| 503 |
* @return object|Give |
| 504 |
*/ |
| 505 |
function give($abstract = null) |
| 506 |
{ |
| 507 |
static $instance = null; |
| 508 |
|
| 509 |
if ($instance === null) { |
| 510 |
$instance = new Give(); |
| 511 |
} |
| 512 |
|
| 513 |
if ($abstract !== null) { |
| 514 |
return $instance->make($abstract); |
| 515 |
} |
| 516 |
|
| 517 |
return $instance; |
| 518 |
} |
| 519 |
|
| 520 |
require __DIR__ . '/vendor/autoload.php'; |
| 521 |
|
| 522 |
give()->boot(); |
| 523 |
|