Passed
Push — master ( dafa5d...51f1c0 )
by Brian
05:09
created
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -20,199 +20,199 @@  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
-		// Create any missing database tables.
46
-		$method = "upgrade_from_$upgrade_from";
47
-
48
-		if ( method_exists( $this, $method ) ) {
49
-			$this->$method();
50
-		}
51
-
52
-	}
53
-
54
-	/**
55
-	 * Do a fresh install.
56
-	 *
57
-	 */
58
-	public function upgrade_from_0() {
59
-		$this->create_subscriptions_table();
60
-		$this->create_invoices_table();
61
-		$this->create_invoice_items_table();
62
-	}
63
-
64
-	/**
65
-	 * Upgrade to 0.0.5
66
-	 *
67
-	 */
68
-	public function upgrade_from_004() {
69
-		global $wpdb;
70
-
71
-		// Invoices.
72
-		$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' )" );
73
-		if ( ! empty( $results ) ) {
74
-			$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' )" );
75
-
76
-			// Clean post cache
77
-			foreach ( $results as $row ) {
78
-				clean_post_cache( $row->ID );
79
-			}
80
-
81
-		}
82
-
83
-		// Item meta key changes
84
-		$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' )";
85
-		$results = $wpdb->get_results( $query );
86
-
87
-		if ( ! empty( $results ) ) {
88
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
89
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
90
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
91
-
92
-			foreach ( $results as $row ) {
93
-				clean_post_cache( $row->post_id );
94
-			}
95
-
96
-		}
97
-
98
-		$this->upgrade_from_102();
99
-	}
100
-
101
-	/**
102
-	 * Upgrade to 1.0.3
103
-	 *
104
-	 */
105
-	public function upgrade_from_102() {
106
-		$this->create_subscriptions_table();
107
-		$this->upgrade_from_118();
108
-	}
109
-
110
-	/**
111
-	 * Upgrade to version 2.0.0.
112
-	 *
113
-	 */
114
-	public function upgrade_from_118() {
115
-		$this->create_invoices_table();
116
-		$this->create_invoice_items_table();
117
-		$this->migrate_old_invoices();
118
-	}
119
-
120
-	/**
121
-	 * Give administrators the capability to manage GetPaid.
122
-	 *
123
-	 */
124
-	public function add_capabilities() {
125
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
126
-	}
127
-
128
-	/**
129
-	 * Re-create GetPaid pages.
130
-	 *
131
-	 */
132
-	public function create_pages() {
133
-
134
-		$pages = apply_filters(
135
-			'wpinv_create_pages',
136
-			array(
137
-
138
-				// Checkout page.
139
-				'checkout_page' => array(
140
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
141
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
142
-					'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
+        // Create any missing database tables.
46
+        $method = "upgrade_from_$upgrade_from";
47
+
48
+        if ( method_exists( $this, $method ) ) {
49
+            $this->$method();
50
+        }
51
+
52
+    }
53
+
54
+    /**
55
+     * Do a fresh install.
56
+     *
57
+     */
58
+    public function upgrade_from_0() {
59
+        $this->create_subscriptions_table();
60
+        $this->create_invoices_table();
61
+        $this->create_invoice_items_table();
62
+    }
63
+
64
+    /**
65
+     * Upgrade to 0.0.5
66
+     *
67
+     */
68
+    public function upgrade_from_004() {
69
+        global $wpdb;
70
+
71
+        // Invoices.
72
+        $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' )" );
73
+        if ( ! empty( $results ) ) {
74
+            $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' )" );
75
+
76
+            // Clean post cache
77
+            foreach ( $results as $row ) {
78
+                clean_post_cache( $row->ID );
79
+            }
80
+
81
+        }
82
+
83
+        // Item meta key changes
84
+        $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' )";
85
+        $results = $wpdb->get_results( $query );
86
+
87
+        if ( ! empty( $results ) ) {
88
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
89
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
90
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
91
+
92
+            foreach ( $results as $row ) {
93
+                clean_post_cache( $row->post_id );
94
+            }
95
+
96
+        }
97
+
98
+        $this->upgrade_from_102();
99
+    }
100
+
101
+    /**
102
+     * Upgrade to 1.0.3
103
+     *
104
+     */
105
+    public function upgrade_from_102() {
106
+        $this->create_subscriptions_table();
107
+        $this->upgrade_from_118();
108
+    }
109
+
110
+    /**
111
+     * Upgrade to version 2.0.0.
112
+     *
113
+     */
114
+    public function upgrade_from_118() {
115
+        $this->create_invoices_table();
116
+        $this->create_invoice_items_table();
117
+        $this->migrate_old_invoices();
118
+    }
119
+
120
+    /**
121
+     * Give administrators the capability to manage GetPaid.
122
+     *
123
+     */
124
+    public function add_capabilities() {
125
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
126
+    }
127
+
128
+    /**
129
+     * Re-create GetPaid pages.
130
+     *
131
+     */
132
+    public function create_pages() {
133
+
134
+        $pages = apply_filters(
135
+            'wpinv_create_pages',
136
+            array(
137
+
138
+                // Checkout page.
139
+                'checkout_page' => array(
140
+                    'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
141
+                    'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
142
+                    'content'   => '
143 143
 						<!-- wp:shortcode -->
144 144
 						[wpinv_checkout]
145 145
 						<!-- /wp:shortcode -->
146 146
 					',
147
-					'parent'    => '',
148
-				),
149
-
150
-				// Invoice history page.
151
-				'invoice_history_page' => array(
152
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
153
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
154
-					'content' => '
147
+                    'parent'    => '',
148
+                ),
149
+
150
+                // Invoice history page.
151
+                'invoice_history_page' => array(
152
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
153
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
154
+                    'content' => '
155 155
 					<!-- wp:shortcode -->
156 156
 					[wpinv_history]
157 157
 					<!-- /wp:shortcode -->
158 158
 				',
159
-					'parent'  => '',
160
-				),
161
-
162
-				// Success page content.
163
-				'success_page' => array(
164
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
165
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
166
-					'content'  => '
159
+                    'parent'  => '',
160
+                ),
161
+
162
+                // Success page content.
163
+                'success_page' => array(
164
+                    'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
165
+                    'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
166
+                    'content'  => '
167 167
 					<!-- wp:shortcode -->
168 168
 					[wpinv_receipt]
169 169
 					<!-- /wp:shortcode -->
170 170
 				',
171
-					'parent'   => 'gp-checkout',
172
-				),
173
-
174
-				// Failure page content.
175
-				'failure_page' => array(
176
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
177
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
178
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
179
-					'parent'  => 'gp-checkout',
180
-				),
181
-
182
-				// Subscriptions history page.
183
-				'invoice_subscription_page' => array(
184
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
185
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
186
-					'content' => '
171
+                    'parent'   => 'gp-checkout',
172
+                ),
173
+
174
+                // Failure page content.
175
+                'failure_page' => array(
176
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
177
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
178
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
179
+                    'parent'  => 'gp-checkout',
180
+                ),
181
+
182
+                // Subscriptions history page.
183
+                'invoice_subscription_page' => array(
184
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
185
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
186
+                    'content' => '
187 187
 					<!-- wp:shortcode -->
188 188
 					[wpinv_subscriptions]
189 189
 					<!-- /wp:shortcode -->
190 190
 				',
191
-					'parent' => '',
192
-				),
191
+                    'parent' => '',
192
+                ),
193 193
 
194
-			)
195
-		);
194
+            )
195
+        );
196 196
 
197
-		foreach ( $pages as $key => $page ) {
198
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
199
-		}
197
+        foreach ( $pages as $key => $page ) {
198
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
199
+        }
200 200
 
201
-	}
201
+    }
202 202
 
203
-	/**
204
-	 * Create subscriptions table.
205
-	 *
206
-	 */
207
-	public function create_subscriptions_table() {
203
+    /**
204
+     * Create subscriptions table.
205
+     *
206
+     */
207
+    public function create_subscriptions_table() {
208 208
 
209
-		global $wpdb;
209
+        global $wpdb;
210 210
 
211
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
211
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
212 212
 
213
-		// Create tables.
214
-		$charset_collate = $wpdb->get_charset_collate();
215
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
213
+        // Create tables.
214
+        $charset_collate = $wpdb->get_charset_collate();
215
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
216 216
 			id bigint(20) unsigned NOT NULL auto_increment,
217 217
 			customer_id bigint(20) NOT NULL,
218 218
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -235,22 +235,22 @@  discard block
 block discarded – undo
235 235
 			KEY customer_and_status (customer_id, status)
236 236
 		  ) $charset_collate;";
237 237
 
238
-		dbDelta( $sql );
238
+        dbDelta( $sql );
239 239
 
240
-	}
240
+    }
241 241
 
242
-	/**
243
-	 * Create invoices table.
244
-	 *
245
-	 */
246
-	public function create_invoices_table() {
247
-		global $wpdb;
242
+    /**
243
+     * Create invoices table.
244
+     *
245
+     */
246
+    public function create_invoices_table() {
247
+        global $wpdb;
248 248
 
249
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
249
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
250 250
 
251
-		// Create tables.
252
-		$charset_collate = $wpdb->get_charset_collate();
253
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
251
+        // Create tables.
252
+        $charset_collate = $wpdb->get_charset_collate();
253
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
254 254
 			post_id BIGINT(20) NOT NULL,
255 255
             `number` VARCHAR(100),
256 256
             `key` VARCHAR(100),
@@ -286,22 +286,22 @@  discard block
 block discarded – undo
286 286
 			KEY `key` (`key`)
287 287
 		  ) $charset_collate;";
288 288
 
289
-		dbDelta( $sql );
289
+        dbDelta( $sql );
290 290
 
291
-	}
291
+    }
292 292
 
