Passed
Push — master ( 5faead...57234e )
by Brian
04:33
created
includes/admin/class-getpaid-installer.php 2 patches
Indentation   +363 added lines, -363 removed lines patch added patch discarded remove patch
@@ -20,214 +20,214 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		if ( method_exists( $this, $method ) ) {
52
-			$this->$method();
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Do a fresh install.
59
-	 *
60
-	 */
61
-	public function upgrade_from_0() {
62
-		$this->create_subscriptions_table();
63
-		$this->create_invoices_table();
64
-		$this->create_invoice_items_table();
65
-
66
-		// Save default tax rates.
67
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
68
-	}
69
-
70
-	/**
71
-	 * Upgrade to 0.0.5
72
-	 *
73
-	 */
74
-	public function upgrade_from_004() {
75
-		global $wpdb;
76
-
77
-		// Invoices.
78
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
-		if ( ! empty( $results ) ) {
80
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
81
-
82
-			// Clean post cache
83
-			foreach ( $results as $row ) {
84
-				clean_post_cache( $row->ID );
85
-			}
86
-
87
-		}
88
-
89
-		// Item meta key changes
90
-		$query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
-		$results = $wpdb->get_results( $query );
92
-
93
-		if ( ! empty( $results ) ) {
94
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
97
-
98
-			foreach ( $results as $row ) {
99
-				clean_post_cache( $row->post_id );
100
-			}
101
-
102
-		}
103
-
104
-		$this->upgrade_from_102();
105
-	}
106
-
107
-	/**
108
-	 * Upgrade to 1.0.3
109
-	 *
110
-	 */
111
-	public function upgrade_from_102() {
112
-		$this->create_subscriptions_table();
113
-		$this->upgrade_from_118();
114
-	}
115
-
116
-	/**
117
-	 * Upgrade to version 2.0.0.
118
-	 *
119
-	 */
120
-	public function upgrade_from_118() {
121
-		$this->create_invoices_table();
122
-		$this->create_invoice_items_table();
123
-		$this->migrate_old_invoices();
124
-	}
125
-
126
-	/**
127
-	 * Upgrade to version 2.0.8.
128
-	 *
129
-	 */
130
-	public function upgrade_from_207() {
131
-		global $wpdb;
132
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
133
-	}
134
-
135
-	/**
136
-	 * Give administrators the capability to manage GetPaid.
137
-	 *
138
-	 */
139
-	public function add_capabilities() {
140
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
141
-	}
142
-
143
-	/**
144
-	 * Re-create GetPaid pages.
145
-	 *
146
-	 */
147
-	public function create_pages() {
148
-
149
-		$pages = apply_filters(
150
-			'wpinv_create_pages',
151
-			array(
152
-
153
-				// Checkout page.
154
-				'checkout_page' => array(
155
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
157
-					'content'   => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        if ( method_exists( $this, $method ) ) {
52
+            $this->$method();
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Do a fresh install.
59
+     *
60
+     */
61
+    public function upgrade_from_0() {
62
+        $this->create_subscriptions_table();
63
+        $this->create_invoices_table();
64
+        $this->create_invoice_items_table();
65
+
66
+        // Save default tax rates.
67
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
68
+    }
69
+
70
+    /**
71
+     * Upgrade to 0.0.5
72
+     *
73
+     */
74
+    public function upgrade_from_004() {
75
+        global $wpdb;
76
+
77
+        // Invoices.
78
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
+        if ( ! empty( $results ) ) {
80
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
81
+
82
+            // Clean post cache
83
+            foreach ( $results as $row ) {
84
+                clean_post_cache( $row->ID );
85
+            }
86
+
87
+        }
88
+
89
+        // Item meta key changes
90
+        $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
+        $results = $wpdb->get_results( $query );
92
+
93
+        if ( ! empty( $results ) ) {
94
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
97
+
98
+            foreach ( $results as $row ) {
99
+                clean_post_cache( $row->post_id );
100
+            }
101
+
102
+        }
103
+
104
+        $this->upgrade_from_102();
105
+    }
106
+
107
+    /**
108
+     * Upgrade to 1.0.3
109
+     *
110
+     */
111
+    public function upgrade_from_102() {
112
+        $this->create_subscriptions_table();
113
+        $this->upgrade_from_118();
114
+    }
115
+
116
+    /**
117
+     * Upgrade to version 2.0.0.
118
+     *
119
+     */
120
+    public function upgrade_from_118() {
121
+        $this->create_invoices_table();
122
+        $this->create_invoice_items_table();
123
+        $this->migrate_old_invoices();
124
+    }
125
+
126
+    /**
127
+     * Upgrade to version 2.0.8.
128
+     *
129
+     */
130
+    public function upgrade_from_207() {
131
+        global $wpdb;
132
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
133
+    }
134
+
135
+    /**
136
+     * Give administrators the capability to manage GetPaid.
137
+     *
138
+     */
139
+    public function add_capabilities() {
140
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
141
+    }
142
+
143
+    /**
144
+     * Re-create GetPaid pages.
145
+     *
146
+     */
147
+    public function create_pages() {
148
+
149
+        $pages = apply_filters(
150
+            'wpinv_create_pages',
151
+            array(
152
+
153
+                // Checkout page.
154
+                'checkout_page' => array(
155
+                    'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
+                    'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
157
+                    'content'   => '
158 158
 						<!-- wp:shortcode -->
159 159
 						[wpinv_checkout]
160 160
 						<!-- /wp:shortcode -->
161 161
 					',
162
-					'parent'    => '',
163
-				),
164
-
165
-				// Invoice history page.
166
-				'invoice_history_page' => array(
167
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
169
-					'content' => '
162
+                    'parent'    => '',
163
+                ),
164
+
165
+                // Invoice history page.
166
+                'invoice_history_page' => array(
167
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
169
+                    'content' => '
170 170
 					<!-- wp:shortcode -->
171 171
 					[wpinv_history]
172 172
 					<!-- /wp:shortcode -->
173 173
 				',
174
-					'parent'  => '',
175
-				),
176
-
177
-				// Success page content.
178
-				'success_page' => array(
179
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
181
-					'content'  => '
174
+                    'parent'  => '',
175
+                ),
176
+
177
+                // Success page content.
178
+                'success_page' => array(
179
+                    'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
+                    'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
181
+                    'content'  => '
182 182
 					<!-- wp:shortcode -->
183 183
 					[wpinv_receipt]
184 184
 					<!-- /wp:shortcode -->
185 185
 				',
186
-					'parent'   => 'gp-checkout',
187
-				),
188
-
189
-				// Failure page content.
190
-				'failure_page' => array(
191
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
194
-					'parent'  => 'gp-checkout',
195
-				),
196
-
197
-				// Subscriptions history page.
198
-				'invoice_subscription_page' => array(
199
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
201
-					'content' => '
186
+                    'parent'   => 'gp-checkout',
187
+                ),
188
+
189
+                // Failure page content.
190
+                'failure_page' => array(
191
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
194
+                    'parent'  => 'gp-checkout',
195
+                ),
196
+
197
+                // Subscriptions history page.
198
+                'invoice_subscription_page' => array(
199
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
201
+                    'content' => '
202 202
 					<!-- wp:shortcode -->
203 203
 					[wpinv_subscriptions]
204 204
 					<!-- /wp:shortcode -->
205 205
 				',
206
-					'parent' => '',
207
-				),
206
+                    'parent' => '',
207
+                ),
208 208
 
209
-			)
210
-		);
209
+            )
210
+        );
211 211
 
212
-		foreach ( $pages as $key => $page ) {
213
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
214
-		}
212
+        foreach ( $pages as $key => $page ) {
213
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
214
+        }
215 215
 
216
-	}
216
+    }
217 217
 
218
-	/**
219
-	 * Create subscriptions table.
220
-	 *
221
-	 */
222
-	public function create_subscriptions_table() {
218
+    /**
219
+     * Create subscriptions table.
220
+     *
221
+     */
222
+    public function create_subscriptions_table() {
223 223
 
224
-		global $wpdb;
224
+        global $wpdb;
225 225
 
226
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
226
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
227 227
 
228
-		// Create tables.
229
-		$charset_collate = $wpdb->get_charset_collate();
230
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
228
+        // Create tables.
229
+        $charset_collate = $wpdb->get_charset_collate();
230
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
231 231
 			id bigint(20) unsigned NOT NULL auto_increment,
232 232
 			customer_id bigint(20) NOT NULL,
233 233
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -250,22 +250,22 @@  discard block
 block discarded – undo
250 250
 			KEY customer_and_status (customer_id, status)
251 251
 		  ) $charset_collate;";
252 252
 
253
-		dbDelta( $sql );
253
+        dbDelta( $sql );
254 254
 
255
-	}
255
+    }
256 256
 
257
-	/**
258
-	 * Create invoices table.
259
-	 *
260
-	 */
261
-	public function create_invoices_table() {
262
-		global $wpdb;
257
+    /**
258
+     * Create invoices table.
259
+     *
260
+     */
261
+    public function create_invoices_table() {
262
+        global $wpdb;
263 263
 
264
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
264
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
265 265
 
266
-		// Create tables.
267
-		$charset_collate = $wpdb->get_charset_collate();
268
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
266
+        // Create tables.
267
+        $charset_collate = $wpdb->get_charset_collate();
268
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
269 269
 			post_id BIGINT(20) NOT NULL,
270 270
             `number` VARCHAR(100),
271 271
             `key` VARCHAR(100),
@@ -301,22 +301,22 @@  discard block
 block discarded – undo
301 301
 			KEY `key` (`key`)
302 302
 		  ) $charset_collate;";
303 303
 
304
-		dbDelta( $sql );
304
+        dbDelta( $sql );
305 305
 
306
-	}
306
+    }
307 307
 
