Passed
Push — master ( c4c78b...c15536 )
by Brian
08:03 queued 02:54
created
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 2 patches
Indentation   +273 added lines, -273 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
 /**
@@ -16,84 +16,84 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Meta_Box_Invoice_Address {
18 18
 
19
-	/**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
24
-	public static function output( $post ) {
25
-
26
-		// Prepare the invoice.
27
-		$invoice  = new WPInv_Invoice( $post );
28
-		$customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-		$customer = new WP_User( $customer );
30
-		$display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-		wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
-
33
-		// Address fields.
34
-		$address_fields = array(
35
-			'first_name' => array(
36
-				'label' => __( 'First Name', 'invoicing' ),
37
-				'type'  => 'text',
38
-			),
39
-			'last_name'  => array(
40
-				'label' => __( 'Last Name', 'invoicing' ),
41
-				'type'  => 'text',
42
-			),
43
-			'company'    => array(
44
-				'label' => __( 'Company', 'invoicing' ),
45
-				'type'  => 'text',
46
-				'class' => 'getpaid-recalculate-prices-on-change',
47
-			),
48
-			'vat_number' => array(
49
-				'label' => __( 'VAT Number', 'invoicing' ),
50
-				'type'  => 'text',
51
-			),
52
-			'address'    => array(
53
-				'label' => __( 'Address', 'invoicing' ),
54
-				'type'  => 'text',
55
-			),
56
-			'city'       => array(
57
-				'label' => __( 'City', 'invoicing' ),
58
-				'type'  => 'text',
59
-			),
60
-			'country'    => array(
61
-				'label'       => __( 'Country', 'invoicing' ),
62
-				'type'        => 'select',
63
-				'class'       => 'getpaid-recalculate-prices-on-change',
64
-				'options'     => wpinv_get_country_list(),
65
-				'placeholder' => __( 'Choose a country', 'invoicing' ),
66
-			),
67
-			'state'      => array(
68
-				'label' => __( 'State', 'invoicing' ),
69
-				'type'  => 'text',
70
-				'class' => 'getpaid-recalculate-prices-on-change',
71
-			),
72
-			'zip'        => array(
73
-				'label' => __( 'Zip', 'invoicing' ),
74
-				'type'  => 'text',
75
-			),
76
-			'phone'      => array(
77
-				'label' => __( 'Phone', 'invoicing' ),
78
-				'type'  => 'text',
79
-			),
80
-		);
81
-
82
-		$states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
83
-
84
-		if ( ! empty( $states ) ) {
85
-			$address_fields['state']['type']        = 'select';
86
-			$address_fields['state']['options']     = $states;
87
-			$address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
88
-		}
89
-
90
-		// Maybe remove the VAT field.
91
-		if ( ! wpinv_use_taxes() ) {
92
-			unset( $address_fields['vat_number'] );
93
-		}
94
-
95
-		$address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
96
-		?>
19
+    /**
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24
+    public static function output( $post ) {
25
+
26
+        // Prepare the invoice.
27
+        $invoice  = new WPInv_Invoice( $post );
28
+        $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
+        $customer = new WP_User( $customer );
30
+        $display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
+        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
+
33
+        // Address fields.
34
+        $address_fields = array(
35
+            'first_name' => array(
36
+                'label' => __( 'First Name', 'invoicing' ),
37
+                'type'  => 'text',
38
+            ),
39
+            'last_name'  => array(
40
+                'label' => __( 'Last Name', 'invoicing' ),
41
+                'type'  => 'text',
42
+            ),
43
+            'company'    => array(
44
+                'label' => __( 'Company', 'invoicing' ),
45
+                'type'  => 'text',
46
+                'class' => 'getpaid-recalculate-prices-on-change',
47
+            ),
48
+            'vat_number' => array(
49
+                'label' => __( 'VAT Number', 'invoicing' ),
50
+                'type'  => 'text',
51
+            ),
52
+            'address'    => array(
53
+                'label' => __( 'Address', 'invoicing' ),
54
+                'type'  => 'text',
55
+            ),
56
+            'city'       => array(
57
+                'label' => __( 'City', 'invoicing' ),
58
+                'type'  => 'text',
59
+            ),
60
+            'country'    => array(
61
+                'label'       => __( 'Country', 'invoicing' ),
62
+                'type'        => 'select',
63
+                'class'       => 'getpaid-recalculate-prices-on-change',
64
+                'options'     => wpinv_get_country_list(),
65
+                'placeholder' => __( 'Choose a country', 'invoicing' ),
66
+            ),
67
+            'state'      => array(
68
+                'label' => __( 'State', 'invoicing' ),
69
+                'type'  => 'text',
70
+                'class' => 'getpaid-recalculate-prices-on-change',
71
+            ),
72
+            'zip'        => array(
73
+                'label' => __( 'Zip', 'invoicing' ),
74
+                'type'  => 'text',
75
+            ),
76
+            'phone'      => array(
77
+                'label' => __( 'Phone', 'invoicing' ),
78
+                'type'  => 'text',
79
+            ),
80
+        );
81
+
82
+        $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
83
+
84
+        if ( ! empty( $states ) ) {
85
+            $address_fields['state']['type']        = 'select';
86
+            $address_fields['state']['options']     = $states;
87
+            $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
88
+        }
89
+
90
+        // Maybe remove the VAT field.
91
+        if ( ! wpinv_use_taxes() ) {
92
+            unset( $address_fields['vat_number'] );
93
+        }
94
+
95
+        $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
96
+        ?>
97 97
 
98 98
 		<style>
99 99
 			#wpinv-address label {
@@ -118,19 +118,19 @@  discard block
 block discarded – undo
118 118
 							<div id="getpaid-invoice-email-wrapper" class="d-none">
119 119
 								<input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" />
120 120
 								<?php
121
-									aui()->input(
122
-										array(
123
-											'type'        => 'text',
124
-											'id'          => 'getpaid-invoice-new-user-email',
125
-											'name'        => 'wpinv_email',
126
-											'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
127
-											'label_type'  => 'vertical',
128
-											'placeholder' => '[email protected]',
129
-											'class'       => 'form-control-sm',
130
-										),
131
-										true
132
-									);
133
-								?>
121
+                                    aui()->input(
122
+                                        array(
123
+                                            'type'        => 'text',
124
+                                            'id'          => 'getpaid-invoice-new-user-email',
125
+                                            'name'        => 'wpinv_email',
126
+                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
127
+                                            'label_type'  => 'vertical',
128
+                                            'placeholder' => '[email protected]',
129
+                                            'class'       => 'form-control-sm',
130
+                                        ),
131
+                                        true
132
+                                    );
133
+                                ?>
134 134
 							</div>
135 135
 						</div>
136 136
 						<div class="col-12 col-sm-6 form-group mb-3 mt-sm-4">
@@ -154,39 +154,39 @@  discard block
 block discarded – undo
154 154
 							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper">
155 155
 								<?php
156 156
 
157
-									if ( 'select' === $field['type'] ) {
158
-										aui()->select(
159
-											array(
160
-												'id'               => 'wpinv_' . $key,
161
-												'name'             => 'wpinv_' . $key,
162
-												'label'            => $field['label'],
163
-												'label_type'       => 'vertical',
164
-												'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
165
-												'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
166
-												'value'            => $invoice->get( $key, 'edit' ),
167
-												'options'          => $field['options'],
168
-												'data-allow-clear' => 'false',
169
-												'select2'          => true,
170
-											),
171
-											true
172
-										);
173
-									} else {
174
-										aui()->input(
175
-											array(
176
-												'type'        => $field['type'],
177
-												'id'          => 'wpinv_' . $key,
178
-												'name'        => 'wpinv_' . $key,
179
-												'label'       => $field['label'],
180
-												'label_type'  => 'vertical',
181
-												'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
182
-												'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
183
-												'value'       => $invoice->get( $key, 'edit' ),
184
-											),
185
-											true
186
-										);
187
-									}
188
-
189
-								?>
157
+                                    if ( 'select' === $field['type'] ) {
158
+                                        aui()->select(
159
+                                            array(
160
+                                                'id'               => 'wpinv_' . $key,
161
+                                                'name'             => 'wpinv_' . $key,
162
+                                                'label'            => $field['label'],
163
+                                                'label_type'       => 'vertical',
164
+                                                'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
165
+                                                'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
166
+                                                'value'            => $invoice->get( $key, 'edit' ),
167
+                                                'options'          => $field['options'],
168
+                                                'data-allow-clear' => 'false',
169
+                                                'select2'          => true,
170
+                                            ),
171
+                                            true
172
+                                        );
173
+                                    } else {
174
+                                        aui()->input(
175
+                                            array(
176
+                                                'type'        => $field['type'],
177
+                                                'id'          => 'wpinv_' . $key,
178
+                                                'name'        => 'wpinv_' . $key,
179
+                                                'label'       => $field['label'],
180
+                                                'label_type'  => 'vertical',
181
+                                                'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
182
+                                                'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
183
+                                                'value'       => $invoice->get( $key, 'edit' ),
184
+                                            ),
185
+                                            true
186
+                                        );
187
+                                    }
188
+
189
+                                ?>
190 190
 							</div>
191 191
 						<?php endforeach; ?>
192 192
 					</div>
@@ -197,49 +197,49 @@  discard block
 block discarded – undo
197 197
 						<div class="row">
198 198
 							<div class="col-12 col-sm-6">
199 199
 								<?php
200
-									aui()->select(
201
-										array(
202
-											'id'          => 'wpinv_template',
203
-											'name'        => 'wpinv_template',
204
-											'label'       => __( 'Template', 'invoicing' ),
205
-											'label_type'  => 'vertical',
206
-											'placeholder' => __( 'Choose a template', 'invoicing' ),
207
-											'class'       => 'form-control-sm',
208
-											'value'       => $invoice->get_template( 'edit' ),
209
-											'options'     => array(
210
-												'quantity' => __( 'Quantity', 'invoicing' ),
211
-												'hours'    => __( 'Hours', 'invoicing' ),
212
-												//'amount'   => __( 'Amount Only', 'invoicing' ),
213
-											),
214
-											'data-allow-clear' => 'false',
215
-											'select2'     => true,
216
-										),
217
-										true
218
-									);
219
-								?>
200
+                                    aui()->select(
201
+                                        array(
202
+                                            'id'          => 'wpinv_template',
203
+                                            'name'        => 'wpinv_template',
204
+                                            'label'       => __( 'Template', 'invoicing' ),
205
+                                            'label_type'  => 'vertical',
206
+                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
207
+                                            'class'       => 'form-control-sm',
208
+                                            'value'       => $invoice->get_template( 'edit' ),
209
+                                            'options'     => array(
210
+                                                'quantity' => __( 'Quantity', 'invoicing' ),
211
+                                                'hours'    => __( 'Hours', 'invoicing' ),
212
+                                                //'amount'   => __( 'Amount Only', 'invoicing' ),
213
+                                            ),
214
+                                            'data-allow-clear' => 'false',
215
+                                            'select2'     => true,
216
+                                        ),
217
+                                        true
218
+                                    );
219
+                                ?>
220 220
 							</div>
221 221
 							<div class="col-12 col-sm-6">
222 222
 								<?php
223 223
 
224
-									// Set currency.
225
-									aui()->select(
226
-										array(
227
-											'id'          => 'wpinv_currency',
228
-											'name'        => 'wpinv_currency',
229
-											'label'       => __( 'Currency', 'invoicing' ),
230
-											'label_type'  => 'vertical',
231
-											'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
-											'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
-											'value'       => $invoice->get_currency( 'edit' ),
234
-											'required'    => false,
235
-											'data-allow-clear' => 'false',
236
-											'select2'     => true,
237
-											'options'     => wpinv_get_currencies(),
238
-										),
239
-										true
240
-									);
241
-
242
-								?>
224
+                                    // Set currency.
225
+                                    aui()->select(
226
+                                        array(
227
+                                            'id'          => 'wpinv_currency',
228
+                                            'name'        => 'wpinv_currency',
229
+                                            'label'       => __( 'Currency', 'invoicing' ),
230
+                                            'label_type'  => 'vertical',
231
+                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
+                                            'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
+                                            'value'       => $invoice->get_currency( 'edit' ),
234
+                                            'required'    => false,
235
+                                            'data-allow-clear' => 'false',
236
+                                            'select2'     => true,
237
+                                            'options'     => wpinv_get_currencies(),
238
+                                        ),
239
+                                        true
240
+                                    );
241
+
242
+                                ?>
243 243
 							</div>
244 244
 						</div>
245 245
 
@@ -249,119 +249,119 @@  discard block
 block discarded – undo
249 249
 					<div class="row">
250 250
 						<div class="col-12 col-sm-6">
251 251
 							<?php
252
-								aui()->input(
253
-									array(
254
-										'type'        => 'text',
255
-										'id'          => 'wpinv_company_id',
256
-										'name'        => 'wpinv_company_id',
257
-										'label'       => __( 'Company ID', 'invoicing' ),
258
-										'label_type'  => 'vertical',
259
-										'placeholder' => '',
260
-										'class'       => 'form-control-sm',
261
-										'value'       => $invoice->get_company_id( 'edit' ),
262
-									),
263
-									true
264
-								);
265
-							?>
252
+                                aui()->input(
253
+                                    array(
254
+                                        'type'        => 'text',
255
+                                        'id'          => 'wpinv_company_id',
256
+                                        'name'        => 'wpinv_company_id',
257
+                                        'label'       => __( 'Company ID', 'invoicing' ),
258
+                                        'label_type'  => 'vertical',
259
+                                        'placeholder' => '',
260
+                                        'class'       => 'form-control-sm',
261
+                                        'value'       => $invoice->get_company_id( 'edit' ),
262
+                                    ),
263
+                                    true
264
+                                );
265
+                            ?>
266 266
 						</div>
267 267
 					</div>
268 268
 
269 269
 					<?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
270 270
 			</div>
271 271
 		<?php
272
-	}
273
-
274
-	/**
275
-	 * Save meta box data.
276
-	 *
277
-	 * @param int $post_id
278
-	 */
279
-	public static function save( $post_id ) {
280
-
281
-		// Prepare the invoice.
282
-		$invoice = new WPInv_Invoice( $post_id );
283
-
284
-		// Load new data.
285
-		$invoice->set_props(
286
-			array(
287
-				'template'       => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
288
-				'email_cc'       => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
289
-				'disable_taxes'  => ! empty( $_POST['disable_taxes'] ),
290
-				'currency'       => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null,
291
-				'gateway'        => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null,
292
-				'address'        => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null,
293
-				'vat_number'     => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null,
294
-				'company'        => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null,
295
-				'company_id'     => isset( $_POST['wpinv_company_id'] ) ? wpinv_clean( $_POST['wpinv_company_id'] ) : null,
296
-				'zip'            => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null,
297
-				'state'          => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null,
298
-				'city'           => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null,
299
-				'country'        => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null,
300
-				'phone'          => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null,
301
-				'first_name'     => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null,
302
-				'last_name'      => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null,
303
-				'author'         => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null,
304
-				'date_created'   => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null,
305
-				'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null,
306
-				'due_date'       => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
307
-				'number'         => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
308
-				'status'         => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
309
-			)
310
-		);
311
-
312
-		// Discount code.
313
-		if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
314
-
315
-			if ( isset( $_POST['wpinv_discount_code'] ) ) {
316
-				$invoice->set_discount_code( wpinv_clean( $_POST['wpinv_discount_code'] ) );
317
-			}
318
-
319
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
320
-			if ( $discount->exists() ) {
321
-				$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
322
-			} else {
323
-				$invoice->remove_discount( 'discount_code' );
324
-			}
325
-
326
-			// Recalculate totals.
327
-			$invoice->recalculate_total();
328
-
329
-		}
330
-
331
-		// If we're creating a new user...
332
-		if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( stripslashes( $_POST['wpinv_email'] ) ) ) {
333
-
334
-			// Attempt to create the user.
335
-			$user = wpinv_create_user( sanitize_email( stripslashes( $_POST['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
336
-
337
-			// If successful, update the invoice author.
338
-			if ( is_numeric( $user ) ) {
339
-				$invoice->set_author( $user );
340
-			} else {
341
-				wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
342
-			}
343
-		}
344
-
345
-		// Do not send new invoice notifications.
346
-		$GLOBALS['wpinv_skip_invoice_notification'] = true;
347
-
348
-		// Save the invoice.
349
-		$invoice->save();
350
-
351
-		// Undo do not send new invoice notifications.
352
-		$GLOBALS['wpinv_skip_invoice_notification'] = false;
353
-
354
-		// (Maybe) send new user notification.
355
-		$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
356
-		if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
357
-			wp_send_new_user_notifications( $user, 'user' );
358
-		}
359
-
360
-		if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) {
361
-			getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
362
-		}
363
-
364
-		// Fires after an invoice is saved.
365
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
366
-	}
272
+    }
273
+
274
+    /**
275
+     * Save meta box data.
276
+     *
277
+     * @param int $post_id
278
+     */
279
+    public static function save( $post_id ) {
280
+
281
+        // Prepare the invoice.
282
+        $invoice = new WPInv_Invoice( $post_id );
283
+
284
+        // Load new data.
285
+        $invoice->set_props(
286
+            array(
287
+                'template'       => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
288
+                'email_cc'       => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
289
+                'disable_taxes'  => ! empty( $_POST['disable_taxes'] ),
290
+                'currency'       => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null,
291
+                'gateway'        => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null,
292
+                'address'        => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null,
293
+                'vat_number'     => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null,
294
+                'company'        => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null,
295
+                'company_id'     => isset( $_POST['wpinv_company_id'] ) ? wpinv_clean( $_POST['wpinv_company_id'] ) : null,
296
+                'zip'            => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null,
297
+                'state'          => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null,
298
+                'city'           => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null,
299
+                'country'        => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null,
300
+                'phone'          => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null,
301
+                'first_name'     => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null,
302
+                'last_name'      => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null,
303
+                'author'         => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null,
304
+                'date_created'   => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null,
305
+                'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null,
306
+                'due_date'       => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
307
+                'number'         => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
308
+                'status'         => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
309
+            )
310
+        );
311
+
312
+        // Discount code.
313
+        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
314
+
315
+            if ( isset( $_POST['wpinv_discount_code'] ) ) {
316
+                $invoice->set_discount_code( wpinv_clean( $_POST['wpinv_discount_code'] ) );
317
+            }
318
+
319
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
320
+            if ( $discount->exists() ) {
321
+                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
322
+            } else {
323
+                $invoice->remove_discount( 'discount_code' );
324
+            }
325
+
326
+            // Recalculate totals.
327
+            $invoice->recalculate_total();
328
+
329
+        }
330
+
331
+        // If we're creating a new user...
332
+        if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( stripslashes( $_POST['wpinv_email'] ) ) ) {
333
+
334
+            // Attempt to create the user.
335
+            $user = wpinv_create_user( sanitize_email( stripslashes( $_POST['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
336
+
337
+            // If successful, update the invoice author.
338
+            if ( is_numeric( $user ) ) {
339
+                $invoice->set_author( $user );
340
+            } else {
341
+                wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
342
+            }
343
+        }
344
+
345
+        // Do not send new invoice notifications.
346
+        $GLOBALS['wpinv_skip_invoice_notification'] = true;
347
+
348
+        // Save the invoice.
349
+        $invoice->save();
350
+
351
+        // Undo do not send new invoice notifications.
352
+        $GLOBALS['wpinv_skip_invoice_notification'] = false;
353
+
354
+        // (Maybe) send new user notification.
355
+        $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
356
+        if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
357
+            wp_send_new_user_notifications( $user, 'user' );
358
+        }
359
+
360
+        if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) {
361
+            getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
362
+        }
363
+
364
+        // Fires after an invoice is saved.
365
+        do_action( 'wpinv_invoice_metabox_saved', $invoice );
366
+    }
367 367
 }
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,78 +21,78 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-	public static function output( $post ) {
24
+	public static function output($post) {
25 25
 
26 26
 		// Prepare the invoice.
27
-		$invoice  = new WPInv_Invoice( $post );
28
-		$customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-		$customer = new WP_User( $customer );
30
-		$display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-		wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
27
+		$invoice  = new WPInv_Invoice($post);
28
+		$customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id();
29
+		$customer = new WP_User($customer);
30
+		$display  = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email);
31
+		wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
32 32
 
33 33
 		// Address fields.
34 34
 		$address_fields = array(
35 35
 			'first_name' => array(
36
-				'label' => __( 'First Name', 'invoicing' ),
36
+				'label' => __('First Name', 'invoicing'),
37 37
 				'type'  => 'text',
38 38
 			),
39 39
 			'last_name'  => array(
40
-				'label' => __( 'Last Name', 'invoicing' ),
40
+				'label' => __('Last Name', 'invoicing'),
41 41
 				'type'  => 'text',
42 42
 			),
43 43
 			'company'    => array(
44
-				'label' => __( 'Company', 'invoicing' ),
44
+				'label' => __('Company', 'invoicing'),
45 45
 				'type'  => 'text',
46 46
 				'class' => 'getpaid-recalculate-prices-on-change',
47 47
 			),
48 48
 			'vat_number' => array(
49
-				'label' => __( 'VAT Number', 'invoicing' ),
49
+				'label' => __('VAT Number', 'invoicing'),
50 50
 				'type'  => 'text',
51 51
 			),
52 52
 			'address'    => array(
53
-				'label' => __( 'Address', 'invoicing' ),
53
+				'label' => __('Address', 'invoicing'),
54 54
 				'type'  => 'text',
55 55
 			),
56 56
 			'city'       => array(
57
-				'label' => __( 'City', 'invoicing' ),
57
+				'label' => __('City', 'invoicing'),
58 58
 				'type'  => 'text',
59 59
 			),
60 60
 			'country'    => array(
61
-				'label'       => __( 'Country', 'invoicing' ),
61
+				'label'       => __('Country', 'invoicing'),
62 62
 				'type'        => 'select',
63 63
 				'class'       => 'getpaid-recalculate-prices-on-change',
64 64
 				'options'     => wpinv_get_country_list(),
65
-				'placeholder' => __( 'Choose a country', 'invoicing' ),
65
+				'placeholder' => __('Choose a country', 'invoicing'),
66 66
 			),
67 67
 			'state'      => array(
68
-				'label' => __( 'State', 'invoicing' ),
68
+				'label' => __('State', 'invoicing'),
69 69
 				'type'  => 'text',
70 70
 				'class' => 'getpaid-recalculate-prices-on-change',
71 71
 			),
72 72
 			'zip'        => array(
73
-				'label' => __( 'Zip', 'invoicing' ),
73
+				'label' => __('Zip', 'invoicing'),
74 74
 				'type'  => 'text',
75 75
 			),
76 76
 			'phone'      => array(
77
-				'label' => __( 'Phone', 'invoicing' ),
77
+				'label' => __('Phone', 'invoicing'),
78 78
 				'type'  => 'text',
79 79
 			),
80 80
 		);
81 81
 
82
-		$states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
82
+		$states = wpinv_get_country_states($invoice->get_country('edit'));
83 83
 
84
-		if ( ! empty( $states ) ) {
84
+		if (!empty($states)) {
85 85
 			$address_fields['state']['type']        = 'select';
86 86
 			$address_fields['state']['options']     = $states;
87
-			$address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
87
+			$address_fields['state']['placeholder'] = __('Choose a state', 'invoicing');
88 88
 		}
89 89
 
90 90
 		// Maybe remove the VAT field.
91
-		if ( ! wpinv_use_taxes() ) {
92
-			unset( $address_fields['vat_number'] );
91
+		if (!wpinv_use_taxes()) {
92
+			unset($address_fields['vat_number']);
93 93
 		}
94 94
 
95
-		$address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
95
+		$address_fields = apply_filters('getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice);
96 96
 		?>
97 97
 
98 98
 		<style>
@@ -106,11 +106,11 @@  discard block
 block discarded – undo
106 106
 						<div class="col-12 col-sm-6">
107 107
 							<div id="getpaid-invoice-user-id-wrapper" class="form-group mb-3">
108 108
 								<div>
109
-									<label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label>
109
+									<label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label>
110 110
 								</div>
111 111
 								<div>
112
-									<select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>">
113
-										<option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>)
112
+									<select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>">
113
+										<option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>)
114 114
 									</select>
115 115
 								</div>
116 116
 							</div>
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 											'type'        => 'text',
124 124
 											'id'          => 'getpaid-invoice-new-user-email',
125 125
 											'name'        => 'wpinv_email',
126
-											'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
126
+											'label'       => __('Email', 'invoicing') . '<span class="required">*</span>',
127 127
 											'label_type'  => 'vertical',
128 128
 											'placeholder' => '[email protected]',
129 129
 											'class'       => 'form-control-sm',
@@ -134,36 +134,36 @@  discard block
 block discarded – undo
134 134
 							</div>
135 135
 						</div>
136 136
 						<div class="col-12 col-sm-6 form-group mb-3 mt-sm-4">
137
-							<?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
137
+							<?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
138 138
 								<a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)">
139 139
 									<i aria-hidden="true" class="fa fa-refresh"></i>
140
-									<?php esc_html_e( 'Fill User Details', 'invoicing' ); ?>
140
+									<?php esc_html_e('Fill User Details', 'invoicing'); ?>
141 141
 								</a>
142 142
 								<a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)">