293
-	/**
294
-	 * Create invoice items table.
295
-	 *
296
-	 */
297
-	public function create_invoice_items_table() {
298
-		global $wpdb;
293
+    /**
294
+     * Create invoice items table.
295
+     *
296
+     */
297
+    public function create_invoice_items_table() {
298
+        global $wpdb;
299 299
 
300
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
300
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
301 301
 
302
-		// Create tables.
303
-		$charset_collate = $wpdb->get_charset_collate();
304
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
302
+        // Create tables.
303
+        $charset_collate = $wpdb->get_charset_collate();
304
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
305 305
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
306 306
             post_id BIGINT(20) NOT NULL,
307 307
             item_id BIGINT(20) NOT NULL,
@@ -323,138 +323,138 @@  discard block
 block discarded – undo
323 323
 			KEY post_id (post_id)
324 324
 		  ) $charset_collate;";
325 325
 
326
-		dbDelta( $sql );
327
-
328
-	}
329
-
330
-	/**
331
-	 * Migrates old invoices to new invoices.
332
-	 *
333
-	 */
334
-	public function migrate_old_invoices() {
335
-		global $wpdb;
336
-
337
-		$invoices = array_unique(
338
-			get_posts(
339
-				array(
340
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
341
-					'posts_per_page' => -1,
342
-					'fields'         => 'ids',
343
-					'post_status'    => array_keys( get_post_stati() ),
344
-				)
345
-			)
346
-		);
347
-
348
-		// Abort if we do not have any invoices.
349
-		if ( empty( $invoices ) ) {
350
-			return;
351
-		}
352
-
353
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
354
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
355
-
356
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
357
-
358
-		$invoice_rows = array();
359
-		foreach ( $invoices as $invoice ) {
360
-
361
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
362
-
363
-			if ( empty( $invoice->ID ) ) {
364
-				return;
365
-			}
366
-
367
-			$fields = array (
368
-				'post_id'        => $invoice->ID,
369
-				'number'         => $invoice->get_number(),
370
-				'key'            => $invoice->get_key(),
371
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
372
-				'mode'           => $invoice->mode,
373
-				'user_ip'        => $invoice->get_ip(),
374
-				'first_name'     => $invoice->get_first_name(),
375
-				'last_name'      => $invoice->get_last_name(),
376
-				'address'        => $invoice->get_address(),
377
-				'city'           => $invoice->city,
378
-				'state'          => $invoice->state,
379
-				'country'        => $invoice->country,
380
-				'zip'            => $invoice->zip,
381
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
382
-				'gateway'        => $invoice->get_gateway(),
383
-				'transaction_id' => $invoice->get_transaction_id(),
384
-				'currency'       => $invoice->get_currency(),
385
-				'subtotal'       => $invoice->get_subtotal(),
386
-				'tax'            => $invoice->get_tax(),
387
-				'fees_total'     => $invoice->get_fees_total(),
388
-				'total'          => $invoice->get_total(),
389
-				'discount'       => $invoice->get_discount(),
390
-				'discount_code'  => $invoice->get_discount_code(),
391
-				'disable_taxes'  => $invoice->disable_taxes,
392
-				'due_date'       => $invoice->get_due_date(),
393
-				'completed_date' => $invoice->get_completed_date(),
394
-				'company'        => $invoice->company,
395
-				'vat_number'     => $invoice->vat_number,
396
-				'vat_rate'       => $invoice->vat_rate,
397
-				'custom_meta'    => $invoice->payment_meta
398
-			);
399
-
400
-			foreach ( $fields as $key => $val ) {
401
-				if ( is_null( $val ) ) {
402
-					$val = '';
403
-				}
404
-				$val = maybe_serialize( $val );
405
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
406
-			}
407
-
408
-			$fields = implode( ', ', $fields );
409
-			$invoice_rows[] = "($fields)";
410
-
411
-			$item_rows    = array();
412
-			$item_columns = array();
413
-			foreach ( $invoice->get_cart_details() as $details ) {
414
-				$fields = array(
415
-					'post_id'          => $invoice->ID,
416
-					'item_id'          => $details['id'],
417
-					'item_name'        => $details['name'],
418
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
419
-					'vat_rate'         => $details['vat_rate'],
420
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
421
-					'tax'              => $details['tax'],
422
-					'item_price'       => $details['item_price'],
423
-					'custom_price'     => $details['custom_price'],
424
-					'quantity'         => $details['quantity'],
425
-					'discount'         => $details['discount'],
426
-					'subtotal'         => $details['subtotal'],
427
-					'price'            => $details['price'],
428
-					'meta'             => $details['meta'],
429
-					'fees'             => $details['fees'],
430
-				);
431
-
432
-				$item_columns = array_keys ( $fields );
433
-
434
-				foreach ( $fields as $key => $val ) {
435
-					if ( is_null( $val ) ) {
436
-						$val = '';
437
-					}
438
-					$val = maybe_serialize( $val );
439
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
440
-				}
441
-
442
-				$fields = implode( ', ', $fields );
443
-				$item_rows[] = "($fields)";
444
-			}
445
-
446
-			$item_rows    = implode( ', ', $item_rows );
447
-			$item_columns = implode( ', ', $item_columns );
448
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
449
-		}
450
-
451
-		if ( empty( $invoice_rows ) ) {
452
-			return;
453
-		}
454
-
455
-		$invoice_rows = implode( ', ', $invoice_rows );
456
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
457
-
458
-	}
326
+        dbDelta( $sql );
327
+
328
+    }
329
+
330
+    /**
331
+     * Migrates old invoices to new invoices.
332
+     *
333
+     */
334
+    public function migrate_old_invoices() {
335
+        global $wpdb;
336
+
337
+        $invoices = array_unique(
338
+            get_posts(
339
+                array(
340
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
341
+                    'posts_per_page' => -1,
342
+                    'fields'         => 'ids',
343
+                    'post_status'    => array_keys( get_post_stati() ),
344
+                )
345
+            )
346
+        );
347
+
348
+        // Abort if we do not have any invoices.
349
+        if ( empty( $invoices ) ) {
350
+            return;
351
+        }
352
+
353
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
354
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
355
+
356
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
357
+
358
+        $invoice_rows = array();
359
+        foreach ( $invoices as $invoice ) {
360
+
361
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
362
+
363
+            if ( empty( $invoice->ID ) ) {
364
+                return;
365
+            }
366
+
367
+            $fields = array (
368
+                'post_id'        => $invoice->ID,
369
+                'number'         => $invoice->get_number(),
370
+                'key'            => $invoice->get_key(),
371
+                'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
372
+                'mode'           => $invoice->mode,
373
+                'user_ip'        => $invoice->get_ip(),
374
+                'first_name'     => $invoice->get_first_name(),
375
+                'last_name'      => $invoice->get_last_name(),
376
+                'address'        => $invoice->get_address(),
377
+                'city'           => $invoice->city,
378
+                'state'          => $invoice->state,
379
+                'country'        => $invoice->country,
380
+                'zip'            => $invoice->zip,
381
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
382
+                'gateway'        => $invoice->get_gateway(),
383
+                'transaction_id' => $invoice->get_transaction_id(),
384
+                'currency'       => $invoice->get_currency(),
385
+                'subtotal'       => $invoice->get_subtotal(),
386
+                'tax'            => $invoice->get_tax(),
387
+                'fees_total'     => $invoice->get_fees_total(),
388
+                'total'          => $invoice->get_total(),
389
+                'discount'       => $invoice->get_discount(),
390
+                'discount_code'  => $invoice->get_discount_code(),
391
+                'disable_taxes'  => $invoice->disable_taxes,
392
+                'due_date'       => $invoice->get_due_date(),
393
+                'completed_date' => $invoice->get_completed_date(),
394
+                'company'        => $invoice->company,
395
+                'vat_number'     => $invoice->vat_number,
396
+                'vat_rate'       => $invoice->vat_rate,
397
+                'custom_meta'    => $invoice->payment_meta
398
+            );
399
+
400
+            foreach ( $fields as $key => $val ) {
401
+                if ( is_null( $val ) ) {
402
+                    $val = '';
403
+                }
404
+                $val = maybe_serialize( $val );
405
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
406
+            }
407
+
408
+            $fields = implode( ', ', $fields );
409
+            $invoice_rows[] = "($fields)";
410
+
411
+            $item_rows    = array();
412
+            $item_columns = array();
413
+            foreach ( $invoice->get_cart_details() as $details ) {
414
+                $fields = array(
415
+                    'post_id'          => $invoice->ID,
416
+                    'item_id'          => $details['id'],
417
+                    'item_name'        => $details['name'],
418
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
419
+                    'vat_rate'         => $details['vat_rate'],
420
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
421
+                    'tax'              => $details['tax'],
422
+                    'item_price'       => $details['item_price'],
423
+                    'custom_price'     => $details['custom_price'],
424
+                    'quantity'         => $details['quantity'],
425
+                    'discount'         => $details['discount'],
426
+                    'subtotal'         => $details['subtotal'],
427
+                    'price'            => $details['price'],
428
+                    'meta'             => $details['meta'],
429
+                    'fees'             => $details['fees'],
430
+                );
431
+
432
+                $item_columns = array_keys ( $fields );
433
+
434
+                foreach ( $fields as $key => $val ) {
435
+                    if ( is_null( $val ) ) {
436
+                        $val = '';
437
+                    }
438
+                    $val = maybe_serialize( $val );
439
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
440
+                }
441
+
442
+                $fields = implode( ', ', $fields );
443
+                $item_rows[] = "($fields)";
444
+            }
445
+
446
+            $item_rows    = implode( ', ', $item_rows );
447
+            $item_columns = implode( ', ', $item_columns );
448
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
449
+        }
450
+
451
+        if ( empty( $invoice_rows ) ) {
452
+            return;
453
+        }
454
+
455
+        $invoice_rows = implode( ', ', $invoice_rows );
456
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
457
+
458
+    }
459 459
 
460 460
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin.php 1 patch
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
 class GetPaid_Admin {
15 15
 
16 16
     /**
17
-	 * Local path to this plugins admin directory
18
-	 *
19
-	 * @var         string
20
-	 */
21
-	public $admin_path;
22
-
23
-	/**
24
-	 * Web path to this plugins admin directory
25
-	 *
26
-	 * @var         string
27
-	 */
28
-	public $admin_url;
17
+     * Local path to this plugins admin directory
18
+     *
19
+     * @var         string
20
+     */
21
+    public $admin_path;
22
+
23
+    /**
24
+     * Web path to this plugins admin directory
25
+     *
26
+     * @var         string
27
+     */
28
+    public $admin_url;
29 29
 	
30
-	/**
31
-	 * Reports components.
32
-	 *
33
-	 * @var GetPaid_Reports
34
-	 */
30
+    /**
31
+     * Reports components.
32
+     *
33
+     * @var GetPaid_Reports
34
+     */
35 35
     public $reports;
36 36
 
37 37
     /**
38
-	 * Class constructor.
39
-	 */
40
-	public function __construct(){
38
+     * Class constructor.
39
+     */
40
+    public function __construct(){
41 41
 
42 42
         $this->admin_path  = plugin_dir_path( __FILE__ );
43
-		$this->admin_url   = plugins_url( '/', __FILE__ );
44
-		$this->reports     = new GetPaid_Reports();
43
+        $this->admin_url   = plugins_url( '/', __FILE__ );
44
+        $this->reports     = new GetPaid_Reports();
45 45
 
46 46
         if ( is_admin() ) {
47
-			$this->init_admin_hooks();
47
+            $this->init_admin_hooks();
48 48
         }
49 49
 
50 50
     }
51 51
 
52 52
     /**
53
-	 * Init action and filter hooks
54
-	 *
55
-	 */
56
-	private function init_admin_hooks() {
53
+     * Init action and filter hooks
54
+     *
55
+     */
56
+    private function init_admin_hooks() {
57 57
         add_action( 'admin_enqueue_scripts', array( $this, 'enqeue_scripts' ) );
58 58
         add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
59 59
         add_action( 'admin_init', array( $this, 'init_ayecode_connect_helper' ) );
60 60
         add_action( 'admin_init', array( $this, 'activation_redirect') );
61 61
         add_action( 'admin_init', array( $this, 'maybe_do_admin_action') );
62
-		add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
-		add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
-		add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
-		add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
62
+        add_action( 'admin_notices', array( $this, 'show_notices' ) );
63
+        add_action( 'getpaid_authenticated_admin_action_rate_plugin', array( $this, 'redirect_to_wordpress_rating_page' ) );
64
+        add_action( 'getpaid_authenticated_admin_action_send_invoice', array( $this, 'send_customer_invoice' ) );
65
+        add_action( 'getpaid_authenticated_admin_action_send_invoice_reminder', array( $this, 'send_customer_payment_reminder' ) );
66 66
         add_action( 'getpaid_authenticated_admin_action_reset_tax_rates', array( $this, 'admin_reset_tax_rates' ) );
67
-		add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
68
-		do_action( 'getpaid_init_admin_hooks', $this );
67
+        add_filter( 'admin_footer_text', array( $this, 'admin_footer_text' ) );
68
+        do_action( 'getpaid_init_admin_hooks', $this );
69 69
 
70 70
     }
71 71
 
72 72
     /**
73
-	 * Register admin scripts
74
-	 *
75
-	 */
76
-	public function enqeue_scripts() {
73
+     * Register admin scripts
74
+     *
75
+     */
76
+    public function enqeue_scripts() {
77 77
         global $current_screen, $pagenow;
78 78
 
79
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
80
-		$editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
79
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
80
+        $editing = $pagenow == 'post.php' || $pagenow == 'post-new.php';
81 81
 
82 82
         if ( ! empty( $current_screen->post_type ) ) {
83
-			$page = $current_screen->post_type;
83
+            $page = $current_screen->post_type;
84 84
         }
85 85
 
86 86
         // General styles.
@@ -103,54 +103,54 @@  discard block
 block discarded – undo
103 103
         }
104 104
 
105 105
         // Payment form scripts.
106
-		if ( 'wpi_payment_form' == $page && $editing ) {
106
+        if ( 'wpi_payment_form' == $page && $editing ) {
107 107
             $this->load_payment_form_scripts();
108 108
         }
109 109
 
110
-		if ( $page == 'wpinv-subscriptions' ) {
111
-			wp_enqueue_script( 'postbox' );
112
-		}
110
+        if ( $page == 'wpinv-subscriptions' ) {
111
+            wp_enqueue_script( 'postbox' );
112
+        }
113 113
 
114 114
     }
115 115
 
116 116
     /**
117
-	 * Returns admin js translations.
118
-	 *
119
-	 */
120
-	protected function get_admin_i18() {
117
+     * Returns admin js translations.
118
+     *
119
+     */
120
+    protected function get_admin_i18() {
121 121
         global $post;
122 122
 
123
-		$date_range = array(
124
-			'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
125
-		);
123
+        $date_range = array(
124
+            'period' => isset( $_GET['date_range'] ) ? sanitize_text_field( $_GET['date_range'] ) : '7_days'
125
+        );
126 126
 
127
-		if ( $date_range['period'] == 'custom' ) {
127
+        if ( $date_range['period'] == 'custom' ) {
128 128
 			
129
-			if ( isset( $_GET['from'] ) ) {
130
-				$date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
131
-			}
129
+            if ( isset( $_GET['from'] ) ) {
130
+                $date_range[ 'after' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['from'] ), current_time( 'timestamp' ) ) - DAY_IN_SECONDS );
131
+            }
132 132
 
133
-			if ( isset( $_GET['to'] ) ) {
134
-				$date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
135
-			}
133
+            if ( isset( $_GET['to'] ) ) {
134
+                $date_range[ 'before' ] = date( 'Y-m-d', strtotime( sanitize_text_field( $_GET['to'] ), current_time( 'timestamp' ) ) + DAY_IN_SECONDS );
135
+            }
136 136
 
137
-		}
137
+        }
138 138
 
139 139
         $i18n = array(
140 140
             'ajax_url'                  => admin_url( 'admin-ajax.php' ),
141 141
             'post_ID'                   => isset( $post->ID ) ? $post->ID : '',
142
-			'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
143
-			'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
144
-			'rest_root'                 => esc_url_raw( rest_url() ),
145
-			'date_range'                => $date_range,
142
+            'wpinv_nonce'               => wp_create_nonce( 'wpinv-nonce' ),
143
+            'rest_nonce'                => wp_create_nonce( 'wp_rest' ),
144
+            'rest_root'                 => esc_url_raw( rest_url() ),
145
+            'date_range'                => $date_range,
146 146
             'add_invoice_note_nonce'    => wp_create_nonce( 'add-invoice-note' ),
147 147
             'delete_invoice_note_nonce' => wp_create_nonce( 'delete-invoice-note' ),
148 148
             'invoice_item_nonce'        => wp_create_nonce( 'invoice-item' ),
149 149
             'billing_details_nonce'     => wp_create_nonce( 'get-billing-details' ),
150 150
             'tax'                       => wpinv_tax_amount(),
151 151
             'discount'                  => 0,
152
-			'currency_symbol'           => wpinv_currency_symbol(),
153
-			'currency'                  => wpinv_get_currency(),
152
+            'currency_symbol'           => wpinv_currency_symbol(),
153
+            'currency'                  => wpinv_get_currency(),
154 154
             'currency_pos'              => wpinv_currency_position(),
155 155
             'thousand_sep'              => wpinv_thousands_separator(),
156 156
             'decimal_sep'               => wpinv_decimal_separator(),
@@ -173,112 +173,112 @@  discard block
 block discarded – undo
173 173
             'searching'                 => __( 'Searching', 'invoicing' ),
174 174
         );
175 175
 
176
-		if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
176
+        if ( ! empty( $post ) && getpaid_is_invoice_post_type( $post->post_type ) ) {
177 177
 
178
-			$invoice              = new WPInv_Invoice( $post );
179
-			$i18n['save_invoice'] = sprintf(
180
-				__( 'Save %s', 'invoicing' ),
181
-				ucfirst( $invoice->get_invoice_quote_type() )
182
-			);
178
+            $invoice              = new WPInv_Invoice( $post );
179
+            $i18n['save_invoice'] = sprintf(
180
+                __( 'Save %s', 'invoicing' ),
181
+                ucfirst( $invoice->get_invoice_quote_type() )
182
+            );
183 183
 
184
-			$i18n['invoice_description'] = sprintf(
185
-				__( '%s Description', 'invoicing' ),
186
-				ucfirst( $invoice->get_invoice_quote_type() )
187
-			);
184
+            $i18n['invoice_description'] = sprintf(
185
+                __( '%s Description', 'invoicing' ),
186
+                ucfirst( $invoice->get_invoice_quote_type() )
187
+            );
188 188
 
189
-		}
190
-		return $i18n;
191
-	}
189
+        }
190
+        return $i18n;
191
+    }
192 192
 
193
-	/**
194
-	 * Change the admin footer text on GetPaid admin pages.
195
-	 *
196
-	 * @since  2.0.0
197
-	 * @param  string $footer_text
198
-	 * @return string
199
-	 */
200
-	public function admin_footer_text( $footer_text ) {
201
-		global $current_screen;
193
+    /**
194
+     * Change the admin footer text on GetPaid admin pages.
195
+     *
196
+     * @since  2.0.0
197
+     * @param  string $footer_text
198
+     * @return string
199
+     */
200
+    public function admin_footer_text( $footer_text ) {
201
+        global $current_screen;
202 202
 
203
-		$page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
203
+        $page    = isset( $_GET['page'] ) ? $_GET['page'] : '';
204 204
 
205 205
         if ( ! empty( $current_screen->post_type ) ) {
206
-			$page = $current_screen->post_type;
206
+            $page = $current_screen->post_type;
207 207
         }
208 208
 
209 209
         // General styles.
210 210
         if ( apply_filters( 'getpaid_display_admin_footer_text', wpinv_current_user_can_manage_invoicing() ) && false !== stripos( $page, 'wpi' ) ) {
211 211
 
212
-			// Change the footer text
213
-			if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
214
-
215
-				$rating_url  = esc_url(
216
-					wp_nonce_url(
217
-						admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
218
-						'getpaid-nonce',
219
-						'getpaid-nonce'
220
-						)
221
-				);
222
-
223
-				$footer_text = sprintf(
224
-					/* translators: %s: five stars */
225
-					__( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
226
-					"<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
227
-				);
228
-
229
-			} else {
230
-
231
-				$footer_text = sprintf(
232
-					/* translators: %s: GetPaid */
233
-					__( 'Thank you for using %s!', 'invoicing' ),
234
-					"<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
235
-				);
236
-
237
-			}
238
-
239
-		}
240
-
241
-		return $footer_text;
242
-	}
243
-
244
-	/**
245
-	 * Redirects to wp.org to rate the plugin.
246
-	 *
247
-	 * @since  2.0.0
248
-	 */
249
-	public function redirect_to_wordpress_rating_page() {
250
-		update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
251
-		wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
252
-		exit;
253
-	}
212
+            // Change the footer text
213
+            if ( ! get_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', true ) ) {
214
+
215
+                $rating_url  = esc_url(
216
+                    wp_nonce_url(
217
+                        admin_url( 'admin.php?page=wpinv-reports&getpaid-admin-action=rate_plugin' ),
218
+                        'getpaid-nonce',
219
+                        'getpaid-nonce'
220
+                        )
221
+                );
222
+
223
+                $footer_text = sprintf(
224
+                    /* translators: %s: five stars */
225
+                    __( 'If you like <strong>GetPaid</strong>, please leave us a %s rating. A huge thanks in advance!', 'invoicing' ),
226
+                    "<a href='$rating_url'>&#9733;&#9733;&#9733;&#9733;&#9733;</a>"
227
+                );
228
+
229
+            } else {
230
+
231
+                $footer_text = sprintf(
232
+                    /* translators: %s: GetPaid */
233
+                    __( 'Thank you for using %s!', 'invoicing' ),
234
+                    "<a href='https://wpgetpaid.com/' target='_blank'><strong>GetPaid</strong></a>"
235
+                );
236
+
237
+            }
238
+
239
+        }
240
+
241
+        return $footer_text;
242
+    }
254 243
 
