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