Passed
Push — master ( 32890d...b6d11a )
by Brian
13:10
created
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +375 added lines, -375 removed lines patch added patch discarded remove patch
@@ -20,228 +20,228 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-		$this->create_subscriptions_table();
69
-		$this->create_invoices_table();
70
-		$this->create_invoice_items_table();
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$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' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$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' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-
93
-		}
94
-
95
-		// Item meta key changes
96
-		$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' )";
97
-		$results = $wpdb->get_results( $query );
98
-
99
-		if ( ! empty( $results ) ) {
100
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
101
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
102
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
103
-
104
-			foreach ( $results as $row ) {
105
-				clean_post_cache( $row->post_id );
106
-			}
107
-
108
-		}
109
-
110
-		$this->upgrade_from_102();
111
-	}
112
-
113
-	/**
114
-	 * Upgrade to 1.0.3
115
-	 *
116
-	 */
117
-	public function upgrade_from_102() {
118
-		$this->create_subscriptions_table();
119
-		$this->upgrade_from_118();
120
-	}
121
-
122
-	/**
123
-	 * Upgrade to version 2.0.0.
124
-	 *
125
-	 */
126
-	public function upgrade_from_118() {
127
-		$this->create_invoices_table();
128
-		$this->create_invoice_items_table();
129
-		$this->migrate_old_invoices();
130
-	}
131
-
132
-	/**
133
-	 * Upgrade to version 2.0.8.
134
-	 *
135
-	 */
136
-	public function upgrade_from_207() {
137
-		global $wpdb;
138
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
139
-	}
140
-
141
-	/**
142
-	 * Give administrators the capability to manage GetPaid.
143
-	 *
144
-	 */
145
-	public function add_capabilities() {
146
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
147
-	}
148
-
149
-	/**
150
-	 * Retreives GetPaid pages.
151
-	 *
152
-	 */
153
-	public static function get_pages() {
154
-
155
-		return apply_filters(
156
-			'wpinv_create_pages',
157
-			array(
158
-
159
-				// Checkout page.
160
-				'checkout_page' => array(
161
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
162
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
163
-					'content'   => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+        $this->create_subscriptions_table();
69
+        $this->create_invoices_table();
70
+        $this->create_invoice_items_table();
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $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' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $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' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+
93
+        }
94
+
95
+        // Item meta key changes
96
+        $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' )";
97
+        $results = $wpdb->get_results( $query );
98
+
99
+        if ( ! empty( $results ) ) {
100
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
101
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
102
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
103
+
104
+            foreach ( $results as $row ) {
105
+                clean_post_cache( $row->post_id );
106
+            }
107
+
108
+        }
109
+
110
+        $this->upgrade_from_102();
111
+    }
112
+
113
+    /**
114
+     * Upgrade to 1.0.3
115
+     *
116
+     */
117
+    public function upgrade_from_102() {
118
+        $this->create_subscriptions_table();
119
+        $this->upgrade_from_118();
120
+    }
121
+
122
+    /**
123
+     * Upgrade to version 2.0.0.
124
+     *
125
+     */
126
+    public function upgrade_from_118() {
127
+        $this->create_invoices_table();
128
+        $this->create_invoice_items_table();
129
+        $this->migrate_old_invoices();
130
+    }
131
+
132
+    /**
133
+     * Upgrade to version 2.0.8.
134
+     *
135
+     */
136
+    public function upgrade_from_207() {
137
+        global $wpdb;
138
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
139
+    }
140
+
141
+    /**
142
+     * Give administrators the capability to manage GetPaid.
143
+     *
144
+     */
145
+    public function add_capabilities() {
146
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
147
+    }
148
+
149
+    /**
150
+     * Retreives GetPaid pages.
151
+     *
152
+     */
153
+    public static function get_pages() {
154
+
155
+        return apply_filters(
156
+            'wpinv_create_pages',
157
+            array(
158
+
159
+                // Checkout page.
160
+                'checkout_page' => array(
161
+                    'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
162
+                    'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
163
+                    'content'   => '
164 164
 						<!-- wp:shortcode -->
165 165
 						[wpinv_checkout]
166 166
 						<!-- /wp:shortcode -->
167 167
 					',
168
-					'parent'    => '',
169
-				),
170
-
171
-				// Invoice history page.
172
-				'invoice_history_page' => array(
173
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
174
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
175
-					'content' => '
168
+                    'parent'    => '',
169
+                ),
170
+
171
+                // Invoice history page.
172
+                'invoice_history_page' => array(
173
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
174
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
175
+                    'content' => '
176 176
 					<!-- wp:shortcode -->
177 177
 					[wpinv_history]
178 178
 					<!-- /wp:shortcode -->
179 179
 				',
180
-					'parent'  => '',
181
-				),
182
-
183
-				// Success page content.
184
-				'success_page' => array(
185
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
186
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
187
-					'content'  => '
180
+                    'parent'  => '',
181
+                ),
182
+
183
+                // Success page content.
184
+                'success_page' => array(
185
+                    'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
186
+                    'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
187
+                    'content'  => '
188 188
 					<!-- wp:shortcode -->
189 189
 					[wpinv_receipt]
190 190
 					<!-- /wp:shortcode -->
191 191
 				',
192
-					'parent'   => 'gp-checkout',
193
-				),
194
-
195
-				// Failure page content.
196
-				'failure_page' => array(
197
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
198
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
199
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
200
-					'parent'  => 'gp-checkout',
201
-				),
202
-
203
-				// Subscriptions history page.
204
-				'invoice_subscription_page' => array(
205
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
206
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
207
-					'content' => '
192
+                    'parent'   => 'gp-checkout',
193
+                ),
194
+
195
+                // Failure page content.
196
+                'failure_page' => array(
197
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
198
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
199
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
200
+                    'parent'  => 'gp-checkout',
201
+                ),
202
+
203
+                // Subscriptions history page.
204
+                'invoice_subscription_page' => array(
205
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
206
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
207
+                    'content' => '
208 208
 					<!-- wp:shortcode -->
209 209
 					[wpinv_subscriptions]
210 210
 					<!-- /wp:shortcode -->
211 211
 				',
212
-					'parent' => '',
213
-				),
212
+                    'parent' => '',
213
+                ),
214 214
 
215
-			)
216
-		);
215
+            )
216
+        );
217 217
 
218
-	}
218
+    }
219 219
 
220
-	/**
221
-	 * Re-create GetPaid pages.
222
-	 *
223
-	 */
224
-	public function create_pages() {
220
+    /**
221
+     * Re-create GetPaid pages.
222
+     *
223
+     */
224
+    public function create_pages() {
225 225
 
226
-		foreach ( self::get_pages() as $key => $page ) {
227
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
228
-		}
226
+        foreach ( self::get_pages() as $key => $page ) {
227
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
228
+        }
229 229
 
230
-	}
230
+    }
231 231
 
232
-	/**
233
-	 * Create subscriptions table.
234
-	 *
235
-	 */
236
-	public function create_subscriptions_table() {
232
+    /**
233
+     * Create subscriptions table.
234
+     *
235
+     */
236
+    public function create_subscriptions_table() {
237 237
 
238
-		global $wpdb;
238
+        global $wpdb;
239 239
 
240
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
240
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
241 241
 
242
-		// Create tables.
243
-		$charset_collate = $wpdb->get_charset_collate();
244
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
242
+        // Create tables.
243
+        $charset_collate = $wpdb->get_charset_collate();
244
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
245 245
 			id bigint(20) unsigned NOT NULL auto_increment,
246 246
 			customer_id bigint(20) NOT NULL,
247 247
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -264,22 +264,22 @@  discard block
 block discarded – undo
264 264
 			KEY customer_and_status (customer_id, status)
265 265
 		  ) $charset_collate;";
266 266
 
267
-		dbDelta( $sql );
267
+        dbDelta( $sql );
268 268
 
269
-	}
269
+    }
270 270
 
271
-	/**
272
-	 * Create invoices table.
273
-	 *
274
-	 */
275
-	public function create_invoices_table() {
276
-		global $wpdb;
271
+    /**
272
+     * Create invoices table.
273
+     *
274
+     */
275
+    public function create_invoices_table() {
276
+        global $wpdb;
277 277
 
278
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
278
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
279 279
 
280
-		// Create tables.
281
-		$charset_collate = $wpdb->get_charset_collate();
282
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
280
+        // Create tables.
281
+        $charset_collate = $wpdb->get_charset_collate();
282
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
283 283
 			post_id BIGINT(20) NOT NULL,
284 284
             `number` VARCHAR(100),
285 285
             `key` VARCHAR(100),
@@ -315,22 +315,22 @@  discard block
 block discarded – undo
315 315
 			KEY `key` (`key`)
316 316
 		  ) $charset_collate;";
317 317
 
318
-		dbDelta( $sql );
318
+        dbDelta( $sql );
319 319
 
320
-	}
320
+    }
321 321
 
322
-	/**
323
-	 * Create invoice items table.
324
-	 *
325
-	 */
326
-	public function create_invoice_items_table() {
327
-		global $wpdb;
322
+    /**
323
+     * Create invoice items table.
324
+     *
325
+     */
326
+    public function create_invoice_items_table() {
327
+        global $wpdb;
328 328
 
329
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
329
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
330 330
 
331
-		// Create tables.
332
-		$charset_collate = $wpdb->get_charset_collate();
333
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
331
+        // Create tables.
332
+        $charset_collate = $wpdb->get_charset_collate();
333
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
334 334
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
335 335
             post_id BIGINT(20) NOT NULL,
336 336
             item_id BIGINT(20) NOT NULL,
@@ -352,159 +352,159 @@  discard block
 block discarded – undo
352 352
 			KEY post_id (post_id)
353 353
 		  ) $charset_collate;";
354 354
 
355
-		dbDelta( $sql );
356
-
357
-	}
358
-
359
-	/**
360
-	 * Migrates old invoices to new invoices.
361
-	 *
362
-	 */
363
-	public function migrate_old_invoices() {
364
-		global $wpdb;
365
-
366
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
367
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
368
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
369
-		$invoices            = array_unique(
370
-			get_posts(
371
-				array(
372
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
373
-					'posts_per_page' => -1,
374
-					'fields'         => 'ids',
375
-					'post_status'    => array_keys( get_post_stati() ),
376
-					'exclude'        => (array) $migrated,
377
-				)
378
-			)
379
-		);
380
-
381
-		// Abort if we do not have any invoices.
382
-		if ( empty( $invoices ) ) {
383
-			return;
384
-		}
385
-
386
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
387
-
388
-		$invoice_rows = array();
389
-		foreach ( $invoices as $invoice ) {
390
-
391
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
392
-
393
-			if ( empty( $invoice->ID ) ) {
394
-				return;
395
-			}
396
-
397
-			$fields = array (
398
-				'post_id'        => $invoice->ID,
399
-				'number'         => $invoice->get_number(),
400
-				'key'            => $invoice->get_key(),
401
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
402
-				'mode'           => $invoice->mode,
403
-				'user_ip'        => $invoice->get_ip(),
404
-				'first_name'     => $invoice->get_first_name(),
405
-				'last_name'      => $invoice->get_last_name(),
406
-				'address'        => $invoice->get_address(),
407
-				'city'           => $invoice->city,
408
-				'state'          => $invoice->state,
409
-				'country'        => $invoice->country,
410
-				'zip'            => $invoice->zip,
411
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
412
-				'gateway'        => $invoice->get_gateway(),
413
-				'transaction_id' => $invoice->get_transaction_id(),
414
-				'currency'       => $invoice->get_currency(),
415
-				'subtotal'       => $invoice->get_subtotal(),
416
-				'tax'            => $invoice->get_tax(),
417
-				'fees_total'     => $invoice->get_fees_total(),
418
-				'total'          => $invoice->get_total(),
419
-				'discount'       => $invoice->get_discount(),
420
-				'discount_code'  => $invoice->get_discount_code(),
421
-				'disable_taxes'  => $invoice->disable_taxes,
422
-				'due_date'       => $invoice->get_due_date(),
423
-				'completed_date' => $invoice->get_completed_date(),
424
-				'company'        => $invoice->company,
425
-				'vat_number'     => $invoice->vat_number,
426
-				'vat_rate'       => $invoice->vat_rate,
427
-				'custom_meta'    => $invoice->payment_meta
428
-			);
429
-
430
-			foreach ( $fields as $key => $val ) {
431
-				if ( is_null( $val ) ) {
432
-					$val = '';
433
-				}
434
-				$val = maybe_serialize( $val );
435
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
436
-			}
437
-
438
-			$fields = implode( ', ', $fields );
439
-			$invoice_rows[] = "($fields)";
440
-
441
-			$item_rows    = array();
442
-			$item_columns = array();
443
-			foreach ( $invoice->get_cart_details() as $details ) {
444
-				$fields = array(
445
-					'post_id'          => $invoice->ID,
446
-					'item_id'          => $details['id'],
447
-					'item_name'        => $details['name'],
448
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
449
-					'vat_rate'         => $details['vat_rate'],
450
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
451
-					'tax'              => $details['tax'],
452
-					'item_price'       => $details['item_price'],
453
-					'custom_price'     => $details['custom_price'],
454
-					'quantity'         => $details['quantity'],
455
-					'discount'         => $details['discount'],
456
-					'subtotal'         => $details['subtotal'],
457
-					'price'            => $details['price'],
458
-					'meta'             => $details['meta'],
459
-					'fees'             => $details['fees'],
460
-				);
461
-
462
-				$item_columns = array_keys ( $fields );
463
-
464
-				foreach ( $fields as $key => $val ) {
465
-					if ( is_null( $val ) ) {
466
-						$val = '';
467
-					}
468
-					$val = maybe_serialize( $val );
469
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
470
-				}
471
-
472
-				$fields = implode( ', ', $fields );
473
-				$item_rows[] = "($fields)";
474
-			}
475
-
476
-			$item_rows    = implode( ', ', $item_rows );
477
-			$item_columns = implode( ', ', $item_columns );
478
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
479
-		}
480
-
481
-		if ( empty( $invoice_rows ) ) {
482
-			return;
483
-		}
484
-
485
-		$invoice_rows = implode( ', ', $invoice_rows );
486
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
487
-
488
-	}
489
-
490
-	/**
491
-	 * Migrates old invoices to new invoices.
492
-	 *
493
-	 */
494
-	public static function rename_gateways_label() {
495
-		global $wpdb;
496
-
497
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
498
-
499
-			$wpdb->update(
500
-				$wpdb->prefix . 'getpaid_invoices',
501
-				array( 'gateway' => $gateway ),
502
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
503
-				'%s',
504
-				'%s'
505
-			);
506
-
507
-		}
508
-	}
355
+        dbDelta( $sql );
356
+
357
+    }
358
+
359
+    /**
360
+     * Migrates old invoices to new invoices.
361
+     *
362
+     */
363
+    public function migrate_old_invoices() {
364
+        global $wpdb;
365
+
366
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
367
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
368
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
369
+        $invoices            = array_unique(
370
+            get_posts(
371
+                array(
372
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
373
+                    'posts_per_page' => -1,
374
+                    'fields'         => 'ids',
375
+                    'post_status'    => array_keys( get_post_stati() ),
376
+                    'exclude'        => (array) $migrated,
377
+                )
378
+            )
379
+        );
380
+
381
+        // Abort if we do not have any invoices.
382
+        if ( empty( $invoices ) ) {
383
+            return;
384
+        }
385
+
386
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
387
+
388
+        $invoice_rows = array();
389
+        foreach ( $invoices as $invoice ) {
390
+
391
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
392
+
393
+            if ( empty( $invoice->ID ) ) {
394
+                return;
395
+            }
396
+
397
+            $fields = array (
398
+                'post_id'        => $invoice->ID,
399
+                'number'         => $invoice->get_number(),
400
+                'key'            => $invoice->get_key(),
401
+                'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
402
+                'mode'           => $invoice->mode,
403
+                'user_ip'        => $invoice->get_ip(),
404
+                'first_name'     => $invoice->get_first_name(),
405
+                'last_name'      => $invoice->get_last_name(),
406
+                'address'        => $invoice->get_address(),
407
+                'city'           => $invoice->city,
408
+                'state'          => $invoice->state,
409
+                'country'        => $invoice->country,
410
+                'zip'            => $invoice->zip,
411
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
412
+                'gateway'        => $invoice->get_gateway(),
413
+                'transaction_id' => $invoice->get_transaction_id(),
414
+                'currency'       => $invoice->get_currency(),
415
+                'subtotal'       => $invoice->get_subtotal(),
416
+                'tax'            => $invoice->get_tax(),
417
+                'fees_total'     => $invoice->get_fees_total(),
418
+                'total'          => $invoice->get_total(),
419
+                'discount'       => $invoice->get_discount(),
420
+                'discount_code'  => $invoice->get_discount_code(),
421
+                'disable_taxes'  => $invoice->disable_taxes,
422
+                'due_date'       => $invoice->get_due_date(),
423
+                'completed_date' => $invoice->get_completed_date(),
424
+                'company'        => $invoice->company,
425
+                'vat_number'     => $invoice->vat_number,
426
+                'vat_rate'       => $invoice->vat_rate,
427
+                'custom_meta'    => $invoice->payment_meta
428
+            );
429
+
430
+            foreach ( $fields as $key => $val ) {
431
+                if ( is_null( $val ) ) {
432
+                    $val = '';
433
+                }
434
+                $val = maybe_serialize( $val );
435
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
436
+            }
437
+
438
+            $fields = implode( ', ', $fields );
439
+            $invoice_rows[] = "($fields)";
440
+
441
+            $item_rows    = array();
442
+            $item_columns = array();
443
+            foreach ( $invoice->get_cart_details() as $details ) {
444
+                $fields = array(
445
+                    'post_id'          => $invoice->ID,
446
+                    'item_id'          => $details['id'],
447
+                    'item_name'        => $details['name'],
448
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
449
+                    'vat_rate'         => $details['vat_rate'],
450
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
451
+                    'tax'              => $details['tax'],
452
+                    'item_price'       => $details['item_price'],
453
+                    'custom_price'     => $details['custom_price'],
454
+                    'quantity'         => $details['quantity'],
455
+                    'discount'         => $details['discount'],
456
+                    'subtotal'         => $details['subtotal'],
457
+                    'price'            => $details['price'],
458
+                    'meta'             => $details['meta'],
459
+                    'fees'             => $details['fees'],
460
+                );
461
+
462
+                $item_columns = array_keys ( $fields );
463
+
464
+                foreach ( $fields as $key => $val ) {
465
+                    if ( is_null( $val ) ) {
466
+                        $val = '';
467
+                    }
468
+                    $val = maybe_serialize( $val );
469
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
470
+                }
471
+
472
+                $fields = implode( ', ', $fields );
473
+                $item_rows[] = "($fields)";
474
+            }
475
+
476
+            $item_rows    = implode( ', ', $item_rows );
477
+            $item_columns = implode( ', ', $item_columns );
478
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
479
+        }
480
+
481
+        if ( empty( $invoice_rows ) ) {
482
+            return;
483
+        }
484
+
485
+        $invoice_rows = implode( ', ', $invoice_rows );
486
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
487
+
488
+    }
489
+
490
+    /**
491
+     * Migrates old invoices to new invoices.
492
+     *
493
+     */
494
+    public static function rename_gateways_label() {
495
+        global $wpdb;
496
+
497
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
498
+
499
+            $wpdb->update(
500
+                $wpdb->prefix . 'getpaid_invoices',
501
+                array( 'gateway' => $gateway ),
502
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
503
+                '%s',
504
+                '%s'
505
+            );
506
+
507
+        }
508
+    }
509 509
 
