Passed
Push — master ( edf7ac...1b48ee )
by Brian
09:08
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.
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-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/class-getpaid-daily-maintenance.php 1 patch
Indentation   +140 added lines, -140 removed lines patch added patch discarded remove patch
@@ -12,145 +12,145 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
-
33
-	}
34
-
35
-	/**
36
-	 * Schedules a cron to run every day at 7 a.m
37
-	 *
38
-	 */
39
-	public function maybe_create_scheduled_event() {
40
-
41
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
-		}
45
-
46
-	}
47
-
48
-	/**
49
-	 * Clears deprecated events.
50
-	 *
51
-	 */
52
-	public function maybe_clear_deprecated_events() {
53
-
54
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
-			update_option( 'wpinv_cleared_old_events', 1 );
58
-		}
59
-
60
-	}
61
-
62
-	/**
63
-	 * Fires the old hook for backwards compatibility.
64
-	 *
65
-	 */
66
-	public function backwards_compat() {
67
-		do_action( 'wpinv_register_schedule_event_daily' );
68
-	}
69
-
70
-	/**
71
-	 * Checks for subscriptions that are scheduled to renew.
72
-	 *
73
-	 */
74
-	public function check_renewing_subscriptions() {
75
-
76
-		// Fetch subscriptions that expire today.
77
-		$args  = array(
78
-			'number'             => -1,
79
-			'count_total'        => false,
80
-			'status'             => 'trialling active',
81
-			'date_expires_query' => array(
82
-				array(
83
-					'year'          => date( 'Y', current_time( 'timestamp' ) ),
84
-					'month'         => date( 'n', current_time( 'timestamp' ) ),
85
-					'day'           => date( 'j', current_time( 'timestamp' ) ),
86
-					'compare'       => '=',
87
-				),
88
-			),
89
-		);
90
-
91
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
92
-
93
-		foreach ( $subscriptions->get_results() as $subscription ) {
94
-
95
-			/** @var WPInv_Subscription $subscription */
96
-			if ( $subscription->is_last_renewal() ) {
97
-				$subscription->complete();
98
-			} else {
99
-				do_action( 'getpaid_should_renew_subscription', $subscription );
100
-			}
101
-
102
-		}
103
-
104
-	}
105
-
106
-	/**
107
-	 * Expires expired subscriptions.
108
-	 *
109
-	 */
110
-	public function maybe_expire_subscriptions() {
111
-
112
-		// Fetch expired subscriptions (skips those that expire today).
113
-		$args  = array(
114
-			'number'             => -1,
115
-			'count_total'        => false,
116
-			'status'             => 'trialling active failing cancelled',
117
-			'date_expires_query' => array(
118
-				'before'    => 'yesterday',
119
-				'inclusive' => false,
120
-			),
121
-		);
122
-
123
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
124
-
125
-		foreach ( $subscriptions->get_results() as $subscription ) {
126
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
127
-				$subscription->set_status( 'expired' );
128
-				$subscription->save();
129
-			}
130
-		}
131
-
132
-	}
133
-
134
-	/**
135
-	 * Logs cron runs.
136
-	 *
137
-	 */
138
-	public function log_cron_run() {
139
-		wpinv_error_log( 'GetPaid Daily Cron', false );
140
-	}
141
-
142
-	/**
143
-	 * Updates GeoIP databases.
144
-	 *
145
-	 */
146
-	public function maybe_update_geoip_databases() {
147
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
148
-
149
-		if ( false === $updated ) {
150
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
151
-			do_action( 'getpaid_update_geoip_databases' );
152
-		}
153
-
154
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'check_renewing_subscriptions' ) );
31
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
32
+
33
+    }
34
+
35
+    /**
36
+     * Schedules a cron to run every day at 7 a.m
37
+     *
38
+     */
39
+    public function maybe_create_scheduled_event() {
40
+
41
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
42
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
43
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
44
+        }
45
+
46
+    }
47
+
48
+    /**
49
+     * Clears deprecated events.
50
+     *
51
+     */
52
+    public function maybe_clear_deprecated_events() {
53
+
54
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
56
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
57
+            update_option( 'wpinv_cleared_old_events', 1 );
58
+        }
59
+
60
+    }
61
+
62
+    /**
63
+     * Fires the old hook for backwards compatibility.
64
+     *
65
+     */
66
+    public function backwards_compat() {
67
+        do_action( 'wpinv_register_schedule_event_daily' );
68
+    }
69
+
70
+    /**
71
+     * Checks for subscriptions that are scheduled to renew.
72
+     *
73
+     */
74
+    public function check_renewing_subscriptions() {
75
+
76
+        // Fetch subscriptions that expire today.
77
+        $args  = array(
78
+            'number'             => -1,
79
+            'count_total'        => false,
80
+            'status'             => 'trialling active',
81
+            'date_expires_query' => array(
82
+                array(
83
+                    'year'          => date( 'Y', current_time( 'timestamp' ) ),
84
+                    'month'         => date( 'n', current_time( 'timestamp' ) ),
85
+                    'day'           => date( 'j', current_time( 'timestamp' ) ),
86
+                    'compare'       => '=',
87
+                ),
88
+            ),
89
+        );
90
+
91
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
92
+
93
+        foreach ( $subscriptions->get_results() as $subscription ) {
94
+
95
+            /** @var WPInv_Subscription $subscription */
96
+            if ( $subscription->is_last_renewal() ) {
97
+                $subscription->complete();
98
+            } else {
99
+                do_action( 'getpaid_should_renew_subscription', $subscription );
100
+            }
101
+
102
+        }
103
+
104
+    }
105
+
106
+    /**
107
+     * Expires expired subscriptions.
108
+     *
109
+     */
110
+    public function maybe_expire_subscriptions() {
111
+
112
+        // Fetch expired subscriptions (skips those that expire today).
113
+        $args  = array(
114
+            'number'             => -1,
115
+            'count_total'        => false,
116
+            'status'             => 'trialling active failing cancelled',
117
+            'date_expires_query' => array(
118
+                'before'    => 'yesterday',
119
+                'inclusive' => false,
120
+            ),
121
+        );
122
+
123
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
124
+
125
+        foreach ( $subscriptions->get_results() as $subscription ) {
126
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', false, $subscription ) ) {
127
+                $subscription->set_status( 'expired' );
128
+                $subscription->save();
129
+            }
130
+        }
131
+
132
+    }
133
+
134
+    /**
135
+     * Logs cron runs.
136
+     *
137
+     */
138
+    public function log_cron_run() {
139
+        wpinv_error_log( 'GetPaid Daily Cron', false );
140
+    }
141
+
142
+    /**
143
+     * Updates GeoIP databases.
144
+     *
145
+     */
146
+    public function maybe_update_geoip_databases() {
147
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
148
+
149
+        if ( false === $updated ) {
150
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
151
+            do_action( 'getpaid_update_geoip_databases' );
152
+        }
153
+
154
+    }
155 155
 
156 156
 }
Please login to merge, or discard this patch.
includes/class-wpinv-addons.php 1 patch
Indentation   +216 added lines, -216 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 if ( ! defined( 'ABSPATH' ) ) {
9
-	exit;
9
+    exit;
10 10
 }
11 11
 