255 244
     /**
256
-	 * Loads payment form js.
257
-	 *
258
-	 */
259
-	protected function load_payment_form_scripts() {
245
+     * Redirects to wp.org to rate the plugin.
246
+     *
247
+     * @since  2.0.0
248
+     */
249
+    public function redirect_to_wordpress_rating_page() {
250
+        update_user_meta( get_current_user_id(), 'getpaid_admin_footer_text_rated', 1 );
251
+        wp_redirect( 'https://wordpress.org/support/plugin/invoicing/reviews?rate=5#new-post' );
252
+        exit;
253
+    }
254
+
255
+    /**
256
+     * Loads payment form js.
257
+     *
258
+     */
259
+    protected function load_payment_form_scripts() {
260 260
         global $post;
261 261
 
262 262
         wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
263
-		wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
264
-		wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
263
+        wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
264
+        wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
265 265
 
266
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
267
-		wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
266
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
267
+        wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
268 268
 
269
-		wp_localize_script(
269
+        wp_localize_script(
270 270
             'wpinv-admin-payment-form-script',
271 271
             'wpinvPaymentFormAdmin',
272 272
             array(
273
-				'elements'      => wpinv_get_data( 'payment-form-elements' ),
274
-				'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
275
-				'currency'      => wpinv_currency_symbol(),
276
-				'position'      => wpinv_currency_position(),
277
-				'decimals'      => (int) wpinv_decimals(),
278
-				'thousands_sep' => wpinv_thousands_separator(),
279
-				'decimals_sep'  => wpinv_decimal_separator(),
280
-				'form_items'    => gepaid_get_form_items( $post->ID ),
281
-				'is_default'    => $post->ID == wpinv_get_default_payment_form(),
273
+                'elements'      => wpinv_get_data( 'payment-form-elements' ),
274
+                'form_elements' => getpaid_get_payment_form_elements( $post->ID ),
275
+                'currency'      => wpinv_currency_symbol(),
276
+                'position'      => wpinv_currency_position(),
277
+                'decimals'      => (int) wpinv_decimals(),
278
+                'thousands_sep' => wpinv_thousands_separator(),
279
+                'decimals_sep'  => wpinv_decimal_separator(),
280
+                'form_items'    => gepaid_get_form_items( $post->ID ),
281
+                'is_default'    => $post->ID == wpinv_get_default_payment_form(),
282 282
             )
283 283
         );
284 284
 
@@ -287,20 +287,20 @@  discard block
 block discarded – undo
287 287
     }
288 288
 
289 289
     /**
290
-	 * Add our classes to admin pages.
290
+     * Add our classes to admin pages.
291 291
      *
292 292
      * @param string $classes
293 293
      * @return string
294
-	 *
295
-	 */
294
+     *
295
+     */
296 296
     public function admin_body_class( $classes ) {
297
-		global $pagenow, $post, $current_screen;
297
+        global $pagenow, $post, $current_screen;
298 298
 
299 299
 
300 300
         $page = isset( $_GET['page'] ) ? $_GET['page'] : '';
301 301
 
302 302
         if ( ! empty( $current_screen->post_type ) ) {
303
-			$page = $current_screen->post_type;
303
+            $page = $current_screen->post_type;
304 304
         }
305 305
 
306 306
         if ( false !== stripos( $page, 'wpi' ) ) {
@@ -309,59 +309,59 @@  discard block
 block discarded – undo
309 309
 
310 310
         if ( in_array( $page, wpinv_parse_list( 'wpi_invoice wpi_payment_form wpi_quote' ) ) ) {
311 311
             $classes .= ' wpinv-cpt wpinv';
312
-		}
312
+        }
313 313
 		
314
-		if ( getpaid_is_invoice_post_type( $page ) ) {
314
+        if ( getpaid_is_invoice_post_type( $page ) ) {
315 315
             $classes .= ' getpaid-is-invoice-cpt';
316 316
         }
317 317
 
318
-		return $classes;
318
+        return $classes;
319 319
     }
320 320
 
321 321
     /**
322
-	 * Maybe show the AyeCode Connect Notice.
323
-	 */
324
-	public function init_ayecode_connect_helper(){
322
+     * Maybe show the AyeCode Connect Notice.
323
+     */
324
+    public function init_ayecode_connect_helper(){
325 325
 
326 326
         new AyeCode_Connect_Helper(
327 327
             array(
328
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
329
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
330
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
331
-				'connect_button'    => __("Connect Site","invoicing"),
332
-				'connecting_button'    => __("Connecting...","invoicing"),
333
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
334
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
328
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
329
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
330
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
331
+                'connect_button'    => __("Connect Site","invoicing"),
332
+                'connecting_button'    => __("Connecting...","invoicing"),
333
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
334
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
335 335
             ),
336 336
             array( 'wpi-addons' )
337 337
         );
338 338
 
339 339
     }
340 340
 
341
-	/**
342
-	 * Redirect users to settings on activation.
343
-	 *
344
-	 * @return void
345
-	 */
346
-	public function activation_redirect() {
341
+    /**
342
+     * Redirect users to settings on activation.
343
+     *
344
+     * @return void
345
+     */
346
+    public function activation_redirect() {
347 347
 
348
-		$redirected = get_option( 'wpinv_redirected_to_settings' );
348
+        $redirected = get_option( 'wpinv_redirected_to_settings' );
349 349
 
350
-		if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
351
-			return;
352
-		}
350
+        if ( ! empty( $redirected ) || wp_doing_ajax() || ! current_user_can( 'manage_options' ) ) {
351
+            return;
352
+        }
353 353
 
354
-		// Bail if activating from network, or bulk
355
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
356
-			return;
357
-		}
354
+        // Bail if activating from network, or bulk
355
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
356
+            return;
357
+        }
358 358
 
359
-	    update_option( 'wpinv_redirected_to_settings', 1 );
359
+        update_option( 'wpinv_redirected_to_settings', 1 );
360 360
 
361 361
         wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
362 362
         exit;
363 363
 
364
-	}
364
+    }
365 365
 
366 366
     /**
367 367
      * Fires an admin action after verifying that a user can fire them.
@@ -375,162 +375,162 @@  discard block
 block discarded – undo
375 375
 
376 376
     }
377 377
 
378
-	/**
378
+    /**
379 379
      * Sends a payment reminder to a customer.
380
-	 * 
381
-	 * @param array $args
380
+     * 
381
+     * @param array $args
382 382
      */
383 383
     public function send_customer_invoice( $args ) {
384
-		$sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
384
+        $sent = getpaid()->get( 'invoice_emails' )->user_invoice( new WPInv_Invoice( $args['invoice_id'] ) );
385 385
 
386
-		if ( $sent ) {
387
-			$this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
388
-		} else {
389
-			$this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
390
-		}
386
+        if ( $sent ) {
387
+            $this->show_success( __( 'Invoice was successfully sent to the customer', 'invoicing' ) );
388
+        } else {
389
+            $this->show_error( __( 'Could not sent the invoice to the customer', 'invoicing' ) );
390
+        }
391 391
 
392
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
393
-		exit;
394
-	}
392
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
393
+        exit;
394
+    }
395 395
 
396
-	/**
396
+    /**
397 397
      * Sends a payment reminder to a customer.
398
-	 * 
399
-	 * @param array $args
398
+     * 
399
+     * @param array $args
400 400
      */
401 401
     public function send_customer_payment_reminder( $args ) {
402
-		$sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
402
+        $sent = getpaid()->get( 'invoice_emails' )->force_send_overdue_notice( new WPInv_Invoice( $args['invoice_id'] ) );
403 403
 
404
-		if ( $sent ) {
405
-			$this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
406
-		} else {
407
-			$this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
408
-		}
404
+        if ( $sent ) {
405
+            $this->show_success( __( 'Payment reminder was successfully sent to the customer', 'invoicing' ) );
406
+        } else {
407
+            $this->show_error( __( 'Could not sent payment reminder to the customer', 'invoicing' ) );
408
+        }
409 409
 
410
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
411
-		exit;
412
-	}
410
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce', 'invoice_id' ) ) );
411
+        exit;
412
+    }
413 413
 
414
-	/**
414
+    /**
415 415
      * Resets tax rates.
416
-	 * 
416
+     * 
417 417
      */
418 418
     public function admin_reset_tax_rates() {
419 419
 
420
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
421
-		wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
422
-		exit;
420
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
421
+        wp_safe_redirect( remove_query_arg( array( 'getpaid-admin-action', 'getpaid-nonce' ) ) );
422
+        exit;
423 423
 
424
-	}
424
+    }
425 425
 
426 426
     /**
427
-	 * Returns an array of admin notices.
428
-	 *
429
-	 * @since       1.0.19
427
+     * Returns an array of admin notices.
428
+     *
429
+     * @since       1.0.19
430 430
      * @return array
431
-	 */
432
-	public function get_notices() {
433
-		$notices = get_option( 'wpinv_admin_notices' );
431
+     */
432
+    public function get_notices() {
433
+        $notices = get_option( 'wpinv_admin_notices' );
434 434
         return is_array( $notices ) ? $notices : array();
435
-	}
436
-
437
-	/**
438
-	 * Clears all admin notices
439
-	 *
440
-	 * @access      public
441
-	 * @since       1.0.19
442
-	 */
443
-	public function clear_notices() {
444
-		delete_option( 'wpinv_admin_notices' );
445
-	}
446
-
447
-	/**
448
-	 * Saves a new admin notice
449
-	 *
450
-	 * @access      public
451
-	 * @since       1.0.19
452
-	 */
453
-	public function save_notice( $type, $message ) {
454
-		$notices = $this->get_notices();
455
-
456
-		if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
457
-			$notices[ $type ] = array();
458
-		}
459
-
460
-		$notices[ $type ][] = $message;
461
-
462
-		update_option( 'wpinv_admin_notices', $notices );
463
-	}
464
-
465
-	/**
466
-	 * Displays a success notice
467
-	 *
468
-	 * @param       string $msg The message to qeue.
469
-	 * @access      public
470
-	 * @since       1.0.19
471
-	 */
472
-	public function show_success( $msg ) {
473
-		$this->save_notice( 'success', $msg );
474
-	}
475
-
476
-	/**
477
-	 * Displays a error notice
478
-	 *
479
-	 * @access      public
480
-	 * @param       string $msg The message to qeue.
481
-	 * @since       1.0.19
482
-	 */
483
-	public function show_error( $msg ) {
484
-		$this->save_notice( 'error', $msg );
485
-	}
486
-
487
-	/**
488
-	 * Displays a warning notice
489
-	 *
490
-	 * @access      public
491
-	 * @param       string $msg The message to qeue.
492
-	 * @since       1.0.19
493
-	 */
494
-	public function show_warning( $msg ) {
495
-		$this->save_notice( 'warning', $msg );
496
-	}
497
-
498
-	/**
499
-	 * Displays a info notice
500
-	 *
501
-	 * @access      public
502
-	 * @param       string $msg The message to qeue.
503
-	 * @since       1.0.19
504
-	 */
505
-	public function show_info( $msg ) {
506
-		$this->save_notice( 'info', $msg );
507
-	}
508
-
509
-	/**
510
-	 * Show notices
511
-	 *
512
-	 * @access      public
513
-	 * @since       1.0.19
514
-	 */
515
-	public function show_notices() {
435
+    }
436
+
437
+    /**
438
+     * Clears all admin notices
439
+     *
440
+     * @access      public
441
+     * @since       1.0.19
442
+     */
443
+    public function clear_notices() {
444
+        delete_option( 'wpinv_admin_notices' );
445
+    }
446
+
447
+    /**
448
+     * Saves a new admin notice
449
+     *
450
+     * @access      public
451
+     * @since       1.0.19
452
+     */
453
+    public function save_notice( $type, $message ) {
454
+        $notices = $this->get_notices();
455
+
456
+        if ( empty( $notices[ $type ] ) || ! is_array( $notices[ $type ]) ) {
457
+            $notices[ $type ] = array();
458
+        }
459
+
460
+        $notices[ $type ][] = $message;
461
+
462
+        update_option( 'wpinv_admin_notices', $notices );
463
+    }
464
+
465
+    /**
466
+     * Displays a success notice
467
+     *
468
+     * @param       string $msg The message to qeue.
469
+     * @access      public
470
+     * @since       1.0.19
471
+     */
472
+    public function show_success( $msg ) {
473
+        $this->save_notice( 'success', $msg );
474
+    }
475
+
476
+    /**
477
+     * Displays a error notice
478
+     *
479
+     * @access      public
480
+     * @param       string $msg The message to qeue.
481
+     * @since       1.0.19
482
+     */
483
+    public function show_error( $msg ) {
484
+        $this->save_notice( 'error', $msg );
485
+    }
486
+
487
+    /**
488
+     * Displays a warning notice
489
+     *
490
+     * @access      public
491
+     * @param       string $msg The message to qeue.
492
+     * @since       1.0.19
493
+     */
494
+    public function show_warning( $msg ) {
495
+        $this->save_notice( 'warning', $msg );
496
+    }
497
+
498
+    /**
499
+     * Displays a info notice
500
+     *
501
+     * @access      public
502
+     * @param       string $msg The message to qeue.
503
+     * @since       1.0.19
504
+     */
505
+    public function show_info( $msg ) {
506
+        $this->save_notice( 'info', $msg );
507
+    }
508
+
509
+    /**
510
+     * Show notices
511
+     *
512
+     * @access      public
513
+     * @since       1.0.19
514
+     */
515
+    public function show_notices() {
516 516
 
517 517
         $notices = $this->get_notices();
518 518
         $this->clear_notices();
519 519
 
520
-		foreach ( $notices as $type => $messages ) {
520
+        foreach ( $notices as $type => $messages ) {
521 521
 
522
-			if ( ! is_array( $messages ) ) {
523
-				continue;
524
-			}
522
+            if ( ! is_array( $messages ) ) {
523
+                continue;
524
+            }
525 525
 
526 526
             $type  = sanitize_key( $type );
527
-			foreach ( $messages as $message ) {
527
+            foreach ( $messages as $message ) {
528 528
                 $message = wp_kses_post( $message );
529
-				echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
529
+                echo "<div class='notice notice-$type is-dismissible'><p>$message</p></div>";
530 530
             }
531 531
 
532 532
         }
533 533
 
534
-	}
534
+    }
535 535
 
536 536
 }
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +288 added lines, -288 removed lines patch added patch discarded remove patch
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = wpinv_clean( $option['desc'] );
201
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
203
-	}
199
+    if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
+        $tip   = wpinv_clean( $option['desc'] );
201
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
+        unset( $option['desc'] );
203
+    }
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
             'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
