Passed
Pull Request — master (#37)
by Kiran
03:38
created
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {        
8
+    public static function output($post) {        
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
         
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22 22
         $item_types         = wpinv_get_item_types();
@@ -27,17 +27,17 @@  discard block
 block discarded – undo
27 27
         }
28 28
         
29 29
         $cols = 5;
30
-        if ( $item_quantities ) {
30
+        if ($item_quantities) {
31 31
             $cols++;
32 32
         }
33
-        if ( $use_taxes ) {
33
+        if ($use_taxes) {
34 34
             $cols++;
35 35
         }
36 36
         $class = '';
37
-        if ( $invoice->is_paid() ) {
37
+        if ($invoice->is_paid()) {
38 38
             $class .= ' wpinv-paid';
39 39
         }
40
-        if ( $is_recurring ) {
40
+        if ($is_recurring) {
41 41
             $class .= ' wpi-recurring';
42 42
         }
43 43
         ?>
@@ -45,21 +45,21 @@  discard block
 block discarded – undo
45 45
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
46 46
                 <thead>
47 47
                     <tr>
48
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
49
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
50
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
51
-                        <?php if ( $item_quantities ) { ?>
52
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
48
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
49
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
50
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
51
+                        <?php if ($item_quantities) { ?>
52
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
53 53
                         <?php } ?>
54
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
55
-                        <?php if ( $use_taxes ) { ?>
56
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
54
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
55
+                        <?php if ($use_taxes) { ?>
56
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58 58
                         <th class="action"></th>
59 59
                     </tr>
60 60
                 </thead>
61 61
                 <tbody class="wpinv-line-items">
62
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
62
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
63 63
                 </tbody>
64 64
                 <tfoot class="wpinv-totals">
65 65
                     <tr>
@@ -71,44 +71,44 @@  discard block
 block discarded – undo
71 71
                                         </td>
72 72
                                         <td class="title">
73 73
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
74
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
74
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
75 75
                                             <div class="wp-clearfix">
76 76
                                                 <label class="wpi-vat-rule">
77
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
77
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
78 78
                                                     <span class="input-text-wrap">
79
-                                                        <?php echo wpinv_html_select( array(
79
+                                                        <?php echo wpinv_html_select(array(
80 80
                                                             'options'          => $wpinv_euvat->get_rules(),
81 81
                                                             'name'             => '_wpinv_quick[vat_rule]',
82 82
                                                             'id'               => '_wpinv_quick_vat_rule',
83 83
                                                             'show_option_all'  => false,
84 84
                                                             'show_option_none' => false,
85 85
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
86
-                                                        ) ); ?>
86
+                                                        )); ?>
87 87
                                                     </span>
88 88
                                                 </label>
89 89
                                             </div>
90
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
90
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
91 91
                                             <div class="wp-clearfix">
92 92
                                                 <label class="wpi-vat-class">
93
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
93
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
94 94
                                                     <span class="input-text-wrap">
95
-                                                        <?php echo wpinv_html_select( array(
95
+                                                        <?php echo wpinv_html_select(array(
96 96
                                                             'options'          => $wpinv_euvat->get_all_classes(),
97 97
                                                             'name'             => '_wpinv_quick[vat_class]',
98 98
                                                             'id'               => '_wpinv_quick_vat_class',
99 99
                                                             'show_option_all'  => false,
100 100
                                                             'show_option_none' => false,
101 101
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
102
-                                                        ) ); ?>
102
+                                                        )); ?>
103 103
                                                     </span>
104 104
                                                 </label>
105 105
                                             </div>
106 106
                                             <?php } ?>
107 107
                                             <div class="wp-clearfix">
108 108
                                                 <label class="wpi-item-type">
109
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
109
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
110 110
                                                     <span class="input-text-wrap">
111
-                                                        <?php echo wpinv_html_select( array(
111
+                                                        <?php echo wpinv_html_select(array(
112 112
                                                             'options'          => $item_types,
113 113
                                                             'name'             => '_wpinv_quick[type]',
114 114
                                                             'id'               => '_wpinv_quick_type',
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
                                                             'show_option_all'  => false,
117 117
                                                             'show_option_none' => false,
118 118
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
119
-                                                        ) ); ?>
119
+                                                        )); ?>
120 120
                                                     </span>
121 121
                                                 </label>
122 122
                                             </div>
@@ -129,11 +129,11 @@  discard block
 block discarded – undo
129 129
                                             </div>
130 130
                                         </td>
131 131
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
132
-                                        <?php if ( $item_quantities ) { ?>
132
+                                        <?php if ($item_quantities) { ?>
133 133
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
134 134
                                         <?php } ?>
135 135
                                         <td class="total"></td>
136
-                                        <?php if ( $use_taxes ) { ?>
136
+                                        <?php if ($use_taxes) { ?>
137 137
                                         <td class="tax"></td>
138 138
                                         <?php } ?>
139 139
                                         <td class="action"></td>
@@ -146,29 +146,29 @@  discard block
 block discarded – undo
146 146
                         <td colspan="<?php echo $cols; ?>"></td>
147 147
                     </tr>
148 148
                     <tr class="totals">
149
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
149
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
150 150
                         <td colspan="4">
151 151
                             <table cellspacing="0" cellpadding="0">
152 152
                                 <tr class="subtotal">
153
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
154
-                                    <td class="total"><?php echo $subtotal;?></td>
153
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
154
+                                    <td class="total"><?php echo $subtotal; ?></td>
155 155
                                     <td class="action"></td>
156 156
                                 </tr>
157 157
                                 <tr class="discount">
158
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
159
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
158
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
159
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
160 160
                                     <td class="action"></td>
161 161
                                 </tr>
162
-                                <?php if ( $use_taxes ) { ?>
162
+                                <?php if ($use_taxes) { ?>
163 163
                                 <tr class="tax">
164
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
165
-                                    <td class="total"><?php echo $tax;?></td>
164
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
165
+                                    <td class="total"><?php echo $tax; ?></td>
166 166
                                     <td class="action"></td>
167 167
                                 </tr>
168 168
                                 <?php } ?>
169 169
                                 <tr class="total">
170
-                                    <td class="name"><?php _e( 'Invoice Total:', 'invoicing' );?></td>
171
-                                    <td class="total"><?php echo $total;?></td>
170
+                                    <td class="name"><?php _e('Invoice Total:', 'invoicing'); ?></td>
171
+                                    <td class="total"><?php echo $total; ?></td>
172 172
                                     <td class="action"></td>
173 173
                                 </tr>
174 174
                             </table>
@@ -178,89 +178,89 @@  discard block
 block discarded – undo
178 178
             </table>
179 179
             <div class="wpinv-actions">
180 180
                 <?php
181
-                    if ( !$invoice->is_paid() ) {
182
-                    if ( !$invoice->is_recurring() ) {
183
-                    echo wpinv_item_dropdown( array(
181
+                    if (!$invoice->is_paid()) {
182
+                    if (!$invoice->is_recurring()) {
183
+                    echo wpinv_item_dropdown(array(
184 184
                         'name'             => 'wpinv_invoice_item',
185 185
                         'id'               => 'wpinv_invoice_item',
186 186
                         'with_packages'    => false,
187 187
                         'show_recurring'   => true,
188
-                    ) );
188
+                    ));
189 189
                     ?>
190
-                    <input type="button" value="<?php esc_attr_e( 'Add item to Invoice', 'invoicing' );?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
190
+                    <input type="button" value="<?php esc_attr_e('Add item to Invoice', 'invoicing'); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
191 191
                     <?php } ?>
192
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
192
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
193 193
             </div>
194 194
         </div>
195 195
         <?php
196 196
     }
197 197
     
198
-    public static function prices( $post ) {        
198
+    public static function prices($post) {        
199 199
         $symbol         = wpinv_currency_symbol();
200 200
         $position       = wpinv_currency_position();
201
-        $item           = new WPInv_Item( $post->ID );
201
+        $item           = new WPInv_Item($post->ID);
202 202
         
203 203
         $price          = $item->get_price();
204 204
         $is_recurring   = $item->is_recurring();
205 205
         $period         = $item->get_recurring_period();
206
-        $interval       = absint( $item->get_recurring_interval() );
207
-        $times          = absint( $item->get_recurring_limit() );
206
+        $interval       = absint($item->get_recurring_interval());
207
+        $times          = absint($item->get_recurring_limit());
208 208
         $free_trial     = $item->has_free_trial();
209 209
         $trial_interval = $item->get_trial_interval();
210 210
         $trial_period   = $item->get_trial_period();
211 211
         
212 212
         $intervals      = array();
213
-        for ( $i = 1; $i <= 90; $i++ ) {
213
+        for ($i = 1; $i <= 90; $i++) {
214 214
             $intervals[$i] = $i;
215 215
         }
216 216
         
217
-        $interval       = $interval > 0 ? $interval : 1;
217
+        $interval = $interval > 0 ? $interval : 1;
218 218
         
219 219
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
220 220
         ?>
221
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_format_amount( 0 ); ?>" value="<?php echo wpinv_format_amount( $price );?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_package(), true ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
222
-        <?php if ( $item->is_package() ) { ?>
223
-        <span class="description"><?php _e( 'GD package item price can be edited only from GD payment manager.', 'invoicing' ); ?></span>
221
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_format_amount(0); ?>" value="<?php echo wpinv_format_amount($price); ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_package(), true); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
222
+        <?php if ($item->is_package()) { ?>
223
+        <span class="description"><?php _e('GD package item price can be edited only from GD payment manager.', 'invoicing'); ?></span>
224 224
         <?php } ?>
225 225
         </p>
226 226
         <p class="wpinv-row-is-recurring">
227 227
             <label for="wpinv_is_recurring">
228
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
229
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
228
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
229
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
230 230
             </label>
231 231
         </p>
232
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
233
-                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
234
-                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
232
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
233
+                <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
234
+                <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
235 235
                     'options'          => $intervals,
236 236
                     'name'             => 'wpinv_recurring_interval',
237 237
                     'id'               => 'wpinv_recurring_interval',
238 238
                     'selected'         => $interval,
239 239
                     'show_option_all'  => false,
240 240
                     'show_option_none' => false
241
-                ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
242
-                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
241
+                )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
242
+                <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
243 243
                 <span class="clear wpi-trial-clr"></span>
244 244
                 <label class="wpinv-free-trial" for="wpinv_free_trial">
245
-                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
246
-                    <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
245
+                    <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
246
+                    <?php echo __('Offer free trial for', 'invoicing'); ?>
247 247
                 </label>
248 248
                 <label class="wpinv-trial-interval" for="wpinv_trial_interval">
249
-                    <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
249
+                    <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
250 250
                 </label>
251 251
         </p>
252
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
253
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
252
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
253
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
254 254
         <?php
255 255
     }
256 256
     
257
-    public static function vat_rules( $post ) {
257
+    public static function vat_rules($post) {
258 258
         global $wpinv_euvat;
259 259
         
260
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
260
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
261 261
         ?>
262
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
263
-        <?php echo wpinv_html_select( array(
262
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
263
+        <?php echo wpinv_html_select(array(
264 264
                     'options'          => $wpinv_euvat->get_rules(),
265 265
                     'name'             => 'wpinv_vat_rules',
266 266
                     'id'               => 'wpinv_vat_rules',
@@ -268,19 +268,19 @@  discard block
 block discarded – undo
268 268
                     'show_option_all'  => false,
269 269
                     'show_option_none' => false,
270 270
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
271
-                ) ); ?>
271
+                )); ?>
272 272
         </p>
273
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
274
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
273
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
274
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
275 275
         <?php
276 276
     }
277 277
     
278
-    public static function vat_classes( $post ) {
278
+    public static function vat_classes($post) {
279 279
         global $wpinv_euvat;
280 280
         
281
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
281
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
282 282
         ?>
283
-        <p><?php echo wpinv_html_select( array(
283
+        <p><?php echo wpinv_html_select(array(
284 284
                     'options'          => $wpinv_euvat->get_all_classes(),
285 285
                     'name'             => 'wpinv_vat_class',
286 286
                     'id'               => 'wpinv_vat_class',
@@ -288,18 +288,18 @@  discard block
 block discarded – undo
288 288
                     'show_option_all'  => false,
289 289
                     'show_option_none' => false,
290 290
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
291
-                ) ); ?>
291
+                )); ?>
292 292
         </p>
293
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
293
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
294 294
         <?php
295 295
     }
296 296
     
297
-    public static function item_info( $post ) {
298
-        $item_type = wpinv_get_item_type( $post->ID );
299
-        do_action( 'wpinv_item_info_metabox_before', $post );
297
+    public static function item_info($post) {
298
+        $item_type = wpinv_get_item_type($post->ID);
299
+        do_action('wpinv_item_info_metabox_before', $post);
300 300
         ?>
301
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
302
-        <?php echo wpinv_html_select( array(
301
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
302
+        <?php echo wpinv_html_select(array(
303 303
                     'options'          => wpinv_get_item_types(),
304 304
                     'name'             => 'wpinv_item_type',
305 305
                     'id'               => 'wpinv_item_type',
@@ -308,93 +308,93 @@  discard block
 block discarded – undo
308 308
                     'show_option_none' => false,
309 309
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
310 310
                     //'disabled'         => $item_type == 'package' ? true : false,
311
-                ) ); ?>
311
+                )); ?>
312 312
         </p>
313
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( 'Standard: standard item type', 'invoicing' );?><br><?php _e( 'Fee: like Registration Fee, Signup Fee etc.', 'invoicing' );?></p>
313
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('Standard: standard item type', 'invoicing'); ?><br><?php _e('Fee: like Registration Fee, Signup Fee etc.', 'invoicing'); ?></p>
314 314
         <?php
315
-        do_action( 'wpinv_item_info_metabox_after', $post );
315
+        do_action('wpinv_item_info_metabox_after', $post);
316 316
     }
317 317
     
318
-    public static function save( $post_id, $data, $post ) {
319
-        $invoice        = new WPInv_Invoice( $post_id );
318
+    public static function save($post_id, $data, $post) {
319
+        $invoice        = new WPInv_Invoice($post_id);
320 320
         
321 321
         // Billing
322
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
323
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
324
-        $company        = sanitize_text_field( $data['wpinv_company'] );
325
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
326
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
327
-        $address        = sanitize_text_field( $data['wpinv_address'] );
328
-        $city           = sanitize_text_field( $data['wpinv_city'] );
329
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
330
-        $country        = sanitize_text_field( $data['wpinv_country'] );
331
-        $state          = sanitize_text_field( $data['wpinv_state'] );
322
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
323
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
324
+        $company        = sanitize_text_field($data['wpinv_company']);
325
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
326
+        $phone          = sanitize_text_field($data['wpinv_phone']);
327
+        $address        = sanitize_text_field($data['wpinv_address']);
328
+        $city           = sanitize_text_field($data['wpinv_city']);
329
+        $zip            = sanitize_text_field($data['wpinv_zip']);
330
+        $country        = sanitize_text_field($data['wpinv_country']);
331
+        $state          = sanitize_text_field($data['wpinv_state']);
332 332
         
333 333
         // Details
334
-        $status         = sanitize_text_field( $data['wpinv_status'] );
335
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
336
-        $number         = sanitize_text_field( $data['wpinv_number'] );
337
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
334
+        $status         = sanitize_text_field($data['wpinv_status']);
335
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
336
+        $number         = sanitize_text_field($data['wpinv_number']);
337
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
338 338
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
339 339
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
340 340
         
341
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
341
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
342 342
         
343
-        $invoice->set( 'due_date', $due_date );
344
-        $invoice->set( 'first_name', $first_name );
345
-        $invoice->set( 'last_name', $last_name );
346
-        $invoice->set( 'company', $company );
347
-        $invoice->set( 'vat_number', $vat_number );
348
-        $invoice->set( 'phone', $phone );
349
-        $invoice->set( 'address', $address );
350
-        $invoice->set( 'city', $city );
351
-        $invoice->set( 'zip', $zip );
352
-        $invoice->set( 'country', $country );
353
-        $invoice->set( 'state', $state );
354
-        $invoice->set( 'status', $status );
355
-        $invoice->set( 'number', $number );
343
+        $invoice->set('due_date', $due_date);
344
+        $invoice->set('first_name', $first_name);
345
+        $invoice->set('last_name', $last_name);
346
+        $invoice->set('company', $company);
347
+        $invoice->set('vat_number', $vat_number);
348
+        $invoice->set('phone', $phone);
349
+        $invoice->set('address', $address);
350
+        $invoice->set('city', $city);
351
+        $invoice->set('zip', $zip);
352
+        $invoice->set('country', $country);
353
+        $invoice->set('state', $state);
354
+        $invoice->set('status', $status);
355
+        $invoice->set('number', $number);
356 356
         //$invoice->set( 'discounts', $discounts );
357 357
         //$invoice->set( 'discount', $discount );
358
-        $invoice->set( 'ip', $ip );
358
+        $invoice->set('ip', $ip);
359 359
         $invoice->old_status = $_POST['original_post_status'];
360 360
         $invoice->currency = wpinv_get_currency();
361
-        if ( !empty( $data['wpinv_gateway'] ) ) {
362
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
361
+        if (!empty($data['wpinv_gateway'])) {
362
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
363 363
         }
364 364
         $saved = $invoice->save();
365 365
         
366 366
         // Check for payment notes
367
-        if ( !empty( $data['invoice_note'] ) ) {
368
-            $note               = wp_kses( $data['invoice_note'], array() );
369
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
367
+        if (!empty($data['invoice_note'])) {
368
+            $note               = wp_kses($data['invoice_note'], array());
369
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
370 370
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
371 371
         
372
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
372
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
373 373
         }
374 374
         
375 375
         // Update user address if empty.
376
-        if ( $saved && !empty( $invoice ) ) {
377
-            if ( $user_id = $invoice->get_user_id() ) {
378
-                $user_address = wpinv_get_user_address( $user_id, false );
376
+        if ($saved && !empty($invoice)) {
377
+            if ($user_id = $invoice->get_user_id()) {
378
+                $user_address = wpinv_get_user_address($user_id, false);
379 379
                 
380 380
                 if (empty($user_address['first_name'])) {
381
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
382
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
381
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
382
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
383 383
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
384
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
384
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
385 385
                 }
386 386
                 
387 387
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
388
-                    update_user_meta( $user_id, '_wpinv_address', $address );
389
-                    update_user_meta( $user_id, '_wpinv_city', $city );
390
-                    update_user_meta( $user_id, '_wpinv_state', $state );
391
-                    update_user_meta( $user_id, '_wpinv_country', $country );
392
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
393
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
388
+                    update_user_meta($user_id, '_wpinv_address', $address);
389
+                    update_user_meta($user_id, '_wpinv_city', $city);
390
+                    update_user_meta($user_id, '_wpinv_state', $state);
391
+                    update_user_meta($user_id, '_wpinv_country', $country);
392
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
393
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
394 394
                 }
395 395
             }
396 396
             
397
-            do_action( 'wpinv_invoice_metabox_saveed', $invoice );
397
+            do_action('wpinv_invoice_metabox_saveed', $invoice);
398 398
         }
399 399
         
400 400
         return $saved;
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +252 added lines, -252 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 = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'package_id':
33
-            $posts = get_posts( array(
33
+            $posts = get_posts(array(
34 34
                 'post_type'      => 'wpi_item',
35 35
                 'posts_per_page' => 1,
36 36
                 'post_status'    => 'any',
@@ -46,11 +46,11 @@  discard block
 block discarded – undo
46 46
                         'value' => 'package',
47 47
                     )
48 48
                 )
49
-            ) );
49
+            ));
50 50
             
51 51
             break;
52 52
         case 'item_id':
53
-            if ( empty( $value ) ) {
53
+            if (empty($value)) {
54 54
                 return false;
55 55
             }
56 56
             
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 'key'   => '_wpinv_post_id',
60 60
                 'value' => $value,
61 61
             );
62
-            if ( !empty( $type ) ) {
62
+            if (!empty($type)) {
63 63
                 $meta_query[] = array(
64 64
                     'key'   => '_wpinv_type',
65 65
                     'value' => $type,
@@ -72,14 +72,14 @@  discard block
 block discarded – undo
72 72
                 'post_status'    => 'any',
73 73
                 'orderby'        => 'ID',
74 74
                 'order'          => 'ASC',
75
-                'meta_query'     => array( $meta_query )
75
+                'meta_query'     => array($meta_query)
76 76
             );
77 77
             
78
-            $posts = get_posts( $args );
78
+            $posts = get_posts($args);
79 79
 
80 80
             break;
81 81
         case 'custom':
82
-            if ( empty( $value ) || empty( $type ) ) {
82
+            if (empty($value) || empty($type)) {
83 83
                 return false;
84 84
             }
85 85
             
@@ -99,10 +99,10 @@  discard block
 block discarded – undo
99 99
                 'post_status'    => 'any',
100 100
                 'orderby'        => 'ID',
101 101
                 'order'          => 'ASC',
102
-                'meta_query'     => array( $meta_query )
102
+                'meta_query'     => array($meta_query)
103 103
             );
104 104
             
105
-            $posts = get_posts( $args );
105
+            $posts = get_posts($args);
106 106
 
107 107
             break;
108 108
 
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
             return false;
111 111
     }
112 112
     
113
-    if ( !empty( $posts[0] ) ) {
114
-        return new WPInv_Item( $posts[0]->ID );
113
+    if (!empty($posts[0])) {
114
+        return new WPInv_Item($posts[0]->ID);
115 115
     }
116 116
 
117 117
     return false;
118 118
 }
119 119
 
120
-function wpinv_get_item( $item = 0 ) {
121
-    if ( is_numeric( $item ) ) {
122
-        $item = get_post( $item );
123
-        if ( ! $item || 'wpi_item' !== $item->post_type )
120
+function wpinv_get_item($item = 0) {
121
+    if (is_numeric($item)) {
122
+        $item = get_post($item);
123
+        if (!$item || 'wpi_item' !== $item->post_type)
124 124
             return null;
125 125
         return $item;
126 126
     }
@@ -133,136 +133,136 @@  discard block
 block discarded – undo
133 133
 
134 134
     $item = get_posts($args);
135 135
 
136
-    if ( $item ) {
136
+    if ($item) {
137 137
         return $item[0];
138 138
     }
139 139
 
140 140
     return null;
141 141
 }
142 142
 
143
-function wpinv_is_free_item( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_is_free_item($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $item = new WPInv_Item( $item_id );
148
+    $item = new WPInv_Item($item_id);
149 149
     
150 150
     return $item->is_free();
151 151
 }
152 152
 
153
-function wpinv_get_item_price( $item_id = 0 ) {
154
-    if( empty( $item_id ) ) {
153
+function wpinv_get_item_price($item_id = 0) {
154
+    if (empty($item_id)) {
155 155
         return false;
156 156
     }
157 157
 
158
-    $item = new WPInv_Item( $item_id );
158
+    $item = new WPInv_Item($item_id);
159 159
     
160 160
     return $item->get_price();
161 161
 }
162 162
 
163
-function wpinv_is_recurring_item( $item_id = 0 ) {
164
-    if( empty( $item_id ) ) {
163
+function wpinv_is_recurring_item($item_id = 0) {
164
+    if (empty($item_id)) {
165 165
         return false;
166 166
     }
167 167
 
168
-    $item = new WPInv_Item( $item_id );
168
+    $item = new WPInv_Item($item_id);
169 169
     
170 170
     return $item->is_recurring();
171 171
 }
172 172
 
173
-function wpinv_item_price( $item_id = 0 ) {
174
-    if( empty( $item_id ) ) {
173
+function wpinv_item_price($item_id = 0) {
174
+    if (empty($item_id)) {
175 175
         return false;
176 176
     }
177 177
 
178
-    $price = wpinv_get_item_price( $item_id );
179
-    $price = wpinv_price( wpinv_format_amount( $price ) );
178
+    $price = wpinv_get_item_price($item_id);
179
+    $price = wpinv_price(wpinv_format_amount($price));
180 180
     
181
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
181
+    return apply_filters('wpinv_item_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
185
-    if ( empty( $item_id ) ) {
184
+function wpinv_item_show_price($item_id = 0, $echo = true) {
185
+    if (empty($item_id)) {
186 186
         $item_id = get_the_ID();
187 187
     }
188 188
 
189
-    $price = wpinv_item_price( $item_id );
189
+    $price = wpinv_item_price($item_id);
190 190
 
191
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
191
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
192 192
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
193
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
193
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
194 194
 
195
-    if ( $echo ) {
195
+    if ($echo) {
196 196
         echo $formatted_price;
197 197
     } else {
198 198
         return $formatted_price;
199 199
     }
200 200
 }
201 201
 
202
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
203
-    if ( is_null( $amount_override ) ) {
204
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
202
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
203
+    if (is_null($amount_override)) {
204
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
205 205
     } else {
206 206
         $original_price = $amount_override;
207 207
     }
208 208
     
209 209
     $price = $original_price;
210 210
 
211
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
211
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
212 212
 }
213 213
 
214
-function wpinv_item_cpt_singular_name( $item_id ) {
215
-    if( empty( $item_id ) ) {
214
+function wpinv_item_cpt_singular_name($item_id) {
215
+    if (empty($item_id)) {
216 216
         return false;
217 217
     }
218 218
 
219
-    $item = new WPInv_Item( $item_id );
219
+    $item = new WPInv_Item($item_id);
220 220
     
221 221
     return $item->get_cpt_singular_name();
222 222
 }
223 223
 
224 224
 function wpinv_get_item_types() {
225 225
     $item_types = array(
226
-            'custom'    => __( 'Standard', 'invoicing' ),
227
-            'fee'       => __( 'Fee', 'invoicing' ),
226
+            'custom'    => __('Standard', 'invoicing'),
227
+            'fee'       => __('Fee', 'invoicing'),
228 228
         );
229
-    return apply_filters( 'wpinv_get_item_types', $item_types );
229
+    return apply_filters('wpinv_get_item_types', $item_types);
230 230
 }
231 231
 
232 232
 function wpinv_item_types() {
233 233
     $item_types = wpinv_get_item_types();
234 234
     
235
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
235
+    return (!empty($item_types) ? array_keys($item_types) : array());
236 236
 }
237 237
 
238
-function wpinv_get_item_type( $item_id ) {
239
-    if( empty( $item_id ) ) {
238
+function wpinv_get_item_type($item_id) {
239
+    if (empty($item_id)) {
240 240
         return false;
241 241
     }
242 242
 
243
-    $item = new WPInv_Item( $item_id );
243
+    $item = new WPInv_Item($item_id);
244 244
     
245 245
     return $item->get_type();
246 246
 }
247 247
 
248
-function wpinv_item_type( $item_id ) {
248
+function wpinv_item_type($item_id) {
249 249
     $item_types = wpinv_get_item_types();
250 250
     
251
-    $item_type = wpinv_get_item_type( $item_id );
251
+    $item_type = wpinv_get_item_type($item_id);
252 252
     
253
-    if ( empty( $item_type ) ) {
253
+    if (empty($item_type)) {
254 254
         $item_type = '-';
255 255
     }
256 256
     
257
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
257
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
258 258
 
259
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
259
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
260 260
 }
261 261
 
262
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
262
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
263 263
     global $wpinv_logs;
264 264
     
265
-    if ( empty( $wpinv_logs ) ) {
265
+    if (empty($wpinv_logs)) {
266 266
         return false;
267 267
     }
268 268
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         'log_type'		=> 'wpi_item'
272 272
     );
273 273
 
274
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
274
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
275 275
 
276 276
     $log_meta = array(
277 277
         'user_info'	=> $user_info,
@@ -281,247 +281,247 @@  discard block
 block discarded – undo
281 281
         'invoice_id'=> $invoice_id,
282 282
     );
283 283
 
284
-    $wpinv_logs->insert_log( $log_data, $log_meta );
284
+    $wpinv_logs->insert_log($log_data, $log_meta);
285 285
 }
286 286
 
287
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
288
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
287
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
288
+    if ('wpi_item' !== get_post_type($item_id))
289 289
         return;
290 290
 
291 291
     global $wpinv_logs;
292 292
     
293
-    if ( empty( $wpinv_logs ) ) {
293
+    if (empty($wpinv_logs)) {
294 294
         return false;
295 295
     }
296 296
 
297 297
     // Remove all log entries related to this item
298
-    $wpinv_logs->delete_logs( $item_id );
298
+    $wpinv_logs->delete_logs($item_id);
299 299
 }
300
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
300
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
301 301
 
302
-function wpinv_get_random_item( $post_ids = true ) {
303
-    wpinv_get_random_items( 1, $post_ids );
302
+function wpinv_get_random_item($post_ids = true) {
303
+    wpinv_get_random_items(1, $post_ids);
304 304
 }
305 305
 
306
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
307
-    if ( $post_ids ) {
308
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
306
+function wpinv_get_random_items($num = 3, $post_ids = true) {
307
+    if ($post_ids) {
308
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
309 309
     } else {
310
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
310
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
311 311
     }
312 312
     
313
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
313
+    $args = apply_filters('wpinv_get_random_items', $args);
314 314
     
315
-    return get_posts( $args );
315
+    return get_posts($args);
316 316
 }
317 317
 
318
-function wpinv_get_item_token( $url = '' ) {
318
+function wpinv_get_item_token($url = '') {
319 319
     $args    = array();
320
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
321
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
320
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
321
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
322 322
 
323
-    $parts   = parse_url( $url );
323
+    $parts   = parse_url($url);
324 324
     $options = array();
325 325
 
326
-    if ( isset( $parts['query'] ) ) {
327
-        wp_parse_str( $parts['query'], $query_args );
326
+    if (isset($parts['query'])) {
327
+        wp_parse_str($parts['query'], $query_args);
328 328
 
329
-        if ( ! empty( $query_args['o'] ) ) {
330
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
329
+        if (!empty($query_args['o'])) {
330
+            $options = explode(':', rawurldecode($query_args['o']));
331 331
 
332
-            if ( in_array( 'ip', $options ) ) {
332
+            if (in_array('ip', $options)) {
333 333
                 $args['ip'] = wpinv_get_ip();
334 334
             }
335 335
 
336
-            if ( in_array( 'ua', $options ) ) {
336
+            if (in_array('ua', $options)) {
337 337
                 $ua = wpinv_get_user_agent();
338
-                $args['user_agent'] = rawurlencode( $ua );
338
+                $args['user_agent'] = rawurlencode($ua);
339 339
             }
340 340
         }
341 341
     }
342 342
 
343
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
343
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
344 344
 
345 345
     $args['secret'] = $secret;
346 346
     $args['token']  = false;
347 347
 
348
-    $url   = add_query_arg( $args, $url );
349
-    $parts = parse_url( $url );
348
+    $url   = add_query_arg($args, $url);
349
+    $parts = parse_url($url);
350 350
 
351
-    if ( ! isset( $parts['path'] ) ) {
351
+    if (!isset($parts['path'])) {
352 352
         $parts['path'] = '';
353 353
     }
354 354
 
355
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
355
+    $token = md5($parts['path'] . '?' . $parts['query']);
356 356
 
357 357
     return $token;
358 358
 }
359 359
 
360
-function wpinv_validate_url_token( $url = '' ) {
360
+function wpinv_validate_url_token($url = '') {
361 361
     $ret   = false;
362
-    $parts = parse_url( $url );
362
+    $parts = parse_url($url);
363 363
 
364
-    if ( isset( $parts['query'] ) ) {
365
-        wp_parse_str( $parts['query'], $query_args );
364
+    if (isset($parts['query'])) {
365
+        wp_parse_str($parts['query'], $query_args);
366 366
 
367
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
367
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
368 368
             'item',
369 369
             'ttl',
370 370
             'token'
371
-        ) );
371
+        ));
372 372
 
373 373
         $remove = array();
374 374
 
375
-        foreach( $query_args as $key => $value ) {
376
-            if( false === in_array( $key, $allowed ) ) {
375
+        foreach ($query_args as $key => $value) {
376
+            if (false === in_array($key, $allowed)) {
377 377
                 $remove[] = $key;
378 378
             }
379 379
         }
380 380
 
381
-        if( ! empty( $remove ) ) {
382
-            $url = remove_query_arg( $remove, $url );
381
+        if (!empty($remove)) {
382
+            $url = remove_query_arg($remove, $url);
383 383
         }
384 384
 
385
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
386
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
385
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
386
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
387 387
         }
388 388
 
389
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
389
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
390 390
             $ret = true;
391 391
         }
392 392
 
393 393
     }
394 394
 
395
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
395
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
396 396
 }
397 397
 
398
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
398
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
399 399
     $cart_items = wpinv_get_cart_contents();
400 400
 
401 401
     $ret = false;
402 402
 
403
-    if ( is_array( $cart_items ) ) {
404
-        foreach ( $cart_items as $item ) {
405
-            if ( $item['id'] == $item_id ) {
403
+    if (is_array($cart_items)) {
404
+        foreach ($cart_items as $item) {
405
+            if ($item['id'] == $item_id) {
406 406
                 $ret = true;
407 407
                 break;
408 408
             }
409 409
         }
410 410
     }
411 411
 
412
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
412
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
413 413
 }
414 414
 
415
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
415
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
416 416
     $tax = 0;
417
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
418
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
419
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
417
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
418
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
419
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
420 420
 
421
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
421
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
422 422
     }
423 423
 
424
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
424
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
425 425
 }
426 426
 
427
-function wpinv_cart_item_price( $item ) {
427
+function wpinv_cart_item_price($item) {
428 428
     $use_taxes  = wpinv_use_taxes();
429
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
430
-    $price      = isset( $item['item_price'] ) ? wpinv_format_amount( $item['item_price'] ) : 0;
431
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
432
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
433
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
434
-    
435
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
436
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
429
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
430
+    $price      = isset($item['item_price']) ? wpinv_format_amount($item['item_price']) : 0;
431
+    $options    = isset($item['options']) ? $item['options'] : array();
432
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
433
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
434
+    
435
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
436
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
437 437
             $price += $tax;
438 438
         }
439 439
         
440
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
440
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
441 441
             $price -= $tax;
442 442
         }        
443 443
     }
444 444
 
445
-    $price = wpinv_price( wpinv_format_amount( $price ) );
445
+    $price = wpinv_price(wpinv_format_amount($price));
446 446
 
447
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
447
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
448 448
 }
449 449
 
450
-function wpinv_cart_item_subtotal( $item ) {
451
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
452
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
450
+function wpinv_cart_item_subtotal($item) {
451
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
452
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
453 453
 
454
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
454
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
455 455
 }
456 456
 
457
-function wpinv_cart_item_tax( $item ) {
457
+function wpinv_cart_item_tax($item) {
458 458
     $tax        = '';
459 459
     $tax_rate   = '';
460 460
     
461
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
462
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
463
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
464
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount( $tax_rate, 2 ) : '';
461
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
462
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
463
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
464
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_format_amount($tax_rate, 2) : '';
465 465
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
466 466
     }
467 467
     
468
-    $tax        = $tax . $tax_rate;
468
+    $tax = $tax . $tax_rate;
469 469
     
470
-    if ( $tax === '' ) {
470
+    if ($tax === '') {
471 471
         $tax = 0; // Zero tax
472 472
     }
473 473
 
474
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
474
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
475 475
 }
476 476
 
477
-function wpinv_get_cart_item_price( $item_id = 0, $options = array(), $remove_tax_from_inclusive = false ) {
477
+function wpinv_get_cart_item_price($item_id = 0, $options = array(), $remove_tax_from_inclusive = false) {
478 478
     $price = 0;
479
-    $variable_prices = wpinv_has_variable_prices( $item_id );
479
+    $variable_prices = wpinv_has_variable_prices($item_id);
480 480
 
481
-    if ( $variable_prices ) {
482
-        $prices = wpinv_get_variable_prices( $item_id );
481
+    if ($variable_prices) {
482
+        $prices = wpinv_get_variable_prices($item_id);
483 483
 
484
-        if ( $prices ) {
485
-            if( ! empty( $options ) ) {
486
-                $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
484
+        if ($prices) {
485
+            if (!empty($options)) {
486
+                $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
487 487
             } else {
488 488
                 $price = false;
489 489
             }
490 490
         }
491 491
     }
492 492
 
493
-    if( ! $variable_prices || false === $price ) {
493
+    if (!$variable_prices || false === $price) {
494 494
         // Get the standard Item price if not using variable prices
495
-        $price = wpinv_get_item_price( $item_id );
495
+        $price = wpinv_get_item_price($item_id);
496 496
     }
497 497
 
498
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
499
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
498
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
499
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
500 500
     }
501 501
 
502
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $options );
502
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $options);
503 503
 }
504 504
 
505
-function wpinv_get_cart_item_price_id( $item = array() ) {
506
-    if( isset( $item['item_number'] ) ) {
507
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
505
+function wpinv_get_cart_item_price_id($item = array()) {
506
+    if (isset($item['item_number'])) {
507
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
508 508
     } else {
509
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
509
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
510 510
     }
511 511
     return $price_id;
512 512
 }
513 513
 
514
-function wpinv_get_cart_item_price_name( $item = array() ) {
515
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
516
-    $prices   = wpinv_get_variable_prices( $item['id'] );
517
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
518
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
514
+function wpinv_get_cart_item_price_name($item = array()) {
515
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
516
+    $prices   = wpinv_get_variable_prices($item['id']);
517
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
518
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
519 519
 }
520 520
 
521
-function wpinv_get_cart_item_name( $item = array() ) {
522
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
521
+function wpinv_get_cart_item_name($item = array()) {
522
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
523 523
 
524
-    if ( empty( $item_title ) ) {
524
+    if (empty($item_title)) {
525 525
         $item_title = $item['id'];
526 526
     }
527 527
 
@@ -531,23 +531,23 @@  discard block
 block discarded – undo
531 531
     }
532 532
     */
533 533
 
534
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
534
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
535 535
 }
536 536
 
537
-function wpinv_has_variable_prices( $item_id = 0 ) {
537
+function wpinv_has_variable_prices($item_id = 0) {
538 538
     return false;
539 539
 }
540 540
 
541
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
541
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
542 542
     $cart_items = wpinv_get_cart_contents();
543 543
 
544
-    if ( !is_array( $cart_items ) ) {
544
+    if (!is_array($cart_items)) {
545 545
         return false; // Empty cart
546 546
     } else {
547
-        foreach ( $cart_items as $position => $item ) {
548
-            if ( $item['id'] == $item_id ) {
549
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
550
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
547
+        foreach ($cart_items as $position => $item) {
548
+            if ($item['id'] == $item_id) {
549
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
550
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
551 551
                         return $position;
552 552
                     }
553 553
                 } else {
@@ -560,80 +560,80 @@  discard block
 block discarded – undo
560 560
     return false; // Not found
561 561
 }
562 562
 
563
-function wpinv_get_cart_item_quantity( $item ) {
564
-    if ( wpinv_item_quantities_enabled() ) {
565
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
563
+function wpinv_get_cart_item_quantity($item) {
564
+    if (wpinv_item_quantities_enabled()) {
565
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
566 566
     } else {
567 567
         $quantity = 1;
568 568
     }
569 569
     
570
-    if ( $quantity < 1 ) {
570
+    if ($quantity < 1) {
571 571
         $quantity = 1;
572 572
     }
573 573
     
574
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
574
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
575 575
 }
576 576
 
577
-function wpinv_get_item_suffix( $item, $html = true ) {
578
-    if ( empty( $item ) ) {
577
+function wpinv_get_item_suffix($item, $html = true) {
578
+    if (empty($item)) {
579 579
         return NULL;
580 580
     }
581 581
     
582
-    if ( is_int( $item ) ) {
583
-        $item = new WPInv_Item( $item );
582
+    if (is_int($item)) {
583
+        $item = new WPInv_Item($item);
584 584
     }
585 585
     
586
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
586
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
587 587
         return NULL;
588 588
     }
589 589
     
590
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
590
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
591 591
     
592
-    if ( !$html && $suffix ) {
593
-        $suffix = strip_tags( $suffix );
592
+    if (!$html && $suffix) {
593
+        $suffix = strip_tags($suffix);
594 594
     }
595 595
     
596
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
596
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
597 597
 }
598 598
 
599
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
600
-    if ( empty( $item ) ) {
599
+function wpinv_remove_item($item = 0, $force_delete = false) {
600
+    if (empty($item)) {
601 601
         return NULL;
602 602
     }
603 603
     
604
-    if ( is_int( $item ) ) {
605
-        $item = new WPInv_Item( $item );
604
+    if (is_int($item)) {
605
+        $item = new WPInv_Item($item);
606 606
     }
607 607
     
608
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
608
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
609 609
         return NULL;
610 610
     }
611 611
     
612
-    do_action( 'wpinv_pre_delete_item', $item );
612
+    do_action('wpinv_pre_delete_item', $item);
613 613
 
614
-    wp_delete_post( $item->ID, $force_delete );
614
+    wp_delete_post($item->ID, $force_delete);
615 615
 
616
-    do_action( 'wpinv_post_delete_item', $item );
616
+    do_action('wpinv_post_delete_item', $item);
617 617
 }
618 618
 
619
-function wpinv_can_delete_item( $post_id ) {
620
-    $return = current_user_can( 'manage_options' ) ? true : false;
619
+function wpinv_can_delete_item($post_id) {
620
+    $return = current_user_can('manage_options') ? true : false;
621 621
     
622
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
622
+    if ($return && wpinv_item_in_use($post_id)) {
623 623
         $return = false; // Don't delete item already use in invoices.
624 624
     }
625 625
     
626
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
626
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
627 627
 }
628 628
 
629 629
 function wpinv_admin_action_delete() {
630 630
     $screen = get_current_screen();
631 631
     
632
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
632
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
633 633
         $post_ids = array();
634 634
         
635
-        foreach ( $_REQUEST['post'] as $post_id ) {
636
-            if ( !wpinv_can_delete_item( $post_id ) ) {
635
+        foreach ($_REQUEST['post'] as $post_id) {
636
+            if (!wpinv_can_delete_item($post_id)) {
637 637
                 continue;
638 638
             }
639 639
             
@@ -643,83 +643,83 @@  discard block
 block discarded – undo
643 643
         $_REQUEST['post'] = $post_ids;
644 644
     }
645 645
 }
646
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
647
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
646
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
647
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
648 648
 
649
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
650
-    if ( $post->post_type == 'wpi_item' ) {
651
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
649
+function wpinv_check_delete_item($check, $post, $force_delete) {
650
+    if ($post->post_type == 'wpi_item') {
651
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
652 652
             return true;
653 653
         }
654 654
     }
655 655
     
656 656
     return $check;
657 657
 }
658
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
658
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
659 659
 
660
-function wpinv_item_in_use( $item_id ) {
660
+function wpinv_item_in_use($item_id) {
661 661
     global $wpdb, $wpi_items_in_use;
662 662
     
663
-    if ( !$item_id > 0 ) {
663
+    if (!$item_id > 0) {
664 664
         return false;
665 665
     }
666 666
     
667
-    if ( !empty( $wpi_items_in_use ) ) {
668
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
667
+    if (!empty($wpi_items_in_use)) {
668
+        if (isset($wpi_items_in_use[$item_id])) {
669 669
             return $wpi_items_in_use[$item_id];
670 670
         }
671 671
     } else {
672 672
         $wpi_items_in_use = array();
673 673
     }
674 674
     
675
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
675
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
676 676
     
677
-    $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 )";
678
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
677
+    $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 )";
678
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
679 679
     
680 680
     $wpi_items_in_use[$item_id] = $in_use;
681 681
     
682 682
     return $in_use;
683 683
 }
684 684
 
685
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
685
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
686 686
     // Set some defaults
687 687
     $defaults = array(
688
-        'type'               => 'custom',                                                // Optional. Item type. Default 'custom'.
689
-        'item_id'            => 0,                                                       // Required. Any integer number. Must be unique within item type.
690
-        'title'              => '',                                                      // Required. Item title.
691
-        'price'              => '0.00',                                                  // Optional. Item price. Default '0.00'.
692
-        'status'             => 'pending',                                               // Optional. pending, publish
693
-        'vat_rule'           => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
694
-        'cpt_singular_name'  => '',                                                      // Optional. Sub title for item. Should be singular.
695
-        'cpt_name'           => '',                                                      // Optional. Sub title for item. Should be plural.
696
-        'is_recurring'       => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
-        'recurring_period'   => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
-        'recurring_interval' => 0,                                                       // Optional. Integer value between 1 - 90.
699
-        'recurring_limit'    => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
700
-        'free_trial'         => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
701
-        'trial_period'       => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
-        'trial_interval'     => 0,                                                       // Optional. Any integer number.
703
-        'excerpt'            => '',                                                      // Optional. Item short description
688
+        'type'               => 'custom', // Optional. Item type. Default 'custom'.
689
+        'item_id'            => 0, // Required. Any integer number. Must be unique within item type.
690
+        'title'              => '', // Required. Item title.
691
+        'price'              => '0.00', // Optional. Item price. Default '0.00'.
692
+        'status'             => 'pending', // Optional. pending, publish
693
+        'vat_rule'           => 'digital', // Optional. digital => Digital item, physical => Physical item
694
+        'cpt_singular_name'  => '', // Optional. Sub title for item. Should be singular.
695
+        'cpt_name'           => '', // Optional. Sub title for item. Should be plural.
696
+        'is_recurring'       => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
697
+        'recurring_period'   => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
698
+        'recurring_interval' => 0, // Optional. Integer value between 1 - 90.
699
+        'recurring_limit'    => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
700
+        'free_trial'         => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
701
+        'trial_period'       => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
702
+        'trial_interval'     => 0, // Optional. Any integer number.
703
+        'excerpt'            => '', // Optional. Item short description
704 704
     );
705 705
     
706
-    $data = wp_parse_args( $args, $defaults );
706
+    $data = wp_parse_args($args, $defaults);
707 707
     
708
-    if ( empty( $data['item_id'] ) ) {
709
-        if ( $wp_error ) {
710
-            return new WP_Error( 'invalid_item_id', __( 'Invalid item ID.' ) );
708
+    if (empty($data['item_id'])) {
709
+        if ($wp_error) {
710
+            return new WP_Error('invalid_item_id', __('Invalid item ID.'));
711 711
         } else {
712 712
             return false;
713 713
         }
714 714
     }
715 715
     
716
-    if ( empty( $data['type'] ) ) {
716
+    if (empty($data['type'])) {
717 717
         $data['type'] = 'custom';
718 718
     }
719 719
     
720
-    $item = wpinv_get_item_by( 'item_id', $data['item_id'], $data['type'] );
720
+    $item = wpinv_get_item_by('item_id', $data['item_id'], $data['type']);
721 721
         
722
-    if ( !$force_update && !empty( $item ) ) {
722
+    if (!$force_update && !empty($item)) {
723 723
         return $item;
724 724
     }
725 725
         
@@ -728,18 +728,18 @@  discard block
 block discarded – undo
728 728
     $meta['post_id']            = $data['item_id'];
729 729
     $meta['cpt_singular_name']  = $data['cpt_singular_name'];
730 730
     $meta['cpt_name']           = $data['cpt_name'];
731
-    $meta['price']              = wpinv_format_amount( $data['price'], NULL, true );
731
+    $meta['price']              = wpinv_format_amount($data['price'], NULL, true);
732 732
     $meta['vat_rule']           = $data['vat_rule'];
733 733
     $meta['vat_class']          = '_standard';
734 734
     
735
-    if ( !empty( $data['is_recurring'] ) ) {
735
+    if (!empty($data['is_recurring'])) {
736 736
         $meta['is_recurring']       = $data['is_recurring'];
737 737
         $meta['recurring_period']   = $data['recurring_period'];
738
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
739
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
738
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
739
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
740 740
         $meta['free_trial']         = $data['free_trial'];
741 741
         $meta['trial_period']       = $data['trial_period'];
742
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
742
+        $meta['trial_interval']     = absint($data['trial_interval']);
743 743
     } else {
744 744
         $meta['is_recurring']       = 0;
745 745
         $meta['recurring_period']   = '';
@@ -750,18 +750,18 @@  discard block
 block discarded – undo
750 750
         $meta['trial_interval']     = '';
751 751
     }
752 752
     
753
-    $post_data  = array( 
753
+    $post_data = array( 
754 754
         'post_title'    => $data['title'],
755 755
         'post_excerpt'  => $data['excerpt'],
756 756
         'post_status'   => $data['status'],
757 757
         'meta'          => $meta
758 758
     );
759 759
 
760
-    if ( !empty( $item ) ) {
761
-        $item->update( $post_data, $wp_error );
760
+    if (!empty($item)) {
761
+        $item->update($post_data, $wp_error);
762 762
     } else {
763 763
         $item = new WPInv_Item();
764
-        $item->create( $post_data, $wp_error );
764
+        $item->create($post_data, $wp_error);
765 765
     }
766 766
     
767 767
     return $item;
Please login to merge, or discard this patch.