Passed
Pull Request — master (#107)
by Kiran
03:57
created
includes/gateways/authorizenet.php 1 patch
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-8">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-8">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-2">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-8">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
     
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,174 +83,174 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
         
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
         
104 104
         $errors = wpinv_get_errors();
105 105
     
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
             
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
             
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
                 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
             
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
             
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
                 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
             
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
             
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
             
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
             
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
             
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
             
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
                 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
                     
173
-                    $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code );
173
+                    $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code);
174 174
                     
175
-                    wpinv_insert_payment_note( $invoice_id, $message );
175
+                    wpinv_insert_payment_note($invoice_id, $message);
176 176
                     
177
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
177
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
178 178
                     
179 179
                     wpinv_clear_errors();
180 180
                     wpinv_empty_cart();
181 181
                     
182
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
182
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
183 183
                 } else {
184
-                    if ( !empty( $response->response_reason_text ) ) {
185
-                        $error = __( $response->response_reason_text, 'invoicing' );
186
-                    } else if ( !empty( $response->error_message ) ) {
187
-                        $error = __( $response->error_message, 'invoicing' );
184
+                    if (!empty($response->response_reason_text)) {
185
+                        $error = __($response->response_reason_text, 'invoicing');
186
+                    } else if (!empty($response->error_message)) {
187
+                        $error = __($response->error_message, 'invoicing');
188 188
                     } else {
189
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
189
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
190 190
                     } 
191 191
                     
192
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
192
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
193 193
                     
194
-                    wpinv_set_error( 'payment_error', $error );
195
-                    wpinv_record_gateway_error( $error, $response );
196
-                    wpinv_insert_payment_note( $invoice_id, $error );
194
+                    wpinv_set_error('payment_error', $error);
195
+                    wpinv_record_gateway_error($error, $response);
196
+                    wpinv_insert_payment_note($invoice_id, $error);
197 197
                     
198
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
198
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
199 199
                 }
200
-            } catch ( AuthorizeNetException $e ) {
201
-                wpinv_set_error( 'request_error', $e->getMessage() );
202
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
203
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
200
+            } catch (AuthorizeNetException $e) {
201
+                wpinv_set_error('request_error', $e->getMessage());
202
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
203
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
204 204
             }
205 205
         } else {
206
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
206
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
         }
208 208
     } else {
209
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
210
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
209
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
210
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
211 211
     }
212 212
 }
213
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
213
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
214 214
 
215
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
216
-    if ( empty( $subscription_id ) ) {
215
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
216
+    if (empty($subscription_id)) {
217 217
         return false;
218 218
     }
219 219
     
220 220
     try {
221 221
         $authnetXML = wpinv_authorizenet_XML();
222
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
222
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
223 223
 
224 224
         return $authnetXML->isSuccessful();
225
-    } catch( Exception $e ) {
226
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
225
+    } catch (Exception $e) {
226
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
227 227
     }
228 228
     
229 229
     return false;
230 230
 }
231 231
 
232
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
233
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
234
-    if ( empty( $authorizenet_md5_hash ) ) {
232
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
233
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
234
+    if (empty($authorizenet_md5_hash)) {
235 235
         return true;
236 236
     }
237 237
     
238
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
238
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
239 239
     
240
-    return hash_equals( $compare_md5, $md5_hash );
240
+    return hash_equals($compare_md5, $md5_hash);
241 241
 }
242 242
 
