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