Test Failed
Push — fix/broken-phpunit-tests ( b32f1e...963e9e )
by Ravinder
07:40
created

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Plugin Name: Give - Donation Plugin
4
 * Plugin URI: https://givewp.com
5
 * Description: The most robust, flexible, and intuitive way to accept donations on WordPress.
6
 * Author: GiveWP
7
 * Author URI: https://givewp.com/
8
 * Version: 2.9.4
9
 * Text Domain: give
10
 * Domain Path: /languages
11
 *
12
 * Give is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU General Public License as published by
14
 * the Free Software Foundation, either version 3 of the License, or
15
 * any later version.
16
 *
17
 * Give is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU General Public License
23
 * along with Give. If not, see <https://www.gnu.org/licenses/>.
24
 *
25
 * A Tribute to Open Source:
26
 *
27
 * "Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by
28
 * anyone. Open source software is made by many people, and distributed under licenses that comply with the Open Source
29
 * Definition."
30
 *
31
 * -- The Open Source Initiative
32
 *
33
 * Give is a tribute to the spirit and philosophy of Open Source. We at GiveWP gladly embrace the Open Source
34
 * philosophy both in how Give itself was developed, and how we hope to see others build more from our code base.
35
 *
36
 * Give would not have been possible without the tireless efforts of WordPress and the surrounding Open Source projects
37
 * and their talented developers. Thank you all for your contribution to WordPress.
38
 *
39
 * - The GiveWP Team
40
 */
41
42
use Give\Container\Container;
43
use Give\Framework\Migrations\MigrationsServiceProvider;
44
use Give\Form\Templates;
45
use Give\Revenue\RevenueServiceProvider;
46
use Give\Route\Form as FormRoute;
47
use Give\ServiceProviders\PaymentGateways;
48
use Give\ServiceProviders\Routes;
49
use Give\ServiceProviders\LegacyServiceProvider;
50
use Give\ServiceProviders\RestAPI;
51
use Give\ServiceProviders\Onboarding;
52
use Give\MultiFormGoals\ServiceProvider as MultiFormGoalsServiceProvider;
53
use Give\ServiceProviders\ServiceProvider;
54
55
// Exit if accessed directly.
56
if ( ! defined( 'ABSPATH' ) ) {
57
	exit;
58
}
59
60
/**
61
 * Main Give Class
62
 *
63
 * @since 2.8.0 build in a service container
64
 * @since 1.0
65
 *
66
 * @property-read Give_API                        $api
67
 * @property-read Give_Async_Process              $async_process
68
 * @property-read Give_Comment                    $comment
69
 * @property-read Give_DB_Donors                  $donors
70
 * @property-read Give_DB_Donor_Meta              $donor_meta
71
 * @property-read Give_Emails                     $emails
72
 * @property-read Give_Email_Template_Tags        $email_tags
73
 * @property-read Give_DB_Form_Meta               $form_meta
74
 * @property-read Give_Admin_Settings             $give_settings
75
 * @property-read Give_HTML_Elements              $html
76
 * @property-read Give_Logging                    $logs
77
 * @property-read Give_DB_Logs                    $log_db
78
 * @property-read Give_DB_Log_Meta                $logmeta_db
79
 * @property-read Give_Notices                    $notices
80
 * @property-read Give_DB_Payment_Meta            $payment_meta
81
 * @property-read Give_Roles                      $roles
82
 * @property-read FormRoute                       $routeForm
83
 * @property-read Templates                       $templates
84
 * @property-read Give_Scripts                    $scripts
85
 * @property-read Give_DB_Sequential_Ordering     $sequential_donation_db
86
 * @property-read Give_Sequential_Donation_Number $seq_donation_number
87
 * @property-read Give_Session                    $session
88
 * @property-read Give_DB_Sessions                $session_db
89
 * @property-read Give_Tooltips                   $tooltips
90
 *
91
 * @mixin Container
92
 */
