Passed
Push — master ( 9807f2...f9d3bb )
by Brian
05:13
created
includes/admin/class-getpaid-installer.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.0.2
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * The main installer/updater class.
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param string $upgrade_from The current invoicing version.
27 27
 	 */
28
-	public function upgrade_db( $upgrade_from ) {
28
+	public function upgrade_db($upgrade_from) {
29 29
 
30 30
 		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
31
+		update_option('wpinv_version', WPINV_VERSION);
32 32
 
33 33
 		// Setup the invoice Custom Post Type.
34 34
 		GetPaid_Post_Types::register_post_types();
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 		// Create any missing database tables.
49 49
 		$method = "upgrade_from_$upgrade_from";
50 50
 
51
-		if ( method_exists( $this, $method ) ) {
51
+		if (method_exists($this, $method)) {
52 52
 			$this->$method();
53 53
 		}
54 54
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 		$this->create_invoice_items_table();
65 65
 
66 66
 		// Save default tax rates.
67
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
67
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
68 68
 	}
69 69
 
70 70
 	/**
@@ -75,28 +75,28 @@  discard block
 block discarded – undo
75 75
 		global $wpdb;
76 76
 
77 77
 		// Invoices.
78
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
-		if ( ! empty( $results ) ) {
80
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
78
+		$results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
79
+		if (!empty($results)) {
80
+			$wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
81 81
 
82 82
 			// Clean post cache
83
-			foreach ( $results as $row ) {
84
-				clean_post_cache( $row->ID );
83
+			foreach ($results as $row) {
84
+				clean_post_cache($row->ID);
85 85
 			}
86 86
 
87 87
 		}
88 88
 
89 89
 		// Item meta key changes
90 90
 		$query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
-		$results = $wpdb->get_results( $query );
91
+		$results = $wpdb->get_results($query);
92 92
 
93
-		if ( ! empty( $results ) ) {
94
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
93
+		if (!empty($results)) {
94
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
95
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
96
+			$wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
97 97
 
98
-			foreach ( $results as $row ) {
99
-				clean_post_cache( $row->post_id );
98
+			foreach ($results as $row) {
99
+				clean_post_cache($row->post_id);
100 100
 			}
101 101
 
102 102
 		}
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 	 */
130 130
 	public function upgrade_from_207() {
131 131
 		global $wpdb;
132
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
132
+		$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);");
133 133
 	}
134 134
 
135 135
 	/**
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
 	 *
138 138
 	 */
139 139
 	public function add_capabilities() {
140
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
140
+		$GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing');
141 141
 	}
142 142
 
143 143
 	/**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 
153 153
 				// Checkout page.
154 154
 				'checkout_page' => array(
155
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
155
+					'name'      => _x('gp-checkout', 'Page slug', 'invoicing'),
156
+					'title'     => _x('Checkout', 'Page title', 'invoicing'),
157 157
 					'content'   => '
158 158
 						<!-- wp:shortcode -->
159 159
 						[wpinv_checkout]
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 
165 165
 				// Invoice history page.
166 166
 				'invoice_history_page' => array(
167
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
167
+					'name'    => _x('gp-invoices', 'Page slug', 'invoicing'),
168
+					'title'   => _x('My Invoices', 'Page title', 'invoicing'),
169 169
 					'content' => '
170 170
 					<!-- wp:shortcode -->
171 171
 					[wpinv_history]
@@ -176,8 +176,8 @@  discard block
 block discarded – undo
176 176
 
177 177
 				// Success page content.
178 178
 				'success_page' => array(
179
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
179
+					'name'     => _x('gp-receipt', 'Page slug', 'invoicing'),
180
+					'title'    => _x('Payment Confirmation', 'Page title', 'invoicing'),
181 181
 					'content'  => '
182 182
 					<!-- wp:shortcode -->
183 183
 					[wpinv_receipt]
@@ -188,16 +188,16 @@  discard block
 block discarded – undo
188 188
 
189 189
 				// Failure page content.
190 190
 				'failure_page' => array(
191
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
191
+					'name'    => _x('gp-transaction-failed', 'Page slug', 'invoicing'),
192
+					'title'   => _x('Transaction Failed', 'Page title', 'invoicing'),
193
+					'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'),
194 194
 					'parent'  => 'gp-checkout',
195 195
 				),
196 196
 
197 197
 				// Subscriptions history page.
198 198
 				'invoice_subscription_page' => array(
199
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
199
+					'name'    => _x('gp-subscriptions', 'Page slug', 'invoicing'),
200
+					'title'   => _x('My Subscriptions', 'Page title', 'invoicing'),
201 201
 					'content' => '
202 202
 					<!-- wp:shortcode -->
203 203
 					[wpinv_subscriptions]
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 			)
210 210
 		);
211 211
 
212
-		foreach ( $pages as $key => $page ) {
213
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
212
+		foreach ($pages as $key => $page) {
213
+			wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']);
214 214
 		}
215 215
 
216 216
 	}
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 
224 224
 		global $wpdb;
225 225
 
226
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
226
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
227 227
 
228 228
 		// Create tables.
229 229
 		$charset_collate = $wpdb->get_charset_collate();
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 			KEY customer_and_status (customer_id, status)
251 251
 		  ) $charset_collate;";
252 252
 
253
-		dbDelta( $sql );
253
+		dbDelta($sql);
254 254
 
255 255
 	}
256 256
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	public function create_invoices_table() {
262 262
 		global $wpdb;
263 263
 
264
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
264
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
265 265
 
266 266
 		// Create tables.
267 267
 		$charset_collate = $wpdb->get_charset_collate();
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
 			KEY `key` (`key`)
302 302
 		  ) $charset_collate;";
303 303
 
304
-		dbDelta( $sql );
304
+		dbDelta($sql);
305 305
 
306 306
 	}
307 307
 
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
 	public function create_invoice_items_table() {
313 313
 		global $wpdb;
314 314
 
315
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
315
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
316 316
 
317 317
 		// Create tables.
318 318
 		$charset_collate = $wpdb->get_charset_collate();
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 			KEY post_id (post_id)
339 339
 		  ) $charset_collate;";
340 340
 
341
-		dbDelta( $sql );
341
+		dbDelta($sql);
342 342
 
343 343
 	}
344 344
 
@@ -351,40 +351,40 @@  discard block
 block discarded – undo
351 351
 
352 352
 		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
353 353
 		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
354
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
354
+		$migrated            = $wpdb->get_col("SELECT post_id FROM $invoices_table");
355 355
 		$invoices            = array_unique(
356 356
 			get_posts(
357 357
 				array(
358
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
358
+					'post_type'      => array('wpi_invoice', 'wpi_quote'),
359 359
 					'posts_per_page' => -1,
360 360
 					'fields'         => 'ids',
361
-					'post_status'    => array_keys( get_post_stati() ),
361
+					'post_status'    => array_keys(get_post_stati()),
362 362
 					'exclude'        => (array) $migrated,
363 363
 				)
364 364
 			)
365 365
 		);
366 366
 
367 367
 		// Abort if we do not have any invoices.
368
-		if ( empty( $invoices ) ) {
368
+		if (empty($invoices)) {
369 369
 			return;
370 370
 		}
371 371
 
372
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
372
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php');
373 373
 
374 374
 		$invoice_rows = array();
375
-		foreach ( $invoices as $invoice ) {
375
+		foreach ($invoices as $invoice) {
376 376
 
377
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
377
+			$invoice = new WPInv_Legacy_Invoice($invoice);
378 378
 
379
-			if ( empty( $invoice->ID ) ) {
379
+			if (empty($invoice->ID)) {
380 380
 				return;
381 381
 			}
382 382
 
383
-			$fields = array (
383
+			$fields = array(
384 384
 				'post_id'        => $invoice->ID,
385 385
 				'number'         => $invoice->get_number(),
386 386
 				'key'            => $invoice->get_key(),
387
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
387
+				'type'           => str_replace('wpi_', '', $invoice->post_type),
388 388
 				'mode'           => $invoice->mode,
389 389
 				'user_ip'        => $invoice->get_ip(),
390 390
 				'first_name'     => $invoice->get_first_name(),
@@ -413,27 +413,27 @@  discard block
 block discarded – undo
413 413
 				'custom_meta'    => $invoice->payment_meta
414 414
 			);
415 415
 
416
-			foreach ( $fields as $key => $val ) {
417
-				if ( is_null( $val ) ) {
416
+			foreach ($fields as $key => $val) {
417
+				if (is_null($val)) {
418 418
 					$val = '';
419 419
 				}
420
-				$val = maybe_serialize( $val );
421
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
420
+				$val = maybe_serialize($val);
421
+				$fields[$key] = $wpdb->prepare('%s', $val);
422 422
 			}
423 423
 
424
-			$fields = implode( ', ', $fields );
424
+			$fields = implode(', ', $fields);
425 425
 			$invoice_rows[] = "($fields)";
426 426
 
427 427
 			$item_rows    = array();
428 428
 			$item_columns = array();
429
-			foreach ( $invoice->get_cart_details() as $details ) {
429
+			foreach ($invoice->get_cart_details() as $details) {
430 430
 				$fields = array(
431 431
 					'post_id'          => $invoice->ID,
432 432
 					'item_id'          => $details['id'],
433 433
 					'item_name'        => $details['name'],
434
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
434
+					'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
435 435
 					'vat_rate'         => $details['vat_rate'],
436
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
436
+					'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
437 437
 					'tax'              => $details['tax'],
438 438
 					'item_price'       => $details['item_price'],
439 439
 					'custom_price'     => $details['custom_price'],
@@ -445,31 +445,31 @@  discard block
 block discarded – undo
445 445
 					'fees'             => $details['fees'],
446 446
 				);
447 447
 
448
-				$item_columns = array_keys ( $fields );
448
+				$item_columns = array_keys($fields);
449 449
 
450
-				foreach ( $fields as $key => $val ) {
451
-					if ( is_null( $val ) ) {
450
+				foreach ($fields as $key => $val) {
451
+					if (is_null($val)) {
452 452
 						$val = '';
453 453
 					}
454
-					$val = maybe_serialize( $val );
455
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
454
+					$val = maybe_serialize($val);
455
+					$fields[$key] = $wpdb->prepare('%s', $val);
456 456
 				}
457 457
 
458
-				$fields = implode( ', ', $fields );
458
+				$fields = implode(', ', $fields);
459 459
 				$item_rows[] = "($fields)";
460 460
 			}
461 461
 
462
-			$item_rows    = implode( ', ', $item_rows );
463
-			$item_columns = implode( ', ', $item_columns );
464
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
462
+			$item_rows    = implode(', ', $item_rows);
463
+			$item_columns = implode(', ', $item_columns);
464
+			$wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
465 465
 		}
466 466
 
467
-		if ( empty( $invoice_rows ) ) {
467
+		if (empty($invoice_rows)) {
468 468
 			return;
469 469
 		}
470 470
 
471
-		$invoice_rows = implode( ', ', $invoice_rows );
472
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
471
+		$invoice_rows = implode(', ', $invoice_rows);
472
+		$wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
473 473
 
474 474
 	}
475 475
 
Please login to merge, or discard this patch.