510 510
 }
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 1 patch
Indentation   +451 added lines, -451 removed lines patch added patch discarded remove patch
@@ -12,492 +12,492 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		$skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
-		if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
-			return;
186
-		}
187
-
188
-		$mailer     = new GetPaid_Notification_Email_Sender();
189
-		$merge_tags = $email->get_merge_tags();
190
-
191
-		$result = $mailer->send(
192
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
-			$email->get_content( $merge_tags, $extra_args ),
195
-			$email->get_attachments()
196
-		);
197
-
198
-		// Maybe send a copy to the admin.
199
-		if ( $email->include_admin_bcc() ) {
200
-			$mailer->send(
201
-				wpinv_get_admin_email(),
202
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
-				$email->get_content( $merge_tags ),
204
-				$email->get_attachments()
205
-			);
206
-		}
207
-
208
-		if ( $result ) {
209
-			$invoice->add_system_note(
210
-				sprintf(
211
-					__( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
-					sanitize_key( $type ),
213
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
-				)
215
-			);
216
-		} else {
217
-			$invoice->add_system_note(
218
-				sprintf(
219
-					__( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
-					sanitize_key( $type ),
221
-					$email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
-				)
223
-			);	
224
-		}
225
-
226
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
-
228
-		return $result;
229
-	}
230
-
231
-	/**
232
-	 * Also send emails to any cc users.
233
-	 *
234
-	 * @param array $recipients
235
-	 * @param GetPaid_Notification_Email $email
236
-	 */
237
-	public function filter_email_recipients( $recipients, $email ) {
238
-
239
-		if ( ! $email->is_admin_email() ) {
240
-			$cc   = $email->object->get_email_cc();
241
-			$cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
-
243
-			if ( ! empty( $cc ) ) {
244
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
-			}
247
-
248
-			if ( ! empty( $cc_2 ) ) {
249
-				$cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
-			}
252
-
253
-		}
254
-
255
-		return $recipients;
256
-
257
-	}
258
-
259
-	/**
260
-	 * Sends a new invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function new_invoice( $invoice ) {
265
-
266
-		// Only send this email for invoices created via the admin page.
267
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
-			return;
269
-		}
270
-
271
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
-		$recipient = wpinv_get_admin_email();
273
-
274
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
-
276
-	}
277
-
278
-	/**
279
-	 * Sends a cancelled invoice notification.
280
-	 *
281
-	 * @param WPInv_Invoice $invoice
282
-	 */
283
-	public function cancelled_invoice( $invoice ) {
284
-
285
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
-		$recipient = wpinv_get_admin_email();
287
-
288
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
-
290
-	}
291
-
292
-	/**
293
-	 * Sends a failed invoice notification.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice
296
-	 */
297
-	public function failed_invoice( $invoice ) {
298
-
299
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
-		$recipient = wpinv_get_admin_email();
301
-
302
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
-
304
-	}
305
-
306
-	/**
307
-	 * Sends a notification whenever an invoice is put on hold.
308
-	 *
309
-	 * @param WPInv_Invoice $invoice
310
-	 */
311
-	public function onhold_invoice( $invoice ) {
312
-
313
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
-		$recipient = $invoice->get_email();
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' );
184
+        if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) {
185
+            return;
186
+        }
187
+
188
+        $mailer     = new GetPaid_Notification_Email_Sender();
189
+        $merge_tags = $email->get_merge_tags();
190
+
191
+        $result = $mailer->send(
192
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
193
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
194
+            $email->get_content( $merge_tags, $extra_args ),
195
+            $email->get_attachments()
196
+        );
197
+
198
+        // Maybe send a copy to the admin.
199
+        if ( $email->include_admin_bcc() ) {
200
+            $mailer->send(
201
+                wpinv_get_admin_email(),
202
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
203
+                $email->get_content( $merge_tags ),
204
+                $email->get_attachments()
205
+            );
206
+        }
207
+
208
+        if ( $result ) {
209
+            $invoice->add_system_note(
210
+                sprintf(
211
+                    __( 'Successfully sent %s notification email to %s.', 'invoicing' ),
212
+                    sanitize_key( $type ),
213
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
214
+                )
215
+            );
216
+        } else {
217
+            $invoice->add_system_note(
218
+                sprintf(
219
+                    __( 'Failed sending %s notification email to %s.', 'invoicing' ),
220
+                    sanitize_key( $type ),
221
+                    $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' )
222
+                )
223
+            );	
224
+        }
225
+
226
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
227
+
228
+        return $result;
229
+    }
230
+
231
+    /**
232
+     * Also send emails to any cc users.
233
+     *
234
+     * @param array $recipients
235
+     * @param GetPaid_Notification_Email $email
236
+     */
237
+    public function filter_email_recipients( $recipients, $email ) {
238
+
239
+        if ( ! $email->is_admin_email() ) {
240
+            $cc   = $email->object->get_email_cc();
241
+            $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true );
242
+
243
+            if ( ! empty( $cc ) ) {
244
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
245
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
246
+            }
247
+
248
+            if ( ! empty( $cc_2 ) ) {
249
+                $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) );
250
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) );
251
+            }
252
+
253
+        }
254
+
255
+        return $recipients;
256
+
257
+    }
258
+
259
+    /**
260
+     * Sends a new invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function new_invoice( $invoice ) {
265
+
266
+        // Only send this email for invoices created via the admin page.
267
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
268
+            return;
269
+        }
270
+
271
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
272
+        $recipient = wpinv_get_admin_email();
273
+
274
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
275
+
276
+    }
277
+
278
+    /**
279
+     * Sends a cancelled invoice notification.
280
+     *
281
+     * @param WPInv_Invoice $invoice
282
+     */
283
+    public function cancelled_invoice( $invoice ) {
284
+
285
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
286
+        $recipient = wpinv_get_admin_email();
287
+
288
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
289
+
290
+    }
291
+
292
+    /**
293
+     * Sends a failed invoice notification.
294
+     *
295
+     * @param WPInv_Invoice $invoice
296
+     */
297
+    public function failed_invoice( $invoice ) {
298
+
299
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
300
+        $recipient = wpinv_get_admin_email();
301
+
302
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
303
+
304
+    }
305
+
306
+    /**
307
+     * Sends a notification whenever an invoice is put on hold.
308
+     *
309
+     * @param WPInv_Invoice $invoice
310
+     */
311
+    public function onhold_invoice( $invoice ) {
312
+
313
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
314
+        $recipient = $invoice->get_email();
315 315
 
316
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
316
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
317 317
 
318
-	}
318
+    }
319 319
 
320
-	/**
321
-	 * Sends a notification whenever an invoice is marked as processing payment.
322
-	 *
323
-	 * @param WPInv_Invoice $invoice
324
-	 */
325
-	public function processing_invoice( $invoice ) {
320
+    /**
321
+     * Sends a notification whenever an invoice is marked as processing payment.
322
+     *
323
+     * @param WPInv_Invoice $invoice
324
+     */
325
+    public function processing_invoice( $invoice ) {
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
-
332
-	}
333
-
334
-	/**
335
-	 * Sends a notification whenever an invoice is paid.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function completed_invoice( $invoice ) {
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331
+
332
+    }
333
+
334
+    /**
335
+     * Sends a notification whenever an invoice is paid.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function completed_invoice( $invoice ) {
340 340
 
341
-		// (Maybe) abort if it is a renewal invoice.
342
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
-			return;
344
-		}
341
+        // (Maybe) abort if it is a renewal invoice.
342
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
343
+            return;
344
+        }
345 345
 
346
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
-		$recipient = $invoice->get_email();
346
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
347
+        $recipient = $invoice->get_email();
348 348
 
349
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
349
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
350 350
 
351
-	}
351
+    }
352 352
 
353
-	/**
354
-	 * Sends a notification whenever an invoice is refunded.
355
-	 *
356
-	 * @param WPInv_Invoice $invoice
357
-	 */
358
-	public function refunded_invoice( $invoice ) {
353
+    /**
354
+     * Sends a notification whenever an invoice is refunded.
355
+     *
356
+     * @param WPInv_Invoice $invoice
357
+     */
358
+    public function refunded_invoice( $invoice ) {
359 359
 
360
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
-		$recipient = $invoice->get_email();
360
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
361
+        $recipient = $invoice->get_email();
362 362
 
363
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
363
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
364 364
 
365
-	}
365
+    }
366 366
 
367
-	/**
368
-	 * Notifies a user about new invoices
369
-	 *
370
-	 * @param WPInv_Invoice $invoice
371
-	 * @param bool $force
372
-	 */
373
-	public function user_invoice( $invoice, $force = false ) {
367
+    /**
368
+     * Notifies a user about new invoices
369
+     *
370
+     * @param WPInv_Invoice $invoice
371
+     * @param bool $force
372
+     */
373
+    public function user_invoice( $invoice, $force = false ) {
374 374
 
375
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
-			return;
377
-		}
378
-
379
-		// Only send this email for invoices created via the admin page.
380
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
-			return;
382
-		}
375
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
376
+            return;
377
+        }
378
+
379
+        // Only send this email for invoices created via the admin page.
380
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
381
+            return;
382
+        }
383 383
 
384
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
-		$recipient = $invoice->get_email();
384
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
385
+        $recipient = $invoice->get_email();
386 386
 
387
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
387
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
388 388
 
389
-	}
390
-
391
-	/**
392
-	 * Checks if an invoice is a payment form invoice.
393
-	 *
394
-	 * @param int $invoice
395
-	 * @return bool
396
-	 */
397
-	public function is_payment_form_invoice( $invoice ) {
398
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
-	}
389
+    }
390
+
391
+    /**
392
+     * Checks if an invoice is a payment form invoice.
393
+     *
394
+     * @param int $invoice
395
+     * @return bool
396
+     */
397
+    public function is_payment_form_invoice( $invoice ) {
398
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
399
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
400
+    }
401 401
 
