Passed
Push — master ( ff3d3b...35d84f )
by Brian
05:12
created
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat;
10 10
 
11 11
         $currency_symbol    = wpinv_currency_symbol();
12
-        $statuses           = wpinv_get_invoice_statuses( true );
12
+        $statuses           = wpinv_get_invoice_statuses(true);
13 13
 
14
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
15
-        $invoice            = new WPInv_Invoice( $post_id );
16
-        $status             = $invoice->get_status( false ); // Current status    
14
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
15
+        $invoice            = new WPInv_Invoice($post_id);
16
+        $status             = $invoice->get_status(false); // Current status    
17 17
         $discount           = $invoice->get_discount();
18 18
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
19 19
         $invoice_number     = $invoice->get_number();
20 20
         $taxable            = $invoice->is_taxable();
21 21
 
22 22
         $date_created       = $invoice->get_created_date();
23
-        $datetime_created   = strtotime( $date_created );
24
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
23
+        $datetime_created   = strtotime($date_created);
24
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
25 25
         $date_completed     = $invoice->get_completed_date();
26
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
27
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
28
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
29
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
26
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
27
+        $title['status'] = __('Invoice Status:', 'invoicing');
28
+        $title['number'] = __('Invoice Number:', 'invoicing');
29
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
30 30
 
31 31
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
32 32
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -36,36 +36,36 @@  discard block
 block discarded – undo
36 36
 <div class="gdmbx2-wrap form-table">
37 37
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
38 38
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created">
39
-            <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div>
40
-            <div class="gdmbx-td"><?php echo $date_created;?></div>
39
+            <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div>
40
+            <div class="gdmbx-td"><?php echo $date_created; ?></div>
41 41
         </div>
42
-        <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?>
42
+        <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?>
43 43
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
44
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
44
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
45 45
             <div class="gdmbx-td">
46
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
47
-                <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p>
46
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
47
+                <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p>
48 48
             </div>
49 49
         </div>
50 50
         <?php } ?>
51
-        <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?>
52
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
51
+        <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?>
52
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
53 53
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
54
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
55
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
54
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
55
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
56 56
         </div>
57 57
         <?php } ?>
58
-        <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?>
58
+        <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?>
59 59
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed">
60
-            <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div>
61
-            <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div>
60
+            <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div>
61
+            <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div>
62 62
         </div>
63 63
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
64 64
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
65 65
             <div class="gdmbx-td">
66 66
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2">
67
-                    <?php foreach ( $statuses as $value => $label ) { ?>
68
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
67
+                    <?php foreach ($statuses as $value => $label) { ?>
68
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
69 69
                     <?php } ?>
70 70
                 </select>
71 71
             </div>
@@ -74,129 +74,129 @@  discard block
 block discarded – undo
74 74
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
75 75
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
76 76
             <div class="gdmbx-td">
77
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
77
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
78 78
             </div>
79 79
         </div>
80
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id );
80
+        <?php do_action('wpinv_meta_box_details_inner', $post_id);
81 81
         $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id);
82 82
         ?>
83 83
 
84
-        <?php if ( $wpinv_euvat->allow_vat_rules() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
84
+        <?php if ($wpinv_euvat->allow_vat_rules() && !($invoice->is_paid() || $invoice->is_refunded())) { ?>
85 85
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-taxable">
86 86
             <div class="gdmbx-th">
87 87
                 <label for="wpinv_taxable">
88
-                    <input type="checkbox" name="disable_taxes" value="1" <?php checked( $taxable, false ); ?> id="wpinv_taxable">
89
-                    <?php _e( 'Disable taxes', 'invoicing' ); ?>
88
+                    <input type="checkbox" name="disable_taxes" value="1" <?php checked($taxable, false); ?> id="wpinv_taxable">
89
+                    <?php _e('Disable taxes', 'invoicing'); ?>
90 90
                 </label>
91 91
             </div>
92 92
         </div>
93 93
         <?php } ?>
94 94
 
95
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?>
95
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?>
96 96
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
97
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
97
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
98 98
             <div class="gdmbx-td">
99
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
99
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
100 100
             </div>
101 101
         </div>
102 102
         <?php } ?>
103 103
     </div>
104 104
 </div>
105 105
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
106
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
106
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
107 107
         <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2">
108
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
109
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
108
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
109
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
110 110
         </select>
111 111
     </p>
112 112
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
113 113
 </div>
114
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
114
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
115 115
         <?php
116 116
     }
117 117
     
118
-    public static function resend_invoice( $post ) {
118
+    public static function resend_invoice($post) {
119 119
         global $wpi_mb_invoice;
120 120
         
121
-        if ( empty( $wpi_mb_invoice ) ) {
121
+        if (empty($wpi_mb_invoice)) {
122 122
             return;
123 123
         }
124 124
         
125 125
         $text = array(
126
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
127
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
126
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
127
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
128 128
         );
129 129
             
130 130
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
131
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
131
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
132 132
         
133
-        if ( $email = $wpi_mb_invoice->get_email() ) {
133
+        if ($email = $wpi_mb_invoice->get_email()) {
134 134
             $email_actions = array();
135
-            $email_actions['email_url']      = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) );
136
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
135
+            $email_actions['email_url']      = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)));
136
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
137 137
             
138
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
138
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
139 139
         ?>
140 140
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
141
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
142
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
143
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
141
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
142
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
143
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
144 144
         <?php } ?>
145 145
         <?php
146 146
         }
147 147
         
148
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
148
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
149 149
     }
150 150
     
151
-    public static function subscriptions( $post ) {
152
-        $invoice = wpinv_get_invoice( $post->ID );
151
+    public static function subscriptions($post) {
152
+        $invoice = wpinv_get_invoice($post->ID);
153 153
 
154
-        if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
155
-            $subscription = wpinv_get_subscription( $invoice );
154
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
155
+            $subscription = wpinv_get_subscription($invoice);
156 156
 
157
-            if ( empty( $subscription ) ) {
157
+            if (empty($subscription)) {
158 158
                 ?>
159
-                <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p>
159
+                <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p>
160 160
                 <?php
161 161
                 return;
162 162
             }
163
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency );
164
-            $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
165
-            $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
163
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
164
+            $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency;
165
+            $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id));
166 166
             $payments = $subscription->get_child_payments();
167 167
             ?>
168 168
             <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p>
169
-            <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?>
169
+            <?php if (!empty($subscription) && !empty($subscription->id)) { ?>
170 170
                 <p class="wpi-meta-row wpi-sub-id">
171
-                    <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
171
+                    <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
172 172
             <?php } ?>
173 173
             <p class="wpi-meta-row wpi-bill-cycle">
174
-                <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?>
174
+                <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?>
175 175
             </p>
176 176
             <p class="wpi-meta-row wpi-billed-times">
177
-                <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?>
177
+                <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?>
178 178
             </p>
179 179
             <p class="wpi-meta-row wpi-start-date">
180
-                <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
180
+                <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?>
181 181
             </p>
182 182
             <p class="wpi-meta-row wpi-end-date">
183
-                <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?>
183
+                <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?>
184 184
             </p>
185
-            <?php if ( $subscription->status ) { ?>
185
+            <?php if ($subscription->status) { ?>
186 186
                 <p class="wpi-meta-row wpi-sub-status">
187
-                    <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
187
+                    <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
188 188
                 </p>
189 189
             <?php } ?>
190
-            <?php if ( !empty( $payments ) ) { ?>
191
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
190
+            <?php if (!empty($payments)) { ?>
191
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
192 192
                 <ul id="wpi-sub-payments">
193
-                <?php foreach ( $payments as $payment ) {
193
+                <?php foreach ($payments as $payment) {
194 194
                     $invoice_id = $payment->ID;
195 195
                     ?>
196 196
                     <li>
197
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
198
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
199
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
197
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
198
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
199
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
200 200
                     </li>
201 201
                 <?php } ?>
202 202
                 </ul>
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
         }
205 205
     }
206 206
     
207
-    public static function renewals( $post ) {
208
-        $invoice = wpinv_get_invoice( $post->ID );
207
+    public static function renewals($post) {
208
+        $invoice = wpinv_get_invoice($post->ID);
209 209
         
210
-        if ( wpinv_is_subscription_payment( $invoice ) ) {
211
-            $parent_url = get_edit_post_link( $invoice->parent_invoice );
212
-            $parent_id  = wpinv_get_invoice_number( $invoice->parent_invoice );
213
-            $subscription = wpinv_get_subscription( $invoice );
210
+        if (wpinv_is_subscription_payment($invoice)) {
211
+            $parent_url = get_edit_post_link($invoice->parent_invoice);
212
+            $parent_id  = wpinv_get_invoice_number($invoice->parent_invoice);
213
+            $subscription = wpinv_get_subscription($invoice);
214 214
         ?>
215
-        <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
216
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
215
+        <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
216
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
217 217
         <?php
218 218
         }
219 219
     }
@@ -221,47 +221,47 @@  discard block
 block discarded – undo
221 221
     /**
222 222
      * Renders a metabox to edit a payment form.
223 223
      */
224
-    public static function payment_form( $post ) {
225
-        WPInv_Meta_Box_Form_Items::output_options( $post );
224
+    public static function payment_form($post) {
225
+        WPInv_Meta_Box_Form_Items::output_options($post);
226 226
     }
227 227
 
228 228
     /**
229 229
      * Renders a metabox to select items.
230 230
      */
231
-    public static function payment_form_items( $post ) {
232
-        WPInv_Meta_Box_Form_Items::output( $post );
231
+    public static function payment_form_items($post) {
232
+        WPInv_Meta_Box_Form_Items::output($post);
233 233
     }
234 234
     
235
-    public static function payment_meta( $post ) {
235
+    public static function payment_meta($post) {
236 236
         global $wpi_mb_invoice;
237 237
 
238
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
239
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
238
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
239
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
240 240
             $set_dateway = true;
241 241
         }
242 242
         
243 243
         ?>
244 244
         <p class="wpi-meta-row">
245
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
246
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
245
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
246
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
247 247
             <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway">
248
-                <?php foreach ( $gateways as $name => $gateway ) {
249
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
248
+                <?php foreach ($gateways as $name => $gateway) {
249
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
250 250
                         continue;
251 251
                     }
252 252
                     ?>
253
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
253
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
254 254
                 <?php } ?>
255 255
             </select>
256 256
         <?php } else { 
257
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) );
257
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway));
258 258
         } ?>
259 259
         </p>
260
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
261
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
260
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
261
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
262 262
         <?php } ?>
263
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
264
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
263
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
264
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
265 265
         <?php } ?>
266 266
         <?php
267 267
     }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float) $invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -74,45 +74,45 @@  discard block
 block discarded – undo
74 74
                                         <td class="id">
75 75
                                         </td>
76 76
                                         <td class="title">
77
-                                            <input type="text" class="regular-text" placeholder="<?php _e( 'Item Name', 'invoicing' ); ?>" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
77
+                                            <input type="text" class="regular-text" placeholder="<?php _e('Item Name', 'invoicing'); ?>" value="" name="_wpinv_quick[name]">
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule wpi_select2',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class wpi_select2',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,37 +120,37 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type wpi_select2',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
127 127
 
128 128
                                             <div class="wp-clearfix">
129 129
                                                 <?php 
130
-                                                    echo wpinv_html_textarea( array(
130
+                                                    echo wpinv_html_textarea(array(
131 131
                                                         'name'  => '_wpinv_quick[excerpt]',
132 132
                                                         'id'    => '_wpinv_quick_excerpt',
133 133
                                                         'value' => '',
134 134
                                                         'class' => 'large-text',
135
-                                                        'label' => __( 'Item description', 'invoicing' ),
136
-                                                    ) ); 
135
+                                                        'label' => __('Item description', 'invoicing'),
136
+                                                    )); 
137 137
                                                 ?>
138 138
                                             </div>
139 139
 
140 140
                                             <div class="wp-clearfix">
141 141
                                                 <label class="wpi-item-actions">
142 142
                                                     <span class="input-text-wrap">
143
-                                                        <input type="button" value="<?php esc_attr_e( 'Add', 'invoicing' ); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
143
+                                                        <input type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" id="wpinv-save-item"><input type="button" value="Cancel" class="button button-secondary" id="wpinv-cancel-item">
144 144
                                                     </span>
145 145
                                                 </label>
146 146
                                             </div>
147 147
                                         </td>