12 12
 /**
@@ -15,85 +15,85 @@  discard block
 block discarded – undo
15 15
 class WPInv_Admin_Addons extends Ayecode_Addons {
16 16
 
17 17
 
18
-	/**
19
-	 * Get the extensions page tabs.
20
-	 *
21
-	 * @return array of tabs.
22
-	 */
23
-	public function get_tabs(){
24
-		$tabs = array(
25
-			'addons' => __("Addons", "invoicing"),
18
+    /**
19
+     * Get the extensions page tabs.
20
+     *
21
+     * @return array of tabs.
22
+     */
23
+    public function get_tabs(){
24
+        $tabs = array(
25
+            'addons' => __("Addons", "invoicing"),
26 26
             'gateways' => __("Payment Gateways", "invoicing"),
27 27
             'recommended_plugins' => __("Recommended plugins", "invoicing"),
28 28
             'membership' => __("Membership", "invoicing"),
29
-		);
30
-
31
-		return $tabs;
32
-	}
33
-
34
-	/**
35
-	 * Get section content for the addons screen.
36
-	 *
37
-	 * @param  string $section_id
38
-	 *
39
-	 * @return array
40
-	 */
41
-	public function get_section_data( $section_id ) {
42
-		$section      = self::get_tab( $section_id );
43
-		$api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
-		$section_data = new stdClass();
45
-
46
-		if($section_id=='recommended_plugins'){
47
-			$section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
-		}
49
-		elseif ( ! empty( $section ) ) {
50
-			if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
-			//if ( 1==1) {
52
-
53
-				$query_args = array( 'category' => $section_id, 'number' => 100);
54
-				$query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
-
56
-				$raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
-
58
-				if ( ! is_wp_error( $raw_section ) ) {
59
-					$section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
-
61
-					if ( ! empty( $section_data->products ) ) {
62
-						set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
-					}
64
-				}
65
-			}
66
-
67
-		}
68
-
69
-		$products = isset($section_data->products) ? $section_data->products : array();
70
-		if ( 'addons' == $section_id ) {
71
-
72
-			$quotes = new stdClass();
73
-			$quotes->info = new stdClass();
74
-			$quotes->info->id = '';
75
-			$quotes->info->slug = 'invoicing-quotes';
76
-			$quotes->info->title = __( 'Quotes', 'invoicing' );
77
-			$quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
-			$quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
-			$quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
-
81
-			$products[] = $quotes;
82
-		}
29
+        );
30
+
31
+        return $tabs;
32
+    }
33
+
34
+    /**
35
+     * Get section content for the addons screen.
36
+     *
37
+     * @param  string $section_id
38
+     *
39
+     * @return array
40
+     */
41
+    public function get_section_data( $section_id ) {
42
+        $section      = self::get_tab( $section_id );
43
+        $api_url = "https://wpinvoicing.com/edd-api/v2/products/";
44
+        $section_data = new stdClass();
45
+
46
+        if($section_id=='recommended_plugins'){
47
+            $section_data->products = self::get_recommend_wp_plugins_edd_formatted();
48
+        }
49
+        elseif ( ! empty( $section ) ) {
50
+            if ( false === ( $section_data = get_transient( 'wpi_addons_section_' . $section_id ) ) ) { //@todo restore after testing
51
+            //if ( 1==1) {
52
+
53
+                $query_args = array( 'category' => $section_id, 'number' => 100);
54
+                $query_args = apply_filters('wpeu_edd_api_query_args',$query_args,$api_url,$section_id);
55
+
56
+                $raw_section = wp_safe_remote_get( esc_url_raw( add_query_arg($query_args ,$api_url) ), array( 'user-agent' => 'Invoicing Addons Page','timeout'     => 15, ) );
57
+
58
+                if ( ! is_wp_error( $raw_section ) ) {
59
+                    $section_data = json_decode( wp_remote_retrieve_body( $raw_section ) );
60
+
61
+                    if ( ! empty( $section_data->products ) ) {
62
+                        set_transient( 'wpi_addons_section_' . $section_id, $section_data, DAY_IN_SECONDS );
63
+                    }
64
+                }
65
+            }
66
+
67
+        }
68
+
69
+        $products = isset($section_data->products) ? $section_data->products : array();
70
+        if ( 'addons' == $section_id ) {
71
+
72
+            $quotes = new stdClass();
73
+            $quotes->info = new stdClass();
74
+            $quotes->info->id = '';
75
+            $quotes->info->slug = 'invoicing-quotes';
76
+            $quotes->info->title = __( 'Quotes', 'invoicing' );
77
+            $quotes->info->excerpt = __( 'Create quotes and estimates', 'invoicing' );
78
+            $quotes->info->link = 'https://wordpress.org/plugins/invoicing-quotes/';
79
+            $quotes->info->thumbnail = 'https://wpgetpaid.com/wp-content/uploads/sites/13/edd/2019/11/Quotes-1-768x384.png';
80
+
81
+            $products[] = $quotes;
82
+        }
83 83
 		
84
-		return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
-	}
86
-
87
-	/**
88
-	 * Outputs a button.
89
-	 *ccc
90
-	 * @param string $url
91
-	 * @param string $text
92
-	 * @param string $theme
93
-	 * @param string $plugin
94
-	 */
95
-	public function output_button( $addon ) {
96
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
84
+        return apply_filters( 'wpi_addons_section_data', $products, $section_id );
85
+    }
86
+
87
+    /**
88
+     * Outputs a button.
89
+     *ccc
90
+     * @param string $url
91
+     * @param string $text
92
+     * @param string $theme
93
+     * @param string $plugin
94
+     */
95
+    public function output_button( $addon ) {
96
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
97 97
 //		$button_text = __('Free','invoicing');
98 98
 //		$licensing = false;
99 99
 //		$installed = false;
@@ -105,123 +105,123 @@  discard block
 block discarded – undo
105 105
 //		$install_status = 'get';
106 106
 //		$onclick = '';
107 107
 
108
-		$wp_org_themes = array('supreme-directory','directory-starter');
109
-
110
-		$button_args = array(
111
-			'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
-			'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
-			'title' => isset($addon->info->title) ? $addon->info->title : '',
114
-			'button_text' => __('Free','invoicing'),
115
-			'price_text' => __('Free','invoicing'),
116
-			'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
-			'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
-			'class' => 'button-primary',
119
-			'install_status' => 'get',
120
-			'installed' => false,
121
-			'price' => '',
122
-			'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
-			'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
-			'onclick' => '',
125
-			'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
-			'active' => false,
127
-			'file' => '',
128
-			'update_url' => '',
129
-		);
130
-
131
-		if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
-			$status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
-			$button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
-		}elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
-			include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
-			$status = self::install_plugin_install_status($addon);
140
-			$button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
-			if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
-			$button_args['update_url'] = "https://wpinvoicing.com";
143
-		}elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
-			if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
-			$button_args['installed'] = self::is_theme_installed($addon);
146
-			if(!in_array($button_args['slug'],$wp_org_themes)){
147
-				$button_args['update_url'] = "https://wpinvoicing.com";
148
-			}
149
-		}
150
-
151
-		// set price
152
-		if(isset($addon->pricing) && !empty($addon->pricing)){
153
-			if(is_object($addon->pricing)){
154
-				$prices = (Array)$addon->pricing;
155
-				$button_args['price'] = reset($prices);
156
-			}elseif(isset($addon->pricing)){
157
-				$button_args['price'] = $addon->pricing;
158
-			}
159
-		}
160
-
161
-		// set price text
162
-		if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
-			$button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
-		}
165
-
166
-
167
-		// set if installed
168
-		if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
-			$button_args['installed'] = true;
170
-		}
108
+        $wp_org_themes = array('supreme-directory','directory-starter');
109
+
110
+        $button_args = array(
111
+            'type' => ($current_tab == 'addons' || $current_tab =='gateways') ? 'addons' : $current_tab,
112
+            'id' => isset($addon->info->id) ? absint($addon->info->id) : '',
113
+            'title' => isset($addon->info->title) ? $addon->info->title : '',
114
+            'button_text' => __('Free','invoicing'),
115
+            'price_text' => __('Free','invoicing'),
116
+            'link' => isset($addon->info->link) ? $addon->info->link : '', // link to product
117
+            'url' => isset($addon->info->link) ? $addon->info->link : '', // button url
118
+            'class' => 'button-primary',
119
+            'install_status' => 'get',
120
+            'installed' => false,
121
+            'price' => '',
122
+            'licensing' => isset($addon->licensing->enabled) && $addon->licensing->enabled ? true : false,
123
+            'license' => isset($addon->licensing->license) && $addon->licensing->license ? $addon->licensing->license : '',
124
+            'onclick' => '',
125
+            'slug' => isset($addon->info->slug) ? $addon->info->slug : '',
126
+            'active' => false,
127
+            'file' => '',
128
+            'update_url' => '',
129
+        );
130
+
131
+        if( 'invoicing-quotes' == $addon->info->slug || 'getpaid-stripe-payments' == $addon->info->slug || ( $current_tab == 'recommended_plugins' && isset($addon->info->slug) && $addon->info->slug )){
132
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
133
+            $status = install_plugin_install_status(array("slug"=>$button_args['slug'],"version"=>""));
134
+            $button_args['install_status'] = isset($status['status']) ? $status['status'] : 'install';
135
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
136
+        }elseif( ($current_tab == 'addons' || $current_tab =='gateways') && isset($addon->info->id) && $addon->info->id){
137
+            include_once( ABSPATH . 'wp-admin/includes/plugin-install.php' ); //for plugins_api..
138
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
139
+            $status = self::install_plugin_install_status($addon);
140
+            $button_args['file'] = isset($status['file']) ? $status['file'] : '';
141
+            if(isset($status['status'])){$button_args['install_status'] = $status['status'];}
142
+            $button_args['update_url'] = "https://wpinvoicing.com";
143
+        }elseif($current_tab == 'themes' && isset($addon->info->id) && $addon->info->id) {
144
+            if(!empty($addon->licensing->edd_slug)){$button_args['slug'] = $addon->licensing->edd_slug;}
145
+            $button_args['installed'] = self::is_theme_installed($addon);
146
+            if(!in_array($button_args['slug'],$wp_org_themes)){
147
+                $button_args['update_url'] = "https://wpinvoicing.com";
148
+            }
149
+        }
150
+
151
+        // set price
152
+        if(isset($addon->pricing) && !empty($addon->pricing)){
153
+            if(is_object($addon->pricing)){
154
+                $prices = (Array)$addon->pricing;
155
+                $button_args['price'] = reset($prices);
156
+            }elseif(isset($addon->pricing)){
157
+                $button_args['price'] = $addon->pricing;
158
+            }
159
+        }
160
+
161
+        // set price text
162
+        if( $button_args['price'] && $button_args['price'] != '0.00' ){
163
+            $button_args['price_text'] = sprintf( __('From: $%d', 'invoicing'), $button_args['price']);
164
+        }
165
+
166
+
167
+        // set if installed
168
+        if(in_array($button_args['install_status'], array('installed','latest_installed','update_available','newer_installed'))){
169
+            $button_args['installed'] = true;
170
+        }
171 171
 
172 172
 //		print_r($button_args);