143 143
 									<i aria-hidden="true" class="fa fa-plus"></i>
144
-									<?php esc_html_e( 'Add New User', 'invoicing' ); ?>
144
+									<?php esc_html_e('Add New User', 'invoicing'); ?>
145 145
 								</a>
146 146
 								<a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)">
147 147
 									<i aria-hidden="true" class="fa fa-close"></i>
148
-									<?php esc_html_e( 'Cancel', 'invoicing' ); ?>
148
+									<?php esc_html_e('Cancel', 'invoicing'); ?>
149 149
 								</a>
150 150
 							<?php endif; ?>
151 151
 						</div>
152 152
 
153
-						<?php foreach ( $address_fields as $key => $field ) : ?>
154
-							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper">
153
+						<?php foreach ($address_fields as $key => $field) : ?>
154
+							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr($key); ?>--wrapper">
155 155
 								<?php
156 156
 
157
-									if ( 'select' === $field['type'] ) {
157
+									if ('select' === $field['type']) {
158 158
 										aui()->select(
159 159
 											array(
160 160
 												'id'               => 'wpinv_' . $key,
161 161
 												'name'             => 'wpinv_' . $key,
162 162
 												'label'            => $field['label'],
163 163
 												'label_type'       => 'vertical',
164
-												'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
165
-												'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
166
-												'value'            => $invoice->get( $key, 'edit' ),
164
+												'placeholder'      => isset($field['placeholder']) ? $field['placeholder'] : '',
165
+												'class'            => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''),
166
+												'value'            => $invoice->get($key, 'edit'),
167 167
 												'options'          => $field['options'],
168 168
 												'data-allow-clear' => 'false',
169 169
 												'select2'          => true,
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
 												'name'        => 'wpinv_' . $key,
179 179
 												'label'       => $field['label'],
180 180
 												'label_type'  => 'vertical',
181
-												'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
182
-												'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
183
-												'value'       => $invoice->get( $key, 'edit' ),
181
+												'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '',
182
+												'class'       => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''),
183
+												'value'       => $invoice->get($key, 'edit'),
184 184
 											),
185 185
 											true
186 186
 										);
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 						<?php endforeach; ?>
192 192
 					</div>
