PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.16.1
GiveWP – Donation Plugin and Fundraising Platform v3.16.1
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / give.php

give.php in GiveWP – Donation Plugin and Fundraising Platform 3.16.1, at give.php

608 lines 18.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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: 3.16.1
10 * Requires at least: 6.4
11 * Requires PHP: 7.2
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\ServiceProvider as DonationFormsServiceProvider;
47 use Give\DonationForms\V2\Repositories\DonationFormsRepository;
48 use Give\DonationForms\V2\ServiceProvider as DonationFormsServiceProviderV2;
49 use Give\Donations\Repositories\DonationRepository;
50 use Give\Donations\ServiceProvider as DonationServiceProvider;
51 use Give\DonationSummary\ServiceProvider as DonationSummaryServiceProvider;
52 use Give\DonorDashboards\Profile;
53 use Give\DonorDashboards\ServiceProvider as DonorDashboardsServiceProvider;
54 use Give\DonorDashboards\Tabs\TabsRegister;
55 use Give\Donors\Repositories\DonorRepositoryProxy;
56 use Give\Donors\ServiceProvider as DonorsServiceProvider;
57 use Give\Form\LegacyConsumer\ServiceProvider as FormLegacyConsumerServiceProvider;
58 use Give\Form\Templates;
59 use Give\FormBuilder\ServiceProvider as FormBuilderServiceProvider;
60 use Give\FormMigration\ServiceProvider as FormMigrationServiceProvider;
61 use Give\Framework\Database\ServiceProvider as DatabaseServiceProvider;
62 use Give\Framework\DesignSystem\DesignSystemServiceProvider;
63 use Give\Framework\Exceptions\Primitives\InvalidArgumentException;
64 use Give\Framework\Exceptions\UncaughtExceptionLogger;
65 use Give\Framework\FormDesigns\ServiceProvider as FormDesignServiceProvider;
66 use Give\Framework\Http\ServiceProvider as HttpServiceProvider;
67 use Give\Framework\Migrations\MigrationsServiceProvider;
68 use Give\Framework\PaymentGateways\PaymentGatewayRegister;
69 use Give\Framework\ValidationRules\ValidationRulesServiceProvider;
70 use Give\Framework\WordPressShims\ServiceProvider as WordPressShimsServiceProvider;
71 use Give\Helpers\Language;
72 use Give\LegacySubscriptions\ServiceProvider as LegacySubscriptionsServiceProvider;
73 use Give\License\LicenseServiceProvider;
74 use Give\Log\LogServiceProvider;
75 use Give\MigrationLog\MigrationLogServiceProvider;
76 use Give\MultiFormGoals\ServiceProvider as MultiFormGoalsServiceProvider;
77 use Give\PaymentGateways\Gateways\TestOffsiteGateway\TestOffsiteGateway;
78 use Give\PaymentGateways\ServiceProvider as PaymentGatewaysServiceProvider;
79 use Give\Promotions\ServiceProvider as PromotionsServiceProvider;
80 use Give\Revenue\RevenueServiceProvider;
81 use Give\Route\Form as FormRoute;
82 use Give\ServiceProviders\GlobalStyles as GlobalStylesServiceProvider;
83 use Give\ServiceProviders\LegacyServiceProvider;
84 use Give\ServiceProviders\Onboarding;
85 use Give\ServiceProviders\PaymentGateways;
86 use Give\ServiceProviders\RestAPI;
87 use Give\ServiceProviders\Routes;
88 use Give\ServiceProviders\ServiceProvider;
89 use Give\Subscriptions\Repositories\SubscriptionRepository;
90 use Give\Subscriptions\ServiceProvider as SubscriptionServiceProvider;
91 use Give\TestData\ServiceProvider as TestDataServiceProvider;
92 use Give\Tracking\TrackingServiceProvider;
93 use Give\VendorOverrides\FieldConditions\FieldConditionsServiceProvider;
94 use Give\VendorOverrides\Validation\ValidationServiceProvider;
95
96 // Exit if accessed directly.
97 if (!defined('ABSPATH')) {
98 exit;
99 }
100
101 /**
102 * Main Give Class
103 *
104 * @since 2.21.0 Remove php dependency validation logic and constant
105 * @since 2.19.6 add $donations, $subscriptions, and replace $donors class with DonorRepositoryProxy
106 * @since 2.8.0 build in a service container
107 * @since 1.0
108 *
109 * @property-read Give_API $api
110 * @property-read Give_Async_Process $async_process
111 * @property-read Give_Comment $comment
112 * @property-read Give_DB_Donor_Meta $donor_meta
113 * @property-read Give_Emails $emails
114 * @property-read Give_Email_Template_Tags $email_tags
115 * @property-read Give_DB_Form_Meta $form_meta
116 * @property-read Give_Admin_Settings $give_settings
117 * @property-read Give_HTML_Elements $html
118 * @property-read Give_Logging $logs
119 * @property-read Give_Notices $notices
120 * @property-read Give_DB_Payment_Meta $payment_meta
121 * @property-read Give_Roles $roles
122 * @property-read FormRoute $routeForm
123 * @property-read Templates $templates
124 * @property-read Give_Scripts $scripts
125 * @property-read Give_DB_Sequential_Ordering $sequential_donation_db
126 * @property-read Give_Sequential_Donation_Number $seq_donation_number
127 * @property-read Give_Session $session
128 * @property-read Give_DB_Sessions $session_db
129 * @property-read Give_Tooltips $tooltips
130 * @property-read PaymentGatewayRegister $gateways
131 * @property-read DonationRepository $donations
132 * @property-read DonorRepositoryProxy $donors
133 * @property-read SubscriptionRepository $subscriptions
134 * @property-read DonationFormsRepository $donationForms
135 * @property-read Profile $donorDashboard
136 * @property-read TabsRegister $donorDashboardTabs
137 * @property-read Give_Recurring_DB_Subscription_Meta $subscription_meta
138 *
139 * @mixin Container
140 */
141 final class Give
142 {
143 /**
144 * Give Template Loader Object
145 *
146 * @since 1.0
147 * @access public
148 *
149 * @var Give_Template_Loader object
150 */
151 public $template_loader;
152
153 /**
154 * Give No Login Object
155 *
156 * @since 1.0
157 * @access public
158 *
159 * @var Give_Email_Access object
160 */
161 public $email_access;
162
163 /**
164 * Give_Stripe Object.
165 *
166 * @since 2.5.0
167 * @access public
168 *
169 * @var Give_Stripe
170 */
171 public $stripe;
172
173 /**
174 * @var Give_DB_Customers
175 * @deprecated use give()->donors instead
176 */
177 public $customers;
178
179 /**
180 * @var Give_DB_Customer_Meta
181 * @deprecated use give()->donor_meta instead
182 */
183 public $customer_meta;
184
185 /**
186 * @since 2.8.0
187 *
188 * @var Container
189 */
190 private $container;
191
192 /**
193 * @since 2.25.0 added HttpServiceProvider
194 * @since 2.19.6 added Donors, Donations, and Subscriptions
195 * @since 2.8.0
196 *
197 * @var array Array of Service Providers to load
198 */
199 private $serviceProviders = [
200 LegacyServiceProvider::class,
201 RestAPI::class,
202 Routes::class,
203 PaymentGateways::class,
204 Onboarding::class,
205 MigrationsServiceProvider::class,
206 RevenueServiceProvider::class,
207 MultiFormGoalsServiceProvider::class,
208 DonorDashboardsServiceProvider::class,
209 TrackingServiceProvider::class,
210 TestDataServiceProvider::class,
211 MigrationLogServiceProvider::class,
212 LogServiceProvider::class,
213 FormLegacyConsumerServiceProvider::class,
214 LicenseServiceProvider::class,
215 Give\Email\ServiceProvider::class,
216 DonationSummaryServiceProvider::class,
217 PaymentGatewaysServiceProvider::class,
218 LegacySubscriptionsServiceProvider::class,
219 Give\Exports\ServiceProvider::class,
220 DonationServiceProvider::class,
221 DonorsServiceProvider::class,
222 SubscriptionServiceProvider::class,
223 DonationFormsServiceProviderV2::class,
224 PromotionsServiceProvider::class,
225 LegacySubscriptionsServiceProvider::class,
226 WordPressShimsServiceProvider::class,
227 DatabaseServiceProvider::class,
228 GlobalStylesServiceProvider::class,
229 ValidationServiceProvider::class,
230 ValidationRulesServiceProvider::class,
231 HttpServiceProvider::class,
232 DesignSystemServiceProvider::class,
233 FieldConditionsServiceProvider::class,
234 FormBuilderServiceProvider::class,
235 DonationFormsServiceProvider::class,
236 FormDesignServiceProvider::class,
237 FormMigrationServiceProvider::class,
238 //TODO: merge this service provider
239 Give\PaymentGateways\Gateways\ServiceProvider::class,
240 Give\EventTickets\ServiceProvider::class,
241 Give\BetaFeatures\ServiceProvider::class,
242 Give\FormTaxonomies\ServiceProvider::class,
243 Give\DonationSpam\ServiceProvider::class,
244 ];
245
246 /**
247 * @since 2.8.0
248 *
249 * @var bool Make sure the providers are loaded only once
250 */
251 private $providersLoaded = false;
252
253 /**
254 * Give constructor.
255 *
256 * Sets up the Container to be used for managing all other instances and data
257 *
258 * @since 2.8.0
259 */
260 public function __construct()
261 {
262 $this->container = new Container();
263 }
264
265 /**
266 * Init Give when WordPress Initializes.
267 *
268 * @since 1.8.9
269 */
270 public function init()
271 {
272 /**
273 * Fires before the Give core is initialized.
274 *
275 * @since 1.8.9
276 */
277 do_action('before_give_init');
278
279 // Set up localization.
280 $this->load_textdomain();
281
282 $this->bindClasses();
283
284 $this->setupExceptionHandler();
285
286 $this->loadServiceProviders();
287
288 // Load form template
289 $this->templates->load();
290
291 // Load routes.
292 $this->routeForm->init();
293
294 /**
295 * Fire the action after Give core loads.
296 *
297 * @since 1.8.7
298 *
299 * @param Give class instance.
300 *
301 */
302 do_action('give_init', $this);
303 }
304
305 /**
306 * Loads the plugin language files.
307 *
308 * @since 3.0.0 Use Language class
309 * @since 1.0
310 * @access public
311 *
312 * @return void
313 */
314 public function load_textdomain()
315 {
316 Language::load();
317 }
318
319 /**
320 * Binds the initial classes to the service provider.
321 *
322 * @since 2.8.0
323 */
324 private function bindClasses()
325 {
326 $this->container->singleton('templates', Templates::class);
327 $this->container->singleton('routeForm', FormRoute::class);
328 }
329
330 /**
331 * Sets up the Exception Handler to catch and handle uncaught exceptions
332 *
333 * @since 2.11.1
334 */
335 private function setupExceptionHandler()
336 {
337 $handler = new UncaughtExceptionLogger();
338 $handler->setupExceptionHandler();
339 }
340
341 /**
342 * Load all the service providers to bootstrap the various parts of the application.
343 *
344 * @since 2.8.0
345 */
346 private function loadServiceProviders()
347 {
348 if ($this->providersLoaded) {
349 return;
350 }
351
352 $providers = [];
353
354 foreach ($this->serviceProviders as $serviceProvider) {
355 if (!is_subclass_of($serviceProvider, ServiceProvider::class)) {
356 throw new InvalidArgumentException(
357 "$serviceProvider class must implement the ServiceProvider interface"
358 );
359 }
360
361 /** @var ServiceProvider $serviceProvider */
362 $serviceProvider = new $serviceProvider();
363
364 $serviceProvider->register();
365
366 $providers[] = $serviceProvider;
367 }
368
369 foreach ($providers as $serviceProvider) {
370 $serviceProvider->boot();
371 }
372
373 $this->providersLoaded = true;
374 }
375
376 /**
377 * Bootstraps the Give Plugin
378 *
379 * @since 2.8.0
380 */
381 public function boot()
382 {
383 $this->setup_constants();
384
385 $this->disableVisualDonationFormBuilderFeaturePlugin();
386
387 // Add compatibility notice for recurring and stripe support with Give 2.5.0.
388 add_action('admin_notices', [$this, 'display_old_recurring_compatibility_notice']);
389
390 add_action('plugins_loaded', [$this, 'init'], 0);
391
392 register_activation_hook(GIVE_PLUGIN_FILE, [$this, 'install']);
393
394 do_action('give_loaded');
395 }
396
397 /**
398 * Setup plugin constants
399 *
400 * @since 1.0
401 * @access private
402 *
403 * @return void
404 */
405 private function setup_constants()
406 {
407 // Plugin version.
408 if (!defined('GIVE_VERSION')) {
409 define('GIVE_VERSION', '3.16.1');
410 }
411
412 // Plugin Root File.
413 if (!defined('GIVE_PLUGIN_FILE')) {
414 define('GIVE_PLUGIN_FILE', __FILE__);
415 }
416
417 // Plugin Folder Path.
418 if (!defined('GIVE_PLUGIN_DIR')) {
419 define('GIVE_PLUGIN_DIR', plugin_dir_path(GIVE_PLUGIN_FILE));
420 }
421
422 // Plugin Folder URL.
423 if (!defined('GIVE_PLUGIN_URL')) {
424 define('GIVE_PLUGIN_URL', plugin_dir_url(GIVE_PLUGIN_FILE));
425 }
426
427 // Plugin Basename aka: "give/give.php".
428 if (!defined('GIVE_PLUGIN_BASENAME')) {
429 define('GIVE_PLUGIN_BASENAME', plugin_basename(GIVE_PLUGIN_FILE));
430 }
431
432 // Make sure CAL_GREGORIAN is defined.
433 if (!defined('CAL_GREGORIAN')) {
434 define('CAL_GREGORIAN', 1);
435 }
436 }
437
438 protected function disableVisualDonationFormBuilderFeaturePlugin()
439 {
440 // Include plugin.php to use is_plugin_active() below.
441 include_once ABSPATH . 'wp-admin/includes/plugin.php';
442
443 // Prevent fatal error due to a renamed class.
444 class_alias(TestOffsiteGateway::class, 'Give\PaymentGateways\Gateways\TestGateway\TestGatewayOffsite', true);
445
446 if (is_plugin_active('givewp-next-gen/give-visual-form-builder.php')) {
447 deactivate_plugins(['givewp-next-gen/give-visual-form-builder.php']);
448
449 add_action('admin_notices', function () {
450 Give()->notices->register_notice([
451 'id' => 'give-visual-donation-form-builder-feature-plugin-deactivated',
452 'description' => __(
453 'The Visual Form Builder Beta plugin is no longer needed, since the form builder is included in your current version of GiveWP. To prevent conflicts, the Beta plugin has been deactivated and can be safely deleted.',
454 'give'
455 ),
456 'type' => 'info',
457 ]);
458 });
459 }
460 }
461
462 /**
463 * Display compatibility notice for Give 2.5.0 and Recurring 1.8.13 when Stripe premium is not active.
464 *
465 * @since 2.5.0
466 *
467 * @return void
468 */
469 public function display_old_recurring_compatibility_notice()
470 {
471 // Show notice, if incompatibility found.
472 if (
473 defined('GIVE_RECURRING_VERSION')
474 && version_compare(GIVE_RECURRING_VERSION, '1.9.0', '<')
475 && defined('GIVE_STRIPE_VERSION')
476 && version_compare(GIVE_STRIPE_VERSION, '2.2.0', '<')
477 ) {
478 $message = sprintf(
479 __(
480 '<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.',
481 'give'
482 ),
483 esc_url('https://givewp.com/wp-login.php'),
484 esc_url('https://givewp.com/my-account/#tab_downloads')
485 );
486
487 Give()->notices->register_notice(
488 [
489 'id' => 'give-compatibility-with-old-recurring',
490 'description' => $message,
491 'dismissible_type' => 'user',
492 'dismiss_interval' => 'shortly',
493 ]
494 );
495 }
496 }
497
498 /**
499 * Install Give
500 *
501 * Runs on plugin activation and performs initial setup.
502 *
503 * @since 3.4.0 check if installing in WP multisite
504 * @since 2.33.3 set network_wide parameter to true, enabling installing in WP multisite
505 * @since 1.0.0
506 */
507 public function install()
508 {
509 $this->loadServiceProviders();
510 give_install(is_plugin_active_for_network(GIVE_PLUGIN_BASENAME));
511 }
512
513 /**
514 * Register a Service Provider for bootstrapping
515 *
516 * @since 2.8.0
517 *
518 * @param string $serviceProvider
519 */
520 public function registerServiceProvider($serviceProvider)
521 {
522 $this->serviceProviders[] = $serviceProvider;
523 }
524
525 /**
526 * Magic properties are passed to the service container to retrieve the data.
527 *
528 * @since 2.7.0
529 *
530 * @since 2.8.0 retrieve from the service container
531 * @param string $propertyName
532 *
533 * @return mixed
534 * @throws Exception
535 */
536 public function __get($propertyName)
537 {
538 return $this->container->get($propertyName);
539 }
540
541 /**
542 * Magic methods are passed to the service container.
543 *
544 * @since 2.8.0
545 *
546 * @param $name
547 *
548 * @param $arguments
549 *
550 * @return mixed
551 */
552 public function __call($name, $arguments)
553 {
554 return call_user_func_array([$this->container, $name], $arguments);
555 }
556
557 /**
558 * Retrieves the underlying container instance. This isn't usually necessary, but sometimes we want to pass along
559 * the container itself.
560 *
561 * @since 2.24.0
562 */
563 public function getContainer(): Container
564 {
565 return $this->container;
566 }
567 }
568
569 /**
570 * Start Give
571 *
572 * The main function responsible for returning the one true Give instance to functions everywhere.
573 *
574 * Use this function like you would a global variable, except without needing
575 * to declare the global.
576 *
577 * Example: <?php $give = Give(); ?>
578 *
579 * @since 2.8.0 add parameter for quick retrieval from container
580 * @since 1.0
581 *
582 * @template T
583 *
584 * @param class-string<T>|null $abstract Selector for data to retrieve from the service container
585 *
586 * @return Give|T
587 */
588 function give(string $abstract = null)
589 {
590 static $instance = null;
591
592 if ($instance === null) {
593 $instance = new Give();
594 }
595
596 if ($abstract !== null) {
597 return $instance->make($abstract);
598 }
599
600 return $instance;
601 }
602
603 require __DIR__ . '/vendor/autoload.php';
604 require __DIR__ . '/vendor/vendor-prefixed/autoload.php';
605 require __DIR__ . '/vendor/woocommerce/action-scheduler/action-scheduler.php';
606
607 give()->boot();
608