173
-		// set if active
174
-		if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
-			if($button_args['type'] != 'themes'){
176
-				$button_args['active'] = is_plugin_active($button_args['file']);
177
-			}else{
178
-				$button_args['active'] = self::is_theme_active($addon);
179
-			}
180
-		}
181
-
182
-		// set button text and class
183
-		if($button_args['active']){
184
-			$button_args['button_text'] = __('Active','invoicing');
185
-			$button_args['class'] = ' button-secondary disabled ';
186
-		}elseif($button_args['installed']){
187
-			$button_args['button_text'] = __('Activate','invoicing');
188
-
189
-			if($button_args['type'] != 'themes'){
190
-				if ( current_user_can( 'manage_options' ) ) {
191
-					$button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
-				}else{
193
-					$button_args['url'] = '#';
194
-				}
195
-			}else{
196
-				if ( current_user_can( 'switch_themes' ) ) {
197
-					$button_args['url'] = self::get_theme_activation_url($addon);
198
-				}else{
199
-					$button_args['url'] = '#';
200
-				}
201
-			}
202
-
203
-		}else{
204
-			if($button_args['type'] == 'recommended_plugins'){
205
-				$button_args['button_text'] = __('Install','invoicing');
206
-			}else{
207
-				$button_args['button_text'] = __('Get it','invoicing');
208
-
209
-				/*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
173
+        // set if active
174
+        if($button_args['installed'] && ($button_args['file'] || $button_args['type'] == 'themes')){
175
+            if($button_args['type'] != 'themes'){
176
+                $button_args['active'] = is_plugin_active($button_args['file']);
177
+            }else{
178
+                $button_args['active'] = self::is_theme_active($addon);
179
+            }
180
+        }
181
+
182
+        // set button text and class
183
+        if($button_args['active']){
184
+            $button_args['button_text'] = __('Active','invoicing');
185
+            $button_args['class'] = ' button-secondary disabled ';
186
+        }elseif($button_args['installed']){
187
+            $button_args['button_text'] = __('Activate','invoicing');
188
+
189
+            if($button_args['type'] != 'themes'){
190
+                if ( current_user_can( 'manage_options' ) ) {
191
+                    $button_args['url'] = wp_nonce_url(admin_url('plugins.php?action=activate&plugin='.$button_args['file']), 'activate-plugin_' . $button_args['file']);
192
+                }else{
193
+                    $button_args['url'] = '#';
194
+                }
195
+            }else{
196
+                if ( current_user_can( 'switch_themes' ) ) {
197
+                    $button_args['url'] = self::get_theme_activation_url($addon);
198
+                }else{
199
+                    $button_args['url'] = '#';
200
+                }
201
+            }
202
+
203
+        }else{
204
+            if($button_args['type'] == 'recommended_plugins'){
205
+                $button_args['button_text'] = __('Install','invoicing');
206
+            }else{
207
+                $button_args['button_text'] = __('Get it','invoicing');
208
+
209
+                /*if($button_args['type'] == 'themes' && in_array($button_args['slug'],$wp_org_themes) ){
210 210
 					$button_args['button_text'] = __('Install','invoicing');
211 211
 					$button_args['url'] = self::get_theme_install_url($button_args['slug']);
212 212
 					$button_args['onclick'] = 'gd_set_button_installing(this);';
213 213
 				}*/
214 214
 
215
-			}
216
-		}
215
+            }
216
+        }
217 217
 
218 218
 		
219
-		// filter the button arguments
220
-		$button_args = apply_filters('edd_api_button_args',$button_args);
219
+        // filter the button arguments
220
+        $button_args = apply_filters('edd_api_button_args',$button_args);
221 221
 //		print_r($button_args);
222
-		// set price text
223
-		if(isset($button_args['price_text'])){
224
-			?>
222
+        // set price text
223
+        if(isset($button_args['price_text'])){
224
+            ?>
225 225
 			<a
226 226
 				target="_blank"
227 227
 				class="addons-price-text"
@@ -229,15 +229,15 @@  discard block
 block discarded – undo
229 229
 				<?php echo esc_html( $button_args['price_text'] ); ?>
230 230
 			</a>
231 231
 			<?php
232
-		}
232
+        }
233 233
 
234 234
 
235
-		$target = '';
236
-		if ( ! empty( $button_args['url'] ) ) {
237
-			$target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
-		}
235
+        $target = '';
236
+        if ( ! empty( $button_args['url'] ) ) {
237
+            $target = strpos($button_args['url'], get_site_url()) !== false ? '' : ' target="_blank" ';
238
+        }
239 239
 
240
-		?>
240
+        ?>
241 241
 		<a
242 242
 			data-licence="<?php echo esc_attr($button_args['license']);?>"
243 243
 			data-licensing="<?php echo $button_args['licensing'] ? 1 : 0;?>"
@@ -260,33 +260,33 @@  discard block
 block discarded – undo
260 260
 		<?php
261 261
 
262 262
 
