Completed
Push — issues/1781 ( da0482 )
by Ravinder
19:23
created

Give::instance()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 54 and the first side effect is on line 44.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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: WordImpress
7
 * Author URI: https://wordimpress.com
8
 * Version: 1.8.9
9
 * Text Domain: give
10
 * Domain Path: /languages
11
 * GitHub Plugin URI: https://github.com/WordImpress/Give
12
 *
13
 * Give is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation, either version 3 of the License, or
16
 * any later version.
17
 *
18
 * Give is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with Give. If not, see <https://www.gnu.org/licenses/>.
25
 *
26
 * A Tribute to Open Source:
27
 *
28
 * "Open source software is software that can be freely used, changed, and shared (in modified or unmodified form) by anyone. Open
29
 * source software is made by many people, and distributed under licenses that comply with the Open Source Definition."
30
 *
31
 * -- The Open Source Initiative
32
 *
33
 * Give is a tribute to the spirit and philosophy of Open Source. We at WordImpress gladly embrace the Open Source philosophy both
34
 * 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 and their talented developers. Thank you all for your
37
 * contribution to WordPress.
38
 *
39
 * - The WordImpress Team
40
 */
41
42
// Exit if accessed directly.
43
if ( ! defined( 'ABSPATH' ) ) {
44
	exit;
45
}
46
47
if ( ! class_exists( 'Give' ) ) :
48
49
	/**
50
	 * Main Give Class
51
	 *
52
	 * @since 1.0
53
	 */