243 243
 function wpinv_authorizenet_AIM() {
244
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
245
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
244
+    if (!class_exists('AuthorizeNetException')) {
245
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
246 246
     }
247 247
     
248
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
248
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
249 249
     
250
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
251
-        $authorizeAIM->setSandbox( true );
250
+    if (wpinv_is_test_mode('authorizenet')) {
251
+        $authorizeAIM->setSandbox(true);
252 252
     } else {
253
-        $authorizeAIM->setSandbox( false );
253
+        $authorizeAIM->setSandbox(false);
254 254
     }
255 255
     
256 256
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -259,164 +259,164 @@  discard block
 block discarded – undo
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_XML() {
262
-    if ( !class_exists( 'AuthnetXML' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
262
+    if (!class_exists('AuthnetXML')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
264 264
     }
265 265
     
266
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
266
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
267 267
     
268 268
     return $authnetXML;
269 269
 }
270 270
 
271
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
272
-    if ( empty( $response ) || empty( $invoice ) ) {
271
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
272
+    if (empty($response) || empty($invoice)) {
273 273
         return false;
274 274
     }
275 275
     
276
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
277
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
276
+    if ($invoice->is_recurring() && !empty($response->approved)) {
277
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
278 278
 
279
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
280
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
279
+        if (!empty($subscription) && $subscription->isSuccessful()) {
280
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
281 281
             
282
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
282
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
283 283
             
284
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
284
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
285 285
         } else {
286
-            if ( isset( $subscription->messages->message ) ) {
286
+            if (isset($subscription->messages->message)) {
287 287
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
288
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
288
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
289 289
             } else {
290
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
291
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
290
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
291
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
292 292
             }
293 293
             
294
-            wpinv_record_gateway_error( $error, $subscription );
294
+            wpinv_record_gateway_error($error, $subscription);
295 295
             
296
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
296
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
297 297
         }
298 298
     }
299 299
 }
300
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
300
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
301 301
 
302
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
303
-    if ( empty( $invoice ) ) {
302
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
303
+    if (empty($invoice)) {
304 304
         return false;
305 305
     }
306 306
     
307
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
307
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
308 308
     
309 309
     try {
310 310
         $authnetXML = wpinv_authorizenet_XML();
311
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
312
-    } catch( Exception $e ) {
311
+        $authnetXML->ARBCreateSubscriptionRequest($params);
312
+    } catch (Exception $e) {
313 313
         $authnetXML = array();
314
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
314
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
315 315
     }
316 316
     
317 317
     return $authnetXML;
318 318
 }
319 319
 
320
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
321
-    if ( empty( $invoice ) ) {
320
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
321
+    if (empty($invoice)) {
322 322
         return false;
323 323
     }
324 324
     
325
-    $subscription_item = $invoice->get_recurring( true );
326
-    if ( empty( $subscription_item ) ) {
325
+    $subscription_item = $invoice->get_recurring(true);
326
+    if (empty($subscription_item)) {
327 327
         return false;
328 328
     }
329 329
     
330
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
330
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
331 331
     $subscription_name  = $invoice->get_subscription_name();
332
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
333
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
332
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
333
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
334 334
     $interval           = $subscription_item->get_recurring_interval();
335 335
     $period             = $subscription_item->get_recurring_period();
336 336
     $bill_times         = (int)$subscription_item->get_recurring_limit();
337 337
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
338 338
     
339
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
339
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
340 340
     $interval           = $time_period['interval'];
341 341
     $period             = $time_period['period'];
342 342
     
343 343
     $current_tz = date_default_timezone_get();
344
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
-    $today = date( 'Y-m-d' );
346
-    date_default_timezone_set( $current_tz );
344
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
+    $today = date('Y-m-d');
346
+    date_default_timezone_set($current_tz);
347 347
     
348 348
     $free_trial = $invoice->is_free_trial();
349
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
349
+    if ($free_trial && $subscription_item->has_free_trial()) {
350 350
         $trial_interval    = $subscription_item->get_trial_interval();
351
-        $trial_period      = $subscription_item->get_trial_period( true );
351
+        $trial_period      = $subscription_item->get_trial_period(true);
352 352
     }
353 353
     
354 354
     $subscription = array();
355 355
     $subscription['name'] = $subscription_name;
356 356
     
357 357
     $subscription['paymentSchedule'] = array(
358
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
358
+        'interval'         => array('length' => $interval, 'unit' => $period),
359 359
         'startDate'        => $today,
360 360
         'totalOccurrences' => $bill_times,
361
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
361
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
362 362
     );
363 363
     
364 364
     $subscription['amount'] = $recurring_amount;
365 365
     $subscription['trialAmount'] = $initial_amount;
366
-    $subscription['payment'] = array( 'creditCard' => $card_details );
367
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
368
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
366
+    $subscription['payment'] = array('creditCard' => $card_details);
367
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
368
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
369 369
     
370 370
     $subscription['billTo'] = array(
371 371
         'firstName' => $invoice->get_first_name(),
372 372
         'lastName'  => $invoice->get_last_name(),
373 373
         'company'   => $invoice->company,
374
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
374
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
375 375
         'city'      => $invoice->city,
376 376
         'state'     => $invoice->state,
377 377
         'zip'       => $invoice->zip,
378 378
         'country'   => $invoice->country,
379 379
     );
380 380
     
381
-    $params = array( 'subscription' => $subscription );
381
+    $params = array('subscription' => $subscription);
382 382
     
383
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
383
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
384 384
 }
385 385
 
386
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
387
-    $card_defaults      = array(
386
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
387
+    $card_defaults = array(
388 388
         'cc_owner'          => null,
389 389
         'cc_number'         => null,
390 390
         'cc_expire_month'   => null,
391 391
         'cc_expire_year'    => null,
392 392
         'cc_cvv2'           => null,
393 393
     );
394
-    $card_info = wp_parse_args( $card_info, $card_defaults );
394
+    $card_info = wp_parse_args($card_info, $card_defaults);
395 395
         
396 396
     $card_details = array(
397
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
398
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
399
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
397
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
398
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
399
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
400 400
     );
401 401
 
402 402
     return $card_details;
403 403
 }
404 404
 
405
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
406
-    if ( empty( $invoice ) || empty( $subscription ) ) {
405
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
406
+    if (empty($invoice) || empty($subscription)) {
407 407
         return false;
408 408
     }
409 409
     
410
-    $subscription_item = $invoice->get_recurring( true );
411
-    if ( empty( $subscription_item ) ) {
410
+    $subscription_item = $invoice->get_recurring(true);
411
+    if (empty($subscription_item)) {
412 412
         return false;
413 413
     }
414 414
     
415 415
     $invoice_id         = $invoice->ID;
416 416
     $subscriptionId     = (array)$subscription->subscriptionId;
417
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
417
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
418 418
 
419
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
419
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
420 420
     
421 421
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
422 422
     
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         'profile_id'        => $subscription_id,
425 425
         'item_id'           => $subscription_item->ID,
426 426
         'initial_amount'    => $invoice->get_total(),
427
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
427
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
428 428
         'period'            => $subscription_item->get_recurring_period(),
429 429
         'interval'          => $subscription_item->get_recurring_interval(),
430 430
         'bill_times'        => $subscription_item->get_recurring_limit(),
431
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
431
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
432 432
         'status'            => $status,
433
-        'created'           => current_time( 'mysql', 0 )
433
+        'created'           => current_time('mysql', 0)
434 434
     );
435 435
     
436
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
436
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
437 437
         $args['trial_period']      = $subscription_item->get_trial_period();
438 438
         $args['trial_interval']    = $subscription_item->get_trial_interval();
439 439
     } else {
@@ -441,58 +441,58 @@  discard block
 block discarded – undo
441 441
         $args['trial_interval']    = 0;
442 442
     }
443 443
     
444
-    return $invoice->update_subscription( $args );
444
+    return $invoice->update_subscription($args);
445 445
 }
446 446
 
447
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
448
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
447
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
448
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
449 449
         $error = false;
450 450
         
451
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
451
+        if (empty($post['authorizenet']['cc_owner'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
453
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
455
+        if (empty($post['authorizenet']['cc_number'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
457
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_month'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
461
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
463
+        if (empty($post['authorizenet']['cc_expire_year'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
465
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
466 466
         }
467
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
467
+        if (empty($post['authorizenet']['cc_cvv2'])) {
468 468
             $error = true;
469
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
469
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
470 470
         }
471 471
         
472
-        if ( $error ) {
472
+        if ($error) {
473 473
             return;
474 474
         }
475 475
         
476 476
         $invoice = wpinv_get_invoice_cart();
477 477
         
478
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
479
-            $subscription_item = $invoice->get_recurring( true );
478
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
479
+            $subscription_item = $invoice->get_recurring(true);
480 480
             
481 481
             $interval   = $subscription_item->get_recurring_interval();
482 482
             $period     = $subscription_item->get_recurring_period();
483 483
             
484
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
485
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
484
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
485
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
486 486
             }
487 487
         }
488 488
     }
489 489
 }
490
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
490
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
491 491
 
492
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
493
-    $subscription_interval = absint( $subscription_interval );
492
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
493
+    $subscription_interval = absint($subscription_interval);
494 494
 
495
-    switch( $subscription_period ) {
495
+    switch ($subscription_period) {
496 496
         case 'W':
497 497
         case 'week':
498 498
         case 'weeks':
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
         case 'M':
503 503
         case 'month':
504 504
         case 'months':
505
-            if ( $subscription_interval > 12 ) {
505
+            if ($subscription_interval > 12) {
506 506
                 $subscription_interval = 12;
507 507
             }
508 508
             
509 509
             $interval = $subscription_interval;
510 510
             $period   = 'months';
511 511
             
512
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
512
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
513 513
                 $interval = $subscription_interval * 30;
514 514
                 $period   = 'days';
515 515
             }
@@ -526,40 +526,40 @@  discard block
 block discarded – undo
526 526
             break;
527 527
     }
528 528
 
529
-    return compact( 'interval', 'period' );
529
+    return compact('interval', 'period');
530 530
 }
531 531
 
532 532
 function wpinv_authorizenet_process_ipn() {
533
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
533
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
534 534
         return;
535 535
     }
536 536
     
537
-    $subscription_id = intval( $_POST['x_subscription_id'] );
537
+    $subscription_id = intval($_POST['x_subscription_id']);
538 538
     
539
-    if ( $subscription_id ) {
540
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
541
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
542
-        $response_code  = intval( $_POST['x_response_code'] );
543
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
539
+    if ($subscription_id) {
540
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
541
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
542
+        $response_code  = intval($_POST['x_response_code']);
543
+        $reason_code    = intval($_POST['x_response_reason_code']);
544 544
 
545
-        if ( 1 == $response_code ) {
545
+        if (1 == $response_code) {
546 546
             // Approved
547
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
548
-        } else if ( 2 == $response_code ) {
547
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
548
+        } else if (2 == $response_code) {
549 549
             // Declined
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
552
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
552
+        } else if (3 == $response_code || 8 == $reason_code) {
553 553
             // An expired card
554
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
554
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
556 556
 
557 557
         } else {
558 558
             // Other Error
559
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
559
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
560 560
         }
561 561
         
562 562
         exit;
563 563
     }
564 564
 }
565
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
566 565
\ No newline at end of file
566
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
567 567
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-api.php 1 patch
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -7,51 +7,51 @@  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_API {
15 15
     protected $post_type = 'wpi_invoice';
16 16
     
17
-    public function __construct( $params = array() ) {
17
+    public function __construct($params = array()) {
18 18
     }
19
-    public function insert_invoice( $data ) {
19
+    public function insert_invoice($data) {
20 20
         global $wpdb;
21 21
         //wpinv_transaction_query( 'start' );
22 22
 
23 23
         try {
24
-            if ( empty( $data['invoice'] ) ) {
25
-                throw new WPInv_API_Exception( 'wpinv_api_missing_invoice_data', sprintf( __( 'No %1$s data specified to create %1$s', 'invoicing' ), 'invoice' ), 400 );
24
+            if (empty($data['invoice'])) {
25
+                throw new WPInv_API_Exception('wpinv_api_missing_invoice_data', sprintf(__('No %1$s data specified to create %1$s', 'invoicing'), 'invoice'), 400);
26 26
             }
27 27
 
28
-            $data = apply_filters( 'wpinv_api_create_invoice_data', $data['invoice'], $this );
28
+            $data = apply_filters('wpinv_api_create_invoice_data', $data['invoice'], $this);
29 29
 
30
-            $invoice = wpinv_insert_invoice( $data, true );
31
-            if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
32
-                throw new WPInv_API_Exception( 'wpinv_api_cannot_create_invoice', sprintf( __( 'Cannot create invoice: %s', 'invoicing' ), implode( ', ', $invoice->get_error_messages() ) ), 400 );
30
+            $invoice = wpinv_insert_invoice($data, true);
31
+            if (empty($invoice->ID) || is_wp_error($invoice)) {
32
+                throw new WPInv_API_Exception('wpinv_api_cannot_create_invoice', sprintf(__('Cannot create invoice: %s', 'invoicing'), implode(', ', $invoice->get_error_messages())), 400);
33 33
             }
34 34
 
35 35
             // HTTP 201 Created
36
-            $this->send_status( 201 );
36
+            $this->send_status(201);
37 37
 
38
-            do_action( 'wpinv_api_create_invoice', $invoice->ID, $data, $this );
38
+            do_action('wpinv_api_create_invoice', $invoice->ID, $data, $this);
39 39
 
40 40
             //wpinv_transaction_query( 'commit' );
41 41
 
42
-            return wpinv_get_invoice( $invoice->ID );
43
-        } catch ( WPInv_API_Exception $e ) {
42
+            return wpinv_get_invoice($invoice->ID);
43
+        } catch (WPInv_API_Exception $e) {
44 44
             //wpinv_transaction_query( 'rollback' );
45 45
 
46
-            return new WP_Error( $e->getErrorCode(), $e->getMessage(), array( 'status' => $e->getCode() ) );
46
+            return new WP_Error($e->getErrorCode(), $e->getMessage(), array('status' => $e->getCode()));
47 47
         }
48 48
     }
49 49
     
50
-    public function send_status( $code ) {
51
-        status_header( $code );
50
+    public function send_status($code) {
51
+        status_header($code);
52 52
     }
53 53
     
54
-    protected function set_billing_details( $invoice, $data ) {
54
+    protected function set_billing_details($invoice, $data) {
55 55
         $address_fields = array(
56 56
             'user_id',
57 57
             'first_name',
@@ -70,66 +70,66 @@  discard block
 block discarded – undo
70 70
         $billing_details = array();
71 71
         $user_id = $invoice->get_user_id();
72 72
         
73
-        foreach ( $address_fields as $field ) {
74
-            if ( isset( $data['billing_details'][ $field ] ) ) {
75
-                $value = sanitize_text_field( $data['billing_details'][ $field ] );
73
+        foreach ($address_fields as $field) {
74
+            if (isset($data['billing_details'][$field])) {
75
+                $value = sanitize_text_field($data['billing_details'][$field]);
76 76
                 
77
-                if ( $field == 'country' && empty( $value ) ) {
78
-                    if ( !empty( $invoice->country ) ) {
77
+                if ($field == 'country' && empty($value)) {
78
+                    if (!empty($invoice->country)) {
79 79
                         $value = $invoice->country;
80 80
                     } else {
81
-                        $value = wpinv_default_billing_country( '', $user_id );
81
+                        $value = wpinv_default_billing_country('', $user_id);
82 82
                     }
83 83
                 }
84 84
                 
85
-                if ( $field == 'state' && empty( $value ) ) {
86
-                    if ( !empty( $invoice->state ) ) {
85
+                if ($field == 'state' && empty($value)) {
86
+                    if (!empty($invoice->state)) {
87 87
                         $value = $invoice->state;
88 88
                     } else {
89 89
                         $value = wpinv_get_default_state();
90 90
                     }
91 91
                 }
92 92
                 
93
-                $invoice->set( $field, $value );
93
+                $invoice->set($field, $value);
94 94
                 
95
-                update_post_meta( $invoice->ID, '_wpinv_' . $field, $value );
95
+                update_post_meta($invoice->ID, '_wpinv_' . $field, $value);
96 96
             }
97 97
         }
98 98
         
99 99
         return $invoice;
100 100
     }
101 101
     
102
-    protected function set_discount( $invoice, $data ) {
103
-        if ( isset( $data['discount'] ) ) {
104
-            $invoice->set( 'discount', wpinv_round_amount( $data['discount'] ) );
102
+    protected function set_discount($invoice, $data) {
103
+        if (isset($data['discount'])) {
104
+            $invoice->set('discount', wpinv_round_amount($data['discount']));
105 105
             
106
-            update_post_meta( $invoice->ID, '_wpinv_discount', wpinv_round_amount( $data['discount'] ) );
106
+            update_post_meta($invoice->ID, '_wpinv_discount', wpinv_round_amount($data['discount']));
107 107
             
108
-            if ( isset( $data['discount_code'] ) ) {
109
-                $invoice->set( 'discount_code', $data['discount_code'] );
108
+            if (isset($data['discount_code'])) {
109
+                $invoice->set('discount_code', $data['discount_code']);
110 110
                 
111
-                update_post_meta( $invoice->ID, '_wpinv_discount_code', $data['discount_code'] );
111
+                update_post_meta($invoice->ID, '_wpinv_discount_code', $data['discount_code']);
112 112
             }
113 113
         }
114 114
         
115 115
         return $invoice;
116 116
     }
117 117
     
118
-    protected function set_items( $invoice, $data ) {
119
-        if ( !empty( $data['items'] ) && is_array( $data['items'] ) ) {
118
+    protected function set_items($invoice, $data) {
119
+        if (!empty($data['items']) && is_array($data['items'])) {
120 120
             $items_array = array();
121 121
            
122
-            if ( !empty( $invoice->country ) ) {
122
+            if (!empty($invoice->country)) {
123 123
                 $country = $invoice->country;
124
-            } else if ( !empty( $data['billing_details']['country'] ) ) {
124
+            } else if (!empty($data['billing_details']['country'])) {
125 125
                 $country = $data['billing_details']['country'];
126 126
             } else {
127
-                $country = wpinv_default_billing_country( '', $invoice->get_user_id() );
127
+                $country = wpinv_default_billing_country('', $invoice->get_user_id());
128 128
             }
129 129
             
130
-            if ( !empty( $invoice->state ) ) {
130
+            if (!empty($invoice->state)) {
131 131
                 $state = $invoice->state;
132
-            } else if ( !empty( $data['billing_details']['state'] ) ) {
132
+            } else if (!empty($data['billing_details']['state'])) {
133 133
                 $state = $data['billing_details']['state'];
134 134
             } else {
135 135
                 $state = wpinv_get_default_state();
@@ -138,54 +138,54 @@  discard block
 block discarded – undo
138 138
             $_POST['country']   = $country;
139 139
             $_POST['state']     = $state;
140 140
             
141
-            $rate = wpinv_get_tax_rate( $country, $state, 'global' );
141
+            $rate = wpinv_get_tax_rate($country, $state, 'global');
142 142
             
143 143
             $total_tax = 0;
144
-            foreach ( $data['items'] as $item ) {
145
-                $id                 = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
146
-                $title              = isset( $item['title'] ) ? sanitize_text_field( $item['title'] ) : '';
147
-                $desc               = isset( $item['description'] ) ? sanitize_text_field( $item['description'] ) : '';
148
-                $amount             = isset( $item['amount'] ) ? wpinv_round_amount( $item['amount'] ) : 0;
144
+            foreach ($data['items'] as $item) {
145
+                $id                 = isset($item['id']) ? sanitize_text_field($item['id']) : '';
146
+                $title              = isset($item['title']) ? sanitize_text_field($item['title']) : '';
147
+                $desc               = isset($item['description']) ? sanitize_text_field($item['description']) : '';
148
+                $amount             = isset($item['amount']) ? wpinv_round_amount($item['amount']) : 0;
149 149
                 
150
-                if ( !empty( $item['vat_rates_class'] ) ) {
150
+                if (!empty($item['vat_rates_class'])) {
151 151
                     $vat_rates_class = $item['vat_rates_class'];
152 152
                 } else {
153 153
                     $vat_rates_class = '_standard';
154 154
                 }
155
-                $vat_rate = wpinv_get_tax_rate( $country, $state, $id );
155
+                $vat_rate = wpinv_get_tax_rate($country, $state, $id);
156 156
                 
157
-                $tax = $amount > 0 ? ( $amount * 0.01 * (float)$vat_rate ) : 0;
157
+                $tax = $amount > 0 ? ($amount * 0.01 * (float)$vat_rate) : 0;
158 158
                 $total_tax += $tax;
159 159
                 
160 160
                 $items_array[] = array(
161 161
                     'id'                => $id,
162
-                    'title'             => esc_html( $title ),
163
-                    'description'       => esc_html( $desc ),
164
-                    'amount'            => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
165
-                    'subtotal'          => $amount > 0 ? wpinv_round_amount( $amount ) : 0,
162
+                    'title'             => esc_html($title),
163
+                    'description'       => esc_html($desc),
164
+                    'amount'            => $amount > 0 ? wpinv_round_amount($amount) : 0,
165
+                    'subtotal'          => $amount > 0 ? wpinv_round_amount($amount) : 0,
166 166
                     'vat_rates_class'   => $vat_rates_class,
167 167
                     'vat_rate'          => $vat_rate,
168
-                    'tax'               => $tax > 0 ? wpinv_round_amount( $tax ) : 0,
168
+                    'tax'               => $tax > 0 ? wpinv_round_amount($tax) : 0,
169 169
                 );
170 170
             }
171 171
 
172
-            update_post_meta( $invoice->ID, '_wpinv_tax', wpinv_round_amount( $total_tax ) );
173
-            $invoice->set( 'tax', wpinv_round_amount( $total_tax ) );
172
+            update_post_meta($invoice->ID, '_wpinv_tax', wpinv_round_amount($total_tax));
173
+            $invoice->set('tax', wpinv_round_amount($total_tax));
174 174
             
175
-            $items_array = apply_filters( 'wpinv_save_invoice_items', $items_array, $data['items'], $invoice );
175
+            $items_array = apply_filters('wpinv_save_invoice_items', $items_array, $data['items'], $invoice);
176 176
             
177
-            $invoice->set( 'items', $items_array );
178
-            update_post_meta( $invoice->ID, '_wpinv_items', $items_array );
177
+            $invoice->set('items', $items_array);
178
+            update_post_meta($invoice->ID, '_wpinv_items', $items_array);
179 179
         }
180 180
         
181 181
         return $invoice;
182 182
     }
183 183
     
184
-    protected function set_invoice_meta( $invoice_id, $invoice_meta ) {
185
-        foreach ( $invoice_meta as $meta_key => $meta_value ) {
184
+    protected function set_invoice_meta($invoice_id, $invoice_meta) {
185
+        foreach ($invoice_meta as $meta_key => $meta_value) {
186 186
 
187
-            if ( is_string( $meta_key) && ! is_protected_meta( $meta_key ) && is_scalar( $meta_value ) ) {
188
-                update_post_meta( $invoice_id, $meta_key, $meta_value );
187
+            if (is_string($meta_key) && !is_protected_meta($meta_key) && is_scalar($meta_value)) {
188
+                update_post_meta($invoice_id, $meta_key, $meta_value);
189 189
             }
190 190
         }
191 191
     }
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 class WPInv_API_Exception extends Exception {
196 196
     protected $error_code;
197 197
 
198
-    public function __construct( $error_code, $error_message, $http_status_code ) {
198
+    public function __construct($error_code, $error_message, $http_status_code) {
199 199
         $this->error_code = $error_code;
200
-        parent::__construct( $error_message, $http_status_code );
200
+        parent::__construct($error_message, $http_status_code);
201 201
     }
202 202
 
203 203
     public function getErrorCode() {
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
@@ -90,97 +90,97 @@  discard block
 block discarded – undo
90 90
     
91 91
     public function export() {
92 92
         $statuses = wpinv_get_invoice_statuses();
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => '',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,35 +415,35 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         }
421 421
 
422
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
422
+        if (!empty($this->from_date) || !empty($this->to_date)) {
423 423
             $args['date_query'] = array(
424 424
                 array(
425
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
426
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
425
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
426
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
427 427
                     'inclusive' => true
428 428
                 )
429 429
             );
430 430
         }
431 431
 
432
-        $invoices = wpinv_get_invoices( $args );
432
+        $invoices = wpinv_get_invoices($args);
433 433
         
434 434
         $data = array();
435 435
         
436
-        if ( !empty( $invoices ) ) {
437
-            foreach ( $invoices as $invoice ) {
436
+        if (!empty($invoices)) {
437
+            foreach ($invoices as $invoice) {
438 438
                 $row = array(
439 439
                     'id'            => $invoice->ID,
440 440
                     'number'        => $invoice->get_number(),
441
-                    'date'          => $invoice->get_invoice_date( false ),
442
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
443
-                    'status_nicename' => $invoice->get_status( true ),
441
+                    'date'          => $invoice->get_invoice_date(false),
442
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
443
+                    'status_nicename' => $invoice->get_status(true),
444 444
                     'status'        => $invoice->get_status(),
445
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
446
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
445
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
446
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
447 447
                     'user_id'       => $invoice->get_user_id(),
448 448
                     'email'         => $invoice->get_email(),
449 449
                     'first_name'    => $invoice->get_first_name(),
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
                     'due_date'      => $invoice->needs_payment() ? $invoice->get_due_date() : '',
465 465
                 );
466 466
                 
467
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
467
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
468 468
             }
469 469
 
470 470
             return $data;
@@ -480,29 +480,29 @@  discard block
 block discarded – undo
480 480
             'return'   => 'ids',
481 481
         );
482 482
         
483
-        if ( $this->status != 'any' ) {
483
+        if ($this->status != 'any') {
484 484
             $args['status'] = $this->status;
485 485
         }
486 486
 
487
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
487
+        if (!empty($this->from_date) || !empty($this->to_date)) {
488 488
             $args['date_query'] = array(
489 489
                 array(
490
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
491
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
490
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
491
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
492 492
                     'inclusive' => true
493 493
                 )
494 494
             );
495 495
         }
496 496
 
497
-        $invoices   = wpinv_get_invoices( $args );
498
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
497
+        $invoices   = wpinv_get_invoices($args);
498
+        $total      = !empty($invoices) ? count($invoices) : 0;
499 499
         $status     = 100;
500 500
 
501
-        if ( $total > 0 ) {
502
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
501
+        if ($total > 0) {
502
+            $status = (($this->per_page * $this->step) / $total) * 100;
503 503
         }
504 504
 
505
-        if ( $status > 100 ) {
505
+        if ($status > 100) {
506 506
             $status = 100;
507 507
         }
508 508
 
Please login to merge, or discard this patch.
templates/emails/wpinv-email-user_note.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 
8
-do_action( 'wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
8
+do_action('wpinv_email_before_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
9 9
 
10
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
10
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
11 11
 
12
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note );
16
+do_action('wpinv_email_after_note_details', $invoice, $email_type, $sent_to_admin, $customer_note);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-notes.php 1 patch
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -14,73 +14,73 @@  discard block
 block discarded – undo
14 14
     }
15 15
     
16 16
     public function init() {
17
-        do_action( 'wpinv_class_notes_init', $this );
17
+        do_action('wpinv_class_notes_init', $this);
18 18
     }
19 19
     
20 20
     public function includes() {
21
-        do_action( 'wpinv_class_notes_includes', $this );
21
+        do_action('wpinv_class_notes_includes', $this);
22 22
     }
23 23
     
24 24
     public function actions() {
25 25
         // Secure inovice notes
26
-        add_action( 'pre_get_comments', array( $this, 'set_invoice_note_type' ), 11, 1 );
26
+        add_action('pre_get_comments', array($this, 'set_invoice_note_type'), 11, 1);
27 27
         
28 28
         // Count comments
29
-        add_filter( 'wp_count_comments', array( $this, 'wp_count_comments' ), 11, 2 );
29
+        add_filter('wp_count_comments', array($this, 'wp_count_comments'), 11, 2);
30 30
         
31 31
         // Delete comments count cache whenever there is a new comment or a comment status changes
32
-        add_action( 'wp_insert_comment', array( $this, 'delete_comments_count_cache' ) );
33
-        add_action( 'wp_set_comment_status', array( $this, 'delete_comments_count_cache' ) );
32
+        add_action('wp_insert_comment', array($this, 'delete_comments_count_cache'));
33
+        add_action('wp_set_comment_status', array($this, 'delete_comments_count_cache'));
34 34
         
35
-        do_action( 'wpinv_class_notes_actions', $this );
35
+        do_action('wpinv_class_notes_actions', $this);
36 36
     }
37 37
         
38
-    public function set_invoice_note_type( $query ) {
39
-        $post_ID        = !empty( $query->query_vars['post_ID'] ) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
38
+    public function set_invoice_note_type($query) {
39
+        $post_ID = !empty($query->query_vars['post_ID']) ? $query->query_vars['post_ID'] : $query->query_vars['post_id'];
40 40
         
41
-        if ( $post_ID && in_array(get_post_type( $post_ID ), array($this->invoice_post_type, 'wpi_quote' )) ) {
41
+        if ($post_ID && in_array(get_post_type($post_ID), array($this->invoice_post_type, 'wpi_quote'))) {
42 42
             $query->query_vars['type__in']      = $this->comment_type;
43 43
             $query->query_vars['type__not_in']  = '';
44 44
         } else {        
45
-            if ( isset( $query->query_vars['type__in'] ) && $type_in = $query->query_vars['type__in'] ) {
46
-                if ( is_array( $type_in ) && in_array( $this->comment_type, $type_in ) ) {
47
-                    $key = array_search( $this->comment_type, $type_in );
48
-                    unset( $query->query_vars['type__in'][$key] );
49
-                } else if ( !is_array( $type_in ) && $type_in == $this->comment_type ) {
45
+            if (isset($query->query_vars['type__in']) && $type_in = $query->query_vars['type__in']) {
46
+                if (is_array($type_in) && in_array($this->comment_type, $type_in)) {
47
+                    $key = array_search($this->comment_type, $type_in);
48
+                    unset($query->query_vars['type__in'][$key]);
49
+                } else if (!is_array($type_in) && $type_in == $this->comment_type) {
50 50
                     $query->query_vars['type__in'] = '';
51 51
                 }
52 52
             }
53 53
             
54
-            if ( isset( $query->query_vars['type__not_in'] ) && $type_not_in = $query->query_vars['type__not_in'] ) {
55
-                if ( is_array( $type_not_in ) && !in_array( $this->comment_type, $type_not_in ) ) {
54
+            if (isset($query->query_vars['type__not_in']) && $type_not_in = $query->query_vars['type__not_in']) {
55
+                if (is_array($type_not_in) && !in_array($this->comment_type, $type_not_in)) {
56 56
                     $query->query_vars['type__not_in'][] = $this->comment_type;
57
-                } else if ( !is_array( $type_not_in ) && $type_not_in != $this->comment_type ) {
57
+                } else if (!is_array($type_not_in) && $type_not_in != $this->comment_type) {
58 58
                     $query->query_vars['type__not_in'] = (array)$query->query_vars['type__not_in'];
59 59
                     $query->query_vars['type__not_in'][] = $this->comment_type;
60 60
                 }
61 61
             } else {
62
-                $query->query_vars['type__not_in']  = $this->comment_type;
62
+                $query->query_vars['type__not_in'] = $this->comment_type;
63 63
             }
64 64
         }
65 65
         
66 66
         return $query;
67 67
     }
68 68
     
69
-    public function get_invoice_notes( $invoice_id = 0, $type = '' ) {
69
+    public function get_invoice_notes($invoice_id = 0, $type = '') {
70 70
         $args = array( 
71 71
             'post_id'   => $invoice_id,
72 72
             'orderby'   => 'comment_ID',
73 73
             'order'     => 'ASC',
74 74
         );
75 75
         
76
-        if ( $type == 'customer' ) {
76
+        if ($type == 'customer') {
77 77
             $args['meta_key']   = '_wpi_customer_note';
78 78
             $args['meta_value'] = 1;
79 79
         }
80 80
         
81
-        $args   = apply_filters( 'wpinv_invoice_notes_args', $args, $this, $invoice_id, $type );
81
+        $args = apply_filters('wpinv_invoice_notes_args', $args, $this, $invoice_id, $type);
82 82
         
83
-        return get_comments( $args );
83
+        return get_comments($args);
84 84
     }
85 85
     
86 86
     /**
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * @return void
92 92
      */
93 93
     public function delete_comments_count_cache() {
94
-        delete_transient( 'wpinv_count_comments' );
94
+        delete_transient('wpinv_count_comments');
95 95
     }
96 96
     
97 97
     /**
@@ -102,16 +102,16 @@  discard block
 block discarded – undo
102 102
      * @param  int    $post_id Post ID.
103 103
      * @return object
104 104
      */
105
-    public function wp_count_comments( $stats, $post_id ) {
105
+    public function wp_count_comments($stats, $post_id) {
106 106
         global $wpdb;
107 107
 
108
-        if ( 0 === $post_id ) {
109
-            $stats = get_transient( 'wpinv_count_comments' );
108
+        if (0 === $post_id) {
109
+            $stats = get_transient('wpinv_count_comments');
110 110
 
111
-            if ( ! $stats ) {
111
+            if (!$stats) {
112 112
                 $stats = array();
113 113
 
114
-                $count = $wpdb->get_results( "SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A );
114
+                $count = $wpdb->get_results("SELECT comment_approved, COUNT(*) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN ('" . $this->comment_type . "') GROUP BY comment_approved", ARRAY_A);
115 115
 
116 116
                 $total = 0;
117 117
                 $approved = array(
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
                     'post-trashed' => 'post-trashed',
123 123
                 );
124 124
 
125
-                foreach ( (array) $count as $row ) {
125
+                foreach ((array)$count as $row) {
126 126
                     // Do not count post-trashed toward totals.
127
-                    if ( 'post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved'] ) {
127
+                    if ('post-trashed' !== $row['comment_approved'] && 'trash' !== $row['comment_approved']) {
128 128
                         $total += $row['num_comments'];
129 129
                     }
130
-                    if ( isset( $approved[ $row['comment_approved'] ] ) ) {
131
-                        $stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
130
+                    if (isset($approved[$row['comment_approved']])) {
131
+                        $stats[$approved[$row['comment_approved']]] = $row['num_comments'];
132 132
                     }
133 133
                 }
134 134
 
135 135
                 $stats['total_comments'] = $total;
136 136
                 $stats['all'] = $total;
137
-                foreach ( $approved as $key ) {
138
-                    if ( empty( $stats[ $key ] ) ) {
139
-                        $stats[ $key ] = 0;
137
+                foreach ($approved as $key) {
138
+                    if (empty($stats[$key])) {
139
+                        $stats[$key] = 0;
140 140
                     }
141 141
                 }
142 142
 
143
-                $stats = (object) $stats;
144
-                set_transient( 'wpinv_count_comments', $stats );
143
+                $stats = (object)$stats;
144
+                set_transient('wpinv_count_comments', $stats);
145 145
             }
146 146
         }
147 147
 
Please login to merge, or discard this patch.
templates/emails/wpinv-email-new_invoice.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,18 +1,18 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-do_action( 'wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin );
6
+do_action('wpinv_email_header', $email_heading, $invoice, $email_type, $sent_to_admin);
7 7
 ?>
8 8
 
9
-<p><?php printf( __( 'You have received payment from %s. The invoice is as follows:', 'invoicing' ), $invoice->get_user_full_name() ); ?></p>
9
+<p><?php printf(__('You have received payment from %s. The invoice is as follows:', 'invoicing'), $invoice->get_user_full_name()); ?></p>
10 10
 
11 11
 <?php
12
-do_action( 'wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin );
12
+do_action('wpinv_email_invoice_details', $invoice, $email_type, $sent_to_admin);
13 13
 
14
-do_action( 'wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin );
14
+do_action('wpinv_email_invoice_items', $invoice, $email_type, $sent_to_admin);
15 15
 
16
-do_action( 'wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin );
16
+do_action('wpinv_email_billing_details', $invoice, $email_type, $sent_to_admin);
17 17
 
18
-do_action( 'wpinv_email_footer', $invoice, $email_type, $sent_to_admin );
19 18
\ No newline at end of file
19
+do_action('wpinv_email_footer', $invoice, $email_type, $sent_to_admin);
20 20
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +282 added lines, -282 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,253 +251,253 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
397
+function wpinv_cart_item_price($item) {
398 398
     $use_taxes  = wpinv_use_taxes();
399
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
400
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
401
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
402
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
403
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
404
-    
405
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
406
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
399
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
400
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
401
+    $options    = isset($item['options']) ? $item['options'] : array();
402
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
403
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
404
+    
405
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
406
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
407 407
             $price += $tax;
408 408
         }
409 409
         
410
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
410
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
411 411
             $price -= $tax;
412 412
         }        
413 413
     }
414 414
 
415
-    $price = wpinv_price( wpinv_format_amount( $price ) );
415
+    $price = wpinv_price(wpinv_format_amount($price));
416 416
 
417
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
417
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
418 418
 }
419 419
 
420
-function wpinv_cart_item_subtotal( $item ) {
421
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
422
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
420
+function wpinv_cart_item_subtotal($item) {
421
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
422
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
423 423
 
424
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
424
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
425 425
 }
426 426
 
427
-function wpinv_cart_item_tax( $item ) {
427
+function wpinv_cart_item_tax($item) {
428 428
     $tax        = '';
429 429
     $tax_rate   = '';
430 430
     
431
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
432
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
433
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
434
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
431
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
432
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
433
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
434
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
435 435
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
436 436
     }
437 437
     
438
-    $tax        = $tax . $tax_rate;
438
+    $tax = $tax . $tax_rate;
439 439
     
440
-    if ( $tax === '' ) {
440
+    if ($tax === '') {
441 441
         $tax = 0; // Zero tax
442 442
     }
443 443
 
444
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
444
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
445 445
 }
446 446
 
447
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
447
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
448 448
     $price = 0;
449 449
     
450 450
     // Set custom price
451
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
451
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
452 452
         $price = $cart_item['custom_price'];
453 453
     } else {
454
-        $variable_prices = wpinv_has_variable_prices( $item_id );
454
+        $variable_prices = wpinv_has_variable_prices($item_id);
455 455
 
456
-        if ( $variable_prices ) {
457
-            $prices = wpinv_get_variable_prices( $item_id );
456
+        if ($variable_prices) {
457
+            $prices = wpinv_get_variable_prices($item_id);
458 458
 
459
-            if ( $prices ) {
460
-                if( ! empty( $options ) ) {
461
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
459
+            if ($prices) {
460
+                if (!empty($options)) {
461
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
462 462
                 } else {
463 463
                     $price = false;
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        if( ! $variable_prices || false === $price ) {
468
+        if (!$variable_prices || false === $price) {
469 469
             // Get the standard Item price if not using variable prices
470
-            $price = wpinv_get_item_price( $item_id );
470
+            $price = wpinv_get_item_price($item_id);
471 471
         }
472 472
     }
473 473
 
474
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
475
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
474
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
475
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
476 476
     }
477 477
 
478
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
478
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
479 479
 }
480 480
 
481
-function wpinv_get_cart_item_price_id( $item = array() ) {
482
-    if( isset( $item['item_number'] ) ) {
483
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
481
+function wpinv_get_cart_item_price_id($item = array()) {
482
+    if (isset($item['item_number'])) {
483
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
484 484
     } else {
485
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
485
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
486 486
     }
487 487
     return $price_id;
488 488
 }
489 489
 
490
-function wpinv_get_cart_item_price_name( $item = array() ) {
491
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
492
-    $prices   = wpinv_get_variable_prices( $item['id'] );
493
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
494
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
490
+function wpinv_get_cart_item_price_name($item = array()) {
491
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
492
+    $prices   = wpinv_get_variable_prices($item['id']);
493
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
494
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
495 495
 }
496 496
 
497
-function wpinv_get_cart_item_name( $item = array() ) {
498
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
497
+function wpinv_get_cart_item_name($item = array()) {
498
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
499 499
 
500
-    if ( empty( $item_title ) ) {
500
+    if (empty($item_title)) {
501 501
         $item_title = $item['id'];
502 502
     }
503 503
 
@@ -507,23 +507,23 @@  discard block
 block discarded – undo
507 507
     }
508 508
     */
509 509
 
510
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
510
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
511 511
 }
512 512
 
513
-function wpinv_has_variable_prices( $item_id = 0 ) {
513
+function wpinv_has_variable_prices($item_id = 0) {
514 514
     return false;
515 515
 }
516 516
 
517
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
517
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
518 518
     $cart_items = wpinv_get_cart_contents();
519 519
 
520
-    if ( !is_array( $cart_items ) ) {
520
+    if (!is_array($cart_items)) {
521 521
         return false; // Empty cart
522 522
     } else {
523
-        foreach ( $cart_items as $position => $item ) {
524
-            if ( $item['id'] == $item_id ) {
525
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
526
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
523
+        foreach ($cart_items as $position => $item) {
524
+            if ($item['id'] == $item_id) {
525
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
526
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
527 527
                         return $position;
528 528
                     }
529 529
                 } else {
@@ -536,80 +536,80 @@  discard block
 block discarded – undo
536 536
     return false; // Not found
537 537
 }
538 538
 
539
-function wpinv_get_cart_item_quantity( $item ) {
540
-    if ( wpinv_item_quantities_enabled() ) {
541
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
539
+function wpinv_get_cart_item_quantity($item) {
540
+    if (wpinv_item_quantities_enabled()) {
541
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
542 542
     } else {
543 543
         $quantity = 1;
544 544
     }
545 545
     
546
-    if ( $quantity < 1 ) {
546
+    if ($quantity < 1) {
547 547
         $quantity = 1;
548 548
     }
549 549
     
550
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
550
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
551 551
 }
552 552
 
553
-function wpinv_get_item_suffix( $item, $html = true ) {
554
-    if ( empty( $item ) ) {
553
+function wpinv_get_item_suffix($item, $html = true) {
554
+    if (empty($item)) {
555 555
         return NULL;
556 556
     }
557 557
     
558
-    if ( is_int( $item ) ) {
559
-        $item = new WPInv_Item( $item );
558
+    if (is_int($item)) {
559
+        $item = new WPInv_Item($item);
560 560
     }
561 561
     
562
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
562
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
563 563
         return NULL;
564 564
     }
565 565
     
566
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
566
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
567 567
     
568
-    if ( !$html && $suffix ) {
569
-        $suffix = strip_tags( $suffix );
568
+    if (!$html && $suffix) {
569
+        $suffix = strip_tags($suffix);
570 570
     }
571 571
     
572
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
572
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
573 573
 }
574 574
 
575
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
576
-    if ( empty( $item ) ) {
575
+function wpinv_remove_item($item = 0, $force_delete = false) {
576
+    if (empty($item)) {
577 577
         return NULL;
578 578
     }
579 579
     
580
-    if ( is_int( $item ) ) {
581
-        $item = new WPInv_Item( $item );
580
+    if (is_int($item)) {
581
+        $item = new WPInv_Item($item);
582 582
     }
583 583
     
584
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
584
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
585 585
         return NULL;
586 586
     }
587 587
     
588
-    do_action( 'wpinv_pre_delete_item', $item );
588
+    do_action('wpinv_pre_delete_item', $item);
589 589
 
590
-    wp_delete_post( $item->ID, $force_delete );
590
+    wp_delete_post($item->ID, $force_delete);
591 591
 
592
-    do_action( 'wpinv_post_delete_item', $item );
592
+    do_action('wpinv_post_delete_item', $item);
593 593
 }
594 594
 
595
-function wpinv_can_delete_item( $post_id ) {
596
-    $return = current_user_can( 'manage_options' ) ? true : false;
595
+function wpinv_can_delete_item($post_id) {
596
+    $return = current_user_can('manage_options') ? true : false;
597 597
     
598
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
598
+    if ($return && wpinv_item_in_use($post_id)) {
599 599
         $return = false; // Don't delete item already use in invoices.
600 600
     }
601 601
     
602
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
602
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
603 603
 }
604 604
 
605 605
 function wpinv_admin_action_delete() {
606 606
     $screen = get_current_screen();
607 607
     
608
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
608
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
609 609
         $post_ids = array();
610 610
         
611
-        foreach ( $_REQUEST['post'] as $post_id ) {
612
-            if ( !wpinv_can_delete_item( $post_id ) ) {
611
+        foreach ($_REQUEST['post'] as $post_id) {
612
+            if (!wpinv_can_delete_item($post_id)) {
613 613
                 continue;
614 614
             }
615 615
             
@@ -619,86 +619,86 @@  discard block
 block discarded – undo
619 619
         $_REQUEST['post'] = $post_ids;
620 620
     }
621 621
 }
622
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
623
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
622
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
623
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
624 624
 
625
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
626
-    if ( $post->post_type == 'wpi_item' ) {
627
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
625
+function wpinv_check_delete_item($check, $post, $force_delete) {
626
+    if ($post->post_type == 'wpi_item') {
627
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
628 628
             return true;
629 629
         }
630 630
     }
631 631
     
632 632
     return $check;
633 633
 }
634
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
634
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
635 635
 
636
-function wpinv_item_in_use( $item_id ) {
636
+function wpinv_item_in_use($item_id) {
637 637
     global $wpdb, $wpi_items_in_use;
638 638
     
639
-    if ( !$item_id > 0 ) {
639
+    if (!$item_id > 0) {
640 640
         return false;
641 641
     }
642 642
     
643
-    if ( !empty( $wpi_items_in_use ) ) {
644
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
643
+    if (!empty($wpi_items_in_use)) {
644
+        if (isset($wpi_items_in_use[$item_id])) {
645 645
             return $wpi_items_in_use[$item_id];
646 646
         }
647 647
     } else {
648 648
         $wpi_items_in_use = array();
649 649
     }
650 650
     
651
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
651
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
652 652
     
653
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
653
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
654
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
655 655
     
656 656
     $wpi_items_in_use[$item_id] = $in_use;
657 657
     
658 658
     return $in_use;
659 659
 }
660 660
 
661
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
661
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
662 662
     // Set some defaults
663 663
     $defaults = array(
664
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
665
-        'title'                => '',                                                      // Required. Item title.
666
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
667
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
668
-        'status'               => 'pending',                                               // Optional. pending, publish
669
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
670
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
671
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
672
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
673
-        'excerpt'              => '',                                                      // Optional. Item short description
664
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
665
+        'title'                => '', // Required. Item title.
666
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
667
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
668
+        'status'               => 'pending', // Optional. pending, publish
669
+        'custom_name'          => '', // Optional. Plural sub title for item.
670
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
671
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
672
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
673
+        'excerpt'              => '', // Optional. Item short description
674 674
         /* Recurring item fields */
675
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
678
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
679
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
680
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
675
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
676
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
677
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
678
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
679
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
680
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
+        'trial_interval'       => 0, // Optional. Any integer number.
682 682
     );
683 683
 
684
-    $data = wp_parse_args( $args, $defaults );
684
+    $data = wp_parse_args($args, $defaults);
685 685
 
686
-    if ( empty( $data['type'] ) ) {
686
+    if (empty($data['type'])) {
687 687
         $data['type'] = 'custom';
688 688
     }
689 689
 
690
-    if ( !empty( $data['custom_id'] ) ) {
691
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
690
+    if (!empty($data['custom_id'])) {
691
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
692 692
     } else {
693 693
         $item = NULL;
694 694
     }
695 695
 
696
-    if ( !empty( $item ) ) {
697
-        if ( $force_update ) {
698
-            if ( empty( $args['ID'] ) ) {
696
+    if (!empty($item)) {
697
+        if ($force_update) {
698
+            if (empty($args['ID'])) {
699 699
                 $args['ID'] = $item->ID;
700 700
             }
701
-            return wpinv_update_item( $args, $wp_error );
701
+            return wpinv_update_item($args, $wp_error);
702 702
         }
703 703
 
704 704
         return $item;
@@ -709,19 +709,19 @@  discard block
 block discarded – undo
709 709
     $meta['custom_id']              = $data['custom_id'];
710 710
     $meta['custom_singular_name']   = $data['custom_singular_name'];
711 711
     $meta['custom_name']            = $data['custom_name'];
712
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
712
+    $meta['price']                  = wpinv_round_amount($data['price']);
713 713
     $meta['editable']               = (int)$data['editable'];
714 714
     $meta['vat_rule']               = $data['vat_rule'];
715 715
     $meta['vat_class']              = '_standard';
716 716
     
717
-    if ( !empty( $data['is_recurring'] ) ) {
717
+    if (!empty($data['is_recurring'])) {
718 718
         $meta['is_recurring']       = $data['is_recurring'];
719 719
         $meta['recurring_period']   = $data['recurring_period'];
720
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
721
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
720
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
721
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
722 722
         $meta['free_trial']         = $data['free_trial'];
723 723
         $meta['trial_period']       = $data['trial_period'];
724
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
724
+        $meta['trial_interval']     = absint($data['trial_interval']);
725 725
     } else {
726 726
         $meta['is_recurring']       = 0;
727 727
         $meta['recurring_period']   = '';
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
         $meta['trial_interval']     = '';
733 733
     }
734 734
     
735
-    $post_data  = array( 
735
+    $post_data = array( 
736 736
         'post_title'    => $data['title'],
737 737
         'post_excerpt'  => $data['excerpt'],
738 738
         'post_status'   => $data['status'],
@@ -740,86 +740,86 @@  discard block
 block discarded – undo
740 740
     );
741 741
 
742 742
     $item = new WPInv_Item();
743
-    $return = $item->create( $post_data, $wp_error );
743
+    $return = $item->create($post_data, $wp_error);
744 744
 
745
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
745
+    if ($return && !empty($item) && !is_wp_error($return)) {
746 746
         return $item;
747 747
     }
748 748
 
749
-    if ( $wp_error && is_wp_error( $return ) ) {
749
+    if ($wp_error && is_wp_error($return)) {
750 750
         return $return;
751 751
     }
752 752
     return 0;
753 753
 }
754 754
 
755
-function wpinv_update_item( $args = array(), $wp_error = false ) {
756
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
755
+function wpinv_update_item($args = array(), $wp_error = false) {
756
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
757 757
 
758
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
759
-        if ( $wp_error ) {
760
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
758
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
759
+        if ($wp_error) {
760
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
761 761
         }
762 762
         return 0;
763 763
     }
764 764
     
765
-    if ( !empty( $args['custom_id'] ) ) {
766
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
765
+    if (!empty($args['custom_id'])) {
766
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
767 767
         
768
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
769
-            if ( $wp_error ) {
770
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
768
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
769
+            if ($wp_error) {
770
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
771 771
             }
772 772
             return 0;
773 773
         }
774 774
     }
775 775
 
776
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
776
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
777 777
 
778 778
     $post_data = array();
779
-    if ( isset( $args['title'] ) ) { 
779
+    if (isset($args['title'])) { 
780 780
         $post_data['post_title'] = $args['title'];
781 781
     }
782
-    if ( isset( $args['excerpt'] ) ) { 
782
+    if (isset($args['excerpt'])) { 
783 783
         $post_data['post_excerpt'] = $args['excerpt'];
784 784
     }
785
-    if ( isset( $args['status'] ) ) { 
785
+    if (isset($args['status'])) { 
786 786
         $post_data['post_status'] = $args['status'];
787 787
     }
788 788
     
789
-    foreach ( $meta_fields as $meta_field ) {
790
-        if ( isset( $args[ $meta_field ] ) ) { 
791
-            $value = $args[ $meta_field ];
789
+    foreach ($meta_fields as $meta_field) {
790
+        if (isset($args[$meta_field])) { 
791
+            $value = $args[$meta_field];
792 792
 
793
-            switch ( $meta_field ) {
793
+            switch ($meta_field) {
794 794
                 case 'price':
795
-                    $value = wpinv_round_amount( $value );
795
+                    $value = wpinv_round_amount($value);
796 796
                 break;
797 797
                 case 'recurring_interval':
798 798
                 case 'recurring_limit':
799 799
                 case 'trial_interval':
800
-                    $value = absint( $value );
800
+                    $value = absint($value);
801 801
                 break;
802 802
             }
803 803
 
804
-            $post_data['meta'][ $meta_field ] = $value;
804
+            $post_data['meta'][$meta_field] = $value;
805 805
         };
806 806
     }
807 807
 
808
-    if ( empty( $post_data ) ) {
809
-        if ( $wp_error ) {
810
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
808
+    if (empty($post_data)) {
809
+        if ($wp_error) {
810
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
811 811
         }
812 812
         return 0;
813 813
     }
814 814
     $post_data['ID'] = $args['ID'];
815 815
 
816
-    $return = $item->update( $post_data, $wp_error );
816
+    $return = $item->update($post_data, $wp_error);
817 817
 
818
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
818
+    if ($return && !empty($item) && !is_wp_error($return)) {
819 819
         return $item;
820 820
     }
821 821
 
822
-    if ( $wp_error && is_wp_error( $return ) ) {
822
+    if ($wp_error && is_wp_error($return)) {
823 823
         return $return;
824 824
     }
825 825
     return 0;
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -1,72 +1,72 @@  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
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
42
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
42
+    $columns['status']      = __('Status', 'invoicing');
43 43
 
44 44
     return $columns;
45 45
 }
46 46
 
47
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
48
-function wpinv_discount_custom_column( $column ) {
47
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
48
+function wpinv_discount_custom_column($column) {
49 49
     global $post;
50 50
     
51 51
     $discount = $post;
52 52
 
53
-    switch ( $column ) {
53
+    switch ($column) {
54 54
         case 'name' :
55
-            echo get_the_title( $discount->ID );
55
+            echo get_the_title($discount->ID);
56 56
         break;
57 57
         case 'code' :
58
-            echo wpinv_get_discount_code( $discount->ID );
58
+            echo wpinv_get_discount_code($discount->ID);
59 59
         break;
60 60
         case 'amount' :
61
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
61
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
62 62
         break;
63 63
         case 'usage_limit' :
64
-            echo wpinv_get_discount_uses( $discount->ID );
64
+            echo wpinv_get_discount_uses($discount->ID);
65 65
         break;
66 66
         case 'usage' :
67
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
68
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
69
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
67
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
68
+            if (wpinv_get_discount_max_uses($discount->ID)) {
69
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
70 70
             } else {
71 71
                 $usage .= ' &infin;';
72 72
             }
@@ -74,162 +74,162 @@  discard block
 block discarded – undo
74 74
             echo $usage;
75 75
         break;
76 76
         case 'expiry_date' :
77
-            if ( wpinv_get_discount_expiration( $discount->ID ) ) {
78
-                $expiration = date_i18n( get_option( 'date_format' ), strtotime( wpinv_get_discount_expiration( $discount->ID ) ) );
77
+            if (wpinv_get_discount_expiration($discount->ID)) {
78
+                $expiration = date_i18n(get_option('date_format'), strtotime(wpinv_get_discount_expiration($discount->ID)));
79 79
             } else {
80
-                $expiration = __( 'Never', 'invoicing' );
80
+                $expiration = __('Never', 'invoicing');
81 81
             }
82 82
                 
83 83
             echo $expiration;
84 84
         break;
85 85
         case 'description' :
86
-            echo wp_kses_post( $post->post_excerpt );
86
+            echo wp_kses_post($post->post_excerpt);
87 87
         break;
88 88
         case 'status' :
89
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
89
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
90 90
             
91
-            echo wpinv_discount_status( $status );
91
+            echo wpinv_discount_status($status);
92 92
         break;
93 93
     }
94 94
 }
95 95
 
96
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
97
-function wpinv_post_row_actions( $actions, $post ) {
98
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
96
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
97
+function wpinv_post_row_actions($actions, $post) {
98
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
99 99
     
100
-    if ( $post_type == 'wpi_invoice' ) {
100
+    if ($post_type == 'wpi_invoice') {
101 101
         $actions = array();
102 102
     }
103 103
     
104
-    if ( $post_type == 'wpi_discount' ) {
105
-        $actions = wpinv_discount_row_actions( $post, $actions );
104
+    if ($post_type == 'wpi_discount') {
105
+        $actions = wpinv_discount_row_actions($post, $actions);
106 106
     }
107 107
     
108 108
     return $actions;
109 109
 }
110 110
 
111
-function wpinv_discount_row_actions( $discount, $row_actions ) {
112
-    $row_actions  = array();
113
-    $edit_link = get_edit_post_link( $discount->ID );
114
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
111
+function wpinv_discount_row_actions($discount, $row_actions) {
112
+    $row_actions = array();
113
+    $edit_link = get_edit_post_link($discount->ID);
114
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
115 115
 
116
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
117
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
118
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
119
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
116
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
117
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
118
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
119
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
120 120
     }
121 121
 
122
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
123
-        if ( isset( $row_actions['delete'] ) ) {
124
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
122
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
123
+        if (isset($row_actions['delete'])) {
124
+            unset($row_actions['delete']); // Don't delete used discounts.
125 125
         }
126 126
     } else {
127
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
127
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
128 128
     }
129 129
     
130 130
 
131
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
131
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
132 132
 
133 133
     return $row_actions;
134 134
 }
135 135
 
136
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
137
-function wpinv_table_primary_column( $default, $screen_id ) {
138
-    if ( 'edit-wpi_invoice' === $screen_id ) {
136
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
137
+function wpinv_table_primary_column($default, $screen_id) {
138
+    if ('edit-wpi_invoice' === $screen_id) {
139 139
         return 'name';
140 140
     }
141 141
     
142 142
     return $default;
143 143
 }
144 144
 
145
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
146
-    if ( !$display ) {
145
+function wpinv_discount_bulk_actions($actions, $display = false) {    
146
+    if (!$display) {
147 147
         return array();
148 148
     }
149 149
     
150 150
     $actions = array(
151
-        'activate'   => __( 'Activate', 'invoicing' ),
152
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
153
-        'delete'     => __( 'Delete', 'invoicing' ),
151
+        'activate'   => __('Activate', 'invoicing'),
152
+        'deactivate' => __('Deactivate', 'invoicing'),
153
+        'delete'     => __('Delete', 'invoicing'),
154 154
     );
155 155
     $two = '';
156 156
     $which = 'top';
157 157
     echo '</div><div class="alignleft actions bulkactions">';
158
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
159
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
160
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
158
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
159
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
160
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
161 161
 
162
-    foreach ( $actions as $name => $title ) {
162
+    foreach ($actions as $name => $title) {
163 163
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
164 164
 
165 165
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
166 166
     }
167 167
     echo "</select>";
168 168
 
169
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
169
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
170 170
     
171 171
     echo '</div><div class="alignleft actions">';
172 172
 }
173
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
173
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
174 174
 
175
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
176
-    if ( $post_type == 'wpi_discount' ) {
175
+function wpinv_disable_months_dropdown($disable, $post_type) {
176
+    if ($post_type == 'wpi_discount') {
177 177
         $disable = true;
178 178
     }
179 179
     
180 180
     return $disable;
181 181
 }
182
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
182
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
183 183
 
184 184
 function wpinv_restrict_manage_posts() {
185 185
     global $typenow;
186 186
 
187
-    if( 'wpi_discount' == $typenow ) {
187
+    if ('wpi_discount' == $typenow) {
188 188
         wpinv_discount_filters();
189 189
     }
190 190
 }
191
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
191
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
192 192
 
193 193
 function wpinv_discount_filters() {
194
-    echo wpinv_discount_bulk_actions( array(), true );
194
+    echo wpinv_discount_bulk_actions(array(), true);
195 195
     
196 196
     ?>
197 197
     <select name="discount_type" id="dropdown_wpinv_discount_type">
198
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
198
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
199 199
         <?php
200 200
             $types = wpinv_get_discount_types();
201 201
 
202
-            foreach ( $types as $name => $type ) {
203
-                echo '<option value="' . esc_attr( $name ) . '"';
202
+            foreach ($types as $name => $type) {
203
+                echo '<option value="' . esc_attr($name) . '"';
204 204
 
205
-                if ( isset( $_GET['discount_type'] ) )
206
-                    selected( $name, $_GET['discount_type'] );
205
+                if (isset($_GET['discount_type']))
206
+                    selected($name, $_GET['discount_type']);
207 207
 
208
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
208
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
209 209
             }
210 210
         ?>
211 211
     </select>
212 212
     <?php
213 213
 }
214 214
 
215
-function wpinv_request( $vars ) {
215
+function wpinv_request($vars) {
216 216
     global $typenow, $wp_query, $wp_post_statuses;
217 217
 
218
-    if ( 'wpi_invoice' === $typenow ) {
219
-        if ( !isset( $vars['post_status'] ) ) {
218
+    if ('wpi_invoice' === $typenow) {
219
+        if (!isset($vars['post_status'])) {
220 220
             $post_statuses = wpinv_get_invoice_statuses();
221 221
 
222
-            foreach ( $post_statuses as $status => $value ) {
223
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
224
-                    unset( $post_statuses[ $status ] );
222
+            foreach ($post_statuses as $status => $value) {
223
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
224
+                    unset($post_statuses[$status]);
225 225
                 }
226 226
             }
227 227
 
228
-            $vars['post_status'] = array_keys( $post_statuses );
228
+            $vars['post_status'] = array_keys($post_statuses);
229 229
         }
230 230
         
231
-        if ( isset( $vars['orderby'] ) ) {
232
-            if ( 'amount' == $vars['orderby'] ) {
231
+        if (isset($vars['orderby'])) {
232
+            if ('amount' == $vars['orderby']) {
233 233
                 $vars = array_merge(
234 234
                     $vars,
235 235
                     array(
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
                         'orderby'  => 'meta_value_num'
238 238
                     )
239 239
                 );
240
-            } else if ( 'customer' == $vars['orderby'] ) {
240
+            } else if ('customer' == $vars['orderby']) {
241 241
                 $vars = array_merge(
242 242
                     $vars,
243 243
                     array(
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
                         'orderby'  => 'meta_value'
246 246
                     )
247 247
                 );
248
-            } else if ( 'number' == $vars['orderby'] ) {
248
+            } else if ('number' == $vars['orderby']) {
249 249
                 $vars = array_merge(
250 250
                     $vars,
251 251
                     array(
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
                 );
256 256
             }
257 257
         }
258
-    } else if ( 'wpi_item' == $typenow ) {
258
+    } else if ('wpi_item' == $typenow) {
259 259
         // Check if 'orderby' is set to "price"
260
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
260
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
261 261
             $vars = array_merge(
262 262
                 $vars,
263 263
                 array(
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
         }
269 269
 
270 270
         // Check if "orderby" is set to "vat_rule"
271
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
271
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
272 272
             $vars = array_merge(
273 273
                 $vars,
274 274
                 array(
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
         }
280 280
 
281 281
         // Check if "orderby" is set to "vat_class"
282
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
282
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
283 283
             $vars = array_merge(
284 284
                 $vars,
285 285
                 array(
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
         }
291 291
         
292 292
         // Check if "orderby" is set to "type"
293
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
293
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
294 294
             $vars = array_merge(
295 295
                 $vars,
296 296
                 array(
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
         }
302 302
         
303 303
         // Check if "orderby" is set to "recurring"
304
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
304
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
305 305
             $vars = array_merge(
306 306
                 $vars,
307 307
                 array(
@@ -311,120 +311,120 @@  discard block
 block discarded – undo
311 311
             );
312 312
         }
313 313
 
314
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
314
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
315 315
         // Filter vat rule type
316
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
316
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
317 317
             $meta_query[] = array(
318 318
                     'key'   => '_wpinv_vat_rule',
319
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
319
+                    'value' => sanitize_text_field($_GET['vat_rule']),
320 320
                     'compare' => '='
321 321
                 );
322 322
         }
323 323
         
324 324
         // Filter vat class
325
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
325
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
326 326
             $meta_query[] = array(
327 327
                     'key'   => '_wpinv_vat_class',
328
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
328
+                    'value' => sanitize_text_field($_GET['vat_class']),
329 329
                     'compare' => '='
330 330
                 );
331 331
         }
332 332
         
333 333
         // Filter item type
334
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
334
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
335 335
             $meta_query[] = array(
336 336
                     'key'   => '_wpinv_type',
337
-                    'value' => sanitize_text_field( $_GET['type'] ),
337
+                    'value' => sanitize_text_field($_GET['type']),
338 338
                     'compare' => '='
339 339
                 );
340 340
         }
341 341
         
342
-        if ( !empty( $meta_query ) ) {
342
+        if (!empty($meta_query)) {
343 343
             $vars['meta_query'] = $meta_query;
344 344
         }
345
-    } else if ( 'wpi_discount' == $typenow ) {
346
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
345
+    } else if ('wpi_discount' == $typenow) {
346
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
347 347
         // Filter vat rule type
348
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
348
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
349 349
             $meta_query[] = array(
350 350
                     'key'   => '_wpi_discount_type',
351
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
351
+                    'value' => sanitize_text_field($_GET['discount_type']),
352 352
                     'compare' => '='
353 353
                 );
354 354
         }
355 355
         
356
-        if ( !empty( $meta_query ) ) {
356
+        if (!empty($meta_query)) {
357 357
             $vars['meta_query'] = $meta_query;
358 358
         }
359 359
     }
360 360
 
361 361
     return $vars;
362 362
 }
363
-add_filter( 'request', 'wpinv_request' );
363
+add_filter('request', 'wpinv_request');
364 364
 
365 365
 function wpinv_options_page() {
366
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
366
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
367 367
     
368
-    if ( $page !== 'wpinv-settings' ) {
368
+    if ($page !== 'wpinv-settings') {
369 369
         return;
370 370
     }
371 371
     
372 372
     $settings_tabs = wpinv_get_settings_tabs();
373 373
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
374
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
375
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
374
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
375
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
376 376
     $key           = 'main';
377 377
 
378
-    if ( is_array( $sections ) ) {
379
-        $key = key( $sections );
378
+    if (is_array($sections)) {
379
+        $key = key($sections);
380 380
     }
381 381
 
382
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
383
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
382
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
383
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
384 384
     ob_start();
385 385
     ?>
386 386
     <div class="wrap">
387 387
         <h1 class="nav-tab-wrapper">
388 388
             <?php
389
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
390
-                $tab_url = add_query_arg( array(
389
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
390
+                $tab_url = add_query_arg(array(
391 391
                     'settings-updated' => false,
392 392
                     'tab' => $tab_id,
393
-                ) );
393
+                ));
394 394
 
395 395
                 // Remove the section from the tabs so we always end up at the main section
396
-                $tab_url = remove_query_arg( 'section', $tab_url );
397
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
396
+                $tab_url = remove_query_arg('section', $tab_url);
397
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
398 398
 
399 399
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
400 400
 
401
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
402
-                    echo esc_html( $tab_name );
401
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
402
+                    echo esc_html($tab_name);
403 403
                 echo '</a>';
404 404
             }
405 405
             ?>
406 406
         </h1>
407 407
         <?php
408
-        $number_of_sections = count( $sections );
408
+        $number_of_sections = count($sections);
409 409
         $number = 0;
410
-        if ( $number_of_sections > 1 ) {
410
+        if ($number_of_sections > 1) {
411 411
             echo '<div><ul class="subsubsub">';
412
-            foreach( $sections as $section_id => $section_name ) {
412
+            foreach ($sections as $section_id => $section_name) {
413 413
                 echo '<li>';
414 414
                 $number++;
415
-                $tab_url = add_query_arg( array(
415
+                $tab_url = add_query_arg(array(
416 416
                     'settings-updated' => false,
417 417
                     'tab' => $active_tab,
418 418
                     'section' => $section_id
419
-                ) );
420
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
419
+                ));
420
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
421 421
                 $class = '';
422
-                if ( $section == $section_id ) {
422
+                if ($section == $section_id) {
423 423
                     $class = 'current';
424 424
                 }
425
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
425
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
426 426
 
427
-                if ( $number != $number_of_sections ) {
427
+                if ($number != $number_of_sections) {
428 428
                     echo ' | ';
429 429
                 }
430 430
                 echo '</li>';
@@ -436,19 +436,19 @@  discard block
 block discarded – undo
436 436
             <form method="post" action="options.php">
437 437
                 <table class="form-table">
438 438
                 <?php
439
-                settings_fields( 'wpinv_settings' );
439
+                settings_fields('wpinv_settings');
440 440
 
441
-                if ( 'main' === $section ) {
442
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
441
+                if ('main' === $section) {
442
+                    do_action('wpinv_settings_tab_top', $active_tab);
443 443
                 }
444 444
 
445
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section );
446
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section );
447
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section  );
445
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section);
446
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section);
447
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section);
448 448
 
449 449
                 // For backwards compatibility
450
-                if ( 'main' === $section ) {
451
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
450
+                if ('main' === $section) {
451
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
452 452
                 }
453 453
                 ?>
454 454
                 </table>
@@ -461,53 +461,53 @@  discard block
 block discarded – undo
461 461
     echo $content;
462 462
 }
463 463
 
464
-function wpinv_item_type_class( $classes, $class, $post_id ) {
464
+function wpinv_item_type_class($classes, $class, $post_id) {
465 465
     global $pagenow, $typenow;
466 466
 
467
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
468
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
469
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
467
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
468
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
469
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
470 470
         }
471 471
         
472
-        if ( !wpinv_item_is_editable( $post_id ) ) {
472
+        if (!wpinv_item_is_editable($post_id)) {
473 473
             $classes[] = 'wpi-editable-n';
474 474
         }
475 475
     }
476 476
     return $classes;
477 477
 }
478
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
478
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
479 479
 
480 480
 function wpinv_check_quick_edit() {
481 481
     global $pagenow, $current_screen, $wpinv_item_screen;
482 482
 
483
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
484
-        if ( empty( $wpinv_item_screen ) ) {
485
-            if ( $current_screen->post_type == 'wpi_item' ) {
483
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
484
+        if (empty($wpinv_item_screen)) {
485
+            if ($current_screen->post_type == 'wpi_item') {
486 486
                 $wpinv_item_screen = 'y';
487 487
             } else {
488 488
                 $wpinv_item_screen = 'n';
489 489
             }
490 490
         }
491 491
 
492
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
493
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
494
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
492
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
493
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
494
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
495 495
         }
496 496
     }
497 497
 }
498
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
498
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
499 499
 
500
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
501
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
502
-        unset( $actions['inline hide-if-no-js'] );
500
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
501
+    if (isset($actions['inline hide-if-no-js'])) {
502
+        unset($actions['inline hide-if-no-js']);
503 503
     }
504 504
     
505
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
506
-        if ( isset( $actions['trash'] ) ) {
507
-            unset( $actions['trash'] );
505
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
506
+        if (isset($actions['trash'])) {
507
+            unset($actions['trash']);
508 508
         }
509
-        if ( isset( $actions['delete'] ) ) {
510
-            unset( $actions['delete'] );
509
+        if (isset($actions['delete'])) {
510
+            unset($actions['delete']);
511 511
         }
512 512
     }
513 513
 
@@ -524,19 +524,19 @@  discard block
 block discarded – undo
524 524
  * @param int $post_parent (default: 0) Parent for the new page
525 525
  * @return int page ID
526 526
  */
527
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
527
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
528 528
     global $wpdb;
529 529
 
530
-    $option_value = wpinv_get_option( $option );
530
+    $option_value = wpinv_get_option($option);
531 531
 
532
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
533
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
532
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
533
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
534 534
             // Valid page is already in place
535 535
             return $page_object->ID;
536 536
         }
537 537
     }
538 538
 
539
-    if(!empty($post_parent)){
539
+    if (!empty($post_parent)) {
540 540
         $page = get_page_by_path($post_parent);
541 541
         if ($page) {
542 542
             $post_parent = $page->ID;
@@ -545,40 +545,40 @@  discard block
 block discarded – undo
545 545
         }
546 546
     }
547 547
 
548
-    if ( strlen( $page_content ) > 0 ) {
548
+    if (strlen($page_content) > 0) {
549 549
         // Search for an existing page with the specified page content (typically a shortcode)
550
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
550
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
551 551
     } else {
552 552
         // Search for an existing page with the specified page slug
553
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
553
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
554 554
     }
555 555
 
556
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
556
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
557 557
 
558
-    if ( $valid_page_found ) {
559
-        if ( $option ) {
560
-            wpinv_update_option( $option, $valid_page_found );
558
+    if ($valid_page_found) {
559
+        if ($option) {
560
+            wpinv_update_option($option, $valid_page_found);
561 561
         }
562 562
         return $valid_page_found;
563 563
     }
564 564
 
565 565
     // Search for a matching valid trashed page
566
-    if ( strlen( $page_content ) > 0 ) {
566
+    if (strlen($page_content) > 0) {
567 567
         // Search for an existing page with the specified page content (typically a shortcode)
568
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
568
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
569 569
     } else {
570 570
         // Search for an existing page with the specified page slug
571
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
571
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
572 572
     }
573 573
 
574
-    if ( $trashed_page_found ) {
574
+    if ($trashed_page_found) {
575 575
         $page_id   = $trashed_page_found;
576 576
         $page_data = array(
577 577
             'ID'             => $page_id,
578 578
             'post_status'    => 'publish',
579 579
             'post_parent'    => $post_parent,
580 580
         );
581
-        wp_update_post( $page_data );
581
+        wp_update_post($page_data);
582 582
     } else {
583 583
         $page_data = array(
584 584
             'post_status'    => 'publish',
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
             'post_parent'    => $post_parent,
591 591
             'comment_status' => 'closed',
592 592
         );
593
-        $page_id = wp_insert_post( $page_data );
593
+        $page_id = wp_insert_post($page_data);
594 594
     }
595 595
 
596
-    if ( $option ) {
597
-        wpinv_update_option( $option, (int)$page_id );
596
+    if ($option) {
597
+        wpinv_update_option($option, (int)$page_id);
598 598
     }
599 599
 
600 600
     return $page_id;
Please login to merge, or discard this patch.
templates/wpinv-invoice-history.php 1 patch
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -1,80 +1,80 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( !( $user_id = get_current_user_id() ) ) {
6
+if (!($user_id = get_current_user_id())) {
7 7
     ?>
8
-    <div class="wpinv-empty alert alert-error"><?php _e( 'You are not allowed to access this section', 'invoicing' ) ;?></div>
8
+    <div class="wpinv-empty alert alert-error"><?php _e('You are not allowed to access this section', 'invoicing'); ?></div>
9 9
     <?php
10 10
     return;
11 11
 }
12 12
 
13 13
 global $current_page;
14
-$current_page   = empty( $current_page ) ? 1 : absint( $current_page );
15
-$query          = apply_filters( 'wpinv_user_invoices_query', array( 'user' => $user_id, 'page' => $current_page, 'paginate' => true ) );
16
-$user_invoices  = wpinv_get_invoices( $query );
14
+$current_page   = empty($current_page) ? 1 : absint($current_page);
15
+$query          = apply_filters('wpinv_user_invoices_query', array('user' => $user_id, 'page' => $current_page, 'paginate' => true));
16
+$user_invoices  = wpinv_get_invoices($query);
17 17
 $has_invoices   = 0 < $user_invoices->total;
18 18
     
19
-do_action( 'wpinv_before_user_invoices', $has_invoices ); ?>
19
+do_action('wpinv_before_user_invoices', $has_invoices); ?>
20 20
 
21
-<?php if ( $has_invoices ) { ?>
21
+<?php if ($has_invoices) { ?>
22 22
 	<table class="table table-bordered table-hover wpi-user-invoices">
23 23
 		<thead>
24 24
 			<tr>
25
-				<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
26
-					<th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
25
+				<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
26
+					<th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
27 27
 				<?php endforeach; ?>
28 28
 			</tr>
29 29
 		</thead>
30 30
 
31 31
 		<tbody>
32
-			<?php foreach ( $user_invoices->invoices as $invoice ) {
32
+			<?php foreach ($user_invoices->invoices as $invoice) {
33 33
 				?>
34 34
 				<tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
35
-					<?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
36
-						<td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
37
-							<?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
38
-								<?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
39
-
40
-							<?php elseif ( 'invoice-number' === $column_id ) : ?>
41
-								<a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
42
-									<?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
35
+					<?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
36
+						<td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
37
+							<?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
38
+								<?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
39
+
40
+							<?php elseif ('invoice-number' === $column_id) : ?>
41
+								<a href="<?php echo esc_url($invoice->get_view_url()); ?>">
42
+									<?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
43 43
 								</a>
44 44
 
45
-							<?php elseif ( 'invoice-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s' ); ?>
46
-								<time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
45
+							<?php elseif ('invoice-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s'); ?>
46
+								<time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
47 47
 
48
-							<?php elseif ( 'invoice-status' === $column_id ) : ?>
49
-								<?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
48
+							<?php elseif ('invoice-status' === $column_id) : ?>
49
+								<?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
50 50
 
51
-							<?php elseif ( 'invoice-total' === $column_id ) : ?>
52
-								<?php echo $invoice->get_total( true ); ?>
51
+							<?php elseif ('invoice-total' === $column_id) : ?>
52
+								<?php echo $invoice->get_total(true); ?>
53 53
 
54
-							<?php elseif ( 'invoice-actions' === $column_id ) : ?>
54
+							<?php elseif ('invoice-actions' === $column_id) : ?>
55 55
 								<?php
56 56
 									$actions = array(
57 57
 										'pay'    => array(
58 58
 											'url'  => $invoice->get_checkout_payment_url(),
59
-											'name' => __( 'Pay Now', 'invoicing' ),
59
+											'name' => __('Pay Now', 'invoicing'),
60 60
                                             'class' => 'btn-success'
61 61
 										),
62 62
                                         'print'   => array(
63 63
 											'url'  => $invoice->get_view_url(),
64
-											'name' => __( 'Print', 'invoicing' ),
64
+											'name' => __('Print', 'invoicing'),
65 65
                                             'class' => 'btn-primary',
66 66
                                             'attrs' => 'target="_blank"'
67 67
 										)
68 68
 									);
69 69
 
70
-									if ( ! $invoice->needs_payment() ) {
71
-										unset( $actions['pay'] );
70
+									if (!$invoice->needs_payment()) {
71
+										unset($actions['pay']);
72 72
 									}
73 73
 
74
-									if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
75
-										foreach ( $actions as $key => $action ) {
74
+									if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
75
+										foreach ($actions as $key => $action) {
76 76
 											$class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
77
-                                            echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
77
+                                            echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
78 78
 										}
79 79
 									}
80 80
 								?>
@@ -86,9 +86,9 @@  discard block
 block discarded – undo
86 86
 		</tbody>
87 87
 	</table>
88 88
 
89
-	<?php do_action( 'wpinv_before_user_invoices_pagination' ); ?>
89
+	<?php do_action('wpinv_before_user_invoices_pagination'); ?>
90 90
 
91
-	<?php if ( 1 < $user_invoices->max_num_pages ) : ?>
91
+	<?php if (1 < $user_invoices->max_num_pages) : ?>
92 92
 		<div class="invoicing-Pagination">
93 93
 			<?php
94 94
 			$big = 999999;
@@ -100,20 +100,20 @@  discard block
 block discarded – undo
100 100
 			else
101 101
 				$current_page = 1;
102 102
 
103
-			echo paginate_links( array(
104
-				'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
103
+			echo paginate_links(array(
104
+				'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
105 105
 				'format'  => '?paged=%#%',
106
-				'current' => max( 1, $current_page ),
106
+				'current' => max(1, $current_page),
107 107
 				'total'   => $user_invoices->max_num_pages,
108
-			) );
108
+			));
109 109
 			?>
110 110
 		</div>
111 111
 	<?php endif; ?>
112 112
 
113 113
 <?php } else { ?>
114 114
 	<div class="wpinv-empty alert-info">
115
-		<?php _e( 'No invoice has been made yet.', 'invoicing' ); ?>
115
+		<?php _e('No invoice has been made yet.', 'invoicing'); ?>
116 116
 	</div>
117 117
 <?php } ?>
118 118
 
119
-<?php do_action( 'wpinv_after_user_invoices', $has_invoices ); ?>
119
+<?php do_action('wpinv_after_user_invoices', $has_invoices); ?>
Please login to merge, or discard this patch.