402
-	/**
403
-	 * Notifies admin about new invoice notes
404
-	 *
405
-	 * @param WPInv_Invoice $invoice
406
-	 * @param string $note
407
-	 */
408
-	public function user_note( $invoice, $note ) {
409
-
410
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
-		$recipient = $invoice->get_email();
402
+    /**
403
+     * Notifies admin about new invoice notes
404
+     *
405
+     * @param WPInv_Invoice $invoice
406
+     * @param string $note
407
+     */
408
+    public function user_note( $invoice, $note ) {
409
+
410
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
411
+        $recipient = $invoice->get_email();
412 412
 
413
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
-
415
-	}
416
-
417
-	/**
418
-	 * (Force) Sends overdue notices.
419
-	 *
420
-	 * @param WPInv_Invoice $invoice
421
-	 */
422
-	public function force_send_overdue_notice( $invoice ) {
423
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
-	}
426
-
427
-	/**
428
-	 * Sends overdue notices.
429
-	 *
430
-	 * @TODO: Create an invoices query class.
431
-	 */
432
-	public function overdue() {
433
-		global $wpdb;
434
-
435
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
436
-
437
-		// Fetch reminder days.
438
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
-
440
-		// Abort if non is set.
441
-		if ( empty( $reminder_days ) ) {
442
-			return;
443
-		}
444
-
445
-		// Retrieve date query.
446
-		$date_query = $this->get_date_query( $reminder_days );
447
-
448
-		// Invoices table.
449
-		$table = $wpdb->prefix . 'getpaid_invoices';
450
-
451
-		// Fetch invoices.
452
-		$invoices  = $wpdb->get_col(
453
-			"SELECT posts.ID FROM $wpdb->posts as posts
413
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
414
+
415
+    }
416
+
417
+    /**
418
+     * (Force) Sends overdue notices.
419
+     *
420
+     * @param WPInv_Invoice $invoice
421
+     */
422
+    public function force_send_overdue_notice( $invoice ) {
423
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
424
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
425
+    }
426
+
427
+    /**
428
+     * Sends overdue notices.
429
+     *
430
+     * @TODO: Create an invoices query class.
431
+     */
432
+    public function overdue() {
433
+        global $wpdb;
434
+
435
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
436
+
437
+        // Fetch reminder days.
438
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
439
+
440
+        // Abort if non is set.
441
+        if ( empty( $reminder_days ) ) {
442
+            return;
443
+        }
444
+
445
+        // Retrieve date query.
446
+        $date_query = $this->get_date_query( $reminder_days );
447
+
448
+        // Invoices table.
449
+        $table = $wpdb->prefix . 'getpaid_invoices';
450
+
451
+        // Fetch invoices.
452
+        $invoices  = $wpdb->get_col(
453
+            "SELECT posts.ID FROM $wpdb->posts as posts
454 454
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
455 455
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
456 456
 
457
-		foreach ( $invoices as $invoice ) {
457
+        foreach ( $invoices as $invoice ) {
458 458
 
459
-			// Only send this email for invoices created via the admin page.
460
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
-				$invoice       = new WPInv_Invoice( $invoice );
462
-				$email->object = $invoice;
459
+            // Only send this email for invoices created via the admin page.
460
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
461
+                $invoice       = new WPInv_Invoice( $invoice );
462
+                $email->object = $invoice;
463 463
 
464
-				if ( $invoice->needs_payment() ) {
465
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
-				}
464
+                if ( $invoice->needs_payment() ) {
465
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
466
+                }
467 467
 
468
-			}
468
+            }
469 469
 
470
-		}
470
+        }
471 471
 
472
-	}
472
+    }
473 473
 
474
-	/**
475
-	 * Calculates the date query for an invoices query
476
-	 *
477
-	 * @param array $reminder_days
478
-	 * @return string
479
-	 */
480
-	public function get_date_query( $reminder_days ) {
474
+    /**
475
+     * Calculates the date query for an invoices query
476
+     *
477
+     * @param array $reminder_days
478
+     * @return string
479
+     */
480
+    public function get_date_query( $reminder_days ) {
481 481
 
482
-		$date_query = array(
483
-			'relation'  => 'OR'
484
-		);
482
+        $date_query = array(
483
+            'relation'  => 'OR'
484
+        );
485 485
 
486
-		foreach ( $reminder_days as $days ) {
487
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
486
+        foreach ( $reminder_days as $days ) {
487
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
488 488
 
489
-			$date_query[] = array(
490
-				'year'  => $date['year'],
491
-				'month' => $date['month'],
492
-				'day'   => $date['day'],
493
-			);
489
+            $date_query[] = array(
490
+                'year'  => $date['year'],
491
+                'month' => $date['month'],
492
+                'day'   => $date['day'],
493
+            );
494 494
 
495
-		}
495
+        }
496 496
 
497
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
497
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
498 498
 
499
-		return $date_query->get_sql();
499
+        return $date_query->get_sql();
500 500
 
501
-	}
501
+    }
502 502
 
503 503
 }
Please login to merge, or discard this patch.
templates/payment-forms/cart-item.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -24,64 +24,64 @@  discard block
 block discarded – undo
24 24
 
25 25
 				<?php
26 26
 
27
-					// Fires before printing a line item column.
28
-					do_action( "getpaid_form_cart_item_before_$key", $item, $form );
27
+                    // Fires before printing a line item column.
28
+                    do_action( "getpaid_form_cart_item_before_$key", $item, $form );
29 29
 
30
-					// Item name.
31
-					if ( 'name' == $key ) {
30
+                    // Item name.
31
+                    if ( 'name' == $key ) {
32 32
 
33
-						// Display the name.
34
-						echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
33
+                        // Display the name.
34
+                        echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>';
35 35
 
36
-						// And an optional description.
36
+                        // And an optional description.
37 37
                         $description = $item->get_description();
38 38
 
39 39
                         if ( ! empty( $description ) ) {
40 40
                             $description = wp_kses_post( $description );
41 41
                             echo "<small class='form-text text-muted pr-2 m-0'>$description</small>";
42
-						}
42
+                        }
43 43
 
44
-						// Price help text.
44
+                        // Price help text.
45 45
                         $description = getpaid_item_recurring_price_help_text( $item, $currency );
46 46
                         if ( $description ) {
47 47
                             echo "<small class='getpaid-form-item-price-desc form-text text-muted pr-2 m-0'>$description</small>";
48
-						}
48
+                        }
49 49
 
50
-					}
50
+                    }
51 51
 
52
-					// Item price.
53
-					if ( 'price' == $key ) {
52
+                    // Item price.
53
+                    if ( 'price' == $key ) {
54 54
 
55
-						// Set the currency position.
56
-						$position = wpinv_currency_position();
55
+                        // Set the currency position.
56
+                        $position = wpinv_currency_position();
57 57
 
58
-						if ( $position == 'left_space' ) {
59
-							$position = 'left';
60
-						}
58
+                        if ( $position == 'left_space' ) {
59
+                            $position = 'left';
60
+                        }
61 61
 
62
-						if ( $position == 'right_space' ) {
63
-							$position = 'right';
64
-						}
62
+                        if ( $position == 'right_space' ) {
63
+                            $position = 'right';
64
+                        }
65 65
 
66
-						if ( $item->user_can_set_their_price() ) {
67
-							$price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
-							$minimum          = (float) $item->get_minimum_price();
69
-							$validate_minimum = '';
70
-							$class            = '';
71
-							$data_minimum     = '';
66
+                        if ( $item->user_can_set_their_price() ) {
67
+                            $price            = max( (float) $item->get_price(), (float) $item->get_minimum_price() );
68
+                            $minimum          = (float) $item->get_minimum_price();
69
+                            $validate_minimum = '';
70
+                            $class            = '';
71
+                            $data_minimum     = '';
72 72
 
73
-							if ( $minimum > 0 ) {
74
-								$validate_minimum = sprintf(
75
-									esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
-									sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
-								);
73
+                            if ( $minimum > 0 ) {
74
+                                $validate_minimum = sprintf(
75
+                                    esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ),
76
+                                    sanitize_text_field( wpinv_price( $minimum, $currency ) )
77
+                                );
78 78
 
79
-								$class = 'getpaid-validate-minimum-amount';
79
+                                $class = 'getpaid-validate-minimum-amount';
80 80
 
81
-								$data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
82
-							}
81
+                                $data_minimum     = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'";
82
+                            }
83 83
 
84
-							?>
84
+                            ?>
85 85
 								<div class="input-group input-group-sm">
86 86
 									<?php if( 'left' == $position ) : ?>
87 87
 										<div class="input-group-prepend">
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
 								</div>
106 106
 
107 107
 							<?php
108
-						} else {
109
-							echo wpinv_price( $item->get_price(), $currency );
110
-							?>
108
+                        } else {
109
+                            echo wpinv_price( $item->get_price(), $currency );
110
+                            ?>
111 111
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'>
112 112
 							<?php
113
-						}
114
-					}
113
+                        }
114
+                    }
115 115
 
116
-					// Item quantity.
117
-					if ( 'quantity' == $key ) {
116
+                    // Item quantity.
117
+                    if ( 'quantity' == $key ) {
118 118
 
119
-						if ( $item->allows_quantities() ) {
120
-							?>
119
+                        if ( $item->allows_quantities() ) {
120
+                            ?>
121 121
 								<input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type='text' style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity(); ?>' min='1' required>
122 122
 							<?php
123
-						} else {
124
-							echo (float) $item->get_quantity();
125
-							echo '&nbsp;&nbsp;&nbsp;';
126
-							?>
123
+                        } else {
124
+                            echo (float) $item->get_quantity();
125
+                            echo '&nbsp;&nbsp;&nbsp;';
126
+                            ?>
127 127
 								<input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'>
128 128
 							<?php
129
-						}
130
-					}
129
+                        }
130
+                    }
131 131
 
132
-					// Item sub total.
133
-					if ( 'subtotal' == $key ) {
134
-						echo wpinv_price( $item->get_sub_total(), $currency );
135
-					}
132
+                    // Item sub total.
133
+                    if ( 'subtotal' == $key ) {
134
+                        echo wpinv_price( $item->get_sub_total(), $currency );
135
+                    }
136 136
 
137
-					do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
-				?>
137
+                    do_action( "getpaid_payment_form_cart_item_$key", $item, $form );
138
+                ?>
139 139
 
140 140
 			</div>
141 141
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Item_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the item.
@@ -270,35 +270,35 @@  discard block
 block discarded – undo
270 270
     }
271 271
 
272 272
     /**
273
-	 * Save meta box data.
274
-	 *
275
-	 * @param int $post_id
276
-	 */
277
-	public static function save( $post_id ) {
273
+     * Save meta box data.
274
+     *
275
+     * @param int $post_id
276
+     */
277
+    public static function save( $post_id ) {
278 278
 
279 279
         // Prepare the item.
280 280
         $item = new WPInv_Item( $post_id );
281 281
 
282 282
         // Load new data.
283 283
         $item->set_props(
284
-			array(
285
-				'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
-				'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
-				'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
-				'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
-				'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
284
+            array(
285
+                'price'                => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null,
286
+                'vat_rule'             => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null,
287
+                'vat_class'            => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null,
288
+                'type'                 => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null,
289
+                'is_dynamic_pricing'   => isset( $_POST['wpinv_name_your_price'] ),
290 290
                 'minimum_price'        => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null,
291
-				'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
292
-				'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
-				'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
-				'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
-				'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
-				'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
-				'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
-			)
291
+                'is_recurring'         => isset( $_POST['wpinv_is_recurring'] ),
292
+                'recurring_period'     => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null,
293
+                'recurring_interval'   => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1,
294
+                'recurring_limit'      => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null,
295
+                'is_free_trial'        => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null,
296
+                'trial_period'         => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null,
297
+                'trial_interval'       => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null,
298
+            )
299 299
         );
300 300
 
301
-		$item->save();
302
-		do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
-	}
301
+        $item->save();
302
+        do_action( 'getpaid_item_metabox_save', $post_id, $item );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,80 +12,80 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // For default forms, ensure that an item has been set.
38
+        if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
40
+            $payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
+        }
42
+
43
+        // Process each individual item.
44
+        foreach ( $payment_form->get_items() as $item ) {
45
+            $this->process_item( $item, $selected_items, $submission );
46
+        }
47
+
48
+    }
20 49
 
21 50
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// For default forms, ensure that an item has been set.
38
-		if ( $payment_form->is_default() && ( ! $submission->has_invoice() || 'payment_form' == $submission->get_invoice()->get_created_via() ) && isset( $data['getpaid-form-items'] ) ) {
39
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
40
-			$payment_form->set_items( getpaid_convert_items_to_array( $form_items ) );
41
-		}
42
-
43
-		// Process each individual item.
44
-		foreach ( $payment_form->get_items() as $item ) {
45
-			$this->process_item( $item, $selected_items, $submission );
46
-		}
47
-
48
-	}
49
-
50
-	/**
51
-	 * Process a single item.
52
-	 *
53
-	 * @param GetPaid_Form_Item $item
54
-	 * @param array $selected_items
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function process_item( $item, $selected_items, $submission ) {
58
-
59
-		// Abort if this is an optional item and it has not been selected.
60
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
-			return;
62
-		}
63
-
64
-		// (maybe) let customers change the quantities and prices.
65
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
-
67
-			// Maybe change the quantities.
68
-			if ( $item->allows_quantities() ) {
69
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
-			}
71
-
72
-			// Maybe change the price.
73
-			if ( $item->user_can_set_their_price() ) {
74
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
-
76
-				if ( $item->get_minimum_price() > $price ) {
77
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
78
-				}
79
-
80
-				$item->set_price( $price );
81
-
82
-			}
83
-
84
-		}
85
-
86
-		// Save the item.
87
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
-
89
-	}
51
+     * Process a single item.
52
+     *
53
+     * @param GetPaid_Form_Item $item
54
+     * @param array $selected_items
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function process_item( $item, $selected_items, $submission ) {
58
+
59
+        // Abort if this is an optional item and it has not been selected.
60
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
61
+            return;
62
+        }
63
+
64
+        // (maybe) let customers change the quantities and prices.
65
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
66
+
67
+            // Maybe change the quantities.
68
+            if ( $item->allows_quantities() ) {
69
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
70
+            }
71
+
72
+            // Maybe change the price.
73
+            if ( $item->user_can_set_their_price() ) {
74
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
75
+
76
+                if ( $item->get_minimum_price() > $price ) {
77
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
78
+                }
79
+
80
+                $item->set_price( $price );
81
+
82
+            }
83
+
84
+        }
85
+
86
+        // Save the item.
87
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
88
+
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-fees.php 1 patch
Indentation   +107 added lines, -107 removed lines patch added patch discarded remove patch
@@ -12,114 +12,114 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Fees {
14 14
 
15
-	/**
16
-	 * The fee validation error.
17
-	 * @var string
18
-	 */
19
-	public $fee_error;
20
-
21
-	/**
22
-	 * Submission fees.
23
-	 * @var array
24
-	 */
25
-	public $fees = array();
15
+    /**
16
+     * The fee validation error.
17
+     * @var string
18
+     */
19
+    public $fee_error;
20
+
21
+    /**
22
+     * Submission fees.
23
+     * @var array
24
+     */
25
+    public $fees = array();
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Process any existing invoice fees.
35
+        if ( $submission->has_invoice() ) {
36
+            $this->fees = $submission->get_invoice()->get_fees();
37
+        }
38
+
39
+        // Process price fields.
40
+        $data         = $submission->get_data();
41
+        $payment_form = $submission->get_payment_form();
42
+
43
+        foreach ( $payment_form->get_elements() as $element ) {
44
+
45
+            if ( 'price_input' == $element['type'] ) {
46
+                $this->process_price_input( $element, $data, $submission );
47
+            }
48
+
49
+            if ( 'price_select' == $element['type'] ) {
50
+                $this->process_price_select( $element, $data );
51
+            }
52
+
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Process a price input field.
59
+     *
60
+     * @param array $element
61
+     * @param array $data
62
+     * @param GetPaid_Payment_Form_Submission $submission
63
+     */
64
+    public function process_price_input( $element, $data, $submission ) {
65
+
66
+        // Abort if not passed.
67
+        if ( empty( $data[ $element['id'] ] ) ) {
68
+            return;
69
+        }
70
+
71
+        $amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
72
+        $minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
73
+
74
+        if ( $amount < $minimum ) {
75
+            throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) );
76
+        }
77
+
78
+        $this->fees[ $element['label'] ] = array(
79
+            'name'          => $element['label'],
80
+            'initial_fee'   => $amount,
81
+            'recurring_fee' => 0,
82
+        );
83
+
84
+    }
26 85
 