263
-	}
264
-
265
-
266
-	/**
267
-	 * Handles output of the addons page in admin.
268
-	 */
269
-	public function output() {
270
-		$tabs            = self::get_tabs();
271
-		$sections        = self::get_sections();
272
-		$theme           = wp_get_theme();
273
-		$section_keys    = array_keys( $sections );
274
-		$current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
-		$current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
-		include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
-	}
278
-
279
-	/**
280
-	 * A list of recommended wp.org plugins.
281
-	 * @return array
282
-	 */
283
-	public function get_recommend_wp_plugins(){
284
-		$plugins = array(
263
+    }
264
+
265
+
266
+    /**
267
+     * Handles output of the addons page in admin.
268
+     */
269
+    public function output() {
270
+        $tabs            = self::get_tabs();
271
+        $sections        = self::get_sections();
272
+        $theme           = wp_get_theme();
273
+        $section_keys    = array_keys( $sections );
274
+        $current_section = isset( $_GET['section'] ) ? sanitize_text_field( $_GET['section'] ) : current( $section_keys );
275
+        $current_tab     = empty( $_GET['tab'] ) ? 'addons' : sanitize_title( $_GET['tab'] );
276
+        include_once( WPINV_PLUGIN_DIR . '/includes/admin/html-admin-page-addons.php' );
277
+    }
278
+
279
+    /**
280
+     * A list of recommended wp.org plugins.
281
+     * @return array
282
+     */
283
+    public function get_recommend_wp_plugins(){
284
+        $plugins = array(
285 285
             'invoicing-quotes' => array(
286 286
                 'url'   => 'https://wordpress.org/plugins/invoicing-quotes/',
287 287
                 'slug'   => 'invoicing-quotes',
288
-				'name'   => 'Quotes',
289
-				'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
288
+                'name'   => 'Quotes',
289
+                'thumbnail'  => 'https://ps.w.org/invoicing-quotes/assets/banner-772x250.png',
290 290
                 'desc'   => __('Allows you to create quotes, send them to clients and convert them to Invoices when accepted by the customer.','invoicing'),
291 291
             ),
292 292
             'geodirectory' => array(
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
                 'name'   => 'UsersWP',
302 302
                 'desc'   => __('Allow frontend user login and registration as well as have slick profile pages.','invoicing'),
303 303
             ),
304
-		);
304
+        );
305 305
 
306
-		return $plugins;
307
-	}
306
+        return $plugins;
307
+    }
308 308
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 1 patch
Indentation   +403 added lines, -403 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,300 +21,300 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @ver 1.0.13
33
-	 * @todo decide how to implement textdomain
34
-	 */
35
-	class WP_Font_Awesome_Settings {
36
-
37
-		/**
38
-		 * Class version version.
39
-		 *
40
-		 * @var string
41
-		 */
42
-		public $version = '1.0.13';
43
-
44
-		/**
45
-		 * Class textdomain.
46
-		 *
47
-		 * @var string
48
-		 */
49
-		public $textdomain = 'font-awesome-settings';
50
-
51
-		/**
52
-		 * Latest version of Font Awesome at time of publish published.
53
-		 *
54
-		 * @var string
55
-		 */
56
-		public $latest = "5.8.2";
57
-
58
-		/**
59
-		 * The title.
60
-		 *
61
-		 * @var string
62
-		 */
63
-		public $name = 'Font Awesome';
64
-
65
-		/**
66
-		 * Holds the settings values.
67
-		 *
68
-		 * @var array
69
-		 */
70
-		private $settings;
71
-
72
-		/**
73
-		 * WP_Font_Awesome_Settings instance.
74
-		 *
75
-		 * @access private
76
-		 * @since  1.0.0
77
-		 * @var    WP_Font_Awesome_Settings There can be only one!
78
-		 */
79
-		private static $instance = null;
80
-
81
-		/**
82
-		 * Main WP_Font_Awesome_Settings Instance.
83
-		 *
84
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
-		 *
86
-		 * @since 1.0.0
87
-		 * @static
88
-		 * @return WP_Font_Awesome_Settings - Main instance.
89
-		 */
90
-		public static function instance() {
91
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
-				self::$instance = new WP_Font_Awesome_Settings;
93
-
94
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
-
96
-				if ( is_admin() ) {
97
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
-				}
100
-
101
-				do_action( 'wp_font_awesome_settings_loaded' );
102
-			}
103
-
104
-			return self::$instance;
105
-		}
106
-
107
-		/**
108
-		 * Initiate the settings and add the required action hooks.
109
-		 *
110
-		 * @since 1.0.8 Settings name wrong - FIXED
111
-		 */
112
-		public function init() {
113
-			$this->settings = $this->get_settings();
114
-
115
-			if ( $this->settings['type'] == 'CSS' ) {
116
-
117
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
-				}
120
-
121
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
-				}
124
-
125
-			} else {
126
-
127
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
-				}
130
-
131
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
-				}
134
-			}
135
-
136
-			// remove font awesome if set to do so
137
-			if ( $this->settings['dequeue'] == '1' ) {
138
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
-			}
140
-
141
-		}
142
-
143
-		/**
144
-		 * Adds the Font Awesome styles.
145
-		 */
146
-		public function enqueue_style() {
147
-			// build url
148
-			$url = $this->get_url();
149
-
150
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
-			wp_register_style( 'font-awesome', $url, array(), null );
152
-			wp_enqueue_style( 'font-awesome' );
153
-
154
-			// RTL language support CSS.
155
-			if ( is_rtl() ) {
156
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
-			}
158
-
159
-			if ( $this->settings['shims'] ) {
160
-				$url = $this->get_url( true );
161
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
163
-				wp_enqueue_style( 'font-awesome-shims' );
164
-			}
165
-		}
166
-
167
-		/**
168
-		 * Adds the Font Awesome JS.
169
-		 */
170
-		public function enqueue_scripts() {
171
-			// build url
172
-			$url = $this->get_url();
173
-
174
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
-			wp_register_script( 'font-awesome', $url, array(), null );
177
-			wp_enqueue_script( 'font-awesome' );
178
-
179
-			if ( $this->settings['shims'] ) {
180
-				$url = $this->get_url( true );
181
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
183
-				wp_enqueue_script( 'font-awesome-shims' );
184
-			}
185
-		}
186
-
187
-		/**
188
-		 * Get the url of the Font Awesome files.
189
-		 *
190
-		 * @param bool $shims If this is a shim file or not.
191
-		 *
192
-		 * @return string The url to the file.
193
-		 */
194
-		public function get_url( $shims = false ) {
195
-			$script  = $shims ? 'v4-shims' : 'all';
196
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
197
-			$type    = $this->settings['type'];
198
-			$version = $this->settings['version'];
199
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
-			$url     = '';
201
-
202
-			if ( $type == 'KIT' && $kit_url ) {
203
-				if ( $shims ) {
204
-					// if its a kit then we don't add shims here
205
-					return '';
206
-				}
207
-				$url .= $kit_url; // CDN
208
-				$url .= "?wpfas=true"; // set our var so our version is not removed
209
-			} else {
210
-				$url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
-				$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
-				$url .= "?wpfas=true"; // set our var so our version is not removed
215
-			}
216
-
217
-			return $url;
218
-		}
219
-
220
-		/**
221
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
-		 *
223
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
-		 *
225
-		 * @param $url
226
-		 * @param $original_url
227
-		 * @param $_context
228
-		 *
229
-		 * @return string The filtered url.
230
-		 */
231
-		public function remove_font_awesome( $url, $original_url, $_context ) {
232
-
233
-			if ( $_context == 'display'
234
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
-			) {// it's a font-awesome-url (probably)
237
-
238
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
239
-					if ( $this->settings['type'] == 'JS' ) {
240
-						if ( $this->settings['js-pseudo'] ) {
241
-							$url .= "' data-search-pseudo-elements defer='defer";
242
-						} else {
243
-							$url .= "' defer='defer";
244
-						}
245
-					}
246
-				} else {
247
-					$url = ''; // removing the url removes the file
248
-				}
249
-
250
-			}
251
-
252
-			return $url;
253
-		}
254
-
255
-		/**
256
-		 * Register the database settings with WordPress.
257
-		 */
258
-		public function register_settings() {
259
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
-		}
261
-
262
-		/**
263
-		 * Add the WordPress settings menu item.
264
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
-		 */
266
-		public function menu_item() {
267
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
-				$this,
270
-				'settings_page'
271
-			) );
272
-		}
273
-
274
-		/**
275
-		 * Get the current Font Awesome output settings.
276
-		 *
277
-		 * @return array The array of settings.
278
-		 */
279
-		public function get_settings() {
280
-
281
-			$db_settings = get_option( 'wp-font-awesome-settings' );
282
-
283
-			$defaults = array(
284
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
285
-				'version'   => '', // latest
286
-				'enqueue'   => '', // front and backend
287
-				'shims'     => '0', // default OFF now in 2020
288
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
-				'pro'       => '0', // if pro CDN url should be used
291
-				'kit-url'   => '', // the kit url
292
-			);
293
-
294
-			$settings = wp_parse_args( $db_settings, $defaults );
295
-
296
-			/**
297
-			 * Filter the Font Awesome settings.
298
-			 *
299
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
-			 */
301
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
-		}
303
-
304
-
305
-		/**
306
-		 * The settings page html output.
307
-		 */
308
-		public function settings_page() {
309
-			if ( ! current_user_can( 'manage_options' ) ) {
310
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
-			}
312
-
313
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
315
-				$this->get_latest_version( $force_api = true );
316
-			}
317
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @ver 1.0.13
33
+     * @todo decide how to implement textdomain
34
+     */
35
+    class WP_Font_Awesome_Settings {
36
+
37
+        /**
38
+         * Class version version.
39
+         *
40
+         * @var string
41
+         */
42
+        public $version = '1.0.13';
43
+
44
+        /**
45
+         * Class textdomain.
46
+         *
47
+         * @var string
48
+         */
49
+        public $textdomain = 'font-awesome-settings';
50
+
51
+        /**
52
+         * Latest version of Font Awesome at time of publish published.
53
+         *
54
+         * @var string
55
+         */
56
+        public $latest = "5.8.2";
57
+
58
+        /**
59
+         * The title.
60
+         *
61
+         * @var string
62
+         */
63
+        public $name = 'Font Awesome';
64
+
65
+        /**
66
+         * Holds the settings values.
67
+         *
68
+         * @var array
69
+         */
70
+        private $settings;
71
+
72
+        /**
73
+         * WP_Font_Awesome_Settings instance.
74
+         *
75
+         * @access private
76
+         * @since  1.0.0
77
+         * @var    WP_Font_Awesome_Settings There can be only one!
78
+         */
79
+        private static $instance = null;
80
+
81
+        /**
82
+         * Main WP_Font_Awesome_Settings Instance.
83
+         *
84
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
85
+         *
86
+         * @since 1.0.0
87
+         * @static
88
+         * @return WP_Font_Awesome_Settings - Main instance.
89
+         */
90
+        public static function instance() {
91
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
92
+                self::$instance = new WP_Font_Awesome_Settings;
93
+
94
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
95
+
96
+                if ( is_admin() ) {
97
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
98
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
99
+                }
100
+
101
+                do_action( 'wp_font_awesome_settings_loaded' );
102
+            }
103
+
104
+            return self::$instance;
105
+        }
106
+
107
+        /**
108
+         * Initiate the settings and add the required action hooks.
109
+         *
110
+         * @since 1.0.8 Settings name wrong - FIXED
111
+         */
112
+        public function init() {
113
+            $this->settings = $this->get_settings();
114
+
115
+            if ( $this->settings['type'] == 'CSS' ) {
116
+
117
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
118
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
119
+                }
120
+
121
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
122
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
123
+                }
124
+
125
+            } else {
126
+
127
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
128
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
129
+                }
130
+
131
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
132
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
133
+                }
134
+            }
135
+
136
+            // remove font awesome if set to do so
137
+            if ( $this->settings['dequeue'] == '1' ) {
138
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
139
+            }
140
+
141
+        }
142
+
143
+        /**
144
+         * Adds the Font Awesome styles.
145
+         */
146
+        public function enqueue_style() {
147
+            // build url
148
+            $url = $this->get_url();
149
+
150
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
151
+            wp_register_style( 'font-awesome', $url, array(), null );
152
+            wp_enqueue_style( 'font-awesome' );
153
+
154
+            // RTL language support CSS.
155
+            if ( is_rtl() ) {
156
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
157
+            }
158
+
159
+            if ( $this->settings['shims'] ) {
160
+                $url = $this->get_url( true );
161
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
162
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
163
+                wp_enqueue_style( 'font-awesome-shims' );
164
+            }
165
+        }
166
+
167
+        /**
168
+         * Adds the Font Awesome JS.
169
+         */
170
+        public function enqueue_scripts() {
171
+            // build url
172
+            $url = $this->get_url();
173
+
174
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
175
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
176
+            wp_register_script( 'font-awesome', $url, array(), null );
177
+            wp_enqueue_script( 'font-awesome' );
178
+
179
+            if ( $this->settings['shims'] ) {
180
+                $url = $this->get_url( true );
181
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
182
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
183
+                wp_enqueue_script( 'font-awesome-shims' );
184
+            }
185
+        }
186
+
187
+        /**
188
+         * Get the url of the Font Awesome files.
189
+         *
190
+         * @param bool $shims If this is a shim file or not.
191
+         *
192
+         * @return string The url to the file.
193
+         */
194
+        public function get_url( $shims = false ) {
195
+            $script  = $shims ? 'v4-shims' : 'all';
196
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
197
+            $type    = $this->settings['type'];
198
+            $version = $this->settings['version'];
199
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
200
+            $url     = '';
201
+
202
+            if ( $type == 'KIT' && $kit_url ) {
203
+                if ( $shims ) {
204
+                    // if its a kit then we don't add shims here
205
+                    return '';
206
+                }
207
+                $url .= $kit_url; // CDN
208
+                $url .= "?wpfas=true"; // set our var so our version is not removed
209
+            } else {
210
+                $url .= "https://$sub.fontawesome.com/releases/"; // CDN
211
+                $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
212
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
213
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
214
+                $url .= "?wpfas=true"; // set our var so our version is not removed
215
+            }
216
+
217
+            return $url;
218
+        }
219
+
220
+        /**
221
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
222
+         *
223
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
224
+         *
225
+         * @param $url
226
+         * @param $original_url
227
+         * @param $_context
228
+         *
229
+         * @return string The filtered url.
230
+         */
231
+        public function remove_font_awesome( $url, $original_url, $_context ) {
232
+
233
+            if ( $_context == 'display'
234
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
235
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
236
+            ) {// it's a font-awesome-url (probably)
237
+
238
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
239
+                    if ( $this->settings['type'] == 'JS' ) {
240
+                        if ( $this->settings['js-pseudo'] ) {
241
+                            $url .= "' data-search-pseudo-elements defer='defer";
242
+                        } else {
243
+                            $url .= "' defer='defer";
244
+                        }
245
+                    }
246
+                } else {
247
+                    $url = ''; // removing the url removes the file
248
+                }
249
+
250
+            }
251
+
252
+            return $url;
253
+        }
254
+
255
+        /**
256
+         * Register the database settings with WordPress.
257
+         */
258
+        public function register_settings() {
259
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
260
+        }
261
+
262
+        /**
263
+         * Add the WordPress settings menu item.
264
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
265
+         */
266
+        public function menu_item() {
267
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
268
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
269
+                $this,
270
+                'settings_page'
271
+            ) );
272
+        }
273
+
274
+        /**
275
+         * Get the current Font Awesome output settings.
276
+         *
277
+         * @return array The array of settings.
278
+         */
279
+        public function get_settings() {
280
+
281
+            $db_settings = get_option( 'wp-font-awesome-settings' );
282
+
283
+            $defaults = array(
284
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
285
+                'version'   => '', // latest
286
+                'enqueue'   => '', // front and backend
287
+                'shims'     => '0', // default OFF now in 2020
288
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
289
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
290
+                'pro'       => '0', // if pro CDN url should be used
291
+                'kit-url'   => '', // the kit url
292
+            );
293
+
294
+            $settings = wp_parse_args( $db_settings, $defaults );
295
+
296
+            /**
297
+             * Filter the Font Awesome settings.
298
+             *
299
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
300
+             */
301
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
302
+        }
303
+
304
+
305
+        /**
306
+         * The settings page html output.
307
+         */
308
+        public function settings_page() {
309
+            if ( ! current_user_can( 'manage_options' ) ) {
310
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
311
+            }
312
+
313
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
314
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
315
+                $this->get_latest_version( $force_api = true );
316
+            }
317
+            ?>
318 318
 			<style>