308
-	/**
309
-	 * Create invoice items table.
310
-	 *
311
-	 */
312
-	public function create_invoice_items_table() {
313
-		global $wpdb;
308
+    /**
309
+     * Create invoice items table.
310
+     *
311
+     */
312
+    public function create_invoice_items_table() {
313
+        global $wpdb;
314 314
 
315
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
315
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
316 316
 
317
-		// Create tables.
318
-		$charset_collate = $wpdb->get_charset_collate();
319
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
317
+        // Create tables.
318
+        $charset_collate = $wpdb->get_charset_collate();
319
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
320 320
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
321 321
             post_id BIGINT(20) NOT NULL,
322 322
             item_id BIGINT(20) NOT NULL,
@@ -338,159 +338,159 @@  discard block
 block discarded – undo
338 338
 			KEY post_id (post_id)
339 339
 		  ) $charset_collate;";
340 340
 
341
-		dbDelta( $sql );
342
-
343
-	}
344
-
345
-	/**
346
-	 * Migrates old invoices to new invoices.
347
-	 *
348
-	 */
349
-	public function migrate_old_invoices() {
350
-		global $wpdb;
351
-
352
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
353
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
354
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
355
-		$invoices            = array_unique(
356
-			get_posts(
357
-				array(
358
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
359
-					'posts_per_page' => -1,
360
-					'fields'         => 'ids',
361
-					'post_status'    => array_keys( get_post_stati() ),
362
-					'exclude'        => (array) $migrated,
363
-				)
364
-			)
365
-		);
366
-
367
-		// Abort if we do not have any invoices.
368
-		if ( empty( $invoices ) ) {
369
-			return;
370
-		}
371
-
372
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
373
-
374
-		$invoice_rows = array();
375
-		foreach ( $invoices as $invoice ) {
376
-
377
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
378
-
379
-			if ( empty( $invoice->ID ) ) {
380
-				return;
381
-			}
382
-
383
-			$fields = array (
384
-				'post_id'        => $invoice->ID,
385
-				'number'         => $invoice->get_number(),
386
-				'key'            => $invoice->get_key(),
387
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
388
-				'mode'           => $invoice->mode,
389
-				'user_ip'        => $invoice->get_ip(),
390
-				'first_name'     => $invoice->get_first_name(),
391
-				'last_name'      => $invoice->get_last_name(),
392
-				'address'        => $invoice->get_address(),
393
-				'city'           => $invoice->city,
394
-				'state'          => $invoice->state,
395
-				'country'        => $invoice->country,
396
-				'zip'            => $invoice->zip,
397
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
398
-				'gateway'        => $invoice->get_gateway(),
399
-				'transaction_id' => $invoice->get_transaction_id(),
400
-				'currency'       => $invoice->get_currency(),
401
-				'subtotal'       => $invoice->get_subtotal(),
402
-				'tax'            => $invoice->get_tax(),
403
-				'fees_total'     => $invoice->get_fees_total(),
404
-				'total'          => $invoice->get_total(),
405
-				'discount'       => $invoice->get_discount(),
406
-				'discount_code'  => $invoice->get_discount_code(),
407
-				'disable_taxes'  => $invoice->disable_taxes,
408
-				'due_date'       => $invoice->get_due_date(),
409
-				'completed_date' => $invoice->get_completed_date(),
410
-				'company'        => $invoice->company,
411
-				'vat_number'     => $invoice->vat_number,
412
-				'vat_rate'       => $invoice->vat_rate,
413
-				'custom_meta'    => $invoice->payment_meta
414
-			);
415
-
416
-			foreach ( $fields as $key => $val ) {
417
-				if ( is_null( $val ) ) {
418
-					$val = '';
419
-				}
420
-				$val = maybe_serialize( $val );
421
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
422
-			}
423
-
424
-			$fields = implode( ', ', $fields );
425
-			$invoice_rows[] = "($fields)";
426
-
427
-			$item_rows    = array();
428
-			$item_columns = array();
429
-			foreach ( $invoice->get_cart_details() as $details ) {
430
-				$fields = array(
431
-					'post_id'          => $invoice->ID,
432
-					'item_id'          => $details['id'],
433
-					'item_name'        => $details['name'],
434
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
435
-					'vat_rate'         => $details['vat_rate'],
436
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
437
-					'tax'              => $details['tax'],
438
-					'item_price'       => $details['item_price'],
439
-					'custom_price'     => $details['custom_price'],
440
-					'quantity'         => $details['quantity'],
441
-					'discount'         => $details['discount'],
442
-					'subtotal'         => $details['subtotal'],
443
-					'price'            => $details['price'],
444
-					'meta'             => $details['meta'],
445
-					'fees'             => $details['fees'],
446
-				);
447
-
448
-				$item_columns = array_keys ( $fields );
449
-
450
-				foreach ( $fields as $key => $val ) {
451
-					if ( is_null( $val ) ) {
452
-						$val = '';
453
-					}
454
-					$val = maybe_serialize( $val );
455
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
456
-				}
457
-
458
-				$fields = implode( ', ', $fields );
459
-				$item_rows[] = "($fields)";
460
-			}
461
-
462
-			$item_rows    = implode( ', ', $item_rows );
463
-			$item_columns = implode( ', ', $item_columns );
464
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
465
-		}
466
-
467
-		if ( empty( $invoice_rows ) ) {
468
-			return;
469
-		}
470
-
471
-		$invoice_rows = implode( ', ', $invoice_rows );
472
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
473
-
474
-	}
475
-
476
-	/**
477
-	 * Migrates old invoices to new invoices.
478
-	 *
479
-	 */
480
-	public static function rename_gateways_label() {
481
-		global $wpdb;
482
-
483
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
484
-
485
-			$wpdb->update(
486
-				$wpdb->prefix . 'getpaid_invoices',
487
-				array( 'gateway' => $gateway ),
488
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
489
-				'%s',
490
-				'%s'
491
-			);
492
-
493
-		}
494
-	}
341
+        dbDelta( $sql );
342
+
343
+    }
344
+
345
+    /**
346
+     * Migrates old invoices to new invoices.
347
+     *
348
+     */
349
+    public function migrate_old_invoices() {
350
+        global $wpdb;
351
+
352
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
353
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
354
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
355
+        $invoices            = array_unique(
356
+            get_posts(
357
+                array(
358
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
359
+                    'posts_per_page' => -1,
360
+                    'fields'         => 'ids',
361
+                    'post_status'    => array_keys( get_post_stati() ),
362
+                    'exclude'        => (array) $migrated,
363
+                )
364
+            )
365
+        );
366
+
367
+        // Abort if we do not have any invoices.
368
+        if ( empty( $invoices ) ) {
369
+            return;
370
+        }
371
+
372
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
373
+
374
+        $invoice_rows = array();
375
+        foreach ( $invoices as $invoice ) {
376
+
377
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
378
+
379
+            if ( empty( $invoice->ID ) ) {
380
+                return;
381
+            }
382
+
383
+            $fields = array (
384
+                'post_id'        => $invoice->ID,
385
+                'number'         => $invoice->get_number(),
386
+                'key'            => $invoice->get_key(),
387
+                'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
388
+                'mode'           => $invoice->mode,
389
+                'user_ip'        => $invoice->get_ip(),
390
+                'first_name'     => $invoice->get_first_name(),
391
+                'last_name'      => $invoice->get_last_name(),
392
+                'address'        => $invoice->get_address(),
393
+                'city'           => $invoice->city,
394
+                'state'          => $invoice->state,
395
+                'country'        => $invoice->country,
396
+                'zip'            => $invoice->zip,
397
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
398
+                'gateway'        => $invoice->get_gateway(),
399
+                'transaction_id' => $invoice->get_transaction_id(),
400
+                'currency'       => $invoice->get_currency(),
401
+                'subtotal'       => $invoice->get_subtotal(),
402
+                'tax'            => $invoice->get_tax(),
403
+                'fees_total'     => $invoice->get_fees_total(),
404
+                'total'          => $invoice->get_total(),
405
+                'discount'       => $invoice->get_discount(),
406
+                'discount_code'  => $invoice->get_discount_code(),
407
+                'disable_taxes'  => $invoice->disable_taxes,
408
+                'due_date'       => $invoice->get_due_date(),
409
+                'completed_date' => $invoice->get_completed_date(),
410
+                'company'        => $invoice->company,
411
+                'vat_number'     => $invoice->vat_number,
412
+                'vat_rate'       => $invoice->vat_rate,
413
+                'custom_meta'    => $invoice->payment_meta
414
+            );
415
+
416
+            foreach ( $fields as $key => $val ) {
417
+                if ( is_null( $val ) ) {
418
+                    $val = '';
419
+                }
420
+                $val = maybe_serialize( $val );
421
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
422
+            }
423
+
424
+            $fields = implode( ', ', $fields );
425
+            $invoice_rows[] = "($fields)";
426
+
427
+            $item_rows    = array();
428
+            $item_columns = array();
429
+            foreach ( $invoice->get_cart_details() as $details ) {
430
+                $fields = array(
431
+                    'post_id'          => $invoice->ID,
432
+                    'item_id'          => $details['id'],
433
+                    'item_name'        => $details['name'],
434
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
435
+                    'vat_rate'         => $details['vat_rate'],
436
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
437
+                    'tax'              => $details['tax'],
438
+                    'item_price'       => $details['item_price'],
439
+                    'custom_price'     => $details['custom_price'],
440
+                    'quantity'         => $details['quantity'],
441
+                    'discount'         => $details['discount'],
442
+                    'subtotal'         => $details['subtotal'],
443
+                    'price'            => $details['price'],
444
+                    'meta'             => $details['meta'],
445
+                    'fees'             => $details['fees'],
446
+                );
447
+
448
+                $item_columns = array_keys ( $fields );
449
+
450
+                foreach ( $fields as $key => $val ) {
451
+                    if ( is_null( $val ) ) {
452
+                        $val = '';
453
+                    }
454
+                    $val = maybe_serialize( $val );
455
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
456
+                }
457
+
458
+                $fields = implode( ', ', $fields );
459
+                $item_rows[] = "($fields)";
460
+            }
461
+
462
+            $item_rows    = implode( ', ', $item_rows );
463
+            $item_columns = implode( ', ', $item_columns );
464
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
465
+        }
466
+
467
+        if ( empty( $invoice_rows ) ) {
468
+            return;
469
+        }
470
+
471
+        $invoice_rows = implode( ', ', $invoice_rows );
472
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
473
+
474
+    }
475
+
476
+    /**
477
+     * Migrates old invoices to new invoices.
478
+     *
479
+     */
480
+    public static function rename_gateways_label() {
481
+        global $wpdb;
482
+
483
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
484
+
485
+            $wpdb->update(
486
+                $wpdb->prefix . 'getpaid_invoices',
487
+                array( 'gateway' => $gateway ),
488
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
489
+                '%s',
490
+                '%s'
491
+            );
492
+
493
+        }
494
+    }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.0.2
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * The main installer/updater class.
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param string $upgrade_from The current invoicing version.
27 27
 	 */
