PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.8.1
GiveWP – Donation Plugin and Fundraising Platform v4.16.8.1
4.16.8.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 All 254 releases
give / give.php

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

629 lines 20.2 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.16.8.1
10 * Requires at least: 6.6
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 Give\ThirdPartyCompatibility\ServiceProvider::class,
254 Give\API\REST\V3\Routes\ServiceProvider::class,
255 Give\Framework\PaymentGateways\ServiceProvider::class,
256 Give\ThirdPartySupport\Elementor\ServiceProvider::class,
257 Give\MCP\ServiceProvider::class,
258 Give\VendorOverrides\Harbor\HarborServiceProvider::class,
259 ];
260
261 /**
262 * @since 2.8.0
263 *
264 * @var bool Make sure the providers are loaded only once
265 */
266 private $providersLoaded = false;
267
268 /**
269 * Give constructor.
270 *
271 * Sets up the Container to be used for managing all other instances and data
272 *
273 * @since 2.8.0
274 */
275 public function __construct()
276 {
277 $this->container = new Container();
278 }
279
280 /**
281 * Init Give when WordPress Initializes.
282 *
283 * @since 3.19.0 Move the loading of the `give` textdomain to the `init` action hook.
284 * @since 1.8.9
285 */
286 public function init()
287 {
288 /**
289 * Fires before the Give core is initialized.
290 *
291 * @since 1.8.9
292 */
293 do_action('before_give_init');
294
295 $this->bindClasses();
296
297 $this->setupExceptionHandler();
298
299 $this->loadServiceProviders();
300
301 // Load form template
302 $this->templates->load();
303
304 // Load routes.
305 $this->routeForm->init();
306
307 /**
308 * Fire the action after Give core loads.
309 *
310 * @since 1.8.7
311 *
312 * @param Give class instance.
313 *
314 */
315 do_action('give_init', $this);
316
317 // Activate any bundled licenses if not already activated.
318 add_action('admin_init', 'Give_License::activate_bundled_licenses');
319 }
320
321 /**
322 * Loads the plugin language files.
323 *
324 * @since 3.0.0 Use Language class
325 * @since 1.0
326 * @access public
327 *
328 * @return void
329 */
330 public function load_textdomain()
331 {
332 Language::load();
333 }
334
335 /**
336 * Binds the initial classes to the service provider.
337 *
338 * @since 2.8.0
339 */
340 private function bindClasses()
341 {
342 $this->container->singleton('templates', Templates::class);
343 $this->container->singleton('routeForm', FormRoute::class);
344 }
345
346 /**
347 * Sets up the Exception Handler to catch and handle uncaught exceptions
348 *
349 * @since 2.11.1
350 */
351 private function setupExceptionHandler()
352 {
353 $handler = new UncaughtExceptionLogger();
354 $handler->setupExceptionHandler();
355 }
356
357 /**
358 * Load all the service providers to bootstrap the various parts of the application.
359 *
360 * @since 2.8.0
361 */
362 private function loadServiceProviders()
363 {
364 if ($this->providersLoaded) {
365 return;
366 }
367
368 $providers = [];
369
370 foreach ($this->serviceProviders as $serviceProvider) {
371 if (!is_subclass_of($serviceProvider, ServiceProvider::class)) {
372 throw new InvalidArgumentException(
373 "$serviceProvider class must implement the ServiceProvider interface"
374 );
375 }
376
377 /** @var ServiceProvider $serviceProvider */
378 $serviceProvider = new $serviceProvider();
379
380 $serviceProvider->register();
381
382 $providers[] = $serviceProvider;
383 }
384
385 foreach ($providers as $serviceProvider) {
386 $serviceProvider->boot();
387 }
388
389 $this->providersLoaded = true;
390 }
391
392 /**
393 * Bootstraps the Give Plugin
394 *
395 * @since 3.19.0 Load the `give` textdomain on the `init` action hook.
396 * @since 2.8.0
397 */
398 public function boot()
399 {
400 $this->setup_constants();
401
402 $this->disableVisualDonationFormBuilderFeaturePlugin();
403
404 // Add compatibility notice for recurring and stripe support with Give 2.5.0.
405 add_action('admin_notices', [$this, 'display_old_recurring_compatibility_notice']);
406
407 add_action('plugins_loaded', [$this, 'init'], 0);
408
409 // Set up localization.
410 add_action('init', [$this, 'load_textdomain']);
411
412 register_activation_hook(GIVE_PLUGIN_FILE, [$this, 'install']);
413
414 do_action('give_loaded');
415 }
416
417 /**
418 * Setup plugin constants
419 *
420 * @since 1.0
421 * @access private
422 *
423 * @return void
424 */
425 private function setup_constants()
426 {
427 // Plugin version.
428 if (!defined('GIVE_VERSION')) {
429 define('GIVE_VERSION', '4.16.8.1');
430 }
431
432 // Plugin Root File.
433 if (!defined('GIVE_PLUGIN_FILE')) {
434 define('GIVE_PLUGIN_FILE', __FILE__);
435 }
436
437 // Plugin Folder Path.
438 if (!defined('GIVE_PLUGIN_DIR')) {
439 define('GIVE_PLUGIN_DIR', plugin_dir_path(GIVE_PLUGIN_FILE));
440 }
441
442 // Plugin Folder URL.
443 if (!defined('GIVE_PLUGIN_URL')) {
444 define('GIVE_PLUGIN_URL', plugin_dir_url(GIVE_PLUGIN_FILE));
445 }
446
447 // Plugin Basename aka: "give/give.php".
448 if (!defined('GIVE_PLUGIN_BASENAME')) {
449 define('GIVE_PLUGIN_BASENAME', plugin_basename(GIVE_PLUGIN_FILE));
450 }
451
452 // Make sure CAL_GREGORIAN is defined.
453 if (!defined('CAL_GREGORIAN')) {
454 define('CAL_GREGORIAN', 1);
455 }
456 }
457
458 protected function disableVisualDonationFormBuilderFeaturePlugin()
459 {
460 // Include plugin.php to use is_plugin_active() below.
461 include_once ABSPATH . 'wp-admin/includes/plugin.php';
462
463 // Prevent fatal error due to a renamed class.
464 class_alias(TestOffsiteGateway::class, 'Give\PaymentGateways\Gateways\TestGateway\TestGatewayOffsite', true);
465
466 if (is_plugin_active('givewp-next-gen/give-visual-form-builder.php')) {
467 deactivate_plugins(['givewp-next-gen/give-visual-form-builder.php']);
468
469 add_action('admin_notices', function () {
470 Give()->notices->register_notice([
471 'id' => 'give-visual-donation-form-builder-feature-plugin-deactivated',
472 'description' => __(
473 '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.',
474 'give'
475 ),
476 'type' => 'info',
477 ]);
478 });
479 }
480 }
481
482 /**
483 * Display compatibility notice for Give 2.5.0 and Recurring 1.8.13 when Stripe premium is not active.
484 *
485 * @since 2.5.0
486 *
487 * @return void
488 */
489 public function display_old_recurring_compatibility_notice()
490 {
491 // Show notice, if incompatibility found.
492 if (
493 defined('GIVE_RECURRING_VERSION')
494 && version_compare(GIVE_RECURRING_VERSION, '1.9.0', '<')
495 && defined('GIVE_STRIPE_VERSION')
496 && version_compare(GIVE_STRIPE_VERSION, '2.2.0', '<')
497 ) {
498 $message = sprintf(
499 __(
500 '<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.',
501 'give'
502 ),
503 esc_url('https://givewp.com/wp-login.php'),
504 esc_url('https://givewp.com/my-account/#tab_downloads')
505 );
506
507 Give()->notices->register_notice(
508 [
509 'id' => 'give-compatibility-with-old-recurring',
510 'description' => $message,
511 'dismissible_type' => 'user',
512 'dismiss_interval' => 'shortly',
513 ]
514 );
515 }
516 }
517
518 /**
519 * Install Give
520 *
521 * Runs on plugin activation and performs initial setup.
522 *
523 * @since 3.4.0 check if installing in WP multisite
524 * @since 2.33.3 set network_wide parameter to true, enabling installing in WP multisite
525 * @since 1.0.0
526 */
527 public function install()
528 {
529 $this->loadServiceProviders();
530 give_install(is_plugin_active_for_network(GIVE_PLUGIN_BASENAME));
531 }
532
533 /**
534 * Register a Service Provider for bootstrapping
535 *
536 * @since 2.8.0
537 *
538 * @param string $serviceProvider
539 */
540 public function registerServiceProvider($serviceProvider)
541 {
542 $this->serviceProviders[] = $serviceProvider;
543 }
544
545 /**
546 * Magic properties are passed to the service container to retrieve the data.
547 *
548 * @since 2.7.0
549 *
550 * @since 2.8.0 retrieve from the service container
551 * @param string $propertyName
552 *
553 * @return mixed
554 * @throws Exception
555 */
556 public function __get($propertyName)
557 {
558 return $this->container->get($propertyName);
559 }
560
561 /**
562 * Magic methods are passed to the service container.
563 *
564 * @since 2.8.0
565 *
566 * @param $name
567 *
568 * @param $arguments
569 *
570 * @return mixed
571 */
572 public function __call($name, $arguments)
573 {
574 return call_user_func_array([$this->container, $name], $arguments);
575 }
576
577 /**
578 * Retrieves the underlying container instance. This isn't usually necessary, but sometimes we want to pass along
579 * the container itself.
580 *
581 * @since 2.24.0
582 */
583 public function getContainer(): Container
584 {
585 return $this->container;
586 }
587 }
588
589 /**
590 * Start Give
591 *
592 * The main function responsible for returning the one true Give instance to functions everywhere.
593 *
594 * Use this function like you would a global variable, except without needing
595 * to declare the global.
596 *
597 * Example: <?php $give = Give(); ?>
598 *
599 * @since 4.6.0 add explicit nullable type to give function
600 * @since 2.8.0 add parameter for quick retrieval from container
601 * @since 1.0
602 *
603 * @template T
604 *
605 * @param class-string<T>|null $abstract Selector for data to retrieve from the service container
606 *
607 * @return Give|T
608 */
609 function give(?string $abstract = null)
610 {
611 static $instance = null;
612
613 if ($instance === null) {
614 $instance = new Give();
615 }
616
617 if ($abstract !== null) {
618 return $instance->make($abstract);
619 }
620
621 return $instance;
622 }
623
624 require __DIR__ . '/vendor/autoload.php';
625 require __DIR__ . '/vendor/vendor-prefixed/autoload.php';
626 require __DIR__ . '/vendor/woocommerce/action-scheduler/action-scheduler.php';
627
628 give()->boot();
629