228 228
             'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
229 229
             'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
230
-			'class'       => isset( $option['class'] )     ? $option['class']         : '',
231
-			'style'       => isset( $option['style'] )     ? $option['style']         : '',
230
+            'class'       => isset( $option['class'] )     ? $option['class']         : '',
231
+            'style'       => isset( $option['style'] )     ? $option['style']         : '',
232 232
             'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
233 233
             'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
234 234
         )
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @return array
243 243
  */
244 244
 function wpinv_get_registered_settings() {
245
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
245
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
246 246
 }
247 247
 
248 248
 /**
@@ -289,10 +289,10 @@  discard block
 block discarded – undo
289 289
         }
290 290
 
291 291
         // General filter
292
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
292
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
293 293
 
294
-		// Key specific filter.
295
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
294
+        // Key specific filter.
295
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
296 296
     }
297 297
 
298 298
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
 
349 349
     foreach ( $new_rates as $rate ) {
350 350
 
351
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
352
-		$rate['name']    = sanitize_text_field( $rate['name'] );
353
-		$rate['state']   = sanitize_text_field( $rate['state'] );
354
-		$rate['country'] = sanitize_text_field( $rate['country'] );
355
-		$rate['global']  = empty( $rate['state'] );
356
-		$tax_rates[]     = $rate;
351
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
352
+        $rate['name']    = sanitize_text_field( $rate['name'] );
353
+        $rate['state']   = sanitize_text_field( $rate['state'] );
354
+        $rate['country'] = sanitize_text_field( $rate['country'] );
355
+        $rate['global']  = empty( $rate['state'] );
356
+        $tax_rates[]     = $rate;
357 357
 
358
-	}
358
+    }
359 359
 
360 360
     update_option( 'wpinv_tax_rates', $tax_rates );
361 361
 
@@ -373,11 +373,11 @@  discard block
 block discarded – undo
373 373
     $tabs['general']  = __( 'General', 'invoicing' );
374 374
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
375 375
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
376
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
376
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
377 377
 
378
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
379
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
380
-	}
378
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
379
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
380
+    }
381 381
 
382 382
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
383 383
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -415,14 +415,14 @@  discard block
 block discarded – undo
415 415
         ) ),
416 416
         'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
417 417
             'main'  => __( 'Tax Settings', 'invoicing' ),
418
-			'rates' => __( 'Tax Rates', 'invoicing' ),
419
-			'vat'   => __( 'EU VAT Settings', 'invoicing' )
418
+            'rates' => __( 'Tax Rates', 'invoicing' ),
419
+            'vat'   => __( 'EU VAT Settings', 'invoicing' )
420 420
         ) ),
421 421
         'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
422 422
             'main' => __( 'Email Settings', 'invoicing' ),
423
-		) ),
423
+        ) ),
424 424
 
425
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
425
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
426 426
 
427 427
         'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
428 428
             'main' => __( 'Privacy policy', 'invoicing' ),
@@ -442,51 +442,51 @@  discard block
 block discarded – undo
442 442
 }
443 443
 
444 444
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
445
-	$pages_options = array();
445
+    $pages_options = array();
446 446
 
447
-	if( $default_label !== NULL && $default_label !== false ) {
448
-		$pages_options = array( '' => $default_label ); // Blank option
449
-	}
447
+    if( $default_label !== NULL && $default_label !== false ) {
448
+        $pages_options = array( '' => $default_label ); // Blank option
449
+    }
450 450
 
451
-	$pages = get_pages();
452
-	if ( $pages ) {
453
-		foreach ( $pages as $page ) {
454
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
451
+    $pages = get_pages();
452
+    if ( $pages ) {
453
+        foreach ( $pages as $page ) {
454
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
455 455
             $pages_options[ $page->ID ] = $title;
456
-		}
457
-	}
456
+        }
457
+    }
458 458
 
459
-	return $pages_options;
459
+    return $pages_options;
460 460
 }
461 461
 
462 462
 function wpinv_header_callback( $args ) {
463
-	if ( !empty( $args['desc'] ) ) {
463
+    if ( !empty( $args['desc'] ) ) {
464 464
         echo $args['desc'];
465 465
     }
466 466
 }
467 467
 
468 468
 function wpinv_hidden_callback( $args ) {
469
-	global $wpinv_options;
470
-
471
-	if ( isset( $args['set_value'] ) ) {
472
-		$value = $args['set_value'];
473
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
474
-		$value = $wpinv_options[ $args['id'] ];
475
-	} else {
476
-		$value = isset( $args['std'] ) ? $args['std'] : '';
477
-	}
478
-
479
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
480
-		$args['readonly'] = true;
481
-		$value = isset( $args['std'] ) ? $args['std'] : '';
482
-		$name  = '';
483
-	} else {
484
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
485
-	}
486
-
487
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
469
+    global $wpinv_options;
470
+
471
+    if ( isset( $args['set_value'] ) ) {
472
+        $value = $args['set_value'];
473
+    } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
474
+        $value = $wpinv_options[ $args['id'] ];
475
+    } else {
476
+        $value = isset( $args['std'] ) ? $args['std'] : '';
477
+    }
478
+
479
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
480
+        $args['readonly'] = true;
481
+        $value = isset( $args['std'] ) ? $args['std'] : '';
482
+        $name  = '';
483
+    } else {
484
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
485
+    }
486
+
487
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
488 488
     
489
-	echo $html;
489
+    echo $html;
490 490
 }
491 491
 
492 492
 /**
@@ -494,12 +494,12 @@  discard block
 block discarded – undo
494 494
  */
495 495
 function wpinv_checkbox_callback( $args ) {
496 496
 
497
-	$std = isset( $args['std'] ) ? $args['std'] : '';
498
-	$std = wpinv_get_option( $args['id'], $std );
499
-	$id  = esc_attr( $args['id'] );
497
+    $std = isset( $args['std'] ) ? $args['std'] : '';
498
+    $std = wpinv_get_option( $args['id'], $std );
499
+    $id  = esc_attr( $args['id'] );
500 500
 
501
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
502
-	?>
501
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
502
+    ?>
503 503
 		<fieldset>
504 504
 			<label>
505 505
 				<input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -511,77 +511,77 @@  discard block
 block discarded – undo
511 511
 
512 512
 function wpinv_multicheck_callback( $args ) {
513 513
 	
514
-	global $wpinv_options;
514
+    global $wpinv_options;
515 515
 
516
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
517
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
516
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
517
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
518 518
 
519
-	if ( ! empty( $args['options'] ) ) {
519
+    if ( ! empty( $args['options'] ) ) {
520 520
 
521
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
522
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
521
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
522
+        $value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
523 523
 
524
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
524
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
525 525
         foreach( $args['options'] as $key => $option ):
526
-			$sanitize_key = wpinv_sanitize_key( $key );
527
-			if ( in_array( $sanitize_key, $value ) ) { 
528
-				$enabled = $sanitize_key;
529
-			} else { 
530
-				$enabled = NULL; 
531
-			}
532
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
533
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
534
-		endforeach;
535
-		echo '</div>';
536
-		echo '<p class="description">' . $args['desc'] . '</p>';
537
-	}
526
+            $sanitize_key = wpinv_sanitize_key( $key );
527
+            if ( in_array( $sanitize_key, $value ) ) { 
528
+                $enabled = $sanitize_key;
529
+            } else { 
530
+                $enabled = NULL; 
531
+            }
532
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
533
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
534
+        endforeach;
535
+        echo '</div>';
536
+        echo '<p class="description">' . $args['desc'] . '</p>';
537
+    }
538 538
 }
539 539
 
540 540
 function wpinv_payment_icons_callback( $args ) {
541
-	global $wpinv_options;
541
+    global $wpinv_options;
542 542
     
543 543
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
544 544
 
545
-	if ( ! empty( $args['options'] ) ) {
546
-		foreach( $args['options'] as $key => $option ) {
545
+    if ( ! empty( $args['options'] ) ) {
546
+        foreach( $args['options'] as $key => $option ) {
547 547
             $sanitize_key = wpinv_sanitize_key( $key );
548 548
             
549
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
550
-				$enabled = $option;
551
-			} else {
552
-				$enabled = NULL;
553
-			}
554
-
555
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
556
-
557
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
558
-
559
-				if ( wpinv_string_is_image_url( $key ) ) {
560
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
-				} else {
562
-					$card = strtolower( str_replace( ' ', '', $option ) );
563
-
564
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
565
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
566
-					} else {
567
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
568
-						$content_dir = WP_CONTENT_DIR;
569
-
570
-						if ( function_exists( 'wp_normalize_path' ) ) {
571
-							// Replaces backslashes with forward slashes for Windows systems
572
-							$image = wp_normalize_path( $image );
573
-							$content_dir = wp_normalize_path( $content_dir );
574
-						}
575
-
576
-						$image = str_replace( $content_dir, content_url(), $image );
577
-					}
578
-
579
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
580
-				}
581
-			echo $option . '</label>';
582
-		}
583
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
584
-	}
549
+            if( isset( $wpinv_options[$args['id']][$key] ) ) {
550
+                $enabled = $option;
551
+            } else {
552
+                $enabled = NULL;
553
+            }
554
+
555
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
556
+
557
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
558
+
559
+                if ( wpinv_string_is_image_url( $key ) ) {
560
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
+                } else {
562
+                    $card = strtolower( str_replace( ' ', '', $option ) );
563
+
564
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
565
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
566
+                    } else {
567
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
568
+                        $content_dir = WP_CONTENT_DIR;
569
+
570
+                        if ( function_exists( 'wp_normalize_path' ) ) {
571
+                            // Replaces backslashes with forward slashes for Windows systems
572
+                            $image = wp_normalize_path( $image );
573
+                            $content_dir = wp_normalize_path( $content_dir );
574
+                        }
575
+
576
+                        $image = str_replace( $content_dir, content_url(), $image );
577
+                    }
578
+
579
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
580
+                }
581
+            echo $option . '</label>';
582
+        }
583
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
584
+    }
585 585
 }
586 586
 
587 587
 /**
@@ -589,9 +589,9 @@  discard block
 block discarded – undo
589 589
  */
590 590
 function wpinv_radio_callback( $args ) {
591 591
 
592
-	$std = isset( $args['std'] ) ? $args['std'] : '';
593
-	$std = wpinv_get_option( $args['id'], $std );
594
-	?>
592
+    $std = isset( $args['std'] ) ? $args['std'] : '';
593
+    $std = wpinv_get_option( $args['id'], $std );
594
+    ?>
595 595
 		<fieldset>
596 596
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
597 597
 				<?php foreach( $args['options'] as $key => $option ) : ?>
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 			</ul>
606 606
 		</fieldset>
607 607
 	<?php
608
-	getpaid_settings_description_callback( $args );
608
+    getpaid_settings_description_callback( $args );
609 609
 }
610 610
 
611 611
 /**
@@ -613,50 +613,50 @@  discard block
 block discarded – undo
613 613
  */
614 614
 function getpaid_settings_description_callback( $args ) {
615 615
 
616
-	if ( ! empty( $args['desc'] ) ) {
617
-		$description = wp_kses_post( $args['desc'] );
618
-		echo "<p class='description'>$description</p>";
619
-	}
616
+    if ( ! empty( $args['desc'] ) ) {
617
+        $description = wp_kses_post( $args['desc'] );
618
+        echo "<p class='description'>$description</p>";
619
+    }
620 620
 
621 621
 }
622 622
 