93
final class Give {
94
	/**
95
	 * Give Template Loader Object
96
	 *
97
	 * @since  1.0
98
	 * @access public
99
	 *
100
	 * @var    Give_Template_Loader object
101
	 */
102
	public $template_loader;
103
104
	/**
105
	 * Give No Login Object
106
	 *
107
	 * @since  1.0
108
	 * @access public
109
	 *
110
	 * @var    Give_Email_Access object
111
	 */
112
	public $email_access;
113
114
	/**
115
	 * Give_Stripe Object.
116
	 *
117
	 * @since  2.5.0
118
	 * @access public
119
	 *
120
	 * @var Give_Stripe
121
	 */
122
	public $stripe;
123
124
	/**
125
	 * @since 2.8.0
126
	 *
127
	 * @var Container
128
	 */
129
	private $container;
130
131
	/**
132
	 * @since 2.8.0
133
	 *
134
	 * @var array Array of Service Providers to load
135
	 */
136
	private $serviceProviders = [
137
		LegacyServiceProvider::class,
138
		RestAPI::class,
139
		Routes::class,
140
		PaymentGateways::class,
141
		Onboarding::class,
142
		MigrationsServiceProvider::class,
143
		RevenueServiceProvider::class,
144
		MultiFormGoalsServiceProvider::class,
145
	];
146
147
	/**
148
	 * @since 2.8.0
149
	 *
150
	 * @var bool Make sure the providers are loaded only once
151
	 */
152
	private $providersLoaded = false;
153
154
	/**
155
	 * Give constructor.
156
	 *
157
	 * Sets up the Container to be used for managing all other instances and data
158
	 *
159
	 * @since 2.8.0
160
	 */
161
	public function __construct() {
162
		$this->container = new Container();
163
	}
164
165
	/**
166
	 * Bootstraps the Give Plugin
167
	 *
168
	 * @since 2.8.0
169
	 */
170
	public function boot() {
171
		// PHP version
172
		if ( ! defined( 'GIVE_REQUIRED_PHP_VERSION' ) ) {
173
			define( 'GIVE_REQUIRED_PHP_VERSION', '5.6.0' );
174
		}
175
176
		// Bailout: Need minimum php version to load plugin.
177
		if ( function_exists( 'phpversion' ) && version_compare( GIVE_REQUIRED_PHP_VERSION, phpversion(), '>' ) ) {
178
			add_action( 'admin_notices', [ $this, 'minimum_phpversion_notice' ] );
179
180
			return;
181
		}
182
183
		$this->setup_constants();
184
185
		// Add compatibility notice for recurring and stripe support with Give 2.5.0.
186
		add_action( 'admin_notices', [ $this, 'display_old_recurring_compatibility_notice' ] );
187
188
		add_action( 'plugins_loaded', [ $this, 'init' ], 0 );
189
190
		register_activation_hook( GIVE_PLUGIN_FILE, [ $this, 'install' ] );
191
192
		do_action( 'give_loaded' );
193
	}
194
195
	/**
196
	 * Init Give when WordPress Initializes.
197
	 *
198
	 * @since 1.8.9
199
	 */
200
	public function init() {
201
		/**
202
		 * Fires before the Give core is initialized.
203
		 *
204
		 * @since 1.8.9
205
		 */
206
		do_action( 'before_give_init' );
207
208
		// Set up localization.
209
		$this->load_textdomain();
210
211
		$this->bindClasses();
212
213
		$this->loadServiceProviders();
214
215
		// Load form template
216
		$this->templates->load();
217
218
		// Load routes.
219
		$this->routeForm->init();
220
221
		/**
222
		 * Fire the action after Give core loads.
223
		 *
224
		 * @since 1.8.7
225
		 *
226
		 * @param Give class instance.
227
		 *
228
		 */
229
		do_action( 'give_init', $this );
230
	}
231
232
	/**
233
	 * Binds the initial classes to the service provider.
234
	 *
235
	 * @since 2.8.0
236
	 */
237
	private function bindClasses() {
238
		$this->container->singleton( 'templates', Templates::class );
239
		$this->container->singleton( 'routeForm', FormRoute::class );
240
	}
241
242
	/**
243
	 * Setup plugin constants
244
	 *
245
	 * @since  1.0
246
	 * @access private
247
	 *
248
	 * @return void
249
	 */
250
	private function setup_constants() {
251
		// Plugin version.
252
		if ( ! defined( 'GIVE_VERSION' ) ) {
253
			define( 'GIVE_VERSION', '2.9.4' );
254
		}
255
256
		// Plugin Root File.
257
		if ( ! defined( 'GIVE_PLUGIN_FILE' ) ) {
258
			define( 'GIVE_PLUGIN_FILE', __FILE__ );
259
		}
260
261
		// Plugin Folder Path.
262
		if ( ! defined( 'GIVE_PLUGIN_DIR' ) ) {
263
			define( 'GIVE_PLUGIN_DIR', plugin_dir_path( GIVE_PLUGIN_FILE ) );
264
		}
265
266
		// Plugin Folder URL.
267
		if ( ! defined( 'GIVE_PLUGIN_URL' ) ) {
268
			define( 'GIVE_PLUGIN_URL', plugin_dir_url( GIVE_PLUGIN_FILE ) );
269
		}
270
271
		// Plugin Basename aka: "give/give.php".
272
		if ( ! defined( 'GIVE_PLUGIN_BASENAME' ) ) {
273
			define( 'GIVE_PLUGIN_BASENAME', plugin_basename( GIVE_PLUGIN_FILE ) );
274
		}
275
276
		// Make sure CAL_GREGORIAN is defined.
277
		if ( ! defined( 'CAL_GREGORIAN' ) ) {
278
			define( 'CAL_GREGORIAN', 1 );
279
		}
280
	}
281
282
	/**
283
	 * Loads the plugin language files.
284
	 *
285
	 * @since  1.0
286
	 * @access public
287
	 *
288
	 * @return void
289
	 */
290
	public function load_textdomain() {
291
		// Set filter for Give's languages directory
292
		$give_lang_dir = dirname( plugin_basename( GIVE_PLUGIN_FILE ) ) . '/languages/';
293
		$give_lang_dir = apply_filters( 'give_languages_directory', $give_lang_dir );
294
295
		// Traditional WordPress plugin locale filter.
296
		$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
297
		$locale = apply_filters( 'plugin_locale', $locale, 'give' );
298
299
		unload_textdomain( 'give' );
300
		load_textdomain( 'give', WP_LANG_DIR . '/give/give-' . $locale . '.mo' );
301
		load_plugin_textdomain( 'give', false, $give_lang_dir );
302
	}
303
304
305
	/**
306
	 *  Show minimum PHP version notice.
307
	 *
308
	 * @since  1.8.12
309
	 * @access public
310
	 */
311
	public function minimum_phpversion_notice() {
312
		// Bailout.
313
		if ( ! is_admin() ) {
314
			return;
315
		}
316
317
		$notice_desc  = '<p><strong>' . __(
318
			'Your site could be faster and more secure with a newer PHP version.',
319
			'give'
320
		) . '</strong></p>';
321
		$notice_desc .= '<p>' . __(
322
			'Hey, we\'ve noticed that you\'re running an outdated version of PHP. PHP is the programming language that WordPress and GiveWP are built on. The version that is currently used for your site is no longer supported. Newer versions of PHP are both faster and more secure. In fact, your version of PHP no longer receives security updates, which is why we\'re sending you this notice.',
323
			'give'
324
		) . '</p>';
325
		$notice_desc .= '<p>' . __(
326
			'Hosts have the ability to update your PHP version, but sometimes they don\'t dare to do that because they\'re afraid they\'ll break your site.',
327
			'give'
328
		) . '</p>';
329
		$notice_desc .= '<p><strong>' . __( 'To which version should I update?', 'give' ) . '</strong></p>';
330
		$notice_desc .= '<p>' . __(
331
			'You should update your PHP version to either 5.6 or to 7.0 or 7.1. On a normal WordPress site, switching to PHP 5.6 should never cause issues. We would however actually recommend you switch to PHP7. There are some plugins that are not ready for PHP7 though, so do some testing first. PHP7 is much faster than PHP 5.6. It\'s also the only PHP version still in active development and therefore the better option for your site in the long run.',
332
			'give'
333
		) . '</p>';
334
		$notice_desc .= '<p><strong>' . __( 'Can\'t update? Ask your host!', 'give' ) . '</strong></p>';
335
		$notice_desc .= '<p>' . sprintf(
336
			__(
337
				'If you cannot upgrade your PHP version yourself, you can send an email to your host. If they don\'t want to upgrade your PHP version, we would suggest you switch hosts. Have a look at one of the recommended %1$sWordPress hosting partners%2$s.',
338
				'give'
339
			),
340
			sprintf(
341
				'<a href="%1$s" target="_blank">',
342
				esc_url( 'https://wordpress.org/hosting/' )
343
			),
344
			'</a>'
345
		) . '</p>';
346
347
		echo sprintf(
348
			'<div class="notice notice-error">%1$s</div>',
349
			wp_kses_post( $notice_desc )
350
		);
351
	}
352
353
	/**
354
	 * Display compatibility notice for Give 2.5.0 and Recurring 1.8.13 when Stripe premium is not active.
355
	 *
356
	 * @since 2.5.0
357
	 *
358
	 * @return void
359
	 */
360
	public function display_old_recurring_compatibility_notice() {
361
		// Show notice, if incompatibility found.
362
		if (
363
			defined( 'GIVE_RECURRING_VERSION' )
364
			&& version_compare( GIVE_RECURRING_VERSION, '1.9.0', '<' )
365
			&& defined( 'GIVE_STRIPE_VERSION' )
366
			&& version_compare( GIVE_STRIPE_VERSION, '2.2.0', '<' )
367
		) {
368
			$message = sprintf(
369
				__(
370
					'<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.',
371
					'give'
372
				),
373
				esc_url( 'https://givewp.com/wp-login.php' ),
374
				esc_url( 'https://givewp.com/my-account/#tab_downloads' )
375
			);
376
377
			Give()->notices->register_notice(
378
				[
379
					'id'               => 'give-compatibility-with-old-recurring',
380
					'description'      => $message,
381
					'dismissible_type' => 'user',
382
					'dismiss_interval' => 'shortly',
383
				]
384
			);
385
		}
386
	}
387
388
	public function install() {
389
		$this->loadServiceProviders();
390
		give_install();
391
	}
392
393
	/**
394
	 * Load all the service providers to bootstrap the various parts of the application.
395
	 *
396
	 * @since 2.8.0
397
	 */
398
	private function loadServiceProviders() {
399
		if ( $this->providersLoaded ) {
400
			return;
401
		}
402
403
		$providers = [];
404
405
		foreach ( $this->serviceProviders as $serviceProvider ) {
406
			if ( ! is_subclass_of( $serviceProvider, ServiceProvider::class ) ) {
407
				throw new InvalidArgumentException( "$serviceProvider class must implement the ServiceProvider interface" );
408
			}
409
410
			/** @var ServiceProvider $serviceProvider */
411
			$serviceProvider = new $serviceProvider();
412
413
			$serviceProvider->register();
414
415
			$providers[] = $serviceProvider;
416
		}
417
418
		foreach ( $providers as $serviceProvider ) {
419
			$serviceProvider->boot();
420
		}
421
422
		$this->providersLoaded = true;
423
	}
424
425
	/**
426
	 * Register a Service Provider for bootstrapping
427
	 *
428
	 * @since 2.8.0
429
	 *
430
	 * @param string $serviceProvider
431
	 */
432
	public function registerServiceProvider( $serviceProvider ) {
433
		$this->serviceProviders[] = $serviceProvider;
434
	}
435
436
	/**
437
	 * Magic properties are passed to the service container to retrieve the data.
438
	 *
439
	 * @since 2.8.0 retrieve from the service container
440
	 * @since 2.7.0
441
	 *
442
	 * @param string $propertyName
443
	 *
444
	 * @return mixed
445
	 * @throws Exception
446
	 */
447
	public function __get( $propertyName ) {
448
		return $this->container->get( $propertyName );
449
	}
450
451
	/**
452
	 * Magic methods are passed to the service container.
453
	 *
454
	 * @since 2.8.0
455
	 *
456
	 * @param $name
457
	 * @param $arguments
458
	 *
459
	 * @return mixed
460
	 */
461
	public function __call( $name, $arguments ) {
462
		return call_user_func_array( [ $this->container, $name ], $arguments );
463
	}
464
}
465
466
/**
467
 * Start Give
468
 *
469
 * The main function responsible for returning the one true Give instance to functions everywhere.
470
 *
471
 * Use this function like you would a global variable, except without needing
472
 * to declare the global.
473
 *
474
 * Example: <?php $give = Give(); ?>
475
 *
476
 * @since 2.8.0 add parameter for quick retrieval from container
477
 * @since 1.0
478
 *
479
 * @param null $abstract Selector for data to retrieve from the service container
480
 *
481
 * @return object|Give
482
 */
483
function Give( $abstract = null ) {
484
	static $instance = null;
485
486
	if ( $instance === null ) {
487
		$instance = new Give();
488
	}
489
490
	if ( $abstract !== null ) {
491
		return $instance->make( $abstract );
0 ignored issues
show
Documentation Bug introduced by
The method make does not exist on object<Give>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
492
	}
493
494
	return $instance;
495
}
496
497
require 'vendor/autoload.php';
498
499
Give()->boot();
500