27 86
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Process any existing invoice fees.
35
-		if ( $submission->has_invoice() ) {
36
-			$this->fees = $submission->get_invoice()->get_fees();
37
-		}
38
-
39
-		// Process price fields.
40
-		$data         = $submission->get_data();
41
-		$payment_form = $submission->get_payment_form();
42
-
43
-		foreach ( $payment_form->get_elements() as $element ) {
44
-
45
-			if ( 'price_input' == $element['type'] ) {
46
-				$this->process_price_input( $element, $data, $submission );
47
-			}
48
-
49
-			if ( 'price_select' == $element['type'] ) {
50
-				$this->process_price_select( $element, $data );
51
-			}
52
-
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Process a price input field.
59
-	 *
60
-	 * @param array $element
61
-	 * @param array $data
62
-	 * @param GetPaid_Payment_Form_Submission $submission
63
-	 */
64
-	public function process_price_input( $element, $data, $submission ) {
65
-
66
-		// Abort if not passed.
67
-		if ( empty( $data[ $element['id'] ] ) ) {
68
-			return;
69
-		}
70
-
71
-		$amount  = (float) wpinv_sanitize_amount( $data[ $element['id'] ] );
72
-		$minimum = empty( $element['minimum'] ) ? 0 : (float) wpinv_sanitize_amount( $element['minimum'] );
73
-
74
-		if ( $amount < $minimum ) {
75
-			throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $minimum, $submission->get_currency() ) ) );
76
-		}
77
-
78
-		$this->fees[ $element['label'] ] = array(
79
-			'name'          => $element['label'],
80
-			'initial_fee'   => $amount,
81
-			'recurring_fee' => 0,
82
-		);
83
-
84
-	}
85
-
86
-	/**
87
-	 * Process a price select field.
88
-	 *
89
-	 * @param array $element
90
-	 * @param array $data
91
-	 */
92
-	public function process_price_select( $element, $data ) {
93
-
94
-		// Abort if not passed.
95
-		if ( empty( $data[ $element['id'] ] ) ) {
96
-			return;
97
-		}
98
-
99
-		$options    = getpaid_convert_price_string_to_options( $element['options'] );
100
-		$selected   = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) );
101
-		$total      = 0;
102
-		$sub_labels = array();
103
-
104
-		foreach ( $selected as $price ) {
105
-
106
-			if ( ! isset( $options[ $price ] ) ) {
107
-				throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
108
-			}
109
-
110
-			$price = explode( '|', $price );
111
-
112
-			$sub_labels[] = $price[0];
113
-			$total += (float) wpinv_sanitize_amount( $price[1] );
114
-		}
115
-
116
-		$this->fees[ $element['label'] ] = array(
117
-			'name'          => $element['label'],
118
-			'initial_fee'   => $total,
119
-			'recurring_fee' => 0,
120
-			'description'   => implode( ', ', $sub_labels ),
121
-		);
122
-
123
-	}
87
+     * Process a price select field.
88
+     *
89
+     * @param array $element
90
+     * @param array $data
91
+     */
92
+    public function process_price_select( $element, $data ) {
93
+
94
+        // Abort if not passed.
95
+        if ( empty( $data[ $element['id'] ] ) ) {
96
+            return;
97
+        }
98
+
99
+        $options    = getpaid_convert_price_string_to_options( $element['options'] );
100
+        $selected   = array_filter( array_map( 'trim', explode( ',', $data[ $element['id'] ] ) ) );
101
+        $total      = 0;
102
+        $sub_labels = array();
103
+
104
+        foreach ( $selected as $price ) {
105
+
106
+            if ( ! isset( $options[ $price ] ) ) {
107
+                throw new Exception( __( 'You have selected an invalid amount', 'invoicing' ) );
108
+            }
109
+
110
+            $price = explode( '|', $price );
111
+
112
+            $sub_labels[] = $price[0];
113
+            $total += (float) wpinv_sanitize_amount( $price[1] );
114
+        }
115
+
116
+        $this->fees[ $element['label'] ] = array(
117
+            'name'          => $element['label'],
118
+            'initial_fee'   => $total,
119
+            'recurring_fee' => 0,
120
+            'description'   => implode( ', ', $sub_labels ),
121
+        );
122
+
123
+    }
124 124
 
125 125
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-admin-setup-wizard.php 1 patch
Indentation   +385 added lines, -385 removed lines patch added patch discarded remove patch
@@ -17,397 +17,397 @@
 block discarded – undo
17 17
  */
18 18
 class GetPaid_Admin_Setup_Wizard {
19 19
 
20
-	/**
21
-	 * @var string Current Step
22
-	 */
23
-	protected $step = '';
24
-
25
-	/**
26
-	 * @var string|false Previous Step
27
-	 */
28
-	protected $previous_step = '';
29
-
30
-	/**
31
-	 * @var string|false Next Step
32
-	 */
33
-	protected $next_step = '';
34
-
35
-	/**
36
-	 * @var array All available steps for the setup wizard
37
-	 */
38
-	protected $steps = array();
39
-
40
-	/**
41
-	 * Class constructor.
42
-	 *
43
-	 * @since 2.4.0
44
-	 */
45
-	public function __construct() {
46
-
47
-		if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
-			add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
-			add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
-		}
51
-
52
-	}
53
-
54
-	/**
55
-	 * Add admin menus/screens.
56
-	 *
57
-	 * @since 2.4.0
58
-	 */
59
-	public function add_menu() {
60
-		add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
-	}
62
-
63
-	/**
64
-	 * Sets up the setup wizard.
65
-	 *
66
-	 * @since 2.4.0
67
-	 */
68
-	public function setup_wizard() {
69
-
70
-		if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
-			$this->setup_globals();
72
-			$this->maybe_save_current_step();
73
-			$this->display_wizard();
74
-			exit;
75
-		}
76
-
77
-	}
78
-
79
-	/**
80
-	 * Sets up class variables.
81
-	 *
82
-	 * @since 2.4.0
83
-	 */
84
-	protected function setup_globals() {
85
-		$this->steps         = $this->get_setup_steps();
86
-		$this->step          = $this->get_current_step();
87
-		$this->previous_step = $this->get_previous_step();
88
-		$this->next_step     = $this->get_next_step();
89
-	}
90
-
91
-	/**
92
-	 * Saves the current step.
93
-	 *
94
-	 * @since 2.4.0
95
-	 */
96
-	protected function maybe_save_current_step() {
97
-		if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
-			call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
-		}
100
-	}
101
-
102
-	/**
103
-	 * Returns the setup steps.
104
-	 *
105
-	 * @since 2.4.0
106
-	 * @return array
107
-	 */
108
-	protected function get_setup_steps() {
109
-
110
-		$steps = array(
111
-
112
-			'introduction'     => array(
113
-				'name'    => __( 'Introduction', 'invoicing' ),
114
-				'view'    => array( $this, 'setup_introduction' ),
115
-				'handler' => '',
116
-			),
117
-
118
-			'business_details'             => array(
119
-				'name'    => __( "Business Details", 'invoicing' ),
120
-				'view'    => array( $this, 'setup_business' ),
121
-				'handler' => '',
122
-			),
123
-
124
-			'currency' => array(
125
-				'name'    => __( 'Currency', 'invoicing' ),
126
-				'view'    => array( $this, 'setup_currency' ),
127
-				'handler' => '',
128
-			),
129
-
130
-			'payments'        => array(
131
-				'name'    => __( 'Payment Gateways', 'invoicing' ),
132
-				'view'    => array( $this, 'setup_payments' ),
133
-				'handler' => array( $this, 'setup_payments_save' ),
134
-			),
135
-
136
-			'recommend'          => array(
137
-				'name'    => __( 'Recommend', 'invoicing' ),
138
-				'view'    => array( $this, 'setup_recommend' ),
139
-				'handler' => '',
140
-			),
141
-
142
-			'next_steps'       => array(
143
-				'name'    => __( 'Get Paid', 'invoicing' ),
144
-				'view'    => array( $this, 'setup_ready' ),
145
-				'handler' => '',
146
-			),
147
-
148
-		);
149
-
150
-		return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
-
152
-	}
153
-
154
-	/**
155
-	 * Returns the current step.
156
-	 *
157
-	 * @since 2.4.0
158
-	 * @return string
159
-	 */
160
-	protected function get_current_step() {
161
-		$step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
-		return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
-	}
164
-
165
-	/**
166
-	 * Returns the previous step.
167
-	 *
168
-	 * @since 2.4.0
169
-	 * @return string|false
170
-	 */
171
-	protected function get_previous_step() {
172
-
173
-		$previous = false;
174
-		$current  = $this->step;
175
-		foreach ( array_keys( $this->steps ) as $step ) {
176
-			if ( $current === $step ) {
177
-				return $previous;
178
-			}
179
-
180
-			$previous = $step;
181
-		}
182
-
183
-		return false;
184
-	}
185
-
186
-	/**
187
-	 * Returns the next step.
188
-	 *
189
-	 * @since 2.4.0
190
-	 * @return string|false
191
-	 */
192
-	protected function get_next_step() {
193
-
194
-		$on_current = false;
195
-		$current    = $this->step;
196
-		foreach ( array_keys( $this->steps ) as $step ) {
197
-
198
-			if ( $on_current ) {
199
-				return $step;
200
-			}
201
-
202
-			if ( $current === $step ) {
203
-				return $on_current = true;
204
-			}
205
-
206
-		}
207
-
208
-		return false;
209
-	}
210
-
211
-	/**
212
-	 * Displays the setup wizard.
213
-	 *
214
-	 * @since 2.4.0
215
-	 */
216
-	public function display_wizard() {
217
-		$this->display_header();
218
-		$this->display_current_step();
219
-		$this->display_footer();
220
-	}
221
-
222
-	/**
223
-	 * Displays the Wizard Header.
224
-	 *
225
-	 * @since 2.0.0
226
-	 */
227
-	public function display_header() {
228
-		$steps     = $this->steps;
229
-		$current   = $this->step;
230
-		$next_step = $this->next_step;
231
-		array_shift( $steps );
232
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
-	}
234
-
235
-	/**
236
-	 * Displays the content for the current step.
237
-	 *
238
-	 * @since 2.4.0
239
-	 */
240
-	public function display_current_step() {
241
-		?>
20
+    /**
21
+     * @var string Current Step
22
+     */
23
+    protected $step = '';
24
+
25
+    /**
26
+     * @var string|false Previous Step
27
+     */
28
+    protected $previous_step = '';
29
+
30
+    /**
31
+     * @var string|false Next Step
32
+     */
33
+    protected $next_step = '';
34
+
35
+    /**
36
+     * @var array All available steps for the setup wizard
37
+     */
38
+    protected $steps = array();
39
+
40
+    /**
41
+     * Class constructor.
42
+     *
43
+     * @since 2.4.0
44
+     */
45
+    public function __construct() {
46
+
47
+        if ( apply_filters( 'getpaid_enable_setup_wizard', true ) && wpinv_current_user_can_manage_invoicing() ) {
48
+            add_action( 'admin_menu', array( $this, 'add_menu' ) );
49
+            add_action( 'current_screen', array( $this, 'setup_wizard' ) );
50
+        }
51
+
52
+    }
53
+
54
+    /**
55
+     * Add admin menus/screens.
56
+     *
57
+     * @since 2.4.0
58
+     */
59
+    public function add_menu() {
60
+        add_dashboard_page( '', '', wpinv_get_capability(), 'gp-setup', '' );
61
+    }
62
+
63
+    /**
64
+     * Sets up the setup wizard.
65
+     *
66
+     * @since 2.4.0
67
+     */
68
+    public function setup_wizard() {
69
+
70
+        if ( isset( $_GET['page'] ) && 'gp-setup' === $_GET['page'] ) {
71
+            $this->setup_globals();
72
+            $this->maybe_save_current_step();
73
+            $this->display_wizard();
74
+            exit;
75
+        }
76
+
77
+    }
78
+
79
+    /**
80
+     * Sets up class variables.
81
+     *
82
+     * @since 2.4.0
83
+     */
84
+    protected function setup_globals() {
85
+        $this->steps         = $this->get_setup_steps();
86
+        $this->step          = $this->get_current_step();
87
+        $this->previous_step = $this->get_previous_step();
88
+        $this->next_step     = $this->get_next_step();
89
+    }
90
+
91
+    /**
92
+     * Saves the current step.
93
+     *
94
+     * @since 2.4.0
95
+     */
96
+    protected function maybe_save_current_step() {
97
+        if ( ! empty( $_POST['save_step'] ) && is_callable( $this->steps[ $this->step ]['handler'] ) ) {
98
+            call_user_func( $this->steps[ $this->step ]['handler'], $this );
99
+        }
100
+    }
101
+
102
+    /**
103
+     * Returns the setup steps.
104
+     *
105
+     * @since 2.4.0
106
+     * @return array
107
+     */
108
+    protected function get_setup_steps() {
109
+
110
+        $steps = array(
111
+
112
+            'introduction'     => array(
113
+                'name'    => __( 'Introduction', 'invoicing' ),
114
+                'view'    => array( $this, 'setup_introduction' ),
115
+                'handler' => '',
116
+            ),
117
+
118
+            'business_details'             => array(
119
+                'name'    => __( "Business Details", 'invoicing' ),
120
+                'view'    => array( $this, 'setup_business' ),
121
+                'handler' => '',
122
+            ),
123
+
124
+            'currency' => array(
125
+                'name'    => __( 'Currency', 'invoicing' ),
126
+                'view'    => array( $this, 'setup_currency' ),
127
+                'handler' => '',
128
+            ),
129
+
130
+            'payments'        => array(
131
+                'name'    => __( 'Payment Gateways', 'invoicing' ),
132
+                'view'    => array( $this, 'setup_payments' ),
133
+                'handler' => array( $this, 'setup_payments_save' ),
134
+            ),
135
+
136
+            'recommend'          => array(
137
+                'name'    => __( 'Recommend', 'invoicing' ),
138
+                'view'    => array( $this, 'setup_recommend' ),
139
+                'handler' => '',
140
+            ),
141
+
142
+            'next_steps'       => array(
143
+                'name'    => __( 'Get Paid', 'invoicing' ),
144
+                'view'    => array( $this, 'setup_ready' ),
145
+                'handler' => '',
146
+            ),
147
+
148
+        );
149
+
150
+        return apply_filters( 'getpaid_setup_wizard_steps', $steps );
151
+
152
+    }
153
+
154
+    /**
155
+     * Returns the current step.
156
+     *
157
+     * @since 2.4.0
158
+     * @return string
159
+     */
160
+    protected function get_current_step() {
161
+        $step = isset( $_GET['step'] ) ? sanitize_key( $_GET['step'] ) : '';
162
+        return ! empty( $step ) && in_array( $step, array_keys( $this->steps ) ) ? $step : current( array_keys( $this->steps ) );
163
+    }
164
+
165
+    /**
166
+     * Returns the previous step.
167
+     *
168
+     * @since 2.4.0
169
+     * @return string|false
170
+     */
171
+    protected function get_previous_step() {
172
+
173
+        $previous = false;
174
+        $current  = $this->step;
175
+        foreach ( array_keys( $this->steps ) as $step ) {
176
+            if ( $current === $step ) {
177
+                return $previous;
178
+            }
179
+
180
+            $previous = $step;
181
+        }
182
+
183
+        return false;
184
+    }
185
+
186
+    /**
187
+     * Returns the next step.
188
+     *
189
+     * @since 2.4.0
190
+     * @return string|false
191
+     */
192
+    protected function get_next_step() {
193
+
194
+        $on_current = false;
195
+        $current    = $this->step;
196
+        foreach ( array_keys( $this->steps ) as $step ) {
197
+
198
+            if ( $on_current ) {
199
+                return $step;
200
+            }
201
+
202
+            if ( $current === $step ) {
203
+                return $on_current = true;
204
+            }
205
+
206
+        }
207
+
208
+        return false;
209
+    }
210
+
211
+    /**
212
+     * Displays the setup wizard.
213
+     *
214
+     * @since 2.4.0
215
+     */
216
+    public function display_wizard() {
217
+        $this->display_header();
218
+        $this->display_current_step();
219
+        $this->display_footer();
220
+    }
221
+
222
+    /**
223
+     * Displays the Wizard Header.
224
+     *
225
+     * @since 2.0.0
226
+     */
227
+    public function display_header() {
228
+        $steps     = $this->steps;
229
+        $current   = $this->step;
230
+        $next_step = $this->next_step;
231
+        array_shift( $steps );
232
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-header.php';
233
+    }
234
+
235
+    /**
236
+     * Displays the content for the current step.
237
+     *
238
+     * @since 2.4.0
239
+     */
240
+    public function display_current_step() {
241
+        ?>
242 242
 			<div class="gp-setup-content rowx mw-100 text-center mb-3">
243 243
 				<div class="col-12 col-md-5 m-auto">
244 244
 					<?php call_user_func( $this->steps[ $this->step ]['view'], $this ); ?>
245 245
 				</div>
246 246
 			</div>
247 247
 		<?php
248
-	}
249
-
250
-	/**
251
-	 * Setup Wizard Footer.
252
-	 *
253
-	 * @since 2.4.0
254
-	 */
255
-	public function display_footer() {
256
-
257
-		if ( isset( $_GET['step'] ) ) {
258
-			$next_url = esc_url( $this->get_next_step_link() );
259
-			$label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
-
261
-			echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
-		}
263
-
264
-		echo '</body></html>';
265
-	}
266
-
267
-	/**
268
-	 * Introduction step.
269
-	 *
270
-	 * @since 2.0.0
271
-	 */
272
-	public function setup_introduction() {
273
-		$next_url = $this->get_next_step_link();
274
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
-	}
276
-
277
-	/**
278
-	 * Get the URL for the next step's screen.
279
-	 *
280
-	 * @param string step   slug (default: current step)
281
-	 *
282
-	 * @return string       URL for next step if a next step exists.
283
-	 *                      Admin URL if it's the last step.
284
-	 *                      Empty string on failure.
285
-	 * @since 3.0.0
286
-	 */
287
-	public function get_next_step_link( $step = '' ) {
288
-		if ( ! $step ) {
289
-			$step = $this->step;
290
-		}
291
-
292
-		$keys = array_keys( $this->steps );
293
-		if ( end( $keys ) === $step ) {
294
-			return admin_url();
295
-		}
296
-
297
-		$step_index = array_search( $step, $keys );
298
-		if ( false === $step_index ) {
299
-			return '';
300
-		}
301
-
302
-		return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
-	}
304
-
305
-	/**
306
-	 * Setup maps api.
307
-	 *
308
-	 * @since 2.0.0
309
-	 */
310
-	public function setup_business() {
311
-		$next_url = $this->get_next_step_link();
312
-		$wizard   = $this;
313
-		$page     = 'wpinv_settings_general_main';
314
-		$section  = 'wpinv_settings_general_main';
315
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
-	}
317
-
318
-	/**
319
-	 * Default Location settings.
320
-	 *
321
-	 * @since 2.0.0
322
-	 */
323
-	public function setup_currency() {
324
-		$next_url = $this->get_next_step_link();
325
-		$wizard   = $this;
326
-		$page     = 'wpinv_settings_general_currency_section';
327
-		$section  = 'wpinv_settings_general_currency_section';
328
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
-	}
330
-
331
-	/**
332
-	 * Installation of recommended plugins.
333
-	 *
334
-	 * @since 1.0.0
335
-	 */
336
-	public function setup_recommend() {
337
-		$next_url            = $this->get_next_step_link();
338
-		$recommended_plugins = self::get_recommend_wp_plugins();
339
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
-	}
341
-
342
-	/**
343
-	 * A list of recommended wp.org plugins.
344
-	 * @return array
345
-	 */
346
-	public static function get_recommend_wp_plugins(){
347
-		return array(
348
-			'ayecode-connect' => array(
349
-				'file'   => 'ayecode-connect/ayecode-connect.php',
350
-				'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
-				'slug'   => 'ayecode-connect',
352
-				'name'   => 'AyeCode Connect',
353
-				'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
-			),
355
-			'invoicing-quotes' => array(
356
-				'file'   => 'invoicing-quotes/wpinv-quote.php',
357
-				'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
-				'slug'   => 'invoicing-quotes',
359
-				'name'   => 'Customer Quotes',
360
-				'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
-			),
362
-			'userswp'    => array(
363
-				'file'   => 'userswp/userswp.php',
364
-				'url'    => 'https://wordpress.org/plugins/userswp/',
365
-				'slug'   => 'userswp',
366
-				'name'   => 'UsersWP',
367
-				'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
-			),
369
-		);
370
-	}
371
-
372
-	/**
373
-	 * Dummy Data setup.
374
-	 *
375
-	 * @since 2.4.0
376
-	 */
377
-	public function setup_payments() {
378
-		$next_url = $this->get_next_step_link();
379
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
-	}
381
-
382
-	/**
383
-	 * Dummy data save.
384
-	 *
385
-	 * This is done via ajax so we just pass onto the next step.
386
-	 *
387
-	 * @since 2.0.0
388
-	 */
389
-	public function setup_payments_save() {
390
-		check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
-		wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
-
393
-		if ( ! empty( $_POST['paypal-email'] ) ) {
394
-			wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
395
-			wpinv_update_option( 'paypal_active', 1 );
396
-			wpinv_update_option( 'paypal_sandbox', 0 );
397
-		}
398
-
399
-		wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
400
-		exit;
401
-	}
402
-
403
-	/**
404
-	 * Final step.
405
-	 *
406
-	 * @since 2.0.0
407
-	 */
408
-	public function setup_ready() {
409
-		include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
410
-	}
248
+    }
249
+
250
+    /**
251
+     * Setup Wizard Footer.
252
+     *
253
+     * @since 2.4.0
254
+     */
255
+    public function display_footer() {
256
+
257
+        if ( isset( $_GET['step'] ) ) {
258
+            $next_url = esc_url( $this->get_next_step_link() );
259
+            $label    = $this->step == 'next_steps' ? __( 'Return to the WordPress Dashboard', 'invoicing' ) : __( 'Skip this step', 'invoicing' );
260
+
261
+            echo '<p class="gd-return-to-dashboard-wrap"> <a href="' . $next_url . '" class="gd-return-to-dashboard btn btn-link d-block text-muted">' . $label . '</a></p>';
262
+        }
263
+
264
+        echo '</body></html>';
265
+    }
266
+
267
+    /**
268
+     * Introduction step.
269
+     *
270
+     * @since 2.0.0
271
+     */
272
+    public function setup_introduction() {
273
+        $next_url = $this->get_next_step_link();
274
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-introduction.php';
275
+    }
276
+
277
+    /**
278
+     * Get the URL for the next step's screen.
279
+     *
280
+     * @param string step   slug (default: current step)
281
+     *
282
+     * @return string       URL for next step if a next step exists.
283
+     *                      Admin URL if it's the last step.
284
+     *                      Empty string on failure.
285
+     * @since 3.0.0
286
+     */
287
+    public function get_next_step_link( $step = '' ) {
288
+        if ( ! $step ) {
289
+            $step = $this->step;
290
+        }
291
+
292
+        $keys = array_keys( $this->steps );
293
+        if ( end( $keys ) === $step ) {
294
+            return admin_url();
295
+        }
296
+
297
+        $step_index = array_search( $step, $keys );
298
+        if ( false === $step_index ) {
299
+            return '';
300
+        }
301
+
302
+        return remove_query_arg('settings-updated', add_query_arg( 'step', $keys[ $step_index + 1 ] ));
303
+    }
304
+
305
+    /**
306
+     * Setup maps api.
307
+     *
308
+     * @since 2.0.0
309
+     */
310
+    public function setup_business() {
311
+        $next_url = $this->get_next_step_link();
312
+        $wizard   = $this;
313
+        $page     = 'wpinv_settings_general_main';
314
+        $section  = 'wpinv_settings_general_main';
315
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
316
+    }
317
+
318
+    /**
319
+     * Default Location settings.
320
+     *
321
+     * @since 2.0.0
322
+     */
323
+    public function setup_currency() {
324
+        $next_url = $this->get_next_step_link();
325
+        $wizard   = $this;
326
+        $page     = 'wpinv_settings_general_currency_section';
327
+        $section  = 'wpinv_settings_general_currency_section';
328
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-settings.php';
329
+    }
330
+
331
+    /**
332
+     * Installation of recommended plugins.
333
+     *
334
+     * @since 1.0.0
335
+     */
336
+    public function setup_recommend() {
337
+        $next_url            = $this->get_next_step_link();
338
+        $recommended_plugins = self::get_recommend_wp_plugins();
339
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-plugins.php';
340
+    }
341
+
342
+    /**
343
+     * A list of recommended wp.org plugins.
344
+     * @return array
345
+     */
346
+    public static function get_recommend_wp_plugins(){
347
+        return array(
348
+            'ayecode-connect' => array(
349
+                'file'   => 'ayecode-connect/ayecode-connect.php',
350
+                'url'    => 'https://wordpress.org/plugins/ayecode-connect/',
351
+                'slug'   => 'ayecode-connect',
352
+                'name'   => 'AyeCode Connect',
353
+                'desc'   => __( 'Documentation and Support from within your WordPress admin.', 'geodirectory' ),
354
+            ),
355
+            'invoicing-quotes' => array(
356
+                'file'   => 'invoicing-quotes/wpinv-quote.php',
357
+                'url'    => 'https://wordpress.org/plugins/invoicing-quotes/',
358
+                'slug'   => 'invoicing-quotes',
359
+                'name'   => 'Customer Quotes',
360
+                'desc'   => __('Create & Send Quotes to Customers and have them accept and pay.','geodirectory'),
361
+            ),
362
+            'userswp'    => array(
363
+                'file'   => 'userswp/userswp.php',
364
+                'url'    => 'https://wordpress.org/plugins/userswp/',
365
+                'slug'   => 'userswp',
366
+                'name'   => 'UsersWP',
367
+                'desc'   => __('Frontend user login and registration as well as slick profile pages.','geodirectory'),
368
+            ),
369
+        );
370
+    }
371
+
372
+    /**
373
+     * Dummy Data setup.
374
+     *
375
+     * @since 2.4.0
376
+     */
377
+    public function setup_payments() {
378
+        $next_url = $this->get_next_step_link();
379
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-gateways.php';
380
+    }
381
+
382
+    /**
383
+     * Dummy data save.
384
+     *
385
+     * This is done via ajax so we just pass onto the next step.
386
+     *
387
+     * @since 2.0.0
388
+     */
389
+    public function setup_payments_save() {
390
+        check_admin_referer( 'getpaid-setup-wizard', 'getpaid-setup-wizard' );
391
+        wpinv_update_option( 'manual_active', ! empty( $_POST['enable-manual-gateway'] ) );
392
+
393
+        if ( ! empty( $_POST['paypal-email'] ) ) {
394
+            wpinv_update_option( 'paypal_email', sanitize_email( $_POST['paypal-email'] ) );
395
+            wpinv_update_option( 'paypal_active', 1 );
396
+            wpinv_update_option( 'paypal_sandbox', 0 );
397
+        }
398
+
399
+        wp_redirect( esc_url_raw( $this->get_next_step_link() ) );
400
+        exit;
401
+    }
402
+
403
+    /**
404
+     * Final step.
405
+     *
406
+     * @since 2.0.0
407
+     */
408
+    public function setup_ready() {
409
+        include plugin_dir_path( __FILE__ ) . 'views/wizard-thank-you.php';
410
+    }
411 411
 