623 623
 function wpinv_gateways_callback( $args ) {
624 624
 
625
-	$gateways    = wpinv_get_option( 'gateways', array( 'manual' => 1 ) );
625
+    $gateways    = wpinv_get_option( 'gateways', array( 'manual' => 1 ) );
626 626
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
627 627
 
628
-	foreach ( $args['options'] as $key => $option ) :
629
-		$sanitize_key = wpinv_sanitize_key( $key );
628
+    foreach ( $args['options'] as $key => $option ) :
629
+        $sanitize_key = wpinv_sanitize_key( $key );
630 630
         
631 631
         if ( is_array( $gateways ) && isset( $gateways[ $key ] ) )
632
-			$enabled = '1';
633
-		else
634
-			$enabled = null;
632
+            $enabled = '1';
633
+        else
634
+            $enabled = null;
635 635
 
636
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
637
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
638
-	endforeach;
636
+        echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
637
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
638
+    endforeach;
639 639
 }
640 640
 
641 641
 function wpinv_gateway_select_callback($args) {
642
-	global $wpinv_options;
642
+    global $wpinv_options;
643 643
     
644 644
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
645 645
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
646 646
 
647
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
647
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
648 648
 
649
-	foreach ( $args['options'] as $key => $option ) :
650
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
649
+    foreach ( $args['options'] as $key => $option ) :
650
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
651 651
             $selected = selected( $key, $args['selected'], false );
652 652
         } else {
653 653
             $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
654 654
         }
655
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
656
-	endforeach;
655
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
656
+    endforeach;
657 657
 
658
-	echo '</select>';
659
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
658
+    echo '</select>';
659
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
660 660
 }
661 661
 
662 662
 /**
@@ -667,29 +667,29 @@  discard block
 block discarded – undo
667 667
  */
668 668
 function wpinv_settings_attrs_helper( $args ) {
669 669
 
670
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
671
-	$id           = esc_attr( $args['id'] );
672
-	$placeholder  = esc_attr( $args['placeholder'] );
670
+    $value        = isset( $args['std'] ) ? $args['std'] : '';
671
+    $id           = esc_attr( $args['id'] );
672
+    $placeholder  = esc_attr( $args['placeholder'] );
673 673
 
674
-	if ( ! empty( $args['faux'] ) ) {
675
-		$args['readonly'] = true;
676
-		$name             = '';
677
-	} else {
678
-		$value  = wpinv_get_option( $args['id'], $value );
679
-		$name   = "wpinv_settings[$id]";
680
-	}
674
+    if ( ! empty( $args['faux'] ) ) {
675
+        $args['readonly'] = true;
676
+        $name             = '';
677
+    } else {
678
+        $value  = wpinv_get_option( $args['id'], $value );
679
+        $name   = "wpinv_settings[$id]";
680
+    }
681 681
 
682
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
683
-	$class    = esc_attr( $args['class'] );
684
-	$style    = esc_attr( $args['style'] );
685
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
682
+    $value    = is_scalar( $value ) ? esc_attr( $value ) : '';
683
+    $class    = esc_attr( $args['class'] );
684
+    $style    = esc_attr( $args['style'] );
685
+    $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
686 686
 
687
-	$onchange = '';
687
+    $onchange = '';
688 688
     if ( ! empty( $args['onchange'] ) ) {
689 689
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
690
-	}
690
+    }
691 691
 
692
-	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
692
+    return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
693 693
 }
694 694
 
695 695
 /**
@@ -697,11 +697,11 @@  discard block
 block discarded – undo
697 697
  */
698 698
 function wpinv_text_callback( $args ) {
699 699
 
700
-	$desc = wp_kses_post( $args['desc'] );
701
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
702
-	$attr = wpinv_settings_attrs_helper( $args );
700
+    $desc = wp_kses_post( $args['desc'] );
701
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
702
+    $attr = wpinv_settings_attrs_helper( $args );
703 703
 
704
-	?>
704
+    ?>
705 705
 		<label style="width: 100%;">
706 706
 			<input type="text" <?php echo $attr; ?>>
707 707
 			<?php echo $desc; ?>
@@ -715,14 +715,14 @@  discard block
 block discarded – undo
715 715
  */
716 716
 function wpinv_number_callback( $args ) {
717 717
 
718
-	$desc = wp_kses_post( $args['desc'] );
719
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
720
-	$attr = wpinv_settings_attrs_helper( $args );
721
-	$max  = intval( $args['max'] );
722
-	$min  = intval( $args['min'] );
723
-	$step = floatval( $args['step'] );
718
+    $desc = wp_kses_post( $args['desc'] );
719
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
720
+    $attr = wpinv_settings_attrs_helper( $args );
721
+    $max  = intval( $args['max'] );
722
+    $min  = intval( $args['min'] );
723
+    $step = floatval( $args['step'] );
724 724
 
725
-	?>
725
+    ?>
726 726
 		<label style="width: 100%;">
727 727
 			<input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>>
728 728
 			<?php echo $desc; ?>
@@ -732,48 +732,48 @@  discard block
 block discarded – undo
732 732
 }
733 733
 
734 734
 function wpinv_textarea_callback( $args ) {
735
-	global $wpinv_options;
735
+    global $wpinv_options;
736 736
     
737 737
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
738 738
 
739
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
740
-		$value = $wpinv_options[ $args['id'] ];
741
-	} else {
742
-		$value = isset( $args['std'] ) ? $args['std'] : '';
743
-	}
739
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
740
+        $value = $wpinv_options[ $args['id'] ];
741
+    } else {
742
+        $value = isset( $args['std'] ) ? $args['std'] : '';
743
+    }
744 744
     
745 745
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
746 746
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
747 747
 
748
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
749
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
748
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
749
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
750 750
 
751
-	echo $html;
751
+    echo $html;
752 752
 }
753 753
 
754 754
 function wpinv_password_callback( $args ) {
755
-	global $wpinv_options;
755
+    global $wpinv_options;
756 756
     
757 757
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
758 758
 
759
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
760
-		$value = $wpinv_options[ $args['id'] ];
761
-	} else {
762
-		$value = isset( $args['std'] ) ? $args['std'] : '';
763
-	}
759
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
760
+        $value = $wpinv_options[ $args['id'] ];
761
+    } else {
762
+        $value = isset( $args['std'] ) ? $args['std'] : '';
763
+    }
764 764
 
765
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
766
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
767
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
765
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
766
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
767
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
768 768
 
769
-	echo $html;
769
+    echo $html;
770 770
 }
771 771
 
772 772
 function wpinv_missing_callback($args) {
773
-	printf(
774
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
775
-		'<strong>' . $args['id'] . '</strong>'
776
-	);
773
+    printf(
774
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
775
+        '<strong>' . $args['id'] . '</strong>'
776
+    );
777 777
 }
778 778
 
779 779
 /**
@@ -781,13 +781,13 @@  discard block
 block discarded – undo
781 781
  */
782 782
 function wpinv_select_callback( $args ) {
783 783
 
784
-	$desc   = wp_kses_post( $args['desc'] );
785
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
786
-	$attr   = wpinv_settings_attrs_helper( $args );
787
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
788
-	$value  = wpinv_get_option( $args['id'], $value );
784
+    $desc   = wp_kses_post( $args['desc'] );
785
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
786
+    $attr   = wpinv_settings_attrs_helper( $args );
787
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
788
+    $value  = wpinv_get_option( $args['id'], $value );
789 789
 
790
-	?>
790
+    ?>
791 791
 		<label style="width: 100%;">
792 792
 			<select <?php echo $attr; ?>>
793 793
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -801,123 +801,123 @@  discard block
 block discarded – undo
801 801
 }
802 802
 
803 803
 function wpinv_color_select_callback( $args ) {
804
-	global $wpinv_options;
804
+    global $wpinv_options;
805 805
     
806 806
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
807 807
 
808
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
809
-		$value = $wpinv_options[ $args['id'] ];
810
-	} else {
811
-		$value = isset( $args['std'] ) ? $args['std'] : '';
812
-	}
808
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
809
+        $value = $wpinv_options[ $args['id'] ];
810
+    } else {
811
+        $value = isset( $args['std'] ) ? $args['std'] : '';
812
+    }
813 813
 
814
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
814
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
815 815
 
816
-	foreach ( $args['options'] as $option => $color ) {
817
-		$selected = selected( $option, $value, false );
818
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
819
-	}
816
+    foreach ( $args['options'] as $option => $color ) {
817
+        $selected = selected( $option, $value, false );
818
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
819
+    }
820 820
 
821
-	$html .= '</select>';
822
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
821
+    $html .= '</select>';
822
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
823 823
 
824
-	echo $html;
824
+    echo $html;
825 825
 }
826 826
 
827 827
 function wpinv_rich_editor_callback( $args ) {
828
-	global $wpinv_options, $wp_version;
828
+    global $wpinv_options, $wp_version;
829 829
     
830 830
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
831 831
 
832
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
833
-		$value = $wpinv_options[ $args['id'] ];
832
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
833
+        $value = $wpinv_options[ $args['id'] ];
834 834
 
835
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
836
-			$value = isset( $args['std'] ) ? $args['std'] : '';
837
-		}
838
-	} else {
839
-		$value = isset( $args['std'] ) ? $args['std'] : '';
840
-	}
835
+        if( empty( $args['allow_blank'] ) && empty( $value ) ) {
836
+            $value = isset( $args['std'] ) ? $args['std'] : '';
837
+        }
838
+    } else {
839
+        $value = isset( $args['std'] ) ? $args['std'] : '';
840
+    }
841 841
 
842
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
842
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
843 843
 
844
-	$html = '<div class="getpaid-settings-editor-input">';
845
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
846
-		ob_start();
847
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
848
-		$html .= ob_get_clean();
849
-	} else {
850
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
851
-	}
844
+    $html = '<div class="getpaid-settings-editor-input">';
845
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
846
+        ob_start();
847
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
848
+        $html .= ob_get_clean();
849
+    } else {
850
+        $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
851
+    }
852 852
 
853
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
853
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
854 854
 
855
-	echo $html;
855
+    echo $html;
856 856
 }
857 857
 
858 858
 function wpinv_upload_callback( $args ) {
859
-	global $wpinv_options;
859
+    global $wpinv_options;
860 860
     
861 861
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
862 862
 
863
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
864
-		$value = $wpinv_options[$args['id']];
865
-	} else {
866
-		$value = isset($args['std']) ? $args['std'] : '';
867
-	}
863
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
864
+        $value = $wpinv_options[$args['id']];
865
+    } else {
866
+        $value = isset($args['std']) ? $args['std'] : '';
867
+    }
868 868
 
869
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
870
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
871
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
872
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
869
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
870
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
871
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
872
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
873 873
 
874
-	echo $html;
874
+    echo $html;
875 875
 }
876 876
 
877 877
 function wpinv_color_callback( $args ) {
878
-	global $wpinv_options;
878
+    global $wpinv_options;
879 879
     
880 880
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
881 881
 
882
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
883
-		$value = $wpinv_options[ $args['id'] ];
884
-	} else {
885
-		$value = isset( $args['std'] ) ? $args['std'] : '';
886
-	}
882
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
883
+        $value = $wpinv_options[ $args['id'] ];
884
+    } else {
885
+        $value = isset( $args['std'] ) ? $args['std'] : '';
886
+    }
887 887
 
888
-	$default = isset( $args['std'] ) ? $args['std'] : '';
888
+    $default = isset( $args['std'] ) ? $args['std'] : '';
889 889
 
890
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
891
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
890
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
891
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
892 892
 
893
-	echo $html;
893
+    echo $html;
894 894
 }
895 895
 
896 896
 function wpinv_country_states_callback($args) {
897
-	global $wpinv_options;
897
+    global $wpinv_options;
898 898
     
899 899
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
900 900
 
901
-	if ( isset( $args['placeholder'] ) ) {
902
-		$placeholder = $args['placeholder'];
903
-	} else {
904
-		$placeholder = '';
905
-	}
901
+    if ( isset( $args['placeholder'] ) ) {
902
+        $placeholder = $args['placeholder'];
903
+    } else {
904
+        $placeholder = '';
905
+    }
906 906
 
907
-	$states = wpinv_get_country_states();
907
+    $states = wpinv_get_country_states();
908 908
 
909
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
910
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
909
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
910
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
911 911
 
912
-	foreach ( $states as $option => $name ) {
913
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
914
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
915
-	}
912
+    foreach ( $states as $option => $name ) {
913
+        $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
914
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
915
+    }
916 916
 
917
-	$html .= '</select>';
918
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
917
+    $html .= '</select>';
918
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
919 919
 
920
-	echo $html;
920
+    echo $html;
921 921
 }
922 922
 
923 923
 /**
@@ -925,7 +925,7 @@  discard block
 block discarded – undo
925 925
  */
926 926
 function wpinv_tax_rates_callback() {
927 927
 	
928
-	?>
928
+    ?>
929 929
 		</td>
930 930
 	</tr>
931 931
 	<tr class="bsui">
@@ -940,17 +940,17 @@  discard block
 block discarded – undo
940 940
  * Displays a tax rate' edit row.
941 941
  */
942 942
 function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
943
-	ob_start();
943
+    ob_start();
944 944
 
945
-	$key                      = sanitize_key( $key );
946
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
947
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
945
+    $key                      = sanitize_key( $key );
946
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
947
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
948 948
 
949
-	if ( $echo ) {
950
-		echo ob_get_clean();
951
-	} else {
952
-		return ob_get_clean(); 
953
-	}
949
+    if ( $echo ) {
950
+        echo ob_get_clean();
951
+    } else {
952
+        return ob_get_clean(); 
953
+    }
954 954
 
955 955
 }
956 956
 
@@ -978,19 +978,19 @@  discard block
 block discarded – undo
978 978
 }
979 979
 
980 980
 function wpinv_descriptive_text_callback( $args ) {
981
-	echo wp_kses_post( $args['desc'] );
981
+    echo wp_kses_post( $args['desc'] );
982 982
 }
983 983
 
984 984
 function wpinv_raw_html_callback( $args ) {
985
-	echo $args['desc'];
985
+    echo $args['desc'];
986 986
 }
987 987
 
988 988
 function wpinv_hook_callback( $args ) {
989
-	do_action( 'wpinv_' . $args['id'], $args );
989
+    do_action( 'wpinv_' . $args['id'], $args );
990 990
 }
991 991
 
992 992
 function wpinv_set_settings_cap() {
993
-	return wpinv_get_capability();
993
+    return wpinv_get_capability();
994 994
 }
995 995
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
996 996
 
Please login to merge, or discard this patch.
includes/class-getpaid-post-types.php 1 patch
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -15,319 +15,319 @@
 block discarded – undo