319 319
 				.wpfas-kit-show {
320 320
 					display: none;
@@ -332,10 +332,10 @@  discard block
 block discarded – undo
332 332
 				<h1><?php echo $this->name; ?></h1>
333 333
 				<form method="post" action="options.php">
334 334
 					<?php
335
-					settings_fields( 'wp-font-awesome-settings' );
336
-					do_settings_sections( 'wp-font-awesome-settings' );
337
-					$kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
-					?>
335
+                    settings_fields( 'wp-font-awesome-settings' );
336
+                    do_settings_sections( 'wp-font-awesome-settings' );
337
+                    $kit_set = $this->settings['type'] == 'KIT' ? 'wpfas-kit-set' : '';
338
+                    ?>
339 339
 					<table class="form-table wpfas-table-settings <?php echo esc_attr( $kit_set ); ?>">
340 340
 						<tr valign="top">
341 341
 							<th scope="row"><label
@@ -361,12 +361,12 @@  discard block
 block discarded – undo
361 361
 								       value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>"
362 362
 								       placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
363 363
 								<span><?php
364
-									echo sprintf(
365
-										__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
-										'</a>'
368
-									);
369
-									?></span>
364
+                                    echo sprintf(
365
+                                        __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
366
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
367
+                                        '</a>'
368
+                                    );
369
+                                    ?></span>
370 370
 							</td>
371 371
 						</tr>
372 372
 
@@ -426,14 +426,14 @@  discard block
 block discarded – undo
426 426
 								<input type="checkbox" name="wp-font-awesome-settings[pro]"
427 427
 								       value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro"/>
428 428
 								<span><?php
429
-									echo sprintf(
430
-										__( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
-										'</a>',
433
-										'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
-										'</a>'
435
-									);
436
-									?></span>
429
+                                    echo sprintf(
430
+                                        __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ),
431
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/pro"><i class="fas fa-external-link-alt"></i>',
432
+                                        '</a>',
433
+                                        '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn"><i class="fas fa-external-link-alt"></i>',
434
+                                        '</a>'
435
+                                    );
436
+                                    ?></span>
437 437
 							</td>
438 438
 						</tr>
439 439
 
@@ -476,100 +476,100 @@  discard block
 block discarded – undo
476 476
 
477 477
 					</table>
478 478
 					<?php
479
-					submit_button();
480
-					?>
479
+                    submit_button();
480
+                    ?>
481 481
 				</form>
482 482
 
483 483
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
484 484
 			</div>
485 485
 
486 486
 			<?php
487
-		}
488
-
489
-		/**
490
-		 * Check a version number is valid and if so return it or else return an empty string.
491
-		 *
492
-		 * @param $version string The version number to check.
493
-		 *
494
-		 * @since 1.0.6
495
-		 *
496
-		 * @return string Either a valid version number or an empty string.
497
-		 */
498
-		public function validate_version_number( $version ) {
499
-
500
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
-				// valid
502
-			} else {
503
-				$version = '';// not validated
504
-			}
505
-
506
-			return $version;
507
-		}
508
-
509
-
510
-		/**
511
-		 * Get the latest version of Font Awesome.
512
-		 *
513
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
-		 *
515
-		 * @since 1.0.7
516
-		 * @return mixed|string The latest version number found.
517
-		 */
518
-		public function get_latest_version( $force_api = false ) {
519
-			$latest_version = $this->latest;
520
-
521
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
522
-
523
-			if ( $cache === false || $force_api ) { // its not set
524
-				$api_ver = $this->get_latest_version_from_api();
525
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
-					$latest_version = $api_ver;
527
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
-				}
529
-			} elseif ( $this->validate_version_number( $cache ) ) {
530
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
-					$latest_version = $cache;
532
-				}
533
-			}
534
-
535
-			return $latest_version;
536
-		}
537
-
538
-		/**
539
-		 * Get the latest Font Awesome version from the github API.
540
-		 *
541
-		 * @since 1.0.7
542
-		 * @return string The latest version number or `0` on API fail.
543
-		 */
544
-		public function get_latest_version_from_api() {
545
-			$version  = "0";
546
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
-					$version = $api_response['tag_name'];
551
-				}
552
-			}
553
-
554
-			return $version;
555
-		}
556
-
557
-		/**
558
-		 * Inline CSS for RTL language support.
559
-		 *
560
-		 * @since 1.0.13
561
-		 * @return string Inline CSS.
562
-		 */
563
-		public function rtl_inline_css() {
564
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
-
566
-			return $inline_css;
567
-		}
568
-
569
-	}
570
-
571
-	/**
572
-	 * Run the class if found.
573
-	 */
574
-	WP_Font_Awesome_Settings::instance();
487
+        }
488
+
489
+        /**
490
+         * Check a version number is valid and if so return it or else return an empty string.
491
+         *
492
+         * @param $version string The version number to check.
493
+         *
494
+         * @since 1.0.6
495
+         *
496
+         * @return string Either a valid version number or an empty string.
497
+         */
498
+        public function validate_version_number( $version ) {
499
+
500
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
501
+                // valid
502
+            } else {
503
+                $version = '';// not validated
504
+            }
505
+
506
+            return $version;
507
+        }
508
+
509
+
510
+        /**
511
+         * Get the latest version of Font Awesome.
512
+         *
513
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
514
+         *
515
+         * @since 1.0.7
516
+         * @return mixed|string The latest version number found.
517
+         */
518
+        public function get_latest_version( $force_api = false ) {
519
+            $latest_version = $this->latest;
520
+
521
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
522
+
523
+            if ( $cache === false || $force_api ) { // its not set
524
+                $api_ver = $this->get_latest_version_from_api();
525
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
526
+                    $latest_version = $api_ver;
527
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
528
+                }
529
+            } elseif ( $this->validate_version_number( $cache ) ) {
530
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
531
+                    $latest_version = $cache;
532
+                }
533
+            }
534
+
535
+            return $latest_version;
536
+        }
537
+
538
+        /**
539
+         * Get the latest Font Awesome version from the github API.
540
+         *
541
+         * @since 1.0.7
542
+         * @return string The latest version number or `0` on API fail.
543
+         */
544
+        public function get_latest_version_from_api() {
545
+            $version  = "0";
546
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
547
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
548
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
549
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
550
+                    $version = $api_response['tag_name'];
551
+                }
552
+            }
553
+
554
+            return $version;
555
+        }
556
+
557
+        /**
558
+         * Inline CSS for RTL language support.
559
+         *
560
+         * @since 1.0.13
561
+         * @return string Inline CSS.
562
+         */
563
+        public function rtl_inline_css() {
564
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
565
+
566
+            return $inline_css;
567
+        }
568
+
569
+    }
570
+
571
+    /**
572
+     * Run the class if found.
573
+     */
574
+    WP_Font_Awesome_Settings::instance();
575 575
 }