193 193
 
194
-					<?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?>
195
-						<?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?>
194
+					<?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?>
195
+						<?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?>
196 196
 
197 197
 						<div class="row">
198 198
 							<div class="col-12 col-sm-6">
@@ -201,14 +201,14 @@  discard block
 block discarded – undo
201 201
 										array(
202 202
 											'id'          => 'wpinv_template',
203 203
 											'name'        => 'wpinv_template',
204
-											'label'       => __( 'Template', 'invoicing' ),
204
+											'label'       => __('Template', 'invoicing'),
205 205
 											'label_type'  => 'vertical',
206
-											'placeholder' => __( 'Choose a template', 'invoicing' ),
206
+											'placeholder' => __('Choose a template', 'invoicing'),
207 207
 											'class'       => 'form-control-sm',
208
-											'value'       => $invoice->get_template( 'edit' ),
208
+											'value'       => $invoice->get_template('edit'),
209 209
 											'options'     => array(
210
-												'quantity' => __( 'Quantity', 'invoicing' ),
211
-												'hours'    => __( 'Hours', 'invoicing' ),
210
+												'quantity' => __('Quantity', 'invoicing'),
211
+												'hours'    => __('Hours', 'invoicing'),
212 212
 												//'amount'   => __( 'Amount Only', 'invoicing' ),
213 213
 											),
214 214
 											'data-allow-clear' => 'false',
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 										array(
227 227
 											'id'          => 'wpinv_currency',
228 228
 											'name'        => 'wpinv_currency',
229
-											'label'       => __( 'Currency', 'invoicing' ),
229
+											'label'       => __('Currency', 'invoicing'),
230 230
 											'label_type'  => 'vertical',
231
-											'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
231
+											'placeholder' => __('Select Invoice Currency', 'invoicing'),
232 232
 											'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
-											'value'       => $invoice->get_currency( 'edit' ),
233
+											'value'       => $invoice->get_currency('edit'),
234 234
 											'required'    => false,
235 235
 											'data-allow-clear' => 'false',
236 236
 											'select2'     => true,
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 							</div>
244 244
 						</div>
245 245
 
246
-						<?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?>
246
+						<?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?>
247 247
 					<?php endif; ?>
248 248
 
249 249
 					<div class="row">
@@ -254,11 +254,11 @@  discard block
 block discarded – undo
254 254
 										'type'        => 'text',
255 255
 										'id'          => 'wpinv_company_id',
256 256
 										'name'        => 'wpinv_company_id',
257
-										'label'       => __( 'Company ID', 'invoicing' ),
257
+										'label'       => __('Company ID', 'invoicing'),
258 258
 										'label_type'  => 'vertical',
259 259
 										'placeholder' => '',
260 260
 										'class'       => 'form-control-sm',
261
-										'value'       => $invoice->get_company_id( 'edit' ),
261
+										'value'       => $invoice->get_company_id('edit'),
262 262
 									),
263 263
 									true
264 264
 								);
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 						</div>
267 267
 					</div>
