@@ -11,55 +11,55 @@ discard block |
||
11 | 11 | * @since 1.0.0 |
12 | 12 | */ |
13 | 13 | function wpinv_automatic_upgrade() { |
14 | - $wpi_version = get_option( 'wpinv_version' ); |
|
14 | + $wpi_version = get_option('wpinv_version'); |
|
15 | 15 | |
16 | 16 | // Update tables. |
17 | - if ( ! get_option( 'getpaid_created_invoice_tables' ) ) { |
|
17 | + if (!get_option('getpaid_created_invoice_tables')) { |
|
18 | 18 | wpinv_v119_upgrades(); |
19 | - update_option( 'getpaid_created_invoice_tables', true ); |
|
19 | + update_option('getpaid_created_invoice_tables', true); |
|
20 | 20 | } |
21 | 21 | |
22 | - if ( $wpi_version == WPINV_VERSION ) { |
|
22 | + if ($wpi_version == WPINV_VERSION) { |
|
23 | 23 | return; |
24 | 24 | } |
25 | 25 | |
26 | - if ( version_compare( $wpi_version, '0.0.5', '<' ) ) { |
|
26 | + if (version_compare($wpi_version, '0.0.5', '<')) { |
|
27 | 27 | wpinv_v005_upgrades(); |
28 | 28 | } |
29 | 29 | |
30 | - if ( version_compare( $wpi_version, '1.0.3', '<' ) ) { |
|
30 | + if (version_compare($wpi_version, '1.0.3', '<')) { |
|
31 | 31 | wpinv_v110_upgrades(); |
32 | 32 | } |
33 | 33 | |
34 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
34 | + update_option('wpinv_version', WPINV_VERSION); |
|
35 | 35 | } |
36 | -add_action( 'admin_init', 'wpinv_automatic_upgrade' ); |
|
36 | +add_action('admin_init', 'wpinv_automatic_upgrade'); |
|
37 | 37 | |
38 | 38 | function wpinv_v005_upgrades() { |
39 | 39 | global $wpdb; |
40 | 40 | |
41 | 41 | // Invoices status |
42 | - $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' )" ); |
|
43 | - if ( !empty( $results ) ) { |
|
44 | - $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' )" ); |
|
42 | + $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' )"); |
|
43 | + if (!empty($results)) { |
|
44 | + $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' )"); |
|
45 | 45 | |
46 | 46 | // Clean post cache |
47 | - foreach ( $results as $row ) { |
|
48 | - clean_post_cache( $row->ID ); |
|
47 | + foreach ($results as $row) { |
|
48 | + clean_post_cache($row->ID); |
|
49 | 49 | } |
50 | 50 | } |
51 | 51 | |
52 | 52 | // Item meta key changes |
53 | 53 | $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' )"; |
54 | - $results = $wpdb->get_results( $query ); |
|
54 | + $results = $wpdb->get_results($query); |
|
55 | 55 | |
56 | - if ( !empty( $results ) ) { |
|
57 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
58 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
59 | - $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
56 | + if (!empty($results)) { |
|
57 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )"); |
|
58 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'"); |
|
59 | + $wpdb->query("UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'"); |
|
60 | 60 | |
61 | - foreach ( $results as $row ) { |
|
62 | - clean_post_cache( $row->post_id ); |
|
61 | + foreach ($results as $row) { |
|
62 | + clean_post_cache($row->post_id); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | function wpinv_create_invoices_table() { |
89 | 89 | global $wpdb; |
90 | 90 | |
91 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
91 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
92 | 92 | |
93 | 93 | // Create invoices table. |
94 | 94 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | KEY `key` ( `key` ) |
133 | 133 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
134 | 134 | |
135 | - dbDelta( $sql ); |
|
135 | + dbDelta($sql); |
|
136 | 136 | |
137 | 137 | // Create invoice items table. |
138 | 138 | $table = $wpdb->prefix . 'getpaid_invoice_items'; |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | KEY post_id ( post_id ) |
161 | 161 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
162 | 162 | |
163 | - dbDelta( $sql ); |
|
163 | + dbDelta($sql); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | /** |
@@ -172,40 +172,40 @@ discard block |
||
172 | 172 | $invoices = array_unique( |
173 | 173 | get_posts( |
174 | 174 | array( |
175 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
175 | + 'post_type' => array('wpi_invoice', 'wpi_quote'), |
|
176 | 176 | 'posts_per_page' => -1, |
177 | 177 | 'fields' => 'ids', |
178 | - 'post_status' => array_keys( get_post_stati() ), |
|
178 | + 'post_status' => array_keys(get_post_stati()), |
|
179 | 179 | ) |
180 | 180 | ) |
181 | 181 | ); |
182 | 182 | |
183 | 183 | // Abort if we do not have any invoices. |
184 | - if ( empty( $invoices ) ) { |
|
184 | + if (empty($invoices)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
188 | 188 | $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
189 | 189 | $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
190 | 190 | |
191 | - if ( ! class_exists( 'WPInv_Legacy_Invoice' ) ) { |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' ); |
|
191 | + if (!class_exists('WPInv_Legacy_Invoice')) { |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | $invoice_rows = array(); |
196 | - foreach ( $invoices as $invoice ) { |
|
196 | + foreach ($invoices as $invoice) { |
|
197 | 197 | |
198 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
198 | + $invoice = new WPInv_Legacy_Invoice($invoice); |
|
199 | 199 | |
200 | - if ( empty( $invoice->ID ) ) { |
|
200 | + if (empty($invoice->ID)) { |
|
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | - $fields = array ( |
|
204 | + $fields = array( |
|
205 | 205 | 'post_id' => $invoice->ID, |
206 | 206 | 'number' => $invoice->get_number(), |
207 | 207 | 'key' => $invoice->get_key(), |
208 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
208 | + 'type' => str_replace('wpi_', '', $invoice->post_type), |
|
209 | 209 | 'mode' => $invoice->mode, |
210 | 210 | 'user_ip' => $invoice->get_ip(), |
211 | 211 | 'first_name' => $invoice->get_first_name(), |
@@ -234,27 +234,27 @@ discard block |
||
234 | 234 | 'custom_meta' => $invoice->payment_meta |
235 | 235 | ); |
236 | 236 | |
237 | - foreach ( $fields as $key => $val ) { |
|
238 | - if ( is_null( $val ) ) { |
|
237 | + foreach ($fields as $key => $val) { |
|
238 | + if (is_null($val)) { |
|
239 | 239 | $val = ''; |
240 | 240 | } |
241 | - $val = maybe_serialize( $val ); |
|
242 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
241 | + $val = maybe_serialize($val); |
|
242 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
243 | 243 | } |
244 | 244 | |
245 | - $fields = implode( ', ', $fields ); |
|
245 | + $fields = implode(', ', $fields); |
|
246 | 246 | $invoice_rows[] = "($fields)"; |
247 | 247 | |
248 | 248 | $item_rows = array(); |
249 | 249 | $item_columns = array(); |
250 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
250 | + foreach ($invoice->get_cart_details() as $details) { |
|
251 | 251 | $fields = array( |
252 | 252 | 'post_id' => $invoice->ID, |
253 | 253 | 'item_id' => $details['id'], |
254 | 254 | 'item_name' => $details['name'], |
255 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
255 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
256 | 256 | 'vat_rate' => $details['vat_rate'], |
257 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
257 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
258 | 258 | 'tax' => $details['tax'], |
259 | 259 | 'item_price' => $details['item_price'], |
260 | 260 | 'custom_price' => $details['custom_price'], |
@@ -266,26 +266,26 @@ discard block |
||
266 | 266 | 'fees' => $details['fees'], |
267 | 267 | ); |
268 | 268 | |
269 | - $item_columns = array_keys ( $fields ); |
|
269 | + $item_columns = array_keys($fields); |
|
270 | 270 | |
271 | - foreach ( $fields as $key => $val ) { |
|
272 | - if ( is_null( $val ) ) { |
|
271 | + foreach ($fields as $key => $val) { |
|
272 | + if (is_null($val)) { |
|
273 | 273 | $val = ''; |
274 | 274 | } |
275 | - $val = maybe_serialize( $val ); |
|
276 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
275 | + $val = maybe_serialize($val); |
|
276 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
277 | 277 | } |
278 | 278 | |
279 | - $fields = implode( ', ', $fields ); |
|
279 | + $fields = implode(', ', $fields); |
|
280 | 280 | $item_rows[] = "($fields)"; |
281 | 281 | } |
282 | 282 | |
283 | - $item_rows = implode( ', ', $item_rows ); |
|
284 | - $item_columns = implode( ', ', $item_columns ); |
|
285 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
283 | + $item_rows = implode(', ', $item_rows); |
|
284 | + $item_columns = implode(', ', $item_columns); |
|
285 | + $wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows"); |
|
286 | 286 | } |
287 | 287 | |
288 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
289 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
288 | + $invoice_rows = implode(', ', $invoice_rows); |
|
289 | + $wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows"); |
|
290 | 290 | |
291 | 291 | } |