Completed
Push — master ( 647547...13dcfc )
by Devin
17:56
created

Give   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 348
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Test Coverage

Coverage 2.01%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
dl 0
loc 348
ccs 3
cts 149
cp 0.0201
rs 10
c 2
b 1
f 1
wmc 19
lcom 1
cbo 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __clone() 0 4 1
A __wakeup() 0 4 1
C setup_constants() 0 32 7
B load_textdomain() 0 24 3
B instance() 0 24 3
B includes() 0 108 4
1
<?php
1 ignored issue
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 53 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.5.2
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 2 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 <http://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 contribution to WordPress.
37
 *
38
 * - The WordImpress Team
39
 *
40
 */
41
42
// Exit if accessed directly
43
if ( ! defined( 'ABSPATH' ) ) {
44
	exit;
45
}
46
47
if ( ! class_exists( 'Give' ) ) :
48
	/**
49
	 * Main Give Class
50
	 *
51
	 * @since 1.0
52
	 */
53
	final class Give {
54
		/** Singleton *************************************************************/
55
56
57
		/**
58
		 * @var Give The one true Give
59
		 * @since 1.0
60
		 */
61
		private static $instance;
62
63
		/**
64
		 * Give Roles Object
65
		 *
66
		 * @var Give_Roles object
67
		 * @since 1.0
68
		 */
69
		public $roles;
70
71
		/**
72
		 * Give Settings Object
73
		 *
74
		 * @var Give_Plugin_Settings object
75
		 * @since 1.0
76
		 */
77
		public $give_settings;
78
79
		/**
80
		 * Give Session Object
81
		 *
82
		 * This holds donation data for user's session
83
		 *
84
		 * @var Give_Session object
85
		 * @since 1.0
86
		 */
87
		public $session;
88
89
		/**
90
		 * Give HTML Element Helper Object
91
		 *
92
		 * @var Give_HTML_Elements object
93
		 * @since 1.0
94
		 */
95
		public $html;
96
97
98
		/**
99
		 * Give Emails Object
100
		 *
101
		 * @var Give_Emails object
102
		 * @since 1.0
103
		 */
104
		public $emails;
105
106
		/**
107
		 * Give Email Template Tags Object
108
		 *
109
		 * @var Give_Email_Template_Tags object
110
		 * @since 1.0
111
		 */
112
		public $email_tags;
113
114
		/**
115
		 * Give Customers DB Object
116
		 *
117
		 * @var object|Give_DB_Customers object
118
		 * @since 1.0
119
		 */
120
		public $customers;
121
122
		/**
123
		 * Give API Object
124
		 *
125
		 * @var Give_API object
126
		 * @since 1.1
127
		 */
128
		public $api;
129
130
		/**
131
		 * Give Template Loader Object
132
		 *
133
		 * @var Give_Template_Loader object
134
		 * @since 1.0
135
		 */
136
		public $template_loader;
137
138
		/**
139
		 * Give No Login Object
140
		 *
141
		 * @var Give_Email_Access object
142
		 * @since 1.0
143
		 */
144
		public $email_access;
145
146
		/**
147
		 * Main Give Instance
148
		 *
149
		 * Insures that only one instance of Give exists in memory at any one
150
		 * time. Also prevents needing to define globals all over the place.
151
		 *
152
		 * @since     1.0
153
		 * @static
154
		 * @staticvar array $instance
155
		 * @uses      Give::setup_constants() Setup the constants needed
156
		 * @uses      Give::includes() Include the required files
157
		 * @uses      Give::load_textdomain() load the language files
158
		 * @see       Give()
159
		 * @return    Give
160
		 */
161 60
		public static function instance() {
162 60
			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Give ) ) {
163
				self::$instance = new Give;
164
				self::$instance->setup_constants();
165
166
				add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
167
168
				self::$instance->includes();
169
				self::$instance->roles           = new Give_Roles();
170
				self::$instance->api             = new Give_API();
171
				self::$instance->give_settings   = new Give_Plugin_Settings();
172
				self::$instance->session         = new Give_Session();
173
				self::$instance->html            = new Give_HTML_Elements();
174
				self::$instance->emails          = new Give_Emails();
175
				self::$instance->email_tags      = new Give_Email_Template_Tags();
176
				self::$instance->customers       = new Give_DB_Customers();
177
				self::$instance->template_loader = new Give_Template_Loader();
178
				self::$instance->email_access    = new Give_Email_Access();
179
180
			}
181
182
183 60
			return self::$instance;
184
		}
185
186
		/**
187
		 * Throw error on object clone
188
		 *
189
		 * The whole idea of the singleton design pattern is that there is a single
190
		 * object, therefore we don't want the object to be cloned.
191
		 *
192
		 * @since  1.0
193
		 * @access protected
194
		 * @return void
195
		 */