15 15
 class GetPaid_Post_Types {
16 16
 
17 17
     /**
18
-	 * Hook in methods.
19
-	 */
20
-	public function __construct() {
21
-		add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
-		add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
-		add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
-		add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
-	}
18
+     * Hook in methods.
19
+     */
20
+    public function __construct() {
21
+        add_action( 'init', array( __CLASS__, 'register_post_types' ), 1 );
22
+        add_action( 'init', array( __CLASS__, 'register_post_status' ), 4 );
23
+        add_action( 'getpaid_flush_rewrite_rules', array( __CLASS__, 'flush_rewrite_rules' ) );
24
+        add_action( 'getpaid_after_register_post_types', array( __CLASS__, 'maybe_flush_rewrite_rules' ) );
25
+    }
26 26
 
27
-	/**
28
-	 * Register core post types.
29
-	 */
30
-	public static function register_post_types() {
27
+    /**
28
+     * Register core post types.
29
+     */
30
+    public static function register_post_types() {
31 31
 
32
-		if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
-			return;
34
-		}
32
+        if ( ! is_blog_installed() || post_type_exists( 'wpi_item' ) ) {
33
+            return;
34
+        }
35 35
 
36
-		// Fires before registering post types.
37
-		do_action( 'getpaid_register_post_types' );
36
+        // Fires before registering post types.
37
+        do_action( 'getpaid_register_post_types' );
38 38
 
39
-		// Register item post type.
40
-		register_post_type(
41
-			'wpi_item',
42
-			apply_filters(
43
-				'wpinv_register_post_type_invoice_item',
44
-				array(
45
-					'labels'             => array(
46
-						'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
47
-						'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
48
-						'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
49
-						'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
50
-						'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
51
-						'add_new_item'       => __( 'Add New Item', 'invoicing' ),
52
-						'new_item'           => __( 'New Item', 'invoicing' ),
53
-						'edit_item'          => __( 'Edit Item', 'invoicing' ),
54
-						'view_item'          => __( 'View Item', 'invoicing' ),
55
-						'all_items'          => __( 'Items', 'invoicing' ),
56
-						'search_items'       => __( 'Search items', 'invoicing' ),
57
-						'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
58
-						'not_found'          => __( 'No items found.', 'invoicing' ),
59
-						'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
60
-					),
61
-					'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
62
-					'public'                => false,
63
-					'has_archive'           => false,
64
-					'_builtin'              => false,
65
-					'show_ui'               => true,
66
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
67
-					'show_in_nav_menus'     => false,
68
-					'supports'              => array( 'title', 'excerpt', 'thumbnail' ),
69
-					'rewrite'               => false,
70
-					'query_var'             => false,
71
-					'map_meta_cap'          => true,
72
-					'show_in_admin_bar'     => true,
73
-					'can_export'            => true,
74
-				)
75
-			)
76
-		);
39
+        // Register item post type.
40
+        register_post_type(
41
+            'wpi_item',
42
+            apply_filters(
43
+                'wpinv_register_post_type_invoice_item',
44
+                array(
45
+                    'labels'             => array(
46
+                        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
47
+                        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
48
+                        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
49
+                        'name_admin_bar'     => _x( 'Item', 'add new on admin bar', 'invoicing' ),
50
+                        'add_new'            => _x( 'Add New', 'Item', 'invoicing' ),
51
+                        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
52
+                        'new_item'           => __( 'New Item', 'invoicing' ),
53
+                        'edit_item'          => __( 'Edit Item', 'invoicing' ),
54
+                        'view_item'          => __( 'View Item', 'invoicing' ),
55
+                        'all_items'          => __( 'Items', 'invoicing' ),
56
+                        'search_items'       => __( 'Search items', 'invoicing' ),
57
+                        'parent_item_colon'  => __( 'Parent item:', 'invoicing' ),
58
+                        'not_found'          => __( 'No items found.', 'invoicing' ),
59
+                        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
60
+                    ),
61
+                    'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
62
+                    'public'                => false,
63
+                    'has_archive'           => false,
64
+                    '_builtin'              => false,
65
+                    'show_ui'               => true,
66
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
67
+                    'show_in_nav_menus'     => false,
68
+                    'supports'              => array( 'title', 'excerpt', 'thumbnail' ),
69
+                    'rewrite'               => false,
70
+                    'query_var'             => false,
71
+                    'map_meta_cap'          => true,
72
+                    'show_in_admin_bar'     => true,
73
+                    'can_export'            => true,
74
+                )
75
+            )
76
+        );
77 77
 
78
-		// Register payment form post type.
79
-		register_post_type(
80
-			'wpi_payment_form',
81
-			apply_filters(
82
-				'wpinv_register_post_type_payment_form',
83
-				array(
84
-					'labels'             => array(
85
-						'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
86
-						'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
87
-						'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
88
-						'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
89
-						'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
90
-						'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
91
-						'new_item'           => __( 'New Payment Form', 'invoicing' ),
92
-						'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
93
-						'view_item'          => __( 'View Payment Form', 'invoicing' ),
94
-						'all_items'          => __( 'Payment Forms', 'invoicing' ),
95
-						'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
96
-						'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
97
-						'not_found'          => __( 'No payment forms found.', 'invoicing' ),
98
-						'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' )
99
-					),
100
-					'description'        => __( 'Add new payment forms.', 'invoicing' ),
101
-					'public'             => false,
102
-					'show_ui'            => true,
103
-					'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true,
104
-					'show_in_nav_menus'  => false,
105
-					'query_var'          => false,
106
-					'rewrite'            => true,
107
-					'map_meta_cap'       => true,
108
-					'has_archive'        => false,
109
-					'hierarchical'       => false,
110
-					'menu_position'      => null,
111
-					'supports'           => array( 'title' ),
112
-					'menu_icon'          => 'dashicons-media-form',
113
-				)
114
-			)
115
-		);
78
+        // Register payment form post type.
79
+        register_post_type(
80
+            'wpi_payment_form',
81
+            apply_filters(
82
+                'wpinv_register_post_type_payment_form',
83
+                array(
84
+                    'labels'             => array(
85
+                        'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
86
+                        'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
87
+                        'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
88
+                        'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
89
+                        'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
90
+                        'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
91
+                        'new_item'           => __( 'New Payment Form', 'invoicing' ),
92
+                        'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
93
+                        'view_item'          => __( 'View Payment Form', 'invoicing' ),
94
+                        'all_items'          => __( 'Payment Forms', 'invoicing' ),
95
+                        'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
96
+                        'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
97
+                        'not_found'          => __( 'No payment forms found.', 'invoicing' ),
98
+                        'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' )
99
+                    ),
100
+                    'description'        => __( 'Add new payment forms.', 'invoicing' ),
101
+                    'public'             => false,
102
+                    'show_ui'            => true,
103
+                    'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true,
104
+                    'show_in_nav_menus'  => false,
105
+                    'query_var'          => false,
106
+                    'rewrite'            => true,
107
+                    'map_meta_cap'       => true,
108
+                    'has_archive'        => false,
109
+                    'hierarchical'       => false,
110
+                    'menu_position'      => null,
111
+                    'supports'           => array( 'title' ),
112
+                    'menu_icon'          => 'dashicons-media-form',
113
+                )
114
+            )
115
+        );
116 116
 
117
-		// Register invoice post type.
118
-		register_post_type(
119
-			'wpi_invoice',
120
-			apply_filters(
121
-				'wpinv_register_post_type_invoice',
122
-				array(
123
-					'labels'                 => array(
124
-						'name'                  => __( 'Invoices', 'invoicing' ),
125
-						'singular_name'         => __( 'Invoice', 'invoicing' ),
126
-						'all_items'             => __( 'Invoices', 'invoicing' ),
127
-						'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
128
-						'add_new'               => __( 'Add New', 'invoicing' ),
129
-						'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
130
-						'edit'                  => __( 'Edit', 'invoicing' ),
131
-						'edit_item'             => __( 'Edit invoice', 'invoicing' ),
132
-						'new_item'              => __( 'New invoice', 'invoicing' ),
133
-						'view_item'             => __( 'View invoice', 'invoicing' ),
134
-						'view_items'            => __( 'View Invoices', 'invoicing' ),
135
-						'search_items'          => __( 'Search invoices', 'invoicing' ),
136
-						'not_found'             => __( 'No invoices found', 'invoicing' ),
137
-						'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
138
-						'parent'                => __( 'Parent invoice', 'invoicing' ),
139
-						'featured_image'        => __( 'Invoice image', 'invoicing' ),
140
-						'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
141
-						'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
142
-						'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
143
-						'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
144
-						'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
145
-						'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
146
-						'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
147
-						'items_list'            => __( 'Invoices list', 'invoicing' ),
148
-					),
149
-					'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
150
-					'public'                => true,
151
-					'has_archive'           => false,
152
-					'publicly_queryable'    => true,
153
-        			'exclude_from_search'   => true,
154
-        			'show_ui'               => true,
155
-					'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
156
-					'show_in_nav_menus'     => false,
157
-					'supports'              => array( 'title', 'author', 'excerpt'  ),
158
-					'rewrite'               => array(
159
-						'slug'              => 'invoice',
160
-						'with_front'        => false,
161
-					),
162
-					'query_var'             => false,
163
-					'map_meta_cap'          => true,
164
-					'show_in_admin_bar'     => true,
165
-					'can_export'            => true,
166
-					'hierarchical'          => false,
167
-					'menu_position'         => null,
168
-					'menu_icon'             => 'dashicons-media-spreadsheet',
169
-				)
170
-			)
171
-		);
117
+        // Register invoice post type.
118
+        register_post_type(
119
+            'wpi_invoice',
120
+            apply_filters(
121
+                'wpinv_register_post_type_invoice',
122
+                array(
123
+                    'labels'                 => array(
124
+                        'name'                  => __( 'Invoices', 'invoicing' ),
125
+                        'singular_name'         => __( 'Invoice', 'invoicing' ),
126
+                        'all_items'             => __( 'Invoices', 'invoicing' ),
127
+                        'menu_name'             => _x( 'Invoices', 'Admin menu name', 'invoicing' ),
128
+                        'add_new'               => __( 'Add New', 'invoicing' ),
129
+                        'add_new_item'          => __( 'Add new invoice', 'invoicing' ),
130
+                        'edit'                  => __( 'Edit', 'invoicing' ),
131
+                        'edit_item'             => __( 'Edit invoice', 'invoicing' ),
132
+                        'new_item'              => __( 'New invoice', 'invoicing' ),
133
+                        'view_item'             => __( 'View invoice', 'invoicing' ),
134
+                        'view_items'            => __( 'View Invoices', 'invoicing' ),
135
+                        'search_items'          => __( 'Search invoices', 'invoicing' ),
136
+                        'not_found'             => __( 'No invoices found', 'invoicing' ),
137
+                        'not_found_in_trash'    => __( 'No invoices found in trash', 'invoicing' ),
138
+                        'parent'                => __( 'Parent invoice', 'invoicing' ),
139
+                        'featured_image'        => __( 'Invoice image', 'invoicing' ),
140
+                        'set_featured_image'    => __( 'Set invoice image', 'invoicing' ),
141
+                        'remove_featured_image' => __( 'Remove invoice image', 'invoicing' ),
142
+                        'use_featured_image'    => __( 'Use as invoice image', 'invoicing' ),
143
+                        'insert_into_item'      => __( 'Insert into invoice', 'invoicing' ),
144
+                        'uploaded_to_this_item' => __( 'Uploaded to this invoice', 'invoicing' ),
145
+                        'filter_items_list'     => __( 'Filter invoices', 'invoicing' ),
146
+                        'items_list_navigation' => __( 'Invoices navigation', 'invoicing' ),
147
+                        'items_list'            => __( 'Invoices list', 'invoicing' ),
148
+                    ),
149
+                    'description'           => __( 'This is where invoices are stored.', 'invoicing' ),
150
+                    'public'                => true,
151
+                    'has_archive'           => false,
152
+                    'publicly_queryable'    => true,
153
+                    'exclude_from_search'   => true,
154
+                    'show_ui'               => true,
155
+                    'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
156
+                    'show_in_nav_menus'     => false,
157
+                    'supports'              => array( 'title', 'author', 'excerpt'  ),
158
+                    'rewrite'               => array(
159
+                        'slug'              => 'invoice',
160
+                        'with_front'        => false,
161
+                    ),
162
+                    'query_var'             => false,
163
+                    'map_meta_cap'          => true,
164
+                    'show_in_admin_bar'     => true,
165
+                    'can_export'            => true,
166
+                    'hierarchical'          => false,
167
+                    'menu_position'         => null,
168
+                    'menu_icon'             => 'dashicons-media-spreadsheet',
169
+                )
170
+            )
171
+        );
172 172
 
