Passed
Push — master ( 37ef0b...5302c6 )
by Brian
04:00
created
includes/admin/class-getpaid-installer.php 1 patch
Spacing   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.0.2
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * The main installer/updater class.
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param string $upgrade_from The current invoicing version.
27 27
 	 */
28
-	public function upgrade_db( $upgrade_from ) {
28
+	public function upgrade_db($upgrade_from) {
29 29
 
30 30
 		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
31
+		update_option('wpinv_version', WPINV_VERSION);
32 32
 
33 33
 		// Setup the invoice Custom Post Type.
34 34
 		GetPaid_Post_Types::register_post_types();
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		// Create any missing database tables.
49 49
 		$method = "upgrade_from_$upgrade_from";
50 50
 
51
-		if ( method_exists( $this, $method ) ) {
51
+		if (method_exists($this, $method)) {
52 52
 			$this->$method();
53 53
 		}
54 54
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->create_invoice_items_table();
65 65
 
66 66
 		// Save default tax rates.
67
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
67
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
68 68
 	}
69 69
 
70 70
 	/**
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 		global $wpdb;
76 76
 
77 77
 		// Invoices.
78
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
-		if ( ! empty( $results ) ) {
80
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
78
+		$results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
79
+		if (!empty($results)) {
80
+			$wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
81 81
 
82 82
 			// Clean post cache
83
-			foreach ( $results as $row ) {
84
-				clean_post_cache( $row->ID );
83
+			foreach ($results as $row) {
84
+				clean_post_cache($row->ID);
85 85
 			}
86 86
 
87 87
 		}
88 88
 
89 89
 		// Item meta key changes
90 90
 		$query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
-		$results = $wpdb->get_results( $query );
91
+		$results = $wpdb->get_results($query);
92 92
 
93
-		if ( ! empty( $results ) ) {
94
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
93
+		if (!empty($results)) {
94
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
95
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
96
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
97 97
 
98
-			foreach ( $results as $row ) {
99
-				clean_post_cache( $row->post_id );
98
+			foreach ($results as $row) {
99
+				clean_post_cache($row->post_id);
100 100
 			}
101 101
 
102 102
 		}
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 *
129 129
 	 */
130 130
 	public function add_capabilities() {
131
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
131
+		$GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing');
132 132
 	}
133 133
 
134 134
 	/**
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
 
144 144
 				// Checkout page.
145 145
 				'checkout_page' => array(
146
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
147
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
146
+					'name'      => _x('gp-checkout', 'Page slug', 'invoicing'),
147
+					'title'     => _x('Checkout', 'Page title', 'invoicing'),
148 148
 					'content'   => '
149 149
 						<!-- wp:shortcode -->
150 150
 						[wpinv_checkout]
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
 
156 156
 				// Invoice history page.
157 157
 				'invoice_history_page' => array(
158
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
159
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
158
+					'name'    => _x('gp-invoices', 'Page slug', 'invoicing'),
159
+					'title'   => _x('My Invoices', 'Page title', 'invoicing'),
160 160
 					'content' => '
161 161
 					<!-- wp:shortcode -->
162 162
 					[wpinv_history]
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 
168 168
 				// Success page content.
169 169
 				'success_page' => array(
170
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
171
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
170
+					'name'     => _x('gp-receipt', 'Page slug', 'invoicing'),
171
+					'title'    => _x('Payment Confirmation', 'Page title', 'invoicing'),
172 172
 					'content'  => '
173 173
 					<!-- wp:shortcode -->
174 174
 					[wpinv_receipt]
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 
180 180
 				// Failure page content.
181 181
 				'failure_page' => array(
182
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
183
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
184
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
182
+					'name'    => _x('gp-transaction-failed', 'Page slug', 'invoicing'),
183
+					'title'   => _x('Transaction Failed', 'Page title', 'invoicing'),
184
+					'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'),
185 185
 					'parent'  => 'gp-checkout',
186 186
 				),
187 187
 
188 188
 				// Subscriptions history page.
189 189
 				'invoice_subscription_page' => array(
190
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
191
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
190
+					'name'    => _x('gp-subscriptions', 'Page slug', 'invoicing'),
191
+					'title'   => _x('My Subscriptions', 'Page title', 'invoicing'),
192 192
 					'content' => '
193 193
 					<!-- wp:shortcode -->
194 194
 					[wpinv_subscriptions]
@@ -200,8 +200,8 @@  discard block
 block discarded – undo
200 200
 			)
201 201
 		);
202 202
 
203
-		foreach ( $pages as $key => $page ) {
204
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
203
+		foreach ($pages as $key => $page) {
204
+			wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']);
205 205
 		}
206 206
 
207 207
 	}
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 
215 215
 		global $wpdb;
216 216
 
217
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
217
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
218 218
 
219 219
 		// Create tables.
220 220
 		$charset_collate = $wpdb->get_charset_collate();
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
 			KEY customer_and_status (customer_id, status)
242 242
 		  ) $charset_collate;";
243 243
 
244
-		dbDelta( $sql );
244
+		dbDelta($sql);
245 245
 
246 246
 	}
247 247
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
 	public function create_invoices_table() {
253 253
 		global $wpdb;
254 254
 
255
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
255
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
256 256
 
257 257
 		// Create tables.
258 258
 		$charset_collate = $wpdb->get_charset_collate();
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 			KEY `key` (`key`)
293 293
 		  ) $charset_collate;";
294 294
 
295
-		dbDelta( $sql );
295
+		dbDelta($sql);
296 296
 
297 297
 	}
298 298
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	public function create_invoice_items_table() {
304 304
 		global $wpdb;
305 305
 
306
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
306
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
307 307
 
308 308
 		// Create tables.
309 309
 		$charset_collate = $wpdb->get_charset_collate();
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
 			KEY post_id (post_id)
330 330
 		  ) $charset_collate;";
331 331
 
332
-		dbDelta( $sql );
332
+		dbDelta($sql);
333 333
 
334 334
 	}
335 335
 
@@ -343,38 +343,38 @@  discard block
 block discarded – undo
343 343
 		$invoices = array_unique(
344 344
 			get_posts(
345 345
 				array(
346
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
346
+					'post_type'      => array('wpi_invoice', 'wpi_quote'),
347 347
 					'posts_per_page' => -1,
348 348
 					'fields'         => 'ids',
349
-					'post_status'    => array_keys( get_post_stati() ),
349
+					'post_status'    => array_keys(get_post_stati()),
350 350
 				)
351 351
 			)
352 352
 		);
353 353
 
354 354
 		// Abort if we do not have any invoices.
355
-		if ( empty( $invoices ) ) {
355
+		if (empty($invoices)) {
356 356
 			return;
357 357
 		}
358 358
 
359 359
 		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
360 360
 		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
361 361
 
362
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
362
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
363 363
 
364 364
 		$invoice_rows = array();
365
-		foreach ( $invoices as $invoice ) {
365
+		foreach ($invoices as $invoice) {
366 366
 
367
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
367
+			$invoice = new WPInv_Legacy_Invoice($invoice);
368 368
 
369
-			if ( empty( $invoice->ID ) ) {
369
+			if (empty($invoice->ID)) {
370 370
 				return;
371 371
 			}
372 372
 
373
-			$fields = array (
373
+			$fields = array(
374 374
 				'post_id'        => $invoice->ID,
375 375
 				'number'         => $invoice->get_number(),
376 376
 				'key'            => $invoice->get_key(),
377
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
377
+				'type'           => str_replace('wpi_', '', $invoice->post_type),
378 378
 				'mode'           => $invoice->mode,
379 379
 				'user_ip'        => $invoice->get_ip(),
380 380
 				'first_name'     => $invoice->get_first_name(),
@@ -403,27 +403,27 @@  discard block
 block discarded – undo
403 403
 				'custom_meta'    => $invoice->payment_meta
404 404
 			);
405 405
 
406
-			foreach ( $fields as $key => $val ) {
407
-				if ( is_null( $val ) ) {
406
+			foreach ($fields as $key => $val) {
407
+				if (is_null($val)) {
408 408
 					$val = '';
409 409
 				}
410
-				$val = maybe_serialize( $val );
411
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
410
+				$val = maybe_serialize($val);
411
+				$fields[$key] = $wpdb->prepare('%s', $val);
412 412
 			}
413 413
 
414
-			$fields = implode( ', ', $fields );
414
+			$fields = implode(', ', $fields);
415 415
 			$invoice_rows[] = "($fields)";
416 416
 
417 417
 			$item_rows    = array();
418 418
 			$item_columns = array();
419
-			foreach ( $invoice->get_cart_details() as $details ) {
419
+			foreach ($invoice->get_cart_details() as $details) {
420 420
 				$fields = array(
421 421
 					'post_id'          => $invoice->ID,
422 422
 					'item_id'          => $details['id'],
423 423
 					'item_name'        => $details['name'],
424
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
424
+					'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
425 425
 					'vat_rate'         => $details['vat_rate'],
426
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
426
+					'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
427 427
 					'tax'              => $details['tax'],
428 428
 					'item_price'       => $details['item_price'],
429 429
 					'custom_price'     => $details['custom_price'],
@@ -435,31 +435,31 @@  discard block
 block discarded – undo
435 435
 					'fees'             => $details['fees'],
436 436
 				);
437 437
 
438
-				$item_columns = array_keys ( $fields );
438
+				$item_columns = array_keys($fields);
439 439
 
440
-				foreach ( $fields as $key => $val ) {
441
-					if ( is_null( $val ) ) {
440
+				foreach ($fields as $key => $val) {
441
+					if (is_null($val)) {
442 442
 						$val = '';
443 443
 					}
444
-					$val = maybe_serialize( $val );
445
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
444
+					$val = maybe_serialize($val);
445
+					$fields[$key] = $wpdb->prepare('%s', $val);
446 446
 				}
447 447
 
448
-				$fields = implode( ', ', $fields );
448
+				$fields = implode(', ', $fields);
449 449
 				$item_rows[] = "($fields)";
450 450
 			}
451 451
 
452
-			$item_rows    = implode( ', ', $item_rows );
453
-			$item_columns = implode( ', ', $item_columns );
454
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
452
+			$item_rows    = implode(', ', $item_rows);
453
+			$item_columns = implode(', ', $item_columns);
454
+			$wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
455 455
 		}
456 456
 
457
-		if ( empty( $invoice_rows ) ) {
457
+		if (empty($invoice_rows)) {
458 458
 			return;
459 459
 		}
460 460
 
461
-		$invoice_rows = implode( ', ', $invoice_rows );
462
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
461
+		$invoice_rows = implode(', ', $invoice_rows);
462
+		$wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
463 463
 
464 464
 	}
465 465
 
Please login to merge, or discard this patch.