54
	final class Give {
55
56
		/** Singleton *************************************************************/
57
58
		/**
59
		 * Give Instance
60
		 *
61
		 * @since  1.0
62
		 * @access private
63
		 *
64
		 * @var    Give() The one true Give
65
		 */
66
		protected static $_instance;
67
68
		/**
69
		 * Give Roles Object
70
		 *
71
		 * @since  1.0
72
		 * @access public
73
		 *
74
		 * @var    Give_Roles object
75
		 */
76
		public $roles;
77
78
		/**
79
		 * Give Settings Object
80
		 *
81
		 * @since  1.0
82
		 * @access public
83
		 *
84
		 * @var    Give_Plugin_Settings object
85
		 */
86
		public $give_settings;
87
88
		/**
89
		 * Give Session Object
90
		 *
91
		 * This holds donation data for user's session.
92
		 *
93
		 * @since  1.0
94
		 * @access public
95
		 *
96
		 * @var    Give_Session object
97
		 */
98
		public $session;
99
100
		/**
101
		 * Give HTML Element Helper Object
102
		 *
103
		 * @since  1.0
104
		 * @access public
105
		 *
106
		 * @var    Give_HTML_Elements object
107
		 */
108
		public $html;
109
110
		/**
111
		 * Give Emails Object
112
		 *
113
		 * @since  1.0
114
		 * @access public
115
		 *
116
		 * @var    Give_Emails object
117
		 */
118
		public $emails;
119
120
		/**
121
		 * Give Email Template Tags Object
122
		 *
123
		 * @since  1.0
124
		 * @access public
125
		 *
126
		 * @var    Give_Email_Template_Tags object
127
		 */
128
		public $email_tags;
129
130
		/**
131
		 * Give Donors DB Object
132
		 *
133
		 * @since  1.0
134
		 * @access public
135
		 *
136
		 * @var    Give_DB_Donors object
137
		 */
138
		public $donors;
139
140
		/**
141
		 * Give Donor meta DB Object
142
		 *
143
		 * @since  1.6
144
		 * @access public
145
		 *
146
		 * @var    Give_DB_Donor_Meta object
147
		 */
148
		public $donor_meta;
149
150
		/**
151
		 * Give API Object
152
		 *
153
		 * @since  1.0
154
		 * @access public
155
		 *
156
		 * @var    Give_API object
157
		 */
158
		public $api;
159
160
		/**
161
		 * Give Template Loader Object
162
		 *
163
		 * @since  1.0
164
		 * @access public
165
		 *
166
		 * @var    Give_Template_Loader object
167
		 */
168
		public $template_loader;
169
170
		/**
171
		 * Give No Login Object
172
		 *
173
		 * @since  1.0
174
		 * @access public
175
		 *
176
		 * @var    Give_Email_Access object
177
		 */
178
		public $email_access;
179
180
		/**
181
		 * Main Give Instance
182
		 *
183
		 * Ensures that only one instance of Give exists in memory at any one
184
		 * time. Also prevents needing to define globals all over the place.
185
		 *
186
		 * @since     1.0
187
		 * @access    public
188
		 *
189
		 * @static
190
		 * @see       Give()
191
		 *
192
		 * @return    Give
193
		 */
194
		public static function instance() {
195
			if ( is_null( self::$_instance ) ) {
196
				self::$_instance = new self();
197
			}
198
199
			return self::$_instance;
200
		}
201
202
		/**
203
		 * Give Constructor.
204
		 */
205
		public function __construct() {
206
			$this->setup_constants();
207
			$this->includes();
208
			$this->init_hooks();
209
210
			do_action( 'give_loaded' );
211
		}
212
213
		/**
214
		 * Hook into actions and filters.
215
		 *
216
		 * @since  1.8.9
217
		 */
218
		private function init_hooks() {
219
			register_activation_hook( __FILE__, 'give_install' );
220
			add_action( 'plugins_loaded', array( $this, 'init' ), 0 );
221
		}
222
		/**
223
		 * Init Give when WordPress Initializes.
224
		 *
225
		 * @since 1.8.9
226
		 */
227
		public function init() {
228
229
			/**
230
			 * Fires before the Give core is initialized.
231
			 *
232
			 * @since 1.8.9
233
			 */
234
			do_action( 'before_give_init' );
235
236
			// Set up localization.
237
			$this->load_textdomain();
238
239
			$this->roles           = new Give_Roles();
240
			$this->api             = new Give_API();
241
			$this->give_settings   = new Give_Admin_Settings();
242
			$this->session         = new Give_Session();
243
			$this->html            = new Give_HTML_Elements();
244
			$this->emails          = new Give_Emails();
245
			$this->email_tags      = new Give_Email_Template_Tags();
246
			$this->donors          = new Give_DB_Donors();
247
			$this->donor_meta      = new Give_DB_Donor_Meta();
248
			$this->template_loader = new Give_Template_Loader();
249
			$this->email_access    = new Give_Email_Access();
250
251
			/**
252
			 * Fire the action after Give core loads.
253
			 *
254
			 * @param class Give class instance.
255
			 *
256
			 * @since 1.8.7
257
			 */
258
			do_action( 'give_init', $this );
259
260
		}
261
262
		/**
263
		 * Throw error on object clone
264
		 *
265
		 * The whole idea of the singleton design pattern is that there is a single
266
		 * object, therefore we don't want the object to be cloned.
267
		 *
268
		 * @since  1.0
269
		 * @access protected
270
		 *
271
		 * @return void
272
		 */
273
		public function __clone() {
274
			// Cloning instances of the class is forbidden.
275
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
276
		}
277
278
		/**
279
		 * Disable unserializing of the class
280
		 *
281
		 * @since  1.0
282
		 * @access protected
283
		 *
284
		 * @return void
285
		 */
286
		public function __wakeup() {
287
			// Unserializing instances of the class is forbidden.
288
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
289
		}
290
291
		/**
292
		 * Setup plugin constants
293
		 *
294
		 * @since  1.0
295
		 * @access private
296
		 *
297
		 * @return void
298
		 */
299
		private function setup_constants() {
300
301
			// Plugin version
302
			if ( ! defined( 'GIVE_VERSION' ) ) {
303
				define( 'GIVE_VERSION', '1.8.9' );
304
			}
305
306
			// Plugin Folder Path
307
			if ( ! defined( 'GIVE_PLUGIN_DIR' ) ) {
308
				define( 'GIVE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
309
			}
310
311
			// Plugin Folder URL
312
			if ( ! defined( 'GIVE_PLUGIN_URL' ) ) {
313
				define( 'GIVE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
314
			}
315
316
			// Plugin Basename aka: "give/give.php"
317
			if ( ! defined( 'GIVE_PLUGIN_BASENAME' ) ) {
318
				define( 'GIVE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
319
			}
320
321
			// Plugin Root File
322
			if ( ! defined( 'GIVE_PLUGIN_FILE' ) ) {
323
				define( 'GIVE_PLUGIN_FILE', __FILE__ );
324
			}
325
326
			// Make sure CAL_GREGORIAN is defined
327
			if ( ! defined( 'CAL_GREGORIAN' ) ) {
328
				define( 'CAL_GREGORIAN', 1 );
329
			}
330
		}
331
332
		/**
333
		 * Include required files
334
		 *
335
		 * @since  1.0
336
		 * @access private
337
		 *
338
		 * @return void
339
		 */
340
		private function includes() {
341
			global $give_options;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
342
343
			require_once GIVE_PLUGIN_DIR . 'includes/admin/class-admin-settings.php';
344
			require_once GIVE_PLUGIN_DIR . 'includes/admin/class-give-settings.php';
345
			$give_options = give_get_settings();
346
347
			require_once GIVE_PLUGIN_DIR . 'includes/admin/give-metabox-functions.php';
348
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-cache.php';
349
			require_once GIVE_PLUGIN_DIR . 'includes/post-types.php';
350
			require_once GIVE_PLUGIN_DIR . 'includes/scripts.php';
351
			require_once GIVE_PLUGIN_DIR . 'includes/ajax-functions.php';
352
			require_once GIVE_PLUGIN_DIR . 'includes/actions.php';
353
			require_once GIVE_PLUGIN_DIR . 'includes/filters.php';
354
			require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api.php';
355
356
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-roles.php';
357
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-template-loader.php';
358
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-donate-form.php';
359
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db.php';
360
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-donors.php';
361
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-donor-meta.php';
362
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-donor.php';
363
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-stats.php';
364
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-session.php';
365
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-html-elements.php';
366
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-logging.php';
367
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-license-handler.php';
368
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-cron.php';
369
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-email-access.php';
370
371
			require_once GIVE_PLUGIN_DIR . 'includes/country-functions.php';
372
			require_once GIVE_PLUGIN_DIR . 'includes/template-functions.php';
373
			require_once GIVE_PLUGIN_DIR . 'includes/misc-functions.php';
374
			require_once GIVE_PLUGIN_DIR . 'includes/forms/functions.php';
375
			require_once GIVE_PLUGIN_DIR . 'includes/forms/template.php';
376
			require_once GIVE_PLUGIN_DIR . 'includes/forms/widget.php';
377
			require_once GIVE_PLUGIN_DIR . 'includes/shortcodes.php';
378
			require_once GIVE_PLUGIN_DIR . 'includes/formatting.php';
379
			require_once GIVE_PLUGIN_DIR . 'includes/price-functions.php';
380
			require_once GIVE_PLUGIN_DIR . 'includes/error-tracking.php';
381
			require_once GIVE_PLUGIN_DIR . 'includes/process-donation.php';
382
			require_once GIVE_PLUGIN_DIR . 'includes/login-register.php';
383
			require_once GIVE_PLUGIN_DIR . 'includes/user-functions.php';
384
			require_once GIVE_PLUGIN_DIR . 'includes/plugin-compatibility.php';
385
			require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-classes.php';
386
			require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-functions.php';
387
			require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-actions.php';
388
			require_once GIVE_PLUGIN_DIR . 'includes/deprecated/deprecated-filters.php';
389
390
			require_once GIVE_PLUGIN_DIR . 'includes/payments/functions.php';
391
			require_once GIVE_PLUGIN_DIR . 'includes/payments/actions.php';
392
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payment-stats.php';
393
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payments-query.php';
394
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-give-payment.php';
395
396
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/functions.php';
397
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/actions.php';
398
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/paypal-standard.php';
399
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/offline-donations.php';
400
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/manual.php';
401
402
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-emails.php';
403
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-email-tags.php';
404
			require_once GIVE_PLUGIN_DIR . 'includes/emails/functions.php';
405
			require_once GIVE_PLUGIN_DIR . 'includes/emails/template.php';
406
			require_once GIVE_PLUGIN_DIR . 'includes/emails/actions.php';
407
408
			if ( defined( 'WP_CLI' ) && WP_CLI ) {
409
				require_once GIVE_PLUGIN_DIR . 'includes/class-give-cli-commands.php';
410
			}
411
412
			if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
413
414
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-footer.php';
415
				require_once GIVE_PLUGIN_DIR . 'includes/admin/welcome.php';
416
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-pages.php';
417
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-admin-notices.php';
418
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
419
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-i18n-module.php';
420
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-actions.php';
421
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-filters.php';
422
				require_once GIVE_PLUGIN_DIR . 'includes/admin/system-info.php';
423
				require_once GIVE_PLUGIN_DIR . 'includes/admin/add-ons.php';
424
				require_once GIVE_PLUGIN_DIR . 'includes/admin/plugins.php';
425
				require_once GIVE_PLUGIN_DIR . 'includes/admin/dashboard-widgets.php';
426
427
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/actions.php';
428
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/payments-history.php';
429
430
				require_once GIVE_PLUGIN_DIR . 'includes/admin/donors/donors.php';
431
				require_once GIVE_PLUGIN_DIR . 'includes/admin/donors/donor-functions.php';
432
				require_once GIVE_PLUGIN_DIR . 'includes/admin/donors/donor-actions.php';
433
434
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/metabox.php';
435
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/class-metabox-form-data.php';
436
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/dashboard-columns.php';
437
438
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/export-functions.php';
439
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/class-export.php';
440
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/export-actions.php';
441
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/export/pdf-reports.php';
442
443
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/reports.php';
444
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/class-give-graph.php';
445
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/graphing.php';
446
447
				require_once GIVE_PLUGIN_DIR . 'includes/admin/tools/data/tools-actions.php';
448
449
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/abstract-shortcode-generator.php';
450
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/class-shortcode-button.php';
451
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-form.php';
452
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-goal.php';
453
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-login.php';
454
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-register.php';
455
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-profile-editor.php';
456
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-donation-history.php';
457
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-receipt.php';
458
459
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
460
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrades.php';
461
462
			}// End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
463
464
			require_once GIVE_PLUGIN_DIR . 'includes/install.php';
465
466
		}
467
468
		/**
469
		 * Loads the plugin language files.
470
		 *
471
		 * @since  1.0
472
		 * @access public
473
		 *
474
		 * @return void
475
		 */
476
		public function load_textdomain() {
477
478
			// Set filter for Give's languages directory
479
			$give_lang_dir = dirname( plugin_basename( GIVE_PLUGIN_FILE ) ) . '/languages/';
480
			$give_lang_dir = apply_filters( 'give_languages_directory', $give_lang_dir );
481
482
			// Traditional WordPress plugin locale filter.
483
			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
484
			$locale = apply_filters( 'plugin_locale', $locale, 'give' );
485
486
			unload_textdomain( 'give' );
487
			load_textdomain( 'give', WP_LANG_DIR . '/give/give-' . $locale . '.mo' );
488
			load_plugin_textdomain( 'give', false, $give_lang_dir );
489
490
		}
491
492
	}
493
494
endif; // End if class_exists check
495
496
497
/**
498
 * Start Give
499
 *
500
 * The main function responsible for returning the one true Give instance to functions everywhere.
501
 *
502
 * Use this function like you would a global variable, except without needing
503
 * to declare the global.
504
 *
505
 * Example: <?php $give = Give(); ?>
506
 *
507
 * @since 1.0
508
 * @return object|Give
509
 */
510
function Give() {
511
	return Give::instance();
512
}
513
514
Give();
515