412 412
 }
413 413
 
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -195,13 +195,13 @@  discard block
 block discarded – undo
195 195
     $name       = isset( $option['name'] ) ? $option['name'] : '';
196 196
     $cb         = "wpinv_{$option['type']}_callback";
197 197
     $section    = "wpinv_settings_{$tab}_$section";
198
-	$is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
198
+    $is_wizzard = is_admin() && isset( $_GET['page'] ) && 'gp-setup' == $_GET['page'];
199 199
 
200
-	if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
201
-		$tip   = wpinv_clean( $option['desc'] );
202
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
203
-		unset( $option['desc'] );
204
-	}
200
+    if ( isset( $option['desc'] ) && ( ! $is_wizzard && ! empty( $option['help-tip'] ) ) ) {
201
+        $tip   = wpinv_clean( $option['desc'] );
202
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
203
+        unset( $option['desc'] );
204
+    }
205 205
 
206 206
     // Loop through all tabs.
207 207
     add_settings_field(
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
             'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
229 229
             'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
230 230
             'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
231
-			'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
232
-			'class'       => isset( $option['class'] )     ? $option['class']         : '',
233
-			'style'       => isset( $option['style'] )     ? $option['style']         : '',
231
+            'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
232
+            'class'       => isset( $option['class'] )     ? $option['class']         : '',
233
+            'style'       => isset( $option['style'] )     ? $option['style']         : '',
234 234
             'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
235 235
             'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
236 236
         )
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
  * @return array
245 245
  */
246 246
 function wpinv_get_registered_settings() {
247
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
247
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
248 248
 }
249 249
 
250 250
 /**
@@ -263,18 +263,18 @@  discard block
 block discarded – undo
263 263
  */
264 264
 function wpinv_settings_sanitize( $input = array() ) {
265 265
 
266
-	$wpinv_options = wpinv_get_options();
267
-	$raw_referrer  = wp_get_raw_referer();
266
+    $wpinv_options = wpinv_get_options();
267
+    $raw_referrer  = wp_get_raw_referer();
268 268
 
269 269
     if ( empty( $raw_referrer ) ) {
270
-		return array_merge( $wpinv_options, $input );
270
+        return array_merge( $wpinv_options, $input );
271 271
     }
272 272
 
273 273
     wp_parse_str( $raw_referrer, $referrer );
274 274
 
275
-	if ( in_array( 'gp-setup', $referrer ) ) {
276
-		return array_merge( $wpinv_options, $input );
277
-	}
275
+    if ( in_array( 'gp-setup', $referrer ) ) {
276
+        return array_merge( $wpinv_options, $input );
277
+    }
278 278
 
279 279
     $settings = wpinv_get_registered_settings();
280 280
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
         }
297 297
 
298 298
         // General filter
299
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
299
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
300 300
 
301
-		// Key specific filter.
302
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
301
+        // Key specific filter.
302
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
303 303
     }
304 304
 
305 305
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -342,14 +342,14 @@  discard block
 block discarded – undo
342 342
 
343 343
     foreach ( $new_rates as $rate ) {
344 344
 
345
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
346
-		$rate['name']    = sanitize_text_field( $rate['name'] );
347
-		$rate['state']   = sanitize_text_field( $rate['state'] );
348
-		$rate['country'] = sanitize_text_field( $rate['country'] );
349
-		$rate['global']  = empty( $rate['state'] );
350
-		$tax_rates[]     = $rate;
345
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
346
+        $rate['name']    = sanitize_text_field( $rate['name'] );
347
+        $rate['state']   = sanitize_text_field( $rate['state'] );
348
+        $rate['country'] = sanitize_text_field( $rate['country'] );
349
+        $rate['global']  = empty( $rate['state'] );
350
+        $tax_rates[]     = $rate;
351 351
 
352
-	}
352
+    }
353 353
 
354 354
     update_option( 'wpinv_tax_rates', $tax_rates );
355 355
 
@@ -362,11 +362,11 @@  discard block
 block discarded – undo
362 362
     $tabs['general']  = __( 'General', 'invoicing' );
363 363
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
364 364
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
365
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
365
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
366 366
 
367
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
368
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
369
-	}
367
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
368
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
369
+    }
370 370
 
371 371
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
372 372
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -405,14 +405,14 @@  discard block
 block discarded – undo
