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