28
-	public function upgrade_db( $upgrade_from ) {
28
+	public function upgrade_db($upgrade_from) {
29 29
 
30 30
 		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
31
+		update_option('wpinv_version', WPINV_VERSION);
32 32
 
33 33
 		// Setup the invoice Custom Post Type.
34 34
 		GetPaid_Post_Types::register_post_types();
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		// Create any missing database tables.
49 49
 		$method = "upgrade_from_$upgrade_from";
50 50
 
51
-		if ( method_exists( $this, $method ) ) {
51
+		if (method_exists($this, $method)) {
52 52
 			$this->$method();
53 53
 		}
54 54
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->create_invoice_items_table();
65 65
 
66 66
 		// Save default tax rates.
67
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
67
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
68 68
 	}
69 69
 
70 70
 	/**
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 		global $wpdb;
76 76
 
77 77
 		// Invoices.
78
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
-		if ( ! empty( $results ) ) {
80
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
78
+		$results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
79
+		if (!empty($results)) {
80
+			$wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
81 81
 
82 82
 			// Clean post cache
83
-			foreach ( $results as $row ) {
84
-				clean_post_cache( $row->ID );
83
+			foreach ($results as $row) {
84
+				clean_post_cache($row->ID);
85 85
 			}
86 86
 
87 87
 		}
88 88
 
89 89
 		// Item meta key changes
90 90
 		$query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
-		$results = $wpdb->get_results( $query );
91
+		$results = $wpdb->get_results($query);
92 92
 
93
-		if ( ! empty( $results ) ) {
94
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
93
+		if (!empty($results)) {
94
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
95
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
96
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
97 97
 
98
-			foreach ( $results as $row ) {
99
-				clean_post_cache( $row->post_id );
98
+			foreach ($results as $row) {
99
+				clean_post_cache($row->post_id);
100 100
 			}
101 101
 
102 102
 		}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	public function upgrade_from_207() {
131 131
 		global $wpdb;
132
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
132
+		$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);");
133 133
 	}
134 134
 
135 135
 	/**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 */
139 139
 	public function add_capabilities() {
140
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
140
+		$GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing');
141 141
 	}
142 142
 
143 143
 	/**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 
153 153
 				// Checkout page.
154 154
 				'checkout_page' => array(
155
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
155
+					'name'      => _x('gp-checkout', 'Page slug', 'invoicing'),
156
+					'title'     => _x('Checkout', 'Page title', 'invoicing'),
157 157
 					'content'   => '
158 158
 						<!-- wp:shortcode -->
159 159
 						[wpinv_checkout]
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 
165 165
 				// Invoice history page.
166 166
 				'invoice_history_page' => array(
167
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
167
+					'name'    => _x('gp-invoices', 'Page slug', 'invoicing'),
168
+					'title'   => _x('My Invoices', 'Page title', 'invoicing'),
169 169
 					'content' => '
170 170
 					<!-- wp:shortcode -->
171 171
 					[wpinv_history]
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 
177 177
 				// Success page content.
178 178
 				'success_page' => array(
179
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
179
+					'name'     => _x('gp-receipt', 'Page slug', 'invoicing'),
180
+					'title'    => _x('Payment Confirmation', 'Page title', 'invoicing'),
181 181
 					'content'  => '
182 182
 					<!-- wp:shortcode -->
183 183
 					[wpinv_receipt]
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 
189 189
 				// Failure page content.
190 190
 				'failure_page' => array(
191
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
191
+					'name'    => _x('gp-transaction-failed', 'Page slug', 'invoicing'),
192
+					'title'   => _x('Transaction Failed', 'Page title', 'invoicing'),
193
+					'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'),
194 194
 					'parent'  => 'gp-checkout',
195 195
 				),
196 196
 
197 197
 				// Subscriptions history page.
198 198
 				'invoice_subscription_page' => array(
199
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
199
+					'name'    => _x('gp-subscriptions', 'Page slug', 'invoicing'),
200
+					'title'   => _x('My Subscriptions', 'Page title', 'invoicing'),
201 201
 					'content' => '
202 202
 					<!-- wp:shortcode -->
203 203
 					[wpinv_subscriptions]
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 			)
210 210
 		);
211 211
 
212
-		foreach ( $pages as $key => $page ) {
213
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
+		foreach ($pages as $key => $page) {
213
+			wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']);
214 214
 		}
215 215
 
216 216
 	}
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
 		global $wpdb;
225 225
 
226
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
226
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
227 227
 
228 228
 		// Create tables.
229 229
 		$charset_collate = $wpdb->get_charset_collate();
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 			KEY customer_and_status (customer_id, status)
251 251
 		  ) $charset_collate;";
252 252
 
253
-		dbDelta( $sql );
253
+		dbDelta($sql);
254 254
 
255 255
 	}
256 256
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	public function create_invoices_table() {
262 262
 		global $wpdb;
263 263
 
264
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
264
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
265 265
 
266 266
 		// Create tables.
267 267
 		$charset_collate = $wpdb->get_charset_collate();
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 			KEY `key` (`key`)
302 302
 		  ) $charset_collate;";
303 303
 
304
-		dbDelta( $sql );
304
+		dbDelta($sql);
305 305
 
306 306
 	}
307 307
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	public function create_invoice_items_table() {
313 313
 		global $wpdb;
314 314
 
315
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
315
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
316 316
 
317 317
 		// Create tables.
318 318
 		$charset_collate = $wpdb->get_charset_collate();
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 			KEY post_id (post_id)
339 339
 		  ) $charset_collate;";
340 340
 
341
-		dbDelta( $sql );
341
+		dbDelta($sql);
342 342
 
343 343
 	}
344 344
 
@@ -351,40 +351,40 @@  discard block
 block discarded – undo
351 351
 
352 352
 		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
353 353
 		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
354
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
354
+		$migrated            = $wpdb->get_col("SELECT post_id FROM $invoices_table");
355 355
 		$invoices            = array_unique(
356 356
 			get_posts(
357 357
 				array(
358
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
358
+					'post_type'      => array('wpi_invoice', 'wpi_quote'),
359 359
 					'posts_per_page' => -1,
360 360
 					'fields'         => 'ids',
361
-					'post_status'    => array_keys( get_post_stati() ),
361
+					'post_status'    => array_keys(get_post_stati()),
362 362
 					'exclude'        => (array) $migrated,
363 363
 				)
364 364
 			)
365 365
 		);
366 366
 
367 367
 		// Abort if we do not have any invoices.
368
-		if ( empty( $invoices ) ) {
368
+		if (empty($invoices)) {
369 369
 			return;
370 370
 		}
371 371
 
372
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
372
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
373 373
 
374 374
 		$invoice_rows = array();
375
-		foreach ( $invoices as $invoice ) {
375
+		foreach ($invoices as $invoice) {
376 376
 
377
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
377
+			$invoice = new WPInv_Legacy_Invoice($invoice);
378 378
 
379
-			if ( empty( $invoice->ID ) ) {
379
+			if (empty($invoice->ID)) {
380 380
 				return;
381 381
 			}
382 382
 
383
-			$fields = array (
383
+			$fields = array(
384 384
 				'post_id'        => $invoice->ID,
385 385
 				'number'         => $invoice->get_number(),
386 386
 				'key'            => $invoice->get_key(),
387
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
387
+				'type'           => str_replace('wpi_', '', $invoice->post_type),
388 388
 				'mode'           => $invoice->mode,
389 389
 				'user_ip'        => $invoice->get_ip(),
390 390
 				'first_name'     => $invoice->get_first_name(),
@@ -413,27 +413,27 @@  discard block
 block discarded – undo
413 413
 				'custom_meta'    => $invoice->payment_meta
414 414
 			);
415 415
 
416
-			foreach ( $fields as $key => $val ) {
417
-				if ( is_null( $val ) ) {
416
+			foreach ($fields as $key => $val) {
417
+				if (is_null($val)) {
418 418
 					$val = '';
419 419
 				}
420
-				$val = maybe_serialize( $val );
421
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
420
+				$val = maybe_serialize($val);
421
+				$fields[$key] = $wpdb->prepare('%s', $val);
422 422
 			}
423 423
 
424
-			$fields = implode( ', ', $fields );
424
+			$fields = implode(', ', $fields);
425 425
 			$invoice_rows[] = "($fields)";
426 426
 
427 427
 			$item_rows    = array();
428 428
 			$item_columns = array();
429
-			foreach ( $invoice->get_cart_details() as $details ) {
429
+			foreach ($invoice->get_cart_details() as $details) {
430 430
 				$fields = array(
431 431
 					'post_id'          => $invoice->ID,
432 432
 					'item_id'          => $details['id'],
433 433
 					'item_name'        => $details['name'],
434
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
434
+					'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
435 435
 					'vat_rate'         => $details['vat_rate'],
436
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
436
+					'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
437 437
 					'tax'              => $details['tax'],
438 438
 					'item_price'       => $details['item_price'],
439 439
 					'custom_price'     => $details['custom_price'],
@@ -445,31 +445,31 @@  discard block
 block discarded – undo
445 445
 					'fees'             => $details['fees'],
446 446
 				);
447 447
 
448
-				$item_columns = array_keys ( $fields );
448
+				$item_columns = array_keys($fields);
449 449
 
450
-				foreach ( $fields as $key => $val ) {
451
-					if ( is_null( $val ) ) {
450
+				foreach ($fields as $key => $val) {
451
+					if (is_null($val)) {
452 452
 						$val = '';
453 453
 					}
454
-					$val = maybe_serialize( $val );
455
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
454
+					$val = maybe_serialize($val);
455
+					$fields[$key] = $wpdb->prepare('%s', $val);
456 456
 				}
457 457
 
458
-				$fields = implode( ', ', $fields );
458
+				$fields = implode(', ', $fields);
459 459
 				$item_rows[] = "($fields)";
460 460
 			}
461 461
 
462
-			$item_rows    = implode( ', ', $item_rows );
463
-			$item_columns = implode( ', ', $item_columns );
464
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
462
+			$item_rows    = implode(', ', $item_rows);
463
+			$item_columns = implode(', ', $item_columns);
464
+			$wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
465 465
 		}
466 466
 
467
-		if ( empty( $invoice_rows ) ) {
467
+		if (empty($invoice_rows)) {
468 468
 			return;
469 469
 		}
470 470
 
471
-		$invoice_rows = implode( ', ', $invoice_rows );
472
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
471
+		$invoice_rows = implode(', ', $invoice_rows);
472
+		$wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
473 473
 
474 474
 	}
475 475
 
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
 	public static function rename_gateways_label() {
481 481
 		global $wpdb;
482 482
 
483
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
483
+		foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) {
484 484
 
485 485
 			$wpdb->update(
486 486
 				$wpdb->prefix . 'getpaid_invoices',
487
-				array( 'gateway' => $gateway ),
488
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
487
+				array('gateway' => $gateway),
488
+				array('gateway' => wpinv_get_gateway_admin_label($gateway)),
489 489
 				'%s',
490 490
 				'%s'
491 491
 			);
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-payment-meta.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,10 +21,10 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice = new WPInv_Invoice( $post );
27
+        $invoice = new WPInv_Invoice($post);
28 28
 
29 29
         ?>
30 30
 
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
                                 'id'          => 'wpinv_key',
48 48
                                 'name'        => 'wpinv_key',
49 49
                                 'label'       => sprintf(
50
-                                    __( '%s Key:', 'invoicing' ),
51
-                                    ucfirst( $invoice->get_invoice_quote_type() )
50
+                                    __('%s Key:', 'invoicing'),
51
+                                    ucfirst($invoice->get_invoice_quote_type())
52 52
                                 ),
53 53
                                 'label_type'  => 'vertical',
54 54
                                 'class'       => 'form-control-sm',
55
-                                'value'       => $invoice->get_key( 'edit' ),
55
+                                'value'       => $invoice->get_key('edit'),
56 56
                                 'extra_attributes' => array(
57 57
                                     'onclick'  => 'this.select();',
58 58
                                     'readonly' => 'true',
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
                                 'id'          => 'wpinv_view_url',
68 68
                                 'name'        => 'wpinv_view_url',
69 69
                                 'label'       => sprintf(
70
-                                    __( '%s URL:', 'invoicing' ),
71
-                                    ucfirst( $invoice->get_invoice_quote_type() )
70
+                                    __('%s URL:', 'invoicing'),
71
+                                    ucfirst($invoice->get_invoice_quote_type())
72 72
                                 ),
73 73
                                 'label_type'  => 'vertical',
74 74
                                 'class'       => 'form-control-sm',
@@ -81,7 +81,7 @@  discard block
 block discarded – undo
81 81
                         );
82 82
 
83 83
                         // If the invoice is paid...
84
-                        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
84
+                        if ($invoice->is_paid() || $invoice->is_refunded()) {
85 85
 
86 86
                             // Payment date.
87 87
                             echo aui()->input(
@@ -89,11 +89,11 @@  discard block
 block discarded – undo
89 89
                                     'type'        => 'datepicker',
90 90
                                     'id'          => 'wpinv_date_completed',
91 91
                                     'name'        => 'date_completed',
92
-                                    'label'       => __( 'Payment Date:', 'invoicing' ),
92
+                                    'label'       => __('Payment Date:', 'invoicing'),
93 93
                                     'label_type'  => 'vertical',
94 94
                                     'placeholder' => 'YYYY-MM-DD 00:00',
95 95
                                     'class'       => 'form-control-sm',
96
-                                    'value'       => $invoice->get_date_completed( 'edit' ),
96
+                                    'value'       => $invoice->get_date_completed('edit'),
97 97
                                     'extra_attributes' => array(
98 98
                                         'data-enable-time' => 'true',
99 99
                                         'data-time_24hr'   => 'true',
@@ -108,10 +108,10 @@  discard block
 block discarded – undo
108 108
                                     'type'        => 'text',
109 109
                                     'id'          => 'wpinv_gateway',
110 110
                                     'name'        => '',
111
-                                    'label'       => __( 'Gateway:', 'invoicing' ),
111
+                                    'label'       => __('Gateway:', 'invoicing'),
112 112
                                     'label_type'  => 'vertical',
113 113
                                     'class'       => 'form-control-sm',
114
-                                    'value'       => wpinv_get_gateway_admin_label( $invoice->get_gateway( 'edit' ) ),
114
+                                    'value'       => wpinv_get_gateway_admin_label($invoice->get_gateway('edit')),
115 115
                                     'extra_attributes' => array(
116 116
                                         'onclick'  => 'this.select();',
117 117
                                         'readonly' => 'true',
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
                                     'type'        => 'text',
126 126
                                     'id'          => 'wpinv_transaction_id',
127 127
                                     'name'        => 'wpinv_transaction_id',
128
-                                    'label'       => __( 'Transaction ID:', 'invoicing' ),
128
+                                    'label'       => __('Transaction ID:', 'invoicing'),
129 129
                                     'label_type'  => 'vertical',
130 130
                                     'class'       => 'form-control-sm',
131
-                                    'value'       => $invoice->get_transaction_id( 'edit' ),
132
-                                    'help_text'   => apply_filters( 'wpinv_invoice_transaction_link_' . $invoice->get_gateway( 'edit' ), '', $invoice->get_transaction_id(), $invoice ),
131
+                                    'value'       => $invoice->get_transaction_id('edit'),
132
+                                    'help_text'   => apply_filters('wpinv_invoice_transaction_link_' . $invoice->get_gateway('edit'), '', $invoice->get_transaction_id(), $invoice),
133 133
                                     'extra_attributes' => array(
134 134
                                         'onclick'  => 'this.select();',
135 135
                                         'readonly' => 'true',
@@ -143,10 +143,10 @@  discard block
 block discarded – undo
143 143
                                     'type'        => 'text',
144 144
                                     'id'          => 'wpinv_currency',
145 145
                                     'name'        => 'wpinv_currency',
146
-                                    'label'       => __( 'Currency:', 'invoicing' ),
146
+                                    'label'       => __('Currency:', 'invoicing'),
147 147
                                     'label_type'  => 'vertical',
148 148
                                     'class'       => 'form-control-sm',
149
-                                    'value'       => $invoice->get_currency( 'edit' ),
149
+                                    'value'       => $invoice->get_currency('edit'),
150 150
                                     'extra_attributes' => array(
151 151
                                         'onclick'  => 'this.select();',
152 152
                                         'readonly' => 'true',
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 
157 157
                         } else {
158 158
 
159
-                            if ( 'wpi_invoice' == $invoice->get_post_type() ) {
159
+                            if ('wpi_invoice' == $invoice->get_post_type()) {
160 160
 
161 161
                                 // Payment URL.
162 162
                                 echo aui()->input(
@@ -164,7 +164,7 @@  discard block
 block discarded – undo
164 164
                                         'type'        => 'text',
165 165
                                         'id'          => 'wpinv_payment_url',
166 166
                                         'name'        => 'wpinv_payment_url',
167
-                                        'label'       => __( 'Payment URL:', 'invoicing' ),
167
+                                        'label'       => __('Payment URL:', 'invoicing'),
168 168
                                         'label_type'  => 'vertical',
169 169
                                         'class'       => 'form-control-sm',
170 170
                                         'value'       => $invoice->get_checkout_payment_url(),
@@ -180,13 +180,13 @@  discard block
 block discarded – undo
180 180
                                     array(
181 181
                                         'id'               => 'wpinv_gateway',
182 182
                                         'name'             => 'wpinv_gateway',
183
-                                        'label'            => __( 'Gateway:', 'invoicing' ),
183
+                                        'label'            => __('Gateway:', 'invoicing'),
184 184
                                         'label_type'       => 'vertical',
185
-                                        'placeholder'      => __( 'Select Gateway', 'invoicing' ),
186
-                                        'value'            => $invoice->get_gateway( 'edit' ),
185
+                                        'placeholder'      => __('Select Gateway', 'invoicing'),
186
+                                        'value'            => $invoice->get_gateway('edit'),
187 187
                                         'select2'          => true,
188 188
                                         'data-allow-clear' => 'false',
189
-                                        'options'          => wp_list_pluck( wpinv_get_enabled_payment_gateways( true ), 'admin_label' ),
189
+                                        'options'          => wp_list_pluck(wpinv_get_enabled_payment_gateways(true), 'admin_label'),
190 190
                                     )
191 191
                                 );
192 192
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,14 +21,14 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the invoice.
27
-        $invoice  = new WPInv_Invoice( $post );
28
-        $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-        $customer = new WP_User( $customer );
30
-        $display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
27
+        $invoice  = new WPInv_Invoice($post);
28
+        $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id();
29
+        $customer = new WP_User($customer);
30
+        $display  = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email);
31
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
32 32
 
33 33
         ?>
34 34
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
                         <div class="col-12 col-sm-6">
44 44
                             <div id="getpaid-invoice-user-id-wrapper" class="form-group">
45 45
                                 <div>
46
-                                    <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label>
46
+                                    <label for="post_author_override"><?php _e('Customer', 'invoicing'); ?></label>
47 47
                                 </div>
48 48
                                 <div>
49
-                                    <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>">
50
-                                        <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo sanitize_text_field( $display ); ?> </option>)
49
+                                    <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>">
50
+                                        <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo sanitize_text_field($display); ?> </option>)
51 51
                                     </select>
52 52
                                 </div>
53 53
                             </div>
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
                                             'type'        => 'text',
61 61
                                             'id'          => 'getpaid-invoice-new-user-email',
62 62
                                             'name'        => 'wpinv_email',
63
-                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
63
+                                            'label'       => __('Email', 'invoicing') . '<span class="required">*</span>',
64 64
                                             'label_type'  => 'vertical',
65 65
                                             'placeholder' => '[email protected]',
66 66
                                             'class'       => 'form-control-sm',
@@ -70,18 +70,18 @@  discard block
 block discarded – undo
70 70
                             </div>
71 71
                         </div>
72 72
                         <div class="col-12 col-sm-6 form-group mt-sm-4">
73
-                            <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
73
+                            <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
74 74
                                 <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)">
75 75
                                     <i aria-hidden="true" class="fa fa-refresh"></i>
76
-                                    <?php _e( 'Fill User Details', 'invoicing' );?>
76
+                                    <?php _e('Fill User Details', 'invoicing'); ?>
77 77
                                 </a>
78 78
                                 <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)">
79 79
                                     <i aria-hidden="true" class="fa fa-plus"></i>
80
-                                    <?php _e( 'Add New User', 'invoicing' );?>
80
+                                    <?php _e('Add New User', 'invoicing'); ?>
81 81
                                 </a>
82 82
                                 <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)">
83 83
                                     <i aria-hidden="true" class="fa fa-close"></i>
84
-                                    <?php _e( 'Cancel', 'invoicing' );?>
84
+                                    <?php _e('Cancel', 'invoicing'); ?>
85 85
                                 </a>
86 86
                             <?php endif; ?>
87 87
                         </div>
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
                                         'type'        => 'text',
95 95
                                         'id'          => 'wpinv_first_name',
96 96
                                         'name'        => 'wpinv_first_name',
97
-                                        'label'       => __( 'First Name', 'invoicing' ),
97
+                                        'label'       => __('First Name', 'invoicing'),
98 98
                                         'label_type'  => 'vertical',
99 99
                                         'placeholder' => '',
100 100
                                         'class'       => 'form-control-sm',
101
-                                        'value'       => $invoice->get_first_name( 'edit' ),
101
+                                        'value'       => $invoice->get_first_name('edit'),
102 102
                                     )
103 103
                                 );
104 104
                             ?>
@@ -110,11 +110,11 @@  discard block
 block discarded – undo
110 110
                                         'type'        => 'text',
111 111
                                         'id'          => 'wpinv_last_name',
112 112
                                         'name'        => 'wpinv_last_name',
113
-                                        'label'       => __( 'Last Name', 'invoicing' ),
113
+                                        'label'       => __('Last Name', 'invoicing'),
114 114
                                         'label_type'  => 'vertical',
115 115
                                         'placeholder' => '',
116 116
                                         'class'       => 'form-control-sm',
117
-                                        'value'       => $invoice->get_last_name( 'edit' ),
117
+                                        'value'       => $invoice->get_last_name('edit'),
118 118
                                     )
119 119
                                 );
120 120
                             ?>
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
                                         'type'        => 'text',
130 130
                                         'id'          => 'wpinv_company',
131 131
                                         'name'        => 'wpinv_company',
132
-                                        'label'       => __( 'Company', 'invoicing' ),
132
+                                        'label'       => __('Company', 'invoicing'),
133 133
                                         'label_type'  => 'vertical',
134 134
                                         'placeholder' => '',
135 135
                                         'class'       => 'form-control-sm',
136
-                                        'value'       => $invoice->get_company( 'edit' ),
136
+                                        'value'       => $invoice->get_company('edit'),
137 137
                                     )
138 138
                                 );
139 139
                             ?>
@@ -145,11 +145,11 @@  discard block
 block discarded – undo
145 145
                                         'type'        => 'text',
146 146
                                         'id'          => 'wpinv_vat_number',
147 147
                                         'name'        => 'wpinv_vat_number',
148
-                                        'label'       => __( 'Vat Number', 'invoicing' ),
148
+                                        'label'       => __('Vat Number', 'invoicing'),
149 149
                                         'label_type'  => 'vertical',
150 150
                                         'placeholder' => '',
151 151
                                         'class'       => 'form-control-sm',
152
-                                        'value'       => $invoice->get_vat_number( 'edit' ),
152
+                                        'value'       => $invoice->get_vat_number('edit'),
153 153
                                     )
154 154
                                 );
155 155
                             ?>
@@ -164,11 +164,11 @@  discard block
 block discarded – undo
164 164
                                         'type'        => 'text',
165 165
                                         'id'          => 'wpinv_address',
166 166
                                         'name'        => 'wpinv_address',
167
-                                        'label'       => __( 'Address', 'invoicing' ),
167
+                                        'label'       => __('Address', 'invoicing'),
168 168
                                         'label_type'  => 'vertical',
169 169
                                         'placeholder' => '',
170 170
                                         'class'       => 'form-control-sm',
171
-                                        'value'       => $invoice->get_address( 'edit' ),
171
+                                        'value'       => $invoice->get_address('edit'),
172 172
                                     )
173 173
                                 );
174 174
                             ?>
@@ -180,11 +180,11 @@  discard block
 block discarded – undo
180 180
                                         'type'        => 'text',
181 181
                                         'id'          => 'wpinv_city',
182 182
                                         'name'        => 'wpinv_city',
183
-                                        'label'       => __( 'City', 'invoicing' ),
183
+                                        'label'       => __('City', 'invoicing'),
184 184
                                         'label_type'  => 'vertical',
185 185
                                         'placeholder' => '',
186 186
                                         'class'       => 'form-control-sm',
187
-                                        'value'       => $invoice->get_city( 'edit' ),
187
+                                        'value'       => $invoice->get_city('edit'),
188 188
                                     )
189 189
                                 );
190 190
                             ?>
@@ -198,11 +198,11 @@  discard block
 block discarded – undo
198 198
                                     array(
199 199
                                         'id'          => 'wpinv_country',
200 200
                                         'name'        => 'wpinv_country',
201
-                                        'label'       => __( 'Country', 'invoicing' ),
201
+                                        'label'       => __('Country', 'invoicing'),
202 202
                                         'label_type'  => 'vertical',
203
-                                        'placeholder' => __( 'Choose a country', 'invoicing' ),
203
+                                        'placeholder' => __('Choose a country', 'invoicing'),
204 204
                                         'class'       => 'form-control-sm',
205
-                                        'value'       => $invoice->get_country( 'edit' ),
205
+                                        'value'       => $invoice->get_country('edit'),
206 206
                                         'options'     => wpinv_get_country_list(),
207 207
                                         'data-allow-clear' => 'false',
208 208
                                         'select2'          => true,
@@ -213,20 +213,20 @@  discard block
 block discarded – undo
213 213
                         <div class="col-12 col-sm-6">
214 214
                             <?php
215 215
 
216
-                                $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
216
+                                $states = wpinv_get_country_states($invoice->get_country('edit'));
217 217
 
218
-                                if ( empty( $states ) ) {
218
+                                if (empty($states)) {
219 219
 
220 220
                                     echo aui()->input(
221 221
                                         array(
222 222
                                             'type'        => 'text',
223 223
                                             'id'          => 'wpinv_state',
224 224
                                             'name'        => 'wpinv_state',
225
-                                            'label'       => __( 'State', 'invoicing' ),
225
+                                            'label'       => __('State', 'invoicing'),
226 226
                                             'label_type'  => 'vertical',
227 227
                                             'placeholder' => '',
228 228
                                             'class'       => 'form-control-sm',
229
-                                            'value'       => $invoice->get_state( 'edit' ),
229
+                                            'value'       => $invoice->get_state('edit'),
230 230
                                         )
231 231
                                     );
232 232
 
@@ -236,11 +236,11 @@  discard block
 block discarded – undo
236 236
                                         array(
237 237
                                             'id'          => 'wpinv_state',
238 238
                                             'name'        => 'wpinv_state',
239
-                                            'label'       => __( 'State', 'invoicing' ),
239
+                                            'label'       => __('State', 'invoicing'),
240 240
                                             'label_type'  => 'vertical',
241
-                                            'placeholder' => __( 'Select a state', 'invoicing' ),
241
+                                            'placeholder' => __('Select a state', 'invoicing'),
242 242
                                             'class'       => 'form-control-sm',
243
-                                            'value'       => $invoice->get_state( 'edit' ),
243
+                                            'value'       => $invoice->get_state('edit'),
244 244
                                             'options'     => $states,
245 245
                                             'data-allow-clear' => 'false',
246 246
                                             'select2'          => true,
@@ -261,11 +261,11 @@  discard block
 block discarded – undo
261 261
                                         'type'        => 'text',
262 262
                                         'id'          => 'wpinv_zip',
263 263
                                         'name'        => 'wpinv_zip',
264
-                                        'label'       => __( 'Zip / Postal Code', 'invoicing' ),
264
+                                        'label'       => __('Zip / Postal Code', 'invoicing'),
265 265
                                         'label_type'  => 'vertical',
266 266
                                         'placeholder' => '',
267 267
                                         'class'       => 'form-control-sm',
268
-                                        'value'       => $invoice->get_zip( 'edit' ),
268
+                                        'value'       => $invoice->get_zip('edit'),
269 269
                                     )
270 270
                                 );
271 271
                             ?>
@@ -277,11 +277,11 @@  discard block
 block discarded – undo
277 277
                                         'type'        => 'text',
278 278
                                         'id'          => 'wpinv_phone',
279 279
                                         'name'        => 'wpinv_phone',
280
-                                        'label'       => __( 'Phone', 'invoicing' ),
280
+                                        'label'       => __('Phone', 'invoicing'),
281 281
                                         'label_type'  => 'vertical',
282 282
                                         'placeholder' => '',
283 283
                                         'class'       => 'form-control-sm',
284
-                                        'value'       => $invoice->get_phone( 'edit' ),
284
+                                        'value'       => $invoice->get_phone('edit'),
285 285
                                     )
286 286
                                 );
287 287
                             ?>
@@ -297,49 +297,49 @@  discard block
 block discarded – undo
297 297
 	 *
298 298
 	 * @param int $post_id
299 299
 	 */
300
-	public static function save( $post_id ) {
300
+	public static function save($post_id) {
301 301
 
302 302
         // Prepare the invoice.
303
-        $invoice = new WPInv_Invoice( $post_id );
303
+        $invoice = new WPInv_Invoice($post_id);
304 304
 
305 305
         // Load new data.
306 306
         $invoice->set_props(
307 307
 			array(
308
-                'template'             => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
309
-                'email_cc'             => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
310
-                'disable_taxes'        => isset( $_POST['disable_taxes'] ),
311
-                'currency'             => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null,
312
-                'gateway'              => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null,
313
-                'address'              => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null,
314
-                'vat_number'           => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null,
315
-                'company'              => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null,
316
-                'zip'                  => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null,
317
-                'state'                => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null,
318
-                'city'                 => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null,
319
-                'country'              => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null,
320
-                'phone'                => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null,
321
-                'first_name'           => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null,
322
-                'last_name'            => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null,
323
-                'author'               => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null,
324
-                'date_created'         => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null,
325
-                'due_date'             => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
326
-                'number'               => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
327
-                'status'               => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
308
+                'template'             => isset($_POST['wpinv_template']) ? wpinv_clean($_POST['wpinv_template']) : null,
309
+                'email_cc'             => isset($_POST['wpinv_cc']) ? wpinv_clean($_POST['wpinv_cc']) : null,
310
+                'disable_taxes'        => isset($_POST['disable_taxes']),
311
+                'currency'             => isset($_POST['wpinv_currency']) ? wpinv_clean($_POST['wpinv_currency']) : null,
312
+                'gateway'              => ($invoice->needs_payment() && isset($_POST['wpinv_gateway'])) ? wpinv_clean($_POST['wpinv_gateway']) : null,
313
+                'address'              => isset($_POST['wpinv_address']) ? wpinv_clean($_POST['wpinv_address']) : null,
314
+                'vat_number'           => isset($_POST['wpinv_vat_number']) ? wpinv_clean($_POST['wpinv_vat_number']) : null,
315
+                'company'              => isset($_POST['wpinv_company']) ? wpinv_clean($_POST['wpinv_company']) : null,
316
+                'zip'                  => isset($_POST['wpinv_zip']) ? wpinv_clean($_POST['wpinv_zip']) : null,
317
+                'state'                => isset($_POST['wpinv_state']) ? wpinv_clean($_POST['wpinv_state']) : null,
318
+                'city'                 => isset($_POST['wpinv_city']) ? wpinv_clean($_POST['wpinv_city']) : null,
319
+                'country'              => isset($_POST['wpinv_country']) ? wpinv_clean($_POST['wpinv_country']) : null,
320
+                'phone'                => isset($_POST['wpinv_phone']) ? wpinv_clean($_POST['wpinv_phone']) : null,
321
+                'first_name'           => isset($_POST['wpinv_first_name']) ? wpinv_clean($_POST['wpinv_first_name']) : null,
322
+                'last_name'            => isset($_POST['wpinv_last_name']) ? wpinv_clean($_POST['wpinv_last_name']) : null,
323
+                'author'               => isset($_POST['post_author_override']) ? wpinv_clean($_POST['post_author_override']) : null,
324
+                'date_created'         => isset($_POST['date_created']) ? wpinv_clean($_POST['date_created']) : null,
325
+                'due_date'             => isset($_POST['wpinv_due_date']) ? wpinv_clean($_POST['wpinv_due_date']) : null,
326
+                'number'               => isset($_POST['wpinv_number']) ? wpinv_clean($_POST['wpinv_number']) : null,
327
+                'status'               => isset($_POST['wpinv_status']) ? wpinv_clean($_POST['wpinv_status']) : null,
328 328
 			)
329 329
         );
330 330
 
331 331
         // Discount code.
332
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
332
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
333 333
 
334
-            if ( isset( $_POST['wpinv_discount_code'] ) ) {
335
-                $invoice->set_discount_code( $_POST['wpinv_discount_code'] );
334
+            if (isset($_POST['wpinv_discount_code'])) {
335
+                $invoice->set_discount_code($_POST['wpinv_discount_code']);
336 336
             }
337 337
 
338
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
339
-            if ( $discount->exists() ) {
340
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
338
+            $discount = new WPInv_Discount($invoice->get_discount_code());
339
+            if ($discount->exists()) {
340
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
341 341
             } else {
342
-                $invoice->remove_discount( 'discount_code' );
342
+                $invoice->remove_discount('discount_code');
343 343
             }
344 344
 
345 345
             // Recalculate totals.
@@ -348,17 +348,17 @@  discard block
 block discarded – undo
348 348
         }
349 349
 
350 350
         // If we're creating a new user...
351
-        if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( $_POST['wpinv_email'] ) ) {
351
+        if (!empty($_POST['wpinv_new_user']) && is_email($_POST['wpinv_email'])) {
352 352
 
353 353
             // Attempt to create the user.
354
-            $user = wpinv_create_user( sanitize_email( $_POST['wpinv_email'] ) );
354
+            $user = wpinv_create_user(sanitize_email($_POST['wpinv_email']));
355 355
 
356 356
 
357 357
             // If successful, update the invoice author.
358
-            if ( is_numeric( $user ) ) {
359
-                $invoice->set_author( $user );
358
+            if (is_numeric($user)) {
359
+                $invoice->set_author($user);
360 360
             } else {
361
-                wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
361
+                wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__);
362 362
             }
363 363
         }
364 364
 
@@ -372,23 +372,23 @@  discard block
 block discarded – undo
372 372
         $GLOBALS['wpinv_skip_invoice_notification'] = false;
373 373
 
374 374
         // (Maybe) send new user notification.
375
-        if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', true ) ) {
376
-            wp_send_new_user_notifications( $user, 'user' );
375
+        if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', true)) {
376
+            wp_send_new_user_notifications($user, 'user');
377 377
         }
378 378
 
379
-        if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) {
379
+        if (!empty($_POST['send_to_customer']) && !$invoice->is_draft()) {
380 380
 
381
-            $sent = getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
381
+            $sent = getpaid()->get('invoice_emails')->user_invoice($invoice, true);
382 382
 
383
-            if ( $sent ) {
384
-                getpaid_admin()->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
383
+            if ($sent) {
384
+                getpaid_admin()->show_success(__('Invoice was successfully sent to the customer', 'invoicing'));
385 385
             } else {
386
-                getpaid_admin()->show_error( __( 'Could not send the invoice to the customer', 'invoicing' ) );
386
+                getpaid_admin()->show_error(__('Could not send the invoice to the customer', 'invoicing'));
387 387
             }
388 388
 
389 389
         }
390 390
 
391 391
         // Fires after an invoice is saved.
392
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
392
+		do_action('wpinv_invoice_metabox_saved', $invoice);
393 393
 	}
394 394
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 1 patch
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,64 +100,64 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
             return $response;
142 142
         }
143 143
 
144
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
144
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
145 145
 
146 146
         // Save the payment token.
147
-        if ( $save ) {
147
+        if ($save) {
148 148
             $this->save_token(
149 149
                 array(
150 150
                     'id'      => $response->customerPaymentProfileIdList[0],
151
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
151
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
152 152
                     'default' => true,
153
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
153
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
154 154
                 )
155 155
             );
156 156
         }
157 157
 
158 158
         // Add a note about the validation response.
159 159
         $invoice->add_note(
160
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
160
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
161 161
             false,
162 162
             false,
163 163
             true
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 	 * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176 176
 	 */
177
-	public function get_customer_profile( $profile_id ) {
177
+	public function get_customer_profile($profile_id) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             )
185 185
         );
186 186
 
187
-        return $this->post( $args, false );
187
+        return $this->post($args, false);
188 188
 
189 189
     }
190 190
 
@@ -199,10 +199,10 @@  discard block
 block discarded – undo
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200 200
 	 * @return string|WP_Error Profile id.
201 201
 	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
202
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
203 203
 
204 204
         // Remove non-digits from the number
205
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
205
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
206 206
 
207 207
         // Generate args.
208 208
         $args = array(
@@ -213,34 +213,34 @@  discard block
 block discarded – undo
213 213
 
214 214
                     // Billing information.
215 215
                     'billTo'           => array(
216
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
217
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
218
-                        'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
219
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
220
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
221
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
222
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
216
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
217
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
218
+                        'address'      => getpaid_limit_length($invoice->get_address(), 60),
219
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
220
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
221
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
222
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
223 223
                     ),
224 224
 
225 225
                     // Payment information.
226
-                    'payment'          => $this->get_payment_information( $submission_data['authorizenet'] )
226
+                    'payment'          => $this->get_payment_information($submission_data['authorizenet'])
227 227
                 ),
228
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
228
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
229 229
             )
230 230
         );
231 231
 
232
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
232
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
233 233
 
234
-        if ( is_wp_error( $response ) ) {
234
+        if (is_wp_error($response)) {
235 235
             return $response;
236 236
         }
237 237
 
238 238
         // Save the payment token.
239
-        if ( $save ) {
239
+        if ($save) {
240 240
             $this->save_token(
241 241
                 array(
242 242
                     'id'      => $response->customerPaymentProfileId,
243
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
243
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
244 244
                     'default' => true
245 245
                 )
246 246
             );
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
 
249 249
         // Add a note about the validation response.
250 250
         $invoice->add_note(
251
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
251
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
252 252
             false,
253 253
             false,
254 254
             true
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
 	 * @return string|WP_Error Profile id.
268 268
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
269 269
 	 */
270
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
270
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
271 271
 
272 272
         // Generate args.
273 273
         $args = array(
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
             )
279 279
         );
280 280
 
281
-        return $this->post( $args, false );
281
+        return $this->post($args, false);
282 282
 
283 283
     }
284 284
 
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
292 292
 	 * @return WP_Error|object
293 293
 	 */
294
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
294
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
295 295
 
296 296
         // Generate args.
297 297
         $args = array(
@@ -311,28 +311,28 @@  discard block
 block discarded – undo
311 311
                         )
312 312
                     ),
313 313
                     'order'                    => array(
314
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
314
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
315 315
                     ),
316
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
316
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
317 317
                     'tax'                      => array(
318 318
                         'amount'               => $invoice->get_total_tax(),
319
-                        'name'                 => __( 'TAX', 'invoicing' ),
319
+                        'name'                 => __('TAX', 'invoicing'),
320 320
                     ),
321
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
321
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
322 322
                     'customer'                 => array(
323
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
324
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
323
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
324
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
325 325
                     ),
326 326
                     'customerIP'               => $invoice->get_ip(),
327 327
                 )
328 328
             )