405 405
         ) ),
406 406
         'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
407 407
             'main'  => __( 'Tax Settings', 'invoicing' ),
408
-			'rates' => __( 'Tax Rates', 'invoicing' ),
409
-			'vat'   => __( 'EU VAT Settings', 'invoicing' )
408
+            'rates' => __( 'Tax Rates', 'invoicing' ),
409
+            'vat'   => __( 'EU VAT Settings', 'invoicing' )
410 410
         ) ),
411 411
         'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
412 412
             'main' => __( 'Email Settings', 'invoicing' ),
413
-		) ),
413
+        ) ),
414 414
 
415
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
415
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
416 416
 
417 417
         'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
418 418
             'main' => __( 'Privacy policy', 'invoicing' ),
@@ -432,48 +432,48 @@  discard block
 block discarded – undo
432 432
 }
433 433
 
434 434
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
435
-	$pages_options = array();
435
+    $pages_options = array();
436 436
 
437
-	if( $default_label !== NULL && $default_label !== false ) {
438
-		$pages_options = array( '' => $default_label ); // Blank option
439
-	}
437
+    if( $default_label !== NULL && $default_label !== false ) {
438
+        $pages_options = array( '' => $default_label ); // Blank option
439
+    }
440 440
 
441
-	$pages = get_pages();
442
-	if ( $pages ) {
443
-		foreach ( $pages as $page ) {
444
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
441
+    $pages = get_pages();
442
+    if ( $pages ) {
443
+        foreach ( $pages as $page ) {
444
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
445 445
             $pages_options[ $page->ID ] = $title;
446
-		}
447
-	}
446
+        }
447
+    }
448 448
 
449
-	return $pages_options;
449
+    return $pages_options;
450 450
 }
451 451
 
452 452
 function wpinv_header_callback( $args ) {
453
-	if ( !empty( $args['desc'] ) ) {
453
+    if ( !empty( $args['desc'] ) ) {
454 454
         echo $args['desc'];
455 455
     }
456 456
 }
457 457
 
458 458
 function wpinv_hidden_callback( $args ) {
459 459
 
460
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
461
-	$value   = wpinv_get_option( $args['id'], $std );
460
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
461
+    $value   = wpinv_get_option( $args['id'], $std );
462 462
 
463
-	if ( isset( $args['set_value'] ) ) {
464
-		$value = $args['set_value'];
465
-	}
463
+    if ( isset( $args['set_value'] ) ) {
464
+        $value = $args['set_value'];
465
+    }
466 466
 
467
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
468
-		$args['readonly'] = true;
469
-		$name  = '';
470
-	} else {
471
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
472
-	}
467
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
468
+        $args['readonly'] = true;
469
+        $name  = '';
470
+    } else {
471
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
472
+    }
473 473
 
474
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
474
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
475 475
     
476
-	echo $html;
476
+    echo $html;
477 477
 }
478 478
 
479 479
 /**
@@ -481,12 +481,12 @@  discard block
 block discarded – undo
481 481
  */
482 482
 function wpinv_checkbox_callback( $args ) {
483 483
 
484
-	$std = isset( $args['std'] ) ? $args['std'] : '';
485
-	$std = wpinv_get_option( $args['id'], $std );
486
-	$id  = esc_attr( $args['id'] );
484
+    $std = isset( $args['std'] ) ? $args['std'] : '';
485
+    $std = wpinv_get_option( $args['id'], $std );
486
+    $id  = esc_attr( $args['id'] );
487 487
 
488
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
489
-	?>
488
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
489
+    ?>
490 490
 		<fieldset>
491 491
 			<label>
492 492
 				<input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -498,75 +498,75 @@  discard block
 block discarded – undo
498 498
 
499 499
 function wpinv_multicheck_callback( $args ) {
500 500
 
501
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
502
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
501
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
502
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
503 503
 
504
-	if ( ! empty( $args['options'] ) ) {
504
+    if ( ! empty( $args['options'] ) ) {
505 505
 
506
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
507
-		$value   = wpinv_get_option( $args['id'], $std );
506
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
507
+        $value   = wpinv_get_option( $args['id'], $std );
508 508
 
509
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
509
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
510 510
         foreach( $args['options'] as $key => $option ):
511
-			$sanitize_key = wpinv_sanitize_key( $key );
512
-			if ( in_array( $sanitize_key, $value ) ) { 
513
-				$enabled = $sanitize_key;
514
-			} else { 
515
-				$enabled = NULL; 
516
-			}
517
-			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;';
518
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
519
-		endforeach;
520
-		echo '</div>';
521
-		echo '<p class="description">' . $args['desc'] . '</p>';
522
-	}
511
+            $sanitize_key = wpinv_sanitize_key( $key );
512
+            if ( in_array( $sanitize_key, $value ) ) { 
513
+                $enabled = $sanitize_key;
514
+            } else { 
515
+                $enabled = NULL; 
516
+            }
517
+            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;';
518
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
519
+        endforeach;
520
+        echo '</div>';
521
+        echo '<p class="description">' . $args['desc'] . '</p>';
522
+    }
523 523
 }
524 524
 
525 525
 function wpinv_payment_icons_callback( $args ) {
526 526
     
527 527
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
528
-	$value   = wpinv_get_option( $args['id'], false);
528
+    $value   = wpinv_get_option( $args['id'], false);
529 529
 
530
-	if ( ! empty( $args['options'] ) ) {
531
-		foreach( $args['options'] as $key => $option ) {
530
+    if ( ! empty( $args['options'] ) ) {
531
+        foreach( $args['options'] as $key => $option ) {
532 532
             $sanitize_key = wpinv_sanitize_key( $key );
533 533
             
534
-			if( empty( $value ) ) {
535
-				$enabled = $option;
536
-			} else {
537
-				$enabled = NULL;
538
-			}
539
-
540
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
541
-
542
-				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;';
543
-
544
-				if ( wpinv_string_is_image_url( $key ) ) {
545
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
546
-				} else {
547
-					$card = strtolower( str_replace( ' ', '', $option ) );
548
-
549
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
550
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
551
-					} else {
552
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
553
-						$content_dir = WP_CONTENT_DIR;
554
-
555
-						if ( function_exists( 'wp_normalize_path' ) ) {
556
-							// Replaces backslashes with forward slashes for Windows systems
557
-							$image = wp_normalize_path( $image );
558
-							$content_dir = wp_normalize_path( $content_dir );
559
-						}
560
-
561
-						$image = str_replace( $content_dir, content_url(), $image );
562
-					}
563
-
564
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
565
-				}
566
-			echo $option . '</label>';
567
-		}
568
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
569
-	}
534
+            if( empty( $value ) ) {
535
+                $enabled = $option;
536
+            } else {
537
+                $enabled = NULL;
538
+            }
539
+
540
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
541
+
542
+                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;';
543
+
544
+                if ( wpinv_string_is_image_url( $key ) ) {
545
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
546
+                } else {
547
+                    $card = strtolower( str_replace( ' ', '', $option ) );
548
+
549
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
550
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
551
+                    } else {
552
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
553
+                        $content_dir = WP_CONTENT_DIR;
554
+
555
+                        if ( function_exists( 'wp_normalize_path' ) ) {
556
+                            // Replaces backslashes with forward slashes for Windows systems
557
+                            $image = wp_normalize_path( $image );
558
+                            $content_dir = wp_normalize_path( $content_dir );
559
+                        }
560
+
561
+                        $image = str_replace( $content_dir, content_url(), $image );
562
+                    }
563
+
564
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
565
+                }
566
+            echo $option . '</label>';
567
+        }
568
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
569
+    }
570 570
 }
571 571
 
572 572
 /**
@@ -574,9 +574,9 @@  discard block
 block discarded – undo
574 574
  */
575 575
 function wpinv_radio_callback( $args ) {
576 576
 
577
-	$std = isset( $args['std'] ) ? $args['std'] : '';
578
-	$std = wpinv_get_option( $args['id'], $std );
579
-	?>
577
+    $std = isset( $args['std'] ) ? $args['std'] : '';
578
+    $std = wpinv_get_option( $args['id'], $std );
579
+    ?>
580 580
 		<fieldset>
581 581
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
582 582
 				<?php foreach( $args['options'] as $key => $option ) : ?>
@@ -590,7 +590,7 @@  discard block
 block discarded – undo
590 590
 			</ul>
591 591
 		</fieldset>
592 592
 	<?php
593
-	getpaid_settings_description_callback( $args );
593
+    getpaid_settings_description_callback( $args );
594 594
 }
595 595
 
596 596
 /**
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
  */
599 599
 function getpaid_settings_description_callback( $args ) {
600 600
 
601
-	if ( ! empty( $args['desc'] ) ) {
602
-		$description = wp_kses_post( $args['desc'] );
603
-		echo "<p class='description'>$description</p>";
604
-	}
601
+    if ( ! empty( $args['desc'] ) ) {
602
+        $description = wp_kses_post( $args['desc'] );
603
+        echo "<p class='description'>$description</p>";
604
+    }
605 605
 
606 606
 }
607 607
 
@@ -610,7 +610,7 @@  discard block
 block discarded – undo
610 610
  */
611 611
 function wpinv_gateways_callback() {
612 612
 
613
-	?>
613
+    ?>
614 614
 		</td>
615 615
 	</tr>
616 616
 	<tr class="bsui">
@@ -624,22 +624,22 @@  discard block
 block discarded – undo
624 624
     
625 625
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
626 626
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
627
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
628
-	$value   = wpinv_get_option( $args['id'], $std );
627
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
628
+    $value   = wpinv_get_option( $args['id'], $std );
629 629
 
630
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
630
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
631 631
 
632
-	foreach ( $args['options'] as $key => $option ) :
633
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
632
+    foreach ( $args['options'] as $key => $option ) :
633
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
634 634
             $selected = selected( $key, $args['selected'], false );
635 635
         } else {
636 636
             $selected = selected( $key, $value, false );
637 637
         }
638
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
639
-	endforeach;
638
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
639
+    endforeach;
640 640
 
641
-	echo '</select>';
642
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
641
+    echo '</select>';
642
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
643 643
 }
644 644
 
645 645
 /**
@@ -650,29 +650,29 @@  discard block
 block discarded – undo
650 650
  */
651 651
 function wpinv_settings_attrs_helper( $args ) {
652 652
 
653
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
654
-	$id           = esc_attr( $args['id'] );
655
-	$placeholder  = esc_attr( $args['placeholder'] );
653
+    $value        = isset( $args['std'] ) ? $args['std'] : '';
654
+    $id           = esc_attr( $args['id'] );
655
+    $placeholder  = esc_attr( $args['placeholder'] );
656 656
 
657
-	if ( ! empty( $args['faux'] ) ) {
658
-		$args['readonly'] = true;
659
-		$name             = '';
660
-	} else {
661
-		$value  = wpinv_get_option( $args['id'], $value );
662
-		$name   = "wpinv_settings[$id]";
663
-	}
657
+    if ( ! empty( $args['faux'] ) ) {
658
+        $args['readonly'] = true;
659
+        $name             = '';
660
+    } else {
661
+        $value  = wpinv_get_option( $args['id'], $value );
662
+        $name   = "wpinv_settings[$id]";
663
+    }
664 664
 
665
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
666
-	$class    = esc_attr( $args['class'] );
667
-	$style    = esc_attr( $args['style'] );
668
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
665
+    $value    = is_scalar( $value ) ? esc_attr( $value ) : '';
666
+    $class    = esc_attr( $args['class'] );
667
+    $style    = esc_attr( $args['style'] );
668
+    $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
669 669
 
670
-	$onchange = '';
670
+    $onchange = '';
671 671
     if ( ! empty( $args['onchange'] ) ) {
672 672
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
673
-	}
673
+    }
674 674
 
675
-	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
675
+    return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
676 676
 }
677 677
 
678 678
 /**
@@ -680,11 +680,11 @@  discard block
 block discarded – undo
680 680
  */
681 681
 function wpinv_text_callback( $args ) {
682 682
 
683
-	$desc = wp_kses_post( $args['desc'] );
684
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
685
-	$attr = wpinv_settings_attrs_helper( $args );
683
+    $desc = wp_kses_post( $args['desc'] );
684
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
685
+    $attr = wpinv_settings_attrs_helper( $args );
686 686
 
687
-	?>
687
+    ?>
688 688
 		<label style="width: 100%;">
689 689
 			<input type="text" <?php echo $attr; ?>>
690 690
 			<?php echo $desc; ?>
@@ -698,14 +698,14 @@  discard block
 block discarded – undo
698 698
  */
699 699
 function wpinv_number_callback( $args ) {
700 700
 
701
-	$desc = wp_kses_post( $args['desc'] );
702
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
703
-	$attr = wpinv_settings_attrs_helper( $args );
704
-	$max  = intval( $args['max'] );
705
-	$min  = intval( $args['min'] );
706
-	$step = floatval( $args['step'] );
701
+    $desc = wp_kses_post( $args['desc'] );
702
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
703
+    $attr = wpinv_settings_attrs_helper( $args );
704
+    $max  = intval( $args['max'] );
705
+    $min  = intval( $args['min'] );
706
+    $step = floatval( $args['step'] );
707 707
 
708
-	?>
708
+    ?>
709 709
 		<label style="width: 100%;">
710 710
 			<input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>>
711 711
 			<?php echo $desc; ?>
@@ -717,36 +717,36 @@  discard block
 block discarded – undo
717 717
 function wpinv_textarea_callback( $args ) {
718 718
     
719 719
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
720
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
721
-	$value   = wpinv_get_option( $args['id'], $std );
720
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
721
+    $value   = wpinv_get_option( $args['id'], $std );
722 722
 
723 723
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
724 724
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
725 725
 
726
-	$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>';
727
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
726
+    $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>';
727
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
728 728
 
729
-	echo $html;
729
+    echo $html;
730 730
 }
731 731
 
732 732
 function wpinv_password_callback( $args ) {
733 733
     
734 734
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
735
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
736
-	$value   = wpinv_get_option( $args['id'], $std );
735
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
736
+    $value   = wpinv_get_option( $args['id'], $std );
737 737
 
738
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
739
-	$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 ) . '"/>';
740
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
738
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
739
+    $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 ) . '"/>';
740
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
741 741
 
742
-	echo $html;
742
+    echo $html;
743 743
 }
744 744
 
745 745
 function wpinv_missing_callback($args) {
746
-	printf(
747
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
748
-		'<strong>' . $args['id'] . '</strong>'
749
-	);
746
+    printf(
747
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
748
+        '<strong>' . $args['id'] . '</strong>'
749
+    );
750 750
 }
751 751
 
752 752
 /**
@@ -754,14 +754,14 @@  discard block
 block discarded – undo
754 754
  */