148 148
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
149
-                                        <?php if ( $item_quantities ) { ?>
149
+                                        <?php if ($item_quantities) { ?>
150 150
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
151 151
                                         <?php } ?>
152 152
                                         <td class="total"></td>
153
-                                        <?php if ( $use_taxes ) { ?>
153
+                                        <?php if ($use_taxes) { ?>
154 154
                                         <td class="tax"></td>
155 155
                                         <?php } ?>
156 156
                                         <td class="action"></td>
@@ -163,29 +163,29 @@  discard block
 block discarded – undo
163 163
                         <td colspan="<?php echo $cols; ?>"></td>
164 164
                     </tr>
165 165
                     <tr class="totals">
166
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
166
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
167 167
                         <td colspan="4">
168 168
                             <table cellspacing="0" cellpadding="0">
169 169
                                 <tr class="subtotal">
170
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
171
-                                    <td class="total"><?php echo $subtotal;?></td>
170
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
171
+                                    <td class="total"><?php echo $subtotal; ?></td>
172 172
                                     <td class="action"></td>
173 173
                                 </tr>
174 174
                                 <tr class="discount">
175
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
176
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
175
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
176
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
177 177
                                     <td class="action"></td>
178 178
                                 </tr>
179
-                                <?php if ( $use_taxes ) { ?>
179
+                                <?php if ($use_taxes) { ?>
180 180
                                 <tr class="tax">
181
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
182
-                                    <td class="total"><?php echo $tax;?></td>
181
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
182
+                                    <td class="total"><?php echo $tax; ?></td>
183 183
                                     <td class="action"></td>
184 184
                                 </tr>
185 185
                                 <?php } ?>
186 186
                                 <tr class="total">
187
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
188
-                                    <td class="total"><?php echo $total;?></td>
187
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
188
+                                    <td class="total"><?php echo $total; ?></td>
189 189
                                     <td class="action"></td>
190 190
                                 </tr>
191 191
                             </table>
@@ -196,90 +196,90 @@  discard block
 block discarded – undo
196 196
             <div class="wpinv-actions">
197 197
                 <?php ob_start(); ?>
198 198
                 <?php
199
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
200
-                        if ( !$invoice->is_recurring() ) {
201
-                            echo wpinv_item_dropdown( array(
199
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
200
+                        if (!$invoice->is_recurring()) {
201
+                            echo wpinv_item_dropdown(array(
202 202
                                 'name'             => 'wpinv_invoice_item',
203 203
                                 'id'               => 'wpinv_invoice_item',
204 204
                                 'show_recurring'   => true,
205 205
                                 'class'            => 'wpi_select2',
206
-                            ) );
206
+                            ));
207 207
                     ?>
208
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
208
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
209 209
                     <?php } ?>
210
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
211
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
210
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
211
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
212 212
             </div>
213 213
         </div>
214 214
         <?php
215 215
     }
216 216
 
217
-    public static function prices( $post ) {        
217
+    public static function prices($post) {        
218 218
         $symbol         = wpinv_currency_symbol();
219 219
         $position       = wpinv_currency_position();
220
-        $item           = new WPInv_Item( $post->ID );
220
+        $item           = new WPInv_Item($post->ID);
221 221
 
222 222
         $price                = $item->get_price();
223 223
         $is_dynamic_pricing   = $item->get_is_dynamic_pricing();
224 224
         $minimum_price        = $item->get_minimum_price();
225 225
         $is_recurring         = $item->is_recurring();
226 226
         $period               = $item->get_recurring_period();
227
-        $interval             = absint( $item->get_recurring_interval() );
228
-        $times                = absint( $item->get_recurring_limit() );
227
+        $interval             = absint($item->get_recurring_interval());
228
+        $times                = absint($item->get_recurring_limit());
229 229
         $free_trial           = $item->has_free_trial();
230 230
         $trial_interval       = $item->get_trial_interval();
231 231
         $trial_period         = $item->get_trial_period();
232 232
 
233 233
         $intervals            = array();
234
-        for ( $i = 1; $i <= 90; $i++ ) {
234
+        for ($i = 1; $i <= 90; $i++) {
235 235
             $intervals[$i] = $i;
236 236
         }
237 237
 
238
-        $interval       = $interval > 0 ? $interval : 1;
238
+        $interval = $interval > 0 ? $interval : 1;
239 239
 
240 240
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
241 241
 
242 242
         $minimum_price_style = 'margin-left: 24px;';
243
-        if(! $is_dynamic_pricing ) {
243
+        if (!$is_dynamic_pricing) {
244 244
             $minimum_price_style .= 'display: none;';
245 245
         }
246 246
 
247 247
         ?>
248
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
249
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
248
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
249
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
250 250
         </p>
251 251
 
252
-    <?php if( $item->supports_dynamic_pricing() ) { ?>
252
+    <?php if ($item->supports_dynamic_pricing()) { ?>
253 253
 
254 254
         <p class="wpinv-row-name-your-price">
255 255
             <label>
256
-                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked( 1, $is_dynamic_pricing ); ?> />
257
-                <?php echo apply_filters( 'wpinv_name_your_price_toggle_text', __( 'User can set a custom price', 'invoicing' ) ); ?>
256
+                <input type="checkbox" name="wpinv_name_your_price" id="wpinv_name_your_price" value="1" <?php checked(1, $is_dynamic_pricing); ?> />
257
+                <?php echo apply_filters('wpinv_name_your_price_toggle_text', __('User can set a custom price', 'invoicing')); ?>
258 258
             </label>
259
-            <?php do_action( 'wpinv_prices_metabox_name_your_price_field', $item ); ?>
259
+            <?php do_action('wpinv_prices_metabox_name_your_price_field', $item); ?>
260 260
         </p>
261 261
 
262 262
         <p class="wpinv-row-minimum-price" style="<?php echo $minimum_price_style; ?>">
263 263
             <label>
264
-                <?php _e( 'Minimum Price', 'invoicing' ); ?>
265
-                <?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $minimum_price;?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?>
264
+                <?php _e('Minimum Price', 'invoicing'); ?>
265
+                <?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $minimum_price; ?>" id="wpinv_minimum_price" name="wpinv_minimum_price" class="medium-text wpi-field-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?>
266 266
             </label>
267 267
 
268
-            <?php do_action( 'wpinv_prices_metabox_minimum_price_field', $item ); ?>
268
+            <?php do_action('wpinv_prices_metabox_minimum_price_field', $item); ?>
269 269
         </p>
270 270
 
271 271
     <?php } ?>
272 272
 
273 273
         <p class="wpinv-row-is-recurring">
274 274
             <label for="wpinv_is_recurring">
275
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
276
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
275
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
276
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
277 277
             </label>
278
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
278
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
279 279
         </p>
280
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
281
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
282
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
280
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
281
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select wpi_select2" id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
282
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
283 283
                 'options'          => $intervals,
284 284
                 'name'             => 'wpinv_recurring_interval',
285 285
                 'id'               => 'wpinv_recurring_interval',
@@ -287,30 +287,30 @@  discard block
 block discarded – undo
287 287
                 'show_option_all'  => false,
288 288
                 'show_option_none' => false,
289 289
                 'class'            => 'wpi_select2',
290
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
291
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
290
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
291
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
292 292
             <span class="clear wpi-trial-clr"></span>
293 293
             <label class="wpinv-free-trial" for="wpinv_free_trial">
294
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
295
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
294
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool) $free_trial); ?> /> 
295
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
296 296
             </label>
297 297
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
298
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
298
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select wpi_select2" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
299 299
             </label>
300
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
300
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
301 301
         </p>
302
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
303
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
302
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
303
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
304 304
         <?php
305 305
     }
306 306
 
307
-    public static function vat_rules( $post ) {
307
+    public static function vat_rules($post) {
308 308
         global $wpinv_euvat;
309 309
 
310
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
310
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
311 311
         ?>
312
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
313
-        <?php echo wpinv_html_select( array(
312
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
313
+        <?php echo wpinv_html_select(array(
314 314
                     'options'          => $wpinv_euvat->get_rules(),
315 315
                     'name'             => 'wpinv_vat_rules',
316 316
                     'id'               => 'wpinv_vat_rules',
@@ -318,20 +318,20 @@  discard block
 block discarded – undo
318 318
                     'show_option_all'  => false,
319 319
                     'show_option_none' => false,
320 320
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules wpi_select2',
321
-                ) ); ?>
321
+                )); ?>
322 322
         </p>
323
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
324
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
325
-        <p class="wpi-m0"><?php _e( 'Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing' ); ?></p>
323
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
324
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
325
+        <p class="wpi-m0"><?php _e('Select "Tax-Free" if you do not want to charge VAT for this item.', 'invoicing'); ?></p>
326 326
         <?php
327 327
     }
328 328
 
329
-    public static function vat_classes( $post ) {
329
+    public static function vat_classes($post) {
330 330
         global $wpinv_euvat;
331 331
         
332
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
332
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
333 333
         ?>
334
-        <p><?php echo wpinv_html_select( array(
334
+        <p><?php echo wpinv_html_select(array(
335 335
                     'options'          => $wpinv_euvat->get_all_classes(),
336 336
                     'name'             => 'wpinv_vat_class',
337 337
                     'id'               => 'wpinv_vat_class',
@@ -339,18 +339,18 @@  discard block
 block discarded – undo
339 339
                     'show_option_all'  => false,
340 340
                     'show_option_none' => false,
341 341
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class wpi_select2',
342
-                ) ); ?>
342
+                )); ?>
343 343
         </p>
344
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
344
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
345 345
         <?php
346 346
     }
347 347
 
348
-    public static function item_info( $post ) {
349
-        $item_type = wpinv_get_item_type( $post->ID );
350
-        do_action( 'wpinv_item_info_metabox_before', $post );
348
+    public static function item_info($post) {
349
+        $item_type = wpinv_get_item_type($post->ID);
350
+        do_action('wpinv_item_info_metabox_before', $post);
351 351
         ?>
352
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
353
-        <?php echo wpinv_html_select( array(
352
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
353
+        <?php echo wpinv_html_select(array(
354 354
                     'options'          => wpinv_get_item_types(),
355 355
                     'name'             => 'wpinv_item_type',
356 356
                     'id'               => 'wpinv_item_type',
@@ -358,135 +358,135 @@  discard block
 block discarded – undo
358 358
                     'show_option_all'  => false,
359 359
                     'show_option_none' => false,
360 360
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
361
-                ) ); ?>
361
+                )); ?>
362 362
         </p>
363
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
363
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
364 364
         <?php
365
-        do_action( 'wpinv_item_info_metabox_after', $post );
365
+        do_action('wpinv_item_info_metabox_after', $post);
366 366
     }
367 367
 
368
-    public static function meta_values( $post ) {
369
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
368
+    public static function meta_values($post) {
369
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
370 370
             'type',
371 371
             'custom_id'
372
-        ) );
372
+        ));
373 373
 
374
-        if ( empty( $meta_keys ) ) {
374
+        if (empty($meta_keys)) {
375 375
             return;
376 376
         }
377 377
 
378
-        do_action( 'wpinv_meta_values_metabox_before', $post );
378
+        do_action('wpinv_meta_values_metabox_before', $post);
379 379
 
380
-        foreach ( $meta_keys as $meta_key ) {
380
+        foreach ($meta_keys as $meta_key) {
381 381
             ?>
382
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
382
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
383 383
             <?php 
384 384
         }
385 385
 
386
-        do_action( 'wpinv_meta_values_metabox_after', $post );
386
+        do_action('wpinv_meta_values_metabox_after', $post);
387 387
     }
388 388
 
389
-    public static function save( $post_id, $data, $post ) {
390
-        $invoice        = new WPInv_Invoice( $post_id );
389
+    public static function save($post_id, $data, $post) {
390
+        $invoice        = new WPInv_Invoice($post_id);
391 391
 
392 392
         // Billing
393
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
394
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
395
-        $company        = sanitize_text_field( $data['wpinv_company'] );
396
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
397
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
398
-        $address        = sanitize_text_field( $data['wpinv_address'] );
399
-        $city           = sanitize_text_field( $data['wpinv_city'] );
400
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
401
-        $country        = sanitize_text_field( $data['wpinv_country'] );
402
-        $state          = sanitize_text_field( $data['wpinv_state'] );
393
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
394
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
395
+        $company        = sanitize_text_field($data['wpinv_company']);
396
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
397
+        $phone          = sanitize_text_field($data['wpinv_phone']);
398
+        $address        = sanitize_text_field($data['wpinv_address']);
399
+        $city           = sanitize_text_field($data['wpinv_city']);
400
+        $zip            = sanitize_text_field($data['wpinv_zip']);
401
+        $country        = sanitize_text_field($data['wpinv_country']);
402
+        $state          = sanitize_text_field($data['wpinv_state']);
403 403
 
404 404
         // Details
405
-        $status         = sanitize_text_field( $data['wpinv_status'] );
406
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
407
-        $number         = sanitize_text_field( $data['wpinv_number'] );
408
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
405
+        $status         = sanitize_text_field($data['wpinv_status']);
406
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
407
+        $number         = sanitize_text_field($data['wpinv_number']);
408
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
409 409
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
410 410
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
411 411
 
412 412
         $disable_taxes = 0;
413 413
 
414
-        if ( ! empty( $data['disable_taxes'] ) ) {
414
+        if (!empty($data['disable_taxes'])) {
415 415
             $disable_taxes = 1;
416 416
         }
417 417
 
418
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
419
-
420
-        $invoice->set( 'due_date', $due_date );
421
-        $invoice->set( 'first_name', $first_name );
422
-        $invoice->set( 'last_name', $last_name );
423
-        $invoice->set( 'company', $company );
424
-        $invoice->set( 'vat_number', $vat_number );
425
-        $invoice->set( 'phone', $phone );
426
-        $invoice->set( 'address', $address );
427
-        $invoice->set( 'city', $city );
428
-        $invoice->set( 'zip', $zip );
429
-        $invoice->set( 'country', $country );
430
-        $invoice->set( 'state', $state );
431
-        $invoice->set( 'status', $status );
432
-        $invoice->set( 'set', $status );
418
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
419
+
420
+        $invoice->set('due_date', $due_date);
421
+        $invoice->set('first_name', $first_name);
422
+        $invoice->set('last_name', $last_name);
423
+        $invoice->set('company', $company);
424
+        $invoice->set('vat_number', $vat_number);
425
+        $invoice->set('phone', $phone);
426
+        $invoice->set('address', $address);
427
+        $invoice->set('city', $city);
428
+        $invoice->set('zip', $zip);
429
+        $invoice->set('country', $country);
430
+        $invoice->set('state', $state);
431
+        $invoice->set('status', $status);
432
+        $invoice->set('set', $status);
433 433
         //$invoice->set( 'number', $number );
434 434
         //$invoice->set( 'discounts', $discounts );
435 435
         //$invoice->set( 'discount', $discount );
436
-        $invoice->set( 'disable_taxes', $disable_taxes );
437
-        $invoice->set( 'ip', $ip );
436
+        $invoice->set('disable_taxes', $disable_taxes);
437
+        $invoice->set('ip', $ip);
438 438
         $invoice->old_status = $_POST['original_post_status'];
439 439
         
440 440
         $currency = $invoice->get_currency();
441
-        if ( ! empty( sanitize_text_field( $data['wpinv_currency'] ) ) ) {
442
-            $currency = sanitize_text_field( $data['wpinv_currency'] );
441
+        if (!empty(sanitize_text_field($data['wpinv_currency']))) {
442
+            $currency = sanitize_text_field($data['wpinv_currency']);
443 443
         }
444 444
 
445
-        if ( empty( $currency ) ) {
445
+        if (empty($currency)) {
446 446
             $currency = wpinv_get_currency();
447 447
         }
448 448
 
449
-        if ( ! $invoice->is_paid() ) {
449
+        if (!$invoice->is_paid()) {
450 450
             $invoice->currency = $currency;
451 451
         }
452 452
 
453
-        if ( !empty( $data['wpinv_gateway'] ) ) {
454
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
453
+        if (!empty($data['wpinv_gateway'])) {
454
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
455 455
         }
456 456
         $saved = $invoice->save();
457 457
 
458 458
         // Check for payment notes
459
-        if ( !empty( $data['invoice_note'] ) ) {
460
-            $note               = wp_kses( $data['invoice_note'], array() );
461
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
459
+        if (!empty($data['invoice_note'])) {
460
+            $note               = wp_kses($data['invoice_note'], array());
461
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
462 462
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
463 463
 
464
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
464
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
465 465
         }
466 466
 
467 467
         // Update user address if empty.
468
-        if ( $saved && !empty( $invoice ) ) {
469
-            if ( $user_id = $invoice->get_user_id() ) {
470
-                $user_address = wpinv_get_user_address( $user_id, false );
468
+        if ($saved && !empty($invoice)) {
469
+            if ($user_id = $invoice->get_user_id()) {
470
+                $user_address = wpinv_get_user_address($user_id, false);
471 471
 
472 472
                 if (empty($user_address['first_name'])) {
473
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
474
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
473
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
474
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
475 475
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
476
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
476
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
477 477
                 }
478 478
 
479 479
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
480
-                    update_user_meta( $user_id, '_wpinv_address', $address );
481
-                    update_user_meta( $user_id, '_wpinv_city', $city );
482
-                    update_user_meta( $user_id, '_wpinv_state', $state );
483
-                    update_user_meta( $user_id, '_wpinv_country', $country );
484
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
485
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
480
+                    update_user_meta($user_id, '_wpinv_address', $address);
481
+                    update_user_meta($user_id, '_wpinv_city', $city);
482
+                    update_user_meta($user_id, '_wpinv_state', $state);
483
+                    update_user_meta($user_id, '_wpinv_country', $country);
484
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
485
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
486 486
                 }
487 487
             }
488 488
 
489
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
489
+            do_action('wpinv_invoice_metabox_saved', $invoice);
490 490
         }
491 491
 
492 492
         return $saved;
Please login to merge, or discard this patch.
includes/data/sample-payment-form-items.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 return array(
14 14
 
Please login to merge, or discard this patch.
includes/data/sample-payment-form.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 return array(
14 14
 
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
 
17 17
         'placeholder' => '[email protected]',
18 18
         'value'       => '',
19
-        'label'       => __( 'Billing Email', 'invoicing' ),
19
+        'label'       => __('Billing Email', 'invoicing'),
20 20
         'description' => '',
21 21
         'required'    => true,
22 22
         'id'          => 'mmdwqzpox',
@@ -41,8 +41,8 @@  discard block
 block discarded – undo
41 41
 
42 42
         'value'       =>'',
43 43
         'class'       => 'btn-primary',
44
-        'label'       => __( 'Pay Now »', 'invoicing' ),
45
-        'description' => __( 'By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
44
+        'label'       => __('Pay Now »', 'invoicing'),
45
+        'description' => __('By continuing with your payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'),
46 46
         'id'          => 'rtqljyy',
47 47
         'name'        => 'rtqljyy',
48 48
         'type'        => 'pay_button',
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +781 added lines, -781 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
@@ -28,48 +28,48 @@  discard block
 block discarded – undo
28 28
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
29 29
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
30 30
  */
31
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
32
-    if ( empty( $invoice_data ) ) {
31
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
32
+    if (empty($invoice_data)) {
33 33
         return false;
34 34
     }
35 35
     
36
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
37
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
36
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
37
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
38 38
     }
39 39
     
40 40
     // If no user id is provided, default to the current user id
41
-    if ( empty( $invoice_data['user_id'] ) ) {
41
+    if (empty($invoice_data['user_id'])) {
42 42
         $invoice_data['user_id'] = get_current_user_id();
43 43
     }
44 44
     
45
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
45
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
46 46
     
47
-    if ( empty( $invoice_data['status'] ) ) {
47
+    if (empty($invoice_data['status'])) {
48 48
         $invoice_data['status'] = 'wpi-pending';
49 49
     }
50 50
 
51
-    if ( empty( $invoice_data['post_type'] ) ) {
51
+    if (empty($invoice_data['post_type'])) {
52 52
         $invoice_data['post_type'] = 'wpi_invoice';
53 53
     }
54 54
     
55
-    if ( empty( $invoice_data['ip'] ) ) {
55
+    if (empty($invoice_data['ip'])) {
56 56
         $invoice_data['ip'] = wpinv_get_ip();
57 57
     }
58 58
 
59 59
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
60 60
     $default_args = array(
61
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
62
-        'user_id'       => (int)$invoice_data['user_id'],
61
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
62
+        'user_id'       => (int) $invoice_data['user_id'],
63 63
         'status'        => $invoice_data['status'],
64 64
         'post_type'     => $invoice_data['post_type'],
65 65
     );
66 66
 
67
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
68
-    if ( is_wp_error( $invoice ) ) {
67
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
68
+    if (is_wp_error($invoice)) {
69 69
         return $wp_error ? $invoice : 0;
70 70
     }
71 71
     
72
-    if ( empty( $invoice_data['invoice_id'] ) ) {
72
+    if (empty($invoice_data['invoice_id'])) {
73 73
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
74 74
     }
75 75
     
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
         'discount'              => array(),
93 93
     );
94 94
 
95
-    if ( $user_id = (int)$invoice->get_user_id() ) {
96
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
97
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
95
+    if ($user_id = (int) $invoice->get_user_id()) {
96
+        if ($user_address = wpinv_get_user_address($user_id)) {
97
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
98 98
         }
99 99
     }
100 100
     
101
-    if ( empty( $invoice_data['user_info'] ) ) {
101
+    if (empty($invoice_data['user_info'])) {
102 102
         $invoice_data['user_info'] = array();
103 103
     }
104 104
     
105
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
105
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
106 106
     
107
-    if ( empty( $user_info['first_name'] ) ) {
107
+    if (empty($user_info['first_name'])) {
108 108
         $user_info['first_name'] = $default_user_info['first_name'];
109 109
         $user_info['last_name'] = $default_user_info['last_name'];
110 110
     }
111 111
     
112
-    if ( empty( $user_info['country'] ) ) {
112
+    if (empty($user_info['country'])) {
113 113
         $user_info['country'] = $default_user_info['country'];
114 114
         $user_info['state'] = $default_user_info['state'];
115 115
         $user_info['city'] = $default_user_info['city'];
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
         $user_info['phone'] = $default_user_info['phone'];
119 119
     }
120 120
     
121
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
122
-        $user_info['discount'] = (array)$user_info['discount'];
121
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
122
+        $user_info['discount'] = (array) $user_info['discount'];
123 123
     }
124 124
 
125 125
     // Payment details
126 126
     $payment_details = array();
127
-    if ( !empty( $invoice_data['payment_details'] ) ) {
127
+    if (!empty($invoice_data['payment_details'])) {
128 128
         $default_payment_details = array(
129 129
             'gateway'           => 'manual',
130 130
             'gateway_title'     => '',
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
             'transaction_id'    => '',
133 133
         );
134 134
         
135
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
135
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
136 136
         
137
-        if ( empty( $payment_details['gateway'] ) ) {
137
+        if (empty($payment_details['gateway'])) {
138 138
             $payment_details['gateway'] = 'manual';
139 139
         }
140 140
         
141
-        if ( empty( $payment_details['currency'] ) ) {
141
+        if (empty($payment_details['currency'])) {
142 142
             $payment_details['currency'] = wpinv_get_default_country();
143 143
         }
144 144
         
145
-        if ( empty( $payment_details['gateway_title'] ) ) {
146
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
145
+        if (empty($payment_details['gateway_title'])) {
146
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
147 147
         }
148 148
     }
149 149
     
150
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
151
-    
152
-    if ( !empty( $payment_details ) ) {
153
-        $invoice->set( 'currency', $payment_details['currency'] );
154
-        $invoice->set( 'gateway', $payment_details['gateway'] );
155
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
156
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
157
-    }
158
-    
159
-    $invoice->set( 'user_info', $user_info );
160
-    $invoice->set( 'first_name', $user_info['first_name'] );
161
-    $invoice->set( 'last_name', $user_info['last_name'] );
162
-    $invoice->set( 'address', $user_info['address'] );
163
-    $invoice->set( 'company', $user_info['company'] );
164
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
165
-    $invoice->set( 'phone', $user_info['phone'] );
166
-    $invoice->set( 'city', $user_info['city'] );
167
-    $invoice->set( 'country', $user_info['country'] );
168
-    $invoice->set( 'state', $user_info['state'] );
169
-    $invoice->set( 'zip', $user_info['zip'] );
170
-    $invoice->set( 'discounts', $user_info['discount'] );
171
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
172
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
173
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
174
-    
175
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
176
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
177
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
178
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
179
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
180
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
150
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
151
+    
152
+    if (!empty($payment_details)) {
153
+        $invoice->set('currency', $payment_details['currency']);
154
+        $invoice->set('gateway', $payment_details['gateway']);
155
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
156
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
157
+    }
158
+    
159
+    $invoice->set('user_info', $user_info);
160
+    $invoice->set('first_name', $user_info['first_name']);
161
+    $invoice->set('last_name', $user_info['last_name']);
162
+    $invoice->set('address', $user_info['address']);
163
+    $invoice->set('company', $user_info['company']);
164
+    $invoice->set('vat_number', $user_info['vat_number']);
165
+    $invoice->set('phone', $user_info['phone']);
166
+    $invoice->set('city', $user_info['city']);
167
+    $invoice->set('country', $user_info['country']);
168
+    $invoice->set('state', $user_info['state']);
169
+    $invoice->set('zip', $user_info['zip']);
170
+    $invoice->set('discounts', $user_info['discount']);
171
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
172
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
173
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
174
+    
175
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
176
+        foreach ($invoice_data['cart_details'] as $key => $item) {
177
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
178
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
179
+            $name           = !empty($item['name']) ? $item['name'] : '';
180
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
181 181
             
182
-            $post_item  = new WPInv_Item( $item_id );
183
-            if ( !empty( $post_item ) ) {
184
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
182
+            $post_item = new WPInv_Item($item_id);
183
+            if (!empty($post_item)) {
184
+                $name       = !empty($name) ? $name : $post_item->get_name();
185 185
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
186 186
             } else {
187 187
                 continue;
@@ -191,262 +191,262 @@  discard block
 block discarded – undo
191 191
                 'name'          => $name,
192 192
                 'quantity'      => $quantity,
193 193
                 'item_price'    => $item_price,
194
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
195
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
196
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
197
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
198
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
194
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
195
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
196
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
197
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
198
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
199 199
             );
200 200
 
201
-            $invoice->add_item( $item_id, $args );
201
+            $invoice->add_item($item_id, $args);
202 202
         }
203 203
     }
204 204
 
205
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
205
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
206 206
 
207
-    if ( isset( $invoice_data['post_date'] ) ) {
208
-        $invoice->set( 'date', $invoice_data['post_date'] );
207
+    if (isset($invoice_data['post_date'])) {
208
+        $invoice->set('date', $invoice_data['post_date']);
209 209
     }
210 210
     
211 211
     // Invoice due date
212
-    if ( isset( $invoice_data['due_date'] ) ) {
213
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
212
+    if (isset($invoice_data['due_date'])) {
213
+        $invoice->set('due_date', $invoice_data['due_date']);
214 214
     }
215 215
     
216 216
     $invoice->save();
217 217
     
218 218
     // Add notes
219
-    if ( !empty( $invoice_data['private_note'] ) ) {
220
-        $invoice->add_note( $invoice_data['private_note'] );
219
+    if (!empty($invoice_data['private_note'])) {
220
+        $invoice->add_note($invoice_data['private_note']);
221 221
     }
222
-    if ( !empty( $invoice_data['user_note'] ) ) {
223
-        $invoice->add_note( $invoice_data['user_note'], true );
222
+    if (!empty($invoice_data['user_note'])) {
223
+        $invoice->add_note($invoice_data['user_note'], true);
224 224
     }
225 225
     
226
-    if ( $invoice->is_quote() ) {
226
+    if ($invoice->is_quote()) {
227 227
 
228
-        if ( isset( $invoice_data['valid_until'] ) ) {
229
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
228
+        if (isset($invoice_data['valid_until'])) {
229
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
230 230
         }
231 231
         return $invoice;
232 232
 
233 233
     }
234 234
 
235
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
235
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
236 236
 
237
-    if ( ! empty( $invoice->ID ) ) {
237
+    if (!empty($invoice->ID)) {
238 238
         global $wpi_userID, $wpinv_ip_address_country;
239 239
         
240 240
         $checkout_session = wpinv_get_checkout_session();
241 241
         
242 242
         $data_session                   = array();
243 243
         $data_session['invoice_id']     = $invoice->ID;
244
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
244
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
245 245
         
246
-        wpinv_set_checkout_session( $data_session );
246
+        wpinv_set_checkout_session($data_session);
247 247
         
248
-        $wpi_userID         = (int)$invoice->get_user_id();
248
+        $wpi_userID         = (int) $invoice->get_user_id();
249 249
         
250
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
250
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
251 251
         $_POST['state']     = $invoice->state;
252 252
 
253
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
254
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
253
+        $invoice->set('country', sanitize_text_field($_POST['country']));
254
+        $invoice->set('state', sanitize_text_field($_POST['state']));
255 255
         
256 256
         $wpinv_ip_address_country = $invoice->country;
257 257
         
258
-        $invoice = $invoice->recalculate_totals( true );
258
+        $invoice = $invoice->recalculate_totals(true);
259 259
         
260
-        wpinv_set_checkout_session( $checkout_session );
260
+        wpinv_set_checkout_session($checkout_session);
261 261
                     
262 262
         return $invoice;
263 263
     }
264 264
     
265
-    if ( $wp_error ) {
266
-        if ( is_wp_error( $invoice ) ) {
265
+    if ($wp_error) {
266
+        if (is_wp_error($invoice)) {
267 267
             return $invoice;
268 268
         } else {
269
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
269
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
270 270
         }
271 271
     } else {
272 272
         return 0;
273 273
     }
274 274
 }
275 275
 
276
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
277
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
276
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
277
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
278 278
 
279
-    if ( !$invoice_ID ) {
280
-        if ( $wp_error ) {
281
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
279
+    if (!$invoice_ID) {
280
+        if ($wp_error) {
281
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
282 282
         }
283 283
         return 0;
284 284
     }
285 285
 
286
-    $invoice = wpinv_get_invoice( $invoice_ID );
286
+    $invoice = wpinv_get_invoice($invoice_ID);
287 287
 
288
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
288
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
289 289
 
290
-    if ( empty( $invoice->ID ) ) {
291
-        if ( $wp_error ) {
292
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
290
+    if (empty($invoice->ID)) {
291
+        if ($wp_error) {
292
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
293 293
         }
294 294
         return 0;
295 295
     }
296 296
 
297
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
298
-        if ( $wp_error ) {
299
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
297
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
298
+        if ($wp_error) {
299
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
300 300
         }
301 301
         return 0;
302 302
     }
303 303
 
304 304
     // Invoice status
305
-    if ( !empty( $invoice_data['status'] ) ) {
306
-        $invoice->set( 'status', $invoice_data['status'] );
305
+    if (!empty($invoice_data['status'])) {
306
+        $invoice->set('status', $invoice_data['status']);
307 307
     }
308 308
 
309 309
     // Invoice date
310
-    if ( !empty( $invoice_data['post_date'] ) ) {
311
-        $invoice->set( 'date', $invoice_data['post_date'] );
310
+    if (!empty($invoice_data['post_date'])) {
311
+        $invoice->set('date', $invoice_data['post_date']);
312 312
     }
313 313
 
314 314
     // Invoice due date
315
-    if ( isset( $invoice_data['due_date'] ) ) {
316
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
315
+    if (isset($invoice_data['due_date'])) {
316
+        $invoice->set('due_date', $invoice_data['due_date']);
317 317
     }
318 318
 
319 319
     // Invoice IP address
320
-    if ( !empty( $invoice_data['ip'] ) ) {
321
-        $invoice->set( 'ip', $invoice_data['ip'] );
320
+    if (!empty($invoice_data['ip'])) {
321
+        $invoice->set('ip', $invoice_data['ip']);
322 322
     }
323 323
     
324 324
     // User info
325
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
326
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
325
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
326
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
327 327
 
328
-        if ( $discounts = $invoice->get_discounts() ) {
328
+        if ($discounts = $invoice->get_discounts()) {
329 329
             $set_discount = $discounts;
330 330
         } else {
331 331
             $set_discount = '';
332 332
         }
333 333
 
334 334
         // Manage discount
335
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
335
+        if (!empty($invoice_data['user_info']['discount'])) {
336 336
             // Remove discount
337
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
337
+            if ($invoice_data['user_info']['discount'] == 'none') {
338 338
                 $set_discount = '';
339 339
             } else {
340 340
                 $set_discount = $invoice_data['user_info']['discount'];
341 341
             }
342 342
 
343
-            $invoice->set( 'discounts', $set_discount );
343
+            $invoice->set('discounts', $set_discount);
344 344
         }
345 345
 
346 346
         $user_info['discount'] = $set_discount;
347 347
 
348
-        $invoice->set( 'user_info', $user_info );
348
+        $invoice->set('user_info', $user_info);
349 349
     }
350 350
 
351
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
352
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
351
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
352
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
353 353
 
354
-        if ( !empty( $remove_items[0]['id'] ) ) {
355
-            foreach ( $remove_items as $item ) {
356
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
357
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
358
-                if ( empty( $item_id ) ) {
354
+        if (!empty($remove_items[0]['id'])) {
355
+            foreach ($remove_items as $item) {
356
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
357
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
358
+                if (empty($item_id)) {
359 359
                     continue;
360 360
                 }
361 361
 
362
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
363
-                    if ( $item_id == $cart_item['id'] ) {
362
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
363
+                    if ($item_id == $cart_item['id']) {
364 364
                         $args = array(
365 365
                             'id'         => $item_id,
366 366
                             'quantity'   => $quantity,
367 367
                             'cart_index' => $cart_index
368 368
                         );
369 369
 
370
-                        $invoice->remove_item( $item_id, $args );
370
+                        $invoice->remove_item($item_id, $args);
371 371
                         break;
372 372
                     }
373 373
                 }
374 374
             }
375 375
         }
376 376
 
377
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
377
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
378 378
 
379
-        if ( !empty( $add_items[0]['id'] ) ) {
380
-            foreach ( $add_items as $item ) {
381
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
382
-                $post_item      = new WPInv_Item( $item_id );
383
-                if ( empty( $post_item ) ) {
379
+        if (!empty($add_items[0]['id'])) {
380
+            foreach ($add_items as $item) {
381
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
382
+                $post_item      = new WPInv_Item($item_id);
383
+                if (empty($post_item)) {
384 384
                     continue;
385 385
                 }
386 386
 
387 387
                 $valid_item = true;
388
-                if ( !empty( $recurring_item ) ) {
389
-                    if ( $recurring_item->ID != $item_id ) {
388
+                if (!empty($recurring_item)) {
389
+                    if ($recurring_item->ID != $item_id) {
390 390
                         $valid_item = false;
391 391
                     }
392
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
392
+                } else if (wpinv_is_recurring_item($item_id)) {
393 393
                     $valid_item = false;
394 394
                 }
395 395
                 
396
-                if ( !$valid_item ) {
397
-                    if ( $wp_error ) {
398
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
396
+                if (!$valid_item) {
397
+                    if ($wp_error) {
398
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
399 399
                     }
400 400
                     return 0;
401 401
                 }
402 402
 
403
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
404
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
405
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
403
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
404
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
405
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
406 406
 
407 407
                 $args = array(
408 408
                     'name'          => $name,
409 409
                     'quantity'      => $quantity,
410 410
                     'item_price'    => $item_price,
411
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
412
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
413
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
414
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
415
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
411
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
412
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
413
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
414
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
415
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
416 416
                 );
417 417
 
418
-                $invoice->add_item( $item_id, $args );
418
+                $invoice->add_item($item_id, $args);
419 419
             }
420 420
         }
421 421
     }
422 422
     
423 423
     // Payment details
424
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
425
-        if ( !empty( $payment_details['gateway'] ) ) {
426
-            $invoice->set( 'gateway', $payment_details['gateway'] );
424
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
425
+        if (!empty($payment_details['gateway'])) {
426
+            $invoice->set('gateway', $payment_details['gateway']);
427 427
         }
428 428
 
429
-        if ( !empty( $payment_details['transaction_id'] ) ) {
430
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
429
+        if (!empty($payment_details['transaction_id'])) {
430
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
431 431
         }
432 432
     }
433 433
 
434
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
434
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
435 435
 
436 436
     // Parent invoice
437
-    if ( !empty( $invoice_data['parent'] ) ) {
438
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
437
+    if (!empty($invoice_data['parent'])) {
438
+        $invoice->set('parent_invoice', $invoice_data['parent']);
439 439
     }
440 440
 
441 441
     // Save invoice data.
442 442
     $invoice->save();
443 443
     
444
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
445
-        if ( $wp_error ) {
446
-            if ( is_wp_error( $invoice ) ) {
444
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
445
+        if ($wp_error) {
446
+            if (is_wp_error($invoice)) {
447 447
                 return $invoice;
448 448
             } else {
449
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
449
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
450 450
             }
451 451
         } else {
452 452
             return 0;
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
     }
455 455
 
456 456
     // Add private note
457
-    if ( !empty( $invoice_data['private_note'] ) ) {
458
-        $invoice->add_note( $invoice_data['private_note'] );
457
+    if (!empty($invoice_data['private_note'])) {
458
+        $invoice->add_note($invoice_data['private_note']);
459 459
     }
460 460
 
461 461
     // Add user note
462
-    if ( !empty( $invoice_data['user_note'] ) ) {
463
-        $invoice->add_note( $invoice_data['user_note'], true );
462
+    if (!empty($invoice_data['user_note'])) {
463
+        $invoice->add_note($invoice_data['user_note'], true);
464 464
     }
465 465
 
466
-    if ( $invoice->is_quote() ) {
466
+    if ($invoice->is_quote()) {
467 467
 
468
-        if ( isset( $invoice_data['valid_until'] ) ) {
469
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
468
+        if (isset($invoice_data['valid_until'])) {
469
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
470 470
         }
471 471
         return $invoice;
472 472
 
@@ -478,466 +478,466 @@  discard block
 block discarded – undo
478 478
 
479 479
     $data_session                   = array();
480 480
     $data_session['invoice_id']     = $invoice->ID;
481
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
481
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
482 482
 
483
-    wpinv_set_checkout_session( $data_session );
483
+    wpinv_set_checkout_session($data_session);
484 484
 
485
-    $wpi_userID         = (int)$invoice->get_user_id();
485
+    $wpi_userID         = (int) $invoice->get_user_id();
486 486
 
487
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
487
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
488 488
     $_POST['state']     = $invoice->state;
489 489
 
490
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
491
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
490
+    $invoice->set('country', sanitize_text_field($_POST['country']));
491
+    $invoice->set('state', sanitize_text_field($_POST['state']));
492 492
 
493 493
     $wpinv_ip_address_country = $invoice->country;
494 494
 
495
-    $invoice = $invoice->recalculate_totals( true );
495
+    $invoice = $invoice->recalculate_totals(true);
496 496
 
497
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
497
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
498 498
 
499
-    wpinv_set_checkout_session( $checkout_session );
499
+    wpinv_set_checkout_session($checkout_session);
500 500
 
501 501
     return $invoice;
502 502
 }
503 503
 
504
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
505
-    if ( $cart && empty( $invoice_id ) ) {
506
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
504
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
505
+    if ($cart && empty($invoice_id)) {
506
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
507 507
     }
508 508
 
509
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+    $invoice = new WPInv_Invoice($invoice_id);
510 510
 
511
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
511
+    if (!empty($invoice) && !empty($invoice->ID)) {
512 512
         return $invoice;
513 513
     }
514 514
     
515 515
     return NULL;
516 516
 }
517 517
 
518
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
519
-    return wpinv_get_invoice( $invoice_id, true );
518
+function wpinv_get_invoice_cart($invoice_id = 0) {
519
+    return wpinv_get_invoice($invoice_id, true);
520 520
 }
521 521
 
522
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
523
-    $invoice = new WPInv_Invoice( $invoice_id );
522
+function wpinv_get_invoice_description($invoice_id = 0) {
523
+    $invoice = new WPInv_Invoice($invoice_id);
524 524
     return $invoice->get_description();
525 525
 }
526 526
 
527
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
528
-    $invoice = new WPInv_Invoice( $invoice_id );
527
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
528
+    $invoice = new WPInv_Invoice($invoice_id);
529 529
     return $invoice->get_currency();
530 530
 }
531 531
 
532
-function wpinv_get_payment_user_email( $invoice_id ) {
533
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+function wpinv_get_payment_user_email($invoice_id) {
533
+    $invoice = new WPInv_Invoice($invoice_id);
534 534
     return $invoice->get_email();
535 535
 }
536 536
 
537
-function wpinv_get_user_id( $invoice_id ) {
538
-    $invoice = new WPInv_Invoice( $invoice_id );
537
+function wpinv_get_user_id($invoice_id) {
538
+    $invoice = new WPInv_Invoice($invoice_id);
539 539
     return $invoice->get_user_id();
540 540
 }
541 541
 
542
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
543
-    $invoice = new WPInv_Invoice( $invoice_id );
542
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
543
+    $invoice = new WPInv_Invoice($invoice_id);
544 544
     
545
-    return $invoice->get_status( $return_label );
545
+    return $invoice->get_status($return_label);
546 546
 }
547 547
 
548
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
549
-    $invoice = new WPInv_Invoice( $invoice_id );
548
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
549
+    $invoice = new WPInv_Invoice($invoice_id);
550 550
     
551
-    return $invoice->get_gateway( $return_label );
551
+    return $invoice->get_gateway($return_label);
552 552
 }
553 553
 
554
-function wpinv_get_payment_gateway_name( $invoice_id ) {
555
-    $invoice = new WPInv_Invoice( $invoice_id );
554
+function wpinv_get_payment_gateway_name($invoice_id) {
555
+    $invoice = new WPInv_Invoice($invoice_id);
556 556
     
557 557
     return $invoice->get_gateway_title();
558 558
 }
559 559
 
560
-function wpinv_get_payment_transaction_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_payment_transaction_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     
563 563
     return $invoice->get_transaction_id();
564 564
 }
565 565
 
566
-function wpinv_get_id_by_transaction_id( $key ) {
566
+function wpinv_get_id_by_transaction_id($key) {
567 567
     global $wpdb;
568 568
 
569
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
569
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
570 570
 
571
-    if ( $invoice_id != NULL )
571
+    if ($invoice_id != NULL)
572 572
         return $invoice_id;
573 573
 
574 574
     return 0;
575 575
 }
576 576
 
577
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
 
580
-    return $invoice->get_meta( $meta_key, $single );
580
+    return $invoice->get_meta($meta_key, $single);
581 581
 }
582 582
 
583
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
586
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
587 587
 }
588 588
 
589
-function wpinv_get_items( $invoice_id = 0 ) {
590
-    $invoice            = wpinv_get_invoice( $invoice_id );
589
+function wpinv_get_items($invoice_id = 0) {
590
+    $invoice            = wpinv_get_invoice($invoice_id);
591 591
     
592 592
     $items              = $invoice->get_items();
593 593
     $invoice_currency   = $invoice->get_currency();
594 594
 
595
-    if ( !empty( $items ) && is_array( $items ) ) {
596
-        foreach ( $items as $key => $item ) {
595
+    if (!empty($items) && is_array($items)) {
596
+        foreach ($items as $key => $item) {
597 597
             $items[$key]['currency'] = $invoice_currency;
598 598
 
599
-            if ( !isset( $item['subtotal'] ) ) {
599
+            if (!isset($item['subtotal'])) {
600 600
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
601 601
             }
602 602
         }
603 603
     }
604 604
 
605
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
605
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
606 606
 }
607 607
 
608
-function wpinv_get_fees( $invoice_id = 0 ) {
609
-    $invoice           = wpinv_get_invoice( $invoice_id );
608
+function wpinv_get_fees($invoice_id = 0) {
609
+    $invoice           = wpinv_get_invoice($invoice_id);
610 610
     $fees              = $invoice->get_fees();
611 611
 
612
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
612
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
613 613
 }
614 614
 
615
-function wpinv_get_invoice_ip( $invoice_id ) {
616
-    $invoice = new WPInv_Invoice( $invoice_id );
615
+function wpinv_get_invoice_ip($invoice_id) {
616
+    $invoice = new WPInv_Invoice($invoice_id);
617 617
     return $invoice->get_ip();
618 618
 }
619 619
 
620
-function wpinv_get_invoice_user_info( $invoice_id ) {
621
-    $invoice = new WPInv_Invoice( $invoice_id );
620
+function wpinv_get_invoice_user_info($invoice_id) {
621
+    $invoice = new WPInv_Invoice($invoice_id);
622 622
     return $invoice->get_user_info();
623 623
 }
624 624
 
625
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
626
-    $invoice = new WPInv_Invoice( $invoice_id );
625
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
626
+    $invoice = new WPInv_Invoice($invoice_id);
627 627
 
628
-    return $invoice->get_subtotal( $currency );
628
+    return $invoice->get_subtotal($currency);
629 629
 }
630 630
 
631
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
632
-    $invoice = new WPInv_Invoice( $invoice_id );
631
+function wpinv_tax($invoice_id = 0, $currency = false) {
632
+    $invoice = new WPInv_Invoice($invoice_id);
633 633
 
634
-    return $invoice->get_tax( $currency );
634
+    return $invoice->get_tax($currency);
635 635
 }
636 636
 
637
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
638
-    $invoice = wpinv_get_invoice( $invoice_id );
637
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
638
+    $invoice = wpinv_get_invoice($invoice_id);
639 639
 
640
-    return $invoice->get_discount( $currency, $dash );
640
+    return $invoice->get_discount($currency, $dash);
641 641
 }
642 642
 
643
-function wpinv_discount_code( $invoice_id = 0 ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_discount_code($invoice_id = 0) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
 
646 646
     return $invoice->get_discount_code();
647 647
 }
648 648
 
649
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
650
-    $invoice = new WPInv_Invoice( $invoice_id );
649
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
650
+    $invoice = new WPInv_Invoice($invoice_id);
651 651
 
652
-    return $invoice->get_total( $currency );
652
+    return $invoice->get_total($currency);
653 653
 }
654 654
 
655
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
656
-    $invoice = new WPInv_Invoice( $invoice_id );
655
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
656
+    $invoice = new WPInv_Invoice($invoice_id);
657 657
 
658
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
658
+    $format         = !empty($format) ? $format : get_option('date_format');
659 659
     $date_created   = $invoice->get_created_date();
660
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
660
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
661 661
 
662 662
     return $date_created;
663 663
 }
664 664
 
665
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
666
-    $invoice = new WPInv_Invoice( $invoice_id );
665
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
666
+    $invoice = new WPInv_Invoice($invoice_id);
667 667
     
668
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
668
+    $format         = !empty($format) ? $format : get_option('date_format');
669 669
     $date_completed = $invoice->get_completed_date();
670
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
671
-    if ( $invoice_date == '' && $default ) {
672
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
670
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
671
+    if ($invoice_date == '' && $default) {
672
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
673 673
     }
674 674
 
675 675
     return $invoice_date;
676 676
 }
677 677
 
678
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
     
681 681
     return $invoice->vat_number;
682 682
 }
683 683
 
684
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
685
-    $invoice = new WPInv_Invoice( $invoice_id );
684
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
685
+    $invoice = new WPInv_Invoice($invoice_id);
686 686
 
687
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
687
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
688 688
 }
689 689
 
690
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
690
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
691 691
     global $invoicing;
692 692
     
693
-    if ( empty( $invoice_id ) ) {
693
+    if (empty($invoice_id)) {
694 694
         return NULL;
695 695
     }
696 696
     
697
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
697
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
698 698
     
699
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
699
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
700 700
 }
701 701
 
702
-function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
702
+function wpinv_get_payment_key($invoice_id = 0) {
703
+	$invoice = new WPInv_Invoice($invoice_id);
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
707
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_get_invoice_number($invoice_id = 0) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
     return $invoice->get_number();
710 710
 }
711 711
 
712
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
712
+function wpinv_get_cart_discountable_subtotal($code_id) {
713 713
     $cart_items = wpinv_get_cart_content_details();
714 714
     $items      = array();
715 715
 
716
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
716
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
717 717
 
718
-    if( $cart_items ) {
718
+    if ($cart_items) {
719 719
 
720
-        foreach( $cart_items as $item ) {
720
+        foreach ($cart_items as $item) {
721 721
 
722
-            if( ! in_array( $item['id'], $excluded_items ) ) {
723
-                $items[] =  $item;
722
+            if (!in_array($item['id'], $excluded_items)) {
723
+                $items[] = $item;
724 724
             }
725 725
         }
726 726
     }
727 727
 
728
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
728
+    $subtotal = wpinv_get_cart_items_subtotal($items);
729 729
 
730
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
730
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
731 731
 }
732 732
 
733
-function wpinv_get_cart_items_subtotal( $items ) {
733
+function wpinv_get_cart_items_subtotal($items) {
734 734
     $subtotal = 0.00;
735 735
 
736
-    if ( is_array( $items ) && ! empty( $items ) ) {
737
-        $prices = wp_list_pluck( $items, 'subtotal' );
736
+    if (is_array($items) && !empty($items)) {
737
+        $prices = wp_list_pluck($items, 'subtotal');
738 738
 
739
-        if( is_array( $prices ) ) {
740
-            $subtotal = array_sum( $prices );
739
+        if (is_array($prices)) {
740
+            $subtotal = array_sum($prices);
741 741
         } else {
742 742
             $subtotal = 0.00;
743 743
         }
744 744
 
745
-        if( $subtotal < 0 ) {
745
+        if ($subtotal < 0) {
746 746
             $subtotal = 0.00;
747 747
         }
748 748
     }
749 749
 
750
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
750
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
751 751
 }
752 752
 
753
-function wpinv_get_cart_subtotal( $items = array() ) {
754
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
755
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
753
+function wpinv_get_cart_subtotal($items = array()) {
754
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
755
+    $subtotal = wpinv_get_cart_items_subtotal($items);
756 756
 
757
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
757
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
758 758
 }
759 759
 
760
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
760
+function wpinv_cart_subtotal($items = array(), $currency = '') {
761 761
 
762
-    if( empty( $currency ) ) {
762
+    if (empty($currency)) {
763 763
         $currency = wpinv_get_currency();
764 764
     }
765 765
 
766
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
766
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
767 767
 
768 768
     return $price;
769 769
 }
770 770
 
771
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
772
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
773
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
774
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
775
-    $fees      = (float)wpinv_get_cart_fee_total();
776
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
771
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
772
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
773
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
774
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
775
+    $fees      = (float) wpinv_get_cart_fee_total();
776
+    if (!empty($invoice) && $invoice->is_free_trial()) {
777 777
         $total = 0;
778 778
     } else {
779
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
779
+        $total = $subtotal - $discounts + $cart_tax + $fees;
780 780
     }
781 781
 
782
-    if ( $total < 0 ) {
782
+    if ($total < 0) {
783 783
         $total = 0.00;
784 784
     }
785 785
     
786
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
786
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
787 787
 
788
-    return wpinv_sanitize_amount( $total );
788
+    return wpinv_sanitize_amount($total);
789 789
 }
790 790
 
791
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
791
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
792 792
     global $cart_total;
793
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
794
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
793
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
794
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
795 795
     
796 796
     $cart_total = $total;
797 797
 
798
-    if ( !$echo ) {
798
+    if (!$echo) {
799 799
         return $total;
800 800
     }
801 801
 
802 802
     echo $total;
803 803
 }
804 804
 
805
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
805
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
806 806
 
807
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
807
+    if (!empty($invoice) && !$invoice->is_taxable()) {
808 808
         return 0;
809 809
     }
810 810
 
811 811
     $cart_tax = 0;
812
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
812
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
813 813
 
814
-    if ( $items ) {
815
-        $taxes = wp_list_pluck( $items, 'tax' );
814
+    if ($items) {
815
+        $taxes = wp_list_pluck($items, 'tax');
816 816
 
817
-        if( is_array( $taxes ) ) {
818
-            $cart_tax = array_sum( $taxes );
817
+        if (is_array($taxes)) {
818
+            $cart_tax = array_sum($taxes);
819 819
         }
820 820
     }
821 821
 
822 822
     $cart_tax += wpinv_get_cart_fee_tax();
823 823
 
824
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
824
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
825 825
 }
826 826
 
827
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
827
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
828 828
 
829
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
830
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
829
+    if (!empty($invoice && !$invoice->is_taxable())) {
830
+        echo wpinv_price(wpinv_format_amount(0), $currency);
831 831
         return;
832 832
     }
833 833
 
834
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
835
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
834
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
835
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
836 836
 
837
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
837
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
838 838
 
839
-    if ( !$echo ) {
839
+    if (!$echo) {
840 840
         return $tax;
841 841
     }
842 842
 
843 843
     echo $tax;
844 844
 }
845 845
 
846
-function wpinv_get_cart_discount_code( $items = array() ) {
846
+function wpinv_get_cart_discount_code($items = array()) {
847 847
     $invoice = wpinv_get_invoice_cart();
848
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
848
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
849 849
     
850
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
850
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
851 851
 }
852 852
 
853
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
854
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
853
+function wpinv_cart_discount_code($items = array(), $echo = false) {
854
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
855 855
 
856
-    if ( $cart_discount_code != '' ) {
856
+    if ($cart_discount_code != '') {
857 857
         $cart_discount_code = ' (' . $cart_discount_code . ')';
858 858
     }
859 859
     
860
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
860
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $discount_code;
864 864
     }
865 865
 
866 866
     echo $discount_code;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount( $items = array() ) {
869
+function wpinv_get_cart_discount($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
871
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
873
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
874 874
 }
875 875
 
876
-function wpinv_cart_discount( $items = array(), $echo = false ) {
877
-    $cart_discount = wpinv_get_cart_discount( $items );
878
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
876
+function wpinv_cart_discount($items = array(), $echo = false) {
877
+    $cart_discount = wpinv_get_cart_discount($items);
878
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
879 879
 
880
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
880
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
881 881
 
882
-    if ( !$echo ) {
882
+    if (!$echo) {
883 883
         return $discount;
884 884
     }
885 885
 
886 886
     echo $discount;
887 887
 }
888 888
 
889
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
890
-    $item = new WPInv_Item( $item_id );
889
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
890
+    $item = new WPInv_Item($item_id);
891 891
     
892
-    return $item->get_fees( $type, $item_id );
892
+    return $item->get_fees($type, $item_id);
893 893
 }
894 894
 
895 895
 function wpinv_get_cart_fee_total() {
896
-    $total  = 0;
896
+    $total = 0;
897 897
     $fees = wpinv_get_cart_fees();
898 898
     
899
-    if ( $fees ) {
900
-        foreach ( $fees as $fee_id => $fee ) {
899
+    if ($fees) {
900
+        foreach ($fees as $fee_id => $fee) {
901 901
             $total += $fee['amount'];
902 902
         }
903 903
     }
904 904
 
905
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
905
+    return apply_filters('wpinv_get_cart_fee_total', $total);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_fee_tax() {
909 909
     $tax  = 0;
910 910
     $fees = wpinv_get_cart_fees();
911 911
 
912
-    if ( $fees ) {
913
-        foreach ( $fees as $fee_id => $fee ) {
914
-            if( ! empty( $fee['no_tax'] ) ) {
912
+    if ($fees) {
913
+        foreach ($fees as $fee_id => $fee) {
914
+            if (!empty($fee['no_tax'])) {
915 915
                 continue;
916 916
             }
917 917
 
918
-            $tax += wpinv_calculate_tax( $fee['amount'] );
918
+            $tax += wpinv_calculate_tax($fee['amount']);
919 919
         }
920 920
     }
921 921
 
922
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
922
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
923 923
 }
924 924
 
925 925
 function wpinv_cart_has_recurring_item() {
926 926
     $cart_items = wpinv_get_cart_contents();
927 927
     
928
-    if ( empty( $cart_items ) ) {
928
+    if (empty($cart_items)) {
929 929
         return false;
930 930
     }
931 931
     
932 932
     $has_subscription = false;
933
-    foreach( $cart_items as $cart_item ) {
934
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
933
+    foreach ($cart_items as $cart_item) {
934
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
935 935
             $has_subscription = true;
936 936
             break;
937 937
         }
938 938
     }
939 939
     
940
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
940
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
941 941
 }
942 942
 
943 943
 function wpinv_cart_has_free_trial() {
@@ -945,100 +945,100 @@  discard block
 block discarded – undo
945 945
     
946 946
     $free_trial = false;
947 947
     
948
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
948
+    if (!empty($invoice) && $invoice->is_free_trial()) {
949 949
         $free_trial = true;
950 950
     }
951 951
     
952
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
952
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
953 953
 }
954 954
 
955 955
 function wpinv_get_cart_contents() {
956 956
     $cart_details = wpinv_get_cart_details();
957 957
     
958
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
958
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
959 959
 }
960 960
 
961 961
 function wpinv_get_cart_content_details() {
962 962
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
963 963
     $cart_items = wpinv_get_cart_contents();
964 964
     
965
-    if ( empty( $cart_items ) ) {
965
+    if (empty($cart_items)) {
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+	if (empty($invoice)) {
970 970
         return false;
971 971
     }
972 972
 
973 973
     $details = array();
974
-    $length  = count( $cart_items ) - 1;
974
+    $length  = count($cart_items) - 1;
975 975
     
976
-    if ( empty( $_POST['country'] ) ) {
976
+    if (empty($_POST['country'])) {
977 977
         $_POST['country'] = $invoice->country;
978 978
     }
979
-    if ( !isset( $_POST['state'] ) ) {
979
+    if (!isset($_POST['state'])) {
980 980
         $_POST['state'] = $invoice->state;
981 981
     }
982 982
 
983
-    foreach( $cart_items as $key => $item ) {
984
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
985
-        if ( empty( $item_id ) ) {
983
+    foreach ($cart_items as $key => $item) {
984
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
985
+        if (empty($item_id)) {
986 986
             continue;
987 987
         }
988 988
         
989 989
         $wpi_current_id         = $invoice->ID;
990 990
         $wpi_item_id            = $item_id;
991 991
         
992
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
992
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
993 993
             $item_price = $item['custom_price'];
994 994
         } else {
995
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
995
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
996 996
                 $item_price = $item['item_price'];
997 997
             } else {
998
-                $item_price = wpinv_get_item_price( $item_id );
998
+                $item_price = wpinv_get_item_price($item_id);
999 999
             }
1000 1000
         }
1001
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1002
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1003
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1004
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1001
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1002
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1003
+        $quantity           = wpinv_get_cart_item_quantity($item);
1004
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1005 1005
         
1006 1006
         $subtotal           = $item_price * $quantity;
1007
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1008
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1009
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1007
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1008
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1009
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1010 1010
         
1011
-        if ( ! $invoice->is_taxable() ) {
1011
+        if (!$invoice->is_taxable()) {
1012 1012
             $tax = 0;
1013 1013
         }
1014
-        if ( wpinv_prices_include_tax() ) {
1015
-            $subtotal -= wpinv_round_amount( $tax );
1014
+        if (wpinv_prices_include_tax()) {
1015
+            $subtotal -= wpinv_round_amount($tax);
1016 1016
         }
1017 1017
         
1018
-        $total              = $subtotal - $discount + $tax;
1018
+        $total = $subtotal - $discount + $tax;
1019 1019
         
1020 1020
         // Do not allow totals to go negatve
1021
-        if( $total < 0 ) {
1021
+        if ($total < 0) {
1022 1022
             $total = 0;
1023 1023
         }
1024 1024
         
1025
-        $details[ $key ]  = array(
1025
+        $details[$key] = array(
1026 1026
             'id'                => $item_id,
1027
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1028
-            'item_price'        => wpinv_round_amount( $item_price ),
1029
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1027
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1028
+            'item_price'        => wpinv_round_amount($item_price),
1029
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1030 1030
             'quantity'          => $quantity,
1031
-            'discount'          => wpinv_round_amount( $discount ),
1032
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1033
-            'tax'               => wpinv_round_amount( $tax ),
1034
-            'price'             => wpinv_round_amount( $total ),
1031
+            'discount'          => wpinv_round_amount($discount),
1032
+            'subtotal'          => wpinv_round_amount($subtotal),
1033
+            'tax'               => wpinv_round_amount($tax),
1034
+            'price'             => wpinv_round_amount($total),
1035 1035
             'vat_rates_class'   => $tax_class,
1036 1036
             'vat_rate'          => $tax_rate,
1037
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1037
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1038 1038
             'fees'              => $fees,
1039 1039
         );
1040 1040
         
1041
-        if ( $wpinv_is_last_cart_item ) {
1041
+        if ($wpinv_is_last_cart_item) {
1042 1042
             $wpinv_is_last_cart_item   = false;
1043 1043
             $wpinv_flat_discount_total = 0.00;
1044 1044
         }
@@ -1047,67 +1047,67 @@  discard block
 block discarded – undo
1047 1047
     return $details;
1048 1048
 }
1049 1049
 
1050
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1050
+function wpinv_get_cart_details($invoice_id = 0) {
1051 1051
     global $ajax_cart_details;
1052 1052
 
1053
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1053
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1054 1054
     $cart_details = $ajax_cart_details;
1055
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1055
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1056 1056
         $cart_details = $invoice->cart_details;
1057 1057
     }
1058 1058
 
1059
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1060
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1059
+    if (!empty($cart_details) && is_array($cart_details)) {
1060
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1061 1061
 
1062
-        foreach ( $cart_details as $key => $cart_item ) {
1063
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1062
+        foreach ($cart_details as $key => $cart_item) {
1063
+            $cart_details[$key]['currency'] = $invoice_currency;
1064 1064
 
1065
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1066
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1065
+            if (!isset($cart_item['subtotal'])) {
1066
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1067 1067
             }
1068 1068
         }
1069 1069
     }
1070 1070
 
1071
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1071
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1072 1072
 }
1073 1073
 
1074
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1075
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1074
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1075
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1076 1076
         return;
1077 1077
     }
1078 1078
 
1079
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1079
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1080 1080
         return;
1081 1081
     }
1082 1082
 
1083
-    $invoice    = wpinv_get_invoice( $invoice_id );
1083
+    $invoice    = wpinv_get_invoice($invoice_id);
1084 1084
     
1085
-    $old_status = wpinv_status_nicename( $old_status );
1086
-    $new_status = wpinv_status_nicename( $new_status );
1085
+    $old_status = wpinv_status_nicename($old_status);
1086
+    $new_status = wpinv_status_nicename($new_status);
1087 1087
 
1088
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1088
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1089 1089
     
1090 1090
     // Add note
1091
-    return $invoice->add_note( $status_change, false, false, true );
1091
+    return $invoice->add_note($status_change, false, false, true);
1092 1092
 }
1093
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1093
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1094 1094
 
1095
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1095
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1096 1096
     global $wpi_has_free_trial;
1097 1097
     
1098 1098
     $wpi_has_free_trial = false;
1099 1099
     
1100
-    if ( $old_status == 'publish' ) {
1100
+    if ($old_status == 'publish') {
1101 1101
         return; // Make sure that payments are only paid once
1102 1102
     }
1103 1103
 
1104 1104
     // Make sure the payment completion is only processed when new status is paid
1105
-    if ( $new_status != 'publish' ) {
1105
+    if ($new_status != 'publish') {
1106 1106
         return;
1107 1107
     }
1108 1108
 
1109
-    $invoice = new WPInv_Invoice( $invoice_id );
1110
-    if ( empty( $invoice ) ) {
1109
+    $invoice = new WPInv_Invoice($invoice_id);
1110
+    if (empty($invoice)) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
@@ -1115,58 +1115,58 @@  discard block
 block discarded – undo
1115 1115
     $completed_date = $invoice->completed_date;
1116 1116
     $cart_details   = $invoice->cart_details;
1117 1117
 
1118
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1118
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1119 1119
 
1120
-    if ( is_array( $cart_details ) ) {
1120
+    if (is_array($cart_details)) {
1121 1121
         // Increase purchase count and earnings
1122
-        foreach ( $cart_details as $cart_index => $item ) {
1122
+        foreach ($cart_details as $cart_index => $item) {
1123 1123
             // Ensure these actions only run once, ever
1124
-            if ( empty( $completed_date ) ) {
1125
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1124
+            if (empty($completed_date)) {
1125
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1126 1126
             }
1127 1127
         }
1128 1128
     }
1129 1129
     
1130 1130
     // Check for discount codes and increment their use counts
1131
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1132
-        if( ! empty( $discounts ) ) {
1133
-            foreach( $discounts as $code ) {
1134
-                wpinv_increase_discount_usage( $code );
1131
+    if ($discounts = $invoice->get_discounts(true)) {
1132
+        if (!empty($discounts)) {
1133
+            foreach ($discounts as $code) {
1134
+                wpinv_increase_discount_usage($code);
1135 1135
             }
1136 1136
         }
1137 1137
     }
1138 1138
     
1139 1139
     // Ensure this action only runs once ever
1140
-    if( empty( $completed_date ) ) {
1140
+    if (empty($completed_date)) {
1141 1141
         // Save the completed date
1142
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1142
+        $invoice->set('completed_date', current_time('mysql', 0));
1143 1143
         $invoice->save();
1144 1144
 
1145
-        do_action( 'wpinv_complete_payment', $invoice_id );
1145
+        do_action('wpinv_complete_payment', $invoice_id);
1146 1146
     }
1147 1147
 
1148 1148
     // Empty the shopping cart
1149 1149
     wpinv_empty_cart();
1150 1150
 }
1151
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1151
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1152 1152
 
1153
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1154
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1153
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1154
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1155 1155
     
1156
-    if ( empty( $invoice ) ) {
1156
+    if (empty($invoice)) {
1157 1157
         return false;
1158 1158
     }
1159 1159
     
1160
-    return $invoice->update_status( $new_status );
1160
+    return $invoice->update_status($new_status);
1161 1161
 }
1162 1162
 
1163
-function wpinv_cart_has_fees( $type = 'all' ) {
1163
+function wpinv_cart_has_fees($type = 'all') {
1164 1164
     return false;
1165 1165
 }
1166 1166
 
1167 1167
 function wpinv_validate_checkout_fields() {    
1168 1168
     // Check if there is $_POST
1169
-    if ( empty( $_POST ) ) {
1169
+    if (empty($_POST)) {
1170 1170
         return false;
1171 1171
     }
1172 1172
     
@@ -1178,11 +1178,11 @@  discard block
 block discarded – undo
1178 1178
     );
1179 1179
     
1180 1180
     // Validate agree to terms
1181
-    $page = wpinv_get_option( 'tandc_page' );
1182
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1181
+    $page = wpinv_get_option('tandc_page');
1182
+    if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1183 1183
         // Validate agree to terms
1184
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1185
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1184
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1185
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1186 1186
         }
1187 1187
     }
1188 1188
     
@@ -1198,28 +1198,28 @@  discard block
 block discarded – undo
1198 1198
     
1199 1199
     $invoice = wpinv_get_invoice_cart();
1200 1200
     $has_subscription = $invoice->is_recurring();
1201
-    if ( empty( $invoice ) ) {
1202
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1201
+    if (empty($invoice)) {
1202
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1203 1203
         return $gateway;
1204 1204
     }
1205 1205
 
1206 1206
     // Check if a gateway value is present
1207
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1208
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1207
+    if (!empty($_REQUEST['wpi-gateway'])) {
1208
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1209 1209
 
1210
-        if ( $invoice->is_free() ) {
1210
+        if ($invoice->is_free()) {
1211 1211
             $gateway = 'manual';
1212
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1213
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1214
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1215
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1216
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1212
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1213
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1214
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1215
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1216
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1217 1217
             }
1218 1218
         }
1219 1219
     }
1220 1220
 
1221
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1222
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1221
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1222
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1223 1223
     }
1224 1224
 
1225 1225
     return $gateway;
@@ -1233,10 +1233,10 @@  discard block
 block discarded – undo
1233 1233
     
1234 1234
     $error = false;
1235 1235
     // If we have discounts, loop through them
1236
-    if ( ! empty( $discounts ) ) {
1237
-        foreach ( $discounts as $discount ) {
1236
+    if (!empty($discounts)) {
1237
+        foreach ($discounts as $discount) {
1238 1238
             // Check if valid
1239
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1239
+            if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1240 1240
                 // Discount is not valid
1241 1241
                 $error = true;
1242 1242
             }
@@ -1246,20 +1246,20 @@  discard block
 block discarded – undo
1246 1246
         return NULL;
1247 1247
     }
1248 1248
 
1249
-    if ( $error && !wpinv_get_errors() ) {
1250
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1249
+    if ($error && !wpinv_get_errors()) {
1250
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1251 1251
     }
1252 1252
 
1253
-    return implode( ',', $discounts );
1253
+    return implode(',', $discounts);
1254 1254
 }
1255 1255
 
1256 1256
 function wpinv_checkout_validate_cc() {
1257 1257
     $card_data = wpinv_checkout_get_cc_info();
1258 1258
 
1259 1259
     // Validate the card zip
1260
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1261
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1262
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1260
+    if (!empty($card_data['wpinv_zip'])) {
1261
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1262
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1263 1263
         }
1264 1264
     }
1265 1265
 
@@ -1269,28 +1269,28 @@  discard block
 block discarded – undo
1269 1269
 
1270 1270
 function wpinv_checkout_get_cc_info() {
1271 1271
 	$cc_info = array();
1272
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1273
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1274
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1275
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1276
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1277
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1278
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1279
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1280
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1281
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1272
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1273
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1274
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1275
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1276
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1277
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1278
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1279
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1280
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1281
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1282 1282
 
1283 1283
 	// Return cc info
1284 1284
 	return $cc_info;
1285 1285
 }
1286 1286
 
1287
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1287
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1288 1288
     $ret = false;
1289 1289
 
1290
-    if ( empty( $zip ) || empty( $country_code ) )
1290
+    if (empty($zip) || empty($country_code))
1291 1291
         return $ret;
1292 1292
 
1293
-    $country_code = strtoupper( $country_code );
1293
+    $country_code = strtoupper($country_code);
1294 1294
 
1295 1295
     $zip_regex = array(
1296 1296
         "AD" => "AD\d{3}",
@@ -1450,72 +1450,72 @@  discard block
 block discarded – undo
1450 1450
         "ZM" => "\d{5}"
1451 1451
     );
1452 1452
 
1453
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1453
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1454 1454
         $ret = true;
1455 1455
 
1456
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1456
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1457 1457
 }
1458 1458
 
1459 1459
 function wpinv_checkout_validate_agree_to_terms() {
1460 1460
     // Validate agree to terms
1461
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1461
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1462 1462
         // User did not agree
1463
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1463
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1464 1464
     }
1465 1465
 }
1466 1466
 
1467 1467
 function wpinv_checkout_validate_invoice_user() {
1468 1468
     global $wpi_cart, $user_ID;
1469 1469
 
1470
-    if(empty($wpi_cart)){
1470
+    if (empty($wpi_cart)) {
1471 1471
         $wpi_cart = wpinv_get_invoice_cart();
1472 1472
     }
1473 1473
 
1474
-    $invoice_user = (int)$wpi_cart->get_user_id();
1474
+    $invoice_user = (int) $wpi_cart->get_user_id();
1475 1475
     $valid_user_data = array(
1476 1476
         'user_id' => $invoice_user
1477 1477
     );
1478 1478
 
1479 1479
     // If guest checkout allowed
1480
-    if ( !wpinv_require_login_to_checkout() ) {
1480
+    if (!wpinv_require_login_to_checkout()) {
1481 1481
         return $valid_user_data;
1482 1482
     }
1483 1483
     
1484 1484
     // Verify there is a user_ID
1485
-    if ( $user_ID == $invoice_user ) {
1485
+    if ($user_ID == $invoice_user) {
1486 1486
         // Get the logged in user data
1487
-        $user_data = get_userdata( $user_ID );
1488
-        $required_fields  = wpinv_checkout_required_fields();
1487
+        $user_data = get_userdata($user_ID);
1488
+        $required_fields = wpinv_checkout_required_fields();
1489 1489
 
1490 1490
         // Loop through required fields and show error messages
1491
-         if ( !empty( $required_fields ) ) {
1492
-            foreach ( $required_fields as $field_name => $value ) {
1493
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1494
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1491
+         if (!empty($required_fields)) {
1492
+            foreach ($required_fields as $field_name => $value) {
1493
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1494
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1495 1495
                 }
1496 1496
             }
1497 1497
         }
1498 1498
 
1499 1499
         // Verify data
1500
-        if ( $user_data ) {
1500
+        if ($user_data) {
1501 1501
             // Collected logged in user data
1502 1502
             $valid_user_data = array(
1503 1503
                 'user_id'     => $user_ID,
1504
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1505
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1506
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1504
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1505
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1506
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1507 1507
             );
1508 1508
 
1509
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1510
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1509
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1510
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1511 1511
             }
1512 1512
         } else {
1513 1513
             // Set invalid user error
1514
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1514
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1515 1515
         }
1516 1516
     } else {
1517 1517
         // Set invalid user error
1518
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1518
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1519 1519
     }
1520 1520
 
1521 1521
     // Return user data
@@ -1527,27 +1527,27 @@  discard block
 block discarded – undo
1527 1527
 
1528 1528
     $data = array();
1529 1529
     
1530
-    if ( is_user_logged_in() ) {
1531
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1532
-            $data['user_id'] = (int)get_current_user_id();
1530
+    if (is_user_logged_in()) {
1531
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1532
+            $data['user_id'] = (int) get_current_user_id();
1533 1533
         } else {
1534
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1534
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1535 1535
         }
1536 1536
     } else {
1537 1537
         // If guest checkout allowed
1538
-        if ( !wpinv_require_login_to_checkout() ) {
1538
+        if (!wpinv_require_login_to_checkout()) {
1539 1539
             $data['user_id'] = 0;
1540 1540
         } else {
1541
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1541
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1542 1542
         }
1543 1543
     }
1544 1544
 
1545 1545
     return $data;
1546 1546
 }
1547 1547
 
1548
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1548
+function wpinv_checkout_form_get_user($valid_data = array()) {
1549 1549
 
1550
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1550
+    if (!empty($valid_data['current_user']['user_id'])) {
1551 1551
         $user = $valid_data['current_user'];
1552 1552
     } else {
1553 1553
         // Set the valid invoice user
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
     }
1556 1556
 
1557 1557
     // Verify invoice have an user
1558
-    if ( false === $user || empty( $user ) ) {
1558
+    if (false === $user || empty($user)) {
1559 1559
         return false;
1560 1560
     }
1561 1561
 
@@ -1572,11 +1572,11 @@  discard block
 block discarded – undo
1572 1572
         'zip',
1573 1573
     );
1574 1574
     
1575
-    foreach ( $address_fields as $field ) {
1576
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1575
+    foreach ($address_fields as $field) {
1576
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1577 1577
         
1578
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1579
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1578
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1579
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1580 1580
         }
1581 1581
     }
1582 1582
 
@@ -1584,28 +1584,28 @@  discard block
 block discarded – undo
1584 1584
     return $user;
1585 1585
 }
1586 1586
 
1587
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1587
+function wpinv_set_checkout_session($invoice_data = array()) {
1588 1588
     global $wpi_session;
1589 1589
     
1590
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1590
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1591 1591
 }
1592 1592
 
1593 1593
 function wpinv_get_checkout_session() {
1594 1594
 	global $wpi_session;
1595 1595
 
1596
-    return $wpi_session->get( 'wpinv_checkout' );
1596
+    return $wpi_session->get('wpinv_checkout');
1597 1597
 }
1598 1598
 
1599 1599
 function wpinv_empty_cart() {
1600 1600
     global $wpi_session;
1601 1601
 
1602 1602
     // Remove cart contents
1603
-    $wpi_session->set( 'wpinv_checkout', NULL );
1603
+    $wpi_session->set('wpinv_checkout', NULL);
1604 1604
 
1605 1605
     // Remove all cart fees
1606
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1606
+    $wpi_session->set('wpi_cart_fees', NULL);
1607 1607
 
1608
-    do_action( 'wpinv_empty_cart' );
1608
+    do_action('wpinv_empty_cart');
1609 1609
 }
1610 1610
 
1611 1611
 function wpinv_process_checkout() {
@@ -1614,7 +1614,7 @@  discard block
 block discarded – undo
1614 1614
     wpinv_clear_errors();
1615 1615
 
1616 1616
     $invoice = wpinv_get_invoice_cart();
1617
-    if ( empty( $invoice ) ) {
1617
+    if (empty($invoice)) {
1618 1618
         return false;
1619 1619
     }
1620 1620
 
@@ -1622,42 +1622,42 @@  discard block
 block discarded – undo
1622 1622
 
1623 1623
     $wpi_checkout_id = $invoice->ID;
1624 1624
 
1625
-    do_action( 'wpinv_pre_process_checkout' );
1625
+    do_action('wpinv_pre_process_checkout');
1626 1626
     
1627
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1627
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1628 1628
         $valid_data = false;
1629
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1629
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1630 1630
     } else {
1631 1631
         // Validate the form $_POST data
1632 1632
         $valid_data = wpinv_validate_checkout_fields();
1633 1633
         
1634 1634
         // Allow themes and plugins to hook to errors
1635
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1635
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1636 1636
     }
1637 1637
     
1638
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1638
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1639 1639
     
1640 1640
     // Validate the user
1641
-    $user = wpinv_checkout_form_get_user( $valid_data );
1641
+    $user = wpinv_checkout_form_get_user($valid_data);
1642 1642
 
1643 1643
     // Let extensions validate fields after user is logged in if user has used login/registration form
1644
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1644
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1645 1645
     
1646
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1647
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1648
-            do_action( 'wpinv_ajax_checkout_errors' );
1646
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1647
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1648
+            do_action('wpinv_ajax_checkout_errors');
1649 1649
             die();
1650 1650
         } else {
1651 1651
             return false;
1652 1652
         }
1653 1653
     }
1654 1654
 
1655
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1655
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1656 1656
         // Save address fields.
1657
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1658
-        foreach ( $address_fields as $field ) {
1659
-            if ( isset( $user[$field] ) ) {
1660
-                $invoice->set( $field, $user[$field] );
1657
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1658
+        foreach ($address_fields as $field) {
1659
+            if (isset($user[$field])) {
1660
+                $invoice->set($field, $user[$field]);
1661 1661
             }
1662 1662
 
1663 1663
             $invoice->save();
@@ -1665,16 +1665,16 @@  discard block
 block discarded – undo
1665 1665
 
1666 1666
         $response['success']            = true;
1667 1667
         $response['data']['subtotal']   = $invoice->get_subtotal();
1668
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1668
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1669 1669
         $response['data']['discount']   = $invoice->get_discount();
1670
-        $response['data']['discountf']  = $invoice->get_discount( true );
1670
+        $response['data']['discountf']  = $invoice->get_discount(true);
1671 1671
         $response['data']['tax']        = $invoice->get_tax();
1672
-        $response['data']['taxf']       = $invoice->get_tax( true );
1672
+        $response['data']['taxf']       = $invoice->get_tax(true);
1673 1673
         $response['data']['total']      = $invoice->get_total();
1674
-        $response['data']['totalf']     = $invoice->get_total( true );
1675
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1674
+        $response['data']['totalf']     = $invoice->get_total(true);
1675
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1676 1676
 
1677
-        wp_send_json( $response );
1677
+        wp_send_json($response);
1678 1678
     }
1679 1679
     
1680 1680
     $user_info = array(
@@ -1696,42 +1696,42 @@  discard block
 block discarded – undo
1696 1696
     
1697 1697
     // Setup invoice information
1698 1698
     $invoice_data = array(
1699
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1699
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1700 1700
         'items'             => $cart_items,
1701 1701
         'cart_discounts'    => $discounts,
1702
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1703
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1704
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1705
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1706
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1702
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1703
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1704
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1705
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1706
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1707 1707
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1708 1708
         'user_email'        => $invoice->get_email(),
1709
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1710
-        'user_info'         => stripslashes_deep( $user_info ),
1709
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1710
+        'user_info'         => stripslashes_deep($user_info),
1711 1711
         'post_data'         => $_POST,
1712 1712
         'cart_details'      => $cart_items,
1713 1713
         'gateway'           => $valid_data['gateway'],
1714 1714
         'card_info'         => $valid_data['cc_info']
1715 1715
     );
1716 1716
     
1717
-    $vat_info   = $wpinv_euvat->current_vat_data();
1718
-    if ( is_array( $vat_info ) ) {
1717
+    $vat_info = $wpinv_euvat->current_vat_data();
1718
+    if (is_array($vat_info)) {
1719 1719
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1720 1720
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1721
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1721
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1722 1722
 
1723 1723
         // Add the VAT rate to each item in the cart
1724
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1724
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1725 1725
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1726
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1726
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1727 1727
         }
1728 1728
     }
1729 1729
     
1730 1730
     // Save vat fields.
1731
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1732
-    foreach ( $address_fields as $field ) {
1733
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1734
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1731
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1732
+    foreach ($address_fields as $field) {
1733
+        if (isset($invoice_data['user_info'][$field])) {
1734
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1735 1735
         }
1736 1736
 
1737 1737
         $invoice->save();
@@ -1741,55 +1741,55 @@  discard block
 block discarded – undo
1741 1741
     $valid_data['user'] = $user;
1742 1742
     
1743 1743
     // Allow themes and plugins to hook before the gateway
1744
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1744
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1745 1745
     
1746 1746
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1747
-    if ( !$invoice_data['price'] ) {
1747
+    if (!$invoice_data['price']) {
1748 1748
         // Revert to manual
1749 1749
         $invoice_data['gateway'] = 'manual';
1750 1750
         $_POST['wpi-gateway'] = 'manual';
1751 1751
     }
1752 1752
     
1753 1753
     // Allow the invoice data to be modified before it is sent to the gateway
1754
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1754
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1755 1755
     
1756
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1756
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1757 1757
         $mode = 'test';
1758 1758
     } else {
1759
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1759
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1760 1760
     }
1761 1761
     
1762 1762
     // Setup the data we're storing in the purchase session
1763 1763
     $session_data = $invoice_data;
1764 1764
     // Make sure credit card numbers are never stored in sessions
1765
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1766
-        unset( $session_data['card_info']['card_number'] );
1765
+    if (!empty($session_data['card_info']['card_number'])) {
1766
+        unset($session_data['card_info']['card_number']);
1767 1767
     }
1768 1768
     
1769 1769
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1770
-    wpinv_set_checkout_session( $invoice_data );
1770
+    wpinv_set_checkout_session($invoice_data);
1771 1771
     
1772 1772
     // Set gateway
1773
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1774
-    $invoice->update_meta( '_wpinv_mode', $mode );
1775
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1773
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1774
+    $invoice->update_meta('_wpinv_mode', $mode);
1775
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1776 1776
     
1777
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1777
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1778 1778
 
1779 1779
     // Send info to the gateway for payment processing
1780
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1780
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1781 1781
     die();
1782 1782
 }
1783
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1783
+add_action('wpinv_payment', 'wpinv_process_checkout');
1784 1784
 
1785
-function wpinv_get_invoices( $args ) {
1786
-    $args = wp_parse_args( $args, array(
1787
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1785
+function wpinv_get_invoices($args) {
1786
+    $args = wp_parse_args($args, array(
1787
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1788 1788
         'type'     => 'wpi_invoice',
1789 1789
         'parent'   => null,
1790 1790
         'user'     => null,
1791 1791
         'email'    => '',
1792
-        'limit'    => get_option( 'posts_per_page' ),
1792
+        'limit'    => get_option('posts_per_page'),
1793 1793
         'offset'   => null,
1794 1794
         'page'     => 1,
1795 1795
         'exclude'  => array(),
@@ -1797,7 +1797,7 @@  discard block
 block discarded – undo
1797 1797
         'order'    => 'DESC',
1798 1798
         'return'   => 'objects',
1799 1799
         'paginate' => false,
1800
-    ) );
1800
+    ));
1801 1801
     
1802 1802
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1803 1803
     $map_legacy = array(
@@ -1810,18 +1810,18 @@  discard block
 block discarded – undo
1810 1810
         'paged'          => 'page',
1811 1811
     );
1812 1812
 
1813
-    foreach ( $map_legacy as $from => $to ) {
1814
-        if ( isset( $args[ $from ] ) ) {
1815
-            $args[ $to ] = $args[ $from ];
1813
+    foreach ($map_legacy as $from => $to) {
1814
+        if (isset($args[$from])) {
1815
+            $args[$to] = $args[$from];
1816 1816
         }
1817 1817
     }
1818 1818
 
1819
-    if ( get_query_var( 'paged' ) )
1819
+    if (get_query_var('paged'))
1820 1820
         $args['page'] = get_query_var('paged');
1821
-    else if ( get_query_var( 'page' ) )
1822
-        $args['page'] = get_query_var( 'page' );
1823
-    else if ( !empty( $args[ 'page' ] ) )
1824
-        $args['page'] = $args[ 'page' ];
1821
+    else if (get_query_var('page'))
1822
+        $args['page'] = get_query_var('page');
1823
+    else if (!empty($args['page']))
1824
+        $args['page'] = $args['page'];
1825 1825
     else
1826 1826
         $args['page'] = 1;
1827 1827
 
@@ -1834,48 +1834,48 @@  discard block
 block discarded – undo
1834 1834
         'post_status'    => $args['status'],
1835 1835
         'posts_per_page' => $args['limit'],
1836 1836
         'meta_query'     => array(),
1837
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1837
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1838 1838
         'fields'         => 'ids',
1839 1839
         'orderby'        => $args['orderby'],
1840 1840
         'order'          => $args['order'],
1841 1841
     );
1842 1842
     
1843
-    if ( !empty( $args['user'] ) ) {
1844
-        $wp_query_args['author'] = absint( $args['user'] );
1843
+    if (!empty($args['user'])) {
1844
+        $wp_query_args['author'] = absint($args['user']);
1845 1845
     }
1846 1846
 
1847
-    if ( ! is_null( $args['parent'] ) ) {
1848
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1847
+    if (!is_null($args['parent'])) {
1848
+        $wp_query_args['post_parent'] = absint($args['parent']);
1849 1849
     }
1850 1850
 
1851
-    if ( ! is_null( $args['offset'] ) ) {
1852
-        $wp_query_args['offset'] = absint( $args['offset'] );
1851
+    if (!is_null($args['offset'])) {
1852
+        $wp_query_args['offset'] = absint($args['offset']);
1853 1853
     } else {
1854
-        $wp_query_args['paged'] = absint( $args['page'] );
1854
+        $wp_query_args['paged'] = absint($args['page']);
1855 1855
     }
1856 1856
 
1857
-    if ( ! empty( $args['exclude'] ) ) {
1858
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1857
+    if (!empty($args['exclude'])) {
1858
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1859 1859
     }
1860 1860
 
1861
-    if ( ! $args['paginate' ] ) {
1861
+    if (!$args['paginate']) {
1862 1862
         $wp_query_args['no_found_rows'] = true;
1863 1863
     }
1864 1864
 
1865 1865
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1866 1866
 
1867 1867
     // Get results.
1868
-    $invoices = new WP_Query( $wp_query_args );
1868
+    $invoices = new WP_Query($wp_query_args);
1869 1869
 
1870
-    if ( 'objects' === $args['return'] ) {
1871
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1872
-    } elseif ( 'self' === $args['return'] ) {
1870
+    if ('objects' === $args['return']) {
1871
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1872
+    } elseif ('self' === $args['return']) {
1873 1873
         return $invoices;
1874 1874
     } else {
1875 1875
         $return = $invoices->posts;
1876 1876
     }
1877 1877
 
1878
-    if ( $args['paginate' ] ) {
1878
+    if ($args['paginate']) {
1879 1879
         return (object) array(
1880 1880
             'invoices'      => $return,
1881 1881
             'total'         => $invoices->found_posts,
@@ -1888,22 +1888,22 @@  discard block
 block discarded – undo
1888 1888
 
1889 1889
 function wpinv_get_user_invoices_columns() {
1890 1890
     $columns = array(
1891
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1892
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1893
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1894
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1895
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1896
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1891
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1892
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1893
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1894
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1895
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1896
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1897 1897
         );
1898 1898
 
1899
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1899
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1900 1900
 }
1901 1901
 
1902
-function wpinv_payment_receipt( $atts, $content = null ) {
1902
+function wpinv_payment_receipt($atts, $content = null) {
1903 1903
     global $wpinv_receipt_args;
1904 1904
 
1905
-    $wpinv_receipt_args = shortcode_atts( array(
1906
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1905
+    $wpinv_receipt_args = shortcode_atts(array(
1906
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1907 1907
         'price'           => true,
1908 1908
         'discount'        => true,
1909 1909
         'items'           => true,
@@ -1912,197 +1912,197 @@  discard block
 block discarded – undo
1912 1912
         'invoice_key'     => false,
1913 1913
         'payment_method'  => true,
1914 1914
         'invoice_id'      => true
1915
-    ), $atts, 'wpinv_receipt' );
1915
+    ), $atts, 'wpinv_receipt');
1916 1916
 
1917 1917
     $session = wpinv_get_checkout_session();
1918
-    if ( isset( $_GET['invoice_key'] ) ) {
1919
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1920
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1918
+    if (isset($_GET['invoice_key'])) {
1919
+        $invoice_key = urldecode($_GET['invoice_key']);
1920
+    } else if ($session && isset($session['invoice_key'])) {
1921 1921
         $invoice_key = $session['invoice_key'];
1922
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1922
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1923 1923
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1924
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1925
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1924
+    } else if (isset($_GET['invoice-id'])) {
1925
+        $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']);
1926 1926
     }
1927 1927
 
1928 1928
     // No key found
1929
-    if ( ! isset( $invoice_key ) ) {
1929
+    if (!isset($invoice_key)) {
1930 1930
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1931 1931
     }
1932 1932
 
1933
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1934
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1935
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1936
-        $invoice_id     = (int)$_GET['invoice-id'];
1937
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1933
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1934
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1935
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1936
+        $invoice_id     = (int) $_GET['invoice-id'];
1937
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1938 1938
     }
1939 1939
 
1940 1940
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1941
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1941
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1942 1942
         // login redirect
1943
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1943
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1944 1944
     }
1945 1945
 
1946
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1946
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1947 1947
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1948 1948
     }
1949 1949
 
1950 1950
     ob_start();
1951 1951
 
1952
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1952
+    wpinv_get_template_part('wpinv-invoice-receipt');
1953 1953
 
1954 1954
     $display = ob_get_clean();
1955 1955
 
1956 1956
     return $display;
1957 1957
 }
1958 1958
 
1959
-function wpinv_get_invoice_id_by_key( $key ) {
1959
+function wpinv_get_invoice_id_by_key($key) {
1960 1960
 	global $wpdb;
1961 1961
 
1962
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1962
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1963 1963
 
1964
-	if ( $invoice_id != NULL )
1964
+	if ($invoice_id != NULL)
1965 1965
 		return $invoice_id;
1966 1966
 
1967 1967
 	return 0;
1968 1968
 }
1969 1969
 
1970
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1970
+function wpinv_can_view_receipt($invoice_key = '') {
1971 1971
 	$return = false;
1972 1972
 
1973
-	if ( empty( $invoice_key ) ) {
1973
+	if (empty($invoice_key)) {
1974 1974
 		return $return;
1975 1975
 	}
1976 1976
 
1977 1977
 	global $wpinv_receipt_args;
1978 1978
 
1979
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1980
-	if ( isset( $_GET['invoice-id'] ) ) {
1981
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1979
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1980
+	if (isset($_GET['invoice-id'])) {
1981
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
1982 1982
 	}
1983 1983
 
1984
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1984
+	if (empty($wpinv_receipt_args['id'])) {
1985 1985
 		return $return;
1986 1986
 	}
1987 1987
 
1988
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1989
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1988
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1989
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1990 1990
 		return $return;
1991 1991
 	}
1992 1992
 
1993
-	if ( is_user_logged_in() ) {
1994
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1993
+	if (is_user_logged_in()) {
1994
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
1995 1995
 			$return = true;
1996 1996
 		}
1997 1997
 	}
1998 1998
 
1999 1999
 	$session = wpinv_get_checkout_session();
2000
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2001
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2000
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2001
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2002 2002
 
2003
-		if ( wpinv_require_login_to_checkout() ) {
2003
+		if (wpinv_require_login_to_checkout()) {
2004 2004
 			$return = $return && $check_key === $invoice_key;
2005 2005
 		} else {
2006 2006
 			$return = $check_key === $invoice_key;
2007 2007
 		}
2008 2008
 	}
2009 2009
 
2010
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2010
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2011 2011
 }
2012 2012
 
2013 2013
 function wpinv_pay_for_invoice() {
2014 2014
     global $wpinv_euvat;
2015 2015
     
2016
-    if ( isset( $_GET['invoice_key'] ) ) {
2016
+    if (isset($_GET['invoice_key'])) {
2017 2017
         $checkout_uri   = wpinv_get_checkout_uri();
2018
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2018
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2019 2019
         
2020
-        if ( empty( $invoice_key ) ) {
2021
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2022
-            wp_redirect( $checkout_uri );
2020
+        if (empty($invoice_key)) {
2021
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2022
+            wp_redirect($checkout_uri);
2023 2023
             exit();
2024 2024
         }
2025 2025
         
2026
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2026
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2027 2027
 
2028
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2029
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2030
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2031
-            $invoice_id     = (int)$_GET['invoice-id'];
2032
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2028
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2029
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2030
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2031
+            $invoice_id     = (int) $_GET['invoice-id'];
2032
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2033 2033
         }
2034 2034
         
2035
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2036
-            if ( $invoice->needs_payment() ) {
2035
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2036
+            if ($invoice->needs_payment()) {
2037 2037
                 $data                   = array();
2038 2038
                 $data['invoice_id']     = $invoice_id;
2039
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2039
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2040 2040
                 
2041
-                wpinv_set_checkout_session( $data );
2041
+                wpinv_set_checkout_session($data);
2042 2042
                 
2043
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2043
+                if (wpinv_get_option('vat_ip_country_default')) {
2044 2044
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2045 2045
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2046 2046
                     
2047
-                    wpinv_recalculate_tax( true );
2047
+                    wpinv_recalculate_tax(true);
2048 2048
                 }
2049 2049
                 
2050 2050
             } else {
2051 2051
                 $checkout_uri = $invoice->get_view_url();
2052 2052
             }
2053 2053
         } else {
2054
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2054
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2055 2055
             
2056
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2056
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2057 2057
         }
2058 2058
         
2059
-        if(wp_redirect( $checkout_uri )){
2059
+        if (wp_redirect($checkout_uri)) {
2060 2060
             exit;
2061 2061
         };
2062 2062
         wpinv_die();
2063 2063
     }
2064 2064
 }
2065
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2065
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2066 2066
 
2067
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2068
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2069
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2067
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2068
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2069
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2070 2070
             $user_id = $invoice->get_user_id();
2071
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2071
+            $secret = sanitize_text_field($_GET['_wpipay']);
2072 2072
             
2073
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2074
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2073
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2074
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2075 2075
                 
2076
-                wpinv_guest_redirect( $redirect_to, $user_id );
2076
+                wpinv_guest_redirect($redirect_to, $user_id);
2077 2077
                 exit();
2078 2078
             }
2079 2079
         }
2080 2080
     }
2081 2081
 }
2082
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2082
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2083 2083
 
2084
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2085
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2084
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2085
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2086 2086
     
2087
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2087
+    if (empty($invoice_id) && $invoice_id > 0) {
2088 2088
         return false;
2089 2089
     }
2090 2090
     
2091
-    if ( empty( $transaction_id ) ) {
2091
+    if (empty($transaction_id)) {
2092 2092
         $transaction_id = $invoice_id;
2093 2093
     }
2094 2094
 
2095
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2095
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2096 2096
     
2097
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2097
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2098 2098
 }
2099 2099
 
2100
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2101
-    if ( empty( $status_display ) ) {
2102
-        $status_display = wpinv_status_nicename( $status );
2100
+function wpinv_invoice_status_label($status, $status_display = '') {
2101
+    if (empty($status_display)) {
2102
+        $status_display = wpinv_status_nicename($status);
2103 2103
     }
2104 2104
     
2105
-    switch ( $status ) {
2105
+    switch ($status) {
2106 2106
         case 'publish' :
2107 2107
         case 'wpi-renewal' :
2108 2108
             $class = 'label-success';
@@ -2127,201 +2127,201 @@  discard block
 block discarded – undo
2127 2127
     
2128 2128
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2129 2129
     
2130
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2130
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2131 2131
 }
2132 2132
 
2133
-function wpinv_format_invoice_number( $number, $type = '' ) {
2134
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2135
-    if ( null !== $check ) {
2133
+function wpinv_format_invoice_number($number, $type = '') {
2134
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2135
+    if (null !== $check) {
2136 2136
         return $check;
2137 2137
     }
2138 2138
 
2139
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2139
+    if (!empty($number) && !is_numeric($number)) {
2140 2140
         return $number;
2141 2141
     }
2142 2142
 
2143
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2144
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2145
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2143
+    $padd = wpinv_get_option('invoice_number_padd');
2144
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2145
+    $postfix = wpinv_get_option('invoice_number_postfix');
2146 2146
     
2147
-    $padd = absint( $padd );
2148
-    $formatted_number = absint( $number );
2147
+    $padd = absint($padd);
2148
+    $formatted_number = absint($number);
2149 2149
     
2150
-    if ( $padd > 0 ) {
2151
-        $formatted_number = zeroise( $formatted_number, $padd );
2150
+    if ($padd > 0) {
2151
+        $formatted_number = zeroise($formatted_number, $padd);
2152 2152
     }    
2153 2153
 
2154 2154
     $formatted_number = $prefix . $formatted_number . $postfix;
2155 2155
 
2156
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2156
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2157 2157
 }
2158 2158
 
2159
-function wpinv_get_next_invoice_number( $type = '' ) {
2160
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2161
-    if ( null !== $check ) {
2159
+function wpinv_get_next_invoice_number($type = '') {
2160
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2161
+    if (null !== $check) {
2162 2162
         return $check;
2163 2163
     }
2164 2164
     
2165
-    if ( !wpinv_sequential_number_active() ) {
2165
+    if (!wpinv_sequential_number_active()) {
2166 2166
         return false;
2167 2167
     }
2168 2168
 
2169
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2170
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2171
-    if ( !absint( $start ) > 0 ) {
2169
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2170
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2171
+    if (!absint($start) > 0) {
2172 2172
         $start = 1;
2173 2173
     }
2174 2174
     $increment_number = true;
2175 2175
     $save_number = false;
2176 2176
 
2177
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2178
-        $number = wpinv_clean_invoice_number( $number );
2177
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2178
+        $number = wpinv_clean_invoice_number($number);
2179 2179
     }
2180 2180
 
2181
-    if ( empty( $number ) ) {
2182
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2183
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2181
+    if (empty($number)) {
2182
+        if (!($last_number === 0 || $last_number === '0')) {
2183
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2184 2184
 
2185
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2186
-                if ( is_numeric( $invoice_number ) ) {
2185
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2186
+                if (is_numeric($invoice_number)) {
2187 2187
                     $number = $invoice_number;
2188 2188
                 } else {
2189
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2189
+                    $number = wpinv_clean_invoice_number($invoice_number);
2190 2190
                 }
2191 2191
             }
2192 2192
 
2193
-            if ( empty( $number ) ) {
2193
+            if (empty($number)) {
2194 2194
                 $increment_number = false;
2195 2195
                 $number = $start;
2196
-                $save_number = ( $number - 1 );
2196
+                $save_number = ($number - 1);
2197 2197
             } else {
2198 2198
                 $save_number = $number;
2199 2199
             }
2200 2200
         }
2201 2201
     }
2202 2202
 
2203
-    if ( $start > $number ) {
2203
+    if ($start > $number) {
2204 2204
         $increment_number = false;
2205 2205
         $number = $start;
2206
-        $save_number = ( $number - 1 );
2206
+        $save_number = ($number - 1);
2207 2207
     }
2208 2208
 
2209
-    if ( $save_number !== false ) {
2210
-        update_option( 'wpinv_last_invoice_number', $save_number );
2209
+    if ($save_number !== false) {
2210
+        update_option('wpinv_last_invoice_number', $save_number);
2211 2211
     }
2212 2212
     
2213
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2213
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2214 2214
 
2215
-    if ( $increment_number ) {
2215
+    if ($increment_number) {
2216 2216
         $number++;
2217 2217
     }
2218 2218
 
2219
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2219
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2220 2220
 }
2221 2221
 
2222
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2223
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2224
-    if ( null !== $check ) {
2222
+function wpinv_clean_invoice_number($number, $type = '') {
2223
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2224
+    if (null !== $check) {
2225 2225
         return $check;
2226 2226
     }
2227 2227
     
2228
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2229
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2228
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2229
+    $postfix = wpinv_get_option('invoice_number_postfix');
2230 2230
 
2231
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2231
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2232 2232
 
2233
-    $length      = strlen( $number );
2234
-    $postfix_pos = strrpos( $number, $postfix );
2233
+    $length      = strlen($number);
2234
+    $postfix_pos = strrpos($number, $postfix);
2235 2235
     
2236
-    if ( false !== $postfix_pos ) {
2237
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2236
+    if (false !== $postfix_pos) {
2237
+        $number = substr_replace($number, '', $postfix_pos, $length);
2238 2238
     }
2239 2239
 
2240
-    $number = intval( $number );
2240
+    $number = intval($number);
2241 2241
 
2242
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2242
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2243 2243
 }
2244 2244
 
2245
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2245
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2246 2246
     global $wpdb;
2247 2247
 
2248
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2249
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2248
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2249
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2250 2250
     }
2251 2251
 
2252
-    if ( !$update ) {
2253
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2254
-        clean_post_cache( $post_ID );
2252
+    if (!$update) {
2253
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2254
+        clean_post_cache($post_ID);
2255 2255
     }
2256 2256
 }
2257
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2257
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2258 2258
 
2259
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2260
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2261
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2259
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2260
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2261
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2262 2262
     }
2263 2263
 }
2264
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2264
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2265 2265
 
2266
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2266
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2267 2267
     global $wpdb;
2268 2268
     
2269
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2270
-    if ( null !== $check ) {
2269
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2270
+    if (null !== $check) {
2271 2271
         return $check;
2272 2272
     }
2273 2273
 
2274
-    if ( wpinv_sequential_number_active() ) {
2274
+    if (wpinv_sequential_number_active()) {
2275 2275
         $number = wpinv_get_next_invoice_number();
2276 2276
 
2277
-        if ( $save_sequential ) {
2278
-            update_option( 'wpinv_last_invoice_number', $number );
2277
+        if ($save_sequential) {
2278
+            update_option('wpinv_last_invoice_number', $number);
2279 2279
         }
2280 2280
     } else {
2281 2281
         $number = $post_ID;
2282 2282
     }
2283 2283
 
2284
-    $number = wpinv_format_invoice_number( $number );
2284
+    $number = wpinv_format_invoice_number($number);
2285 2285
 
2286
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2286
+    update_post_meta($post_ID, '_wpinv_number', $number);
2287 2287
 
2288
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2288
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2289 2289
 
2290
-    clean_post_cache( $post_ID );
2290
+    clean_post_cache($post_ID);
2291 2291
 
2292 2292
     return $number;
2293 2293
 }
2294 2294
 
2295
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2296
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2295
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2296
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2297 2297
 }
2298 2298
 
2299
-function wpinv_generate_post_name( $post_ID ) {
2300
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2301
-    $post_name = sanitize_title( $prefix . $post_ID );
2299
+function wpinv_generate_post_name($post_ID) {
2300
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2301
+    $post_name = sanitize_title($prefix . $post_ID);
2302 2302
 
2303
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2303
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2304 2304
 }
2305 2305
 
2306
-function wpinv_is_invoice_viewed( $invoice_id ) {
2307
-    if ( empty( $invoice_id ) ) {
2306
+function wpinv_is_invoice_viewed($invoice_id) {
2307
+    if (empty($invoice_id)) {
2308 2308
         return false;
2309 2309
     }
2310 2310
 
2311
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2311
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2312 2312
 
2313
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2313
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2314 2314
 }
2315 2315
 
2316 2316
 function wpinv_mark_invoice_viewed() {
2317 2317
 
2318
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2319
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2318
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2319
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2320 2320
 	    global $post;
2321 2321
 
2322
-        if(!empty($invoice_key)){
2322
+        if (!empty($invoice_key)) {
2323 2323
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2324
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2324
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2325 2325
 			$invoice_id = $post->ID;
2326 2326
         } else {
2327 2327
         	return;
@@ -2329,60 +2329,60 @@  discard block
 block discarded – undo
2329 2329
 
2330 2330
         $invoice = new WPInv_Invoice($invoice_id);
2331 2331
 
2332
-        if(!$invoice_id){
2332
+        if (!$invoice_id) {
2333 2333
             return;
2334 2334
         }
2335 2335
 
2336
-	    if ( is_user_logged_in() ) {
2337
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2338
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2339
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2340
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2336
+	    if (is_user_logged_in()) {
2337
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2338
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2339
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2340
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2341 2341
 		    }
2342 2342
 	    } else {
2343
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2344
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2343
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2344
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2345 2345
 		    }
2346 2346
 	    }
2347 2347
     }
2348 2348
 
2349 2349
 }
2350
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2350
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2351 2351
 
2352
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2353
-    if ( empty( $invoice ) ) {
2352
+function wpinv_get_subscription($invoice, $by_parent = false) {
2353
+    if (empty($invoice)) {
2354 2354
         return false;
2355 2355
     }
2356 2356
     
2357
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2358
-        $invoice = wpinv_get_invoice( $invoice );
2357
+    if (!is_object($invoice) && is_scalar($invoice)) {
2358
+        $invoice = wpinv_get_invoice($invoice);
2359 2359
     }
2360 2360
     
2361
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2361
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2362 2362
         return false;
2363 2363
     }
2364 2364
     
2365
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2365
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2366 2366
     
2367 2367
     $subs_db    = new WPInv_Subscriptions_DB;
2368
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2368
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2369 2369
     
2370
-    if ( ! empty( $subs ) ) {
2371
-        return reset( $subs );
2370
+    if (!empty($subs)) {
2371
+        return reset($subs);
2372 2372
     }
2373 2373
     
2374 2374
     return false;
2375 2375
 }
2376 2376
 
2377
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2377
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2378 2378
     global $wpdb;
2379 2379
 
2380
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2381
-        if ( !empty( $clauses['join'] ) ) {
2380
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2381
+        if (!empty($clauses['join'])) {
2382 2382
             $clauses['join'] .= " ";
2383 2383
         }
2384 2384
 
2385
-        if ( !empty( $clauses['fields'] ) ) {
2385
+        if (!empty($clauses['fields'])) {
2386 2386
             $clauses['fields'] .= ", ";
2387 2387
         }
2388 2388
 
@@ -2393,4 +2393,4 @@  discard block
 block discarded – undo
2393 2393
 
2394 2394
     return $clauses;
2395 2395
 }
2396
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2397 2396
\ No newline at end of file
2397
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2398 2398
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -7,202 +7,202 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool) apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65 65
 function wpinv_is_subscriptions_history_page() {
66
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
67
-    $ret = $ret ? is_page( $ret ) : false;
68
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
66
+    $ret = wpinv_get_option('invoice_subscription_page', false);
67
+    $ret = $ret ? is_page($ret) : false;
68
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
69 69
 }
70 70
 
71
-function wpinv_send_to_success_page( $args = null ) {
71
+function wpinv_send_to_success_page($args = null) {
72 72
 	$redirect = wpinv_get_success_page_uri();
73 73
     
74
-    if ( !empty( $args ) ) {
74
+    if (!empty($args)) {
75 75
         // Check for backward compatibility
76
-        if ( is_string( $args ) )
77
-            $args = str_replace( '?', '', $args );
76
+        if (is_string($args))
77
+            $args = str_replace('?', '', $args);
78 78
 
79
-        $args = wp_parse_args( $args );
79
+        $args = wp_parse_args($args);
80 80
 
81
-        $redirect = add_query_arg( $args, $redirect );
81
+        $redirect = add_query_arg($args, $redirect);
82 82
     }
83 83
 
84
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
84
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
85 85
     
86
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
87
-    wp_redirect( $redirect );
86
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
87
+    wp_redirect($redirect);
88 88
     exit;
89 89
 }
90 90
 
91
-function wpinv_send_to_failed_page( $args = null ) {
91
+function wpinv_send_to_failed_page($args = null) {
92 92
 	$redirect = wpinv_get_failed_transaction_uri();
93 93
     
94
-    if ( !empty( $args ) ) {
94
+    if (!empty($args)) {
95 95
         // Check for backward compatibility
96
-        if ( is_string( $args ) )
97
-            $args = str_replace( '?', '', $args );
96
+        if (is_string($args))
97
+            $args = str_replace('?', '', $args);
98 98
 
99
-        $args = wp_parse_args( $args );
99
+        $args = wp_parse_args($args);
100 100
 
101
-        $redirect = add_query_arg( $args, $redirect );
101
+        $redirect = add_query_arg($args, $redirect);
102 102
     }
103 103
 
104
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
104
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
105 105
     
106
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
107
-    wp_redirect( $redirect );
106
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
107
+    wp_redirect($redirect);
108 108
     exit;
109 109
 }
110 110
 
111
-function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
111
+function wpinv_get_checkout_uri($args = array()) {
112
+	$uri = wpinv_get_option('checkout_page', false);
113
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
115
+	if (!empty($args)) {
116 116
 		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
117
+		if (is_string($args))
118
+			$args = str_replace('?', '', $args);
119 119
 
120
-		$args = wp_parse_args( $args );
120
+		$args = wp_parse_args($args);
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
122
+		$uri = add_query_arg($args, $uri);
123 123
 	}
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
129
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
130
+		$uri = preg_replace('/^http:/', 'https:', $uri);
131 131
 	}
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+	return apply_filters('wpinv_get_checkout_uri', $uri);
134 134
 }
135 135
 
136
-function wpinv_send_back_to_checkout( $args = array() ) {
136
+function wpinv_send_back_to_checkout($args = array()) {
137 137
 	$redirect = wpinv_get_checkout_uri();
138 138
 
139
-	if ( ! empty( $args ) ) {
139
+	if (!empty($args)) {
140 140
 		// Check for backward compatibility
141
-		if ( is_string( $args ) )
142
-			$args = str_replace( '?', '', $args );
141
+		if (is_string($args))
142
+			$args = str_replace('?', '', $args);
143 143
 
144
-		$args = wp_parse_args( $args );
144
+		$args = wp_parse_args($args);
145 145
 
146
-		$redirect = add_query_arg( $args, $redirect );
146
+		$redirect = add_query_arg($args, $redirect);
147 147
 	}
148 148
 
149
-    do_action( 'wpinv_pre_send_back_to_checkout', $args );
150
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
149
+    do_action('wpinv_pre_send_back_to_checkout', $args);
150
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
151 151
 	exit;
152 152
 }
153 153
 
154
-function wpinv_get_success_page_url( $query_string = null ) {
155
-	$success_page = wpinv_get_option( 'success_page', 0 );
156
-	$success_page = get_permalink( $success_page );
154
+function wpinv_get_success_page_url($query_string = null) {
155
+	$success_page = wpinv_get_option('success_page', 0);
156
+	$success_page = get_permalink($success_page);
157 157
 
158
-	if ( $query_string )
158
+	if ($query_string)
159 159
 		$success_page .= $query_string;
160 160
 
161
-	return apply_filters( 'wpinv_success_page_url', $success_page );
161
+	return apply_filters('wpinv_success_page_url', $success_page);
162 162
 }
163 163
 
164
-function wpinv_get_failed_transaction_uri( $extras = false ) {
165
-	$uri = wpinv_get_option( 'failure_page', '' );
166
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
164
+function wpinv_get_failed_transaction_uri($extras = false) {
165
+	$uri = wpinv_get_option('failure_page', '');
166
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
167 167
 
168
-	if ( $extras )
168
+	if ($extras)
169 169
 		$uri .= $extras;
170 170
 
171
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
171
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
172 172
 }
173 173
 
174 174
 function wpinv_is_failed_transaction_page() {
175
-	$ret = wpinv_get_option( 'failure_page', false );
176
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
175
+	$ret = wpinv_get_option('failure_page', false);
176
+	$ret = isset($ret) ? is_page($ret) : false;
177 177
 
178
-	return apply_filters( 'wpinv_is_failure_page', $ret );
178
+	return apply_filters('wpinv_is_failure_page', $ret);
179 179
 }
180 180
 
181
-function wpinv_transaction_query( $type = 'start' ) {
181
+function wpinv_transaction_query($type = 'start') {
182 182
     global $wpdb;
183 183
 
184 184
     $wpdb->hide_errors();
185 185
 
186
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
187
-        define( 'WPINV_USE_TRANSACTIONS', true );
186
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
187
+        define('WPINV_USE_TRANSACTIONS', true);
188 188
     }
189 189
 
190
-    if ( WPINV_USE_TRANSACTIONS ) {
191
-        switch ( $type ) {
190
+    if (WPINV_USE_TRANSACTIONS) {
191
+        switch ($type) {
192 192
             case 'commit' :
193
-                $wpdb->query( 'COMMIT' );
193
+                $wpdb->query('COMMIT');
194 194
                 break;
195 195
             case 'rollback' :
196
-                $wpdb->query( 'ROLLBACK' );
196
+                $wpdb->query('ROLLBACK');
197 197
                 break;
198 198
             default :
199
-                $wpdb->query( 'START TRANSACTION' );
199
+                $wpdb->query('START TRANSACTION');
200 200
             break;
201 201
         }
202 202
     }
203 203
 }
204 204
 
205
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
205
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
206 206
     $default_args = array(
207 207
         'status'        => '',
208 208
         'user_id'       => null,
@@ -213,66 +213,66 @@  discard block
 block discarded – undo
213 213
         'post_type'     => 'wpi_invoice'
214 214
     );
215 215
 
216
-    $args           = wp_parse_args( $args, $default_args );
216
+    $args           = wp_parse_args($args, $default_args);
217 217
     $invoice_data   = array();
218 218
 
219
-    if ( $args['invoice_id'] > 0 ) {
220
-        $updating           = true;
219
+    if ($args['invoice_id'] > 0) {
220
+        $updating = true;
221 221
         $invoice_data['post_type']  = $args['post_type'];
222 222
         $invoice_data['ID']         = $args['invoice_id'];
223 223
     } else {
224 224
         $updating                       = false;
225 225
         $invoice_data['post_type']      = $args['post_type'];
226
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );
226
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending');
227 227
         $invoice_data['ping_status']    = 'closed';
228
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
229
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
230
-        $invoice_data['post_parent']    = absint( $args['parent'] );
231
-        if ( !empty( $args['created_date'] ) ) {
228
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
229
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
230
+        $invoice_data['post_parent']    = absint($args['parent']);
231
+        if (!empty($args['created_date'])) {
232 232
             $invoice_data['post_date']      = $args['created_date'];
233
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
233
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
234 234
         }
235 235
     }
236 236
 
237
-    if ( $args['status'] ) {
238
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) && 'wpi_invoice' === $invoice_data['post_type'] ) {
239
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
237
+    if ($args['status']) {
238
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses())) && 'wpi_invoice' === $invoice_data['post_type']) {
239
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
240 240
         }
241
-        $invoice_data['post_status']    = $args['status'];
241
+        $invoice_data['post_status'] = $args['status'];
242 242
     }
243 243
 
244
-    if ( ! is_null( $args['user_note'] ) ) {
245
-        $invoice_data['post_excerpt']   = $args['user_note'];
244
+    if (!is_null($args['user_note'])) {
245
+        $invoice_data['post_excerpt'] = $args['user_note'];
246 246
     }
247 247
 
248
-    if ( $updating ) {
249
-        $invoice_id = wp_update_post( $invoice_data, true );
248
+    if ($updating) {
249
+        $invoice_id = wp_update_post($invoice_data, true);
250 250
     } else {
251
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
251
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
252 252
     }
253 253
 
254
-    if ( is_wp_error( $invoice_id ) ) {
254
+    if (is_wp_error($invoice_id)) {
255 255
         return $wp_error ? $invoice_id : 0;
256 256
     }
257 257
     
258
-    $invoice = wpinv_get_invoice( $invoice_id );
259
-
260
-    if ( !$updating ) {
261
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
262
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
263
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
264
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
265
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
266
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
258
+    $invoice = wpinv_get_invoice($invoice_id);
259
+
260
+    if (!$updating) {
261
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
262
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
263
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
264
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
265
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
266
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
267 267
         
268 268
         // Add invoice note
269
-        if ( ! $invoice->is_quote() ) {
270
-            $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
269
+        if (!$invoice->is_quote()) {
270
+            $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
         }
272 272
         
273 273
     }
274 274
 
275
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
275
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
276 276
 
277 277
     return $invoice;
278 278
 }
@@ -280,184 +280,184 @@  discard block
 block discarded – undo
280 280
 function wpinv_get_prefix() {
281 281
     $invoice_prefix = 'INV-';
282 282
     
283
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
283
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
284 284
 }
285 285
 
286 286
 function wpinv_get_business_logo() {
287
-    $business_logo = wpinv_get_option( 'logo' );
288
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
287
+    $business_logo = wpinv_get_option('logo');
288
+    return apply_filters('wpinv_get_business_logo', $business_logo);
289 289
 }
290 290
 
291 291
 function wpinv_get_business_name() {
292 292
     $business_name = wpinv_get_option('store_name');
293
-    return apply_filters( 'wpinv_get_business_name', $business_name );
293
+    return apply_filters('wpinv_get_business_name', $business_name);
294 294
 }
295 295
 
296 296
 function wpinv_get_blogname() {
297
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
297
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
298 298
 }
299 299
 
300 300
 function wpinv_get_admin_email() {
301
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
302
-    return apply_filters( 'wpinv_admin_email', $admin_email );
301
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
302
+    return apply_filters('wpinv_admin_email', $admin_email);
303 303
 }
304 304
 
305 305
 function wpinv_get_business_website() {
306
-    $business_website = home_url( '/' );
307
-    return apply_filters( 'wpinv_get_business_website', $business_website );
306
+    $business_website = home_url('/');
307
+    return apply_filters('wpinv_get_business_website', $business_website);
308 308
 }
309 309
 
310
-function wpinv_get_terms_text( $invoice_id = 0 ) {
310
+function wpinv_get_terms_text($invoice_id = 0) {
311 311
     $terms_text = '';
312
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
312
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
313 313
 }
314 314
 
315 315
 function wpinv_get_business_footer() {
316
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
317
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
318
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
316
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
317
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
318
+    return apply_filters('wpinv_get_business_footer', $business_footer);
319 319
 }
320 320
 
321 321
 function wpinv_checkout_required_fields() {
322 322
     $required_fields = array();
323 323
     
324 324
     // Let payment gateways and other extensions determine if address fields should be required
325
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
325
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
326 326
     
327
-    if ( $require_billing_details ) {
328
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
327
+    if ($require_billing_details) {
328
+		if ((bool) wpinv_get_option('fname_mandatory')) {
329 329
 			$required_fields['first_name'] = array(
330 330
 				'error_id' => 'invalid_first_name',
331
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
331
+				'error_message' => __('Please enter your first name', 'invoicing')
332 332
 			);
333 333
 		}
334
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
334
+		if ((bool) wpinv_get_option('address_mandatory')) {
335 335
 			$required_fields['address'] = array(
336 336
 				'error_id' => 'invalid_address',
337
-				'error_message' => __( 'Please enter your address', 'invoicing' )
337
+				'error_message' => __('Please enter your address', 'invoicing')
338 338
 			);
339 339
 		}
340
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
340
+		if ((bool) wpinv_get_option('city_mandatory')) {
341 341
 			$required_fields['city'] = array(
342 342
 				'error_id' => 'invalid_city',
343
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
343
+				'error_message' => __('Please enter your billing city', 'invoicing')
344 344
 			);
345 345
 		}
346
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
346
+		if ((bool) wpinv_get_option('state_mandatory')) {
347 347
 			$required_fields['state'] = array(
348 348
 				'error_id' => 'invalid_state',
349
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
349
+				'error_message' => __('Please enter billing state / province', 'invoicing')
350 350
 			);
351 351
 		}
352
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
352
+		if ((bool) wpinv_get_option('country_mandatory')) {
353 353
 			$required_fields['country'] = array(
354 354
 				'error_id' => 'invalid_country',
355
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
355
+				'error_message' => __('Please select your billing country', 'invoicing')
356 356
 			);
357 357
 		}
358 358
     }
359 359
 
360
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
360
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
361 361
 }
362 362
 
363 363
 function wpinv_is_ssl_enforced() {
364
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
365
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
364
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
365
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
366 366
 }
367 367
 
368
-function wpinv_user_can_view_invoice( $post ) {
368
+function wpinv_user_can_view_invoice($post) {
369 369
     $allow = false;
370 370
 
371
-    $post = get_post( $post );
371
+    $post = get_post($post);
372 372
 
373
-    if ( empty( $post->ID ) ) {
373
+    if (empty($post->ID)) {
374 374
         return $allow;
375 375
     }
376 376
 
377
-    $invoice = wpinv_get_invoice( $post->ID );
378
-    if ( empty( $invoice->ID ) ) {
377
+    $invoice = wpinv_get_invoice($post->ID);
378
+    if (empty($invoice->ID)) {
379 379
         return $allow;
380 380
     }
381 381
 
382 382
     // Don't allow trash, draft status
383
-    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
384
-        if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->ID ) ) { // Admin user
383
+    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
384
+        if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->ID)) { // Admin user
385 385
             $allow = true;
386 386
         } else {
387
-            if ( is_user_logged_in() ) {
388
-                if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) {
387
+            if (is_user_logged_in()) {
388
+                if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
389 389
                     $allow = true;
390
-                } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
390
+                } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
391 391
                     $allow = true;
392 392
                 }
393 393
             } else {
394
-                if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
394
+                if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
395 395
                     $allow = true;
396 396
                 }
397 397
             }
398 398
         }
399 399
     }
400 400
     
401
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );
401
+    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice);
402 402
 }
403 403
 
404 404
 function wpinv_schedule_events() {
405 405
     // hourly, daily and twicedaily
406
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
407
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
406
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
407
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
408 408
     }
409 409
 }
410
-add_action( 'wp', 'wpinv_schedule_events' );
410
+add_action('wp', 'wpinv_schedule_events');
411 411
 
412 412
 function wpinv_schedule_event_twicedaily() {
413 413
     wpinv_email_payment_reminders();
414 414
 }
415
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
415
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
416 416
 
417 417
 function wpinv_require_login_to_checkout() {
418
-    $return = wpinv_get_option( 'login_to_checkout', false );
419
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
418
+    $return = wpinv_get_option('login_to_checkout', false);
419
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
420 420
 }
421 421
 
422
-function wpinv_sequential_number_active( $type = '' ) {
423
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
424
-    if ( null !== $check ) {
422
+function wpinv_sequential_number_active($type = '') {
423
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
424
+    if (null !== $check) {
425 425
         return $check;
426 426
     }
427 427
     
428
-    return wpinv_get_option( 'sequential_invoice_number' );
428
+    return wpinv_get_option('sequential_invoice_number');
429 429
 }
430 430
 
431
-function wpinv_switch_to_locale( $locale = NULL ) {
431
+function wpinv_switch_to_locale($locale = NULL) {
432 432
     global $invoicing, $wpi_switch_locale;
433 433
 
434
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
435
-        $locale = empty( $locale ) ? get_locale() : $locale;
434
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
435
+        $locale = empty($locale) ? get_locale() : $locale;
436 436
 
437
-        switch_to_locale( $locale );
437
+        switch_to_locale($locale);
438 438
 
439 439
         $wpi_switch_locale = $locale;
440 440
 
441
-        add_filter( 'plugin_locale', 'get_locale' );
441
+        add_filter('plugin_locale', 'get_locale');
442 442
 
443 443
         $invoicing->load_textdomain();
444 444
 
445
-        do_action( 'wpinv_switch_to_locale', $locale );
445
+        do_action('wpinv_switch_to_locale', $locale);
446 446
     }
447 447
 }
448 448
 
449 449
 function wpinv_restore_locale() {
450 450
     global $invoicing, $wpi_switch_locale;
451 451
     
452
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
452
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
453 453
         restore_previous_locale();
454 454
 
455 455
         $wpi_switch_locale = NULL;
456 456
 
457
-        remove_filter( 'plugin_locale', 'get_locale' );
457
+        remove_filter('plugin_locale', 'get_locale');
458 458
 
459 459
         $invoicing->load_textdomain();
460 460
 
461
-        do_action( 'wpinv_restore_locale' );
461
+        do_action('wpinv_restore_locale');
462 462
     }
463 463
 }
464 464
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -33,34 +33,34 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
55
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('widgets_init', array(&$this, 'register_widgets'));
55
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
56 56
 
57
-        if ( is_admin() ) {
58
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
59
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
60
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
57
+        if (is_admin()) {
58
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
59
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
60
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
61 61
 
62 62
         } else {
63
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
63
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
64 64
         }
65 65
         
66 66
         /**
@@ -70,28 +70,28 @@  discard block
 block discarded – undo
70 70
          *
71 71
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
72 72
          */
73
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
73
+        do_action_ref_array('wpinv_actions', array(&$this));
74 74
 
75
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
75
+        add_action('admin_init', array(&$this, 'activation_redirect'));
76 76
     }
77 77
 
78 78
     /**
79 79
      * Maybe show the AyeCode Connect Notice.
80 80
      */
81
-    public function init_ayecode_connect_helper(){
81
+    public function init_ayecode_connect_helper() {
82 82
         // AyeCode Connect notice
83
-        if ( is_admin() ){
83
+        if (is_admin()) {
84 84
             // set the strings so they can be translated
85 85
             $strings = array(
86
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
87
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
88
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
89
-                'connect_button'    => __("Connect Site","invoicing"),
90
-                'connecting_button'    => __("Connecting...","invoicing"),
91
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
92
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
86
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
87
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
88
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
89
+                'connect_button'    => __("Connect Site", "invoicing"),
90
+                'connecting_button'    => __("Connecting...", "invoicing"),
91
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
92
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
93 93
             );
94
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
94
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
95 95
         }
96 96
     }
97 97
     
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
         /* Internationalize the text strings used. */
100 100
         $this->load_textdomain();
101 101
 
102
-        do_action( 'wpinv_loaded' );
102
+        do_action('wpinv_loaded');
103 103
 
104 104
         // Fix oxygen page builder conflict
105
-        if ( function_exists( 'ct_css_output' ) ) {
105
+        if (function_exists('ct_css_output')) {
106 106
             wpinv_oxygen_fix_conflict();
107 107
         }
108 108
     }
@@ -112,237 +112,237 @@  discard block
 block discarded – undo
112 112
      *
113 113
      * @since 1.0
114 114
      */
115
-    public function load_textdomain( $locale = NULL ) {
116
-        if ( empty( $locale ) ) {
117
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
115
+    public function load_textdomain($locale = NULL) {
116
+        if (empty($locale)) {
117
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
118 118
         }
119 119
 
120
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
120
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
121 121
         
122
-        unload_textdomain( 'invoicing' );
123
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
124
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
122
+        unload_textdomain('invoicing');
123
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
124
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
125 125
         
126 126
         /**
127 127
          * Define language constants.
128 128
          */
129
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
129
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
130 130
     }
131 131
         
132 132
     public function includes() {
133 133
         global $wpinv_options;
134 134
         
135
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
135
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
136 136
         $wpinv_options = wpinv_get_settings();
137 137
         
138
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
139
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
140
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
141
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
142
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
143
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
144
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
145
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
148
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
149
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
150
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
151
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
162
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
163
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
164
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
165
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
166
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
168
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
169
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
170
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
174
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
175
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
176
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
177
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
178
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'widgets/payment-form.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
182
-
183
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
184
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
138
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
139
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
140
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
141
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
142
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
143
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
144
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
145
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
148
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
149
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
150
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
151
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
162
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
163
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
164
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
165
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
166
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
168
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
169
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
170
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
174
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
175
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
176
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
177
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
178
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'widgets/payment-form.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
182
+
183
+        if (!class_exists('WPInv_EUVat')) {
184
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
185 185
         }
186 186
         
187
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
188
-        if ( !empty( $gateways ) ) {
189
-            foreach ( $gateways as $gateway ) {
190
-                if ( $gateway == 'manual' ) {
187
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
188
+        if (!empty($gateways)) {
189
+            foreach ($gateways as $gateway) {
190
+                if ($gateway == 'manual') {
191 191
                     continue;
192 192
                 }
193 193
                 
194 194
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
195 195
                 
196
-                if ( file_exists( $gateway_file ) ) {
197
-                    require_once( $gateway_file );
196
+                if (file_exists($gateway_file)) {
197
+                    require_once($gateway_file);
198 198
                 }
199 199
             }
200 200
         }
201
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
201
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
202 202
         
203
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
204
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
205
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
206
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
203
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
204
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
205
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
206
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
207 207
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
208
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
209
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
210
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
211
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
212
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
213
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
214
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
215
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
208
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
209
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
210
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
211
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
212
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
213
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
214
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
215
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
216 216
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
217 217
             // load the user class only on the users.php page
218 218
             global $pagenow;
219
-            if($pagenow=='users.php'){
219
+            if ($pagenow == 'users.php') {
220 220
                 new WPInv_Admin_Users();
221 221
             }
222 222
         }
223 223
 
224 224
         // Register cli commands
225
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
227
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
225
+        if (defined('WP_CLI') && WP_CLI) {
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
227
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
228 228
         }
229 229
         
230 230
         // include css inliner
231
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
232
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
231
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
232
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
233 233
         }
234 234
         
235
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
235
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
236 236
     }
237 237
     
238 238
     public function init() {
239 239
     }
240 240
     
241 241
     public function admin_init() {
242
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
242
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
243 243
     }
244 244
 
245 245
     public function activation_redirect() {
246 246
         // Bail if no activation redirect
247
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
247
+        if (!get_transient('_wpinv_activation_redirect')) {
248 248
             return;
249 249
         }
250 250
 
251 251
         // Delete the redirect transient
252
-        delete_transient( '_wpinv_activation_redirect' );
252
+        delete_transient('_wpinv_activation_redirect');
253 253
 
254 254
         // Bail if activating from network, or bulk
255
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
255
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
256 256
             return;
257 257
         }
258 258
 
259
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
259
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
260 260
         exit;
261 261
     }
262 262
     
263 263
     public function enqueue_scripts() {
264
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
264
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
265 265
         
266
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
267
-        wp_enqueue_style( 'wpinv_front_style' );
266
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
267
+        wp_enqueue_style('wpinv_front_style');
268 268
                
269 269
         // Register scripts
270
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
271
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
270
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
271
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
272 272
 
273 273
         $localize                         = array();
274
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
275
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
274
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
275
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
276 276
         $localize['currency_symbol']      = wpinv_currency_symbol();
277 277
         $localize['currency_pos']         = wpinv_currency_position();
278 278
         $localize['thousand_sep']         = wpinv_thousands_separator();
279 279
         $localize['decimal_sep']          = wpinv_decimal_separator();
280 280
         $localize['decimals']             = wpinv_decimals();
281
-        $localize['txtComplete']          = __( 'Complete', 'invoicing' );
281
+        $localize['txtComplete']          = __('Complete', 'invoicing');
282 282
         $localize['UseTaxes']             = wpinv_use_taxes();
283
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
283
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
284 284
 
285
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
285
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
286 286
         
287
-        wp_enqueue_script( 'jquery-blockui' );
287
+        wp_enqueue_script('jquery-blockui');
288 288
         $autofill_api = wpinv_get_option('address_autofill_api');
289 289
         $autofill_active = wpinv_get_option('address_autofill_active');
290
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
291
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
292
-                wp_dequeue_script( 'google-maps-api' );
290
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
291
+            if (wp_script_is('google-maps-api', 'enqueued')) {
292
+                wp_dequeue_script('google-maps-api');
293 293
             }
294
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
295
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
294
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
295
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
296 296
         }
297 297
 
298
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
299
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
298
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
299
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
300 300
 
301
-        wp_enqueue_script( 'wpinv-front-script' );
302
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
301
+        wp_enqueue_script('wpinv-front-script');
302
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
303 303
 
304
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
305
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
304
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
305
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
306 306
     }
307 307
 
308
-    public function admin_enqueue_scripts( $hook ) {
308
+    public function admin_enqueue_scripts($hook) {
309 309
         global $post, $pagenow;
310 310
         
311 311
         $post_type  = wpinv_admin_post_type();
312
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
313
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
312
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
313
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
314 314
 
315 315
         $jquery_ui_css = false;
316
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
316
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
317 317
             $jquery_ui_css = true;
318
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
318
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
319 319
             $jquery_ui_css = true;
320 320
         }
321
-        if ( $jquery_ui_css ) {
322
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
323
-            wp_enqueue_style( 'jquery-ui-css' );
321
+        if ($jquery_ui_css) {
322
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
323
+            wp_enqueue_style('jquery-ui-css');
324 324
         }
325 325
 
326
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
327
-        wp_enqueue_style( 'wpinv_meta_box_style' );
326
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
327
+        wp_enqueue_style('wpinv_meta_box_style');
328 328
         
329
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
330
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
331
-        wp_enqueue_style( 'wpinv_admin_style' );
329
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
330
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
331
+        wp_enqueue_style('wpinv_admin_style');
332 332
 
333
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
334
-        if ( $page == 'wpinv-subscriptions' ) {
335
-            wp_enqueue_script( 'jquery-ui-datepicker' );
333
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
334
+        if ($page == 'wpinv-subscriptions') {
335
+            wp_enqueue_script('jquery-ui-datepicker');
336 336
         }
337 337
         
338
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
339
-            wp_enqueue_script( 'jquery-ui-datepicker' );
338
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
339
+            wp_enqueue_script('jquery-ui-datepicker');
340 340
         }
341 341
 
342
-        wp_enqueue_style( 'wp-color-picker' );
343
-        wp_enqueue_script( 'wp-color-picker' );
342
+        wp_enqueue_style('wp-color-picker');
343
+        wp_enqueue_script('wp-color-picker');
344 344
         
345
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
345
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
346 346
 
347 347
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
348 348
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -353,21 +353,21 @@  discard block
 block discarded – undo
353 353
             }
354 354
         }
355 355
 
356
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
357
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
356
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
357
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
358 358
 
359
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
360
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
361
-        wp_enqueue_script( 'wpinv-admin-script' );
359
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
360
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
361
+        wp_enqueue_script('wpinv-admin-script');
362 362
         
363 363
         $localize                               = array();
364
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
365
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
366
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
367
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
368
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
369
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
370
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
364
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
365
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
366
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
367
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
368
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
369
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
370
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
371 371
         $localize['tax']                        = wpinv_tax_amount();
372 372
         $localize['discount']                   = wpinv_discount_amount();
373 373
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -375,95 +375,95 @@  discard block
 block discarded – undo
375 375
         $localize['thousand_sep']               = wpinv_thousands_separator();
376 376
         $localize['decimal_sep']                = wpinv_decimal_separator();
377 377
         $localize['decimals']                   = wpinv_decimals();
378
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
379
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
380
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
381
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
382
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
383
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
384
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
385
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
386
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
387
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
388
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
389
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
390
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
391
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
392
-
393
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
394
-
395
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
378
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
379
+        $localize['status_publish']             = wpinv_status_nicename('publish');
380
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
381
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
382
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
383
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
384
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
385
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
386
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
387
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
388
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
389
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
390
+        $localize['action_edit']                = __('Edit', 'invoicing');
391
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
392
+
393
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
394
+
395
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
396 396
 
397 397
         // Load payment form scripts on our admin pages only.
398
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
398
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
399 399
 
400
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
401
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
402
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
400
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
401
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
402
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
403 403
 
404
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
405
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
404
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
405
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
406 406
         
407
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
407
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
408 408
                 'elements'      => $this->form_elements->get_elements(),
409
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
409
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
410 410
                 'all_items'     => $this->form_elements->get_published_items(),
411 411
                 'currency'      => wpinv_currency_symbol(),
412 412
                 'position'      => wpinv_currency_position(),
413 413
                 'decimals'      => (int) wpinv_decimals(),
414 414
                 'thousands_sep' => wpinv_thousands_separator(),
415 415
                 'decimals_sep'  => wpinv_decimal_separator(),
416
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
417
-            ) );
416
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
417
+            ));
418 418
 
419
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
419
+            wp_enqueue_script('wpinv-admin-payment-form-script');
420 420
         }
421 421
 
422
-        if ( $page == 'wpinv-subscriptions' ) {
423
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
424
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
422
+        if ($page == 'wpinv-subscriptions') {
423
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
424
+            wp_enqueue_script('wpinv-sub-admin-script');
425 425
         }
426 426
 
427 427
     }
428 428
 
429
-    public function admin_body_class( $classes ) {
429
+    public function admin_body_class($classes) {
430 430
         global $pagenow, $post, $current_screen;
431 431
         
432
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
432
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
433 433
             $classes .= ' wpinv-cpt';
434 434
         }
435 435
         
436
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
436
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
437 437
 
438
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
439
-        if ( $add_class ) {
440
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
438
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
439
+        if ($add_class) {
440
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
441 441
         }
442 442
         
443 443
         $settings_class = array();
444
-        if ( $page == 'wpinv-settings' ) {
445
-            if ( !empty( $_REQUEST['tab'] ) ) {
446
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
444
+        if ($page == 'wpinv-settings') {
445
+            if (!empty($_REQUEST['tab'])) {
446
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
447 447
             }
448 448
             
449
-            if ( !empty( $_REQUEST['section'] ) ) {
450
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
449
+            if (!empty($_REQUEST['section'])) {
450
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
451 451
             }
452 452
             
453
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
453
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
454 454
         }
455 455
         
456
-        if ( !empty( $settings_class ) ) {
457
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
456
+        if (!empty($settings_class)) {
457
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
458 458
         }
459 459
         
460 460
         $post_type = wpinv_admin_post_type();
461 461
 
462
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
462
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
463 463
             return $classes .= ' wpinv';
464 464
         }
465 465
         
466
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
466
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
467 467
             $classes .= ' wpi-editable-n';
468 468
         }
469 469
 
@@ -475,21 +475,21 @@  discard block
 block discarded – undo
475 475
     }
476 476
     
477 477
     public function wpinv_actions() {
478
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
479
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
478
+        if (isset($_REQUEST['wpi_action'])) {
479
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
480 480
         }
481 481
     }
482 482
     
483
-    public function pre_get_posts( $wp_query ) {
484
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
485
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
483
+    public function pre_get_posts($wp_query) {
484
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
485
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
486 486
         }
487 487
         
488 488
         return $wp_query;
489 489
     }
490 490
     
491 491
     public function bp_invoicing_init() {
492
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
492
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
493 493
     }
494 494
 
495 495
 	/**
@@ -497,13 +497,13 @@  discard block
 block discarded – undo
497 497
 	 *
498 498
 	 */
499 499
 	public function register_widgets() {
500
-		register_widget( "WPInv_Checkout_Widget" );
501
-		register_widget( "WPInv_History_Widget" );
502
-		register_widget( "WPInv_Receipt_Widget" );
503
-		register_widget( "WPInv_Subscriptions_Widget" );
504
-		register_widget( "WPInv_Buy_Item_Widget" );
505
-        register_widget( "WPInv_Messages_Widget" );
506
-        register_widget( 'WPInv_Payment_Form_Widget' );
500
+		register_widget("WPInv_Checkout_Widget");
501
+		register_widget("WPInv_History_Widget");
502
+		register_widget("WPInv_Receipt_Widget");
503
+		register_widget("WPInv_Subscriptions_Widget");
504
+		register_widget("WPInv_Buy_Item_Widget");
505
+        register_widget("WPInv_Messages_Widget");
506
+        register_widget('WPInv_Payment_Form_Widget');
507 507
 	}
508 508
     
509 509
     /**
@@ -512,10 +512,10 @@  discard block
 block discarded – undo
512 512
      * @since 1.0.19
513 513
      * @param int[] $excluded_posts_ids
514 514
      */
515
-    function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
515
+    function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
516 516
 
517 517
         // Ensure that we have an array.
518
-        if ( ! is_array( $excluded_posts_ids ) ) {
518
+        if (!is_array($excluded_posts_ids)) {
519 519
             $excluded_posts_ids = array();
520 520
         }
521 521
 
@@ -523,24 +523,24 @@  discard block
 block discarded – undo
523 523
         $our_pages = array();
524 524
     
525 525
         // Checkout page.
526
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
526
+        $our_pages[] = wpinv_get_option('checkout_page', false);
527 527
 
528 528
         // Success page.
529
-        $our_pages[] = wpinv_get_option( 'success_page', false );
529
+        $our_pages[] = wpinv_get_option('success_page', false);
530 530
 
531 531
         // Failure page.
532
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
532
+        $our_pages[] = wpinv_get_option('failure_page', false);
533 533
 
534 534
         // History page.
535
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
535
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
536 536
 
537 537
         // Subscriptions page.
538
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
538
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
539 539
 
540
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
540
+        $our_pages   = array_map('intval', array_filter($our_pages));
541 541
 
542 542
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
543
-        return array_unique( $excluded_posts_ids );
543
+        return array_unique($excluded_posts_ids);
544 544
 
545 545
     }
546 546
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array) $template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,159 +208,159 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
244
+function wpinv_add_body_classes($class) {
245
+	$classes = (array) $class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
 
334 334
     $options = array(
335
-        '1'  => __( 'January', 'invoicing' ),
336
-        '2'  => __( 'February', 'invoicing' ),
337
-        '3'  => __( 'March', 'invoicing' ),
338
-        '4'  => __( 'April', 'invoicing' ),
339
-        '5'  => __( 'May', 'invoicing' ),
340
-        '6'  => __( 'June', 'invoicing' ),
341
-        '7'  => __( 'July', 'invoicing' ),
342
-        '8'  => __( 'August', 'invoicing' ),
343
-        '9'  => __( 'September', 'invoicing' ),
344
-        '10' => __( 'October', 'invoicing' ),
345
-        '11' => __( 'November', 'invoicing' ),
346
-        '12' => __( 'December', 'invoicing' ),
335
+        '1'  => __('January', 'invoicing'),
336
+        '2'  => __('February', 'invoicing'),
337
+        '3'  => __('March', 'invoicing'),
338
+        '4'  => __('April', 'invoicing'),
339
+        '5'  => __('May', 'invoicing'),
340
+        '6'  => __('June', 'invoicing'),
341
+        '7'  => __('July', 'invoicing'),
342
+        '8'  => __('August', 'invoicing'),
343
+        '9'  => __('September', 'invoicing'),
344
+        '10' => __('October', 'invoicing'),
345
+        '11' => __('November', 'invoicing'),
346
+        '12' => __('December', 'invoicing'),
347 347
     );
348 348
 
349 349
     // If no month is selected, default to the current month
350
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
350
+    $selected = empty($selected) ? date('n') : $selected;
351 351
 
352
-    $output = wpinv_html_select( array(
352
+    $output = wpinv_html_select(array(
353 353
         'name'             => $name,
354 354
         'selected'         => $selected,
355 355
         'options'          => $options,
356 356
         'show_option_all'  => false,
357 357
         'show_option_none' => false
358
-    ) );
358
+    ));
359 359
 
360 360
     return $output;
361 361
 }
362 362
 
363
-function wpinv_html_select( $args = array() ) {
363
+function wpinv_html_select($args = array()) {
364 364
     $defaults = array(
365 365
         'options'          => array(),
366 366
         'name'             => null,
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
         'selected'         => 0,
370 370
         'placeholder'      => null,
371 371
         'multiple'         => false,
372
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
373
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
372
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
373
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
374 374
         'data'             => array(),
375 375
         'onchange'         => null,
376 376
         'required'         => false,
@@ -378,74 +378,74 @@  discard block
 block discarded – undo
378 378
         'readonly'         => false,
379 379
     );
380 380
 
381
-    $args = wp_parse_args( $args, $defaults );
381
+    $args = wp_parse_args($args, $defaults);
382 382
 
383 383
     $data_elements = '';
384
-    foreach ( $args['data'] as $key => $value ) {
385
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
384
+    foreach ($args['data'] as $key => $value) {
385
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
386 386
     }
387 387
 
388
-    if( $args['multiple'] ) {
388
+    if ($args['multiple']) {
389 389
         $multiple = ' MULTIPLE';
390 390
     } else {
391 391
         $multiple = '';
392 392
     }
393 393
 
394
-    if( $args['placeholder'] ) {
394
+    if ($args['placeholder']) {
395 395
         $placeholder = $args['placeholder'];
396 396
     } else {
397 397
         $placeholder = '';
398 398
     }
399 399
     
400 400
     $options = '';
401
-    if( !empty( $args['onchange'] ) ) {
402
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
401
+    if (!empty($args['onchange'])) {
402
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
403 403
     }
404 404
     
405
-    if( !empty( $args['required'] ) ) {
405
+    if (!empty($args['required'])) {
406 406
         $options .= ' required="required"';
407 407
     }
408 408
     
409
-    if( !empty( $args['disabled'] ) ) {
409
+    if (!empty($args['disabled'])) {
410 410
         $options .= ' disabled';
411 411
     }
412 412
     
413
-    if( !empty( $args['readonly'] ) ) {
413
+    if (!empty($args['readonly'])) {
414 414
         $options .= ' readonly';
415 415
     }
416 416
 
417
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
418
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
417
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
418
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
419 419
 
420
-    if ( $args['show_option_all'] ) {
421
-        if( $args['multiple'] ) {
422
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
420
+    if ($args['show_option_all']) {
421
+        if ($args['multiple']) {
422
+            $selected = selected(true, in_array(0, $args['selected']), false);
423 423
         } else {
424
-            $selected = selected( $args['selected'], 0, false );
424
+            $selected = selected($args['selected'], 0, false);
425 425
         }
426
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
426
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
427 427
     }
428 428
 
429
-    if ( !empty( $args['options'] ) ) {
429
+    if (!empty($args['options'])) {
430 430
 
431
-        if ( $args['show_option_none'] ) {
432
-            if( $args['multiple'] ) {
433
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
431
+        if ($args['show_option_none']) {
432
+            if ($args['multiple']) {
433
+                $selected = selected(true, in_array("", $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'] === "", true, false );
435
+                $selected = selected($args['selected'] === "", true, false);
436 436
             }
437
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
437
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
438 438
         }
439 439
 
440
-        foreach( $args['options'] as $key => $option ) {
440
+        foreach ($args['options'] as $key => $option) {
441 441
 
442
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
443
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
442
+            if ($args['multiple'] && is_array($args['selected'])) {
443
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
444 444
             } else {
445
-                $selected = selected( $args['selected'], $key, false );
445
+                $selected = selected($args['selected'], $key, false);
446 446
             }
447 447
 
448
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
448
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
449 449
         }
450 450
     }
451 451
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     return $output;
455 455
 }
456 456
 
457
-function wpinv_item_dropdown( $args = array() ) {
457
+function wpinv_item_dropdown($args = array()) {
458 458
     $defaults = array(
459 459
         'name'              => 'wpi_item',
460 460
         'id'                => 'wpi_item',
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
         'multiple'          => false,
463 463
         'selected'          => 0,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'show_recurring'    => false,
470 470
     );
471 471
 
472
-    $args = wp_parse_args( $args, $defaults );
472
+    $args = wp_parse_args($args, $defaults);
473 473
 
474 474
     $item_args = array(
475 475
         'post_type'      => 'wpi_item',
@@ -478,44 +478,44 @@  discard block
 block discarded – undo
478 478
         'posts_per_page' => $args['number']
479 479
     );
480 480
     
481
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
481
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
482 482
 
483
-    $items      = get_posts( $item_args );
483
+    $items      = get_posts($item_args);
484 484
     $options    = array();
485
-    if ( $items ) {
486
-        foreach ( $items as $item ) {
487
-            $title = esc_html( $item->post_title );
485
+    if ($items) {
486
+        foreach ($items as $item) {
487
+            $title = esc_html($item->post_title);
488 488
             
489
-            if ( !empty( $args['show_recurring'] ) ) {
490
-                $title .= wpinv_get_item_suffix( $item->ID, false );
489
+            if (!empty($args['show_recurring'])) {
490
+                $title .= wpinv_get_item_suffix($item->ID, false);
491 491
             }
492 492
             
493
-            $options[ absint( $item->ID ) ] = $title;
493
+            $options[absint($item->ID)] = $title;
494 494
         }
495 495
     }
496 496
 
497 497
     // This ensures that any selected items are included in the drop down
498
-    if( is_array( $args['selected'] ) ) {
499
-        foreach( $args['selected'] as $item ) {
500
-            if( ! in_array( $item, $options ) ) {
501
-                $title = get_the_title( $item );
502
-                if ( !empty( $args['show_recurring'] ) ) {
503
-                    $title .= wpinv_get_item_suffix( $item, false );
498
+    if (is_array($args['selected'])) {
499
+        foreach ($args['selected'] as $item) {
500
+            if (!in_array($item, $options)) {
501
+                $title = get_the_title($item);
502
+                if (!empty($args['show_recurring'])) {
503
+                    $title .= wpinv_get_item_suffix($item, false);
504 504
                 }
505 505
                 $options[$item] = $title;
506 506
             }
507 507
         }
508
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
509
-        if ( ! in_array( $args['selected'], $options ) ) {
510
-            $title = get_the_title( $args['selected'] );
511
-            if ( !empty( $args['show_recurring'] ) ) {
512
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
508
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
509
+        if (!in_array($args['selected'], $options)) {
510
+            $title = get_the_title($args['selected']);
511
+            if (!empty($args['show_recurring'])) {
512
+                $title .= wpinv_get_item_suffix($args['selected'], false);
513 513
             }
514
-            $options[$args['selected']] = get_the_title( $args['selected'] );
514
+            $options[$args['selected']] = get_the_title($args['selected']);
515 515
         }
516 516
     }
517 517
 
518
-    $output = wpinv_html_select( array(
518
+    $output = wpinv_html_select(array(
519 519
         'name'             => $args['name'],
520 520
         'selected'         => $args['selected'],
521 521
         'id'               => $args['id'],
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
         'show_option_all'  => $args['show_option_all'],
527 527
         'show_option_none' => $args['show_option_none'],
528 528
         'data'             => $args['data'],
529
-    ) );
529
+    ));
530 530
 
531 531
     return $output;
532 532
 }
533 533
 
534
-function wpinv_html_checkbox( $args = array() ) {
534
+function wpinv_html_checkbox($args = array()) {
535 535
     $defaults = array(
536 536
         'name'     => null,
537 537
         'current'  => null,
@@ -542,38 +542,38 @@  discard block
 block discarded – undo
542 542
         )
543 543
     );
544 544
 
545
-    $args = wp_parse_args( $args, $defaults );
545
+    $args = wp_parse_args($args, $defaults);
546 546
 
547
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
547
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
548 548
     $options = '';
549
-    if ( ! empty( $args['options']['disabled'] ) ) {
549
+    if (!empty($args['options']['disabled'])) {
550 550
         $options .= ' disabled="disabled"';
551
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
551
+    } elseif (!empty($args['options']['readonly'])) {
552 552
         $options .= ' readonly';
553 553
     }
554 554
 
555
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
555
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
556 556
 
557 557
     return $output;
558 558
 }
559 559
 
560
-function wpinv_html_text( $args = array() ) {
560
+function wpinv_html_text($args = array()) {
561 561
     // Backwards compatibility
562
-    if ( func_num_args() > 1 ) {
562
+    if (func_num_args() > 1) {
563 563
         $args = func_get_args();
564 564
 
565 565
         $name  = $args[0];
566
-        $value = isset( $args[1] ) ? $args[1] : '';
567
-        $label = isset( $args[2] ) ? $args[2] : '';
568
-        $desc  = isset( $args[3] ) ? $args[3] : '';
566
+        $value = isset($args[1]) ? $args[1] : '';
567
+        $label = isset($args[2]) ? $args[2] : '';
568
+        $desc  = isset($args[3]) ? $args[3] : '';
569 569
     }
570 570
 
571 571
     $defaults = array(
572 572
         'id'           => '',
573
-        'name'         => isset( $name )  ? $name  : 'text',
574
-        'value'        => isset( $value ) ? $value : null,
575
-        'label'        => isset( $label ) ? $label : null,
576
-        'desc'         => isset( $desc )  ? $desc  : null,
573
+        'name'         => isset($name) ? $name : 'text',
574
+        'value'        => isset($value) ? $value : null,
575
+        'label'        => isset($label) ? $label : null,
576
+        'desc'         => isset($desc) ? $desc : null,
577 577
         'placeholder'  => '',
578 578
         'class'        => 'regular-text',
579 579
         'disabled'     => false,
@@ -583,51 +583,51 @@  discard block
 block discarded – undo
583 583
         'data'         => false
584 584
     );
585 585
 
586
-    $args = wp_parse_args( $args, $defaults );
586
+    $args = wp_parse_args($args, $defaults);
587 587
 
588
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
588
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
589 589
     $options = '';
590
-    if( $args['required'] ) {
590
+    if ($args['required']) {
591 591
         $options .= ' required="required"';
592 592
     }
593
-    if( $args['readonly'] ) {
593
+    if ($args['readonly']) {
594 594
         $options .= ' readonly';
595 595
     }
596
-    if( $args['readonly'] ) {
596
+    if ($args['readonly']) {
597 597
         $options .= ' readonly';
598 598
     }
599 599
 
600 600
     $data = '';
601
-    if ( !empty( $args['data'] ) ) {
602
-        foreach ( $args['data'] as $key => $value ) {
603
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
601
+    if (!empty($args['data'])) {
602
+        foreach ($args['data'] as $key => $value) {
603
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
604 604
         }
605 605
     }
606 606
 
607
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
608
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
609
-    if ( ! empty( $args['desc'] ) ) {
610
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
607
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
608
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
609
+    if (!empty($args['desc'])) {
610
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
611 611
     }
612 612
 
613
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
613
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
614 614
 
615 615
     $output .= '</span>';
616 616
 
617 617
     return $output;
618 618
 }
619 619
 
620
-function wpinv_html_date_field( $args = array() ) {
621
-    if( empty( $args['class'] ) ) {
620
+function wpinv_html_date_field($args = array()) {
621
+    if (empty($args['class'])) {
622 622
         $args['class'] = 'wpiDatepicker';
623
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
623
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
624 624
         $args['class'] .= ' wpiDatepicker';
625 625
     }
626 626
 
627
-    return wpinv_html_text( $args );
627
+    return wpinv_html_text($args);
628 628
 }
629 629
 
630
-function wpinv_html_textarea( $args = array() ) {
630
+function wpinv_html_textarea($args = array()) {
631 631
     $defaults = array(
632 632
         'name'        => 'textarea',
633 633
         'value'       => null,
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
         'placeholder' => '',
639 639
     );
640 640
 
641
-    $args = wp_parse_args( $args, $defaults );
641
+    $args = wp_parse_args($args, $defaults);
642 642
 
643
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
643
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
644 644
     $disabled = '';
645
-    if( $args['disabled'] ) {
645
+    if ($args['disabled']) {
646 646
         $disabled = ' disabled="disabled"';
647 647
     }
648 648
 
649
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
650
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
651
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
649
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
650
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
651
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
652 652
 
653
-    if ( ! empty( $args['desc'] ) ) {
654
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
653
+    if (!empty($args['desc'])) {
654
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
655 655
     }
656 656
     $output .= '</span>';
657 657
 
658 658
     return $output;
659 659
 }
660 660
 
661
-function wpinv_html_ajax_user_search( $args = array() ) {
661
+function wpinv_html_ajax_user_search($args = array()) {
662 662
     $defaults = array(
663 663
         'name'        => 'user_id',
664 664
         'value'       => null,
665
-        'placeholder' => __( 'Enter username', 'invoicing' ),
665
+        'placeholder' => __('Enter username', 'invoicing'),
666 666
         'label'       => null,
667 667
         'desc'        => null,
668 668
         'class'       => '',
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         'data'        => false
672 672
     );
673 673
 
674
-    $args = wp_parse_args( $args, $defaults );
674
+    $args = wp_parse_args($args, $defaults);
675 675
 
676 676
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
677 677
 
678 678
     $output  = '<span class="wpinv_user_search_wrap">';
679
-        $output .= wpinv_html_text( $args );
680
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
679
+        $output .= wpinv_html_text($args);
680
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 function wpinv_ip_geolocation() {
687 687
     global $wpinv_euvat;
688 688
     
689
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
689
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
690 690
     $content    = '';
691 691
     $iso        = '';
692 692
     $country    = '';
@@ -697,69 +697,69 @@  discard block
 block discarded – undo
697 697
     $credit     = '';
698 698
     $address    = '';
699 699
     
700
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
700
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
701 701
         try {
702 702
             $iso        = $geoip2_city->country->isoCode;
703 703
             $country    = $geoip2_city->country->name;
704
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
704
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
705 705
             $city       = $geoip2_city->city->name;
706 706
             $longitude  = $geoip2_city->location->longitude;
707 707
             $latitude   = $geoip2_city->location->latitude;
708
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
709
-        } catch( Exception $e ) { }
708
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
709
+        } catch (Exception $e) { }
710 710
     }
711 711
     
712
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
712
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
713 713
         try {
714
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
714
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
715 715
             
716
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
716
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
717 717
                 $iso        = $load_xml->geoplugin_countryCode;
718 718
                 $country    = $load_xml->geoplugin_countryName;
719
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
720
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
719
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
720
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
721 721
                 $longitude  = $load_xml->geoplugin_longitude;
722 722
                 $latitude   = $load_xml->geoplugin_latitude;
723 723
                 $credit     = $load_xml->geoplugin_credit;
724
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
724
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
725 725
             }
726
-        } catch( Exception $e ) { }
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( $iso && $longitude && $latitude ) {
730
-        if ( $city ) {
729
+    if ($iso && $longitude && $latitude) {
730
+        if ($city) {
731 731
             $address .= $city . ', ';
732 732
         }
733 733
         
734
-        if ( $region ) {
734
+        if ($region) {
735 735
             $address .= $region . ', ';
736 736
         }
737 737
         
738 738
         $address .= $country . ' (' . $iso . ')';
739
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
740
-        $content .= '<p>'. $credit . '</p>';
739
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
740
+        $content .= '<p>' . $credit . '</p>';
741 741
     } else {
742
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
742
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
743 743
     }
744 744
     ?>
745 745
 <!DOCTYPE html>
746
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
746
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
747 747
 <body>
748
-    <?php if ( $latitude && $latitude ) { ?>
748
+    <?php if ($latitude && $latitude) { ?>
749 749
     <div id="map"></div>
750 750
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
751 751
         <script type="text/javascript">
752 752
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
753 753
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
754 754
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
755
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
755
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
756 756
 
757 757
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
758 758
 
759 759
         var marker = new L.Marker(latlng);
760 760
         map.addLayer(marker);
761 761
 
762
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
762
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
763 763
     </script>
764 764
     <?php } ?>
765 765
     <div style="height:100px"><?php echo $content; ?></div>
@@ -767,18 +767,18 @@  discard block
 block discarded – undo
767 767
 <?php
768 768
     exit;
769 769
 }
770
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
771
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
770
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
771
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
772 772
 
773 773
 // Set up the template for the invoice.
774
-function wpinv_template( $template ) {
774
+function wpinv_template($template) {
775 775
     global $post, $wp_query;
776 776
     
777
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
778
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
779
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
777
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
778
+        if (wpinv_user_can_view_invoice($post->ID)) {
779
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
780 780
         } else {
781
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
781
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
782 782
         }
783 783
     }
784 784
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 function wpinv_get_business_address() {
789 789
     $business_address   = wpinv_store_address();
790
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
790
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
791 791
     
792 792
     /*
793 793
     $default_country    = wpinv_get_default_country();
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     
812 812
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
813 813
     
814
-    return apply_filters( 'wpinv_get_business_address', $business_address );
814
+    return apply_filters('wpinv_get_business_address', $business_address);
815 815
 }
816 816
 
817 817
 function wpinv_display_from_address() {
@@ -821,107 +821,107 @@  discard block
 block discarded – undo
821 821
     if (empty($from_name)) {
822 822
         $from_name = wpinv_get_business_name();
823 823
     }
824
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
824
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
825 825
     <div class="wrapper col-xs-10">
826
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
827
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
828
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
826
+        <div class="name"><?php echo esc_html($from_name); ?></div>
827
+        <?php if ($address = wpinv_get_business_address()) { ?>
828
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
829 829
         <?php } ?>
830
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
831
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
830
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
831
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
832 832
         <?php } ?>
833 833
     </div>
834 834
     <?php
835 835
 }
836 836
 
837
-function wpinv_watermark( $id = 0 ) {
838
-    $output = wpinv_get_watermark( $id );
837
+function wpinv_watermark($id = 0) {
838
+    $output = wpinv_get_watermark($id);
839 839
     
840
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
840
+    return apply_filters('wpinv_get_watermark', $output, $id);
841 841
 }
842 842
 
843
-function wpinv_get_watermark( $id ) {
844
-    if ( !$id > 0 ) {
843
+function wpinv_get_watermark($id) {
844
+    if (!$id > 0) {
845 845
         return NULL;
846 846
     }
847
-    $invoice = wpinv_get_invoice( $id );
847
+    $invoice = wpinv_get_invoice($id);
848 848
     
849
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
850
-        if ( $invoice->is_paid() ) {
851
-            return __( 'Paid', 'invoicing' );
849
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
850
+        if ($invoice->is_paid()) {
851
+            return __('Paid', 'invoicing');
852 852
         }
853
-        if ( $invoice->is_refunded() ) {
854
-            return __( 'Refunded', 'invoicing' );
853
+        if ($invoice->is_refunded()) {
854
+            return __('Refunded', 'invoicing');
855 855
         }
856
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
857
-            return __( 'Cancelled', 'invoicing' );
856
+        if ($invoice->has_status(array('wpi-cancelled'))) {
857
+            return __('Cancelled', 'invoicing');
858 858
         }
859 859
     }
860 860
     
861 861
     return NULL;
862 862
 }
863 863
 
864
-function wpinv_display_invoice_details( $invoice ) {
864
+function wpinv_display_invoice_details($invoice) {
865 865
     global $wpinv_euvat;
866 866
     
867 867
     $invoice_id = $invoice->ID;
868 868
     $vat_name   = $wpinv_euvat->get_vat_name();
869 869
     $use_taxes  = wpinv_use_taxes();
870 870
     
871
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
871
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
872 872
     ?>
873 873
     <table class="table table-bordered table-sm">
874
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
874
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
875 875
             <tr class="wpi-row-number">
876
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
877
-                <td><?php echo esc_html( $invoice_number ); ?></td>
876
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
877
+                <td><?php echo esc_html($invoice_number); ?></td>
878 878
             </tr>
879 879
         <?php } ?>
880 880
         <tr class="wpi-row-status">
881
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
882
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
881
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
882
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
883 883
         </tr>
884
-        <?php if ( $invoice->is_renewal() ) { ?>
884
+        <?php if ($invoice->is_renewal()) { ?>
885 885
         <tr class="wpi-row-parent">
886
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
887
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
886
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
887
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
888 888
         </tr>
889 889
         <?php } ?>
890
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
890
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
891 891
             <tr class="wpi-row-gateway">
892
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
892
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
893 893
                 <td><?php echo $gateway_name; ?></td>
894 894
             </tr>
895 895
         <?php } ?>
896
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
896
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
897 897
             <tr class="wpi-row-date">
898
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
898
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
899 899
                 <td><?php echo $invoice_date; ?></td>
900 900
             </tr>
901 901
         <?php } ?>
902
-        <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?>
903
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
902
+        <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?>
903
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
904 904
             <tr class="wpi-row-date">
905
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
905
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
906 906
                 <td><?php echo $due_date; ?></td>
907 907
             </tr>
908 908
         <?php } ?>
909
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
910
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
909
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
910
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
911 911
             <tr class="wpi-row-ovatno">
912
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
912
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
913 913
                 <td><?php echo $owner_vat_number; ?></td>
914 914
             </tr>
915 915
         <?php } ?>
916
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
916
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
917 917
             <tr class="wpi-row-uvatno">
918
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
918
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
919 919
                 <td><?php echo $user_vat_number; ?></td>
920 920
             </tr>
921 921
         <?php } ?>
922 922
         <tr class="table-active tr-total wpi-row-total">
923
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
924
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
923
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
924
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
925 925
         </tr>
926 926
     </table>
927 927
 <?php
@@ -937,84 +937,84 @@  discard block
 block discarded – undo
937 937
  * @param  string $separator How to separate address lines.
938 938
  * @return string
939 939
  */
940
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
940
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
941 941
 
942 942
     // Retrieve the address markup...
943
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
944
-    $format = wpinv_get_full_address_format( $country );
943
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
944
+    $format = wpinv_get_full_address_format($country);
945 945
 
946 946
     // ... and the replacements.
947
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
947
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
948 948
 
949
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
949
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
950 950
     
951 951
 	// Remove unavailable tags.
952
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
952
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
955
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
956
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+	$formatted_address = implode($separator, $formatted_address);
963 963
 
964 964
 	// We're done!
965 965
 	return $formatted_address;
966 966
     
967 967
 }
968 968
 
969
-function wpinv_display_to_address( $invoice_id = 0 ) {
970
-    $invoice = wpinv_get_invoice( $invoice_id );
969
+function wpinv_display_to_address($invoice_id = 0) {
970
+    $invoice = wpinv_get_invoice($invoice_id);
971 971
     
972
-    if ( empty( $invoice ) ) {
972
+    if (empty($invoice)) {
973 973
         return NULL;
974 974
     }
975 975
     
976 976
     $billing_details = $invoice->get_user_info();
977
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
977
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
978 978
     $output .= '<div class="wrapper col-xs-10">';
979 979
     
980 980
     ob_start();
981
-    do_action( 'wpinv_display_to_address_top', $invoice );
981
+    do_action('wpinv_display_to_address_top', $invoice);
982 982
     $output .= ob_get_clean();
983 983
     
984
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
984
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
985 985
 
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
 
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
 
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
1012
+    if (!$use_taxes && (float) $invoice->get_tax() > 0) {
1013 1013
         $use_taxes = true;
1014 1014
     }
1015
-    $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1016
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1017
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1015
+    $zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
1016
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1017
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1018 1018
 
1019 1019
     $cart_details       = $invoice->get_cart_details();
1020 1020
     $ajax_cart_details  = $cart_details;
@@ -1023,67 +1023,67 @@  discard block
 block discarded – undo
1023 1023
     <table class="table table-sm table-bordered">
1024 1024
         <thead>
1025 1025
             <tr>
1026
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1027
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1026
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1027
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1028 1028
                 <?php if ($quantities_enabled) { ?>
1029
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1029
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1030 1030
                 <?php } ?>
1031 1031
                 <?php if ($use_taxes && !$zero_tax) { ?>
1032 1032
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1033 1033
                 <?php } ?>
1034
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1034
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1035 1035
             </tr>
1036 1036
         </thead>
1037 1037
         <tbody>
1038 1038
         <?php 
1039
-            if ( !empty( $cart_details ) ) {
1040
-                do_action( 'wpinv_display_line_items_start', $invoice );
1039
+            if (!empty($cart_details)) {
1040
+                do_action('wpinv_display_line_items_start', $invoice);
1041 1041
 
1042 1042
                 $count = 0;
1043 1043
                 $cols  = 3;
1044
-                foreach ( $cart_details as $key => $cart_item ) {
1045
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1046
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1047
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1048
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1044
+                foreach ($cart_details as $key => $cart_item) {
1045
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1046
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1047
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1048
+                    $quantity   = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1049 1049
 
1050
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1050
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+	                $item_name = '';
1053 1053
                     $cols       = 3;
1054
-                    if ( !empty($item) ) {
1054
+                    if (!empty($item)) {
1055 1055
                         $item_name  = $item->get_name();
1056 1056
                         $summary    = $item->get_summary();
1057 1057
                     }
1058
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1058
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1059 1059
 
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
 
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
 
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
 
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
 
1077
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1077
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1078 1078
 
1079
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1080
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1081
-                        if ( $summary !== '' ) {
1082
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1079
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1080
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1081
+                        if ($summary !== '') {
1082
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1083 1083
                         }
1084 1084
                         $line_item .= '</td>';
1085 1085
 
1086
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1086
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1087 1087
                         if ($quantities_enabled) {
1088 1088
                             $cols++;
1089 1089
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1092,55 +1092,55 @@  discard block
 block discarded – undo
1092 1092
                             $cols++;
1093 1093
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1094 1094
                         }
1095
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1095
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1096 1096
                     $line_item .= '</tr>';
1097 1097
 
1098
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1098
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1099 1099
 
1100 1100
                     $count++;
1101 1101
                 }
1102 1102
 
1103
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1103
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1104 1104
                 ?>
1105 1105
                 <tr class="row-sub-total row_odd">
1106
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1107
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1106
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1107
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1108 1108
                 </tr>
1109 1109
                 <?php
1110
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1110
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1111 1111
                 
1112
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1113
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1112
+                if (wpinv_discount($invoice_id, false) > 0) {
1113
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1114 1114
                     ?>
1115 1115
                         <tr class="row-discount">
1116
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1117
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1116
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1117
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1118 1118
                         </tr>
1119 1119
                     <?php
1120
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1120
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1121 1121
                 }
1122 1122
 
1123
-                if ( $use_taxes ) {
1124
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1123
+                if ($use_taxes) {
1124
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1125 1125
                     ?>
1126 1126
                     <tr class="row-tax">
1127
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1128
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1127
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1128
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1129 1129
                     </tr>
1130 1130
                     <?php
1131
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1131
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1132 1132
                 }
1133 1133
 
1134
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1134
+                do_action('wpinv_display_before_total', $invoice, $cols);
1135 1135
                 ?>
1136 1136
                 <tr class="table-active row-total">
1137
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1138
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1137
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1138
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1139 1139
                 </tr>
1140 1140
                 <?php
1141
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1141
+                do_action('wpinv_display_after_total', $invoice, $cols);
1142 1142
 
1143
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1143
+                do_action('wpinv_display_line_end', $invoice, $cols);
1144 1144
             }
1145 1145
         ?>
1146 1146
         </tbody>
@@ -1152,56 +1152,56 @@  discard block
 block discarded – undo
1152 1152
 /**
1153 1153
  * @param WPInv_Invoice $invoice
1154 1154
  */
1155
-function wpinv_display_invoice_notes( $invoice ) {
1155
+function wpinv_display_invoice_notes($invoice) {
1156 1156
 
1157
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1157
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1158 1158
 
1159
-    if ( empty( $notes ) ) {
1159
+    if (empty($notes)) {
1160 1160
         return;
1161 1161
     }
1162 1162
 
1163 1163
     echo '<div class="wpi_invoice_notes_container">';
1164
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1164
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1165 1165
     echo '<ul class="wpi_invoice_notes">';
1166 1166
 
1167
-    foreach( $notes as $note ) {
1168
-        wpinv_get_invoice_note_line_item( $note );
1167
+    foreach ($notes as $note) {
1168
+        wpinv_get_invoice_note_line_item($note);
1169 1169
     }
1170 1170
 
1171 1171
     echo '</ul>';
1172 1172
     echo '</div>';
1173 1173
 }
1174
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1174
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1175 1175
 
1176
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1176
+function wpinv_display_invoice_totals($invoice_id = 0) {
1177 1177
     $use_taxes = wpinv_use_taxes();
1178 1178
 
1179
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1179
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1180 1180
     ?>
1181 1181
     <table class="table table-sm table-bordered table-responsive">
1182 1182
         <tbody>
1183
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1183
+            <?php do_action('wpinv_before_display_totals'); ?>
1184 1184
             <tr class="row-sub-total">
1185
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1186
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1185
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1186
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1187 1187
             </tr>
1188
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1189
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1188
+            <?php do_action('wpinv_after_display_totals'); ?>
1189
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1190 1190
                 <tr class="row-discount">
1191
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1192
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1191
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1192
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1193 1193
                 </tr>
1194
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1194
+            <?php do_action('wpinv_after_display_discount'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $use_taxes ) { ?>
1196
+            <?php if ($use_taxes) { ?>
1197 1197
             <tr class="row-tax">
1198
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1199
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1198
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1199
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1200 1200
             </tr>
1201
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1201
+            <?php do_action('wpinv_after_display_tax'); ?>
1202 1202
             <?php } ?>
1203
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1204
-                <?php foreach ( $fees as $fee ) { ?>
1203
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1204
+                <?php foreach ($fees as $fee) { ?>
1205 1205
                     <tr class="row-fee">
1206 1206
                         <td class="rate"><?php echo $fee['label']; ?></td>
1207 1207
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1209,82 +1209,82 @@  discard block
 block discarded – undo
1209 1209
                 <?php } ?>
1210 1210
             <?php } ?>
1211 1211
             <tr class="table-active row-total">
1212
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1213
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1212
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1213
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1214 1214
             </tr>
1215
-            <?php do_action( 'wpinv_after_totals' ); ?>
1215
+            <?php do_action('wpinv_after_totals'); ?>
1216 1216
         </tbody>
1217 1217
 
1218 1218
     </table>
1219 1219
 
1220
-    <?php do_action( 'wpinv_after_totals_table' );
1220
+    <?php do_action('wpinv_after_totals_table');
1221 1221
 }
1222 1222
 
1223
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1224
-    $invoice = wpinv_get_invoice( $invoice_id );
1223
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1224
+    $invoice = wpinv_get_invoice($invoice_id);
1225 1225
 
1226 1226
     ob_start();
1227
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1228
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1227
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1228
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1229 1229
         ?>
1230 1230
         <div class="wpi-payment-info">
1231
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1232
-            <?php if ( $gateway_title ) { ?>
1233
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1231
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1232
+            <?php if ($gateway_title) { ?>
1233
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1234 1234
             <?php } ?>
1235 1235
         </div>
1236 1236
         <?php
1237 1237
     }
1238
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1238
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1239 1239
     $outout = ob_get_clean();
1240 1240
 
1241
-    if ( $echo ) {
1241
+    if ($echo) {
1242 1242
         echo $outout;
1243 1243
     } else {
1244 1244
         return $outout;
1245 1245
     }
1246 1246
 }
1247 1247
 
1248
-function wpinv_display_style( $invoice ) {
1249
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1248
+function wpinv_display_style($invoice) {
1249
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1250 1250
 
1251
-    wp_print_styles( 'open-sans' );
1252
-    wp_print_styles( 'wpinv-single-style' );
1251
+    wp_print_styles('open-sans');
1252
+    wp_print_styles('wpinv-single-style');
1253 1253
 
1254 1254
     $custom_css = wpinv_get_option('template_custom_css');
1255
-    if(isset($custom_css) && !empty($custom_css)){
1256
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1257
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1255
+    if (isset($custom_css) && !empty($custom_css)) {
1256
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1257
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1258 1258
         echo '<style type="text/css">';
1259 1259
         echo $custom_css;
1260 1260
         echo '</style>';
1261 1261
     }
1262 1262
 }
1263
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1264
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1263
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1264
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1265 1265
 
1266 1266
 function wpinv_checkout_billing_details() {
1267
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1267
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1268 1268
     if (empty($invoice_id)) {
1269
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1269
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1270 1270
         return null;
1271 1271
     }
1272 1272
 
1273
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1273
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1274 1274
     if (empty($invoice)) {
1275
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1275
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1276 1276
         return null;
1277 1277
     }
1278 1278
     $user_id        = $invoice->get_user_id();
1279 1279
     $user_info      = $invoice->get_user_info();
1280
-    $address_info   = wpinv_get_user_address( $user_id );
1280
+    $address_info   = wpinv_get_user_address($user_id);
1281 1281
 
1282
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1282
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1283 1283
         $user_info['first_name'] = $user_info['first_name'];
1284 1284
         $user_info['last_name'] = $user_info['last_name'];
1285 1285
     }
1286 1286
 
1287
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1287
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1288 1288
         $user_info['country']   = $address_info['country'];
1289 1289
         $user_info['state']     = $address_info['state'];
1290 1290
         $user_info['city']      = $address_info['city'];
@@ -1300,99 +1300,99 @@  discard block
 block discarded – undo
1300 1300
         'address'
1301 1301
     );
1302 1302
 
1303
-    foreach ( $address_fields as $field ) {
1304
-        if ( empty( $user_info[$field] ) ) {
1303
+    foreach ($address_fields as $field) {
1304
+        if (empty($user_info[$field])) {
1305 1305
             $user_info[$field] = $address_info[$field];
1306 1306
         }
1307 1307
     }
1308 1308
 
1309
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1309
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1310 1310
 }
1311 1311
 
1312 1312
 function wpinv_admin_get_line_items($invoice = array()) {
1313 1313
     $item_quantities    = wpinv_item_quantities_enabled();
1314 1314
     $use_taxes          = wpinv_use_taxes();
1315 1315
 
1316
-    if ( empty( $invoice ) ) {
1316
+    if (empty($invoice)) {
1317 1317
         return NULL;
1318 1318
     }
1319 1319
 
1320 1320
     $cart_items = $invoice->get_cart_details();
1321
-    if ( empty( $cart_items ) ) {
1321
+    if (empty($cart_items)) {
1322 1322
         return NULL;
1323 1323
     }
1324 1324
 
1325 1325
     ob_start();
1326 1326
 
1327
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1327
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1328 1328
 
1329 1329
     $count = 0;
1330
-    foreach ( $cart_items as $key => $cart_item ) {
1330
+    foreach ($cart_items as $key => $cart_item) {
1331 1331
         $item_id    = $cart_item['id'];
1332
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1332
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1333 1333
 
1334 1334
         if (empty($wpi_item)) {
1335 1335
             continue;
1336 1336
         }
1337 1337
 
1338
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1339
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1338
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1339
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1341 1341
         $can_remove     = true;
1342 1342
 
1343
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1343
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1344 1344
 
1345 1345
         $item_tax       = '';
1346 1346
         $tax_rate       = '';
1347
-        if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1348
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1349
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1350
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1347
+        if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1348
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1349
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1350
+            $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1351 1351
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1352 1352
         }
1353 1353
         $line_item_tax = $item_tax . $tax_rate;
1354 1354
 
1355
-        if ( $line_item_tax === '' ) {
1355
+        if ($line_item_tax === '') {
1356 1356
             $line_item_tax = 0; // Zero tax
1357 1357
         }
1358 1358
 
1359
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1359
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1360 1360
             $line_item .= '<td class="id">' . $item_id . '</td>';
1361
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1362
-            if ( $summary !== '' ) {
1363
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1361
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1362
+            if ($summary !== '') {
1363
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
             $line_item .= '<td class="price">' . $item_price . '</td>';
1367 1367
             
1368
-            if ( $item_quantities ) {
1369
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1368
+            if ($item_quantities) {
1369
+                if (count($cart_items) == 1 && $quantity <= 1) {
1370 1370
                     $can_remove = false;
1371 1371
                 }
1372 1372
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1373 1373
             } else {
1374
-                if ( count( $cart_items ) == 1 ) {
1374
+                if (count($cart_items) == 1) {
1375 1375
                     $can_remove = false;
1376 1376
                 }
1377 1377
             }
1378 1378
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1379 1379
             
1380
-            if ( $use_taxes ) {
1380
+            if ($use_taxes) {
1381 1381
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1382 1382
             }
1383 1383
             $line_item .= '<td class="action">';
1384
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
1384
+            if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1385 1385
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1386 1386
             }
1387 1387
             $line_item .= '</td>';
1388 1388
         $line_item .= '</tr>';
1389 1389
 
1390
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1390
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1391 1391
 
1392 1392
         $count++;
1393 1393
     } 
1394 1394
 
1395
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1395
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1396 1396
 
1397 1397
     return ob_get_clean();
1398 1398
 }
@@ -1404,32 +1404,32 @@  discard block
 block discarded – undo
1404 1404
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1405 1405
 
1406 1406
     //Maybe update the prices
1407
-    if(! empty( $_GET['wpi_dynamic_item'] ) && ! empty( $_GET['wpi_dynamic_price'] ) ) {
1407
+    if (!empty($_GET['wpi_dynamic_item']) && !empty($_GET['wpi_dynamic_price'])) {
1408 1408
 
1409 1409
         //If the invoice exists, update it with new pricing details
1410
-        if (! empty( $wpi_checkout_id ) ) {
1410
+        if (!empty($wpi_checkout_id)) {
1411 1411
 
1412 1412
             $_invoice       = wpinv_get_invoice_cart();
1413 1413
             $_cart_details  = $_invoice->get_cart_details();
1414
-            $_dynamic_item  = sanitize_text_field( $_GET['wpi_dynamic_item'] );
1414
+            $_dynamic_item  = sanitize_text_field($_GET['wpi_dynamic_item']);
1415 1415
 
1416 1416
             //First, fetch the item
1417
-            $item    = new WPInv_Item( $_dynamic_item );
1417
+            $item = new WPInv_Item($_dynamic_item);
1418 1418
     
1419 1419
             //Next, ensure it supports dynamic pricing...
1420
-            if( $item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing() ) {
1420
+            if ($item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing()) {
1421 1421
                 
1422 1422
                 //... and that the new price is not lower than the minimum price
1423
-                $_dynamic_price = (float) wpinv_sanitize_amount( sanitize_text_field( $_GET['wpi_dynamic_price'] ) );
1424
-                if( $_dynamic_price < $item->get_minimum_price() ) {
1423
+                $_dynamic_price = (float) wpinv_sanitize_amount(sanitize_text_field($_GET['wpi_dynamic_price']));
1424
+                if ($_dynamic_price < $item->get_minimum_price()) {
1425 1425
                     $_dynamic_price = $item->get_minimum_price();
1426 1426
                 }
1427 1427
 
1428 1428
                 //Finally, update our invoice with the new price
1429
-                if ( !empty( $_cart_details ) ) {
1429
+                if (!empty($_cart_details)) {
1430 1430
 
1431
-                    foreach ( $_cart_details as $key => $item ) {
1432
-                        if ( !empty( $item['id'] ) && $_dynamic_item == $item['id'] ) {
1431
+                    foreach ($_cart_details as $key => $item) {
1432
+                        if (!empty($item['id']) && $_dynamic_item == $item['id']) {
1433 1433
                             $_cart_details[$key]['custom_price'] = $_dynamic_price;
1434 1434
                             $_cart_details[$key]['item_price']   = $_dynamic_price;
1435 1435
                         }
@@ -1437,8 +1437,8 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
                     $_meta = $_invoice->get_meta();
1439 1439
                     $_meta['cart_details'] = $_cart_details;
1440
-                    $_invoice->set( 'payment_meta', $_meta );
1441
-                    $_invoice->set( 'cart_details', $_cart_details );
1440
+                    $_invoice->set('payment_meta', $_meta);
1441
+                    $_invoice->set('cart_details', $_cart_details);
1442 1442
                     $_invoice->recalculate_totals();
1443 1443
 
1444 1444
                 }
@@ -1449,60 +1449,60 @@  discard block
 block discarded – undo
1449 1449
 
1450 1450
     }
1451 1451
 
1452
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1452
+    $form_action = esc_url(wpinv_get_checkout_uri());
1453 1453
 
1454 1454
     ob_start();
1455
-	    do_action( 'wpinv_checkout_content_before' );
1455
+	    do_action('wpinv_checkout_content_before');
1456 1456
         echo '<div id="wpinv_checkout_wrap">';
1457 1457
 
1458
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1458
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1459 1459
             ?>
1460 1460
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1461
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1461
+                <?php do_action('wpinv_before_checkout_form'); ?>
1462 1462
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1463 1463
                     <?php
1464
-                    do_action( 'wpinv_checkout_form_top' );
1465
-                    do_action( 'wpinv_checkout_billing_info' );
1466
-                    do_action( 'wpinv_checkout_cart' );
1467
-                    do_action( 'wpinv_payment_mode_select'  );
1468
-                    do_action( 'wpinv_checkout_form_bottom' )
1464
+                    do_action('wpinv_checkout_form_top');
1465
+                    do_action('wpinv_checkout_billing_info');
1466
+                    do_action('wpinv_checkout_cart');
1467
+                    do_action('wpinv_payment_mode_select');
1468
+                    do_action('wpinv_checkout_form_bottom')
1469 1469
                     ?>
1470 1470
                 </form>
1471
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1471
+                <?php do_action('wpinv_after_purchase_form'); ?>
1472 1472
             </div><!--end #wpinv_checkout_form_wrap-->
1473 1473
         <?php
1474 1474
         } else {
1475
-            do_action( 'wpinv_cart_empty' );
1475
+            do_action('wpinv_cart_empty');
1476 1476
         }
1477 1477
         echo '</div><!--end #wpinv_checkout_wrap-->';
1478
-	    do_action( 'wpinv_checkout_content_after' );
1478
+	    do_action('wpinv_checkout_content_after');
1479 1479
     return ob_get_clean();
1480 1480
 }
1481 1481
 
1482
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1482
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1483 1483
     global $ajax_cart_details;
1484 1484
     $ajax_cart_details = $cart_details;
1485 1485
 
1486 1486
     ob_start();
1487
-    do_action( 'wpinv_before_checkout_cart' );
1487
+    do_action('wpinv_before_checkout_cart');
1488 1488
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1489 1489
         echo '<div id="wpinv_checkout_cart_wrap">';
1490
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1490
+            wpinv_get_template_part('wpinv-checkout-cart');
1491 1491
         echo '</div>';
1492 1492
     echo '</div>';
1493
-    do_action( 'wpinv_after_checkout_cart' );
1493
+    do_action('wpinv_after_checkout_cart');
1494 1494
     $content = ob_get_clean();
1495 1495
 
1496
-    if ( $echo ) {
1496
+    if ($echo) {
1497 1497
         echo $content;
1498 1498
     } else {
1499 1499
         return $content;
1500 1500
     }
1501 1501
 }
1502
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1502
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1503 1503
 
1504 1504
 function wpinv_empty_cart_message() {
1505
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1505
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1506 1506
 }
1507 1507
 
1508 1508
 /**
@@ -1514,83 +1514,83 @@  discard block
 block discarded – undo
1514 1514
 function wpinv_empty_checkout_cart() {
1515 1515
 	echo wpinv_empty_cart_message();
1516 1516
 }
1517
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1517
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1518 1518
 
1519 1519
 function wpinv_update_cart_button() {
1520
-    if ( !wpinv_item_quantities_enabled() )
1520
+    if (!wpinv_item_quantities_enabled())
1521 1521
         return;
1522 1522
 ?>
1523
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1523
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1524 1524
     <input type="hidden" name="wpi_action" value="update_cart"/>
1525 1525
 <?php
1526 1526
 }
1527 1527
 
1528 1528
 function wpinv_checkout_cart_columns() {
1529 1529
     $default = 3;
1530
-    if ( wpinv_item_quantities_enabled() ) {
1530
+    if (wpinv_item_quantities_enabled()) {
1531 1531
         $default++;
1532 1532
     }
1533 1533
     
1534
-    if ( wpinv_use_taxes() ) {
1534
+    if (wpinv_use_taxes()) {
1535 1535
         $default++;
1536 1536
     }
1537 1537
 
1538
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1538
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_display_cart_messages() {
1542 1542
     global $wpi_session;
1543 1543
 
1544
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1544
+    $messages = $wpi_session->get('wpinv_cart_messages');
1545 1545
 
1546
-    if ( $messages ) {
1547
-        foreach ( $messages as $message_id => $message ) {
1546
+    if ($messages) {
1547
+        foreach ($messages as $message_id => $message) {
1548 1548
             // Try and detect what type of message this is
1549
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1549
+            if (strpos(strtolower($message), 'error')) {
1550 1550
                 $type = 'error';
1551
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1551
+            } elseif (strpos(strtolower($message), 'success')) {
1552 1552
                 $type = 'success';
1553 1553
             } else {
1554 1554
                 $type = 'info';
1555 1555
             }
1556 1556
 
1557
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1557
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1558 1558
 
1559
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1559
+            echo '<div class="' . implode(' ', $classes) . '">';
1560 1560
                 // Loop message codes and display messages
1561 1561
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1562 1562
             echo '</div>';
1563 1563
         }
1564 1564
 
1565 1565
         // Remove all of the cart saving messages
1566
-        $wpi_session->set( 'wpinv_cart_messages', null );
1566
+        $wpi_session->set('wpinv_cart_messages', null);
1567 1567
     }
1568 1568
 }
1569
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1569
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1570 1570
 
1571 1571
 function wpinv_discount_field() {
1572
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1572
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1573 1573
         return; // Only show before a payment method has been selected if ajax is disabled
1574 1574
     }
1575 1575
 
1576
-    if ( !wpinv_is_checkout() ) {
1576
+    if (!wpinv_is_checkout()) {
1577 1577
         return;
1578 1578
     }
1579 1579
 
1580
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1580
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1581 1581
     ?>
1582 1582
     <div id="wpinv-discount-field" class="panel panel-default">
1583 1583
         <div class="panel-body">
1584 1584
             <p>
1585
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1586
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1585
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1586
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1587 1587
             </p>
1588 1588
             <div class="form-group row">
1589 1589
                 <div class="col-sm-4">
1590
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1590
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1591 1591
                 </div>
1592 1592
                 <div class="col-sm-3">
1593
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1593
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1594 1594
                 </div>
1595 1595
                 <div style="clear:both"></div>
1596 1596
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1603,10 +1603,10 @@  discard block
 block discarded – undo
1603 1603
 <?php
1604 1604
     }
1605 1605
 }
1606
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1606
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1607 1607
 
1608 1608
 function wpinv_agree_to_terms_js() {
1609
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1609
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1610 1610
 ?>
1611 1611
 <script type="text/javascript">
1612 1612
     jQuery(document).ready(function($){
@@ -1621,125 +1621,125 @@  discard block
 block discarded – undo
1621 1621
 <?php
1622 1622
     }
1623 1623
 }
1624
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1624
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1625 1625
 
1626 1626
 function wpinv_payment_mode_select() {
1627
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1628
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1629
-    $invoice = wpinv_get_invoice( 0, true );
1627
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1628
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1629
+    $invoice = wpinv_get_invoice(0, true);
1630 1630
 
1631 1631
     do_action('wpinv_payment_mode_top');
1632
-    $invoice_id = $invoice ? (int)$invoice->ID : 0;
1633
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1632
+    $invoice_id = $invoice ? (int) $invoice->ID : 0;
1633
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1634 1634
     ?>
1635
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( ( $invoice && $invoice->is_free() ) ? 'style="display:none;" data-free="1"' : '' ); ?>>
1636
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1635
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo (($invoice && $invoice->is_free()) ? 'style="display:none;" data-free="1"' : ''); ?>>
1636
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1637 1637
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1638
-                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1638
+                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1639 1639
                 <div class="panel-body list-group wpi-payment_methods">
1640 1640
                     <?php
1641
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1642
-
1643
-                    if ( !empty( $gateways ) ) {
1644
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1645
-                            $checked       = checked( $gateway_id, $chosen_gateway, false );
1646
-                            $button_label  = wpinv_get_gateway_button_label( $gateway_id );
1647
-                            $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id );
1648
-                            $description   = wpinv_get_gateway_description( $gateway_id );
1641
+                    do_action('wpinv_payment_mode_before_gateways');
1642
+
1643
+                    if (!empty($gateways)) {
1644
+                        foreach ($gateways as $gateway_id => $gateway) {
1645
+                            $checked       = checked($gateway_id, $chosen_gateway, false);
1646
+                            $button_label  = wpinv_get_gateway_button_label($gateway_id);
1647
+                            $gateway_label = wpinv_get_gateway_checkout_label($gateway_id);
1648
+                            $description   = wpinv_get_gateway_description($gateway_id);
1649 1649
                             ?>
1650 1650
                             <div class="list-group-item">
1651 1651
                                 <div class="radio">
1652
-                                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway_label ); ?></label>
1652
+                                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway_label); ?></label>
1653 1653
                                 </div>
1654
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1655
-                                    <?php if ( !empty( $description ) ) { ?>
1656
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1654
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1655
+                                    <?php if (!empty($description)) { ?>
1656
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1657 1657
                                     <?php } ?>
1658
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1658
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1659 1659
                                 </div>
1660 1660
                             </div>
1661 1661
                             <?php
1662 1662
                         }
1663 1663
                     } else {
1664
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1664
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1665 1665
                     }
1666 1666
 
1667
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1667
+                    do_action('wpinv_payment_mode_after_gateways');
1668 1668
                     ?>
1669 1669
                 </div>
1670 1670
             </div>
1671
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1671
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1672 1672
     </div>
1673 1673
     <?php
1674 1674
     do_action('wpinv_payment_mode_bottom');
1675 1675
 }
1676
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1676
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1677 1677
 
1678 1678
 function wpinv_checkout_billing_info() {
1679
-    if ( wpinv_is_checkout() ) {
1679
+    if (wpinv_is_checkout()) {
1680 1680
         $billing_details    = wpinv_checkout_billing_details();
1681
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1681
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1682 1682
         ?>
1683 1683
         <div id="wpinv-fields" class="clearfix">
1684 1684
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1685
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1685
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1686 1686
                 <div id="wpinv-fields-box" class="panel-body">
1687
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1687
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1688 1688
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1689
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1689
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1690 1690
                         <?php
1691
-                        echo wpinv_html_text( array(
1691
+                        echo wpinv_html_text(array(
1692 1692
                                 'id'            => 'wpinv_first_name',
1693 1693
                                 'name'          => 'wpinv_first_name',
1694 1694
                                 'value'         => $billing_details['first_name'],
1695 1695
                                 'class'         => 'wpi-input form-control',
1696
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1697
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1698
-                            ) );
1696
+                                'placeholder'   => __('First name', 'invoicing'),
1697
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1698
+                            ));
1699 1699
                         ?>
1700 1700
                     </p>
1701 1701
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1702
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1702
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1703 1703
                         <?php
1704
-                        echo wpinv_html_text( array(
1704
+                        echo wpinv_html_text(array(
1705 1705
                                 'id'            => 'wpinv_last_name',
1706 1706
                                 'name'          => 'wpinv_last_name',
1707 1707
                                 'value'         => $billing_details['last_name'],
1708 1708
                                 'class'         => 'wpi-input form-control',
1709
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1710
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1711
-                            ) );
1709
+                                'placeholder'   => __('Last name', 'invoicing'),
1710
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1711
+                            ));
1712 1712
                         ?>
1713 1713
                     </p>
1714 1714
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1715
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1715
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1716 1716
                         <?php
1717
-                        echo wpinv_html_text( array(
1717
+                        echo wpinv_html_text(array(
1718 1718
                                 'id'            => 'wpinv_address',
1719 1719
                                 'name'          => 'wpinv_address',
1720 1720
                                 'value'         => $billing_details['address'],
1721 1721
                                 'class'         => 'wpi-input form-control',
1722
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1723
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1724
-                            ) );
1722
+                                'placeholder'   => __('Address', 'invoicing'),
1723
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1724
+                            ));
1725 1725
                         ?>
1726 1726
                     </p>
1727 1727
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1728
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1728
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1729 1729
                         <?php
1730
-                        echo wpinv_html_text( array(
1730
+                        echo wpinv_html_text(array(
1731 1731
                                 'id'            => 'wpinv_city',
1732 1732
                                 'name'          => 'wpinv_city',
1733 1733
                                 'value'         => $billing_details['city'],
1734 1734
                                 'class'         => 'wpi-input form-control',
1735
-                                'placeholder'   => __( 'City', 'invoicing' ),
1736
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1737
-                            ) );
1735
+                                'placeholder'   => __('City', 'invoicing'),
1736
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1737
+                            ));
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
-                        <?php echo wpinv_html_select( array(
1741
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
+                        <?php echo wpinv_html_select(array(
1743 1743
                             'options'          => wpinv_get_country_list(),
1744 1744
                             'name'             => 'wpinv_country',
1745 1745
                             'id'               => 'wpinv_country',
@@ -1747,16 +1747,16 @@  discard block
 block discarded – undo
1747 1747
                             'show_option_all'  => false,
1748 1748
                             'show_option_none' => false,
1749 1749
                             'class'            => 'wpi-input form-control wpi_select2',
1750
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1751
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1752
-                        ) ); ?>
1750
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1751
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1752
+                        )); ?>
1753 1753
                     </p>
1754 1754
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1755
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1756 1756
                         <?php
1757
-                        $states = wpinv_get_country_states( $selected_country );
1758
-                        if( !empty( $states ) ) {
1759
-                            echo wpinv_html_select( array(
1757
+                        $states = wpinv_get_country_states($selected_country);
1758
+                        if (!empty($states)) {
1759
+                            echo wpinv_html_select(array(
1760 1760
                                 'options'          => $states,
1761 1761
                                 'name'             => 'wpinv_state',
1762 1762
                                 'id'               => 'wpinv_state',
@@ -1764,61 +1764,61 @@  discard block
 block discarded – undo
1764 1764
                                 'show_option_all'  => false,
1765 1765
                                 'show_option_none' => false,
1766 1766
                                 'class'            => 'wpi-input form-control wpi_select2',
1767
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1768
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1769
-                            ) );
1767
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1768
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1769
+                            ));
1770 1770
                         } else {
1771
-                            echo wpinv_html_text( array(
1771
+                            echo wpinv_html_text(array(
1772 1772
                                 'name'          => 'wpinv_state',
1773 1773
                                 'value'         => $billing_details['state'],
1774 1774
                                 'id'            => 'wpinv_state',
1775 1775
                                 'class'         => 'wpi-input form-control',
1776
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1777
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1778
-                            ) );
1776
+                                'placeholder'   => __('State / Province', 'invoicing'),
1777
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1778
+                            ));
1779 1779
                         }
1780 1780
                         ?>
1781 1781
                     </p>
1782 1782
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1783
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1783
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1784 1784
                         <?php
1785
-                        echo wpinv_html_text( array(
1785
+                        echo wpinv_html_text(array(
1786 1786
                                 'name'          => 'wpinv_zip',
1787 1787
                                 'value'         => $billing_details['zip'],
1788 1788
                                 'id'            => 'wpinv_zip',
1789 1789
                                 'class'         => 'wpi-input form-control',
1790
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1791
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1792
-                            ) );
1790
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1791
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1792
+                            ));
1793 1793
                         ?>
1794 1794
                     </p>
1795 1795
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1796
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1796
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1797 1797
                         <?php
1798
-                        echo wpinv_html_text( array(
1798
+                        echo wpinv_html_text(array(
1799 1799
                                 'id'            => 'wpinv_phone',
1800 1800
                                 'name'          => 'wpinv_phone',
1801 1801
                                 'value'         => $billing_details['phone'],
1802 1802
                                 'class'         => 'wpi-input form-control',
1803
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1804
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1805
-                            ) );
1803
+                                'placeholder'   => __('Phone', 'invoicing'),
1804
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1805
+                            ));
1806 1806
                         ?>
1807 1807
                     </p>
1808
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1808
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1809 1809
                     <div class="clearfix"></div>
1810 1810
                 </div>
1811 1811
             </div>
1812
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1812
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1813 1813
         </div>
1814 1814
         <?php
1815 1815
     }
1816 1816
 }
1817
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1817
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1818 1818
 
1819 1819
 function wpinv_checkout_hidden_fields() {
1820 1820
 ?>
1821
-    <?php if ( is_user_logged_in() ) { ?>
1821
+    <?php if (is_user_logged_in()) { ?>
1822 1822
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1823 1823
     <?php } ?>
1824 1824
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1828,9 +1828,9 @@  discard block
 block discarded – undo
1828 1828
 function wpinv_checkout_button_purchase() {
1829 1829
     ob_start();
1830 1830
 ?>
1831
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1831
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1832 1832
 <?php
1833
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1833
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1834 1834
 }
1835 1835
 
1836 1836
 function wpinv_checkout_total() {
@@ -1839,84 +1839,84 @@  discard block
 block discarded – undo
1839 1839
 <div id="wpinv_checkout_total" class="panel panel-info">
1840 1840
     <div class="panel-body">
1841 1841
     <?php
1842
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1842
+    do_action('wpinv_purchase_form_before_checkout_total');
1843 1843
     ?>
1844
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1844
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1845 1845
     <?php
1846
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1846
+    do_action('wpinv_purchase_form_after_checkout_total');
1847 1847
     ?>
1848 1848
     </div>
1849 1849
 </div>
1850 1850
 <?php
1851 1851
 }
1852
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1852
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1853 1853
 
1854 1854
 function wpinv_checkout_accept_tandc() {
1855
-    $page = wpinv_get_option( 'tandc_page' );
1855
+    $page = wpinv_get_option('tandc_page');
1856 1856
     ?>
1857 1857
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1858 1858
         <div class="panel-body">
1859 1859
             <?php echo wpinv_get_policy_text(); ?>
1860 1860
             <?php
1861
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1862
-                $terms_link = esc_url( get_permalink( $page ) );
1861
+            if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1862
+                $terms_link = esc_url(get_permalink($page));
1863 1863
                 ?>
1864 1864
                 <label class="">
1865
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1865
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1866 1866
                 </label>
1867 1867
             <?php } ?>
1868 1868
         </div>
1869 1869
     </div>
1870 1870
     <?php
1871 1871
 }
1872
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1872
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1873 1873
 
1874 1874
 function wpinv_checkout_submit() {
1875 1875
 ?>
1876 1876
 <div id="wpinv_purchase_submit" class="panel panel-success">
1877 1877
     <div class="panel-body text-center">
1878 1878
     <?php
1879
-    do_action( 'wpinv_purchase_form_before_submit' );
1879
+    do_action('wpinv_purchase_form_before_submit');
1880 1880
     wpinv_checkout_hidden_fields();
1881 1881
     echo wpinv_checkout_button_purchase();
1882
-    do_action( 'wpinv_purchase_form_after_submit' );
1882
+    do_action('wpinv_purchase_form_after_submit');
1883 1883
     ?>
1884 1884
     </div>
1885 1885
 </div>
1886 1886
 <?php
1887 1887
 }
1888
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1888
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1889 1889
 
1890
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1891
-    $invoice = wpinv_get_invoice( $invoice_id );
1890
+function wpinv_receipt_billing_address($invoice_id = 0) {
1891
+    $invoice = wpinv_get_invoice($invoice_id);
1892 1892
 
1893
-    if ( empty( $invoice ) ) {
1893
+    if (empty($invoice)) {
1894 1894
         return NULL;
1895 1895
     }
1896 1896
 
1897 1897
     $billing_details = $invoice->get_user_info();
1898
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1898
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1899 1899
 
1900 1900
     ob_start();
1901 1901
     ?>
1902 1902
     <table class="table table-bordered table-sm wpi-billing-details">
1903 1903
         <tbody>
1904 1904
             <tr class="wpi-receipt-name">
1905
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1906
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1905
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1906
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1907 1907
             </tr>
1908 1908
             <tr class="wpi-receipt-email">
1909
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1910
-                <td><?php echo $billing_details['email'] ;?></td>
1909
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1910
+                <td><?php echo $billing_details['email']; ?></td>
1911 1911
             </tr>
1912 1912
             <tr class="wpi-receipt-address">
1913
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1914
-                <td><?php echo $address_row ;?></td>
1913
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1914
+                <td><?php echo $address_row; ?></td>
1915 1915
             </tr>
1916
-            <?php if ( $billing_details['phone'] ) { ?>
1916
+            <?php if ($billing_details['phone']) { ?>
1917 1917
             <tr class="wpi-receipt-phone">
1918
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1919
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1918
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1919
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1920 1920
             </tr>
1921 1921
             <?php } ?>
1922 1922
         </tbody>
@@ -1924,74 +1924,74 @@  discard block
 block discarded – undo
1924 1924
     <?php
1925 1925
     $output = ob_get_clean();
1926 1926
     
1927
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1927
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1928 1928
 
1929 1929
     echo $output;
1930 1930
 }
1931 1931
 
1932
-function wpinv_filter_success_page_content( $content ) {
1933
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1934
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1935
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1932
+function wpinv_filter_success_page_content($content) {
1933
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1934
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1935
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1936 1936
         }
1937 1937
     }
1938 1938
 
1939 1939
     return $content;
1940 1940
 }
1941
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1941
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1942 1942
 
1943
-function wpinv_receipt_actions( $invoice ) {
1944
-    if ( !empty( $invoice ) ) {
1943
+function wpinv_receipt_actions($invoice) {
1944
+    if (!empty($invoice)) {
1945 1945
         $actions = array();
1946 1946
 
1947
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1948
-            $actions['print']   = array(
1949
-                'url'  => $invoice->get_view_url( true ),
1950
-                'name' => __( 'Print Invoice', 'invoicing' ),
1947
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1948
+            $actions['print'] = array(
1949
+                'url'  => $invoice->get_view_url(true),
1950
+                'name' => __('Print Invoice', 'invoicing'),
1951 1951
                 'class' => 'btn-primary',
1952 1952
             );
1953 1953
         }
1954 1954
 
1955
-        if ( is_user_logged_in() ) {
1955
+        if (is_user_logged_in()) {
1956 1956
             $actions['history'] = array(
1957 1957
                 'url'  => wpinv_get_history_page_uri(),
1958
-                'name' => __( 'Invoice History', 'invoicing' ),
1958
+                'name' => __('Invoice History', 'invoicing'),
1959 1959
                 'class' => 'btn-warning',
1960 1960
             );
1961 1961
         }
1962 1962
 
1963
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1963
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1964 1964
 
1965
-        if ( !empty( $actions ) ) {
1965
+        if (!empty($actions)) {
1966 1966
         ?>
1967 1967
         <div class="wpinv-receipt-actions text-right">
1968
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1969
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1968
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1969
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1970 1970
             <?php } ?>
1971 1971
         </div>
1972 1972
         <?php
1973 1973
         }
1974 1974
     }
1975 1975
 }
1976
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1976
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1977 1977
 
1978
-function wpinv_invoice_link( $invoice_id ) {
1979
-    $invoice = wpinv_get_invoice( $invoice_id );
1978
+function wpinv_invoice_link($invoice_id) {
1979
+    $invoice = wpinv_get_invoice($invoice_id);
1980 1980
 
1981
-    if ( empty( $invoice ) ) {
1981
+    if (empty($invoice)) {
1982 1982
         return NULL;
1983 1983
     }
1984 1984
 
1985
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1985
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1986 1986
 
1987
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1987
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1988 1988
 }
1989 1989
 
1990
-function wpinv_invoice_subscription_details( $invoice ) {
1991
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1992
-        $subscription = wpinv_get_subscription( $invoice, true );
1990
+function wpinv_invoice_subscription_details($invoice) {
1991
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1992
+        $subscription = wpinv_get_subscription($invoice, true);
1993 1993
 
1994
-        if ( empty( $subscription ) ) {
1994
+        if (empty($subscription)) {
1995 1995
             return;
1996 1996
         }
1997 1997
 
@@ -2002,15 +2002,15 @@  discard block
 block discarded – undo
2002 2002
         $payments = $subscription->get_child_payments();
2003 2003
         ?>
2004 2004
         <div class="wpinv-subscriptions-details">
2005
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
2010
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
2013
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
2009
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
2010
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
2012
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
2013
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
@@ -2024,29 +2024,29 @@  discard block
 block discarded – undo
2024 2024
                 </tbody>
2025 2025
             </table>
2026 2026
         </div>
2027
-        <?php if ( !empty( $payments ) ) { ?>
2027
+        <?php if (!empty($payments)) { ?>
2028 2028
         <div class="wpinv-renewal-payments">
2029
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2029
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2030 2030
             <table class="table">
2031 2031
                 <thead>
2032 2032
                     <tr>
2033 2033
                         <th>#</th>
2034
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2035
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2036
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2034
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2035
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2036
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2037 2037
                     </tr>
2038 2038
                 </thead>
2039 2039
                 <tbody>
2040 2040
                     <?php
2041 2041
                         $i = 1;
2042
-                        foreach ( $payments as $payment ) {
2042
+                        foreach ($payments as $payment) {
2043 2043
                             $invoice_id = $payment->ID;
2044 2044
                     ?>
2045 2045
                     <tr>
2046
-                        <th scope="row"><?php echo $i;?></th>
2047
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2048
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2049
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2046
+                        <th scope="row"><?php echo $i; ?></th>
2047
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2048
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2049
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2050 2050
                     </tr>
2051 2051
                     <?php $i++; } ?>
2052 2052
                 </tbody>
@@ -2057,52 +2057,52 @@  discard block
 block discarded – undo
2057 2057
     }
2058 2058
 }
2059 2059
 
2060
-function wpinv_cart_total_label( $label, $invoice ) {
2061
-    if ( empty( $invoice ) ) {
2060
+function wpinv_cart_total_label($label, $invoice) {
2061
+    if (empty($invoice)) {
2062 2062
         return $label;
2063 2063
     }
2064 2064
 
2065 2065
     $prefix_label = '';
2066
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2067
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2068
-    } else if ( $invoice->is_renewal() ) {
2069
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2066
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2067
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2068
+    } else if ($invoice->is_renewal()) {
2069
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2070 2070
     }
2071 2071
 
2072
-    if ( $prefix_label != '' ) {
2073
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2072
+    if ($prefix_label != '') {
2073
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2074 2074
     }
2075 2075
 
2076 2076
     return $label;
2077 2077
 }
2078
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2079
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2080
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2078
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2079
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2080
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2081 2081
 
2082
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2082
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2083 2083
 
2084
-function wpinv_invoice_print_description( $invoice ) {
2085
-    if ( empty( $invoice ) ) {
2084
+function wpinv_invoice_print_description($invoice) {
2085
+    if (empty($invoice)) {
2086 2086
         return NULL;
2087 2087
     }
2088
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2088
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2089 2089
         ?>
2090 2090
         <div class="row wpinv-lower">
2091 2091
             <div class="col-sm-12 wpinv-description">
2092
-                <?php echo wpautop( $description ); ?>
2092
+                <?php echo wpautop($description); ?>
2093 2093
             </div>
2094 2094
         </div>
2095 2095
         <?php
2096 2096
     }
2097 2097
 }
2098
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2098
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2099 2099
 
2100
-function wpinv_invoice_print_payment_info( $invoice ) {
2101
-    if ( empty( $invoice ) ) {
2100
+function wpinv_invoice_print_payment_info($invoice) {
2101
+    if (empty($invoice)) {
2102 2102
         return NULL;
2103 2103
     }
2104 2104
 
2105
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2105
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2106 2106
         ?>
2107 2107
         <div class="row wpinv-payments">
2108 2108
             <div class="col-sm-12">
@@ -2114,43 +2114,43 @@  discard block
 block discarded – undo
2114 2114
 }
2115 2115
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2116 2116
 
2117
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2118
-    if ( empty( $note ) ) {
2117
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2118
+    if (empty($note)) {
2119 2119
         return NULL;
2120 2120
     }
2121 2121
 
2122
-    if ( is_int( $note ) ) {
2123
-        $note = get_comment( $note );
2122
+    if (is_int($note)) {
2123
+        $note = get_comment($note);
2124 2124
     }
2125 2125
 
2126
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2126
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2127 2127
         return NULL;
2128 2128
     }
2129 2129
 
2130
-    $note_classes   = array( 'note' );
2131
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2130
+    $note_classes   = array('note');
2131
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2132 2132
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2133
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2134
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2133
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2134
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2135 2135
 
2136 2136
     ob_start();
2137 2137
     ?>
2138
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2138
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2139 2139
         <div class="note_content">
2140
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2140
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2141 2141
         </div>
2142 2142
         <p class="meta">
2143
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2144
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2145
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2143
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2144
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2145
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2146 2146
             <?php } ?>
2147 2147
         </p>
2148 2148
     </li>
2149 2149
     <?php
2150 2150
     $note_content = ob_get_clean();
2151
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2151
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2152 2152
 
2153
-    if ( $echo ) {
2153
+    if ($echo) {
2154 2154
         echo $note_content;
2155 2155
     } else {
2156 2156
         return $note_content;
@@ -2160,43 +2160,43 @@  discard block
 block discarded – undo
2160 2160
 function wpinv_invalid_invoice_content() {
2161 2161
     global $post;
2162 2162
 
2163
-    $invoice = wpinv_get_invoice( $post->ID );
2163
+    $invoice = wpinv_get_invoice($post->ID);
2164 2164
 
2165
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2166
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2167
-        if ( is_user_logged_in() ) {
2168
-            if ( wpinv_require_login_to_checkout() ) {
2169
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2170
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2165
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2166
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2167
+        if (is_user_logged_in()) {
2168
+            if (wpinv_require_login_to_checkout()) {
2169
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2170
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2171 2171
                 }
2172 2172
             }
2173 2173
         } else {
2174
-            if ( wpinv_require_login_to_checkout() ) {
2175
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2176
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2174
+            if (wpinv_require_login_to_checkout()) {
2175
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2176
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2177 2177
                 }
2178 2178
             }
2179 2179
         }
2180 2180
     } else {
2181
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2181
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2182 2182
     }
2183 2183
     ?>
2184 2184
     <div class="row wpinv-row-invalid">
2185 2185
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2186
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2186
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2187 2187
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2188 2188
         </div>
2189 2189
     </div>
2190 2190
     <?php
2191 2191
 }
2192
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2192
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2193 2193
 
2194
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
-function wpinv_force_company_name_field(){
2194
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
+function wpinv_force_company_name_field() {
2196 2196
     $invoice = wpinv_get_invoice_cart();
2197
-    $user_id = wpinv_get_user_id( $invoice->ID );
2198
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2199
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2197
+    $user_id = wpinv_get_user_id($invoice->ID);
2198
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2199
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2200 2200
         ?>
2201 2201
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2202 2202
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2222,21 +2222,21 @@  discard block
 block discarded – undo
2222 2222
  * @return string
2223 2223
  */
2224 2224
 function wpinv_get_policy_text() {
2225
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2225
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2226 2226
 
2227
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2227
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2228 2228
 
2229
-    if(!$privacy_page_id){
2230
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2229
+    if (!$privacy_page_id) {
2230
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2231 2231
     }
2232 2232
 
2233
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2233
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2234 2234
 
2235 2235
     $find_replace = array(
2236 2236
         '[wpinv_privacy_policy]' => $privacy_link,
2237 2237
     );
2238 2238
 
2239
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2239
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2240 2240
 
2241 2241
     return wp_kses_post(wpautop($privacy_text));
2242 2242
 }
@@ -2245,25 +2245,25 @@  discard block
 block discarded – undo
2245 2245
 /**
2246 2246
  * Allows the user to set their own price for an invoice item
2247 2247
  */
2248
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2248
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2249 2249
     
2250 2250
     //Ensure we have an item id
2251
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2251
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2252 2252
         return;
2253 2253
     }
2254 2254
 
2255 2255
     //Fetch the item
2256 2256
     $item_id = $cart_item['id'];
2257
-    $item    = new WPInv_Item( $item_id );
2257
+    $item    = new WPInv_Item($item_id);
2258 2258
     
2259
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2259
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2260 2260
         return;
2261 2261
     }
2262 2262
 
2263 2263
     //Fetch the dynamic pricing "strings"
2264
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2265
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2266
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2264
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2265
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2266
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2267 2267
 
2268 2268
     //Display a "name_your_price" button
2269 2269
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2272,7 +2272,7 @@  discard block
 block discarded – undo
2272 2272
     echo '<div class="name-your-price-miniform">';
2273 2273
     
2274 2274
     //Maybe display the recommended price
2275
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2275
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2276 2276
         $suggested_price = $item->get_the_price();
2277 2277
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2278 2278
     }
@@ -2280,50 +2280,50 @@  discard block
 block discarded – undo
2280 2280
     //Display the update price form
2281 2281
     $symbol         = wpinv_currency_symbol();
2282 2282
     $position       = wpinv_currency_position();
2283
-    $minimum        = esc_attr( $item->get_minimum_price() );
2284
-    $price          = esc_attr( $cart_item['item_price'] );
2285
-    $update         = esc_attr__( "Update", 'invoicing' );
2283
+    $minimum        = esc_attr($item->get_minimum_price());
2284
+    $price          = esc_attr($cart_item['item_price']);
2285
+    $update         = esc_attr__("Update", 'invoicing');
2286 2286
 
2287 2287
     //Ensure it supports dynamic prici
2288
-    if( $price < $minimum ) {
2288
+    if ($price < $minimum) {
2289 2289
         $price = $minimum;
2290 2290
     }
2291 2291
 
2292 2292
     echo '<label>';
2293 2293
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2294 2294
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2295
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2295
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2296 2296
     echo "</label>";
2297 2297
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2298 2298
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2299 2299
 
2300 2300
     //Maybe display the minimum price
2301
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2302
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2301
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2302
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2303 2303
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2304 2304
     }
2305 2305
 
2306 2306
     echo "</div>";
2307 2307
 
2308 2308
 }
2309
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2309
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2310 2310
 
2311 2311
 function wpinv_oxygen_fix_conflict() {
2312 2312
     global $ct_ignore_post_types;
2313 2313
 
2314
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2314
+    if (!is_array($ct_ignore_post_types)) {
2315 2315
         $ct_ignore_post_types = array();
2316 2316
     }
2317 2317
 
2318
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2318
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2319 2319
 
2320
-    foreach ( $post_types as $post_type ) {
2320
+    foreach ($post_types as $post_type) {
2321 2321
         $ct_ignore_post_types[] = $post_type;
2322 2322
 
2323 2323
         // Ignore post type
2324
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2324
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2325 2325
     }
2326 2326
 
2327
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2328
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2327
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2328
+    add_filter('template_include', 'wpinv_template', 999, 1);
2329 2329
 }
Please login to merge, or discard this patch.
widgets/payment-form.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 				'orderby'        => 'title',
23 23
 				'order'          => 'ASC',
24 24
 				'posts_per_page' => -1,
25
-				'post_status'    => array( 'publish' ),
25
+				'post_status'    => array('publish'),
26 26
 			)
27 27
 		);
28 28
 
29 29
 		$options = array(
30
-			'' => __('Select a Form','invoicing')
30
+			'' => __('Select a Form', 'invoicing')
31 31
 		);
32 32
 
33
-		foreach( $forms as $form ) {
34
-			$options[ $form->ID ] = $form->post_title;
33
+		foreach ($forms as $form) {
34
+			$options[$form->ID] = $form->post_title;
35 35
 		}
36 36
 
37 37
         $options = array(
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
             'block-keywords'=> "['invoicing','buy', 'buy item', 'pay', 'payment form']",
42 42
             'class_name'     => __CLASS__,
43 43
             'base_id'       => 'wpinv_payment_form',
44
-            'name'          => __('Invoicing > Payment Form','invoicing'),
44
+            'name'          => __('Invoicing > Payment Form', 'invoicing'),
45 45
             'widget_ops'    => array(
46 46
                 'classname'   => 'wpinv-payment-form-class bsui',
47
-                'description' => esc_html__('Displays a payment form.','invoicing'),
47
+                'description' => esc_html__('Displays a payment form.', 'invoicing'),
48 48
             ),
49 49
             'arguments'           => array(
50 50
                 'form'            => array(
51
-                    'title'       => __( 'Payment Form', 'invoicing' ),
52
-                    'desc'        => __( 'Select your payment form.', 'invoicing' ),
51
+                    'title'       => __('Payment Form', 'invoicing'),
52
+                    'desc'        => __('Select your payment form.', 'invoicing'),
53 53
 					'type'        => 'select',
54 54
 					'options'     =>  $options,
55 55
                     'desc_tip'    => true,
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         );
62 62
 
63 63
 
64
-        parent::__construct( $options );
64
+        parent::__construct($options);
65 65
     }
66 66
 
67 67
 	/**
@@ -73,43 +73,43 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return string
75 75
 	 */
76
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
76
+    public function output($args = array(), $widget_args = array(), $content = '') {
77 77
 		global $invoicing;
78 78
 
79 79
 		// Do we have a payment form?
80
-		if ( empty( $args['form'] ) ) {
80
+		if (empty($args['form'])) {
81 81
 			return aui()->alert(
82 82
 				array(
83 83
 					'type'    => 'warning',
84
-					'content' => __( 'No payment form selected', 'invoicing' ),
84
+					'content' => __('No payment form selected', 'invoicing'),
85 85
 				)
86 86
 			);
87 87
 
88 88
 		}
89 89
 
90 90
 		// If yes, ensure that it is published.
91
-		if ( 'publish' != get_post_status( $args['form'] ) ) {
91
+		if ('publish' != get_post_status($args['form'])) {
92 92
 			return aui()->alert(
93 93
 				array(
94 94
 					'type'    => 'warning',
95
-					'content' => __( 'This payment form is no longer active', 'invoicing' ),
95
+					'content' => __('This payment form is no longer active', 'invoicing'),
96 96
 				)
97 97
 			);
98 98
 		}
99 99
 
100 100
 		// Get the form elements and items.
101
-		$elements = $invoicing->form_elements->get_form_elements( $args['form'] );
102
-		$items    = $invoicing->form_elements->get_form_items( $args['form'] );
101
+		$elements = $invoicing->form_elements->get_form_elements($args['form']);
102
+		$items    = $invoicing->form_elements->get_form_items($args['form']);
103 103
 
104 104
 		ob_start();
105 105
 		echo "<form class='wpinv_payment_form'>";
106 106
 		echo "<input type='hidden' name='form_id' value='{$args['form']}'/>";
107
-		wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
108
-		wp_nonce_field( 'vat_validation', '_wpi_nonce' );
107
+		wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
108
+		wp_nonce_field('vat_validation', '_wpi_nonce');
109 109
 
110
-		foreach ( $elements as $element ) {
111
-			do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] );
112
-			do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] );
110
+		foreach ($elements as $element) {
111
+			do_action('wpinv_frontend_render_payment_form_element', $element, $items, $args['form']);
112
+			do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form']);
113 113
 		}
114 114
 
115 115
 		echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 		$content = ob_get_clean();
119 119
 		
120
-		return str_replace( 'sr-only', '', $content );
120
+		return str_replace('sr-only', '', $content);
121 121
 
122 122
     }
123 123
 
Please login to merge, or discard this patch.