196
		public function __clone() {
197
			// Cloning instances of the class is forbidden
198
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
199
		}
200
201
		/**
202
		 * Disable unserializing of the class
203
		 *
204
		 * @since  1.0
205
		 * @access protected
206
		 * @return void
207
		 */
208
		public function __wakeup() {
209
			// Unserializing instances of the class is forbidden
210
			_doing_it_wrong( __FUNCTION__, __( 'Cheatin&#8217; huh?', 'give' ), '1.0' );
211
		}
212
213
		/**
214
		 * Setup plugin constants
215
		 *
216
		 * @access private
217
		 * @since  1.0
218
		 * @return void
219
		 */
220
		private function setup_constants() {
221
222
			// Plugin version
223
			if ( ! defined( 'GIVE_VERSION' ) ) {
224
				define( 'GIVE_VERSION', '1.5.2' );
225
			}
226
227
			// Plugin Folder Path
228
			if ( ! defined( 'GIVE_PLUGIN_DIR' ) ) {
229
				define( 'GIVE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
230
			}
231
232
			// Plugin Folder URL
233
			if ( ! defined( 'GIVE_PLUGIN_URL' ) ) {
234
				define( 'GIVE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
235
			}
236
237
			// Plugin Basename aka: "give/give.php"
238
			if ( ! defined( 'GIVE_PLUGIN_BASENAME' ) ) {
239
				define( 'GIVE_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
240
			}
241
242
			// Plugin Root File
243
			if ( ! defined( 'GIVE_PLUGIN_FILE' ) ) {
244
				define( 'GIVE_PLUGIN_FILE', __FILE__ );
245
			}
246
247
			// Make sure CAL_GREGORIAN is defined
248
			if ( ! defined( 'CAL_GREGORIAN' ) ) {
249
				define( 'CAL_GREGORIAN', 1 );
250
			}
251
		}
252
253
		/**
254
		 * Include required files
255
		 *
256
		 * @access private
257
		 * @since  1.0
258
		 * @return void
259
		 */
260
		private function includes() {
261
			global $give_options;
1 ignored issue
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...
262
263
			require_once GIVE_PLUGIN_DIR . 'includes/admin/class-give-settings.php';
264
			$give_options = give_get_settings();
265
266
			require_once GIVE_PLUGIN_DIR . 'includes/post-types.php';
267
			require_once GIVE_PLUGIN_DIR . 'includes/scripts.php';
268
			require_once GIVE_PLUGIN_DIR . 'includes/ajax-functions.php';
269
			require_once GIVE_PLUGIN_DIR . 'includes/actions.php';
270
			require_once GIVE_PLUGIN_DIR . 'includes/api/class-give-api.php';
271
272
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-roles.php';
273
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-template-loader.php';
274
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-donate-form.php';
275
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db.php';
276
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-db-customers.php';
277
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-customer.php';
278
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-stats.php';
279
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-session.php';
280
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-html-elements.php';
281
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-logging.php';
282
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-license-handler.php';
283
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-cron.php';
284
			require_once GIVE_PLUGIN_DIR . 'includes/class-give-email-access.php';
285
286
			require_once GIVE_PLUGIN_DIR . 'includes/country-functions.php';
287
			require_once GIVE_PLUGIN_DIR . 'includes/template-functions.php';
288
			require_once GIVE_PLUGIN_DIR . 'includes/misc-functions.php';
289
			require_once GIVE_PLUGIN_DIR . 'includes/forms/functions.php';
290
			require_once GIVE_PLUGIN_DIR . 'includes/forms/template.php';
291
			require_once GIVE_PLUGIN_DIR . 'includes/forms/widget.php';
292
			require_once GIVE_PLUGIN_DIR . 'includes/shortcodes.php';
293
			require_once GIVE_PLUGIN_DIR . 'includes/formatting.php';
294
			require_once GIVE_PLUGIN_DIR . 'includes/price-functions.php';
295
			require_once GIVE_PLUGIN_DIR . 'includes/error-tracking.php';
296
			require_once GIVE_PLUGIN_DIR . 'includes/process-purchase.php';
297
			require_once GIVE_PLUGIN_DIR . 'includes/login-register.php';
298
			require_once GIVE_PLUGIN_DIR . 'includes/user-functions.php';
299
			require_once GIVE_PLUGIN_DIR . 'includes/plugin-compatibility.php';
300
			require_once GIVE_PLUGIN_DIR . 'includes/deprecated-functions.php';
301
302
			require_once GIVE_PLUGIN_DIR . 'includes/payments/functions.php';
303
			require_once GIVE_PLUGIN_DIR . 'includes/payments/actions.php';
304
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payment-stats.php';
305
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-payments-query.php';
306
			require_once GIVE_PLUGIN_DIR . 'includes/payments/class-give-payment.php';
307
308
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/functions.php';
309
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/actions.php';
310
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/paypal-standard.php';
311
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/offline-donations.php';
312
			require_once GIVE_PLUGIN_DIR . 'includes/gateways/manual.php';
313
314
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-emails.php';
315
			require_once GIVE_PLUGIN_DIR . 'includes/emails/class-give-email-tags.php';
316
			require_once GIVE_PLUGIN_DIR . 'includes/emails/functions.php';
317
			require_once GIVE_PLUGIN_DIR . 'includes/emails/template.php';
318
			require_once GIVE_PLUGIN_DIR . 'includes/emails/actions.php';
319
320
			if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
321
322
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-footer.php';
323
				require_once GIVE_PLUGIN_DIR . 'includes/admin/welcome.php';
324
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-pages.php';
325
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-admin-notices.php';
326
				require_once GIVE_PLUGIN_DIR . 'includes/admin/class-api-keys-table.php';
327
				require_once GIVE_PLUGIN_DIR . 'includes/admin/admin-actions.php';
328
				require_once GIVE_PLUGIN_DIR . 'includes/admin/system-info.php';
329
				require_once GIVE_PLUGIN_DIR . 'includes/admin/add-ons.php';
330
				require_once GIVE_PLUGIN_DIR . 'includes/admin/plugins.php';
331
				require_once GIVE_PLUGIN_DIR . 'includes/admin/dashboard-widgets.php';
332
333
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/actions.php';
334
				require_once GIVE_PLUGIN_DIR . 'includes/admin/payments/payments-history.php';
335
336
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customers.php';
337
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customer-functions.php';
338
				require_once GIVE_PLUGIN_DIR . 'includes/admin/customers/customer-actions.php';
339
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/metabox.php';
340
				require_once GIVE_PLUGIN_DIR . 'includes/admin/forms/dashboard-columns.php';
341
342
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/export/export-functions.php';
343
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/reports.php';
344
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools.php';
345
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/tools/tools-actions.php';
346
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/pdf-reports.php';
347
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/class-give-graph.php';
348
				require_once GIVE_PLUGIN_DIR . 'includes/admin/reporting/graphing.php';
349
350
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/abstract-shortcode-generator.php';
351
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/class-shortcode-button.php';
352
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-form.php';
353
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-goal.php';
354
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-login.php';
355
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-register.php';
356
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-profile-editor.php';
357
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-donation-history.php';
358
				require_once GIVE_PLUGIN_DIR . 'includes/admin/shortcodes/shortcode-give-receipt.php';
359
360
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrade-functions.php';
361
				require_once GIVE_PLUGIN_DIR . 'includes/admin/upgrades/upgrades.php';
362
363
			}
364
365
			require_once GIVE_PLUGIN_DIR . 'includes/install.php';
366
367
		}
368
369
		/**
370
		 * Loads the plugin language files
371
		 *
372
		 * @access public
373
		 * @since  1.0
374
		 * @return void
375
		 */
376
		public function load_textdomain() {
377
			// Set filter for Give's languages directory
378
			$give_lang_dir = dirname( plugin_basename( GIVE_PLUGIN_FILE ) ) . '/languages/';
379
			$give_lang_dir = apply_filters( 'give_languages_directory', $give_lang_dir );
380
381
			// Traditional WordPress plugin locale filter
382
			$locale = apply_filters( 'plugin_locale', get_locale(), 'give' );
383
			$mofile = sprintf( '%1$s-%2$s.mo', 'give', $locale );
384
385
			// Setup paths to current locale file
386
			$mofile_local  = $give_lang_dir . $mofile;
387
			$mofile_global = WP_LANG_DIR . '/give/' . $mofile;
388
389
			if ( file_exists( $mofile_global ) ) {
390
				// Look in global /wp-content/languages/give folder
391
				load_textdomain( 'give', $mofile_global );
392
			} elseif ( file_exists( $mofile_local ) ) {
393
				// Look in local location from filter `give_languages_directory`
394
				load_textdomain( 'give', $mofile_local );
395
			} else {
396
				// Load the default language files packaged up w/ Give
397
				load_plugin_textdomain( 'give', false, $give_lang_dir );
398
			}
399
		}
400
	}
401
402
endif; // End if class_exists check
403
404
405
/**
406
 * Start Give 
407
 * 
408
 * The main function responsible for returning the one true Give instance to functions everywhere.
409
 *
410
 * Use this function like you would a global variable, except without needing
411
 * to declare the global.
412
 *
413
 * Example: <?php $give = Give(); ?>
414
 *
415
 * @since 1.0
416
 * @return object|Give 
417
 */
418
function Give() {
419 59
	return Give::instance();
420
}
421
422
// Get Give Running
423
Give();
424