576 576
\ No newline at end of file
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +477 added lines, -477 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,542 +15,542 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'_wpinv_phone',
34
-		'_wpinv_company_id',
35
-		'wpinv_email_cc',
36
-		'wpinv_template',
37
-		'wpinv_created_via'
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
-		'_wpinv_subscription_id'   => 'subscription_id',
50
-		'_wpinv_taxes'             => 'taxes',
51
-		'_wpinv_fees'              => 'fees',
52
-		'_wpinv_discounts'         => 'discounts',
53
-		'_wpinv_submission_id'     => 'submission_id',
54
-		'_wpinv_payment_form'      => 'payment_form',
55
-		'_wpinv_is_viewed'         => 'is_viewed',
56
-		'wpinv_email_cc'           => 'email_cc',
57
-		'wpinv_template'           => 'template',
58
-		'wpinv_created_via'        => 'created_via',
59
-		'_wpinv_phone'             => 'phone',
60
-		'_wpinv_company_id'        => 'company_id',
61
-	);
62
-
63
-	/**
64
-	 * A map of database fields to data props.
65
-	 *
66
-	 * @since 1.0.19
67
-	 *
68
-	 * @var array
69
-	 */
70
-	protected $database_fields_to_props = array(
71
-		'post_id'            => 'id',
72
-		'number'             => 'number',
73
-		'currency'           => 'currency',
74
-		'key'                => 'key',
75
-		'type'               => 'type',
76
-		'mode'               => 'mode',
77
-		'user_ip'            => 'user_ip',
78
-		'first_name'         => 'first_name',
79
-		'last_name'          => 'last_name',
80
-		'address'            => 'address',
81
-		'city'               => 'city',
82
-		'state'              => 'state',
83
-		'country'            => 'country',
84
-		'zip'                => 'zip',
85
-		'zip'                => 'zip',
86
-		'adddress_confirmed' => 'address_confirmed',
87
-		'gateway'            => 'gateway',
88
-		'transaction_id'     => 'transaction_id',
89
-		'currency'           => 'currency',
90
-		'subtotal'           => 'subtotal',
91
-		'tax'                => 'total_tax',
92
-		'fees_total'         => 'total_fees',
93
-		'discount'           => 'total_discount',
94
-		'total'              => 'total',
95
-		'discount_code'      => 'discount_code',
96
-		'disable_taxes'      => 'disable_taxes',
97
-		'due_date'           => 'due_date',
98
-		'completed_date'     => 'completed_date',
99
-		'company'            => 'company',
100
-		'vat_number'         => 'vat_number',
101
-		'vat_rate'           => 'vat_rate',
102
-	);
103
-
104
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        '_wpinv_phone',
34
+        '_wpinv_company_id',
35
+        'wpinv_email_cc',
36
+        'wpinv_template',
37
+        'wpinv_created_via'
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
49
+        '_wpinv_subscription_id'   => 'subscription_id',
50
+        '_wpinv_taxes'             => 'taxes',
51
+        '_wpinv_fees'              => 'fees',
52
+        '_wpinv_discounts'         => 'discounts',
53
+        '_wpinv_submission_id'     => 'submission_id',
54
+        '_wpinv_payment_form'      => 'payment_form',
55
+        '_wpinv_is_viewed'         => 'is_viewed',
56
+        'wpinv_email_cc'           => 'email_cc',
57
+        'wpinv_template'           => 'template',
58
+        'wpinv_created_via'        => 'created_via',
59
+        '_wpinv_phone'             => 'phone',
60
+        '_wpinv_company_id'        => 'company_id',
61
+    );
62
+
63
+    /**
64
+     * A map of database fields to data props.
65
+     *
66
+     * @since 1.0.19
67
+     *
68
+     * @var array
69
+     */
70
+    protected $database_fields_to_props = array(
71
+        'post_id'            => 'id',
72
+        'number'             => 'number',
73
+        'currency'           => 'currency',
74
+        'key'                => 'key',
75
+        'type'               => 'type',
76
+        'mode'               => 'mode',
77
+        'user_ip'            => 'user_ip',
78
+        'first_name'         => 'first_name',
79
+        'last_name'          => 'last_name',
80
+        'address'            => 'address',
81
+        'city'               => 'city',
82
+        'state'              => 'state',
83
+        'country'            => 'country',
84
+        'zip'                => 'zip',
85
+        'zip'                => 'zip',
86
+        'adddress_confirmed' => 'address_confirmed',
87
+        'gateway'            => 'gateway',
88
+        'transaction_id'     => 'transaction_id',
89
+        'currency'           => 'currency',
90
+        'subtotal'           => 'subtotal',
91
+        'tax'                => 'total_tax',
92
+        'fees_total'         => 'total_fees',
93
+        'discount'           => 'total_discount',
94
+        'total'              => 'total',
95
+        'discount_code'      => 'discount_code',
96
+        'disable_taxes'      => 'disable_taxes',
97
+        'due_date'           => 'due_date',
98
+        'completed_date'     => 'completed_date',
99
+        'company'            => 'company',
100
+        'vat_number'         => 'vat_number',
101
+        'vat_rate'           => 'vat_rate',
102
+    );
103
+
104
+    /*
105 105
 	|--------------------------------------------------------------------------
106 106
 	| CRUD Methods
107 107
 	|--------------------------------------------------------------------------
108 108
 	*/
109 109
 