755 755
 function wpinv_select_callback( $args ) {
756 756
 
757
-	$desc   = wp_kses_post( $args['desc'] );
758
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
759
-	$attr   = wpinv_settings_attrs_helper( $args );
760
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
761
-	$value  = wpinv_get_option( $args['id'], $value );
762
-	$rand   = uniqid( 'random_id' );
757
+    $desc   = wp_kses_post( $args['desc'] );
758
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
759
+    $attr   = wpinv_settings_attrs_helper( $args );
760
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
761
+    $value  = wpinv_get_option( $args['id'], $value );
762
+    $rand   = uniqid( 'random_id' );
763 763
 
764
-	?>
764
+    ?>
765 765
 		<label style="width: 100%;">
766 766
 			<select <?php echo $attr; ?>>
767 767
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -794,104 +794,104 @@  discard block
 block discarded – undo
794 794
 function wpinv_color_select_callback( $args ) {
795 795
     
796 796
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
797
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
798
-	$value   = wpinv_get_option( $args['id'], $std );
797
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
798
+    $value   = wpinv_get_option( $args['id'], $std );
799 799
 
800
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
800
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
801 801
 
802
-	foreach ( $args['options'] as $option => $color ) {
803
-		$selected = selected( $option, $value, false );
804
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
805
-	}
802
+    foreach ( $args['options'] as $option => $color ) {
803
+        $selected = selected( $option, $value, false );
804
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
805
+    }
806 806
 
807
-	$html .= '</select>';
808
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
807
+    $html .= '</select>';
808
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
809 809
 
810
-	echo $html;
810
+    echo $html;
811 811
 }
812 812
 
813 813
 function wpinv_rich_editor_callback( $args ) {
814
-	global $wp_version;
814
+    global $wp_version;
815 815
     
816 816
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
817 817
 
818
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
819
-	$value   = wpinv_get_option( $args['id'], $std );
818
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
819
+    $value   = wpinv_get_option( $args['id'], $std );
820 820
 	
821
-	if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
822
-		$value = $std;
823
-	}
821
+    if ( ! empty( $args['allow_blank'] ) && empty( $value ) ) {
822
+        $value = $std;
823
+    }
824 824
 
825
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
825
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
826 826
 
827
-	$html = '<div class="getpaid-settings-editor-input">';
828
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
829
-		ob_start();
830
-		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 ) );
831
-		$html .= ob_get_clean();
832
-	} else {
833
-		$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>';
834
-	}
827
+    $html = '<div class="getpaid-settings-editor-input">';
828
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
829
+        ob_start();
830
+        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 ) );
831
+        $html .= ob_get_clean();
832
+    } else {
833
+        $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>';
834
+    }
835 835
 
836
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
836
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
837 837
 
838
-	echo $html;
838
+    echo $html;
839 839
 }
840 840
 
841 841
 function wpinv_upload_callback( $args ) {
842 842
     
843 843
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
844 844
 
845
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
846
-	$value   = wpinv_get_option( $args['id'], $std );
845
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
846
+    $value   = wpinv_get_option( $args['id'], $std );
847 847
 
848
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
849
-	$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 ) ) . '"/>';
850
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
851
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
848
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
849
+    $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 ) ) . '"/>';
850
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
851
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
852 852
 
853
-	echo $html;
853
+    echo $html;
854 854
 }
855 855
 
856 856
 function wpinv_color_callback( $args ) {
857 857
 
858
-	$std         = isset( $args['std'] ) ? $args['std'] : '';
859
-	$value       = wpinv_get_option( $args['id'], $std );
858
+    $std         = isset( $args['std'] ) ? $args['std'] : '';
859
+    $value       = wpinv_get_option( $args['id'], $std );
860 860
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
861 861
 
862
-	$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( $std ) . '" />';
863
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
862
+    $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( $std ) . '" />';
863
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
864 864
 
865
-	echo $html;
865
+    echo $html;
866 866
 }
867 867
 
868 868
 function wpinv_country_states_callback($args) {
869 869
 
870
-	$std     = isset( $args['std'] ) ? $args['std'] : '';
871
-	$value   = wpinv_get_option( $args['id'], $std );
870
+    $std     = isset( $args['std'] ) ? $args['std'] : '';
871
+    $value   = wpinv_get_option( $args['id'], $std );
872 872
 
873 873
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
874 874
 
875
-	if ( isset( $args['placeholder'] ) ) {
876
-		$placeholder = $args['placeholder'];
877
-	} else {
878
-		$placeholder = '';
879
-	}
875
+    if ( isset( $args['placeholder'] ) ) {
876
+        $placeholder = $args['placeholder'];
877
+    } else {
878
+        $placeholder = '';
879
+    }
880 880
 
881
-	$states = wpinv_get_country_states();
881
+    $states = wpinv_get_country_states();
882 882
 
883
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
884
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
883
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
884
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
885 885
 
886
-	foreach ( $states as $option => $name ) {
887
-		$selected = selected( $option, $value, false );
888
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
889
-	}
886
+    foreach ( $states as $option => $name ) {
887
+        $selected = selected( $option, $value, false );
888
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
889
+    }
890 890
 
891
-	$html .= '</select>';
892
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
891
+    $html .= '</select>';
892
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
893 893
 
894
-	echo $html;
894
+    echo $html;
895 895
 }
896 896
 
897 897
 /**
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
  */
900 900
 function wpinv_tax_rates_callback() {
901 901
 	
902
-	?>
902
+    ?>
903 903
 		</td>
904 904
 	</tr>
905 905
 	<tr class="bsui">
@@ -914,17 +914,17 @@  discard block
 block discarded – undo
914 914
  * Displays a tax rate' edit row.
915 915
  */
916 916
 function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
917
-	ob_start();
917
+    ob_start();
918 918
 
919
-	$key                      = sanitize_key( $key );
920
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
921
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
919
+    $key                      = sanitize_key( $key );
920
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
921
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
922 922
 
923
-	if ( $echo ) {
924
-		echo ob_get_clean();
925
-	} else {
926
-		return ob_get_clean(); 
927
-	}
923
+    if ( $echo ) {
924
+        echo ob_get_clean();
925
+    } else {
926
+        return ob_get_clean(); 
927
+    }
928 928
 
929 929
 }
930 930
 
@@ -952,14 +952,14 @@  discard block
 block discarded – undo
952 952
                 </td>
953 953
                 <td>
954 954
 					<a href="<?php
955
-						echo esc_url(
956
-							wp_nonce_url(
957
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
958
-								'getpaid-nonce',
959
-								'getpaid-nonce'
960
-							)
961
-						);
962
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
955
+                        echo esc_url(
956
+                            wp_nonce_url(
957
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
958
+                                'getpaid-nonce',
959
+                                'getpaid-nonce'
960
+                            )
961
+                        );
962
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
963 963
                 </td>
964 964
             </tr>
965 965
 			<tr>
@@ -969,14 +969,14 @@  discard block
 block discarded – undo
969 969
                 </td>
970 970
                 <td>
971 971
 					<a href="<?php
972
-						echo esc_url(
973
-							wp_nonce_url(
974
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
975
-								'getpaid-nonce',
976
-								'getpaid-nonce'
977
-							)
978
-						);
979
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
972
+                        echo esc_url(
973
+                            wp_nonce_url(
974
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
975
+                                'getpaid-nonce',
976
+                                'getpaid-nonce'
977
+                            )
978
+                        );
979
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
980 980
                 </td>
981 981
             </tr>
982 982
 			<tr>
@@ -986,14 +986,14 @@  discard block
 block discarded – undo
986 986
                 </td>
987 987
                 <td>
988 988
 					<a href="<?php
989
-						echo esc_url(
990
-							wp_nonce_url(
991
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
992
-								'getpaid-nonce',
993
-								'getpaid-nonce'
994
-							)
995
-						);
996
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
989
+                        echo esc_url(
990
+                            wp_nonce_url(
991
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
992
+                                'getpaid-nonce',
993
+                                'getpaid-nonce'
994
+                            )
995
+                        );
996
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
997 997
                 </td>
998 998
             </tr>
999 999
 
@@ -1004,14 +1004,14 @@  discard block
 block discarded – undo
1004 1004
                 </td>
1005 1005
                 <td>
1006 1006
 					<a href="<?php
1007
-						echo esc_url(
1008
-							wp_nonce_url(
1009
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1010
-								'getpaid-nonce',
1011
-								'getpaid-nonce'
1012
-							)
1013
-						);
1014
-					?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1007
+                        echo esc_url(
1008
+                            wp_nonce_url(
1009
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1010
+                                'getpaid-nonce',
1011
+                                'getpaid-nonce'
1012
+                            )
1013
+                        );
1014
+                    ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1015 1015
                 </td>
1016 1016
             </tr>
1017 1017
 
@@ -1022,8 +1022,8 @@  discard block
 block discarded – undo
1022 1022
                 </td>
1023 1023
                 <td>
1024 1024
 					<a href="<?php
1025
-						echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1026
-					?>" class="button button-primary"><?php _e( 'Launch', 'invoicing' );?></a>
1025
+                        echo esc_url( admin_url( 'index.php?page=gp-setup' ) );
1026
+                    ?>" class="button button-primary"><?php _e( 'Launch', 'invoicing' );?></a>
1027 1027
                 </td>
1028 1028
             </tr>
1029 1029
 
@@ -1037,19 +1037,19 @@  discard block
 block discarded – undo
1037 1037
 
1038 1038
 
1039 1039
 function wpinv_descriptive_text_callback( $args ) {
1040
-	echo wp_kses_post( $args['desc'] );
1040
+    echo wp_kses_post( $args['desc'] );
1041 1041
 }
1042 1042
 
1043 1043
 function wpinv_raw_html_callback( $args ) {
1044
-	echo $args['desc'];
1044
+    echo $args['desc'];
1045 1045
 }
1046 1046
 
1047 1047
 function wpinv_hook_callback( $args ) {
1048
-	do_action( 'wpinv_' . $args['id'], $args );
1048
+    do_action( 'wpinv_' . $args['id'], $args );
1049 1049
 }
1050 1050
 
1051 1051
 function wpinv_set_settings_cap() {
1052
-	return wpinv_get_capability();
1052
+    return wpinv_get_capability();
1053 1053
 }
1054 1054
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1055 1055
 
@@ -1073,15 +1073,15 @@  discard block
 block discarded – undo
1073 1073
  */
1074 1074
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1075 1075
 
1076
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1077
-	$link = sprintf(
1078
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1079
-		$url,
1080
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1081
-	);
1076
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1077
+    $link = sprintf(
1078
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1079
+        $url,
1080
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1081
+    );
1082 1082
 
1083
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1083
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1084 1084
 
1085
-	return "$description $link";
1085
+    return "$description $link";
1086 1086
 
1087 1087
 }
Please login to merge, or discard this patch.
includes/admin/class-wpinv-customers-table.php 1 patch
Indentation   +364 added lines, -364 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
 
10 10
 // Load WP_List_Table if not loaded
11 11
 if ( ! class_exists( 'WP_List_Table' ) ) {
12
-	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
12
+    require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
13 13
 }
14 14
 