268 268
 
269
-					<?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
269
+					<?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?>
270 270
 			</div>
271 271
 		<?php
272 272
 	}
@@ -276,51 +276,51 @@  discard block
 block discarded – undo
276 276
 	 *
277 277
 	 * @param int $post_id
278 278
 	 */
279
-	public static function save( $post_id ) {
279
+	public static function save($post_id) {
280 280
 
281 281
 		// Prepare the invoice.
282
-		$invoice = new WPInv_Invoice( $post_id );
282
+		$invoice = new WPInv_Invoice($post_id);
283 283
 
284 284
 		// Load new data.
285 285
 		$invoice->set_props(
286 286
 			array(
287
-				'template'       => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null,
288
-				'email_cc'       => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null,
289
-				'disable_taxes'  => ! empty( $_POST['disable_taxes'] ),
290
-				'currency'       => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null,
291
-				'gateway'        => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null,
292
-				'address'        => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null,
293
-				'vat_number'     => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null,
294
-				'company'        => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null,
295
-				'company_id'     => isset( $_POST['wpinv_company_id'] ) ? wpinv_clean( $_POST['wpinv_company_id'] ) : null,
296
-				'zip'            => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null,
297
-				'state'          => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null,
298
-				'city'           => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null,
299
-				'country'        => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null,
300
-				'phone'          => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null,
301
-				'first_name'     => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null,
302
-				'last_name'      => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null,
303
-				'author'         => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null,
304
-				'date_created'   => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null,
305
-				'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null,
306
-				'due_date'       => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null,
307
-				'number'         => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null,
308
-				'status'         => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null,
287
+				'template'       => isset($_POST['wpinv_template']) ? wpinv_clean($_POST['wpinv_template']) : null,
288
+				'email_cc'       => isset($_POST['wpinv_cc']) ? wpinv_clean($_POST['wpinv_cc']) : null,
289
+				'disable_taxes'  => !empty($_POST['disable_taxes']),
290
+				'currency'       => isset($_POST['wpinv_currency']) ? wpinv_clean($_POST['wpinv_currency']) : null,
291
+				'gateway'        => ($invoice->needs_payment() && isset($_POST['wpinv_gateway'])) ? wpinv_clean($_POST['wpinv_gateway']) : null,
292
+				'address'        => isset($_POST['wpinv_address']) ? wpinv_clean($_POST['wpinv_address']) : null,
293
+				'vat_number'     => isset($_POST['wpinv_vat_number']) ? wpinv_clean($_POST['wpinv_vat_number']) : null,
294
+				'company'        => isset($_POST['wpinv_company']) ? wpinv_clean($_POST['wpinv_company']) : null,
295
+				'company_id'     => isset($_POST['wpinv_company_id']) ? wpinv_clean($_POST['wpinv_company_id']) : null,
296
+				'zip'            => isset($_POST['wpinv_zip']) ? wpinv_clean($_POST['wpinv_zip']) : null,
297
+				'state'          => isset($_POST['wpinv_state']) ? wpinv_clean($_POST['wpinv_state']) : null,
298
+				'city'           => isset($_POST['wpinv_city']) ? wpinv_clean($_POST['wpinv_city']) : null,
299
+				'country'        => isset($_POST['wpinv_country']) ? wpinv_clean($_POST['wpinv_country']) : null,
300
+				'phone'          => isset($_POST['wpinv_phone']) ? wpinv_clean($_POST['wpinv_phone']) : null,
301
+				'first_name'     => isset($_POST['wpinv_first_name']) ? wpinv_clean($_POST['wpinv_first_name']) : null,
302
+				'last_name'      => isset($_POST['wpinv_last_name']) ? wpinv_clean($_POST['wpinv_last_name']) : null,
303
+				'author'         => isset($_POST['post_author_override']) ? wpinv_clean($_POST['post_author_override']) : null,
304
+				'date_created'   => isset($_POST['date_created']) ? wpinv_clean($_POST['date_created']) : null,
305
+				'date_completed' => isset($_POST['wpinv_date_completed']) ? wpinv_clean($_POST['wpinv_date_completed']) : null,
306
+				'due_date'       => isset($_POST['wpinv_due_date']) ? wpinv_clean($_POST['wpinv_due_date']) : null,
307
+				'number'         => isset($_POST['wpinv_number']) ? wpinv_clean($_POST['wpinv_number']) : null,
308
+				'status'         => isset($_POST['wpinv_status']) ? wpinv_clean($_POST['wpinv_status']) : null,
309 309
 			)
310 310
 		);
311 311
 
312 312
 		// Discount code.
313
-		if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
313
+		if (!$invoice->is_paid() && !$invoice->is_refunded()) {
314 314
 
315
-			if ( isset( $_POST['wpinv_discount_code'] ) ) {
316
-				$invoice->set_discount_code( wpinv_clean( $_POST['wpinv_discount_code'] ) );
315
+			if (isset($_POST['wpinv_discount_code'])) {
316
+				$invoice->set_discount_code(wpinv_clean($_POST['wpinv_discount_code']));
317 317
 			}
318 318
 
319
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
320
-			if ( $discount->exists() ) {
321
-				$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
319
+			$discount = new WPInv_Discount($invoice->get_discount_code());
320
+			if ($discount->exists()) {
321
+				$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
322 322
 			} else {
323
-				$invoice->remove_discount( 'discount_code' );
323
+				$invoice->remove_discount('discount_code');
324 324
 			}
325 325
 
326 326
 			// Recalculate totals.
@@ -329,16 +329,16 @@  discard block
 block discarded – undo
329 329
 		}
330 330
 
331 331
 		// If we're creating a new user...
332
-		if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( stripslashes( $_POST['wpinv_email'] ) ) ) {
332
+		if (!empty($_POST['wpinv_new_user']) && is_email(stripslashes($_POST['wpinv_email']))) {
333 333
 
334 334
 			// Attempt to create the user.
335
-			$user = wpinv_create_user( sanitize_email( stripslashes( $_POST['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
335
+			$user = wpinv_create_user(sanitize_email(stripslashes($_POST['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name());
336 336
 
337 337
 			// If successful, update the invoice author.
338
-			if ( is_numeric( $user ) ) {
339
-				$invoice->set_author( $user );
338
+			if (is_numeric($user)) {
339
+				$invoice->set_author($user);
340 340
 			} else {
341
-				wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
341
+				wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__);
342 342
 			}
343 343
 		}
344 344
 
@@ -352,16 +352,16 @@  discard block
 block discarded – undo
352 352
 		$GLOBALS['wpinv_skip_invoice_notification'] = false;
353 353
 
354 354
 		// (Maybe) send new user notification.
355
-		$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
356
-		if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
357
-			wp_send_new_user_notifications( $user, 'user' );
355
+		$should_send_notification = wpinv_get_option('disable_new_user_emails');
356
+		if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) {
357
+			wp_send_new_user_notifications($user, 'user');
358 358
 		}
359 359
 
360
-		if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) {
361
-			getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
360
+		if (!empty($_POST['send_to_customer']) && !$invoice->is_draft()) {
361
+			getpaid()->get('invoice_emails')->user_invoice($invoice, true);
362 362
 		}
363 363
 
364 364
 		// Fires after an invoice is saved.
365
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
365
+		do_action('wpinv_invoice_metabox_saved', $invoice);
366 366
 	}
367 367
 }
Please login to merge, or discard this patch.