110
-	/**
111
-	 * Method to create a new invoice in the database.
112
-	 *
113
-	 * @param WPInv_Invoice $invoice Invoice object.
114
-	 */
115
-	public function create( &$invoice ) {
116
-		$invoice->set_version( WPINV_VERSION );
117
-		$invoice->set_date_created( current_time('mysql') );
118
-
119
-		// Create a new post.
120
-		$id = wp_insert_post(
121
-			apply_filters(
122
-				'getpaid_new_invoice_data',
123
-				array(
124
-					'post_date'     => $invoice->get_date_created( 'edit' ),
125
-					'post_type'     => $invoice->get_post_type( 'edit' ),
126
-					'post_status'   => $this->get_post_status( $invoice ),
127
-					'ping_status'   => 'closed',
128
-					'post_author'   => $invoice->get_user_id( 'edit' ),
129
-					'post_title'    => $invoice->get_title( 'edit' ),
130
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
131
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
-				)
133
-			),
134
-			true
135
-		);
136
-
137
-		if ( $id && ! is_wp_error( $id ) ) {
138
-
139
-			// Update the new id and regenerate a title.
140
-			$invoice->set_id( $id );
141
-
142
-			$invoice->maybe_set_number();
143
-
144
-			wp_update_post(
145
-				array(
146
-					'ID'         => $invoice->get_id(),
147
-					'post_title' => $invoice->get_number( 'edit' ),
148
-					'post_name'  => $invoice->get_path( 'edit' )
149
-				)
150
-			);
151
-
152
-			// Save special fields and items.
153
-			$this->save_special_fields( $invoice );
154
-			$this->save_items( $invoice );
155
-
156
-			// Update meta data.
157
-			$this->update_post_meta( $invoice );
158
-			$invoice->save_meta_data();
159
-
160
-			// Apply changes.
161
-			$invoice->apply_changes();
162
-			$this->clear_caches( $invoice );
163
-
164
-			// Fires after a new invoice is created.
165
-			do_action( 'getpaid_new_invoice', $invoice );
166
-			return true;
167
-		}
168
-
169
-		if ( is_wp_error( $id ) ) {
170
-			$invoice->last_error = $id->get_error_message();
171
-		}
172
-
173
-		return false;
174
-	}
175
-
176
-	/**
177
-	 * Method to read an invoice from the database.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 *
181
-	 */
182
-	public function read( &$invoice ) {
183
-
184
-		$invoice->set_defaults();
185
-		$invoice_object = get_post( $invoice->get_id() );
186
-
187
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
-			$invoice->set_id( 0 );
190
-			return false;
191
-		}
192
-
193
-		$invoice->set_props(
194
-			array(
195
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
-				'status'        => $invoice_object->post_status,
198
-				'author'        => $invoice_object->post_author,
199
-				'description'   => $invoice_object->post_excerpt,
200
-				'parent_id'     => $invoice_object->post_parent,
201
-				'name'          => $invoice_object->post_title,
202
-				'path'          => $invoice_object->post_name,
203
-				'post_type'     => $invoice_object->post_type,
204
-			)
205
-		);
206
-
207
-		$invoice->set_type( $invoice_object->post_type );
208
-
209
-		$this->read_object_data( $invoice, $invoice_object );
210
-		$this->add_special_fields( $invoice );
211
-		$this->add_items( $invoice );
212
-		$invoice->read_meta_data();
213
-		$invoice->set_object_read( true );
214
-		do_action( 'getpaid_read_invoice', $invoice );
215
-
216
-	}
217
-
218
-	/**
219
-	 * Method to update an invoice in the database.
220
-	 *
221
-	 * @param WPInv_Invoice $invoice Invoice object.
222
-	 */
223
-	public function update( &$invoice ) {
224
-		$invoice->save_meta_data();
225
-		$invoice->set_version( WPINV_VERSION );
226
-
227
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
228
-			$invoice->set_date_created(  current_time('mysql') );
229
-		}
230
-
231
-		// Ensure both the key and number are set.
232
-		$invoice->get_path();
233
-
234
-		// Grab the current status so we can compare.
235
-		$previous_status = get_post_status( $invoice->get_id() );
236
-
237
-		$changes = $invoice->get_changes();
238
-
239
-		// Only update the post when the post data changes.
240
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
-			$post_data = array(
242
-				'post_date'         => $invoice->get_date_created( 'edit' ),
243
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
-				'post_status'       => $invoice->get_status( 'edit' ),
245
-				'post_title'        => $invoice->get_name( 'edit' ),
246
-				'post_author'       => $invoice->get_user_id( 'edit' ),
247
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
249
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
-				'post_name'         => $invoice->get_path( 'edit' ),
251
-				'post_type'         => $invoice->get_post_type( 'edit' ),
252
-			);
253
-
254
-			/**
255
-			 * When updating this object, to prevent infinite loops, use $wpdb
256
-			 * to update data, since wp_update_post spawns more calls to the
257
-			 * save_post action.
258
-			 *
259
-			 * This ensures hooks are fired by either WP itself (admin screen save),
260
-			 * or an update purely from CRUD.
261
-			 */
262
-			if ( doing_action( 'save_post' ) ) {
263
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
-				clean_post_cache( $invoice->get_id() );
265
-			} else {
266
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
-			}
268
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
-		}
270
-
271
-		// Update meta data.
272
-		$this->update_post_meta( $invoice );
273
-
274
-		// Save special fields and items.
275
-		$this->save_special_fields( $invoice );
276
-		$this->save_items( $invoice );
277
-
278
-		// Apply the changes.
279
-		$invoice->apply_changes();
280
-
281
-		// Clear caches.
282
-		$this->clear_caches( $invoice );
283
-
284
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
-		$new_status = $invoice->get_status( 'edit' );
286
-
287
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
-			do_action( 'getpaid_new_invoice', $invoice );
289
-		} else {
290
-			do_action( 'getpaid_update_invoice', $invoice );
291
-		}
292
-
293
-	}
294
-
295
-	/*
110
+    /**
111
+     * Method to create a new invoice in the database.
112
+     *
113
+     * @param WPInv_Invoice $invoice Invoice object.
114
+     */
115
+    public function create( &$invoice ) {
116
+        $invoice->set_version( WPINV_VERSION );
117
+        $invoice->set_date_created( current_time('mysql') );
118
+
119
+        // Create a new post.
120
+        $id = wp_insert_post(
121
+            apply_filters(
122
+                'getpaid_new_invoice_data',
123
+                array(
124
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
125
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
126
+                    'post_status'   => $this->get_post_status( $invoice ),
127
+                    'ping_status'   => 'closed',
128
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
129
+                    'post_title'    => $invoice->get_title( 'edit' ),
130
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
131
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
132
+                )
133
+            ),
134
+            true
135
+        );
136
+
137
+        if ( $id && ! is_wp_error( $id ) ) {
138
+
139
+            // Update the new id and regenerate a title.
140
+            $invoice->set_id( $id );
141
+
142
+            $invoice->maybe_set_number();
143
+
144
+            wp_update_post(
145
+                array(
146
+                    'ID'         => $invoice->get_id(),
147
+                    'post_title' => $invoice->get_number( 'edit' ),
148
+                    'post_name'  => $invoice->get_path( 'edit' )
149
+                )
150
+            );
151
+
152
+            // Save special fields and items.
153
+            $this->save_special_fields( $invoice );
154
+            $this->save_items( $invoice );
155
+
156
+            // Update meta data.
157
+            $this->update_post_meta( $invoice );
158
+            $invoice->save_meta_data();
159
+
160
+            // Apply changes.
161
+            $invoice->apply_changes();
162
+            $this->clear_caches( $invoice );
163
+
164
+            // Fires after a new invoice is created.
165
+            do_action( 'getpaid_new_invoice', $invoice );
166
+            return true;
167
+        }
168
+
169
+        if ( is_wp_error( $id ) ) {
170
+            $invoice->last_error = $id->get_error_message();
171
+        }
172
+
173
+        return false;
174
+    }
175
+
176
+    /**
177
+     * Method to read an invoice from the database.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     *
181
+     */
182
+    public function read( &$invoice ) {
183
+
184
+        $invoice->set_defaults();
185
+        $invoice_object = get_post( $invoice->get_id() );
186
+
187
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
188
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
189
+            $invoice->set_id( 0 );
190
+            return false;
191
+        }
192
+
193
+        $invoice->set_props(
194
+            array(
195
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
196
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
197
+                'status'        => $invoice_object->post_status,
198
+                'author'        => $invoice_object->post_author,
199
+                'description'   => $invoice_object->post_excerpt,
200
+                'parent_id'     => $invoice_object->post_parent,
201
+                'name'          => $invoice_object->post_title,
202
+                'path'          => $invoice_object->post_name,
203
+                'post_type'     => $invoice_object->post_type,
204
+            )
205
+        );
206
+
207
+        $invoice->set_type( $invoice_object->post_type );
208
+
209
+        $this->read_object_data( $invoice, $invoice_object );
210
+        $this->add_special_fields( $invoice );
211
+        $this->add_items( $invoice );
212
+        $invoice->read_meta_data();
213
+        $invoice->set_object_read( true );
214
+        do_action( 'getpaid_read_invoice', $invoice );
215
+
216
+    }
217
+
218
+    /**
219
+     * Method to update an invoice in the database.
220
+     *
221
+     * @param WPInv_Invoice $invoice Invoice object.
222
+     */
223
+    public function update( &$invoice ) {
224
+        $invoice->save_meta_data();
225
+        $invoice->set_version( WPINV_VERSION );
226
+
227
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
228
+            $invoice->set_date_created(  current_time('mysql') );
229
+        }
230
+
231
+        // Ensure both the key and number are set.
232
+        $invoice->get_path();
233
+
234
+        // Grab the current status so we can compare.
235
+        $previous_status = get_post_status( $invoice->get_id() );
236
+
237
+        $changes = $invoice->get_changes();
238
+
239
+        // Only update the post when the post data changes.
240
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
241
+            $post_data = array(
242
+                'post_date'         => $invoice->get_date_created( 'edit' ),
243
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
244
+                'post_status'       => $invoice->get_status( 'edit' ),
245
+                'post_title'        => $invoice->get_name( 'edit' ),
246
+                'post_author'       => $invoice->get_user_id( 'edit' ),
247
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
248
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
249
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
250
+                'post_name'         => $invoice->get_path( 'edit' ),
251
+                'post_type'         => $invoice->get_post_type( 'edit' ),
252
+            );
253
+
254
+            /**
255
+             * When updating this object, to prevent infinite loops, use $wpdb
256
+             * to update data, since wp_update_post spawns more calls to the
257
+             * save_post action.
258
+             *
259
+             * This ensures hooks are fired by either WP itself (admin screen save),
260
+             * or an update purely from CRUD.
261
+             */
262
+            if ( doing_action( 'save_post' ) ) {
263
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
264
+                clean_post_cache( $invoice->get_id() );
265
+            } else {
266
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
267
+            }
268
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
269
+        }
270
+
271
+        // Update meta data.
272
+        $this->update_post_meta( $invoice );
273
+
274
+        // Save special fields and items.
275
+        $this->save_special_fields( $invoice );
276
+        $this->save_items( $invoice );
277
+
278
+        // Apply the changes.
279
+        $invoice->apply_changes();
280
+
281
+        // Clear caches.
282
+        $this->clear_caches( $invoice );
283
+
284
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
285
+        $new_status = $invoice->get_status( 'edit' );
286
+
287
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
288
+            do_action( 'getpaid_new_invoice', $invoice );
289
+        } else {
290
+            do_action( 'getpaid_update_invoice', $invoice );
291
+        }
292
+
293
+    }
294
+
295
+    /*
296 296
 	|--------------------------------------------------------------------------
297 297
 	| Additional Methods
298 298
 	|--------------------------------------------------------------------------
299 299
 	*/
300 300
 
301
-	/**
301
+    /**
302 302
      * Retrieves special fields and adds to the invoice.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice Invoice object.
303
+     *
304
+     * @param WPInv_Invoice $invoice Invoice object.
305 305
      */
306 306
     public function add_special_fields( &$invoice ) {
307
-		global $wpdb;
307
+        global $wpdb;
308 308
 
309
-		// Maybe retrieve from the cache.
310
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
309
+        // Maybe retrieve from the cache.
310
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
311 311
 
312
-		// If not found, retrieve from the db.
313
-		if ( false === $data ) {
314
-			$table =  $wpdb->prefix . 'getpaid_invoices';
312
+        // If not found, retrieve from the db.
313
+        if ( false === $data ) {
314
+            $table =  $wpdb->prefix . 'getpaid_invoices';
315 315
 
316
-			$data  = $wpdb->get_row(
317
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
-				ARRAY_A
319
-			);
316
+            $data  = $wpdb->get_row(
317
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
318
+                ARRAY_A
319
+            );
320 320
 
321
-			// Update the cache with our data
322
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
321
+            // Update the cache with our data
322
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
323 323
 
324
-		}
324
+        }
325 325
 
326
-		// Abort if the data does not exist.
327
-		if ( empty( $data ) ) {
328
-			$invoice->set_object_read( true );
329
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
-			return;
331
-		}
326
+        // Abort if the data does not exist.
327
+        if ( empty( $data ) ) {
328
+            $invoice->set_object_read( true );
329
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
330
+            return;
331
+        }
332 332
 
333
-		$props = array();
333
+        $props = array();
334 334
 
335
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
335
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
336 336
 			
337
-			if ( $db_field == 'post_id' ) {
338
-				continue;
339
-			}
340
-
341
-			$props[ $prop ] = $data[ $db_field ];
342
-		}
343
-
344
-		$invoice->set_props( $props );
345
-
346
-	}
347
-
348
-	/**
349
-	 * Gets a list of special fields that need updated based on change state
350
-	 * or if they are present in the database or not.
351
-	 *
352
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
353
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
-	 */
355
-	protected function get_special_fields_to_update( $invoice ) {
356
-		$fields_to_update = array();
357
-		$changed_props   = $invoice->get_changes();
358
-
359
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
360
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
-			if ( array_key_exists( $prop, $changed_props ) ) {
362
-				$fields_to_update[ $database_field ] = $prop;
363
-			}
364
-		}
365
-
366
-		return $fields_to_update;
367
-	}
368
-
369
-	/**
370
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
-	 *
372
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
-	 * @since 1.0.19
374
-	 */
375
-	protected function update_special_fields( &$invoice ) {
376
-		global $wpdb;
377
-
378
-		$updated_props    = array();
379
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
380
-
381
-		foreach ( $fields_to_update as $database_field => $prop ) {
382
-			$value = $invoice->{"get_$prop"}( 'edit' );
383
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
384
-			$value = is_bool( $value ) ? ( int ) $value : $value;
385
-			$updated_props[ $database_field ] = maybe_serialize( $value );
386
-		}
387
-
388
-		if ( ! empty( $updated_props ) ) {
389
-
390
-			$table = $wpdb->prefix . 'getpaid_invoices';
391
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
-
395
-		}
396
-
397
-	}
398
-
399
-	/**
400
-	 * Helper method that inserts special fields to the database.
401
-	 *
402
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
-	 * @since 1.0.19
404
-	 */
405
-	protected function insert_special_fields( &$invoice ) {
406
-		global $wpdb;
407
-
408
-		$updated_props   = array();
409
-
410
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
-			$value = $invoice->{"get_$prop"}( 'edit' );
412
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
413
-			$value = is_bool( $value ) ? ( int ) $value : $value;
414
-			$updated_props[ $database_field ] = maybe_serialize( $value );
415
-		}
416
-
417
-		$table = $wpdb->prefix . 'getpaid_invoices';
418
-		$wpdb->insert( $table, $updated_props );
419
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
-
422
-	}
423
-
424
-	/**
337
+            if ( $db_field == 'post_id' ) {
338
+                continue;
339
+            }
340
+
341
+            $props[ $prop ] = $data[ $db_field ];
342
+        }
343
+
344
+        $invoice->set_props( $props );
345
+
346
+    }
347
+
348
+    /**
349
+     * Gets a list of special fields that need updated based on change state
350
+     * or if they are present in the database or not.
351
+     *
352
+     * @param  WPInv_Invoice $invoice       The Invoice object.
353
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
354
+     */
355
+    protected function get_special_fields_to_update( $invoice ) {
356
+        $fields_to_update = array();
357
+        $changed_props   = $invoice->get_changes();
358
+
359
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
360
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
361
+            if ( array_key_exists( $prop, $changed_props ) ) {
362
+                $fields_to_update[ $database_field ] = $prop;
363
+            }
364
+        }
365
+
366
+        return $fields_to_update;
367
+    }
368
+
369
+    /**
370
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
371
+     *
372
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
373
+     * @since 1.0.19
374
+     */
375
+    protected function update_special_fields( &$invoice ) {
376
+        global $wpdb;
377
+
378
+        $updated_props    = array();
379
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
380
+
381
+        foreach ( $fields_to_update as $database_field => $prop ) {
382
+            $value = $invoice->{"get_$prop"}( 'edit' );
383
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
384
+            $value = is_bool( $value ) ? ( int ) $value : $value;
385
+            $updated_props[ $database_field ] = maybe_serialize( $value );
386
+        }
387
+
388
+        if ( ! empty( $updated_props ) ) {
389
+
390
+            $table = $wpdb->prefix . 'getpaid_invoices';
391
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
392
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
393
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
394
+
395
+        }
396
+
397
+    }
398
+
399
+    /**
400
+     * Helper method that inserts special fields to the database.
401
+     *
402
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
403
+     * @since 1.0.19
404
+     */
405
+    protected function insert_special_fields( &$invoice ) {
406
+        global $wpdb;
407
+
408
+        $updated_props   = array();
409
+
410
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
411
+            $value = $invoice->{"get_$prop"}( 'edit' );
412
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
413
+            $value = is_bool( $value ) ? ( int ) $value : $value;
414
+            $updated_props[ $database_field ] = maybe_serialize( $value );
415
+        }
416
+
417
+        $table = $wpdb->prefix . 'getpaid_invoices';
418
+        $wpdb->insert( $table, $updated_props );
419
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
420
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
421
+
422
+    }
423
+
424
+    /**
425 425
      * Saves all special fields.
426
-	 *
427
-	 * @param WPInv_Invoice $invoice Invoice object.
426
+     *
427
+     * @param WPInv_Invoice $invoice Invoice object.
428 428
      */