15 15
 /**
@@ -21,367 +21,367 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class WPInv_Customers_Table extends WP_List_Table {
23 23
 
24
-	/**
25
-	 * @var int Number of items per page
26
-	 * @since 1.0.19
27
-	 */
28
-	public $per_page = 10;
29
-
30
-	/**
31
-	 * @var int Number of items
32
-	 * @since 1.0.19
33
-	 */
34
-	public $total = 0;
35
-
36
-	/**
37
-	 * Get things started
38
-	 *
39
-	 * @since 1.0.19
40
-	 * @see WP_List_Table::__construct()
41
-	 */
42
-	public function __construct() {
43
-
44
-		// Set parent defaults
45
-		parent::__construct( array(
46
-			'singular' => 'id',
47
-			'plural'   => 'ids',
48
-			'ajax'     => false,
49
-		) );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Gets the name of the primary column.
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @access protected
58
-	 *
59
-	 * @return string Name of the primary column.
60
-	 */
61
-	protected function get_primary_column_name() {
62
-		return 'name';
63
-	}
64
-
65
-	/**
66
-	 * This function renders most of the columns in the list table.
67
-	 *
68
-	 * @since 1.0.19
69
-	 *
70
-	 * @param WP_User $item
71
-	 * @param string $column_name The name of the column
72
-	 *
73
-	 * @return string Column Name
74
-	 */
75
-	public function column_default( $item, $column_name ) {
76
-		$value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
77
-		return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
78
-	}
79
-
80
-	/**
81
-	 * Displays the country column.
82
-	 *
83
-	 * @since 1.0.19
84
-	 *
85
-	 * @param WP_User $user
86
-	 *
87
-	 * @return string Column Name
88
-	 */
89
-	public function column_country( $user ) {
90
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
91
-		if ( $country ) {
92
-			$country = wpinv_country_name( $country );
93
-		}
94
-		return sanitize_text_field( $country );
95
-	}
96
-
97
-	/**
98
-	 * Displays the state column.
99
-	 *
100
-	 * @since 1.0.19
101
-	 *
102
-	 * @param WP_User $user
103
-	 *
104
-	 * @return string Column Name
105
-	 */
106
-	public function column_state( $user ) {
107
-		$country = wpinv_sanitize_country( $user->_wpinv_country );
108
-		$state   = $user->_wpinv_state;
109
-		if ( $state ) {
110
-			$state = wpinv_state_name( $state, $country );
111
-		}
112
-
113
-		return sanitize_text_field( $state );
114
-	}
115
-
116
-	/**
117
-	 * Displays the signup column.
118
-	 *
119
-	 * @since 1.0.19
120
-	 *
121
-	 * @param WP_User $user
122
-	 *
123
-	 * @return string Column Name
124
-	 */
125
-	public function column_signup( $user ) {
126
-		return getpaid_format_date_value( $user->user_registered );
127
-	}
128
-
129
-	/**
130
-	 * Displays the total spent column.
131
-	 *
132
-	 * @since 1.0.19
133
-	 *
134
-	 * @param WP_User $user
135
-	 *
136
-	 * @return string Column Name
137
-	 */
138
-	public function column_total( $user ) {
139
-		return wpinv_price( $this->column_total_raw( $user ) );
140
-	}
141
-
142
-	/**
143
-	 * Displays the total spent column.
144
-	 *
145
-	 * @since 1.0.19
146
-	 *
147
-	 * @param WP_User $user
148
-	 *
149
-	 * @return float
150
-	 */
151
-	public function column_total_raw( $user ) {
152
-
153
-		$args = array(
154
-			'data'             => array(
155
-
156
-				'total'        => array(
157
-					'type'     => 'invoice_data',
158
-					'function' => 'SUM',
159
-					'name'     => 'total_sales',
160
-				)
161
-
162
-			),
163
-			'where'            => array(
164
-
165
-				'author'       => array(
166
-					'type'     => 'post_data',
167
-					'value'    => absint( $user->ID ),
168
-					'key'      => 'posts.post_author',
169
-					'operator' => '=',
170
-				),
171
-
172
-			),
173
-			'query_type'     => 'get_var',
174
-			'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
175
-		);
176
-
177
-		return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
178
-
179
-	}
180
-
181
-	/**
182
-	 * Displays the total spent column.
183
-	 *
184
-	 * @since 1.0.19
185
-	 *
186
-	 * @param WP_User $user
187
-	 *
188
-	 * @return string Column Name
189
-	 */
190
-	public function column_invoices( $user ) {
191
-
192
-		$args = array(
193
-			'data'             => array(
194
-
195
-				'ID'           => array(
196
-					'type'     => 'post_data',
197
-					'function' => 'COUNT',
198
-					'name'     => 'count',
199
-					'distinct' => true,
200
-				),
201
-
202
-			),
203
-			'where'            => array(
204
-
205
-				'author'       => array(
206
-					'type'     => 'post_data',
207
-					'value'    => absint( $user->ID ),
208
-					'key'      => 'posts.post_author',
209
-					'operator' => '=',
210
-				),
211
-
212
-			),
213
-			'query_type'     => 'get_var',
214
-			'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
215
-		);
216
-
217
-		return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
218
-
219
-	}
220
-
221
-	/**
222
-	 * Generates content for a single row of the table
223
-	 * @since 1.0.19
224
-	 *
225
-	 * @param int $item The user id.
226
-	 */
227
-	public function single_row( $item ) {
228
-		$item = get_user_by( 'id', $item );
229
-
230
-		if ( empty( $item ) ) {
231
-			return;
232
-		}
233
-
234
-		echo '<tr>';
235
-		$this->single_row_columns( $item );
236
-		echo '</tr>';
237
-	}
238
-
239
-	/**
240
-	 * Displays the customers name
241
-	 *
242
-	 * @param  WP_User $customer customer.
243
-	 * @return string
244
-	 */
245
-	public function column_name( $customer ) {
246
-
247
-		// Customer view URL.
248
-		$view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
249
-		$row_actions = $this->row_actions(
250
-			array(
251
-				'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
252
-			)
253
-		);
254
-
255
-		// Get user's address.
256
-		$address = wpinv_get_user_address( $customer->ID );
257
-
258
-		// Customer email address.
259
-		$email       = sanitize_email( $customer->user_email );
260
-
261
-		// Customer's avatar.
262
-		$avatar = esc_url( get_avatar_url( $email ) );
263
-		$avatar = "<img src='$avatar' height='32' width='32'/>";
264
-
265
-		// Customer's name.
266
-		$name   = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" );
267
-
268
-		if ( ! empty( $name ) ) {
269
-			$name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
270
-		}
271
-
272
-		$email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
273
-
274
-		return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
275
-
276
-	}
277
-
278
-	/**
279
-	 * Retrieve the table columns
280
-	 *
281
-	 * @since 1.0.19
282
-	 * @return array $columns Array of all the list table columns
283
-	 */
284
-	public function get_columns() {
285
-
286
-		$columns = array(
287
-			'name'     => __( 'Name', 'invoicing' ),
288
-			'country'  => __( 'Country', 'invoicing' ),
289
-			'state'    => __( 'State', 'invoicing' ),
290
-			'city'     => __( 'City', 'invoicing' ),
291
-			'zip'      => __( 'ZIP', 'invoicing' ),
292
-			'address'  => __( 'Address', 'invoicing' ),
293
-			'phone'    => __( 'Phone', 'invoicing' ),
294
-			'company'  => __( 'Company', 'invoicing' ),
295
-			'invoices' => __( 'Invoices', 'invoicing' ),
296
-			'total'    => __( 'Total Spend', 'invoicing' ),
297
-			'signup'   => __( 'Date created', 'invoicing' ),
298
-		);
299
-		return apply_filters( 'wpinv_customers_table_columns', $columns );
300
-
301
-	}
302
-
303
-	/**
304
-	 * Retrieve the current page number
305
-	 *
306
-	 * @since 1.0.19
307
-	 * @return int Current page number
308
-	 */
309
-	public function get_paged() {
310
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
311
-	}
312
-
313
-	/**
314
-	 * Returns bulk actions.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @return void
318
-	 */
319
-	public function bulk_actions( $which = '' ) {
320
-		return array();
321
-	}
322
-
323
-	/**
324
-	 *  Prepares the display query
325
-	 */
326
-	public function prepare_query() {
327
-		global $wpdb;
328
-
329
-		$post_types = '';
330
-
331
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
332
-			$post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
333
-		}
334
-
335
-		$post_types = rtrim( $post_types, ' OR' );
336
-
337
-		// Maybe search.
338
-		if ( ! empty( $_POST['s'] ) ) {
339
-			$users = get_users(
340
-				array(
341
-					'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
342
-					'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
343
-					'fields'         => 'ID',
344
-				)
345
-			);
346
-
347
-			$users      = implode( ', ', $users );
348
-			$post_types = "($post_types) AND ( post_author IN ( $users ) )";
349
-		}
350
-
351
-		// Users with invoices.
352
-    	$customers = $wpdb->get_col(
353
-			$wpdb->prepare(
354
-				"SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
355
-				$this->get_paged() * 10 - 10,
356
-				$this->per_page
357
-			)
358
-		);
359
-
360
-		$this->items = $customers;
361
-		$this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
362
-
363
-	}
364
-
365
-	/**
366
-	 * Setup the final data for the table
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @return void
370
-	 */
371
-	public function prepare_items() {
372
-		$columns               = $this->get_columns();
373
-		$hidden                = array(); // No hidden columns
374
-		$sortable              = $this->get_sortable_columns();
375
-		$this->_column_headers = array( $columns, $hidden, $sortable );
376
-		$this->prepare_query();
377
-
378
-		$this->set_pagination_args(
379
-			array(
380
-			'total_items' => $this->total,
381
-			'per_page'    => $this->per_page,
382
-			'total_pages' => ceil( $this->total / $this->per_page )
383
-			)
384
-		);
385
-
386
-	}
24
+    /**
25
+     * @var int Number of items per page
26
+     * @since 1.0.19
27
+     */
28
+    public $per_page = 10;
29
+
30
+    /**
31
+     * @var int Number of items
32
+     * @since 1.0.19
33
+     */
34
+    public $total = 0;
35
+
36
+    /**
37
+     * Get things started
38
+     *
39
+     * @since 1.0.19
40
+     * @see WP_List_Table::__construct()
41
+     */
42
+    public function __construct() {
43
+
44
+        // Set parent defaults
45
+        parent::__construct( array(
46
+            'singular' => 'id',
47
+            'plural'   => 'ids',
48
+            'ajax'     => false,
49
+        ) );
50
+
51
+    }
52
+
53
+    /**
54
+     * Gets the name of the primary column.
55
+     *
56
+     * @since 1.0.19
57
+     * @access protected
58
+     *
59
+     * @return string Name of the primary column.
60
+     */
61
+    protected function get_primary_column_name() {
62
+        return 'name';
63
+    }
64
+
65
+    /**
66
+     * This function renders most of the columns in the list table.
67
+     *
68
+     * @since 1.0.19
69
+     *
70
+     * @param WP_User $item
71
+     * @param string $column_name The name of the column
72
+     *
73
+     * @return string Column Name
74
+     */
75
+    public function column_default( $item, $column_name ) {
76
+        $value = sanitize_text_field( get_user_meta( $item->ID, '_wpinv_' . $column_name, true ) );
77
+        return apply_filters( 'wpinv_customers_table_column' . $column_name, $value, $item );
78
+    }
79
+
80
+    /**
81
+     * Displays the country column.
82
+     *
83
+     * @since 1.0.19
84
+     *
85
+     * @param WP_User $user
86
+     *
87
+     * @return string Column Name
88
+     */
89
+    public function column_country( $user ) {
90
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
91
+        if ( $country ) {
92
+            $country = wpinv_country_name( $country );
93
+        }
94
+        return sanitize_text_field( $country );
95
+    }
96
+
97
+    /**
98
+     * Displays the state column.
99
+     *
100
+     * @since 1.0.19
101
+     *
102
+     * @param WP_User $user
103
+     *
104
+     * @return string Column Name
105
+     */
106
+    public function column_state( $user ) {
107
+        $country = wpinv_sanitize_country( $user->_wpinv_country );
108
+        $state   = $user->_wpinv_state;
109
+        if ( $state ) {
110
+            $state = wpinv_state_name( $state, $country );
111
+        }
112
+
113
+        return sanitize_text_field( $state );
114
+    }
115
+
116
+    /**
117
+     * Displays the signup column.
118
+     *
119
+     * @since 1.0.19
120
+     *
121
+     * @param WP_User $user
122
+     *
123
+     * @return string Column Name
124
+     */
125
+    public function column_signup( $user ) {
126
+        return getpaid_format_date_value( $user->user_registered );
127
+    }
128
+
129
+    /**
130
+     * Displays the total spent column.
131
+     *
132
+     * @since 1.0.19
133
+     *
134
+     * @param WP_User $user
135
+     *
136
+     * @return string Column Name
137
+     */
138
+    public function column_total( $user ) {
139
+        return wpinv_price( $this->column_total_raw( $user ) );
140
+    }
141
+
142
+    /**
143
+     * Displays the total spent column.
144
+     *
145
+     * @since 1.0.19
146
+     *
147
+     * @param WP_User $user
148
+     *
149
+     * @return float
150
+     */
151
+    public function column_total_raw( $user ) {
152
+
153
+        $args = array(
154
+            'data'             => array(
155
+
156
+                'total'        => array(
157
+                    'type'     => 'invoice_data',
158
+                    'function' => 'SUM',
159
+                    'name'     => 'total_sales',
160
+                )
161
+
162
+            ),
163
+            'where'            => array(
164
+
165
+                'author'       => array(
166
+                    'type'     => 'post_data',
167
+                    'value'    => absint( $user->ID ),
168
+                    'key'      => 'posts.post_author',
169
+                    'operator' => '=',
170
+                ),
171
+
172
+            ),
173
+            'query_type'     => 'get_var',
174
+            'invoice_status' => array( 'wpi-renewal', 'wpi-processing', 'publish' ),
175
+        );
176
+
177
+        return wpinv_round_amount( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
178
+
179
+    }
180
+
181
+    /**
182
+     * Displays the total spent column.
183
+     *
184
+     * @since 1.0.19
185
+     *
186
+     * @param WP_User $user
187
+     *
188
+     * @return string Column Name
189
+     */
190
+    public function column_invoices( $user ) {
191
+
192
+        $args = array(
193
+            'data'             => array(
194
+
195
+                'ID'           => array(
196
+                    'type'     => 'post_data',
197
+                    'function' => 'COUNT',
198
+                    'name'     => 'count',
199
+                    'distinct' => true,
200
+                ),
201
+
202
+            ),
203
+            'where'            => array(
204
+
205
+                'author'       => array(
206
+                    'type'     => 'post_data',
207
+                    'value'    => absint( $user->ID ),
208
+                    'key'      => 'posts.post_author',
209
+                    'operator' => '=',
210
+                ),
211
+
212
+            ),
213
+            'query_type'     => 'get_var',
214
+            'invoice_status' => array_keys( wpinv_get_invoice_statuses() ),
215
+        );
216
+
217
+        return absint( GetPaid_Reports_Helper::get_invoice_report_data( $args ) );
218
+
219
+    }
220
+
221
+    /**
222
+     * Generates content for a single row of the table
223
+     * @since 1.0.19
224
+     *
225
+     * @param int $item The user id.
226
+     */
227
+    public function single_row( $item ) {
228
+        $item = get_user_by( 'id', $item );
229
+
230
+        if ( empty( $item ) ) {
231
+            return;
232
+        }
233
+
234
+        echo '<tr>';
235
+        $this->single_row_columns( $item );
236
+        echo '</tr>';
237
+    }
238
+
239
+    /**
240
+     * Displays the customers name
241
+     *
242
+     * @param  WP_User $customer customer.
243
+     * @return string
244
+     */
245
+    public function column_name( $customer ) {
246
+
247
+        // Customer view URL.
248
+        $view_url    = esc_url( add_query_arg( 'user_id', $customer->ID, admin_url( 'user-edit.php' ) ) );
249
+        $row_actions = $this->row_actions(
250
+            array(
251
+                'view' => '<a href="' . $view_url . '#getpaid-fieldset-billing">' . __( 'Edit Details', 'invoicing' ) . '</a>',
252
+            )
253
+        );
254
+
255
+        // Get user's address.
256
+        $address = wpinv_get_user_address( $customer->ID );
257
+
258
+        // Customer email address.
259
+        $email       = sanitize_email( $customer->user_email );
260
+
261
+        // Customer's avatar.
262
+        $avatar = esc_url( get_avatar_url( $email ) );
263
+        $avatar = "<img src='$avatar' height='32' width='32'/>";
264
+
265
+        // Customer's name.
266
+        $name   = sanitize_text_field( "{$address['first_name']} {$address['last_name']}" );
267
+
268
+        if ( ! empty( $name ) ) {
269
+            $name = "<div style='overflow: hidden;height: 18px;'>$name</div>";
270
+        }
271
+
272
+        $email = "<div class='row-title'><a href='$view_url'>$email</a></div>";
273
+
274
+        return "<div style='display: flex;'><div>$avatar</div><div style='margin-left: 10px;'>$name<strong>$email</strong>$row_actions</div></div>";
275
+
276
+    }
277
+
278
+    /**
279
+     * Retrieve the table columns
280
+     *
281
+     * @since 1.0.19
282
+     * @return array $columns Array of all the list table columns
283
+     */
284
+    public function get_columns() {
285
+
286
+        $columns = array(
287
+            'name'     => __( 'Name', 'invoicing' ),
288
+            'country'  => __( 'Country', 'invoicing' ),
289
+            'state'    => __( 'State', 'invoicing' ),
290
+            'city'     => __( 'City', 'invoicing' ),
291
+            'zip'      => __( 'ZIP', 'invoicing' ),
292
+            'address'  => __( 'Address', 'invoicing' ),
293
+            'phone'    => __( 'Phone', 'invoicing' ),
294
+            'company'  => __( 'Company', 'invoicing' ),
295
+            'invoices' => __( 'Invoices', 'invoicing' ),
296
+            'total'    => __( 'Total Spend', 'invoicing' ),
297
+            'signup'   => __( 'Date created', 'invoicing' ),
298
+        );
299
+        return apply_filters( 'wpinv_customers_table_columns', $columns );
300
+
301
+    }
302
+
303
+    /**
304
+     * Retrieve the current page number
305
+     *
306
+     * @since 1.0.19
307
+     * @return int Current page number
308
+     */
309
+    public function get_paged() {
310
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
311
+    }
312
+
313
+    /**
314
+     * Returns bulk actions.
315
+     *
316
+     * @since 1.0.19
317
+     * @return void
318
+     */
319
+    public function bulk_actions( $which = '' ) {
320
+        return array();
321
+    }
322
+
323
+    /**
324
+     *  Prepares the display query
325
+     */
326
+    public function prepare_query() {
327
+        global $wpdb;
328
+
329
+        $post_types = '';
330
+
331
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
332
+            $post_types .= $wpdb->prepare( "post_type=%s OR ", $post_type );
333
+        }
334
+
335
+        $post_types = rtrim( $post_types, ' OR' );
336
+
337
+        // Maybe search.
338
+        if ( ! empty( $_POST['s'] ) ) {
339
+            $users = get_users(
340
+                array(
341
+                    'search'         => '*' . sanitize_text_field( urldecode( $_POST['s'] ) ) . '*',
342
+                    'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
343
+                    'fields'         => 'ID',
344
+                )
345
+            );
346
+
347
+            $users      = implode( ', ', $users );
348
+            $post_types = "($post_types) AND ( post_author IN ( $users ) )";
349
+        }
350
+
351
+        // Users with invoices.
352
+        $customers = $wpdb->get_col(
353
+            $wpdb->prepare(
354
+                "SELECT DISTINCT( post_author ) FROM $wpdb->posts WHERE $post_types LIMIT %d,%d",
355
+                $this->get_paged() * 10 - 10,
356
+                $this->per_page
357
+            )
358
+        );
359
+
360
+        $this->items = $customers;
361
+        $this->total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT( post_author ) ) FROM $wpdb->posts WHERE $post_types" );
362
+
363
+    }
364
+
365
+    /**
366
+     * Setup the final data for the table
367
+     *
368
+     * @since 1.0.19
369
+     * @return void
370
+     */
371
+    public function prepare_items() {
372
+        $columns               = $this->get_columns();
373
+        $hidden                = array(); // No hidden columns
374
+        $sortable              = $this->get_sortable_columns();
375
+        $this->_column_headers = array( $columns, $hidden, $sortable );
376
+        $this->prepare_query();
377
+
378
+        $this->set_pagination_args(
379
+            array(
380
+            'total_items' => $this->total,
381
+            'per_page'    => $this->per_page,
382
+            'total_pages' => ceil( $this->total / $this->per_page )
383
+            )
384
+        );
385
+
386
+    }
387 387
 }
Please login to merge, or discard this patch.