329 329
         );
330 330
 
331
-        if ( 0 == $invoice->get_total_tax() ) {
332
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
331
+        if (0 == $invoice->get_total_tax()) {
332
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
333 333
         }
334 334
 
335
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
335
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
336 336
 
337 337
     }
338 338
 
@@ -342,29 +342,29 @@  discard block
 block discarded – undo
342 342
      * @param stdClass $result Api response.
343 343
 	 * @param WPInv_Invoice $invoice Invoice.
344 344
 	 */
345
-	public function process_charge_response( $result, $invoice ) {
345
+	public function process_charge_response($result, $invoice) {
346 346
 
347 347
         wpinv_clear_errors();
348 348
 		$response_code = (int) $result->transactionResponse->responseCode;
349 349
 
350 350
 		// Succeeded.
351
-		if ( 1 == $response_code || 4 == $response_code ) {
351
+		if (1 == $response_code || 4 == $response_code) {
352 352
 
353 353
 			// Maybe set a transaction id.
354
-			if ( ! empty( $result->transactionResponse->transId ) ) {
355
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
354
+			if (!empty($result->transactionResponse->transId)) {
355
+				$invoice->set_transaction_id($result->transactionResponse->transId);
356 356
 			}
357 357
 
358
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
358
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
359 359
 
360
-			if ( 1 == $response_code ) {
360
+			if (1 == $response_code) {
361 361
 				return $invoice->mark_paid();
362 362
 			}
363 363
 
364
-			$invoice->set_status( 'wpi-onhold' );
364
+			$invoice->set_status('wpi-onhold');
365 365
         	$invoice->add_note(
366 366
                 sprintf(
367
-                    __( 'Held for review: %s', 'invoicing' ),
367
+                    __('Held for review: %s', 'invoicing'),
368 368
                     $result->transactionResponse->messages->message[0]->description
369 369
                 )
370 370
 			);
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
 
374 374
 		}
375 375
 
376
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
376
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
377 377
 
378
-        if ( ! empty( $result->transactionResponse->errors ) ) {
378
+        if (!empty($result->transactionResponse->errors)) {
379 379
             $errors = (object) $result->transactionResponse->errors;
380
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
380
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
381 381
         }
382 382
 
383 383
     }
@@ -389,10 +389,10 @@  discard block
 block discarded – undo
389 389
 	 * @param array $card Card details.
390 390
 	 * @return array
391 391
 	 */
392
-	public function get_payment_information( $card ) {
392
+	public function get_payment_information($card) {
393 393
         return array(
394 394
 
395
-            'creditCard'         => array (
395
+            'creditCard'         => array(
396 396
                 'cardNumber'     => $card['cc_number'],
397 397
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
398 398
                 'cardCode'       => $card['cc_cvv2'],
@@ -408,8 +408,8 @@  discard block
 block discarded – undo
408 408
 	 * @param WPInv_Invoice $invoice Invoice.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_customer_profile_meta_name( $invoice ) {
412
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
411
+	public function get_customer_profile_meta_name($invoice) {
412
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
413 413
     }
414 414
 
415 415
     /**
@@ -420,34 +420,34 @@  discard block
 block discarded – undo
420 420
      * @param WPInv_Invoice $invoice
421 421
 	 * @return WP_Error|string The payment profile id
422 422
 	 */
423
-	public function validate_submission_data( $submission_data, $invoice ) {
423
+	public function validate_submission_data($submission_data, $invoice) {
424 424
 
425 425
         // Validate authentication details.
426 426
         $auth = $this->get_auth_params();
427 427
 
428
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
429
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
428
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
429
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
430 430
         }
431 431
 
432 432
         // Validate the payment method.
433
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
434
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
433
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
434
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
435 435
         }
436 436
 
437 437
         // Are we adding a new payment method?
438
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
438
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
439 439
             return $submission_data['getpaid-authorizenet-payment-method'];
440 440
         }
441 441
 
442 442
         // Retrieve the customer profile id.
443
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
443
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
444 444
 
445 445
         // Create payment method.
446
-        if ( empty( $profile_id ) ) {
447
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
446
+        if (empty($profile_id)) {
447
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
448 448
         }
449 449
 
450
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
450
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
451 451
 
452 452
     }
453 453
 
@@ -458,16 +458,16 @@  discard block
 block discarded – undo
458 458
 	 * @param WPInv_Invoice $invoice Invoice.
459 459
 	 * @return array
460 460
 	 */
461
-	public function get_line_items( $invoice ) {
461
+	public function get_line_items($invoice) {
462 462
         $items = array();
463 463
 
464
-        foreach ( $invoice->get_items() as $item ) {
464
+        foreach ($invoice->get_items() as $item) {
465 465
 
466 466
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
467 467
             $items[] = array(
468
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
469
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
470
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
468
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
469
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
470
+                'description' => getpaid_limit_length($item->get_description(), 255),
471 471
                 'quantity'    => (string) $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(),
472 472
                 'unitPrice'   => (float) $amount,
473 473
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
@@ -475,15 +475,15 @@  discard block
 block discarded – undo
475 475
 
476 476
         }
477 477
 
478
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
478
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
479 479
 
480
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
480
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
481 481
 
482
-            if ( $amount > 0 ) {
482
+            if ($amount > 0) {
483 483
                 $items[] = array(
484
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
485
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
486
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
484
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
485
+                    'name'        => getpaid_limit_length($fee_name, 31),
486
+                    'description' => getpaid_limit_length($fee_name, 255),
487 487
                     'quantity'    => '1',
488 488
                     'unitPrice'   => (float) $amount,
489 489
                     'taxable'     => false,
@@ -504,36 +504,36 @@  discard block
 block discarded – undo
504 504
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
505 505
 	 * @return array
506 506
 	 */
507
-	public function process_payment( $invoice, $submission_data, $submission ) {
507
+	public function process_payment($invoice, $submission_data, $submission) {
508 508
 
509 509
         // Validate the submitted data.
510
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
510
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
511 511
 
512 512
         // Do we have an error?
513
-        if ( is_wp_error( $payment_profile_id ) ) {
514
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
515
-            wpinv_send_back_to_checkout( $invoice );
513
+        if (is_wp_error($payment_profile_id)) {
514
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
515
+            wpinv_send_back_to_checkout($invoice);
516 516
         }
517 517
 
518 518
         // Save the payment method to the order.
519
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
519
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
520 520
 
521 521
         // Check if this is a subscription or not.
522
-        $subscription = getpaid_get_invoice_subscription( $invoice );
523
-        if ( ! empty( $subscription ) ) {
524
-            $this->process_subscription( $invoice, $subscription );
522
+        $subscription = getpaid_get_invoice_subscription($invoice);
523
+        if (!empty($subscription)) {
524
+            $this->process_subscription($invoice, $subscription);
525 525
         }
526 526
 
527 527
         // If it is free, send to the success page.
528
-        if ( ! $invoice->needs_payment() ) {
528
+        if (!$invoice->needs_payment()) {
529 529
             $invoice->mark_paid();
530
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
530
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
531 531
         }
532 532
 
533 533
         // Charge the payment profile.
534
-        $this->process_initial_payment( $invoice );
534
+        $this->process_initial_payment($invoice);
535 535
 
536
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
536
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
537 537
 
538 538
         exit;
539 539
 
@@ -544,23 +544,23 @@  discard block
 block discarded – undo
544 544
 	 *
545 545
      * @param WPInv_Invoice $invoice Invoice.
546 546
 	 */
547
-	protected function process_initial_payment( $invoice ) {
547
+	protected function process_initial_payment($invoice) {
548 548
 
549
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
550
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
551
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
549
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
550
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
551
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
552 552
 
553 553
 		// Do we have an error?
554
-		if ( is_wp_error( $result ) ) {
555
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
556
-			wpinv_send_back_to_checkout( $invoice );
554
+		if (is_wp_error($result)) {
555
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
556
+			wpinv_send_back_to_checkout($invoice);
557 557
 		}
558 558
 
559 559
 		// Process the response.
560
-		$this->process_charge_response( $result, $invoice );
560
+		$this->process_charge_response($result, $invoice);
561 561
 
562
-		if ( wpinv_get_errors() ) {
563
-			wpinv_send_back_to_checkout( $invoice );
562
+		if (wpinv_get_errors()) {
563
+			wpinv_send_back_to_checkout($invoice);
564 564
 		}
565 565
 
566 566
 	}
@@ -571,24 +571,24 @@  discard block
 block discarded – undo
571 571
      * @param WPInv_Invoice $invoice Invoice.
572 572
      * @param WPInv_Subscription $subscription Subscription.
573 573
 	 */
574
-	public function process_subscription( $invoice, $subscription ) {
574
+	public function process_subscription($invoice, $subscription) {
575 575
 
576 576
         // Check if there is an initial amount to charge.
577
-        if ( (float) $invoice->get_total() > 0 ) {
578
-			$this->process_initial_payment( $invoice );
577
+        if ((float) $invoice->get_total() > 0) {
578
+			$this->process_initial_payment($invoice);
579 579
         }
580 580
 
581 581
         // Activate the subscription.
582
-        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
583
-        $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
582
+        $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
583
+        $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
584 584
 
585
-		$subscription->set_next_renewal_date( $expiry );
586
-		$subscription->set_date_created( current_time( 'mysql' ) );
587
-		$subscription->set_profile_id( $invoice->generate_key() );
585
+		$subscription->set_next_renewal_date($expiry);
586
+		$subscription->set_date_created(current_time('mysql'));
587
+		$subscription->set_profile_id($invoice->generate_key());
588 588
 		$subscription->activate();
589 589
 
590 590
 		// Redirect to the success page.
591
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
591
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
592 592
 
593 593
     }
594 594
 
@@ -599,20 +599,20 @@  discard block
 block discarded – undo
599 599
 	 * @param bool $should_expire
600 600
      * @param WPInv_Subscription $subscription
601 601
 	 */
602
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
602
+	public function maybe_renew_subscription($should_expire, $subscription) {
603 603
 
604 604
         // Ensure its our subscription && it's active.
605
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
605
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
606 606
             return $should_expire;
607 607
         }
608 608
 
609 609
         // If this is the last renewal, complete the subscription.
610
-        if ( $subscription->is_last_renewal() ) {
610
+        if ($subscription->is_last_renewal()) {
611 611
             $subscription->complete();
612 612
             return false;
613 613
         }
614 614
 
615
-        $this->renew_subscription( $subscription );
615
+        $this->renew_subscription($subscription);
616 616
 
617 617
         return false;
618 618
 
@@ -623,28 +623,28 @@  discard block
 block discarded – undo
623 623
 	 *
624 624
      * @param WPInv_Subscription $subscription
625 625
 	 */
626
-	public function renew_subscription( $subscription ) {
626
+	public function renew_subscription($subscription) {
627 627
 
628 628
 		// Generate the renewal invoice.
629 629
 		$new_invoice = $subscription->create_payment();
630 630
 		$old_invoice = $subscription->get_parent_payment();
631 631
 
632
-        if ( empty( $new_invoice ) ) {
633
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
632
+        if (empty($new_invoice)) {
633
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
634 634
             $subscription->failing();
635 635
             return;
636 636
         }
637 637
 
638 638
         // Charge the payment method.
639
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
640
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
641
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
639
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
640
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
641
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
642 642
 
643 643
 		// Do we have an error?
644
-		if ( is_wp_error( $result ) ) {
644
+		if (is_wp_error($result)) {
645 645
 
646 646
 			$old_invoice->add_note(
647
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
647
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
648 648
 				true,
649 649
 				false,
650 650
 				true
@@ -655,12 +655,12 @@  discard block
 block discarded – undo
655 655
 		}
656 656
 
657 657
 		// Process the response.
658
-		$this->process_charge_response( $result, $new_invoice );
658
+		$this->process_charge_response($result, $new_invoice);
659 659
 
660
-		if ( wpinv_get_errors() ) {
660
+		if (wpinv_get_errors()) {
661 661
 
662 662
 			$old_invoice->add_note(
663
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
663
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
664 664
 				true,
665 665
 				false,
666 666
 				true
@@ -670,7 +670,7 @@  discard block
 block discarded – undo
670 670
 
671 671
         }
672 672
 
673
-        $subscription->add_payment( array(), $new_invoice );
673
+        $subscription->add_payment(array(), $new_invoice);
674 674
         $subscription->renew();
675 675
     }
676 676
 
@@ -681,34 +681,34 @@  discard block
 block discarded – undo
681 681
 	 * @param GetPaid_Form_Item[] $items
682 682
 	 * @return WPInv_Invoice
683 683
 	 */
684
-	public function process_addons( $invoice, $items ) {
684
+	public function process_addons($invoice, $items) {
685 685
 
686 686
         global $getpaid_authorize_addons;
687 687
 
688 688
         $getpaid_authorize_addons = array();
689
-        foreach ( $items as $item ) {
689
+        foreach ($items as $item) {
690 690
 
691
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
691
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
692 692
                 $getpaid_authorize_addons[] = $item;
693 693
             }
694 694
 
695 695
         }
696 696
 
697
-        if ( empty( $getpaid_authorize_addons ) ) {
697
+        if (empty($getpaid_authorize_addons)) {
698 698
             return;
699 699
         }
700 700
 
701 701
         $invoice->recalculate_total();
702 702
 
703
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
704
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
703
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
704
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
705 705
 
706
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
707
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
708
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
706
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
707
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
708
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
709 709
 
710
-        if ( is_wp_error( $result ) ) {
711
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
710
+        if (is_wp_error($result)) {
711
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
712 712
             return;
713 713
         }
714 714
 
@@ -721,19 +721,19 @@  discard block
 block discarded – undo
721 721
      * @param array $args
722 722
 	 * @return array
723 723
 	 */
724
-    public function filter_addons_request( $args ) {
724
+    public function filter_addons_request($args) {
725 725
 
726 726
         global $getpaid_authorize_addons;
727 727
         $total = 0;
728 728
 
729
-        foreach ( $getpaid_authorize_addons as $addon ) {
729
+        foreach ($getpaid_authorize_addons as $addon) {
730 730
             $total += $addon->get_sub_total();
731 731
         }
732 732
 
733 733
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
734 734
 
735
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
736
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
735
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
736
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
737 737
         }
738 738
 
739 739
         return $args;
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
     public function sandbox_notice() {
747 747
 
748 748
         return sprintf(
749
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
749
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
750 750
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
751 751
             '</a>'
752 752
         );
@@ -758,42 +758,42 @@  discard block
 block discarded – undo
758 758
 	 *
759 759
 	 * @param array $admin_settings
760 760
 	 */
761
-	public function admin_settings( $admin_settings ) {
761
+	public function admin_settings($admin_settings) {
762 762
 
763 763
         $currencies = sprintf(
764
-            __( 'Supported Currencies: %s', 'invoicing' ),
765
-            implode( ', ', $this->currencies )
764
+            __('Supported Currencies: %s', 'invoicing'),
765
+            implode(', ', $this->currencies)
766 766
         );
767 767
 
768 768
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
769
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
769
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
770 770
 
771 771
         $admin_settings['authorizenet_login_id'] = array(
772 772
             'type' => 'text',
773 773
             'id'   => 'authorizenet_login_id',
774
-            'name' => __( 'API Login ID', 'invoicing' ),
775
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
774
+            'name' => __('API Login ID', 'invoicing'),
775
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
776 776
         );
777 777
 
778 778
         $admin_settings['authorizenet_transaction_key'] = array(
779 779
             'type' => 'text',
780 780
             'id'   => 'authorizenet_transaction_key',
781
-            'name' => __( 'Transaction Key', 'invoicing' ),
781
+            'name' => __('Transaction Key', 'invoicing'),
782 782
         );
783 783
 
784 784
         $admin_settings['authorizenet_signature_key'] = array(
785 785
             'type' => 'text',
786 786
             'id'   => 'authorizenet_signature_key',
787
-            'name' => __( 'Signature Key', 'invoicing' ),
788
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
787
+            'name' => __('Signature Key', 'invoicing'),
788
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
789 789
         );
790 790
 
791 791
         $admin_settings['authorizenet_ipn_url'] = array(
792 792
             'type'     => 'ipn_url',
793 793
             'id'       => 'authorizenet_ipn_url',
794
-            'name'     => __( 'Webhook URL', 'invoicing' ),
794
+            'name'     => __('Webhook URL', 'invoicing'),
795 795
             'std'      => $this->notify_url,
796
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
796
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
797 797
             'custom'   => 'authorizenet',
798 798
             'readonly' => true,
799 799
         );
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +500 added lines, -500 removed lines patch added patch discarded remove patch
@@ -14,543 +14,543 @@
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * @param array An array of payment gateways.
40
-	 */
41
-	public $gateways;
42
-
43
-	/**
44
-	 * Class constructor.
45
-	 */
46
-	public function __construct() {
47
-		$this->define_constants();
48
-		$this->includes();
49
-		$this->init_hooks();
50
-		$this->set_properties();
51
-	}
52
-
53
-	/**
54
-	 * Sets a custom data property.
55
-	 * 
56
-	 * @param string $prop The prop to set.
57
-	 * @param mixed $value The value to retrieve.
58
-	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
61
-	}
62
-
63
-	/**
64
-	 * Gets a custom data property.
65
-	 *
66
-	 * @param string $prop The prop to set.
67
-	 * @return mixed The value.
68
-	 */
69
-	public function get( $prop ) {
70
-
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
73
-		}
74
-
75
-		return null;
76
-	}
77
-
78
-	/**
79
-	 * Define class properties.
80
-	 */
81
-	public function set_properties() {
82
-
83
-		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
-		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
-
88
-		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
-
102
-	}
103
-
104
-	 /**
105
-	 * Define plugin constants.
106
-	 */
107
-	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
-		$this->version = WPINV_VERSION;
111
-	}
112
-
113
-	/**
114
-	 * Hook into actions and filters.
115
-	 *
116
-	 * @since 1.0.19
117
-	 */
118
-	protected function init_hooks() {
119
-		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
-
122
-		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
-
134
-		// Fires after registering actions.
135
-		do_action( 'wpinv_actions', $this );
136
-		do_action( 'getpaid_actions', $this );
137
-
138
-	}
139
-
140
-	public function plugins_loaded() {
141
-		/* Internationalize the text strings used. */
142
-		$this->load_textdomain();
143
-
144
-		do_action( 'wpinv_loaded' );
145
-
146
-		// Fix oxygen page builder conflict
147
-		if ( function_exists( 'ct_css_output' ) ) {
148
-			wpinv_oxygen_fix_conflict();
149
-		}
150
-	}
151
-
152
-	/**
153
-	 * Load the translation of the plugin.
154
-	 *
155
-	 * @since 1.0
156
-	 */
157
-	public function load_textdomain( $locale = NULL ) {
158
-		if ( empty( $locale ) ) {
159
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
160
-		}
161
-
162
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
163
-
164
-		unload_textdomain( 'invoicing' );
165
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
166
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
167
-
168
-		/**
169
-		 * Define language constants.
170
-		 */
171
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
172
-	}
173
-
174
-	/**
175
-	 * Include required core files used in admin and on the frontend.
176
-	 */
177
-	public function includes() {
178
-
179
-		// Start with the settings.
180
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
181
-
182
-		// Packages/libraries.
183
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
184
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
185
-
186
-		// Load functions.
187
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
189
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
190
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
202
-
203
-		// Register autoloader.
204
-		try {
205
-			spl_autoload_register( array( $this, 'autoload' ), true );
206
-		} catch ( Exception $e ) {
207
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
208
-		}
209
-
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
231
-
232
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
233
-			GetPaid_Post_Types_Admin::init();
234
-
235
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
236
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
237
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
241
-			// load the user class only on the users.php page
242
-			global $pagenow;
243
-			if($pagenow=='users.php'){
244
-				new WPInv_Admin_Users();
245
-			}
246
-		}
247
-
248
-		// Register cli commands
249
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
250
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
251
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
252
-		}
253
-
254
-	}
255
-
256
-	/**
257
-	 * Class autoloader
258
-	 *
259
-	 * @param       string $class_name The name of the class to load.
260
-	 * @access      public
261
-	 * @since       1.0.19
262
-	 * @return      void
263
-	 */
264
-	public function autoload( $class_name ) {
265
-
266
-		// Normalize the class name...
267
-		$class_name  = strtolower( $class_name );
268
-
269
-		// ... and make sure it is our class.
270
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
271
-			return;
272
-		}
273
-
274
-		// Next, prepare the file name from the class.
275
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
276
-
277
-		// Base path of the classes.
278
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
279
-
280
-		// And an array of possible locations in order of importance.
281
-		$locations = array(
282
-			"$plugin_path/includes",
283
-			"$plugin_path/includes/data-stores",
284
-			"$plugin_path/includes/gateways",
285
-			"$plugin_path/includes/payments",
286
-			"$plugin_path/includes/geolocation",
287
-			"$plugin_path/includes/reports",
288
-			"$plugin_path/includes/api",
289
-			"$plugin_path/includes/admin",
290
-			"$plugin_path/includes/admin/meta-boxes",
291
-		);
292
-
293
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
294
-
295
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
296
-				include trailingslashit( $location ) . $file_name;
297
-				break;
298
-			}
299
-
300
-		}
301
-
302
-	}
303
-
304
-	/**
305
-	 * Inits hooks etc.
306
-	 */
307
-	public function init() {
308
-
309
-		// Fires before getpaid inits.
310
-		do_action( 'before_getpaid_init', $this );
311
-
312
-		// Maybe upgrade.
313
-		$this->maybe_upgrade_database();
314
-
315
-		// Load default gateways.
316
-		$gateways = apply_filters(
317
-			'getpaid_default_gateways',
318
-			array(
319
-				'manual'        => 'GetPaid_Manual_Gateway',
320
-				'paypal'        => 'GetPaid_Paypal_Gateway',
321
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
322
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
323
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
324
-			)
325
-		);
326
-
327
-		foreach ( $gateways as $id => $class ) {
328
-			$this->gateways[ $id ] = new $class();
329
-		}
330
-
331
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
332
-			GetPaid_Installer::rename_gateways_label();
333
-			update_option( 'wpinv_renamed_gateways', 'yes' );
334
-		}
335
-
336
-		// Fires after getpaid inits.
337
-		do_action( 'getpaid_init', $this );
338
-
339
-	}
340
-
341
-	/**
342
-	 * Checks if this is an IPN request and processes it.
343
-	 */
344
-	public function maybe_process_ipn() {
345
-
346
-		// Ensure that this is an IPN request.
347
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
348
-			return;
349
-		}
350
-
351
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
352
-
353
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
354
-		do_action( "wpinv_verify_{$gateway}_ipn" );
355
-		exit;
356
-
357
-	}
358
-
359
-	public function enqueue_scripts() {
360
-
361
-		// Fires before adding scripts.
362
-		do_action( 'getpaid_enqueue_scripts' );
363
-
364
-		$localize                         = array();
365
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
366
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
368
-		$localize['UseTaxes']             = wpinv_use_taxes();
369
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
370
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
371
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
372
-
373
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
374
-
375
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
376
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
377
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
378
-	}
379
-
380
-	public function wpinv_actions() {
381
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
382
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
383
-		}
384
-	}
385
-
386
-	/**
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * @param array An array of payment gateways.
40
+     */
41
+    public $gateways;
42
+
43
+    /**
44
+     * Class constructor.
45
+     */
46
+    public function __construct() {
47
+        $this->define_constants();
48
+        $this->includes();
49
+        $this->init_hooks();
50
+        $this->set_properties();
51
+    }
52
+
53
+    /**
54
+     * Sets a custom data property.
55
+     * 
56
+     * @param string $prop The prop to set.
57
+     * @param mixed $value The value to retrieve.
58
+     */
59
+    public function set( $prop, $value ) {
60
+        $this->data[ $prop ] = $value;
61
+    }
62
+
63
+    /**
64
+     * Gets a custom data property.
65
+     *
66
+     * @param string $prop The prop to set.
67
+     * @return mixed The value.
68
+     */
69
+    public function get( $prop ) {
70
+
71
+        if ( isset( $this->data[ $prop ] ) ) {
72
+            return $this->data[ $prop ];
73
+        }
74
+
75
+        return null;
76
+    }
77
+
78
+    /**
79
+     * Define class properties.
80
+     */
81
+    public function set_properties() {
82
+
83
+        // Sessions.
84
+        $this->set( 'session', new WPInv_Session_Handler() );
85
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
86
+        $GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87
+
88
+        // Init other objects.
89
+        $this->set( 'session', new WPInv_Session_Handler() );
90
+        $this->set( 'notes', new WPInv_Notes() );
91
+        $this->set( 'api', new WPInv_API() );
92
+        $this->set( 'post_types', new GetPaid_Post_Types() );
93
+        $this->set( 'template', new GetPaid_Template() );
94
+        $this->set( 'admin', new GetPaid_Admin() );
95
+        $this->set( 'subscriptions', new WPInv_Subscriptions() );
96
+        $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
+        $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
+        $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
+        $this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
+        $this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
101
+
102
+    }
103
+
104
+        /**
105
+         * Define plugin constants.
106
+         */
107
+    public function define_constants() {
108
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
110
+        $this->version = WPINV_VERSION;
111
+    }
112
+
113
+    /**
114
+     * Hook into actions and filters.
115
+     *
116
+     * @since 1.0.19
117
+     */
118
+    protected function init_hooks() {
119
+        /* Internationalize the text strings used. */
120
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
121
+
122
+        // Init the plugin after WordPress inits.
123
+        add_action( 'init', array( $this, 'init' ), 1 );
124
+        add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
+        add_action( 'init', array( $this, 'wpinv_actions' ) );
126
+        add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
+        add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
+        add_action( 'wp_head', array( $this, 'wp_head' ) );
130
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
133
+
134
+        // Fires after registering actions.
135
+        do_action( 'wpinv_actions', $this );
136
+        do_action( 'getpaid_actions', $this );
137
+
138
+    }
139
+
140
+    public function plugins_loaded() {
141
+        /* Internationalize the text strings used. */
142
+        $this->load_textdomain();
143
+
144
+        do_action( 'wpinv_loaded' );
145
+
146
+        // Fix oxygen page builder conflict
147
+        if ( function_exists( 'ct_css_output' ) ) {
148
+            wpinv_oxygen_fix_conflict();
149
+        }
150
+    }
151
+
152
+    /**
153
+     * Load the translation of the plugin.
154
+     *
155
+     * @since 1.0
156
+     */
157
+    public function load_textdomain( $locale = NULL ) {
158
+        if ( empty( $locale ) ) {
159
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
160
+        }
161
+
162
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
163
+
164
+        unload_textdomain( 'invoicing' );
165
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
166
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
167
+
168
+        /**
169
+         * Define language constants.
170
+         */
171
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
172
+    }
173
+
174
+    /**
175
+     * Include required core files used in admin and on the frontend.
176
+     */
177
+    public function includes() {
178
+
179
+        // Start with the settings.
180
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
181
+
182
+        // Packages/libraries.
183
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
184
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
185
+
186
+        // Load functions.
187
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
189
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
190
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
202
+
203
+        // Register autoloader.
204
+        try {
205
+            spl_autoload_register( array( $this, 'autoload' ), true );
206
+        } catch ( Exception $e ) {
207
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
208
+        }
209
+
210
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
211
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
212
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
213
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
231
+
232
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
233
+            GetPaid_Post_Types_Admin::init();
234
+
235
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
236
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
237
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
238
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
241
+            // load the user class only on the users.php page
242
+            global $pagenow;
243
+            if($pagenow=='users.php'){
244
+                new WPInv_Admin_Users();
245
+            }
246
+        }
247
+
248
+        // Register cli commands
249
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
250
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
251
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
252
+        }
253
+
254
+    }
255
+
256
+    /**
257
+     * Class autoloader
258
+     *
259
+     * @param       string $class_name The name of the class to load.
260
+     * @access      public
261
+     * @since       1.0.19
262
+     * @return      void
263
+     */
264
+    public function autoload( $class_name ) {
265
+
266
+        // Normalize the class name...
267
+        $class_name  = strtolower( $class_name );
268
+
269
+        // ... and make sure it is our class.
270
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
271
+            return;
272
+        }
273
+
274
+        // Next, prepare the file name from the class.
275
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
276
+
277
+        // Base path of the classes.
278
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
279
+
280
+        // And an array of possible locations in order of importance.
281
+        $locations = array(
282
+            "$plugin_path/includes",
283
+            "$plugin_path/includes/data-stores",
284
+            "$plugin_path/includes/gateways",
285
+            "$plugin_path/includes/payments",
286
+            "$plugin_path/includes/geolocation",
287
+            "$plugin_path/includes/reports",
288
+            "$plugin_path/includes/api",
289
+            "$plugin_path/includes/admin",
290
+            "$plugin_path/includes/admin/meta-boxes",
291
+        );
292
+
293
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
294
+
295
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
296
+                include trailingslashit( $location ) . $file_name;
297
+                break;
298
+            }
299
+
300
+        }
301
+
302
+    }
303
+
304
+    /**
305
+     * Inits hooks etc.
306
+     */
307
+    public function init() {
308
+
309
+        // Fires before getpaid inits.
310
+        do_action( 'before_getpaid_init', $this );
311
+
312
+        // Maybe upgrade.
313
+        $this->maybe_upgrade_database();
314
+
315
+        // Load default gateways.
316
+        $gateways = apply_filters(
317
+            'getpaid_default_gateways',
318
+            array(
319
+                'manual'        => 'GetPaid_Manual_Gateway',
320
+                'paypal'        => 'GetPaid_Paypal_Gateway',
321
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
322
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
323
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
324
+            )
325
+        );
326
+
327
+        foreach ( $gateways as $id => $class ) {
328
+            $this->gateways[ $id ] = new $class();
329
+        }
330
+
331
+        if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
332
+            GetPaid_Installer::rename_gateways_label();
333
+            update_option( 'wpinv_renamed_gateways', 'yes' );
334
+        }
335
+
336
+        // Fires after getpaid inits.
337
+        do_action( 'getpaid_init', $this );
338
+
339
+    }
340
+
341
+    /**
342
+     * Checks if this is an IPN request and processes it.
343
+     */
344
+    public function maybe_process_ipn() {
345
+
346
+        // Ensure that this is an IPN request.
347
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
348
+            return;
349
+        }
350
+
351
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
352
+
353
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
354
+        do_action( "wpinv_verify_{$gateway}_ipn" );
355
+        exit;
356
+
357
+    }
358
+
359
+    public function enqueue_scripts() {
360
+
361
+        // Fires before adding scripts.
362
+        do_action( 'getpaid_enqueue_scripts' );
363
+
364
+        $localize                         = array();
365
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
366
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
368
+        $localize['UseTaxes']             = wpinv_use_taxes();
369
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
370
+        $localize['loading']              = __( 'Loading...', 'invoicing' );
371
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
372
+
373
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
374
+
375
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
376
+        wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
377
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
378
+    }
379
+
380
+    public function wpinv_actions() {
381
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
382
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
383
+        }
384
+    }
385
+
386
+    /**
387 387
      * Fires an action after verifying that a user can fire them.
388
-	 *
389
-	 * Note: If the action is on an invoice, subscription etc, esure that the
390
-	 * current user owns the invoice/subscription.
388
+     *
389
+     * Note: If the action is on an invoice, subscription etc, esure that the
390
+     * current user owns the invoice/subscription.
391 391
      */
392 392
     public function maybe_do_authenticated_action() {
393 393
 
394
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
394
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
395 395
 
396
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
397
-			$data = wp_unslash( $_REQUEST );
398
-			if ( is_user_logged_in() ) {
399
-				do_action( "getpaid_authenticated_action_$key", $data );
400
-			}
396
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
397
+            $data = wp_unslash( $_REQUEST );
398
+            if ( is_user_logged_in() ) {
399
+                do_action( "getpaid_authenticated_action_$key", $data );
400
+            }
401 401
 
402
-			do_action( "getpaid_unauthenticated_action_$key", $data );
402
+            do_action( "getpaid_unauthenticated_action_$key", $data );
403 403
 
404
-		}
404
+        }
405 405
 
406 406
     }
407 407
 
408
-	public function pre_get_posts( $wp_query ) {
409
-
410
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
411
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
412
-		}
413
-
414
-		return $wp_query;
415
-	}
416
-
417
-	/**
418
-	 * Register widgets
419
-	 *
420
-	 */
421
-	public function register_widgets() {
422
-
423
-		// Currently, UX Builder does not work particulaly well with SuperDuper.
424
-		// So we disable our widgets when editing a page with UX Builder.
425
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
426
-			return;
427
-		}
428
-
429
-		$widgets = apply_filters(
430
-			'getpaid_widget_classes',
431
-			array(
432
-				'WPInv_Checkout_Widget',
433
-				'WPInv_History_Widget',
434
-				'WPInv_Receipt_Widget',
435
-				'WPInv_Subscriptions_Widget',
436
-				'WPInv_Buy_Item_Widget',
437
-				'WPInv_Messages_Widget',
438
-				'WPInv_GetPaid_Widget'
439
-			)
440
-		);
441
-
442
-		foreach ( $widgets as $widget ) {
443
-			register_widget( $widget );
444
-		}
408
+    public function pre_get_posts( $wp_query ) {
409
+
410
+        if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
411
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
412
+        }
413
+
414
+        return $wp_query;
415
+    }
416
+
417
+    /**
418
+     * Register widgets
419
+     *
420
+     */
421
+    public function register_widgets() {
422
+
423
+        // Currently, UX Builder does not work particulaly well with SuperDuper.
424
+        // So we disable our widgets when editing a page with UX Builder.
425
+        if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
426
+            return;
427
+        }
428
+
429
+        $widgets = apply_filters(
430
+            'getpaid_widget_classes',
431
+            array(
432
+                'WPInv_Checkout_Widget',
433
+                'WPInv_History_Widget',
434
+                'WPInv_Receipt_Widget',
435
+                'WPInv_Subscriptions_Widget',
436
+                'WPInv_Buy_Item_Widget',
437
+                'WPInv_Messages_Widget',
438
+                'WPInv_GetPaid_Widget'
439
+            )
440
+        );
441
+
442
+        foreach ( $widgets as $widget ) {
443
+            register_widget( $widget );
444
+        }
445 445
 		
446
-	}
446
+    }
447 447
 
448
-	/**
449
-	 * Upgrades the database.
450
-	 *
451
-	 * @since 2.0.2
452
-	 */
453
-	public function maybe_upgrade_database() {
448
+    /**
449
+     * Upgrades the database.
450
+     *
451
+     * @since 2.0.2
452
+     */
453
+    public function maybe_upgrade_database() {
454 454
 
455
-		$wpi_version = get_option( 'wpinv_version', 0 );
455
+        $wpi_version = get_option( 'wpinv_version', 0 );
456 456
 
457
-		if ( $wpi_version == WPINV_VERSION ) {
458
-			return;
459
-		}
457
+        if ( $wpi_version == WPINV_VERSION ) {
458
+            return;
459
+        }
460 460
 
461
-		$installer = new GetPaid_Installer();
461
+        $installer = new GetPaid_Installer();
462 462
 
463
-		if ( empty( $wpi_version ) ) {
464
-			return $installer->upgrade_db( 0 );
465
-		}
463
+        if ( empty( $wpi_version ) ) {
464
+            return $installer->upgrade_db( 0 );
465
+        }
466 466
 
467
-		$upgrades  = array(
468
-			'0.0.5' => '004',
469
-			'1.0.3' => '102',
470
-			'2.0.0' => '118',
471
-			'2.0.8' => '207',
472
-		);
467
+        $upgrades  = array(
468
+            '0.0.5' => '004',
469
+            '1.0.3' => '102',
470
+            '2.0.0' => '118',
471
+            '2.0.8' => '207',
472
+        );
473 473
 
474
-		foreach ( $upgrades as $key => $method ) {
474
+        foreach ( $upgrades as $key => $method ) {
475 475
 
476
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
477
-				return $installer->upgrade_db( $method );
478
-			}
476
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
477
+                return $installer->upgrade_db( $method );
478
+            }
479 479
 
480
-		}
480
+        }
481 481
 
482
-	}
482
+    }
483 483
 
484
-	/**
485
-	 * Flushes the permalinks if needed.
486
-	 *
487
-	 * @since 2.0.8
488
-	 */
489
-	public function maybe_flush_permalinks() {
484
+    /**
485
+     * Flushes the permalinks if needed.
486
+     *
487
+     * @since 2.0.8
488
+     */
489
+    public function maybe_flush_permalinks() {
490 490
 
491
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
491
+        $flush = get_option( 'wpinv_flush_permalinks', 0 );
492 492
 
493
-		if ( ! empty( $flush ) ) {
494
-			flush_rewrite_rules();
495
-			delete_option( 'wpinv_flush_permalinks' );
496
-		}
493
+        if ( ! empty( $flush ) ) {
494
+            flush_rewrite_rules();
495
+            delete_option( 'wpinv_flush_permalinks' );
496
+        }
497 497
 
498
-	}
498
+    }
499 499
 
500
-	/**
501
-	 * Remove our pages from yoast sitemaps.
502
-	 *
503
-	 * @since 1.0.19
504
-	 * @param int[] $excluded_posts_ids
505
-	 */
506
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
500
+    /**
501
+     * Remove our pages from yoast sitemaps.
502
+     *
503
+     * @since 1.0.19
504
+     * @param int[] $excluded_posts_ids
505
+     */
506
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
507 507
 
508
-		// Ensure that we have an array.
509
-		if ( ! is_array( $excluded_posts_ids ) ) {
510
-			$excluded_posts_ids = array();
511
-		}
508
+        // Ensure that we have an array.
509
+        if ( ! is_array( $excluded_posts_ids ) ) {
510
+            $excluded_posts_ids = array();
511
+        }
512 512
 
513
-		// Prepare our pages.
514
-		$our_pages = array();
513
+        // Prepare our pages.
514
+        $our_pages = array();
515 515
 
516
-		// Checkout page.
517
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
516
+        // Checkout page.
517
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
518 518
 
519
-		// Success page.
520
-		$our_pages[] = wpinv_get_option( 'success_page', false );
519
+        // Success page.
520
+        $our_pages[] = wpinv_get_option( 'success_page', false );
521 521
 
522
-		// Failure page.
523
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
522
+        // Failure page.
523
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
524 524
 
525
-		// History page.
526
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
525
+        // History page.
526
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
527 527
 
528
-		// Subscriptions page.
529
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
528
+        // Subscriptions page.
529
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
530 530
 
531
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
531
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
532 532
 
533
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
534
-		return array_unique( $excluded_posts_ids );
533
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
534
+        return array_unique( $excluded_posts_ids );
535 535
 
536
-	}
536
+    }
537 537
 
538
-	/**
539
-	 * Displays additional footer code.
540
-	 * 
541
-	 * @since 2.0.0
542
-	 */
543
-	public function wp_footer() {
544
-		wpinv_get_template( 'frontend-footer.php' );
545
-	}
538
+    /**
539
+     * Displays additional footer code.
540
+     * 
541
+     * @since 2.0.0
542
+     */
543
+    public function wp_footer() {
544
+        wpinv_get_template( 'frontend-footer.php' );
545
+    }
546 546
 
547
-	/**
548
-	 * Displays additional header code.
549
-	 * 
550
-	 * @since 2.0.0
551
-	 */
552
-	public function wp_head() {
553
-		wpinv_get_template( 'frontend-head.php' );
554
-	}
547
+    /**
548
+     * Displays additional header code.
549
+     * 
550
+     * @since 2.0.0
551
+     */
552
+    public function wp_head() {
553
+        wpinv_get_template( 'frontend-head.php' );
554
+    }
555 555
 
556 556
 }
Please login to merge, or discard this patch.
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 * @param string $prop The prop to set.
57 57
 	 * @param mixed $value The value to retrieve.
58 58
 	 */
59
-	public function set( $prop, $value ) {
60
-		$this->data[ $prop ] = $value;
59
+	public function set($prop, $value) {
60
+		$this->data[$prop] = $value;
61 61
 	}
62 62
 
63 63
 	/**
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
 	 * @param string $prop The prop to set.
67 67
 	 * @return mixed The value.
68 68
 	 */
69
-	public function get( $prop ) {
69
+	public function get($prop) {
70 70
 
71
-		if ( isset( $this->data[ $prop ] ) ) {
72
-			return $this->data[ $prop ];
71
+		if (isset($this->data[$prop])) {
72
+			return $this->data[$prop];
73 73
 		}
74 74
 
75 75
 		return null;
@@ -81,23 +81,23 @@  discard block
 block discarded – undo
81 81
 	public function set_properties() {
82 82
 
83 83
 		// Sessions.
84
-		$this->set( 'session', new WPInv_Session_Handler() );
85
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
84
+		$this->set('session', new WPInv_Session_Handler());
85
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
86 86
 		$GLOBALS['wpinv_euvat'] = new WPInv_EUVat(); // Backwards compatibility.
87 87
 
88 88
 		// Init other objects.
89
-		$this->set( 'session', new WPInv_Session_Handler() );
90
-		$this->set( 'notes', new WPInv_Notes() );
91
-		$this->set( 'api', new WPInv_API() );
92
-		$this->set( 'post_types', new GetPaid_Post_Types() );
93
-		$this->set( 'template', new GetPaid_Template() );
94
-		$this->set( 'admin', new GetPaid_Admin() );
95
-		$this->set( 'subscriptions', new WPInv_Subscriptions() );
96
-		$this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() );
97
-		$this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() );
98
-		$this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() );
99
-		$this->set( 'payment_forms', new GetPaid_Payment_Forms() );
100
-		$this->set( 'maxmind', new GetPaid_MaxMind_Geolocation() );
89
+		$this->set('session', new WPInv_Session_Handler());
90
+		$this->set('notes', new WPInv_Notes());
91
+		$this->set('api', new WPInv_API());
92
+		$this->set('post_types', new GetPaid_Post_Types());
93
+		$this->set('template', new GetPaid_Template());
94
+		$this->set('admin', new GetPaid_Admin());
95
+		$this->set('subscriptions', new WPInv_Subscriptions());
96
+		$this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails());
97
+		$this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails());
98
+		$this->set('daily_maintenace', new GetPaid_Daily_Maintenance());
99
+		$this->set('payment_forms', new GetPaid_Payment_Forms());
100
+		$this->set('maxmind', new GetPaid_MaxMind_Geolocation());
101 101
 
102 102
 	}
103 103
 
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 	 * Define plugin constants.
106 106
 	 */
107 107
 	public function define_constants() {
108
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
109
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
108
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
109
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
110 110
 		$this->version = WPINV_VERSION;
111 111
 	}
112 112
 
@@ -117,23 +117,23 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	protected function init_hooks() {
119 119
 		/* Internationalize the text strings used. */
120
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
120
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
121 121
 
122 122
 		// Init the plugin after WordPress inits.
123
-		add_action( 'init', array( $this, 'init' ), 1 );
124
-		add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 );
125
-		add_action( 'init', array( $this, 'wpinv_actions' ) );
126
-		add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 );
127
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
128
-		add_action( 'wp_footer', array( $this, 'wp_footer' ) );
129
-		add_action( 'wp_head', array( $this, 'wp_head' ) );
130
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
131
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
132
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
123
+		add_action('init', array($this, 'init'), 1);
124
+		add_action('init', array($this, 'maybe_process_ipn'), 10);
125
+		add_action('init', array($this, 'wpinv_actions'));
126
+		add_action('init', array($this, 'maybe_do_authenticated_action'), 100);
127
+		add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 11);
128
+		add_action('wp_footer', array($this, 'wp_footer'));
129
+		add_action('wp_head', array($this, 'wp_head'));
130
+		add_action('widgets_init', array(&$this, 'register_widgets'));
131
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
132
+		add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
133 133
 
134 134
 		// Fires after registering actions.
135
-		do_action( 'wpinv_actions', $this );
136
-		do_action( 'getpaid_actions', $this );
135
+		do_action('wpinv_actions', $this);
136
+		do_action('getpaid_actions', $this);
137 137
 
138 138
 	}
139 139
 
@@ -141,10 +141,10 @@  discard block
 block discarded – undo
141 141
 		/* Internationalize the text strings used. */
142 142
 		$this->load_textdomain();
143 143
 
144
-		do_action( 'wpinv_loaded' );
144
+		do_action('wpinv_loaded');
145 145
 
146 146
 		// Fix oxygen page builder conflict
147
-		if ( function_exists( 'ct_css_output' ) ) {
147
+		if (function_exists('ct_css_output')) {
148 148
 			wpinv_oxygen_fix_conflict();
149 149
 		}
150 150
 	}
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
 	 *
155 155
 	 * @since 1.0
156 156
 	 */
157
-	public function load_textdomain( $locale = NULL ) {
158
-		if ( empty( $locale ) ) {
159
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
157
+	public function load_textdomain($locale = NULL) {
158
+		if (empty($locale)) {
159
+			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
160 160
 		}
161 161
 
162
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
162
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
163 163
 
164
-		unload_textdomain( 'invoicing' );
165
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
166
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
164
+		unload_textdomain('invoicing');
165
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
166
+		load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
167 167
 
168 168
 		/**
169 169
 		 * Define language constants.
170 170
 		 */
171
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
171
+		require_once(WPINV_PLUGIN_DIR . 'language.php');
172 172
 	}
173 173
 
174 174
 	/**
@@ -177,78 +177,78 @@  discard block
 block discarded – undo
177 177
 	public function includes() {
178 178
 
179 179
 		// Start with the settings.
180
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
180
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
181 181
 
182 182
 		// Packages/libraries.
183
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
184
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
183
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
184
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
185 185
 
186 186
 		// Load functions.
187
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
189
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
190
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
187
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
188
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
189
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
190
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
191
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
192
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
193
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
194
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
195
+		require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php');
196
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
197
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
198
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
199
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
200
+		require_once(WPINV_PLUGIN_DIR . 'includes/user-functions.php');
201
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
202 202
 
203 203
 		// Register autoloader.
204 204
 		try {
205
-			spl_autoload_register( array( $this, 'autoload' ), true );
206
-		} catch ( Exception $e ) {
207
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
205
+			spl_autoload_register(array($this, 'autoload'), true);
206
+		} catch (Exception $e) {
207
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
208 208
 		}
209 209
 
210
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
211
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
212
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
213
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
231
-
232
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
210
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
211
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
212
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
213
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
214
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
215
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
216
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
217
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
218
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
219
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
220
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
221
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
222
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
223
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
224
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
225
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
226
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
231
+
232
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
233 233
 			GetPaid_Post_Types_Admin::init();
234 234
 
235
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
236
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
237
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
235
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
236
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
237
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
238
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
239
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
240
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
241 241
 			// load the user class only on the users.php page
242 242
 			global $pagenow;
243
-			if($pagenow=='users.php'){
243
+			if ($pagenow == 'users.php') {
244 244
 				new WPInv_Admin_Users();
245 245
 			}
246 246
 		}
247 247
 
248 248
 		// Register cli commands
249
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
250
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
251
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
249
+		if (defined('WP_CLI') && WP_CLI) {
250
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
251
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
252 252
 		}
253 253
 
254 254
 	}
@@ -261,21 +261,21 @@  discard block
 block discarded – undo
261 261
 	 * @since       1.0.19
262 262
 	 * @return      void
263 263
 	 */
264
-	public function autoload( $class_name ) {
264
+	public function autoload($class_name) {
265 265
 
266 266
 		// Normalize the class name...
267
-		$class_name  = strtolower( $class_name );
267
+		$class_name = strtolower($class_name);
268 268
 
269 269
 		// ... and make sure it is our class.
270
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
270
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
271 271
 			return;
272 272
 		}
273 273
 
274 274
 		// Next, prepare the file name from the class.
275
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
275
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
276 276
 
277 277
 		// Base path of the classes.
278
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
278
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
279 279
 
280 280
 		// And an array of possible locations in order of importance.
281 281
 		$locations = array(
@@ -290,10 +290,10 @@  discard block
 block discarded – undo
290 290
 			"$plugin_path/includes/admin/meta-boxes",
291 291
 		);
292 292
 
293
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
293
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
294 294
 
295
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
296
-				include trailingslashit( $location ) . $file_name;
295
+			if (file_exists(trailingslashit($location) . $file_name)) {
296
+				include trailingslashit($location) . $file_name;
297 297
 				break;
298 298
 			}
299 299
 
@@ -307,7 +307,7 @@  discard block
 block discarded – undo
307 307
 	public function init() {
308 308
 
309 309
 		// Fires before getpaid inits.
310
-		do_action( 'before_getpaid_init', $this );
310
+		do_action('before_getpaid_init', $this);
311 311
 
312 312
 		// Maybe upgrade.
313 313
 		$this->maybe_upgrade_database();
@@ -324,17 +324,17 @@  discard block
 block discarded – undo
324 324
 			)
325 325
 		);
326 326
 
327
-		foreach ( $gateways as $id => $class ) {
328
-			$this->gateways[ $id ] = new $class();
327
+		foreach ($gateways as $id => $class) {
328
+			$this->gateways[$id] = new $class();
329 329
 		}
330 330
 
331
-		if ( 'yes' != get_option( 'wpinv_renamed_gateways' ) ) {
331
+		if ('yes' != get_option('wpinv_renamed_gateways')) {
332 332
 			GetPaid_Installer::rename_gateways_label();
333
-			update_option( 'wpinv_renamed_gateways', 'yes' );
333
+			update_option('wpinv_renamed_gateways', 'yes');
334 334
 		}
335 335
 
336 336
 		// Fires after getpaid inits.
337
-		do_action( 'getpaid_init', $this );
337
+		do_action('getpaid_init', $this);
338 338
 
339 339
 	}
340 340
 
@@ -344,14 +344,14 @@  discard block
 block discarded – undo
344 344
 	public function maybe_process_ipn() {
345 345
 
346 346
 		// Ensure that this is an IPN request.
347
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
347
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
348 348
 			return;
349 349
 		}
350 350
 
351
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
351
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
352 352
 
353
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
354
-		do_action( "wpinv_verify_{$gateway}_ipn" );
353
+		do_action('wpinv_verify_payment_ipn', $gateway);
354
+		do_action("wpinv_verify_{$gateway}_ipn");
355 355
 		exit;
356 356
 
357 357
 	}
@@ -359,27 +359,27 @@  discard block
 block discarded – undo
359 359
 	public function enqueue_scripts() {
360 360
 
361 361
 		// Fires before adding scripts.
362
-		do_action( 'getpaid_enqueue_scripts' );
362
+		do_action('getpaid_enqueue_scripts');
363 363
 
364 364
 		$localize                         = array();
365
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
366
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
365
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
366
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
367
+		$localize['txtComplete']          = __('Continue', 'invoicing');
368 368
 		$localize['UseTaxes']             = wpinv_use_taxes();
369
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
370
-		$localize['loading']              = __( 'Loading...', 'invoicing' );
371
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
369
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
370
+		$localize['loading']              = __('Loading...', 'invoicing');
371
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
372 372
 
373
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
373
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
374 374
 
375
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
376
-		wp_enqueue_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'jquery' ),  $version, true );
377
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
375
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
376
+		wp_enqueue_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('jquery'), $version, true);
377
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
378 378
 	}
379 379
 
380 380
 	public function wpinv_actions() {
381
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
382
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
381
+		if (isset($_REQUEST['wpi_action'])) {
382
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
383 383
 		}
384 384
 	}
385 385
 
@@ -391,24 +391,24 @@  discard block
 block discarded – undo
391 391
      */
392 392
     public function maybe_do_authenticated_action() {
393 393
 
394
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
394
+		if (isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) {
395 395
 
396
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
397
-			$data = wp_unslash( $_REQUEST );
398
-			if ( is_user_logged_in() ) {
399
-				do_action( "getpaid_authenticated_action_$key", $data );
396
+			$key  = sanitize_key($_REQUEST['getpaid-action']);
397
+			$data = wp_unslash($_REQUEST);
398
+			if (is_user_logged_in()) {
399
+				do_action("getpaid_authenticated_action_$key", $data);
400 400
 			}
401 401
 
402
-			do_action( "getpaid_unauthenticated_action_$key", $data );
402
+			do_action("getpaid_unauthenticated_action_$key", $data);
403 403
 
404 404
 		}
405 405
 
406 406
     }
407 407
 
408
-	public function pre_get_posts( $wp_query ) {
408
+	public function pre_get_posts($wp_query) {
409 409
 
410
-		if ( ! is_admin() && ! empty( $wp_query->query_vars['post_type'] ) && getpaid_is_invoice_post_type( $wp_query->query_vars['post_type'] ) && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
411
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
410
+		if (!is_admin() && !empty($wp_query->query_vars['post_type']) && getpaid_is_invoice_post_type($wp_query->query_vars['post_type']) && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
411
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses(false, false, $wp_query->query_vars['post_type']));
412 412
 		}
413 413
 
414 414
 		return $wp_query;
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 
423 423
 		// Currently, UX Builder does not work particulaly well with SuperDuper.
424 424
 		// So we disable our widgets when editing a page with UX Builder.
425
-		if ( function_exists( 'ux_builder_is_active' ) && ux_builder_is_active() ) {
425
+		if (function_exists('ux_builder_is_active') && ux_builder_is_active()) {
426 426
 			return;
427 427
 		}
428 428
 
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 			)
440 440
 		);
441 441
 
442
-		foreach ( $widgets as $widget ) {
443
-			register_widget( $widget );
442
+		foreach ($widgets as $widget) {
443
+			register_widget($widget);
444 444
 		}
445 445
 		
446 446
 	}
@@ -452,29 +452,29 @@  discard block
 block discarded – undo
452 452
 	 */
453 453
 	public function maybe_upgrade_database() {
454 454
 
455
-		$wpi_version = get_option( 'wpinv_version', 0 );
455
+		$wpi_version = get_option('wpinv_version', 0);
456 456
 
457
-		if ( $wpi_version == WPINV_VERSION ) {
457
+		if ($wpi_version == WPINV_VERSION) {
458 458
 			return;
459 459
 		}
460 460
 
461 461
 		$installer = new GetPaid_Installer();
462 462
 
463
-		if ( empty( $wpi_version ) ) {
464
-			return $installer->upgrade_db( 0 );
463
+		if (empty($wpi_version)) {
464
+			return $installer->upgrade_db(0);
465 465
 		}
466 466
 
467
-		$upgrades  = array(
467
+		$upgrades = array(
468 468
 			'0.0.5' => '004',
469 469
 			'1.0.3' => '102',
470 470
 			'2.0.0' => '118',
471 471
 			'2.0.8' => '207',
472 472
 		);
473 473
 
474
-		foreach ( $upgrades as $key => $method ) {
474
+		foreach ($upgrades as $key => $method) {
475 475
 
476
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
477
-				return $installer->upgrade_db( $method );
476
+			if (version_compare($wpi_version, $key, '<')) {
477
+				return $installer->upgrade_db($method);
478 478
 			}
479 479
 
480 480
 		}
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 	 */
489 489
 	public function maybe_flush_permalinks() {
490 490
 
491
-		$flush = get_option( 'wpinv_flush_permalinks', 0 );
491
+		$flush = get_option('wpinv_flush_permalinks', 0);
492 492
 
493
-		if ( ! empty( $flush ) ) {
493
+		if (!empty($flush)) {
494 494
 			flush_rewrite_rules();
495
-			delete_option( 'wpinv_flush_permalinks' );
495
+			delete_option('wpinv_flush_permalinks');
496 496
 		}
497 497
 
498 498
 	}
@@ -503,10 +503,10 @@  discard block
 block discarded – undo
503 503
 	 * @since 1.0.19
504 504
 	 * @param int[] $excluded_posts_ids
505 505
 	 */
506
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
506
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
507 507
 
508 508
 		// Ensure that we have an array.
509
-		if ( ! is_array( $excluded_posts_ids ) ) {
509
+		if (!is_array($excluded_posts_ids)) {
510 510
 			$excluded_posts_ids = array();
511 511
 		}
512 512
 
@@ -514,24 +514,24 @@  discard block
 block discarded – undo
514 514
 		$our_pages = array();
515 515
 
516 516
 		// Checkout page.
517
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
517
+		$our_pages[] = wpinv_get_option('checkout_page', false);
518 518
 
519 519
 		// Success page.
520
-		$our_pages[] = wpinv_get_option( 'success_page', false );
520
+		$our_pages[] = wpinv_get_option('success_page', false);
521 521
 
522 522
 		// Failure page.
523
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
523
+		$our_pages[] = wpinv_get_option('failure_page', false);
524 524
 
525 525
 		// History page.
526
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
526
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
527 527
 
528 528
 		// Subscriptions page.
529
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
529
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
530 530
 
531
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
531
+		$our_pages   = array_map('intval', array_filter($our_pages));
532 532
 
533 533
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
534
-		return array_unique( $excluded_posts_ids );
534
+		return array_unique($excluded_posts_ids);
535 535
 
536 536
 	}
537 537
 
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 	 * @since 2.0.0
542 542
 	 */
543 543
 	public function wp_footer() {
544
-		wpinv_get_template( 'frontend-footer.php' );
544
+		wpinv_get_template('frontend-footer.php');
545 545
 	}
546 546
 
547 547
 	/**
@@ -550,7 +550,7 @@  discard block
 block discarded – undo
550 550
 	 * @since 2.0.0
551 551
 	 */
552 552
 	public function wp_head() {
553
-		wpinv_get_template( 'frontend-head.php' );
553
+		wpinv_get_template('frontend-head.php');
554 554
 	}
555 555
 
556 556
 }
Please login to merge, or discard this patch.