429 429
     public function save_special_fields( & $invoice ) {
430
-		global $wpdb;
430
+        global $wpdb;
431 431
 
432
-		// The invoices table.
433
-		$table = $wpdb->prefix . 'getpaid_invoices';
434
-		$id    = (int) $invoice->get_id();
435
-		$invoice->maybe_set_key();
432
+        // The invoices table.
433
+        $table = $wpdb->prefix . 'getpaid_invoices';
434
+        $id    = (int) $invoice->get_id();
435
+        $invoice->maybe_set_key();
436 436
 
437
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
437
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
438 438
 
439
-			$this->update_special_fields( $invoice );
439
+            $this->update_special_fields( $invoice );
440 440
 
441
-		} else {
441
+        } else {
442 442
 
443
-			$this->insert_special_fields( $invoice );
443
+            $this->insert_special_fields( $invoice );
444 444
 
445
-		}
445
+        }
446 446
 
447
-	}
447
+    }
448 448
 
449
-	/**
449
+    /**
450 450
      * Set's up cart details.
451
-	 *
452
-	 * @param WPInv_Invoice $invoice Invoice object.
451
+     *
452
+     * @param WPInv_Invoice $invoice Invoice object.
453 453
      */
454 454
     public function add_items( &$invoice ) {
455
-		global $wpdb;
455
+        global $wpdb;
456 456
 
457
-		// Maybe retrieve from the cache.
458
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
457
+        // Maybe retrieve from the cache.
458
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
459 459
 
460
-		// If not found, retrieve from the db.
461
-		if ( false === $items ) {
462
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
460
+        // If not found, retrieve from the db.
461
+        if ( false === $items ) {
462
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
463 463
 
464
-			$items = $wpdb->get_results(
465
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
-			);
464
+            $items = $wpdb->get_results(
465
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
466
+            );
467 467
 
468
-			// Update the cache with our data
469
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
468
+            // Update the cache with our data
469
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
470 470
 
471
-		}
471
+        }
472 472
 
473
-		// Abort if no items found.
473
+        // Abort if no items found.
474 474
         if ( empty( $items ) ) {
475 475
             return;
476
-		}
477
-
478
-		$_items = array();
479
-		foreach ( $items as $item_data ) {
480
-			$item = new GetPaid_Form_Item( $item_data->item_id );
481
-
482
-			// Set item data.
483
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
-			$item->set_name( $item_data->item_name );
486
-			$item->set_description( $item_data->item_description );
487
-			$item->set_price( $item_data->item_price );
488
-			$item->set_quantity( $item_data->quantity );
489
-			$item->set_item_meta( $item_data->meta );
490
-			$_items[] = $item;
491
-		}
492
-
493
-		$invoice->set_items( $_items );
494
-	}
495
-
496
-	/**
476
+        }
477
+
478
+        $_items = array();
479
+        foreach ( $items as $item_data ) {
480
+            $item = new GetPaid_Form_Item( $item_data->item_id );
481
+
482
+            // Set item data.
483
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
484
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
485
+            $item->set_name( $item_data->item_name );
486
+            $item->set_description( $item_data->item_description );
487
+            $item->set_price( $item_data->item_price );
488
+            $item->set_quantity( $item_data->quantity );
489
+            $item->set_item_meta( $item_data->meta );
490
+            $_items[] = $item;
491
+        }
492
+
493
+        $invoice->set_items( $_items );
494
+    }
495
+
496
+    /**
497 497
      * Saves cart details.
498
-	 *
499
-	 * @param WPInv_Invoice $invoice Invoice object.
498
+     *
499
+     * @param WPInv_Invoice $invoice Invoice object.
500 500
      */
501 501
     public function save_items( $invoice ) {
502 502
 
503
-		// Delete previously existing items.
504
-		$this->delete_items( $invoice );
503
+        // Delete previously existing items.
504
+        $this->delete_items( $invoice );
505 505
 
506
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
506
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
507 507
 
508
-		foreach ( $invoice->get_cart_details() as $item_data ) {
509
-			$item_data = array_map( 'maybe_serialize', $item_data );
510
-			$GLOBALS['wpdb']->insert( $table, $item_data );
511
-		}
508
+        foreach ( $invoice->get_cart_details() as $item_data ) {
509
+            $item_data = array_map( 'maybe_serialize', $item_data );
510
+            $GLOBALS['wpdb']->insert( $table, $item_data );
511
+        }
512 512
 
513
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
-		do_action( "getpaid_invoice_save_items", $invoice );
513
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
514
+        do_action( "getpaid_invoice_save_items", $invoice );
515 515
 
516
-	}
516
+    }
517 517
 
518
-	/**
518
+    /**
519 519
      * Deletes an invoice's cart details from the database.
520
-	 *
521
-	 * @param WPInv_Invoice $invoice Invoice object.
520
+     *
521
+     * @param WPInv_Invoice $invoice Invoice object.
522 522
      */
523 523
     public function delete_items( $invoice ) {
524
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
-	}
524
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
525
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
526
+    }
527 527
 
528
-	/**
528
+    /**
529 529
      * Deletes an invoice's special fields from the database.
530
-	 *
531
-	 * @param WPInv_Invoice $invoice Invoice object.
530
+     *
531
+     * @param WPInv_Invoice $invoice Invoice object.
532 532
      */
533 533
     public function delete_special_fields( $invoice ) {
534
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
-	}
534
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
535
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
536
+    }
537 537
 	
538
-	/**
539
-	 * Get the status to save to the post object.
540
-	 *
541
-	 *
542
-	 * @since 1.0.19
543
-	 * @param  WPInv_Invoice $object GetPaid_Data object.
544
-	 * @return string
545
-	 */
546
-	protected function get_post_status( $object ) {
547
-		$object_status = $object->get_status( 'edit' );
548
-
549
-		if ( ! $object_status ) {
550
-			$object_status = $object->get_default_status();
551
-		}
552
-
553
-		return $object_status;
554
-	}
538
+    /**
539
+     * Get the status to save to the post object.
540
+     *
541
+     *
542
+     * @since 1.0.19
543
+     * @param  WPInv_Invoice $object GetPaid_Data object.
544
+     * @return string
545
+     */
546
+    protected function get_post_status( $object ) {
547
+        $object_status = $object->get_status( 'edit' );
548
+
549
+        if ( ! $object_status ) {
550
+            $object_status = $object->get_default_status();
551
+        }
552
+
553
+        return $object_status;
554
+    }
555 555
 
556 556
 }
Please login to merge, or discard this patch.