give
Last commit date
.phpstan
3 years ago
assets
3 years ago
blocks
3 years ago
includes
3 years ago
languages
3 years ago
sample-data
6 years ago
src
3 years ago
templates
3 years ago
vendor
3 years ago
.phpstorm.meta.php
4 years ago
changelog.txt
5 years ago
give.php
3 years ago
license.txt
6 years ago
phpstan.neon
3 years ago
readme.txt
3 years ago
uninstall.php
3 years ago
wpml-config.xml
6 years ago
give.php
525 lines
| 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.23.2 |
| 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\Database\ServiceProvider as DatabaseServiceProvider; |
| 61 | use Give\Framework\PaymentGateways\PaymentGatewayRegister; |
| 62 | use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider; |
| 63 | use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider; |
| 64 | use Give\License\LicenseServiceProvider; |
| 65 | use Give\Log\LogServiceProvider; |
| 66 | use Give\MigrationLog\MigrationLogServiceProvider; |
| 67 | use Give\MultiFormGoals\ServiceProvider as MultiFormGoalsServiceProvider; |
| 68 | use Give\PaymentGateways\ServiceProvider as PaymentGatewaysServiceProvider; |
| 69 | use Give\Promotions\ServiceProvider as PromotionsServiceProvider; |
| 70 | use Give\Revenue\RevenueServiceProvider; |
| 71 | use Give\Route\Form as FormRoute; |
| 72 | use Give\ServiceProviders\LegacyServiceProvider; |
| 73 | use Give\ServiceProviders\Onboarding; |
| 74 | use Give\ServiceProviders\PaymentGateways; |
| 75 | use Give\ServiceProviders\RestAPI; |
| 76 | use Give\ServiceProviders\Routes; |
| 77 | use Give\ServiceProviders\ServiceProvider; |
| 78 | use Give\Subscriptions\Repositories\SubscriptionRepository; |
| 79 | use Give\Subscriptions\ServiceProvider as SubscriptionServiceProvider; |
| 80 | use Give\TestData\ServiceProvider as TestDataServiceProvider; |
| 81 | use Give\Tracking\TrackingServiceProvider; |
| 82 | |
| 83 | // Exit if accessed directly. |
| 84 | if (!defined('ABSPATH')) { |
| 85 | exit; |
| 86 | } |
| 87 | |
| 88 | /** |
| 89 | * Main Give Class |
| 90 | * |
| 91 | * @since 2.21.0 Remove php dependency validation logic and constant |
| 92 | * @since 2.19.6 add $donations, $subscriptions, and replace $donors class with DonorRepositoryProxy |
| 93 | * @since 2.8.0 build in a service container |
| 94 | * @since 1.0 |
| 95 | * |
| 96 | * @property-read Give_API $api |
| 97 | * @property-read Give_Async_Process $async_process |
| 98 | * @property-read Give_Comment $comment |
| 99 | * @property-read Give_DB_Donor_Meta $donor_meta |
| 100 | * @property-read Give_Emails $emails |
| 101 | * @property-read Give_Email_Template_Tags $email_tags |
| 102 | * @property-read Give_DB_Form_Meta $form_meta |
| 103 | * @property-read Give_Admin_Settings $give_settings |
| 104 | * @property-read Give_HTML_Elements $html |
| 105 | * @property-read Give_Logging $logs |
| 106 | * @property-read Give_Notices $notices |
| 107 | * @property-read Give_DB_Payment_Meta $payment_meta |
| 108 | * @property-read Give_Roles $roles |
| 109 | * @property-read FormRoute $routeForm |
| 110 | * @property-read Templates $templates |
| 111 | * @property-read Give_Scripts $scripts |
| 112 | * @property-read Give_DB_Sequential_Ordering $sequential_donation_db |
| 113 | * @property-read Give_Sequential_Donation_Number $seq_donation_number |
| 114 | * @property-read Give_Session $session |
| 115 | * @property-read Give_DB_Sessions $session_db |
| 116 | * @property-read Give_Tooltips $tooltips |
| 117 | * @property-read PaymentGatewayRegister $gateways |
| 118 | * @property-read DonationRepository $donations |
| 119 | * @property-read DonorRepositoryProxy $donors |
| 120 | * @property-read SubscriptionRepository $subscriptions |
| 121 | * @property-read DonationFormsRepository $donationFormsRepository |
| 122 | * @property-read Profile $donorDashboard |
| 123 | * @property-read TabsRegister $donorDashboardTabs |
| 124 | * @property-read Give_Recurring_DB_Subscription_Meta $subscription_meta |
| 125 | * |
| 126 | * @mixin Container |
| 127 | */ |
| 128 | final class Give |
| 129 | { |
| 130 | /** |
| 131 | * Give Template Loader Object |
| 132 | * |
| 133 | * @since 1.0 |
| 134 | * @access public |
| 135 | * |
| 136 | * @var Give_Template_Loader object |
| 137 | */ |
| 138 | public $template_loader; |
| 139 | |
| 140 | /** |
| 141 | * Give No Login Object |
| 142 | * |
| 143 | * @since 1.0 |
| 144 | * @access public |
| 145 | * |
| 146 | * @var Give_Email_Access object |
| 147 | */ |
| 148 | public $email_access; |
| 149 | |
| 150 | /** |
| 151 | * Give_Stripe Object. |
| 152 | * |
| 153 | * @since 2.5.0 |
| 154 | * @access public |
| 155 | * |
| 156 | * @var Give_Stripe |
| 157 | */ |
| 158 | public $stripe; |
| 159 | |
| 160 | /** |
| 161 | * @since 2.8.0 |
| 162 | * |
| 163 | * @var Container |
| 164 | */ |
| 165 | private $container; |
| 166 | |
| 167 | /** |
| 168 | * @since 2.19.6 added Donors, Donations, and Subscriptions |
| 169 | * @since 2.8.0 |
| 170 | * |
| 171 | * @var array Array of Service Providers to load |
| 172 | */ |
| 173 | private $serviceProviders = [ |
| 174 | LegacyServiceProvider::class, |
| 175 | RestAPI::class, |
| 176 | Routes::class, |
| 177 | PaymentGateways::class, |
| 178 | Onboarding::class, |
| 179 | MigrationsServiceProvider::class, |
| 180 | RevenueServiceProvider::class, |
| 181 | MultiFormGoalsServiceProvider::class, |
| 182 | DonorDashboardsServiceProvider::class, |
| 183 | TrackingServiceProvider::class, |
| 184 | TestDataServiceProvider::class, |
| 185 | MigrationLogServiceProvider::class, |
| 186 | LogServiceProvider::class, |
| 187 | FormLegacyConsumerServiceProvider::class, |
| 188 | LicenseServiceProvider::class, |
| 189 | Give\Email\ServiceProvider::class, |
| 190 | DonationSummaryServiceProvider::class, |
| 191 | PaymentGatewaysServiceProvider::class, |
| 192 | LegacySubscriptionsServiceProvider::class, |
| 193 | Give\Exports\ServiceProvider::class, |
| 194 | DonationServiceProvider::class, |
| 195 | DonorsServiceProvider::class, |
| 196 | SubscriptionServiceProvider::class, |
| 197 | DonationFormsServiceProvider::class, |
| 198 | PromotionsServiceProvider::class, |
| 199 | LegacySubscriptionsServiceProvider::class, |
| 200 | WordPressShimsServiceProvider::class, |
| 201 | DatabaseServiceProvider::class, |
| 202 | ]; |
| 203 | |
| 204 | /** |
| 205 | * @since 2.8.0 |
| 206 | * |
| 207 | * @var bool Make sure the providers are loaded only once |
| 208 | */ |
| 209 | private $providersLoaded = false; |
| 210 | |
| 211 | /** |
| 212 | * Give constructor. |
| 213 | * |
| 214 | * Sets up the Container to be used for managing all other instances and data |
| 215 | * |
| 216 | * @since 2.8.0 |
| 217 | */ |
| 218 | public function __construct() |
| 219 | { |
| 220 | $this->container = new Container(); |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Bootstraps the Give Plugin |
| 225 | * |
| 226 | * @since 2.8.0 |
| 227 | */ |
| 228 | public function boot() |
| 229 | { |
| 230 | $this->setup_constants(); |
| 231 | |
| 232 | // Add compatibility notice for recurring and stripe support with Give 2.5.0. |
| 233 | add_action('admin_notices', [$this, 'display_old_recurring_compatibility_notice']); |
| 234 | |
| 235 | add_action('plugins_loaded', [$this, 'init'], 0); |
| 236 | |
| 237 | register_activation_hook(GIVE_PLUGIN_FILE, [$this, 'install']); |
| 238 | |
| 239 | do_action('give_loaded'); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Init Give when WordPress Initializes. |
| 244 | * |
| 245 | * @since 1.8.9 |
| 246 | */ |
| 247 | public function init() |
| 248 | { |
| 249 | /** |
| 250 | * Fires before the Give core is initialized. |
| 251 | * |
| 252 | * @since 1.8.9 |
| 253 | */ |
| 254 | do_action('before_give_init'); |
| 255 | |
| 256 | // Set up localization. |
| 257 | $this->load_textdomain(); |
| 258 | |
| 259 | $this->bindClasses(); |
| 260 | |
| 261 | $this->setupExceptionHandler(); |
| 262 | |
| 263 | $this->loadServiceProviders(); |
| 264 | |
| 265 | // Load form template |
| 266 | $this->templates->load(); |
| 267 | |
| 268 | // Load routes. |
| 269 | $this->routeForm->init(); |
| 270 | |
| 271 | /** |
| 272 | * Fire the action after Give core loads. |
| 273 | * |
| 274 | * @since 1.8.7 |
| 275 | * |
| 276 | * @param Give class instance. |
| 277 | * |
| 278 | */ |
| 279 | do_action('give_init', $this); |
| 280 | } |
| 281 | |
| 282 | /** |
| 283 | * Binds the initial classes to the service provider. |
| 284 | * |
| 285 | * @since 2.8.0 |
| 286 | */ |
| 287 | private function bindClasses() |
| 288 | { |
| 289 | $this->container->singleton('templates', Templates::class); |
| 290 | $this->container->singleton('routeForm', FormRoute::class); |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Setup plugin constants |
| 295 | * |
| 296 | * @since 1.0 |
| 297 | * @access private |
| 298 | * |
| 299 | * @return void |
| 300 | */ |
| 301 | private function setup_constants() |
| 302 | { |
| 303 | // Plugin version. |
| 304 | if (!defined('GIVE_VERSION')) { |
| 305 | define('GIVE_VERSION', '2.23.2'); |
| 306 | } |
| 307 | |
| 308 | // Plugin Root File. |
| 309 | if (!defined('GIVE_PLUGIN_FILE')) { |
| 310 | define('GIVE_PLUGIN_FILE', __FILE__); |
| 311 | } |
| 312 | |
| 313 | // Plugin Folder Path. |
| 314 | if (!defined('GIVE_PLUGIN_DIR')) { |
| 315 | define('GIVE_PLUGIN_DIR', plugin_dir_path(GIVE_PLUGIN_FILE)); |
| 316 | } |
| 317 | |
| 318 | // Plugin Folder URL. |
| 319 | if (!defined('GIVE_PLUGIN_URL')) { |
| 320 | define('GIVE_PLUGIN_URL', plugin_dir_url(GIVE_PLUGIN_FILE)); |
| 321 | } |
| 322 | |
| 323 | // Plugin Basename aka: "give/give.php". |
| 324 | if (!defined('GIVE_PLUGIN_BASENAME')) { |
| 325 | define('GIVE_PLUGIN_BASENAME', plugin_basename(GIVE_PLUGIN_FILE)); |
| 326 | } |
| 327 | |
| 328 | // Make sure CAL_GREGORIAN is defined. |
| 329 | if (!defined('CAL_GREGORIAN')) { |
| 330 | define('CAL_GREGORIAN', 1); |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Loads the plugin language files. |
| 336 | * |
| 337 | * @since 1.0 |
| 338 | * @access public |
| 339 | * |
| 340 | * @return void |
| 341 | */ |
| 342 | public function load_textdomain() |
| 343 | { |
| 344 | // Set filter for Give's languages directory |
| 345 | $give_lang_dir = dirname(plugin_basename(GIVE_PLUGIN_FILE)) . '/languages/'; |
| 346 | $give_lang_dir = apply_filters('give_languages_directory', $give_lang_dir); |
| 347 | |
| 348 | // Traditional WordPress plugin locale filter. |
| 349 | $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
| 350 | $locale = apply_filters('plugin_locale', $locale, 'give'); |
| 351 | |
| 352 | unload_textdomain('give'); |
| 353 | load_textdomain('give', WP_LANG_DIR . '/give/give-' . $locale . '.mo'); |
| 354 | load_plugin_textdomain('give', false, $give_lang_dir); |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * Display compatibility notice for Give 2.5.0 and Recurring 1.8.13 when Stripe premium is not active. |
| 359 | * |
| 360 | * @since 2.5.0 |
| 361 | * |
| 362 | * @return void |
| 363 | */ |
| 364 | public function display_old_recurring_compatibility_notice() |
| 365 | { |
| 366 | // Show notice, if incompatibility found. |
| 367 | if ( |
| 368 | defined('GIVE_RECURRING_VERSION') |
| 369 | && version_compare(GIVE_RECURRING_VERSION, '1.9.0', '<') |
| 370 | && defined('GIVE_STRIPE_VERSION') |
| 371 | && version_compare(GIVE_STRIPE_VERSION, '2.2.0', '<') |
| 372 | ) { |
| 373 | $message = sprintf( |
| 374 | __( |
| 375 | '<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.', |
| 376 | 'give' |
| 377 | ), |
| 378 | esc_url('https://givewp.com/wp-login.php'), |
| 379 | esc_url('https://givewp.com/my-account/#tab_downloads') |
| 380 | ); |
| 381 | |
| 382 | Give()->notices->register_notice( |
| 383 | [ |
| 384 | 'id' => 'give-compatibility-with-old-recurring', |
| 385 | 'description' => $message, |
| 386 | 'dismissible_type' => 'user', |
| 387 | 'dismiss_interval' => 'shortly', |
| 388 | ] |
| 389 | ); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | public function install() |
| 394 | { |
| 395 | $this->loadServiceProviders(); |
| 396 | give_install(); |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Load all the service providers to bootstrap the various parts of the application. |
| 401 | * |
| 402 | * @since 2.8.0 |
| 403 | */ |
| 404 | private function loadServiceProviders() |
| 405 | { |
| 406 | if ($this->providersLoaded) { |
| 407 | return; |
| 408 | } |
| 409 | |
| 410 | $providers = []; |
| 411 | |
| 412 | foreach ($this->serviceProviders as $serviceProvider) { |
| 413 | if (!is_subclass_of($serviceProvider, ServiceProvider::class)) { |
| 414 | throw new InvalidArgumentException( |
| 415 | "$serviceProvider class must implement the ServiceProvider interface" |
| 416 | ); |
| 417 | } |
| 418 | |
| 419 | /** @var ServiceProvider $serviceProvider */ |
| 420 | $serviceProvider = new $serviceProvider(); |
| 421 | |
| 422 | $serviceProvider->register(); |
| 423 | |
| 424 | $providers[] = $serviceProvider; |
| 425 | } |
| 426 | |
| 427 | foreach ($providers as $serviceProvider) { |
| 428 | $serviceProvider->boot(); |
| 429 | } |
| 430 | |
| 431 | $this->providersLoaded = true; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Register a Service Provider for bootstrapping |
| 436 | * |
| 437 | * @since 2.8.0 |
| 438 | * |
| 439 | * @param string $serviceProvider |
| 440 | */ |
| 441 | public function registerServiceProvider($serviceProvider) |
| 442 | { |
| 443 | $this->serviceProviders[] = $serviceProvider; |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Magic properties are passed to the service container to retrieve the data. |
| 448 | * |
| 449 | * @since 2.8.0 retrieve from the service container |
| 450 | * @since 2.7.0 |
| 451 | * |
| 452 | * @param string $propertyName |
| 453 | * |
| 454 | * @return mixed |
| 455 | * @throws Exception |
| 456 | */ |
| 457 | public function __get($propertyName) |
| 458 | { |
| 459 | return $this->container->get($propertyName); |
| 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Magic methods are passed to the service container. |
| 464 | * |
| 465 | * @since 2.8.0 |
| 466 | * |
| 467 | * @param $arguments |
| 468 | * |
| 469 | * @param $name |
| 470 | * |
| 471 | * @return mixed |
| 472 | */ |
| 473 | public function __call($name, $arguments) |
| 474 | { |
| 475 | return call_user_func_array([$this->container, $name], $arguments); |
| 476 | } |
| 477 | |
| 478 | /** |
| 479 | * Sets up the Exception Handler to catch and handle uncaught exceptions |
| 480 | * |
| 481 | * @since 2.11.1 |
| 482 | */ |
| 483 | private function setupExceptionHandler() |
| 484 | { |
| 485 | $handler = new UncaughtExceptionLogger(); |
| 486 | $handler->setupExceptionHandler(); |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | /** |
| 491 | * Start Give |
| 492 | * |
| 493 | * The main function responsible for returning the one true Give instance to functions everywhere. |
| 494 | * |
| 495 | * Use this function like you would a global variable, except without needing |
| 496 | * to declare the global. |
| 497 | * |
| 498 | * Example: <?php $give = Give(); ?> |
| 499 | * |
| 500 | * @since 2.8.0 add parameter for quick retrieval from container |
| 501 | * @since 1.0 |
| 502 | * |
| 503 | * @param null $abstract Selector for data to retrieve from the service container |
| 504 | * |
| 505 | * @return object|Give |
| 506 | */ |
| 507 | function give($abstract = null) |
| 508 | { |
| 509 | static $instance = null; |
| 510 | |
| 511 | if ($instance === null) { |
| 512 | $instance = new Give(); |
| 513 | } |
| 514 | |
| 515 | if ($abstract !== null) { |
| 516 | return $instance->make($abstract); |
| 517 | } |
| 518 | |
| 519 | return $instance; |
| 520 | } |
| 521 | |
| 522 | require __DIR__ . '/vendor/autoload.php'; |
| 523 | |
| 524 | give()->boot(); |
| 525 |