173
-		// Register discount post type.
174
-		register_post_type(
175
-			'wpi_discount',
176
-			apply_filters(
177
-				'wpinv_register_post_type_discount',
178
-				array(
179
-					'labels'                 => array(
180
-						'name'                  => __( 'Discounts', 'invoicing' ),
181
-						'singular_name'         => __( 'Discount', 'invoicing' ),
182
-						'all_items'             => __( 'Discounts', 'invoicing' ),
183
-						'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
184
-						'add_new'               => __( 'Add New', 'invoicing' ),
185
-						'add_new_item'          => __( 'Add new discount', 'invoicing' ),
186
-						'edit'                  => __( 'Edit', 'invoicing' ),
187
-						'edit_item'             => __( 'Edit discount', 'invoicing' ),
188
-						'new_item'              => __( 'New discount', 'invoicing' ),
189
-						'view_item'             => __( 'View discount', 'invoicing' ),
190
-						'view_items'            => __( 'View Discounts', 'invoicing' ),
191
-						'search_items'          => __( 'Search discounts', 'invoicing' ),
192
-						'not_found'             => __( 'No discounts found', 'invoicing' ),
193
-						'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
194
-						'parent'                => __( 'Parent discount', 'invoicing' ),
195
-						'featured_image'        => __( 'Discount image', 'invoicing' ),
196
-						'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
197
-						'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
198
-						'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
199
-						'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
200
-						'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
201
-						'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
202
-						'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
203
-						'items_list'            => __( 'Discounts list', 'invoicing' ),
204
-					),
205
-					'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
206
-					'public'             => false,
207
-					'can_export'         => true,
208
-					'_builtin'           => false,
209
-					'publicly_queryable' => false,
210
-					'exclude_from_search'=> true,
211
-					'show_ui'            => true,
212
-					'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
213
-					'query_var'          => false,
214
-					'rewrite'            => false,
215
-					'map_meta_cap'       => true,
216
-					'has_archive'        => false,
217
-					'hierarchical'       => false,
218
-					'supports'           => array( 'title', 'excerpt' ),
219
-					'show_in_nav_menus'  => false,
220
-					'show_in_admin_bar'  => true,
221
-					'menu_position'      => null,
222
-				)
223
-			)
224
-		);
173
+        // Register discount post type.
174
+        register_post_type(
175
+            'wpi_discount',
176
+            apply_filters(
177
+                'wpinv_register_post_type_discount',
178
+                array(
179
+                    'labels'                 => array(
180
+                        'name'                  => __( 'Discounts', 'invoicing' ),
181
+                        'singular_name'         => __( 'Discount', 'invoicing' ),
182
+                        'all_items'             => __( 'Discounts', 'invoicing' ),
183
+                        'menu_name'             => _x( 'Discounts', 'Admin menu name', 'invoicing' ),
184
+                        'add_new'               => __( 'Add New', 'invoicing' ),
185
+                        'add_new_item'          => __( 'Add new discount', 'invoicing' ),
186
+                        'edit'                  => __( 'Edit', 'invoicing' ),
187
+                        'edit_item'             => __( 'Edit discount', 'invoicing' ),
188
+                        'new_item'              => __( 'New discount', 'invoicing' ),
189
+                        'view_item'             => __( 'View discount', 'invoicing' ),
190
+                        'view_items'            => __( 'View Discounts', 'invoicing' ),
191
+                        'search_items'          => __( 'Search discounts', 'invoicing' ),
192
+                        'not_found'             => __( 'No discounts found', 'invoicing' ),
193
+                        'not_found_in_trash'    => __( 'No discounts found in trash', 'invoicing' ),
194
+                        'parent'                => __( 'Parent discount', 'invoicing' ),
195
+                        'featured_image'        => __( 'Discount image', 'invoicing' ),
196
+                        'set_featured_image'    => __( 'Set discount image', 'invoicing' ),
197
+                        'remove_featured_image' => __( 'Remove discount image', 'invoicing' ),
198
+                        'use_featured_image'    => __( 'Use as discount image', 'invoicing' ),
199
+                        'insert_into_item'      => __( 'Insert into discount', 'invoicing' ),
200
+                        'uploaded_to_this_item' => __( 'Uploaded to this discount', 'invoicing' ),
201
+                        'filter_items_list'     => __( 'Filter discounts', 'invoicing' ),
202
+                        'items_list_navigation' => __( 'Discount navigation', 'invoicing' ),
203
+                        'items_list'            => __( 'Discounts list', 'invoicing' ),
204
+                    ),
205
+                    'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
206
+                    'public'             => false,
207
+                    'can_export'         => true,
208
+                    '_builtin'           => false,
209
+                    'publicly_queryable' => false,
210
+                    'exclude_from_search'=> true,
211
+                    'show_ui'            => true,
212
+                    'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
213
+                    'query_var'          => false,
214
+                    'rewrite'            => false,
215
+                    'map_meta_cap'       => true,
216
+                    'has_archive'        => false,
217
+                    'hierarchical'       => false,
218
+                    'supports'           => array( 'title', 'excerpt' ),
219
+                    'show_in_nav_menus'  => false,
220
+                    'show_in_admin_bar'  => true,
221
+                    'menu_position'      => null,
222
+                )
223
+            )
224
+        );
225 225
 
226
-		do_action( 'getpaid_after_register_post_types' );
227
-	}
226
+        do_action( 'getpaid_after_register_post_types' );
227
+    }
228 228
 
229
-	/**
230
-	 * Register our custom post statuses.
231
-	 */
232
-	public static function register_post_status() {
229
+    /**
230
+     * Register our custom post statuses.
231
+     */
232
+    public static function register_post_status() {
233 233
 
234
-		$invoice_statuses = apply_filters(
235
-			'getpaid_register_invoice_post_statuses',
236
-			array(
234
+        $invoice_statuses = apply_filters(
235
+            'getpaid_register_invoice_post_statuses',
236
+            array(
237 237
 
238
-				'wpi-pending' => array(
239
-					'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
240
-        			'public'                    => true,
241
-        			'exclude_from_search'       => true,
242
-        			'show_in_admin_all_list'    => true,
243
-					'show_in_admin_status_list' => true,
244
-					/* translators: %s: number of invoices */
245
-        			'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
246
-				),
238
+                'wpi-pending' => array(
239
+                    'label'                     => _x( 'Pending Payment', 'Invoice status', 'invoicing' ),
240
+                    'public'                    => true,
241
+                    'exclude_from_search'       => true,
242
+                    'show_in_admin_all_list'    => true,
243
+                    'show_in_admin_status_list' => true,
244
+                    /* translators: %s: number of invoices */
245
+                    'label_count'               => _n_noop( 'Pending Payment <span class="count">(%s)</span>', 'Pending Payment <span class="count">(%s)</span>', 'invoicing' )
246
+                ),
247 247
 
248
-				'wpi-processing' => array(
249
-					'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
250
-        			'public'                    => true,
251
-        			'exclude_from_search'       => true,
252
-        			'show_in_admin_all_list'    => true,
253
-					'show_in_admin_status_list' => true,
254
-					/* translators: %s: number of invoices */
255
-        			'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
256
-				),
248
+                'wpi-processing' => array(
249
+                    'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
250
+                    'public'                    => true,
251
+                    'exclude_from_search'       => true,
252
+                    'show_in_admin_all_list'    => true,
253
+                    'show_in_admin_status_list' => true,
254
+                    /* translators: %s: number of invoices */
255
+                    'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
256
+                ),
257 257
 
258
-				'wpi-onhold' => array(
259
-					'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
260
-        			'public'                    => true,
261
-        			'exclude_from_search'       => true,
262
-        			'show_in_admin_all_list'    => true,
263
-					'show_in_admin_status_list' => true,
264
-					/* translators: %s: number of invoices */
265
-        			'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
266
-				),
258
+                'wpi-onhold' => array(
259
+                    'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
260
+                    'public'                    => true,
261
+                    'exclude_from_search'       => true,
262
+                    'show_in_admin_all_list'    => true,
263
+                    'show_in_admin_status_list' => true,
264
+                    /* translators: %s: number of invoices */
265
+                    'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
266
+                ),
267 267
 
268
-				'wpi-cancelled' => array(
269
-					'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
270
-        			'public'                    => true,
271
-        			'exclude_from_search'       => true,
272
-        			'show_in_admin_all_list'    => true,
273
-					'show_in_admin_status_list' => true,
274
-					/* translators: %s: number of invoices */
275
-        			'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
276
-				),
268
+                'wpi-cancelled' => array(
269
+                    'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
270
+                    'public'                    => true,
271
+                    'exclude_from_search'       => true,
272
+                    'show_in_admin_all_list'    => true,
273
+                    'show_in_admin_status_list' => true,
274
+                    /* translators: %s: number of invoices */
275
+                    'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
276
+                ),
277 277
 
278
-				'wpi-refunded' => array(
279
-					'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
280
-        			'public'                    => true,
281
-        			'exclude_from_search'       => true,
282
-        			'show_in_admin_all_list'    => true,
283
-					'show_in_admin_status_list' => true,
284
-					/* translators: %s: number of invoices */
285
-        			'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
286
-				),
278
+                'wpi-refunded' => array(
279
+                    'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
280
+                    'public'                    => true,
281
+                    'exclude_from_search'       => true,
282
+                    'show_in_admin_all_list'    => true,
283
+                    'show_in_admin_status_list' => true,
284
+                    /* translators: %s: number of invoices */
285
+                    'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
286
+                ),
287 287
 
288
-				'wpi-failed' => array(
289
-					'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
290
-        			'public'                    => true,
291
-        			'exclude_from_search'       => true,
292
-        			'show_in_admin_all_list'    => true,
293
-					'show_in_admin_status_list' => true,
294
-					/* translators: %s: number of invoices */
295
-        			'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
296
-				),
288
+                'wpi-failed' => array(
289
+                    'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
290
+                    'public'                    => true,
291
+                    'exclude_from_search'       => true,
292
+                    'show_in_admin_all_list'    => true,
293
+                    'show_in_admin_status_list' => true,
294
+                    /* translators: %s: number of invoices */
295
+                    'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
296
+                ),
297 297
 
298
-				'wpi-renewal' => array(
299
-					'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
300
-        			'public'                    => true,
301
-        			'exclude_from_search'       => true,
302
-        			'show_in_admin_all_list'    => true,
303
-					'show_in_admin_status_list' => true,
304
-					/* translators: %s: number of invoices */
305
-        			'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
306
-				)
307
-			)
308
-		);
298
+                'wpi-renewal' => array(
299
+                    'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
300
+                    'public'                    => true,
301
+                    'exclude_from_search'       => true,
302
+                    'show_in_admin_all_list'    => true,
303
+                    'show_in_admin_status_list' => true,
304
+                    /* translators: %s: number of invoices */
305
+                    'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
306
+                )
307
+            )
308
+        );
309 309
 
310
-		foreach ( $invoice_statuses as $invoice_statuse => $args ) {
311
-			register_post_status( $invoice_statuse, $args );
312
-		}
313
-	}
310
+        foreach ( $invoice_statuses as $invoice_statuse => $args ) {
311
+            register_post_status( $invoice_statuse, $args );
312
+        }
313
+    }
314 314
 
315
-	/**
316
-	 * Flush rewrite rules.
317
-	 */
318
-	public static function flush_rewrite_rules() {
319
-		flush_rewrite_rules();
320
-	}
315
+    /**
316
+     * Flush rewrite rules.
317
+     */
318
+    public static function flush_rewrite_rules() {
319
+        flush_rewrite_rules();
320
+    }
321 321
 
322
-	/**
323
-	 * Flush rules to prevent 404.
324
-	 *
325
-	 */
326
-	public static function maybe_flush_rewrite_rules() {
327
-		if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
328
-			update_option( 'getpaid_flushed_rewrite_rules', '1' );
329
-			self::flush_rewrite_rules();
330
-		}
331
-	}
322
+    /**
323
+     * Flush rules to prevent 404.
324
+     *
325
+     */
326
+    public static function maybe_flush_rewrite_rules() {
327
+        if ( ! get_option( 'getpaid_flushed_rewrite_rules' ) ) {
328
+            update_option( 'getpaid_flushed_rewrite_rules', '1' );
329
+            self::flush_rewrite_rules();
330
+        }
331
+    }
332 332
 
333 333
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +479 added lines, -479 removed lines patch added patch discarded remove patch
@@ -14,521 +14,521 @@  discard block
 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
-
128
-		if ( class_exists( 'BuddyPress' ) ) {
129
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
130
-		}
131
-
132
-		add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
133
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
134
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
135
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
136
-		add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
137
-
138
-		// Fires after registering actions.
139
-		do_action( 'wpinv_actions', $this );
140
-		do_action( 'getpaid_actions', $this );
141
-
142
-	}
143
-
144
-	public function plugins_loaded() {
145
-		/* Internationalize the text strings used. */
146
-		$this->load_textdomain();
147
-
148
-		do_action( 'wpinv_loaded' );
149
-
150
-		// Fix oxygen page builder conflict
151
-		if ( function_exists( 'ct_css_output' ) ) {
152
-			wpinv_oxygen_fix_conflict();
153
-		}
154
-	}
155
-
156
-	/**
157
-	 * Load the translation of the plugin.
158
-	 *
159
-	 * @since 1.0
160
-	 */
161
-	public function load_textdomain( $locale = NULL ) {
162
-		if ( empty( $locale ) ) {
163
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
-		}
165
-
166
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
-
168
-		unload_textdomain( 'invoicing' );
169
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
-
172
-		/**
173
-		 * Define language constants.
174
-		 */
175
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
-	}
177
-
178
-	/**
179
-	 * Include required core files used in admin and on the frontend.
180
-	 */
181
-	public function includes() {
182
-
183
-		// Start with the settings.
184
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
-
186
-		// Packages/libraries.
187
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
-
190
-		// Load functions.
191
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
-		require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
-		require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
-
207
-		// Register autoloader.
208
-		try {
209
-			spl_autoload_register( array( $this, 'autoload' ), true );
210
-		} catch ( Exception $e ) {
211
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
-		}
213
-
214
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
-
235
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
-			GetPaid_Post_Types_Admin::init();
237
-
238
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
242
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
-			// load the user class only on the users.php page
246
-			global $pagenow;
247
-			if($pagenow=='users.php'){
248
-				new WPInv_Admin_Users();
249
-			}
250
-		}
251
-
252
-		// Register cli commands
253
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
-		}
257
-
258
-	}
259
-
260
-	/**
261
-	 * Class autoloader
262
-	 *
263
-	 * @param       string $class_name The name of the class to load.
264
-	 * @access      public
265
-	 * @since       1.0.19
266
-	 * @return      void
267
-	 */
268
-	public function autoload( $class_name ) {
269
-
270
-		// Normalize the class name...
271
-		$class_name  = strtolower( $class_name );
272
-
273
-		// ... and make sure it is our class.
274
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
-			return;
276
-		}
277
-
278
-		// Next, prepare the file name from the class.
279
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
280
-
281
-		// Base path of the classes.
282
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
283
-
284
-		// And an array of possible locations in order of importance.
285
-		$locations = array(
286
-			"$plugin_path/includes",
287
-			"$plugin_path/includes/data-stores",
288
-			"$plugin_path/includes/gateways",
289
-			"$plugin_path/includes/payments",
290
-			"$plugin_path/includes/geolocation",
291
-			"$plugin_path/includes/reports",
292
-			"$plugin_path/includes/api",
293
-			"$plugin_path/includes/admin",
294
-			"$plugin_path/includes/admin/meta-boxes",
295
-		);
296
-
297
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
-
299
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
-				include trailingslashit( $location ) . $file_name;
301
-				break;
302
-			}
303
-
304
-		}
305
-
306
-	}
307
-
308
-	/**
309
-	 * Inits hooks etc.
310
-	 */
311
-	public function init() {
312
-
313
-		// Fires before getpaid inits.
314
-		do_action( 'before_getpaid_init', $this );
315
-
316
-		// Maybe upgrade.
317
-		$this->maybe_upgrade_database();
318
-
319
-		// Load default gateways.
320
-		$gateways = apply_filters(
321
-			'getpaid_default_gateways',
322
-			array(
323
-				'manual'        => 'GetPaid_Manual_Gateway',
324
-				'paypal'        => 'GetPaid_Paypal_Gateway',
325
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
-			)
329
-		);
330
-
331
-		foreach ( $gateways as $id => $class ) {
332
-			$this->gateways[ $id ] = new $class();
333
-		}
334
-
335
-		// Fires after getpaid inits.
336
-		do_action( 'getpaid_init', $this );
337
-
338
-	}
339
-
340
-	/**
341
-	 * Checks if this is an IPN request and processes it.
342
-	 */
343
-	public function maybe_process_ipn() {
344
-
345
-		// Ensure that this is an IPN request.
346
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
347
-			return;
348
-		}
349
-
350
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
351
-
352
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
353
-		do_action( "wpinv_verify_{$gateway}_ipn" );
354
-		exit;
355
-
356
-	}
357
-
358
-	public function enqueue_scripts() {
359
-		$suffix  = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
360
-
361
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
362
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
363
-		wp_enqueue_style( 'wpinv_front_style' );
364
-
365
-		// Register scripts
366
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
367
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true );
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
+
128
+        if ( class_exists( 'BuddyPress' ) ) {
129
+            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
130
+        }
131
+
132
+        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 11 );
133
+        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
134
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
135
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
136
+        add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
137
+
138
+        // Fires after registering actions.
139
+        do_action( 'wpinv_actions', $this );
140
+        do_action( 'getpaid_actions', $this );
141
+
142
+    }
143
+
144
+    public function plugins_loaded() {
145
+        /* Internationalize the text strings used. */
146
+        $this->load_textdomain();
147
+
148
+        do_action( 'wpinv_loaded' );
149
+
150
+        // Fix oxygen page builder conflict
151
+        if ( function_exists( 'ct_css_output' ) ) {
152
+            wpinv_oxygen_fix_conflict();
153
+        }
154
+    }
155
+
156
+    /**
157
+     * Load the translation of the plugin.
158
+     *
159
+     * @since 1.0
160
+     */
161
+    public function load_textdomain( $locale = NULL ) {
162
+        if ( empty( $locale ) ) {
163
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
164
+        }
165
+
166
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
167
+
168
+        unload_textdomain( 'invoicing' );
169
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
170
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
171
+
172
+        /**
173
+         * Define language constants.
174
+         */
175
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
176
+    }
177
+
178
+    /**
179
+     * Include required core files used in admin and on the frontend.
180
+     */
181
+    public function includes() {
182
+
183
+        // Start with the settings.
184
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
185
+
186
+        // Packages/libraries.
187
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
188
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
189
+
190
+        // Load functions.
191
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
192
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
193
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
194
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
195
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
196
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
197
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
198
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
199
+        require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' );
200
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
201
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
202
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
203
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
204
+        require_once( WPINV_PLUGIN_DIR . 'includes/user-functions.php' );
205
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
206
+
207
+        // Register autoloader.
208
+        try {
209
+            spl_autoload_register( array( $this, 'autoload' ), true );
210
+        } catch ( Exception $e ) {
211
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
212
+        }
213
+
214
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
215
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
216
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
217
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
219
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
220
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
221
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
224
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
225
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
234
+
235
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
236
+            GetPaid_Post_Types_Admin::init();
237
+
238
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
239
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
240
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
241
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
242
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
243
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
244
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
245
+            // load the user class only on the users.php page
246
+            global $pagenow;
247
+            if($pagenow=='users.php'){
248
+                new WPInv_Admin_Users();
249
+            }
250
+        }
251
+
252
+        // Register cli commands
253
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
254
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
255
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
256
+        }
257
+
258
+    }
259
+
260
+    /**
261
+     * Class autoloader
262
+     *
263
+     * @param       string $class_name The name of the class to load.
264
+     * @access      public
265
+     * @since       1.0.19
266
+     * @return      void
267
+     */
268
+    public function autoload( $class_name ) {
269
+
270
+        // Normalize the class name...
271
+        $class_name  = strtolower( $class_name );
272
+
273
+        // ... and make sure it is our class.
274
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
275
+            return;
276
+        }
368 277
 
369
-		$localize                         = array();
370
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
371
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
-		$localize['UseTaxes']             = wpinv_use_taxes();
374
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
375
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
278
+        // Next, prepare the file name from the class.
279
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
377 280
 
378
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
-
380
-		wp_enqueue_script( 'jquery-blockui' );
381
-
382
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
383
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
384
-
385
-		wp_enqueue_script( 'wpinv-front-script' );
386
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
387
-
388
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
389
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ),  $version, true );
390
-	}
281
+        // Base path of the classes.
282
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
391 283
 
392
-	public function wpinv_actions() {
393
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
394
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
395
-		}
396
-	}
284
+        // And an array of possible locations in order of importance.
285
+        $locations = array(
286
+            "$plugin_path/includes",
287
+            "$plugin_path/includes/data-stores",
288
+            "$plugin_path/includes/gateways",
289
+            "$plugin_path/includes/payments",
290
+            "$plugin_path/includes/geolocation",
291
+            "$plugin_path/includes/reports",
292
+            "$plugin_path/includes/api",
293
+            "$plugin_path/includes/admin",
294
+            "$plugin_path/includes/admin/meta-boxes",
295
+        );
397 296
 
398
-	/**
297
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
298
+
299
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
300
+                include trailingslashit( $location ) . $file_name;
301
+                break;
302
+            }
303
+
304
+        }
305
+
306
+    }
307
+
308
+    /**
309
+     * Inits hooks etc.
310
+     */
311
+    public function init() {
312
+
313
+        // Fires before getpaid inits.
314
+        do_action( 'before_getpaid_init', $this );
315
+
316
+        // Maybe upgrade.
317
+        $this->maybe_upgrade_database();
318
+
319
+        // Load default gateways.
320
+        $gateways = apply_filters(
321
+            'getpaid_default_gateways',
322
+            array(
323
+                'manual'        => 'GetPaid_Manual_Gateway',
324
+                'paypal'        => 'GetPaid_Paypal_Gateway',
325
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
326
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
327
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
328
+            )
329
+        );
330
+
331
+        foreach ( $gateways as $id => $class ) {
332
+            $this->gateways[ $id ] = new $class();
333
+        }
334
+
335
+        // Fires after getpaid inits.
336
+        do_action( 'getpaid_init', $this );
337
+
338
+    }
339
+
340
+    /**
341
+     * Checks if this is an IPN request and processes it.
342
+     */
343
+    public function maybe_process_ipn() {
344
+
345
+        // Ensure that this is an IPN request.
346
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
347
+            return;
348
+        }
349
+
350
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
351
+
352
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
353
+        do_action( "wpinv_verify_{$gateway}_ipn" );
354
+        exit;
355
+
356
+    }
357
+
358
+    public function enqueue_scripts() {
359
+        $suffix  = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
360
+
361
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
362
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
363
+        wp_enqueue_style( 'wpinv_front_style' );
364
+
365
+        // Register scripts
366
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
367
+        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ), true );
368
+
369
+        $localize                         = array();
370
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
371
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
372
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
373
+        $localize['UseTaxes']             = wpinv_use_taxes();
374
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
375
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
376
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
377
+
378
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
379
+
380
+        wp_enqueue_script( 'jquery-blockui' );
381
+
382
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' );
383
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
384
+
385
+        wp_enqueue_script( 'wpinv-front-script' );
386
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
387
+
388
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
389
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script' ),  $version, true );
390
+    }
391
+
392
+    public function wpinv_actions() {
393
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
394
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
395
+        }
396
+    }
397
+
398
+    /**
399 399
      * Fires an action after verifying that a user can fire them.
400
-	 *
401
-	 * Note: If the action is on an invoice, subscription etc, esure that the
402
-	 * current user owns the invoice/subscription.
400
+     *
401
+     * Note: If the action is on an invoice, subscription etc, esure that the
402
+     * current user owns the invoice/subscription.
403 403
      */
404 404
     public function maybe_do_authenticated_action() {
405 405
 
406
-		if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
406
+        if ( isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) {
407 407
 
408
-			$key  = sanitize_key( $_REQUEST['getpaid-action'] );
409
-			$data = wp_unslash( $_REQUEST );
410
-			if ( is_user_logged_in() ) {
411
-				do_action( "getpaid_authenticated_action_$key", $data );
412
-			}
408
+            $key  = sanitize_key( $_REQUEST['getpaid-action'] );
409
+            $data = wp_unslash( $_REQUEST );
410
+            if ( is_user_logged_in() ) {
411
+                do_action( "getpaid_authenticated_action_$key", $data );
412
+            }
413 413
 
414
-			do_action( "getpaid_unauthenticated_action_$key", $data );
414
+            do_action( "getpaid_unauthenticated_action_$key", $data );
415 415
 
416
-		}
416
+        }
417 417
 
418 418
     }
419 419
 
420
-	public function pre_get_posts( $wp_query ) {
421
-
422
-		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() ) {
423
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
424
-		}
425
-
426
-		return $wp_query;
427
-	}
428
-
429
-	public function bp_invoicing_init() {
430
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
431
-	}
432
-
433
-	/**
434
-	 * Register widgets
435
-	 *
436
-	 */
437
-	public function register_widgets() {
438
-		$widgets = apply_filters(
439
-			'getpaid_widget_classes',
440
-			array(
441
-				'WPInv_Checkout_Widget',
442
-				'WPInv_History_Widget',
443
-				'WPInv_Receipt_Widget',
444
-				'WPInv_Subscriptions_Widget',
445
-				'WPInv_Buy_Item_Widget',
446
-				'WPInv_Messages_Widget',
447
-				'WPInv_GetPaid_Widget'
448
-			)
449
-		);
450
-
451
-		foreach ( $widgets as $widget ) {
452
-			register_widget( $widget );
453
-		}
420
+    public function pre_get_posts( $wp_query ) {
421
+
422
+        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() ) {
423
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses( false, false, $wp_query->query_vars['post_type'] ) );
424
+        }
425
+
426
+        return $wp_query;
427
+    }
428
+
429
+    public function bp_invoicing_init() {
430
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
431
+    }
432
+
433
+    /**
434
+     * Register widgets
435
+     *
436
+     */
437
+    public function register_widgets() {
438
+        $widgets = apply_filters(
439
+            'getpaid_widget_classes',
440
+            array(
441
+                'WPInv_Checkout_Widget',
442
+                'WPInv_History_Widget',
443
+                'WPInv_Receipt_Widget',
444
+                'WPInv_Subscriptions_Widget',
445
+                'WPInv_Buy_Item_Widget',
446
+                'WPInv_Messages_Widget',
447
+                'WPInv_GetPaid_Widget'
448
+            )
449
+        );
450
+
451
+        foreach ( $widgets as $widget ) {
452
+            register_widget( $widget );
453
+        }
454 454
 		
455
-	}
455
+    }
456 456
 
457
-	/**
458
-	 * Upgrades the database.
459
-	 *
460
-	 * @since 2.0.2
461
-	 */
462
-	public function maybe_upgrade_database() {
457
+    /**
458
+     * Upgrades the database.
459
+     *
460
+     * @since 2.0.2
461
+     */
462
+    public function maybe_upgrade_database() {
463 463
 
464
-		$wpi_version = get_option( 'wpinv_version', 0 );
464
+        $wpi_version = get_option( 'wpinv_version', 0 );
465 465
 
466
-		if ( $wpi_version == WPINV_VERSION ) {
467
-			return;
468
-		}
466
+        if ( $wpi_version == WPINV_VERSION ) {
467
+            return;
468
+        }
469 469
 
470
-		$installer = new GetPaid_Installer();
470
+        $installer = new GetPaid_Installer();
471 471
 
472
-		if ( empty( $wpi_version ) ) {
473
-			$installer->upgrade_db( 0 );
474
-		}
472
+        if ( empty( $wpi_version ) ) {
473
+            $installer->upgrade_db( 0 );
474
+        }
475 475
 
476
-		$upgrades  = array(
477
-			'0.0.5' => '004',
478
-			'1.0.3' => '102',
479
-			'2.0.0' => '118',
480
-		);
476
+        $upgrades  = array(
477
+            '0.0.5' => '004',
478
+            '1.0.3' => '102',
479
+            '2.0.0' => '118',
480
+        );
481 481
 
482
-		foreach ( $upgrades as $key => $method ) {
482
+        foreach ( $upgrades as $key => $method ) {
483 483
 
484
-			if ( version_compare( $wpi_version, $key, '<' ) ) {
485
-				return $installer->upgrade_db( $method );
486
-			}
484
+            if ( version_compare( $wpi_version, $key, '<' ) ) {
485
+                return $installer->upgrade_db( $method );
486
+            }
487 487
 
488
-		}
488
+        }
489 489
 
490
-	}
490
+    }
491 491
 
492
-	/**
493
-	 * Remove our pages from yoast sitemaps.
494
-	 *
495
-	 * @since 1.0.19
496
-	 * @param int[] $excluded_posts_ids
497
-	 */
498
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
492
+    /**
493
+     * Remove our pages from yoast sitemaps.
494
+     *
495
+     * @since 1.0.19
496
+     * @param int[] $excluded_posts_ids
497
+     */
498
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
499 499
 
500
-		// Ensure that we have an array.
501
-		if ( ! is_array( $excluded_posts_ids ) ) {
502
-			$excluded_posts_ids = array();
503
-		}
500
+        // Ensure that we have an array.
501
+        if ( ! is_array( $excluded_posts_ids ) ) {
502
+            $excluded_posts_ids = array();
503
+        }
504 504
 
505
-		// Prepare our pages.
506
-		$our_pages = array();
505
+        // Prepare our pages.
506
+        $our_pages = array();
507 507
 
508
-		// Checkout page.
509
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
508
+        // Checkout page.
509
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
510 510
 
511
-		// Success page.
512
-		$our_pages[] = wpinv_get_option( 'success_page', false );
511
+        // Success page.
512
+        $our_pages[] = wpinv_get_option( 'success_page', false );
513 513
 
514
-		// Failure page.
515
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
514
+        // Failure page.
515
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
516 516
 
517
-		// History page.
518
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
517
+        // History page.
518
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
519 519
 
520
-		// Subscriptions page.
521
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
520
+        // Subscriptions page.
521
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
522 522
 
523
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
523
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
524 524
 
525
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
526
-		return array_unique( $excluded_posts_ids );
525
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
526
+        return array_unique( $excluded_posts_ids );
527 527
 
528
-	}
528
+    }
529 529
 
530
-	public function wp_footer() {
531
-		echo '
530
+    public function wp_footer() {
531
+        echo '
532 532
 			<div class="bsui">
533 533
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
534 534
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -544,6 +544,6 @@  discard block
 block discarded – undo
544 544
 				</div>
545 545
 			</div>
546 546
 		';
547
-	}
547
+    }
548 548
 
549 549
 }
Please login to merge, or discard this patch.