Passed
Pull Request — master (#126)
by Kiran
03:46
created
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float)$invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -75,44 +75,44 @@  discard block
 block discarded – undo
75 75
                                         </td>
76 76
                                         <td class="title">
77 77
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
                                             </div>
134 134
                                         </td>
135 135
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
136
-                                        <?php if ( $item_quantities ) { ?>
136
+                                        <?php if ($item_quantities) { ?>
137 137
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
138 138
                                         <?php } ?>
139 139
                                         <td class="total"></td>
140
-                                        <?php if ( $use_taxes ) { ?>
140
+                                        <?php if ($use_taxes) { ?>
141 141
                                         <td class="tax"></td>
142 142
                                         <?php } ?>
143 143
                                         <td class="action"></td>
@@ -150,29 +150,29 @@  discard block
 block discarded – undo
150 150
                         <td colspan="<?php echo $cols; ?>"></td>
151 151
                     </tr>
152 152
                     <tr class="totals">
153
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
153
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
154 154
                         <td colspan="4">
155 155
                             <table cellspacing="0" cellpadding="0">
156 156
                                 <tr class="subtotal">
157
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
158
-                                    <td class="total"><?php echo $subtotal;?></td>
157
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
158
+                                    <td class="total"><?php echo $subtotal; ?></td>
159 159
                                     <td class="action"></td>
160 160
                                 </tr>
161 161
                                 <tr class="discount">
162
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
163
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
162
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
163
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
164 164
                                     <td class="action"></td>
165 165
                                 </tr>
166
-                                <?php if ( $use_taxes ) { ?>
166
+                                <?php if ($use_taxes) { ?>
167 167
                                 <tr class="tax">
168
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
169
-                                    <td class="total"><?php echo $tax;?></td>
168
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
169
+                                    <td class="total"><?php echo $tax; ?></td>
170 170
                                     <td class="action"></td>
171 171
                                 </tr>
172 172
                                 <?php } ?>
173 173
                                 <tr class="total">
174
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
175
-                                    <td class="total"><?php echo $total;?></td>
174
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
175
+                                    <td class="total"><?php echo $total; ?></td>
176 176
                                     <td class="action"></td>
177 177
                                 </tr>
178 178
                             </table>
@@ -183,89 +183,89 @@  discard block
 block discarded – undo
183 183
             <div class="wpinv-actions">
184 184
                 <?php ob_start(); ?>
185 185
                 <?php
186
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
187
-                        if ( !$invoice->is_recurring() ) {
188
-                            echo wpinv_item_dropdown( array(
186
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
187
+                        if (!$invoice->is_recurring()) {
188
+                            echo wpinv_item_dropdown(array(
189 189
                                 'name'             => 'wpinv_invoice_item',
190 190
                                 'id'               => 'wpinv_invoice_item',
191 191
                                 'show_recurring'   => true,
192
-                            ) );
192
+                            ));
193 193
                     ?>
194
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
194
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
195 195
                     <?php } ?>
196
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
197
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
196
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
197
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
198 198
             </div>
199 199
         </div>
200 200
         <?php
201 201
     }
202 202
 
203
-    public static function prices( $post ) {        
203
+    public static function prices($post) {        
204 204
         $symbol         = wpinv_currency_symbol();
205 205
         $position       = wpinv_currency_position();
206
-        $item           = new WPInv_Item( $post->ID );
206
+        $item           = new WPInv_Item($post->ID);
207 207
 
208 208
         $price          = $item->get_price();
209 209
         $is_recurring   = $item->is_recurring();
210 210
         $period         = $item->get_recurring_period();
211
-        $interval       = absint( $item->get_recurring_interval() );
212
-        $times          = absint( $item->get_recurring_limit() );
211
+        $interval       = absint($item->get_recurring_interval());
212
+        $times          = absint($item->get_recurring_limit());
213 213
         $free_trial     = $item->has_free_trial();
214 214
         $trial_interval = $item->get_trial_interval();
215 215
         $trial_period   = $item->get_trial_period();
216 216
 
217 217
         $intervals      = array();
218
-        for ( $i = 1; $i <= 90; $i++ ) {
218
+        for ($i = 1; $i <= 90; $i++) {
219 219
             $intervals[$i] = $i;
220 220
         }
221 221
 
222
-        $interval       = $interval > 0 ? $interval : 1;
222
+        $interval = $interval > 0 ? $interval : 1;
223 223
 
224 224
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
225 225
         ?>
226
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
227
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
226
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
227
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
228 228
         </p>
229 229
         <p class="wpinv-row-is-recurring">
230 230
             <label for="wpinv_is_recurring">
231
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
232
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
231
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
232
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
233 233
             </label>
234
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
234
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
235 235
         </p>
236
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
237
-            <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>
238
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
236
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
237
+            <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>
238
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
239 239
                 'options'          => $intervals,
240 240
                 'name'             => 'wpinv_recurring_interval',
241 241
                 'id'               => 'wpinv_recurring_interval',
242 242
                 'selected'         => $interval,
243 243
                 'show_option_all'  => false,
244 244
                 'show_option_none' => false
245
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
246
-            <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>
245
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
246
+            <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>
247 247
             <span class="clear wpi-trial-clr"></span>
248 248
             <label class="wpinv-free-trial" for="wpinv_free_trial">
249
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
250
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
249
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
250
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
251 251
             </label>
252 252
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
253
-                <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>
253
+                <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>
254 254
             </label>
255
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
255
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
256 256
         </p>
257
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
258
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
257
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
258
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
259 259
         <?php
260 260
     }
261 261
 
262
-    public static function vat_rules( $post ) {
262
+    public static function vat_rules($post) {
263 263
         global $wpinv_euvat;
264 264
 
265
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
265
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
266 266
         ?>
267
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
268
-        <?php echo wpinv_html_select( array(
267
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
268
+        <?php echo wpinv_html_select(array(
269 269
                     'options'          => $wpinv_euvat->get_rules(),
270 270
                     'name'             => 'wpinv_vat_rules',
271 271
                     'id'               => 'wpinv_vat_rules',
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
                     'show_option_all'  => false,
274 274
                     'show_option_none' => false,
275 275
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                ) ); ?>
276
+                )); ?>
277 277
         </p>
278
-        <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>
279
-        <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>
278
+        <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>
279
+        <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>
280 280
         <?php
281 281
     }
282 282
 
283
-    public static function vat_classes( $post ) {
283
+    public static function vat_classes($post) {
284 284
         global $wpinv_euvat;
285 285
         
286
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
286
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
287 287
         ?>
288
-        <p><?php echo wpinv_html_select( array(
288
+        <p><?php echo wpinv_html_select(array(
289 289
                     'options'          => $wpinv_euvat->get_all_classes(),
290 290
                     'name'             => 'wpinv_vat_class',
291 291
                     'id'               => 'wpinv_vat_class',
@@ -293,18 +293,18 @@  discard block
 block discarded – undo
293 293
                     'show_option_all'  => false,
294 294
                     'show_option_none' => false,
295 295
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
296
-                ) ); ?>
296
+                )); ?>
297 297
         </p>
298
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
298
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
299 299
         <?php
300 300
     }
301 301
 
302
-    public static function item_info( $post ) {
303
-        $item_type = wpinv_get_item_type( $post->ID );
304
-        do_action( 'wpinv_item_info_metabox_before', $post );
302
+    public static function item_info($post) {
303
+        $item_type = wpinv_get_item_type($post->ID);
304
+        do_action('wpinv_item_info_metabox_before', $post);
305 305
         ?>
306
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
307
-        <?php echo wpinv_html_select( array(
306
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
307
+        <?php echo wpinv_html_select(array(
308 308
                     'options'          => wpinv_get_item_types(),
309 309
                     'name'             => 'wpinv_item_type',
310 310
                     'id'               => 'wpinv_item_type',
@@ -312,114 +312,114 @@  discard block
 block discarded – undo
312 312
                     'show_option_all'  => false,
313 313
                     'show_option_none' => false,
314 314
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
315
-                ) ); ?>
315
+                )); ?>
316 316
         </p>
317
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
317
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
318 318
         <?php
319
-        do_action( 'wpinv_item_info_metabox_after', $post );
319
+        do_action('wpinv_item_info_metabox_after', $post);
320 320
     }
321 321
 
322
-    public static function meta_values( $post ) {
323
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
322
+    public static function meta_values($post) {
323
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
324 324
             'type',
325 325
             'custom_id'
326
-        ) );
326
+        ));
327 327
 
328
-        if ( empty( $meta_keys ) ) {
328
+        if (empty($meta_keys)) {
329 329
             return;
330 330
         }
331 331
 
332
-        do_action( 'wpinv_meta_values_metabox_before', $post );
332
+        do_action('wpinv_meta_values_metabox_before', $post);
333 333
 
334
-        foreach ( $meta_keys as $meta_key ) {
334
+        foreach ($meta_keys as $meta_key) {
335 335
             ?>
336
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
336
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
337 337
             <?php 
338 338
         }
339 339
 
340
-        do_action( 'wpinv_meta_values_metabox_after', $post );
340
+        do_action('wpinv_meta_values_metabox_after', $post);
341 341
     }
342 342
 
343
-    public static function save( $post_id, $data, $post ) {
344
-        $invoice        = new WPInv_Invoice( $post_id );
343
+    public static function save($post_id, $data, $post) {
344
+        $invoice        = new WPInv_Invoice($post_id);
345 345
 
346 346
         // Billing
347
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
348
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
349
-        $company        = sanitize_text_field( $data['wpinv_company'] );
350
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
351
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
352
-        $address        = sanitize_text_field( $data['wpinv_address'] );
353
-        $city           = sanitize_text_field( $data['wpinv_city'] );
354
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
355
-        $country        = sanitize_text_field( $data['wpinv_country'] );
356
-        $state          = sanitize_text_field( $data['wpinv_state'] );
347
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
348
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
349
+        $company        = sanitize_text_field($data['wpinv_company']);
350
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
351
+        $phone          = sanitize_text_field($data['wpinv_phone']);
352
+        $address        = sanitize_text_field($data['wpinv_address']);
353
+        $city           = sanitize_text_field($data['wpinv_city']);
354
+        $zip            = sanitize_text_field($data['wpinv_zip']);
355
+        $country        = sanitize_text_field($data['wpinv_country']);
356
+        $state          = sanitize_text_field($data['wpinv_state']);
357 357
 
358 358
         // Details
359
-        $status         = sanitize_text_field( $data['wpinv_status'] );
360
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
361
-        $number         = sanitize_text_field( $data['wpinv_number'] );
362
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
359
+        $status         = sanitize_text_field($data['wpinv_status']);
360
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
361
+        $number         = sanitize_text_field($data['wpinv_number']);
362
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
363 363
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
364 364
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
365 365
 
366
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
366
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
367 367
 
368
-        $invoice->set( 'due_date', $due_date );
369
-        $invoice->set( 'first_name', $first_name );
370
-        $invoice->set( 'last_name', $last_name );
371
-        $invoice->set( 'company', $company );
372
-        $invoice->set( 'vat_number', $vat_number );
373
-        $invoice->set( 'phone', $phone );
374
-        $invoice->set( 'address', $address );
375
-        $invoice->set( 'city', $city );
376
-        $invoice->set( 'zip', $zip );
377
-        $invoice->set( 'country', $country );
378
-        $invoice->set( 'state', $state );
379
-        $invoice->set( 'status', $status );
368
+        $invoice->set('due_date', $due_date);
369
+        $invoice->set('first_name', $first_name);
370
+        $invoice->set('last_name', $last_name);
371
+        $invoice->set('company', $company);
372
+        $invoice->set('vat_number', $vat_number);
373
+        $invoice->set('phone', $phone);
374
+        $invoice->set('address', $address);
375
+        $invoice->set('city', $city);
376
+        $invoice->set('zip', $zip);
377
+        $invoice->set('country', $country);
378
+        $invoice->set('state', $state);
379
+        $invoice->set('status', $status);
380 380
         //$invoice->set( 'number', $number );
381 381
         //$invoice->set( 'discounts', $discounts );
382 382
         //$invoice->set( 'discount', $discount );
383
-        $invoice->set( 'ip', $ip );
383
+        $invoice->set('ip', $ip);
384 384
         $invoice->old_status = $_POST['original_post_status'];
385 385
         $invoice->currency = wpinv_get_currency();
386
-        if ( !empty( $data['wpinv_gateway'] ) ) {
387
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
386
+        if (!empty($data['wpinv_gateway'])) {
387
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
388 388
         }
389 389
         $saved = $invoice->save();
390 390
 
391 391
         // Check for payment notes
392
-        if ( !empty( $data['invoice_note'] ) ) {
393
-            $note               = wp_kses( $data['invoice_note'], array() );
394
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
392
+        if (!empty($data['invoice_note'])) {
393
+            $note               = wp_kses($data['invoice_note'], array());
394
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
395 395
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
396 396
 
397
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
397
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
398 398
         }
399 399
 
400 400
         // Update user address if empty.
401
-        if ( $saved && !empty( $invoice ) ) {
402
-            if ( $user_id = $invoice->get_user_id() ) {
403
-                $user_address = wpinv_get_user_address( $user_id, false );
401
+        if ($saved && !empty($invoice)) {
402
+            if ($user_id = $invoice->get_user_id()) {
403
+                $user_address = wpinv_get_user_address($user_id, false);
404 404
 
405 405
                 if (empty($user_address['first_name'])) {
406
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
406
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
409
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
409
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
410 410
                 }
411 411
 
412 412
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
413
-                    update_user_meta( $user_id, '_wpinv_address', $address );
414
-                    update_user_meta( $user_id, '_wpinv_city', $city );
415
-                    update_user_meta( $user_id, '_wpinv_state', $state );
416
-                    update_user_meta( $user_id, '_wpinv_country', $country );
417
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
418
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
413
+                    update_user_meta($user_id, '_wpinv_address', $address);
414
+                    update_user_meta($user_id, '_wpinv_city', $city);
415
+                    update_user_meta($user_id, '_wpinv_state', $state);
416
+                    update_user_meta($user_id, '_wpinv_country', $country);
417
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
418
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
419 419
                 }
420 420
             }
421 421
 
422
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
422
+            do_action('wpinv_invoice_metabox_saved', $invoice);
423 423
         }
424 424
 
425 425
         return $saved;
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +92 added lines, -92 removed lines patch added patch discarded remove patch
@@ -1,30 +1,30 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         $currency_symbol    = wpinv_currency_symbol();
10 10
         $statuses           = wpinv_get_invoice_statuses();
11 11
         
12
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
13
-        $invoice            = new WPInv_Invoice( $post_id );
12
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
13
+        $invoice            = new WPInv_Invoice($post_id);
14 14
         
15
-        $status             = $invoice->get_status( false ); // Current status    
15
+        $status             = $invoice->get_status(false); // Current status    
16 16
         $discount           = $invoice->get_discount();
17 17
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
18 18
         $invoice_number     = $invoice->get_number();
19 19
         
20 20
         $date_created       = $invoice->get_created_date();
21
-        $datetime_created   = strtotime( $date_created );
22
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
21
+        $datetime_created   = strtotime($date_created);
22
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
23 23
         $date_completed     = $invoice->get_completed_date();
24
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
25
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
26
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
27
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
24
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
25
+        $title['status'] = __('Invoice Status:', 'invoicing');
26
+        $title['number'] = __('Invoice Number:', 'invoicing');
27
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
28 28
         
29 29
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
30 30
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -34,35 +34,35 @@  discard block
 block discarded – undo
34 34
 <div class="gdmbx2-wrap form-table">
35 35
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
36 36
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-created">
37
-            <div class="gdmbx-th"><label><?php _e( 'Date Created:', 'invoicing' );?></label></div>
38
-            <div class="gdmbx-td"><?php echo $date_created;?></div>
37
+            <div class="gdmbx-th"><label><?php _e('Date Created:', 'invoicing'); ?></label></div>
38
+            <div class="gdmbx-td"><?php echo $date_created; ?></div>
39 39
         </div>
40
-        <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft' ) ) ) ) { ?>
40
+        <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft')))) { ?>
41 41
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
42
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
42
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
43 43
             <div class="gdmbx-td">
44
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
44
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
45 45
             </div>
46 46
         </div>
47 47
         <?php } ?>
48
-        <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?>
49
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
48
+        <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?>
49
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
50 50
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
51
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
52
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
51
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
52
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
53 53
         </div>
54 54
         <?php } ?>
55
-        <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?>
55
+        <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?>
56 56
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed">
57
-            <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div>
58
-            <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div>
57
+            <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div>
58
+            <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div>
59 59
         </div>
60 60
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
61 61
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
62 62
             <div class="gdmbx-td">
63 63
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select">
64
-                    <?php foreach ( $statuses as $value => $label ) { ?>
65
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
64
+                    <?php foreach ($statuses as $value => $label) { ?>
65
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
66 66
                     <?php } ?>
67 67
                 </select>
68 68
             </div>
@@ -70,117 +70,117 @@  discard block
 block discarded – undo
70 70
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
71 71
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
72 72
             <div class="gdmbx-td">
73
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
73
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
74 74
             </div>
75 75
         </div>
76
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id );
76
+        <?php do_action('wpinv_meta_box_details_inner', $post_id);
77 77
         $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id);
78 78
         ?>
79
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?>
79
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?>
80 80
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
81
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
81
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
82 82
             <div class="gdmbx-td">
83
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
83
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
84 84
             </div>
85 85
         </div>
86 86
         <?php } ?>
87 87
     </div>
88 88
 </div>
89 89
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
90
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
90
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
91 91
         <select id="wpi_save_send" name="wpi_save_send">
92
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
93
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
92
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
93
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
94 94
         </select>
95 95
     </p>
96 96
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
97 97
 </div>
98
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
98
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
99 99
         <?php
100 100
     }
101 101
     
102
-    public static function resend_invoice( $post ) {
102
+    public static function resend_invoice($post) {
103 103
         global $wpi_mb_invoice;
104 104
         
105
-        if ( empty( $wpi_mb_invoice ) ) {
105
+        if (empty($wpi_mb_invoice)) {
106 106
             return;
107 107
         }
108 108
         
109 109
         $text = array(
110
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
111
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
110
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
111
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
112 112
         );
113 113
             
114 114
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
115
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
115
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
116 116
         
117
-        if ( $email = $wpi_mb_invoice->get_email() ) {
117
+        if ($email = $wpi_mb_invoice->get_email()) {
118 118
             $email_actions = array();
119
-            $email_actions['email_url']      = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) );
120
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
119
+            $email_actions['email_url']      = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)));
120
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
121 121
             
122
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
122
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
123 123
         ?>
124 124
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
125
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
126
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
127
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
125
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
126
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
127
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
128 128
         <?php } ?>
129 129
         <?php
130 130
         }
131 131
         
132
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
132
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
133 133
     }
134 134
     
135
-    public static function subscriptions( $post ) {
136
-        $invoice = wpinv_get_invoice( $post->ID );
135
+    public static function subscriptions($post) {
136
+        $invoice = wpinv_get_invoice($post->ID);
137 137
 
138
-        if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
139
-            $subscription = wpinv_get_subscription( $invoice );
138
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
139
+            $subscription = wpinv_get_subscription($invoice);
140 140
 
141
-            if ( empty( $subscription ) ) {
141
+            if (empty($subscription)) {
142 142
                 ?>
143
-                <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p>
143
+                <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p>
144 144
                 <?php
145 145
                 return;
146 146
             }
147
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency );
148
-            $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
149
-            $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
147
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
148
+            $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency;
149
+            $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id));
150 150
             $payments = $subscription->get_child_payments();
151 151
             ?>
152 152
             <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p>
153
-            <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?>
153
+            <?php if (!empty($subscription) && !empty($subscription->id)) { ?>
154 154
                 <p class="wpi-meta-row wpi-sub-id">
155
-                    <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
155
+                    <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
156 156
             <?php } ?>
157 157
             <p class="wpi-meta-row wpi-bill-cycle">
158
-                <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?>
158
+                <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?>
159 159
             </p>
160 160
             <p class="wpi-meta-row wpi-billed-times">
161
-                <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?>
161
+                <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?>
162 162
             </p>
163 163
             <p class="wpi-meta-row wpi-start-date">
164
-                <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
164
+                <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?>
165 165
             </p>
166 166
             <p class="wpi-meta-row wpi-end-date">
167
-                <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?>
167
+                <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?>
168 168
             </p>
169
-            <?php if ( $subscription->status ) { ?>
169
+            <?php if ($subscription->status) { ?>
170 170
                 <p class="wpi-meta-row wpi-sub-status">
171
-                    <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
171
+                    <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
172 172
                 </p>
173 173
             <?php } ?>
174
-            <?php if ( !empty( $payments ) ) { ?>
175
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
174
+            <?php if (!empty($payments)) { ?>
175
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
176 176
                 <ul id="wpi-sub-payments">
177
-                <?php foreach ( $payments as $payment ) {
177
+                <?php foreach ($payments as $payment) {
178 178
                     $invoice_id = $payment->ID;
179 179
                     ?>
180 180
                     <li>
181
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
182
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
183
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
181
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
182
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
183
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
184 184
                     </li>
185 185
                 <?php } ?>
186 186
                 </ul>
@@ -188,50 +188,50 @@  discard block
 block discarded – undo
188 188
         }
189 189
     }
190 190
     
191
-    public static function renewals( $post ) {
192
-        $invoice = wpinv_get_invoice( $post->ID );
191
+    public static function renewals($post) {
192
+        $invoice = wpinv_get_invoice($post->ID);
193 193
         
194
-        if ( wpinv_is_subscription_payment( $invoice ) ) {
195
-            $parent_url = get_edit_post_link( $invoice->parent_invoice );
196
-            $parent_id  = wpinv_get_invoice_number( $invoice->parent_invoice );
197
-            $subscription = wpinv_get_subscription( $invoice );
194
+        if (wpinv_is_subscription_payment($invoice)) {
195
+            $parent_url = get_edit_post_link($invoice->parent_invoice);
196
+            $parent_id  = wpinv_get_invoice_number($invoice->parent_invoice);
197
+            $subscription = wpinv_get_subscription($invoice);
198 198
         ?>
199
-        <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
200
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
199
+        <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
200
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
201 201
         <?php
202 202
         }
203 203
     }
204 204
     
205
-    public static function payment_meta( $post ) {
205
+    public static function payment_meta($post) {
206 206
         global $wpi_mb_invoice;
207 207
 
208
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
209
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
208
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
209
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
210 210
             $set_dateway = true;
211 211
         }
212 212
         
213 213
         ?>
214 214
         <p class="wpi-meta-row">
215
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
216
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
215
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
216
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
217 217
             <select required="required" id="wpinv_gateway" name="wpinv_gateway">
218
-                <?php foreach ( $gateways as $name => $gateway ) {
219
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
218
+                <?php foreach ($gateways as $name => $gateway) {
219
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
220 220
                         continue;
221 221
                     }
222 222
                     ?>
223
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
223
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
224 224
                 <?php } ?>
225 225
             </select>
226 226
         <?php } else { 
227
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) );
227
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway));
228 228
         } ?>
229 229
         </p>
230
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
231
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
230
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
231
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
232 232
         <?php } ?>
233
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
234
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
233
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
234
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
235 235
         <?php } ?>
236 236
         <?php
237 237
     }
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 function wpinv_subscriptions_page() {
10 10
 
11
-	if ( ! empty( $_GET['id'] ) ) {
11
+	if (!empty($_GET['id'])) {
12 12
 
13 13
         wpinv_recurring_subscription_details();
14 14
 
@@ -19,7 +19,7 @@  discard block
 block discarded – undo
19 19
 	<div class="wrap">
20 20
 
21 21
 		<h1>
22
-			<?php _e( 'Subscriptions', 'invoicing' ); ?>
22
+			<?php _e('Subscriptions', 'invoicing'); ?>
23 23
 		</h1>
24 24
 		<?php
25 25
 		$subscribers_table = new WPInv_Subscription_Reports_Table();
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 			<input type="hidden" name="post_type" value="download" />
32 32
 			<input type="hidden" name="page" value="wpinv-subscriptions" />
33 33
 			<?php $subscribers_table->views(); ?>
34
-			<?php $subscribers_table->search_box( __( 'Search', 'wpinvoicing' ), 'subscriptions' ); ?>
34
+			<?php $subscribers_table->search_box(__('Search', 'wpinvoicing'), 'subscriptions'); ?>
35 35
 			<?php $subscribers_table->display(); ?>
36 36
 
37 37
 		</form>
@@ -49,34 +49,34 @@  discard block
 block discarded – undo
49 49
 
50 50
 	$render = true;
51 51
 
52
-	if ( ! current_user_can( 'manage_invoicing' ) ) {
53
-		die( __( 'You are not permitted to view this data.', 'invoicing' ) );
52
+	if (!current_user_can('manage_invoicing')) {
53
+		die(__('You are not permitted to view this data.', 'invoicing'));
54 54
 	}
55 55
 
56
-	if ( ! isset( $_GET['id'] ) || ! is_numeric( $_GET['id'] ) ) {
57
-        die( __( 'Invalid subscription ID Provided.', 'invoicing' ) );
56
+	if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
57
+        die(__('Invalid subscription ID Provided.', 'invoicing'));
58 58
 	}
59 59
 
60
-	$sub_id  = (int) $_GET['id'];
61
-	$sub     = new WPInv_Subscription( $sub_id );
60
+	$sub_id  = (int)$_GET['id'];
61
+	$sub     = new WPInv_Subscription($sub_id);
62 62
 
63
-	if ( empty( $sub ) ) {
64
-		die( __( 'Invalid subscription ID Provided.', 'invoicing' ) );
63
+	if (empty($sub)) {
64
+		die(__('Invalid subscription ID Provided.', 'invoicing'));
65 65
 	}
66 66
 
67 67
 	?>
68 68
 	<div class="wrap">
69
-		<h2><?php _e( 'Subscription Details', 'invoicing' ); ?></h2>
69
+		<h2><?php _e('Subscription Details', 'invoicing'); ?></h2>
70 70
 
71
-		<?php if ( $sub ) : ?>
71
+		<?php if ($sub) : ?>
72 72
 
73 73
 			<div id="wpinv-item-card-wrapper">
74 74
 
75
-				<?php do_action( 'wpinv_subscription_card_top', $sub ); ?>
75
+				<?php do_action('wpinv_subscription_card_top', $sub); ?>
76 76
 
77 77
 				<div class="info-wrapper item-section">
78 78
 
79
-					<form id="edit-item-info" method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $sub->id ); ?>">
79
+					<form id="edit-item-info" method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . $sub->id); ?>">
80 80
 
81 81
 						<div class="item-info">
82 82
 
@@ -84,124 +84,124 @@  discard block
 block discarded – undo
84 84
 								<tbody>
85 85
 									<tr>
86 86
 										<td class="row-title">
87
-											<label for="tablecell"><?php _e( 'Billing Cycle:', 'invoicing' ); ?></label>
87
+											<label for="tablecell"><?php _e('Billing Cycle:', 'invoicing'); ?></label>
88 88
 										</td>
89 89
 										<td>
90 90
 											<?php
91
-											$frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $sub->period, $sub->frequency );
92
-											$billing   = wpinv_price( wpinv_format_amount( $sub->recurring_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) ) . ' / ' . $frequency;
93
-											$initial   = wpinv_price( wpinv_format_amount( $sub->initial_amount ), wpinv_get_invoice_currency_code( $sub->parent_payment_id ) );
94
-											printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing );
91
+											$frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($sub->period, $sub->frequency);
92
+											$billing   = wpinv_price(wpinv_format_amount($sub->recurring_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id)) . ' / ' . $frequency;
93
+											$initial   = wpinv_price(wpinv_format_amount($sub->initial_amount), wpinv_get_invoice_currency_code($sub->parent_payment_id));
94
+											printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing);
95 95
 											?>
96 96
 										</td>
97 97
 									</tr>
98 98
 									<tr>
99 99
 										<td class="row-title">
100
-											<label for="tablecell"><?php _e( 'Times Billed:', 'invoicing' ); ?></label>
100
+											<label for="tablecell"><?php _e('Times Billed:', 'invoicing'); ?></label>
101 101
 										</td>
102
-										<td><?php echo $sub->get_times_billed() . ' / ' . ( ( $sub->bill_times == 0 ) ? 'Until Cancelled' : $sub->bill_times ); ?></td>
102
+										<td><?php echo $sub->get_times_billed() . ' / ' . (($sub->bill_times == 0) ? 'Until Cancelled' : $sub->bill_times); ?></td>
103 103
 									</tr>
104 104
 									<tr>
105 105
 										<td class="row-title">
106
-											<label for="tablecell"><?php _e( 'Customer:', 'invoicing' ); ?></label>
106
+											<label for="tablecell"><?php _e('Customer:', 'invoicing'); ?></label>
107 107
 										</td>
108 108
 										<td>
109
-											<?php $subscriber = get_userdata( $sub->customer_id ); ?>
110
-											<a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&view=overview&id=' . $subscriber->ID ) ); ?>" target="_blank"><?php echo ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email; ?></a>
109
+											<?php $subscriber = get_userdata($sub->customer_id); ?>
110
+											<a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&view=overview&id=' . $subscriber->ID)); ?>" target="_blank"><?php echo !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email; ?></a>
111 111
 										</td>
112 112
 									</tr>
113 113
 									<tr>
114 114
 										<td class="row-title">
115
-											<label for="tablecell"><?php _e( 'Initial Invoice:', 'invoicing' ); ?></label>
115
+											<label for="tablecell"><?php _e('Initial Invoice:', 'invoicing'); ?></label>
116 116
 										</td>
117 117
 										<td>
118
-                                            <a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $sub->parent_payment_id ) ); ?>"><?php echo wpinv_get_invoice_number( $sub->parent_payment_id ); ?></a>&nbsp;&nbsp;&nbsp;<?php echo wp_sprintf( __( '( ID: %s )', 'invoicing' ), '<a title="' . esc_attr( __( 'View invoice details', 'invoicing' ) ) . '" href="' . get_edit_post_link( $sub->parent_payment_id ) . '" target="_blank">' . $sub->parent_payment_id . '</a>' ); ?></td>
118
+                                            <a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($sub->parent_payment_id)); ?>"><?php echo wpinv_get_invoice_number($sub->parent_payment_id); ?></a>&nbsp;&nbsp;&nbsp;<?php echo wp_sprintf(__('( ID: %s )', 'invoicing'), '<a title="' . esc_attr(__('View invoice details', 'invoicing')) . '" href="' . get_edit_post_link($sub->parent_payment_id) . '" target="_blank">' . $sub->parent_payment_id . '</a>'); ?></td>
119 119
 									</tr>
120 120
 									<tr>
121 121
 										<td class="row-title">
122
-											<label for="tablecell"><?php _e( 'Item:', 'invoicing' ); ?></label>
122
+											<label for="tablecell"><?php _e('Item:', 'invoicing'); ?></label>
123 123
 										</td>
124 124
 										<td>
125 125
 											<?php
126
-                                            echo wpinv_item_dropdown( array(
126
+                                            echo wpinv_item_dropdown(array(
127 127
                                                 'name'              => 'product_id',
128 128
                                                 'id'                => 'wpinv_invoice_item',
129 129
                                                 'with_packages'     => false,
130 130
                                                 'show_recurring'    => true,
131 131
                                                 'selected'          => $sub->product_id,
132 132
                                                 'class'             => 'wpinv-sub-product-id',
133
-                                            ) );
133
+                                            ));
134 134
 
135 135
                                             ?>
136
-											<a href="<?php echo esc_url( add_query_arg( array(
136
+											<a href="<?php echo esc_url(add_query_arg(array(
137 137
 													'post'   => $sub->product_id,
138 138
 													'action' => 'edit'
139
-												), admin_url( 'post.php' ) ) ); ?>" target="_blank"><?php _e( 'View Item', 'invoicing' ) ; ?></a>
139
+												), admin_url('post.php'))); ?>" target="_blank"><?php _e('View Item', 'invoicing'); ?></a>
140 140
 										</td>
141 141
 									</tr>
142 142
 									<tr>
143 143
 										<td class="row-title">
144
-											<label for="tablecell"><?php _e( 'Payment Method:', 'invoicing' ); ?></label>
144
+											<label for="tablecell"><?php _e('Payment Method:', 'invoicing'); ?></label>
145 145
 										</td>
146
-										<td><?php echo wpinv_get_gateway_admin_label( wpinv_get_payment_gateway( $sub->parent_payment_id ) ); ?></td>
146
+										<td><?php echo wpinv_get_gateway_admin_label(wpinv_get_payment_gateway($sub->parent_payment_id)); ?></td>
147 147
 									</tr>
148 148
 									<tr>
149 149
 										<td class="row-title">
150
-											<label for="tablecell"><?php _e( 'Profile ID:', 'invoicing' ); ?></label>
150
+											<label for="tablecell"><?php _e('Profile ID:', 'invoicing'); ?></label>
151 151
 										</td>
152 152
 										<td>
153 153
 											<span class="wpinv-sub-profile-id">
154
-												<?php echo apply_filters( 'wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub ); ?>
154
+												<?php echo apply_filters('wpinv_subscription_profile_link_' . $sub->gateway, $sub->profile_id, $sub); ?>
155 155
 											</span>
156
-											<input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr( $sub->profile_id ); ?>" />
156
+											<input type="text" name="profile_id" class="hidden wpinv-sub-profile-id" value="<?php echo esc_attr($sub->profile_id); ?>" />
157 157
 											<span>&nbsp;&ndash;&nbsp;</span>
158
-											<a href="#" class="wpinv-edit-sub-profile-id"><?php _e( 'Edit', 'invoicing' ); ?></a>
158
+											<a href="#" class="wpinv-edit-sub-profile-id"><?php _e('Edit', 'invoicing'); ?></a>
159 159
 										</td>
160 160
 									</tr>
161 161
 									<tr>
162 162
 										<td class="row-title">
163
-											<label for="tablecell"><?php _e( 'Transaction ID:', 'invoicing' ); ?></label>
163
+											<label for="tablecell"><?php _e('Transaction ID:', 'invoicing'); ?></label>
164 164
 										</td>
165 165
 										<td>
166 166
 											<span class="wpinv-sub-transaction-id"><?php echo $sub->get_transaction_id(); ?></span>
167
-											<input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr( $sub->get_transaction_id() ); ?>" />
167
+											<input type="text" name="transaction_id" class="hidden wpinv-sub-transaction-id" value="<?php echo esc_attr($sub->get_transaction_id()); ?>" />
168 168
 											<span>&nbsp;&ndash;&nbsp;</span>
169
-											<a href="#" class="wpinv-edit-sub-transaction-id"><?php _e( 'Edit', 'invoicing' ); ?></a>
169
+											<a href="#" class="wpinv-edit-sub-transaction-id"><?php _e('Edit', 'invoicing'); ?></a>
170 170
 										</td>
171 171
 									</tr>
172 172
 									<tr>
173 173
 										<td class="row-title">
174
-											<label for="tablecell"><?php _e( 'Date Created:', 'invoicing' ); ?></label>
174
+											<label for="tablecell"><?php _e('Date Created:', 'invoicing'); ?></label>
175 175
 										</td>
176
-										<td><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->created, current_time( 'timestamp' ) ) ); ?></td>
176
+										<td><?php echo date_i18n(get_option('date_format'), strtotime($sub->created, current_time('timestamp'))); ?></td>
177 177
 									</tr>
178 178
 									<tr>
179 179
 										<td class="row-title">
180 180
 											<label for="tablecell">
181
-												<?php if( 'trialling' == $sub->status ) : ?>
182
-													<?php _e( 'Trialling Until:', 'invoicing' ); ?>
181
+												<?php if ('trialling' == $sub->status) : ?>
182
+													<?php _e('Trialling Until:', 'invoicing'); ?>
183 183
 												<?php else: ?>
184
-													<?php _e( 'Expiration Date:', 'invoicing' ); ?>
184
+													<?php _e('Expiration Date:', 'invoicing'); ?>
185 185
 												<?php endif; ?>
186 186
 											</label>
187 187
 										</td>
188 188
 										<td>
189
-											<span class="wpinv-sub-expiration"><?php echo date_i18n( get_option( 'date_format' ), strtotime( $sub->expiration, current_time( 'timestamp' ) ) ); ?></span>
189
+											<span class="wpinv-sub-expiration"><?php echo date_i18n(get_option('date_format'), strtotime($sub->expiration, current_time('timestamp'))); ?></span>
190 190
 										</td>
191 191
 									</tr>
192 192
 									<tr>
193 193
 										<td class="row-title">
194
-											<label for="tablecell"><?php _e( 'Subscription Status:', 'invoicing' ); ?></label>
194
+											<label for="tablecell"><?php _e('Subscription Status:', 'invoicing'); ?></label>
195 195
 										</td>
196 196
 										<td>
197 197
 											<select name="status">
198
-												<option value="pending"<?php selected( 'pending', $sub->status ); ?>><?php _e( 'Pending', 'invoicing' ); ?></option>
199
-												<option value="active"<?php selected( 'active', $sub->status ); ?>><?php _e( 'Active', 'invoicing' ); ?></option>
200
-												<option value="cancelled"<?php selected( 'cancelled', $sub->status ); ?>><?php _e( 'Cancelled', 'invoicing' ); ?></option>
201
-												<option value="expired"<?php selected( 'expired', $sub->status ); ?>><?php _e( 'Expired', 'invoicing' ); ?></option>
202
-												<option value="trialling"<?php selected( 'trialling', $sub->status ); ?>><?php _e( 'Trialling', 'invoicing' ); ?></option>
203
-												<option value="failing"<?php selected( 'failing', $sub->status ); ?>><?php _e( 'Failing', 'invoicing' ); ?></option>
204
-												<option value="completed"<?php selected( 'completed', $sub->status ); ?>><?php _e( 'Completed', 'invoicing' ); ?></option>
198
+												<option value="pending"<?php selected('pending', $sub->status); ?>><?php _e('Pending', 'invoicing'); ?></option>
199
+												<option value="active"<?php selected('active', $sub->status); ?>><?php _e('Active', 'invoicing'); ?></option>
200
+												<option value="cancelled"<?php selected('cancelled', $sub->status); ?>><?php _e('Cancelled', 'invoicing'); ?></option>
201
+												<option value="expired"<?php selected('expired', $sub->status); ?>><?php _e('Expired', 'invoicing'); ?></option>
202
+												<option value="trialling"<?php selected('trialling', $sub->status); ?>><?php _e('Trialling', 'invoicing'); ?></option>
203
+												<option value="failing"<?php selected('failing', $sub->status); ?>><?php _e('Failing', 'invoicing'); ?></option>
204
+												<option value="completed"<?php selected('completed', $sub->status); ?>><?php _e('Completed', 'invoicing'); ?></option>
205 205
 											</select>
206 206
 										</td>
207 207
 									</tr>
@@ -209,79 +209,79 @@  discard block
 block discarded – undo
209 209
 							</table>
210 210
 						</div>
211 211
 						<div id="wpinv-sub-notices">
212
-							<div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e( 'Changing the product assigned will not automatically adjust any pricing.', 'invoicing' ); ?></p></div>
213
-							<div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e( 'Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing' ); ?></p></div>
212
+							<div class="notice notice-info inline hidden" id="wpinv-sub-product-update-notice"><p><?php _e('Changing the product assigned will not automatically adjust any pricing.', 'invoicing'); ?></p></div>
213
+							<div class="notice notice-warning inline hidden" id="wpinv-sub-profile-id-update-notice"><p><?php _e('Changing the profile ID can result in renewals not being processed. Do this with caution.', 'invoicing'); ?></p></div>
214 214
 						</div>
215 215
 						<div id="item-edit-actions" class="edit-item" style="float:right; margin: 10px 0 0; display: block;">
216
-							<?php wp_nonce_field( 'wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true ); ?>
217
-							<input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e( 'Update Subscription', 'invoicing' ); ?>"/>
218
-							<input type="hidden" name="sub_id" value="<?php echo absint( $sub->id ); ?>" />
219
-							<?php if( $sub->can_cancel() ) : ?>
220
-								<a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e( 'Cancel Subscription', 'invoicing' ); ?></a>
216
+							<?php wp_nonce_field('wpinv-recurring-update', 'wpinv-recurring-update-nonce', false, true); ?>
217
+							<input type="submit" name="wpinv_update_subscription" id="wpinv_update_subscription" class="button button-primary" value="<?php _e('Update Subscription', 'invoicing'); ?>"/>
218
+							<input type="hidden" name="sub_id" value="<?php echo absint($sub->id); ?>" />
219
+							<?php if ($sub->can_cancel()) : ?>
220
+								<a class="button button-primary" href="<?php echo $sub->get_cancel_url(); ?>" ><?php _e('Cancel Subscription', 'invoicing'); ?></a>
221 221
 							<?php endif; ?>
222
-							&nbsp;<input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e( 'Delete Subscription', 'invoicing' ); ?>"/>
222
+							&nbsp;<input type="submit" name="wpinv_delete_subscription" class="wpinv-delete-subscription button" value="<?php _e('Delete Subscription', 'invoicing'); ?>"/>
223 223
 						</div>
224 224
 
225 225
 					</form>
226 226
 				</div>
227 227
 
228
-				<?php do_action( 'wpinv_subscription_before_stats', $sub ); ?>
228
+				<?php do_action('wpinv_subscription_before_stats', $sub); ?>
229 229
 
230
-				<?php do_action( 'wpinv_subscription_before_tables_wrapper', $sub ); ?>
230
+				<?php do_action('wpinv_subscription_before_tables_wrapper', $sub); ?>
231 231
 
232 232
 				<div id="item-tables-wrapper" class="item-section">
233 233
 
234
-					<?php do_action( 'wpinv_subscription_before_tables', $sub ); ?>
234
+					<?php do_action('wpinv_subscription_before_tables', $sub); ?>
235 235
 
236
-					<h3><?php _e( 'Renewal Payments:', 'invoicing' ); ?></h3>
236
+					<h3><?php _e('Renewal Payments:', 'invoicing'); ?></h3>
237 237
 					<?php $payments = $sub->get_child_payments(); ?>
238
-					<?php if ( 'manual' == $sub->gateway ) : ?>
239
-						<p><strong><?php _e( 'Note:', 'invoicing' ); ?></strong> <?php _e( 'Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing' ); ?></p>
238
+					<?php if ('manual' == $sub->gateway) : ?>
239
+						<p><strong><?php _e('Note:', 'invoicing'); ?></strong> <?php _e('Subscriptions purchased with the Test Payment gateway will not renew automatically.', 'invoicing'); ?></p>
240 240
 					<?php endif; ?>
241 241
 					<table class="wp-list-table widefat striped payments">
242 242
 						<thead>
243 243
 						<tr>
244
-							<th><?php _e( 'ID', 'invoicing' ); ?></th>
245
-							<th><?php _e( 'Amount', 'invoicing' ); ?></th>
246
-							<th><?php _e( 'Date', 'invoicing' ); ?></th>
247
-							<th><?php _e( 'Status', 'invoicing' ); ?></th>
248
-                            <th><?php _e( 'Invoice', 'invoicing' ); ?></th>
249
-							<th class="column-wpi_actions"><?php _e( 'Actions', 'invoicing' ); ?></th>
244
+							<th><?php _e('ID', 'invoicing'); ?></th>
245
+							<th><?php _e('Amount', 'invoicing'); ?></th>
246
+							<th><?php _e('Date', 'invoicing'); ?></th>
247
+							<th><?php _e('Status', 'invoicing'); ?></th>
248
+                            <th><?php _e('Invoice', 'invoicing'); ?></th>
249
+							<th class="column-wpi_actions"><?php _e('Actions', 'invoicing'); ?></th>
250 250
 						</tr>
251 251
 						</thead>
252 252
 						<tbody>
253
-						<?php if ( ! empty( $payments ) ) : ?>
254
-							<?php foreach ( $payments as $payment ) : $invoice = wpinv_get_invoice( $payment->ID ); if ( empty( $invoice->ID ) ) continue; ?>
253
+						<?php if (!empty($payments)) : ?>
254
+							<?php foreach ($payments as $payment) : $invoice = wpinv_get_invoice($payment->ID); if (empty($invoice->ID)) continue; ?>
255 255
 								<tr>
256 256
 									<td><?php echo $payment->ID; ?></td>
257
-									<td><?php echo $invoice->get_total( true ); ?></td>
257
+									<td><?php echo $invoice->get_total(true); ?></td>
258 258
 									<td><?php echo $invoice->get_invoice_date(); ?></td>
259
-									<td><?php echo $invoice->get_status( true ); ?></td>
259
+									<td><?php echo $invoice->get_status(true); ?></td>
260 260
 									<td>
261
-										<a target="_blank" title="<?php _e( 'View invoice', 'invoicing' ); ?>" href="<?php echo esc_url( get_permalink( $payment->ID ) ); ?>"><?php echo $invoice->get_number(); ?></a>
262
-										<?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?>
261
+										<a target="_blank" title="<?php _e('View invoice', 'invoicing'); ?>" href="<?php echo esc_url(get_permalink($payment->ID)); ?>"><?php echo $invoice->get_number(); ?></a>
262
+										<?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?>
263 263
 									</td>
264 264
 									<td class="column-wpi_actions">
265
-										<a title="<?php echo esc_attr( wp_sprintf( __( 'View details for invoice: %s', 'invoicing' ), $invoice->get_number() ) ); ?>" href="<?php echo get_edit_post_link( $payment->ID ); ?>"><?php _e( 'View Details', 'invoicing' ); ?>
265
+										<a title="<?php echo esc_attr(wp_sprintf(__('View details for invoice: %s', 'invoicing'), $invoice->get_number())); ?>" href="<?php echo get_edit_post_link($payment->ID); ?>"><?php _e('View Details', 'invoicing'); ?>
266 266
 										</a>
267
-										<?php do_action( 'wpinv_subscription_payments_actions', $sub, $payment ); ?>
267
+										<?php do_action('wpinv_subscription_payments_actions', $sub, $payment); ?>
268 268
 									</td>
269 269
 								</tr>
270 270
 							<?php endforeach; ?>
271 271
 						<?php else: ?>
272 272
 							<tr>
273
-								<td colspan="5"><?php _e( 'No Invoices Found.', 'invoicing' ); ?></td>
273
+								<td colspan="5"><?php _e('No Invoices Found.', 'invoicing'); ?></td>
274 274
 							</tr>
275 275
 						<?php endif; ?>
276 276
 						</tbody>
277 277
 						<tfoot></tfoot>
278 278
 					</table>
279 279
 
280
-					<?php do_action( 'wpinv_subscription_after_tables', $sub ); ?>
280
+					<?php do_action('wpinv_subscription_after_tables', $sub); ?>
281 281
 
282 282
 				</div>
283 283
 
284
-				<?php do_action( 'wpinv_subscription_card_bottom', $sub ); ?>
284
+				<?php do_action('wpinv_subscription_card_bottom', $sub); ?>
285 285
 			</div>
286 286
 
287 287
 		<?php endif; ?>
@@ -299,38 +299,38 @@  discard block
 block discarded – undo
299 299
  */
300 300
 function wpinv_recurring_process_subscription_update() {
301 301
 
302
-	if( empty( $_POST['sub_id'] ) ) {
302
+	if (empty($_POST['sub_id'])) {
303 303
 		return;
304 304
 	}
305 305
 
306
-	if( empty( $_POST['wpinv_update_subscription'] ) ) {
306
+	if (empty($_POST['wpinv_update_subscription'])) {
307 307
 		return;
308 308
 	}
309 309
 
310
-	if( ! current_user_can( 'manage_invoicing') ) {
310
+	if (!current_user_can('manage_invoicing')) {
311 311
 		return;
312 312
 	}
313 313
 
314
-	if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
315
-		wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
314
+	if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) {
315
+		wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
316 316
 	}
317 317
 
318
-	$expiration      = date( 'Y-m-d 23:59:59', strtotime( $_POST['expiration'] ) );
319
-	$profile_id      = sanitize_text_field( $_POST['profile_id'] );
320
-	$transaction_id  = sanitize_text_field( $_POST['transaction_id'] );
321
-	$product_id      = absint( $_POST['product_id'] );
322
-	$subscription    = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
323
-	$subscription->update( array(
324
-		'status'         => sanitize_text_field( $_POST['status'] ),
318
+	$expiration      = date('Y-m-d 23:59:59', strtotime($_POST['expiration']));
319
+	$profile_id      = sanitize_text_field($_POST['profile_id']);
320
+	$transaction_id  = sanitize_text_field($_POST['transaction_id']);
321
+	$product_id      = absint($_POST['product_id']);
322
+	$subscription    = new WPInv_Subscription(absint($_POST['sub_id']));
323
+	$subscription->update(array(
324
+		'status'         => sanitize_text_field($_POST['status']),
325 325
 		'expiration'     => $expiration,
326 326
 		'profile_id'     => $profile_id,
327 327
 		'product_id'     => $product_id,
328 328
 		'transaction_id' => $transaction_id,
329
-	) );
329
+	));
330 330
 
331
-	$status = sanitize_text_field( $_POST['status'] );
331
+	$status = sanitize_text_field($_POST['status']);
332 332
 
333
-	switch( $status ) {
333
+	switch ($status) {
334 334
 
335 335
 		case 'cancelled' :
336 336
 
@@ -349,11 +349,11 @@  discard block
 block discarded – undo
349 349
 
350 350
 	}
351 351
 
352
-	wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id ) );
352
+	wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=updated&id=' . $subscription->id));
353 353
 	exit;
354 354
 
355 355
 }
356
-add_action( 'admin_init', 'wpinv_recurring_process_subscription_update', 1 );
356
+add_action('admin_init', 'wpinv_recurring_process_subscription_update', 1);
357 357
 
358 358
 /**
359 359
  * Handles subscription deletion
@@ -364,30 +364,30 @@  discard block
 block discarded – undo
364 364
  */
365 365
 function wpinv_recurring_process_subscription_deletion() {
366 366
 
367
-	if( empty( $_POST['sub_id'] ) ) {
367
+	if (empty($_POST['sub_id'])) {
368 368
 		return;
369 369
 	}
370 370
 
371
-	if( empty( $_POST['wpinv_delete_subscription'] ) ) {
371
+	if (empty($_POST['wpinv_delete_subscription'])) {
372 372
 		return;
373 373
 	}
374 374
 
375
-	if( ! current_user_can( 'manage_invoicing') ) {
375
+	if (!current_user_can('manage_invoicing')) {
376 376
 		return;
377 377
 	}
378 378
 
379
-	if( ! wp_verify_nonce( $_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update' ) ) {
380
-		wp_die( __( 'Nonce verification failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
379
+	if (!wp_verify_nonce($_POST['wpinv-recurring-update-nonce'], 'wpinv-recurring-update')) {
380
+		wp_die(__('Nonce verification failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
381 381
 	}
382 382
 
383
-	$subscription = new WPInv_Subscription( absint( $_POST['sub_id'] ) );
383
+	$subscription = new WPInv_Subscription(absint($_POST['sub_id']));
384 384
 
385
-	delete_post_meta( $subscription->parent_payment_id, '_wpinv_subscription_payment' );
385
+	delete_post_meta($subscription->parent_payment_id, '_wpinv_subscription_payment');
386 386
 
387 387
 	$subscription->delete();
388 388
 
389
-	wp_redirect( admin_url( 'admin.php?page=wpinv-subscriptions&wpinv-message=deleted' ) );
389
+	wp_redirect(admin_url('admin.php?page=wpinv-subscriptions&wpinv-message=deleted'));
390 390
 	exit;
391 391
 
392 392
 }
393
-add_action( 'admin_init', 'wpinv_recurring_process_subscription_deletion', 2 );
393
+add_action('admin_init', 'wpinv_recurring_process_subscription_deletion', 2);
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  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
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,92 +72,92 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id );
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id);
86 86
 
87
-                    if ( !$allowed ) {
87
+                    if (!$allowed) {
88 88
                         continue;
89 89
                     }
90 90
 
91
-                    if ( $field == '_wpinv_price' ) {
92
-                        $value = wpinv_sanitize_amount( $_POST[ $name ] );
91
+                    if ($field == '_wpinv_price') {
92
+                        $value = wpinv_sanitize_amount($_POST[$name]);
93 93
                     } else {
94
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
94
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
95 95
                     }
96 96
                     
97
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
98
-                    update_post_meta( $post_id, $field, $value );
97
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
98
+                    update_post_meta($post_id, $field, $value);
99 99
                 }
100 100
             }
101 101
             
102
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
103
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
102
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
103
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
104 104
             }
105 105
         }
106 106
     }
107 107
 }
108
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
108
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
109 109
 
110 110
 function wpinv_register_item_meta_boxes() {    
111 111
     global $wpinv_euvat;
112 112
     
113
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
113
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
114 114
 
115
-    if ( $wpinv_euvat->allow_vat_rules() ) {
116
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
115
+    if ($wpinv_euvat->allow_vat_rules()) {
116
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
117 117
     }
118 118
     
119
-    if ( $wpinv_euvat->allow_vat_classes() ) {
120
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
119
+    if ($wpinv_euvat->allow_vat_classes()) {
120
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
121 121
     }
122 122
     
123
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
124
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
123
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
124
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
125 125
 }
126 126
 
127 127
 function wpinv_register_discount_meta_boxes() {
128
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
128
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
129 129
 }
130 130
 
131
-function wpinv_discount_metabox_details( $post ) {
131
+function wpinv_discount_metabox_details($post) {
132 132
     $discount_id    = $post->ID;
133
-    $discount       = wpinv_get_discount( $discount_id );
133
+    $discount       = wpinv_get_discount($discount_id);
134 134
     
135
-    $type               = wpinv_get_discount_type( $discount_id );
136
-    $item_reqs          = wpinv_get_discount_item_reqs( $discount_id );
137
-    $excluded_items     = wpinv_get_discount_excluded_items( $discount_id );
138
-    $min_total          = wpinv_get_discount_min_total( $discount_id );
139
-    $max_total          = wpinv_get_discount_max_total( $discount_id );
140
-    $max_uses           = wpinv_get_discount_max_uses( $discount_id );
141
-    $single_use         = wpinv_discount_is_single_use( $discount_id );
142
-    $recurring          = (bool)wpinv_discount_is_recurring( $discount_id );
143
-    $start_date         = wpinv_get_discount_start_date( $discount_id );
144
-    $expiration_date    = wpinv_get_discount_expiration( $discount_id );
135
+    $type               = wpinv_get_discount_type($discount_id);
136
+    $item_reqs          = wpinv_get_discount_item_reqs($discount_id);
137
+    $excluded_items     = wpinv_get_discount_excluded_items($discount_id);
138
+    $min_total          = wpinv_get_discount_min_total($discount_id);
139
+    $max_total          = wpinv_get_discount_max_total($discount_id);
140
+    $max_uses           = wpinv_get_discount_max_uses($discount_id);
141
+    $single_use         = wpinv_discount_is_single_use($discount_id);
142
+    $recurring          = (bool)wpinv_discount_is_recurring($discount_id);
143
+    $start_date         = wpinv_get_discount_start_date($discount_id);
144
+    $expiration_date    = wpinv_get_discount_expiration($discount_id);
145 145
     
146
-    if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) {
147
-        $start_time         = strtotime( $start_date );
148
-        $start_h            = date_i18n( 'H', $start_time );
149
-        $start_m            = date_i18n( 'i', $start_time );
150
-        $start_date         = date_i18n( 'Y-m-d', $start_time );
146
+    if (!empty($start_date) && strpos($start_date, '0000') === false) {
147
+        $start_time         = strtotime($start_date);
148
+        $start_h            = date_i18n('H', $start_time);
149
+        $start_m            = date_i18n('i', $start_time);
150
+        $start_date         = date_i18n('Y-m-d', $start_time);
151 151
     } else {
152 152
         $start_h            = '00';
153 153
         $start_m            = '00';
154 154
     }
155 155
 
156
-    if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) {
157
-        $expiration_time    = strtotime( $expiration_date );
158
-        $expiration_h       = date_i18n( 'H', $expiration_time );
159
-        $expiration_m       = date_i18n( 'i', $expiration_time );
160
-        $expiration_date    = date_i18n( 'Y-m-d', $expiration_time );
156
+    if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) {
157
+        $expiration_time    = strtotime($expiration_date);
158
+        $expiration_h       = date_i18n('H', $expiration_time);
159
+        $expiration_m       = date_i18n('i', $expiration_time);
160
+        $expiration_date    = date_i18n('Y-m-d', $expiration_time);
161 161
     } else {
162 162
         $expiration_h       = '23';
163 163
         $expiration_m       = '59';
@@ -167,207 +167,207 @@  discard block
 block discarded – undo
167 167
     $max_total          = $max_total > 0 ? $max_total : '';
168 168
     $max_uses           = $max_uses > 0 ? $max_uses : '';
169 169
 ?>
170
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
171
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
170
+<?php do_action('wpinv_discount_form_top', $post); ?>
171
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
172 172
 <table class="form-table wpi-form-table">
173 173
     <tbody>
174
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
175
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
174
+        <?php do_action('wpinv_discount_form_first', $post); ?>
175
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
176 176
         <tr>
177 177
             <th valign="top" scope="row">
178
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
178
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
179 179
             </th>
180 180
             <td>
181
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
182
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
181
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
182
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
183 183
             </td>
184 184
         </tr>
185
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
185
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
186 186
         <tr>
187 187
             <th valign="top" scope="row">
188
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
188
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
189 189
             </th>
190 190
             <td>
191 191
                 <select id="wpinv_discount_type" name="type" class="medium-text">
192
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
193
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
192
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
193
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
194 194
                     <?php } ?>
195 195
                 </select>
196
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
196
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
197 197
             </td>
198 198
         </tr>
199
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
199
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
200 200
         <tr>
201 201
             <th valign="top" scope="row">
202
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
202
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
203 203
             </th>
204 204
             <td>
205
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
206
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
207
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
205
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
206
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
207
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
208 208
             </td>
209 209
         </tr>
210
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
210
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
211 211
         <tr>
212 212
             <th valign="top" scope="row">
213
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
213
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
214 214
             </th>
215 215
             <td>
216
-                <p><?php echo wpinv_item_dropdown( array(
216
+                <p><?php echo wpinv_item_dropdown(array(
217 217
                         'name'              => 'items[]',
218 218
                         'id'                => 'items',
219 219
                         'selected'          => $item_reqs,
220 220
                         'multiple'          => true,
221 221
                         'class'             => 'medium-text',
222
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
222
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
223 223
                         'show_recurring'    => true,
224
-                    ) ); ?>
224
+                    )); ?>
225 225
                 </p>
226
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
226
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
227 227
             </td>
228 228
         </tr>
229
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
229
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
230 230
         <tr>
231 231
             <th valign="top" scope="row">
232
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
232
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
233 233
             </th>
234 234
             <td>
235
-                <p><?php echo wpinv_item_dropdown( array(
235
+                <p><?php echo wpinv_item_dropdown(array(
236 236
                         'name'              => 'excluded_items[]',
237 237
                         'id'                => 'excluded_items',
238 238
                         'selected'          => $excluded_items,
239 239
                         'multiple'          => true,
240 240
                         'class'             => 'medium-text',
241
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
241
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
242 242
                         'show_recurring'    => true,
243
-                    ) ); ?>
243
+                    )); ?>
244 244
                 </p>
245
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
245
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
246 246
             </td>
247 247
         </tr>
248
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
248
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
249 249
         <tr>
250 250
             <th valign="top" scope="row">
251
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
251
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
252 252
             </th>
253 253
             <td>
254
-                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h">
255
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
256
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option>
254
+                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h">
255
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
256
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option>
257 257
                     <?php } ?>
258 258
                 </select> : <select id="wpinv_discount_start_m" name="start_m">
259
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
260
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option>
259
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
260
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option>
261 261
                     <?php } ?>
262 262
                 </select>
263
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272
-                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h">
273
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
274
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option>
272
+                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h">
273
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
274
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option>
275 275
                     <?php } ?>
276 276
                 </select> : <select id="wpinv_discount_expiration_m" name="expiration_m">
277
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
278
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option>
277
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
278
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option>
279 279
                     <?php } ?>
280 280
                 </select>
281
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
281
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
282 282
             </td>
283 283
         </tr>
284
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
284
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
285 285
         <tr>
286 286
             <th valign="top" scope="row">
287
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
287
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
288 288
             </th>
289 289
             <td>
290 290
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
291
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
291
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
292 292
             </td>
293 293
         </tr>
294
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
294
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
295 295
         <tr>
296 296
             <th valign="top" scope="row">
297
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
297
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
298 298
             </th>
299 299
             <td>
300 300
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
301
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
301
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
302 302
             </td>
303 303
         </tr>
304
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
304
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
305 305
         <tr>
306 306
             <th valign="top" scope="row">
307
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
307
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
308 308
             </th>
309 309
             <td>
310 310
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
311
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
312
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
311
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
312
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
313 313
                 </select>
314
-                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
314
+                <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
315 315
             </td>
316 316
         </tr>
317
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
317
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
318 318
         <tr>
319 319
             <th valign="top" scope="row">
320
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
320
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
321 321
             </th>
322 322
             <td>
323 323
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
324
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
324
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
325 325
             </td>
326 326
         </tr>
327
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
327
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
328 328
         <tr>
329 329
             <th valign="top" scope="row">
330
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
330
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
331 331
             </th>
332 332
             <td>
333
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
334
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
333
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
334
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
335 335
             </td>
336 336
         </tr>
337
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
337
+        <?php do_action('wpinv_discount_form_last', $post); ?>
338 338
     </tbody>
339 339
 </table>
340
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
340
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
341 341
     <?php
342 342
 }
343 343
 
344
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
345
-    $post_type = !empty( $post ) ? $post->post_type : '';
344
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
345
+    $post_type = !empty($post) ? $post->post_type : '';
346 346
     
347
-    if ( $post_type != 'wpi_discount' ) {
347
+    if ($post_type != 'wpi_discount') {
348 348
         return;
349 349
     }
350 350
     
351
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
351
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
352 352
         return;
353 353
     }
354 354
     
355
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
355
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
356 356
         return;
357 357
     }
358 358
     
359
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
359
+    if (!current_user_can('manage_options', $post_id)) {
360 360
         return;
361 361
     }
362 362
     
363
-    if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) {
363
+    if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') {
364 364
         $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m'];
365 365
     }
366 366
 
367
-    if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) {
367
+    if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) {
368 368
         $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m'];
369 369
     }
370 370
     
371
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
371
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
372 372
 }
373
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
374 373
\ No newline at end of file
374
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
375 375
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +222 added lines, -222 removed lines patch added patch discarded remove patch
@@ -7,264 +7,264 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
83
-            $time_format = get_option( 'time_format' );
84
-            $date_time_format = $date_format . ' '. $time_format;
82
+            $date_format = get_option('date_format');
83
+            $time_format = get_option('time_format');
84
+            $date_time_format = $date_format . ' ' . $time_format;
85 85
             
86
-            $t_time = get_the_time( $date_time_format );
86
+            $t_time = get_the_time($date_time_format);
87 87
             $m_time = $post->post_date;
88
-            $h_time = mysql2date( $date_format, $m_time );
88
+            $h_time = mysql2date($date_format, $m_time);
89 89
             
90
-            $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
90
+            $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
91 91
             break;
92 92
         case 'payment_date' :
93
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
94
-                $date_format = get_option( 'date_format' );
95
-                $time_format = get_option( 'time_format' );
96
-                $date_time_format = $date_format . ' '. $time_format;
93
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
94
+                $date_format = get_option('date_format');
95
+                $time_format = get_option('time_format');
96
+                $date_time_format = $date_format . ' ' . $time_format;
97 97
                 
98
-                $t_time = get_the_time( $date_time_format );
98
+                $t_time = get_the_time($date_time_format);
99 99
                 $m_time = $date_completed;
100
-                $h_time = mysql2date( $date_format, $m_time );
100
+                $h_time = mysql2date($date_format, $m_time);
101 101
                 
102
-                $value   = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
102
+                $value = '<abbr title="' . $t_time . '">' . $h_time . '</abbr>';
103 103
             } else {
104 104
                 $value = '-';
105 105
             }
106 106
             break;
107 107
         case 'status' :
108
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
109
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
110
-            if ( 1 == $is_viewed ) {
111
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
108
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
109
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
110
+            if (1 == $is_viewed) {
111
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
112 112
             }
113
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && ( $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ) ) ) {
114
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
113
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && ($gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()))) {
114
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
115 115
             }
116 116
             break;
117 117
         case 'number' :
118
-            $edit_link = get_edit_post_link( $post->ID );
119
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
118
+            $edit_link = get_edit_post_link($post->ID);
119
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
120 120
             break;
121 121
         case 'wpi_actions' :
122 122
             $value = '';
123
-            if ( !empty( $post->post_name ) ) {
124
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123
+            if (!empty($post->post_name)) {
124
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
125 125
             }
126 126
             
127
-            if ( $email = $wpi_invoice->get_email() ) {
128
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127
+            if ($email = $wpi_invoice->get_email()) {
128
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
129 129
             }
130 130
             
131 131
             break;
132 132
         default:
133
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
133
+            $value = isset($post->$column_name) ? $post->$column_name : '';
134 134
             break;
135 135
 
136 136
     }
137
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
137
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
138 138
     
139
-    if ( $value !== NULL ) {
139
+    if ($value !== NULL) {
140 140
         echo $value;
141 141
     }
142 142
 }
143 143
 
144
-function wpinv_admin_post_id( $id = 0 ) {
144
+function wpinv_admin_post_id($id = 0) {
145 145
     global $post;
146 146
 
147
-    if ( isset( $id ) && ! empty( $id ) ) {
147
+    if (isset($id) && !empty($id)) {
148 148
         return (int)$id;
149
-    } else if ( get_the_ID() ) {
150
-        return (int) get_the_ID();
151
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
152
-        return (int) $post->ID;
153
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
154
-        return (int) $_GET['post'];
155
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
156
-        return (int) $_GET['id'];
157
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
158
-        return (int) $_POST['id'];
149
+    } else if (get_the_ID()) {
150
+        return (int)get_the_ID();
151
+    } else if (isset($post->ID) && !empty($post->ID)) {
152
+        return (int)$post->ID;
153
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
154
+        return (int)$_GET['post'];
155
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
156
+        return (int)$_GET['id'];
157
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
158
+        return (int)$_POST['id'];
159 159
     } 
160 160
 
161 161
     return null;
162 162
 }
163 163
     
164
-function wpinv_admin_post_type( $id = 0 ) {
165
-    if ( !$id ) {
164
+function wpinv_admin_post_type($id = 0) {
165
+    if (!$id) {
166 166
         $id = wpinv_admin_post_id();
167 167
     }
168 168
     
169
-    $type = get_post_type( $id );
169
+    $type = get_post_type($id);
170 170
     
171
-    if ( !$type ) {
172
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
171
+    if (!$type) {
172
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
173 173
     }
174 174
     
175
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
175
+    return apply_filters('wpinv_admin_post_type', $type, $id);
176 176
 }
177 177
 
178 178
 function wpinv_admin_messages() {
179 179
 	global $wpinv_options, $pagenow, $post;
180 180
 
181
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
182
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
181
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
182
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
183 183
 	}
184 184
 
185
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
186
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
185
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
186
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
187 187
 	}
188 188
 
189
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
190
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
189
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
190
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
191 191
 	}
192 192
 
193
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
194
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
193
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
194
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
195 195
 	}
196 196
 
197
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
198
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
197
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
198
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
199 199
 	}
200 200
 
201
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
202
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
201
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
202
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
203 203
 	}
204 204
 
205
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
206
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
205
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
206
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
207 207
 	}
208 208
 
209
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
210
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
209
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
210
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
211 211
     }
212 212
     
213
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
214
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
213
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
214
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
215 215
     }
216 216
 
217
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
218
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
217
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
218
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
219 219
     }
220 220
 
221
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
222
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
221
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
222
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
223 223
 	}
224 224
 
225
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
226
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
225
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
226
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
227 227
 	}
228 228
 
229
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
230
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
229
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
230
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
231 231
 	}
232 232
     
233
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
234
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
233
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
234
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
235 235
 
236
-		if ( !empty( $message ) ) {
237
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
236
+		if (!empty($message)) {
237
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
238 238
 		}
239 239
 	}
240 240
 
241
-	settings_errors( 'wpinv-notices' );
241
+	settings_errors('wpinv-notices');
242 242
 }
243
-add_action( 'admin_notices', 'wpinv_admin_messages' );
243
+add_action('admin_notices', 'wpinv_admin_messages');
244 244
 
245
-function wpinv_items_columns( $existing_columns ) {
245
+function wpinv_items_columns($existing_columns) {
246 246
     global $wpinv_euvat;
247 247
     
248 248
     $columns                = array();
249 249
     $columns['cb']          = $existing_columns['cb'];
250
-    $columns['title']       = __( 'Title', 'invoicing' );
251
-    $columns['price']       = __( 'Price', 'invoicing' );
252
-    if ( $wpinv_euvat->allow_vat_rules() ) {
253
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
250
+    $columns['title']       = __('Title', 'invoicing');
251
+    $columns['price']       = __('Price', 'invoicing');
252
+    if ($wpinv_euvat->allow_vat_rules()) {
253
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
254 254
     }
255
-    if ( $wpinv_euvat->allow_vat_classes() ) {
256
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
255
+    if ($wpinv_euvat->allow_vat_classes()) {
256
+        $columns['vat_class']   = __('VAT class', 'invoicing');
257 257
     }
258
-    $columns['type']        = __( 'Type', 'invoicing' );
259
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
260
-    $columns['date']        = __( 'Date', 'invoicing' );
261
-    $columns['id']          = __( 'ID', 'invoicing' );
258
+    $columns['type']        = __('Type', 'invoicing');
259
+    $columns['recurring']   = __('Recurring', 'invoicing');
260
+    $columns['date']        = __('Date', 'invoicing');
261
+    $columns['id']          = __('ID', 'invoicing');
262 262
 
263
-    return apply_filters( 'wpinv_items_columns', $columns );
263
+    return apply_filters('wpinv_items_columns', $columns);
264 264
 }
265
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
265
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
266 266
 
267
-function wpinv_items_sortable_columns( $columns ) {
267
+function wpinv_items_sortable_columns($columns) {
268 268
     $columns['price']       = 'price';
269 269
     $columns['vat_rule']    = 'vat_rule';
270 270
     $columns['vat_class']   = 'vat_class';
@@ -274,151 +274,151 @@  discard block
 block discarded – undo
274 274
 
275 275
     return $columns;
276 276
 }
277
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
277
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
278 278
 
279
-function wpinv_items_table_custom_column( $column ) {
279
+function wpinv_items_table_custom_column($column) {
280 280
     global $wpinv_euvat, $post, $wpi_item;
281 281
     
282
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
283
-        $wpi_item = new WPInv_Item( $post->ID );
282
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
283
+        $wpi_item = new WPInv_Item($post->ID);
284 284
     }
285 285
 
286
-    switch ( $column ) {
286
+    switch ($column) {
287 287
         case 'price' :
288
-            echo wpinv_item_price( $post->ID );
288
+            echo wpinv_item_price($post->ID);
289 289
         break;
290 290
         case 'vat_rule' :
291
-            echo $wpinv_euvat->item_rule_label( $post->ID );
291
+            echo $wpinv_euvat->item_rule_label($post->ID);
292 292
         break;
293 293
         case 'vat_class' :
294
-            echo $wpinv_euvat->item_class_label( $post->ID );
294
+            echo $wpinv_euvat->item_class_label($post->ID);
295 295
         break;
296 296
         case 'type' :
297
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
297
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
298 298
         break;
299 299
         case 'recurring' :
300
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
300
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
301 301
         break;
302 302
         case 'id' :
303 303
            echo $post->ID;
304 304
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
305
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
306
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
307
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
305
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
306
+                    if ($wpinv_euvat->allow_vat_rules()) {
307
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
308 308
                     }
309
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
310
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
309
+                    if ($wpinv_euvat->allow_vat_classes()) {
310
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
311 311
                     }
312
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
312
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
313 313
                 </div>';
314 314
         break;
315 315
     }
316 316
     
317
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
317
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
318 318
 }
319
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
319
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
320 320
 
321 321
 function wpinv_add_items_filters() {
322 322
     global $wpinv_euvat, $typenow;
323 323
 
324 324
     // Checks if the current post type is 'item'
325
-    if ( $typenow == 'wpi_item') {
326
-        if ( $wpinv_euvat->allow_vat_rules() ) {
327
-            echo wpinv_html_select( array(
328
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
325
+    if ($typenow == 'wpi_item') {
326
+        if ($wpinv_euvat->allow_vat_rules()) {
327
+            echo wpinv_html_select(array(
328
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
329 329
                     'name'             => 'vat_rule',
330 330
                     'id'               => 'vat_rule',
331
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
331
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
332 332
                     'show_option_all'  => false,
333 333
                     'show_option_none' => false,
334 334
                     'class'            => 'gdmbx2-text-medium',
335
-                ) );
335
+                ));
336 336
         }
337 337
         
338
-        if ( $wpinv_euvat->allow_vat_classes() ) {
339
-            echo wpinv_html_select( array(
340
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
338
+        if ($wpinv_euvat->allow_vat_classes()) {
339
+            echo wpinv_html_select(array(
340
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
341 341
                     'name'             => 'vat_class',
342 342
                     'id'               => 'vat_class',
343
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
343
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
344 344
                     'show_option_all'  => false,
345 345
                     'show_option_none' => false,
346 346
                     'class'            => 'gdmbx2-text-medium',
347
-                ) );
347
+                ));
348 348
         }
349 349
             
350
-        echo wpinv_html_select( array(
351
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
350
+        echo wpinv_html_select(array(
351
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
352 352
                 'name'             => 'type',
353 353
                 'id'               => 'type',
354
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
354
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
355 355
                 'show_option_all'  => false,
356 356
                 'show_option_none' => false,
357 357
                 'class'            => 'gdmbx2-text-medium',
358
-            ) );
358
+            ));
359 359
 
360
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
360
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
361 361
             echo '<input type="hidden" name="all_posts" value="1" />';
362 362
         }
363 363
     }
364 364
 }
365
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
365
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
366 366
 
367
-function wpinv_send_invoice_after_save( $invoice ) {
368
-    if ( empty( $_POST['wpi_save_send'] ) ) {
367
+function wpinv_send_invoice_after_save($invoice) {
368
+    if (empty($_POST['wpi_save_send'])) {
369 369
         return;
370 370
     }
371 371
     
372
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
373
-        wpinv_user_invoice_notification( $invoice->ID );
372
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
373
+        wpinv_user_invoice_notification($invoice->ID);
374 374
     }
375 375
 }
376
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
376
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
377 377
 
378
-function wpinv_send_register_new_user( $data, $postarr ) {
379
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
380
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
381
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
378
+function wpinv_send_register_new_user($data, $postarr) {
379
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
380
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
381
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
382 382
         
383
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
384
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
385
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
386
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
387
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
388
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
383
+        if ($is_new_user && $email && !email_exists($email)) {
384
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
385
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
386
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
387
+            $user_nicename = $display_name ? trim($display_name) : $email;
388
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
389 389
             
390
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
391
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
390
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
391
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
392 392
                 $new_user_login = strstr($email, '@', true);
393
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
394
-                    $user_login = sanitize_user($new_user_login, true );
393
+                if (validate_username($user_login) && username_exists($user_login)) {
394
+                    $user_login = sanitize_user($new_user_login, true);
395 395
                 }
396
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
397
-                    $user_append_text = rand(10,1000);
398
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
396
+                if (validate_username($user_login) && username_exists($user_login)) {
397
+                    $user_append_text = rand(10, 1000);
398
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
399 399
                 }
400 400
                 
401
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
401
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
402 402
                     $user_login = $email;
403 403
                 }
404 404
             }
405 405
             
406 406
             $userdata = array(
407 407
                 'user_login' => $user_login,
408
-                'user_pass' => wp_generate_password( 12, false ),
409
-                'user_email' => sanitize_text_field( $email ),
408
+                'user_pass' => wp_generate_password(12, false),
409
+                'user_email' => sanitize_text_field($email),
410 410
                 'first_name' => $first_name,
411 411
                 'last_name' => $last_name,
412
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
412
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
413 413
                 'nickname' => $display_name,
414 414
                 'display_name' => $display_name,
415 415
             );
416 416
 
417
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
417
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
418 418
             
419
-            $new_user_id = wp_insert_user( $userdata );
419
+            $new_user_id = wp_insert_user($userdata);
420 420
             
421
-            if ( !is_wp_error( $new_user_id ) ) {
421
+            if (!is_wp_error($new_user_id)) {
422 422
                 $data['post_author'] = $new_user_id;
423 423
                 $_POST['post_author'] = $new_user_id;
424 424
                 $_POST['post_author_override'] = $new_user_id;
@@ -439,69 +439,69 @@  discard block
 block discarded – undo
439 439
                 
440 440
                 $meta = array();
441 441
                 ///$meta['_wpinv_user_id'] = $new_user_id;
442
-                foreach ( $meta_fields as $field ) {
443
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
442
+                foreach ($meta_fields as $field) {
443
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
444 444
                 }
445 445
                 
446
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
446
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
447 447
 
448 448
                 // Update user meta.
449
-                foreach ( $meta as $key => $value ) {
450
-                    update_user_meta( $new_user_id, $key, $value );
449
+                foreach ($meta as $key => $value) {
450
+                    update_user_meta($new_user_id, $key, $value);
451 451
                 }
452 452
                 
453
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
453
+                if (function_exists('wp_send_new_user_notifications')) {
454 454
                     // Send email notifications related to the creation of new user.
455
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
455
+                    wp_send_new_user_notifications($new_user_id, 'user');
456 456
                 }
457 457
             } else {
458
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
458
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
459 459
             }
460 460
         }
461 461
     }
462 462
     
463 463
     return $data;
464 464
 }
465
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
465
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
466 466
 
467
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
467
+function wpinv_show_recurring_supported_gateways($item_ID) {
468 468
     $all_gateways = wpinv_get_payment_gateways();
469 469
 
470
-    if ( !empty( $all_gateways ) ) {
470
+    if (!empty($all_gateways)) {
471 471
         $gateways = array();
472 472
 
473
-        foreach ( $all_gateways as $key => $gateway ) {
474
-            if ( wpinv_gateway_support_subscription( $key ) ) {
473
+        foreach ($all_gateways as $key => $gateway) {
474
+            if (wpinv_gateway_support_subscription($key)) {
475 475
                 $gateways[] = $gateway['admin_label'];
476 476
             }
477 477
         }
478 478
 
479
-        if ( !empty( $gateways ) ) {
479
+        if (!empty($gateways)) {
480 480
             ?>
481
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
481
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
482 482
             <?php
483 483
         }
484 484
     }
485 485
 }
486
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
486
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
487 487
 
488
-function wpinv_post_updated_messages( $messages ) {
488
+function wpinv_post_updated_messages($messages) {
489 489
     global $post, $post_ID;
490 490
 
491 491
     $messages['wpi_discount'] = array(
492 492
         0   => '',
493
-        1   => __( 'Discount updated.', 'invoicing' ),
494
-        2   => __( 'Custom field updated.', 'invoicing' ),
495
-        3   => __( 'Custom field deleted.', 'invoicing' ),
496
-        4   => __( 'Discount updated.', 'invoicing' ),
497
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
498
-        6   => __( 'Discount updated.', 'invoicing' ),
499
-        7   => __( 'Discount saved.', 'invoicing' ),
500
-        8   => __( 'Discount submitted.', 'invoicing' ),
501
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
502
-        10  => __( 'Discount draft updated.', 'invoicing' ),
493
+        1   => __('Discount updated.', 'invoicing'),
494
+        2   => __('Custom field updated.', 'invoicing'),
495
+        3   => __('Custom field deleted.', 'invoicing'),
496
+        4   => __('Discount updated.', 'invoicing'),
497
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
498
+        6   => __('Discount updated.', 'invoicing'),
499
+        7   => __('Discount saved.', 'invoicing'),
500
+        8   => __('Discount submitted.', 'invoicing'),
501
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
502
+        10  => __('Discount draft updated.', 'invoicing'),
503 503
     );
504 504
 
505 505
     return $messages;
506 506
 }
507
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
508 507
\ No newline at end of file
508
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
509 509
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-bp-core.php 1 patch
Spacing   +122 added lines, -122 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
 
@@ -11,60 +11,60 @@  discard block
 block discarded – undo
11 11
     public function __construct() {
12 12
         global $bp;
13 13
         
14
-        if ( !defined( 'WPINV_BP_SLUG' ) ) {
15
-            define( 'WPINV_BP_SLUG', 'invoices' );
14
+        if (!defined('WPINV_BP_SLUG')) {
15
+            define('WPINV_BP_SLUG', 'invoices');
16 16
         }
17 17
         
18
-        $position       = wpinv_get_option( 'wpinv_menu_position' );
18
+        $position       = wpinv_get_option('wpinv_menu_position');
19 19
         $position       = $position !== '' && $position !== false ? $position : 91;
20
-        $this->position = apply_filters( 'wpinv_bp_nav_position', $position );
20
+        $this->position = apply_filters('wpinv_bp_nav_position', $position);
21 21
         $this->slug     = WPINV_BP_SLUG;
22 22
         
23 23
         parent::start(
24 24
             'invoicing',
25
-            _x( 'Invoices', 'Invoices screen page <title>', 'invoicing' ),
26
-            trailingslashit( dirname( __FILE__ ) ),
25
+            _x('Invoices', 'Invoices screen page <title>', 'invoicing'),
26
+            trailingslashit(dirname(__FILE__)),
27 27
             array(
28 28
                 'adminbar_myaccount_order' => $this->position
29 29
             )
30 30
         );
31 31
     }
32 32
     
33
-    public function includes( $includes = array() ) {
34
-        parent::includes( $includes );
33
+    public function includes($includes = array()) {
34
+        parent::includes($includes);
35 35
     }
36 36
     
37
-    public function setup_globals( $args = array() ) {
37
+    public function setup_globals($args = array()) {
38 38
         global $bp;
39 39
 
40 40
         $args = array(
41 41
             'slug' => $this->slug,
42 42
         );
43 43
 
44
-        parent::setup_globals( $args );
44
+        parent::setup_globals($args);
45 45
     }
46 46
     
47
-    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
48
-        if ( !bp_is_my_profile() ) {
47
+    public function setup_nav($main_nav = array(), $sub_nav = array()) {
48
+        if (!bp_is_my_profile()) {
49 49
             return;
50 50
         }
51 51
         
52
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) {
52
+        if (wpinv_get_option('wpinv_bp_hide_menu')) {
53 53
             return;
54 54
         }
55 55
         
56 56
         $this->setup_invoice_count();
57 57
 
58 58
         $user_domain    = bp_loggedin_user_domain();
59
-        $invoices_link  = trailingslashit( $user_domain . $this->slug );
60
-        $class          = ( 0 === $this->count ) ? 'no-count' : 'count';
59
+        $invoices_link  = trailingslashit($user_domain . $this->slug);
60
+        $class          = (0 === $this->count) ? 'no-count' : 'count';
61 61
 
62 62
         $main_nav_name = sprintf(
63
-            __( 'My Invoices %s', 'invoicing' ),
63
+            __('My Invoices %s', 'invoicing'),
64 64
             sprintf(
65 65
                 '<span class="%s">%s</span>',
66
-                esc_attr( $class ),
67
-                bp_core_number_format( $this->count )
66
+                esc_attr($class),
67
+                bp_core_number_format($this->count)
68 68
             )
69 69
         );
70 70
 
@@ -72,54 +72,54 @@  discard block
 block discarded – undo
72 72
             'name'                => $main_nav_name,
73 73
             'slug'                => $this->slug,
74 74
             'position'            => $this->position,
75
-            'screen_function'     => array( $this, 'invoices_screen' ),
75
+            'screen_function'     => array($this, 'invoices_screen'),
76 76
             'default_subnav_slug' => 'invoices',
77 77
             'item_css_id'         => $this->id
78 78
         );
79 79
         
80 80
         $sub_nav[] = array(
81
-            'name'            => _x( 'My Invoices', 'Invoices screen sub nav', 'invoicing' ),
81
+            'name'            => _x('My Invoices', 'Invoices screen sub nav', 'invoicing'),
82 82
             'slug'            => 'invoices',
83 83
             'parent_url'      => $invoices_link,
84 84
             'parent_slug'     => $this->slug,
85
-            'screen_function' => array( $this, 'invoices_screen' ),
85
+            'screen_function' => array($this, 'invoices_screen'),
86 86
             'position'        => 10,
87 87
             'item_css_id'     => 'invoices-my-invoices'
88 88
         );
89 89
 
90
-        parent::setup_nav( $main_nav, $sub_nav );
90
+        parent::setup_nav($main_nav, $sub_nav);
91 91
     }
92 92
     
93 93
     public function setup_title() {
94 94
         // Adjust title.
95
-        if ( (bool)bp_is_current_component( 'invoicing' ) ) {
95
+        if ((bool)bp_is_current_component('invoicing')) {
96 96
             global $bp;
97 97
             
98
-            $bp->bp_options_title = __( 'My Invoices', 'invoicing' );
98
+            $bp->bp_options_title = __('My Invoices', 'invoicing');
99 99
         }
100 100
 
101 101
         parent::setup_title();
102 102
     }
103 103
     
104 104
     public function invoices_screen() {
105
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) {
105
+        if (wpinv_get_option('wpinv_bp_hide_menu')) {
106 106
             return;
107 107
         }
108 108
         
109 109
         global $bp;
110 110
         
111
-        add_action( 'bp_template_content', array( $this, 'invoices_content' ) );
111
+        add_action('bp_template_content', array($this, 'invoices_content'));
112 112
 
113
-        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
113
+        $template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
114 114
         
115
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
115
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
116 116
     }
117 117
     
118 118
     public function invoices_content() {
119
-        if ( $this->has_invoices( bp_ajax_querystring( 'invoices' ) ) ) {
119
+        if ($this->has_invoices(bp_ajax_querystring('invoices'))) {
120 120
             global $invoices_template;
121 121
             
122
-            do_action( 'wpinv_bp_invoices_before_content' );
122
+            do_action('wpinv_bp_invoices_before_content');
123 123
             ?>
124 124
             <div class="wpi-bp-invoices invoices invoicing" style="position:relative">
125 125
                 <div id="pag-top" class="pagination">
@@ -133,61 +133,61 @@  discard block
 block discarded – undo
133 133
                 <table class="table table-bordered table-hover wpi-user-invoices" style="margin:0">
134 134
                     <thead>
135 135
                         <tr>
136
-                            <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
137
-                                <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>
136
+                            <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
137
+                                <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>
138 138
                             <?php endforeach; ?>
139 139
                         </tr>
140 140
                     </thead>
141 141
                     <tbody>
142
-                        <?php foreach ( $invoices_template->invoices as $invoice ) {
142
+                        <?php foreach ($invoices_template->invoices as $invoice) {
143 143
                             ?>
144 144
                             <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
145
-                                <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
146
-                                    <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'] ); ?>">
147
-                                        <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
148
-                                            <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
149
-
150
-                                        <?php elseif ( 'invoice-number' === $column_id ) : ?>
151
-                                            <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
152
-                                                <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
145
+                                <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
146
+                                    <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']); ?>">
147
+                                        <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
148
+                                            <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
149
+
150
+                                        <?php elseif ('invoice-number' === $column_id) : ?>
151
+                                            <a href="<?php echo esc_url($invoice->get_view_url()); ?>">
152
+                                                <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
153 153
                                             </a>
154 154
 
155
-                                        <?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?>
156
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
155
+                                        <?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?>
156
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
157 157
 
158
-                                        <?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?>
159
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
158
+                                        <?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?>
159
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
160 160
 
161
-                                        <?php elseif ( 'invoice-status' === $column_id ) : ?>
162
-                                            <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
161
+                                        <?php elseif ('invoice-status' === $column_id) : ?>
162
+                                            <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
163 163
 
164
-                                        <?php elseif ( 'invoice-total' === $column_id ) : ?>
165
-                                            <?php echo $invoice->get_total( true ); ?>
164
+                                        <?php elseif ('invoice-total' === $column_id) : ?>
165
+                                            <?php echo $invoice->get_total(true); ?>
166 166
 
167
-                                        <?php elseif ( 'invoice-actions' === $column_id ) : ?>
167
+                                        <?php elseif ('invoice-actions' === $column_id) : ?>
168 168
                                             <?php
169 169
                                                 $actions = array(
170 170
                                                     'pay'    => array(
171 171
                                                         'url'  => $invoice->get_checkout_payment_url(),
172
-                                                        'name' => __( 'Pay Now', 'invoicing' ),
172
+                                                        'name' => __('Pay Now', 'invoicing'),
173 173
                                                         'class' => 'btn-success'
174 174
                                                     ),
175 175
                                                     'print'   => array(
176 176
                                                         'url'  => $invoice->get_view_url(),
177
-                                                        'name' => __( 'Print', 'invoicing' ),
177
+                                                        'name' => __('Print', 'invoicing'),
178 178
                                                         'class' => 'btn-primary',
179 179
                                                         'attrs' => 'target="_blank"'
180 180
                                                     )
181 181
                                                 );
182 182
 
183
-                                                if ( ! $invoice->needs_payment() ) {
184
-                                                    unset( $actions['pay'] );
183
+                                                if (!$invoice->needs_payment()) {
184
+                                                    unset($actions['pay']);
185 185
                                                 }
186 186
 
187
-                                                if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
188
-                                                    foreach ( $actions as $key => $action ) {
187
+                                                if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
188
+                                                    foreach ($actions as $key => $action) {
189 189
                                                         $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
190
-                                                        echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
190
+                                                        echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
191 191
                                                     }
192 192
                                                 }
193 193
                                             ?>
@@ -215,64 +215,64 @@  discard block
 block discarded – undo
215 215
             </div>
216 216
             <?php
217 217
         
218
-            do_action( 'wpinv_bp_invoices_after_content' );
218
+            do_action('wpinv_bp_invoices_after_content');
219 219
         } else {
220 220
             ?>
221 221
             <div id="message" class="info">
222
-                <p><?php _e( 'No invoice has been made yet.', 'invoicing' ); ?></p>
222
+                <p><?php _e('No invoice has been made yet.', 'invoicing'); ?></p>
223 223
             </div>
224 224
             <?php
225 225
         }
226 226
         
227
-        if ( defined( 'DOING_AJAX' ) ) {
227
+        if (defined('DOING_AJAX')) {
228 228
             exit;
229 229
         }
230 230
     }
231 231
     
232
-    public function has_invoices( $args = '' ) {
232
+    public function has_invoices($args = '') {
233 233
         global $invoices_template;
234 234
 
235
-        $per_page = absint( wpinv_get_option( 'wpinv_bp_per_page' ) );
235
+        $per_page = absint(wpinv_get_option('wpinv_bp_per_page'));
236 236
         // Parse arguments.
237
-        $r = bp_parse_args( $args, array(
237
+        $r = bp_parse_args($args, array(
238 238
             'status'            => 'all',
239 239
             'page_arg'          => 'bpage',
240 240
             'page'              => 1,
241 241
             'per_page'          => $per_page > 0 ? $per_page : 20,
242 242
             'max'               => false,
243 243
             'user_id'           => bp_loggedin_user_id(),
244
-        ), 'has_invoices' );
244
+        ), 'has_invoices');
245 245
 
246 246
 
247
-        if ( ! empty( $r['max'] ) && ( (int)$r['per_page'] > (int)$r['max'] ) ) {
247
+        if (!empty($r['max']) && ((int)$r['per_page'] > (int)$r['max'])) {
248 248
             $r['per_page'] = (int)$r['max'];
249 249
         }
250 250
 
251 251
         // Get the invoices.
252
-        $invoices_template = new WPInv_BP_Invoices_Template( $r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg'] );
252
+        $invoices_template = new WPInv_BP_Invoices_Template($r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg']);
253 253
 
254
-        return apply_filters( 'wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r );
254
+        return apply_filters('wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r);
255 255
     }
256 256
     
257 257
     public function setup_invoice_count() {
258
-        $query      = apply_filters( 'wpinv_user_invoices_count_query', array( 'user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false ) );
259
-        $invoices   = wpinv_get_invoices( $query );
258
+        $query      = apply_filters('wpinv_user_invoices_count_query', array('user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false));
259
+        $invoices   = wpinv_get_invoices($query);
260 260
         
261
-        $this->count = !empty( $invoices ) ? count( $invoices ) : 0;
261
+        $this->count = !empty($invoices) ? count($invoices) : 0;
262 262
     }
263 263
     
264 264
     public function pagination_count() {
265 265
         global $invoices_template;
266 266
 
267
-        $start_num = intval( ( $invoices_template->pag_page - 1 ) * $invoices_template->pag_num ) + 1;
268
-        $from_num  = bp_core_number_format( $start_num );
269
-        $to_num    = bp_core_number_format( ( $start_num + ( $invoices_template->pag_num - 1 ) > $invoices_template->total_invoice_count ) ? $invoices_template->total_invoice_count : $start_num + ( $invoices_template->pag_num - 1 ) );
270
-        $total     = bp_core_number_format( $invoices_template->total_invoice_count );
267
+        $start_num = intval(($invoices_template->pag_page - 1) * $invoices_template->pag_num) + 1;
268
+        $from_num  = bp_core_number_format($start_num);
269
+        $to_num    = bp_core_number_format(($start_num + ($invoices_template->pag_num - 1) > $invoices_template->total_invoice_count) ? $invoices_template->total_invoice_count : $start_num + ($invoices_template->pag_num - 1));
270
+        $total     = bp_core_number_format($invoices_template->total_invoice_count);
271 271
 
272
-        if ( 1 == $invoices_template->total_invoice_count ) {
273
-            $message = __( 'Viewing 1 invoice', 'invoicing' );
272
+        if (1 == $invoices_template->total_invoice_count) {
273
+            $message = __('Viewing 1 invoice', 'invoicing');
274 274
         } else {
275
-            $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing' ), $from_num, $to_num, $total );
275
+            $message = sprintf(_n('Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing'), $from_num, $to_num, $total);
276 276
         }
277 277
 
278 278
         return $message;
@@ -281,32 +281,32 @@  discard block
 block discarded – undo
281 281
     function pagination_links() {
282 282
         global $invoices_template;
283 283
 
284
-        return apply_filters( 'wpinv_bp_get_pagination_links', $invoices_template->pag_links );
284
+        return apply_filters('wpinv_bp_get_pagination_links', $invoices_template->pag_links);
285 285
     }
286 286
     
287
-    public function bp_section( $settings = array() ) {
288
-        $settings['wpinv_bp'] = __( 'BuddyPress Integration', 'invoicing' );
287
+    public function bp_section($settings = array()) {
288
+        $settings['wpinv_bp'] = __('BuddyPress Integration', 'invoicing');
289 289
         return $settings;
290 290
     }
291 291
     
292
-    public function bp_settings( $settings = array() ) {
292
+    public function bp_settings($settings = array()) {
293 293
         $settings['wpinv_bp'] = array(
294 294
             'wpinv_bp_labels' => array(
295 295
                 'id'   => 'wpinv_bp_settings',
296
-                'name' => '<h3>' . __( 'BuddyPress Integration', 'invoicing' ) . '</h3>',
296
+                'name' => '<h3>' . __('BuddyPress Integration', 'invoicing') . '</h3>',
297 297
                 'desc' => '',
298 298
                 'type' => 'header',
299 299
             ),
300 300
             'wpinv_bp_hide_menu' => array(
301 301
                 'id'   => 'wpinv_bp_hide_menu',
302
-                'name' => __( 'Hide Invoices link', 'invoicing' ),
303
-                'desc' => __( 'Hide Invoices link from BP Profile menu.', 'invoicing' ),
302
+                'name' => __('Hide Invoices link', 'invoicing'),
303
+                'desc' => __('Hide Invoices link from BP Profile menu.', 'invoicing'),
304 304
                 'type' => 'checkbox',
305 305
             ),
306 306
             'wpinv_menu_position' => array(
307 307
                 'id'   => 'wpinv_menu_position',
308
-                'name' => __( 'Menu position', 'invoicing' ),
309
-                'desc' => __( 'Menu position for the Invoices link in BP Profile menu.', 'invoicing' ),
308
+                'name' => __('Menu position', 'invoicing'),
309
+                'desc' => __('Menu position for the Invoices link in BP Profile menu.', 'invoicing'),
310 310
                 'type' => 'number',
311 311
                 'size' => 'small',
312 312
                 'min'  => '1',
@@ -316,8 +316,8 @@  discard block
 block discarded – undo
316 316
             ),
317 317
             'wpinv_bp_per_page' => array(
318 318
                 'id'   => 'wpinv_bp_per_page',
319
-                'name' => __( 'Max invoices per page', 'invoicing' ),
320
-                'desc' => __( 'Enter a number to lists the invoices for each page.', 'invoicing' ),
319
+                'name' => __('Max invoices per page', 'invoicing'),
320
+                'desc' => __('Enter a number to lists the invoices for each page.', 'invoicing'),
321 321
                 'type' => 'number',
322 322
                 'size' => 'small',
323 323
                 'min'  => '1',
@@ -342,25 +342,25 @@  discard block
 block discarded – undo
342 342
     public $pag_links = '';
343 343
     public $total_invoice_count = 0;
344 344
     
345
-    public function __construct( $status, $page, $per_page, $max, $user_id, $page_arg = 'bpage' ) {
346
-        $this->invoices = array( 'invoices' => array(), 'total' => 0 );
345
+    public function __construct($status, $page, $per_page, $max, $user_id, $page_arg = 'bpage') {
346
+        $this->invoices = array('invoices' => array(), 'total' => 0);
347 347
         
348
-        $this->pag_arg  = sanitize_key( $page_arg );
349
-        $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page );
350
-        $this->pag_num  = bp_sanitize_pagination_arg( 'num', $per_page );
348
+        $this->pag_arg  = sanitize_key($page_arg);
349
+        $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page);
350
+        $this->pag_num  = bp_sanitize_pagination_arg('num', $per_page);
351 351
 
352
-        $query_args     = array( 'user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true );
353
-        if ( !empty( $status ) && $status != 'all' ) {
352
+        $query_args     = array('user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true);
353
+        if (!empty($status) && $status != 'all') {
354 354
            $query_args['status'] = $status;
355 355
         }
356
-        $invoices  = wpinv_get_invoices( apply_filters( 'wpinv_bp_user_invoices_query', $query_args ) );
356
+        $invoices = wpinv_get_invoices(apply_filters('wpinv_bp_user_invoices_query', $query_args));
357 357
         
358
-        if ( !empty( $invoices ) && !empty( $invoices->found_posts ) ) {
359
-            $this->invoices['invoices'] = array_map( 'wpinv_get_invoice', $invoices->posts );
358
+        if (!empty($invoices) && !empty($invoices->found_posts)) {
359
+            $this->invoices['invoices'] = array_map('wpinv_get_invoice', $invoices->posts);
360 360
             $this->invoices['total']    = $invoices->found_posts;
361 361
         }
362 362
 
363
-        if ( empty( $max ) || ( $max >= (int)$this->invoices['total'] ) ) {
363
+        if (empty($max) || ($max >= (int)$this->invoices['total'])) {
364 364
             $this->total_invoice_count = (int)$this->invoices['total'];
365 365
         } else {
366 366
             $this->total_invoice_count = (int)$max;
@@ -368,52 +368,52 @@  discard block
 block discarded – undo
368 368
 
369 369
         $this->invoices = $this->invoices['invoices'];
370 370
 
371
-        $invoice_count = count( $this->invoices );
371
+        $invoice_count = count($this->invoices);
372 372
 
373
-        if ( empty( $max ) || ( $max >= (int)$invoice_count ) ) {
373
+        if (empty($max) || ($max >= (int)$invoice_count)) {
374 374
             $this->invoice_count = (int)$invoice_count;
375 375
         } else {
376 376
             $this->invoice_count = (int)$max;
377 377
         }
378 378
         
379
-        if ( ! empty( $this->total_invoice_count ) && ! empty( $this->pag_num ) ) {
380
-            $this->pag_links = paginate_links( array(
381
-                'base'      => add_query_arg( $this->pag_arg, '%#%' ),
379
+        if (!empty($this->total_invoice_count) && !empty($this->pag_num)) {
380
+            $this->pag_links = paginate_links(array(
381
+                'base'      => add_query_arg($this->pag_arg, '%#%'),
382 382
                 'format'    => '',
383
-                'total'     => ceil( (int)$this->total_invoice_count / (int)$this->pag_num ),
383
+                'total'     => ceil((int)$this->total_invoice_count / (int)$this->pag_num),
384 384
                 'current'   => (int)$this->pag_page,
385
-                'prev_text' => _x( '&larr;', 'Invoice pagination previous text', 'invoicing' ),
386
-                'next_text' => _x( '&rarr;', 'Invoice pagination next text',     'invoicing' ),
385
+                'prev_text' => _x('&larr;', 'Invoice pagination previous text', 'invoicing'),
386
+                'next_text' => _x('&rarr;', 'Invoice pagination next text', 'invoicing'),
387 387
                 'mid_size'  => 1,
388 388
                 'add_args'  => array(),
389
-            ) );
389
+            ));
390 390
         }
391 391
     }
392 392
 
393 393
     public function has_invoices() {
394
-        return (bool) ! empty( $this->invoice_count );
394
+        return (bool)!empty($this->invoice_count);
395 395
     }
396 396
 
397 397
     public function next_invoice() {
398 398
         $this->current_invoice++;
399
-        $this->invoice = $this->invoices[ $this->current_invoice ];
399
+        $this->invoice = $this->invoices[$this->current_invoice];
400 400
 
401 401
         return $this->invoice;
402 402
     }
403 403
 
404 404
     public function rewind_invoices() {
405 405
         $this->current_invoice = -1;
406
-        if ( $this->invoice_count > 0 ) {
406
+        if ($this->invoice_count > 0) {
407 407
             $this->invoice = $this->invoices[0];
408 408
         }
409 409
     }
410 410
 
411 411
     public function invoices() {
412
-        if ( ( $this->current_invoice + 1 ) < $this->invoice_count ) {
412
+        if (($this->current_invoice + 1) < $this->invoice_count) {
413 413
             return true;
414
-        } elseif ( ( $this->current_invoice + 1 ) === $this->invoice_count ) {
414
+        } elseif (($this->current_invoice + 1) === $this->invoice_count) {
415 415
 
416
-            do_action( 'wpinv_bp_invoice_loop_end' );
416
+            do_action('wpinv_bp_invoice_loop_end');
417 417
             
418 418
             $this->rewind_invoices();
419 419
         }
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
         $this->in_the_loop = true;
428 428
         $this->invoice     = $this->next_invoice();
429 429
 
430
-        if ( 0 === $this->current_invoice ) {
431
-            do_action( 'wpinv_bp_invoice_loop_start' );
430
+        if (0 === $this->current_invoice) {
431
+            do_action('wpinv_bp_invoice_loop_start');
432 432
         }
433 433
     }
434 434
 }
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
 
439 439
     $bp->invoicing = new WPInv_BP_Component();
440 440
     
441
-    add_action( 'wp_ajax_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) );
442
-    add_action( 'wp_ajax_nopriv_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) );
443
-    add_filter( 'wpinv_settings_sections_general', array( $bp->invoicing, 'bp_section' ), 10, 1 );
444
-    add_filter( 'wpinv_settings_general', array( $bp->invoicing, 'bp_settings' ), 10, 1 );
441
+    add_action('wp_ajax_invoicing_filter', array($bp->invoicing, 'invoices_content'));
442
+    add_action('wp_ajax_nopriv_invoicing_filter', array($bp->invoicing, 'invoices_content'));
443
+    add_filter('wpinv_settings_sections_general', array($bp->invoicing, 'bp_section'), 10, 1);
444
+    add_filter('wpinv_settings_general', array($bp->invoicing, 'bp_settings'), 10, 1);
445 445
 }
446
-add_action( 'bp_loaded', 'wpinv_bp_setup_component' );
447 446
\ No newline at end of file
447
+add_action('bp_loaded', 'wpinv_bp_setup_component');
448 448
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +238 added lines, -238 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  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_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        @header( 'X-Robots-Tag: noindex' );
53
+        @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -77,39 +77,39 @@  discard block
 block discarded – undo
77 77
             'buy_items' => true,
78 78
         );
79 79
 
80
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
81
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
80
+        foreach ($ajax_events as $ajax_event => $nopriv) {
81
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
82 82
             
83
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
84
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
83
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
84
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
85 85
             }
86 86
 
87
-            if ( $nopriv ) {
88
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
+            if ($nopriv) {
88
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
89 89
 
90
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
91 91
             }
92 92
         }
93 93
     }
94 94
     
95 95
     public static function add_note() {
96
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
96
+        check_ajax_referer('add-invoice-note', '_nonce');
97 97
 
98
-        if ( !current_user_can( 'manage_options' ) ) {
98
+        if (!current_user_can('manage_options')) {
99 99
             die(-1);
100 100
         }
101 101
 
102
-        $post_id   = absint( $_POST['post_id'] );
103
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
104
-        $note_type = sanitize_text_field( $_POST['note_type'] );
102
+        $post_id   = absint($_POST['post_id']);
103
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
104
+        $note_type = sanitize_text_field($_POST['note_type']);
105 105
 
106 106
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
107 107
 
108
-        if ( $post_id > 0 ) {
109
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
108
+        if ($post_id > 0) {
109
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
110 110
 
111
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
112
-                wpinv_get_invoice_note_line_item( $note_id );
111
+            if ($note_id > 0 && !is_wp_error($note_id)) {
112
+                wpinv_get_invoice_note_line_item($note_id);
113 113
             }
114 114
         }
115 115
 
@@ -117,16 +117,16 @@  discard block
 block discarded – undo
117 117
     }
118 118
 
119 119
     public static function delete_note() {
120
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
120
+        check_ajax_referer('delete-invoice-note', '_nonce');
121 121
 
122
-        if ( !current_user_can( 'manage_options' ) ) {
122
+        if (!current_user_can('manage_options')) {
123 123
             die(-1);
124 124
         }
125 125
 
126 126
         $note_id = (int)$_POST['note_id'];
127 127
 
128
-        if ( $note_id > 0 ) {
129
-            wp_delete_comment( $note_id, true );
128
+        if ($note_id > 0) {
129
+            wp_delete_comment($note_id, true);
130 130
         }
131 131
 
132 132
         die();
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
     }
140 140
     
141 141
     public static function checkout() {
142
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
143
-            define( 'WPINV_CHECKOUT', true );
142
+        if (!defined('WPINV_CHECKOUT')) {
143
+            define('WPINV_CHECKOUT', true);
144 144
         }
145 145
 
146 146
         wpinv_process_checkout();
@@ -149,53 +149,53 @@  discard block
 block discarded – undo
149 149
     
150 150
     public static function add_invoice_item() {
151 151
         global $wpi_userID, $wpinv_ip_address_country;
152
-        check_ajax_referer( 'invoice-item', '_nonce' );
153
-        if ( !current_user_can( 'manage_options' ) ) {
152
+        check_ajax_referer('invoice-item', '_nonce');
153
+        if (!current_user_can('manage_options')) {
154 154
             die(-1);
155 155
         }
156 156
         
157
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
158
-        $invoice_id = absint( $_POST['invoice_id'] );
157
+        $item_id    = sanitize_text_field($_POST['item_id']);
158
+        $invoice_id = absint($_POST['invoice_id']);
159 159
         
160
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
160
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
161 161
             die();
162 162
         }
163 163
         
164
-        $invoice    = wpinv_get_invoice( $invoice_id );
165
-        if ( empty( $invoice ) ) {
164
+        $invoice = wpinv_get_invoice($invoice_id);
165
+        if (empty($invoice)) {
166 166
             die();
167 167
         }
168 168
         
169
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
169
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
170 170
             die(); // Don't allow modify items for paid invoice.
171 171
         }
172 172
         
173
-        if ( !empty( $_POST['user_id'] ) ) {
174
-            $wpi_userID = absint( $_POST['user_id'] ); 
173
+        if (!empty($_POST['user_id'])) {
174
+            $wpi_userID = absint($_POST['user_id']); 
175 175
         }
176 176
 
177
-        $item = new WPInv_Item( $item_id );
178
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
177
+        $item = new WPInv_Item($item_id);
178
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
179 179
             die();
180 180
         }
181 181
         
182 182
         // Validate item before adding to invoice because recurring item must be paid individually.
183
-        if ( !empty( $invoice->cart_details ) ) {
183
+        if (!empty($invoice->cart_details)) {
184 184
             $valid = true;
185 185
             
186
-            if ( $recurring_item = $invoice->get_recurring() ) {
187
-                if ( $recurring_item != $item_id ) {
186
+            if ($recurring_item = $invoice->get_recurring()) {
187
+                if ($recurring_item != $item_id) {
188 188
                     $valid = false;
189 189
                 }
190
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
190
+            } else if (wpinv_is_recurring_item($item_id)) {
191 191
                 $valid = false;
192 192
             }
193 193
             
194
-            if ( !$valid ) {
194
+            if (!$valid) {
195 195
                 $response               = array();
196 196
                 $response['success']    = false;
197
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
198
-                wp_send_json( $response );
197
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
198
+                wp_send_json($response);
199 199
             }
200 200
         }
201 201
         
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
         
204 204
         $data                   = array();
205 205
         $data['invoice_id']     = $invoice_id;
206
-        $data['cart_discounts'] = $invoice->get_discounts( true );
206
+        $data['cart_discounts'] = $invoice->get_discounts(true);
207 207
         
208
-        wpinv_set_checkout_session( $data );
208
+        wpinv_set_checkout_session($data);
209 209
         
210 210
         $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211 211
 
@@ -220,21 +220,21 @@  discard block
 block discarded – undo
220 220
             'fees'          => array()
221 221
         );
222 222
 
223
-        $invoice->add_item( $item_id, $args );
223
+        $invoice->add_item($item_id, $args);
224 224
         $invoice->save();
225 225
         
226
-        if ( empty( $_POST['country'] ) ) {
226
+        if (empty($_POST['country'])) {
227 227
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
228 228
         }
229
-        if ( empty( $_POST['state'] ) ) {
229
+        if (empty($_POST['state'])) {
230 230
             $_POST['state'] = $invoice->state;
231 231
         }
232 232
          
233
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
234
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
233
+        $invoice->country   = sanitize_text_field($_POST['country']);
234
+        $invoice->state     = sanitize_text_field($_POST['state']);
235 235
         
236
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
237
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
236
+        $invoice->set('country', sanitize_text_field($_POST['country']));
237
+        $invoice->set('state', sanitize_text_field($_POST['state']));
238 238
         
239 239
         $wpinv_ip_address_country = $invoice->country;
240 240
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
         
243 243
         $response                       = array();
244 244
         $response['success']            = true;
245
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
245
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
246 246
         $response['data']['subtotal']   = $invoice->get_subtotal();
247 247
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
248 248
         $response['data']['tax']        = $invoice->get_tax();
@@ -254,40 +254,40 @@  discard block
 block discarded – undo
254 254
         
255 255
         wpinv_set_checkout_session($checkout_session);
256 256
         
257
-        wp_send_json( $response );
257
+        wp_send_json($response);
258 258
     }
259 259
     
260 260
     public static function remove_invoice_item() {
261 261
         global $wpi_userID, $wpinv_ip_address_country;
262 262
         
263
-        check_ajax_referer( 'invoice-item', '_nonce' );
264
-        if ( !current_user_can( 'manage_options' ) ) {
263
+        check_ajax_referer('invoice-item', '_nonce');
264
+        if (!current_user_can('manage_options')) {
265 265
             die(-1);
266 266
         }
267 267
         
268
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
269
-        $invoice_id = absint( $_POST['invoice_id'] );
270
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
268
+        $item_id    = sanitize_text_field($_POST['item_id']);
269
+        $invoice_id = absint($_POST['invoice_id']);
270
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
271 271
         
272
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
272
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
273 273
             die();
274 274
         }
275 275
 
276
-        $invoice    = wpinv_get_invoice( $invoice_id );
277
-        if ( empty( $invoice ) ) {
276
+        $invoice = wpinv_get_invoice($invoice_id);
277
+        if (empty($invoice)) {
278 278
             die();
279 279
         }
280 280
         
281
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
281
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
282 282
             die(); // Don't allow modify items for paid invoice.
283 283
         }
284 284
         
285
-        if ( !empty( $_POST['user_id'] ) ) {
286
-            $wpi_userID = absint( $_POST['user_id'] ); 
285
+        if (!empty($_POST['user_id'])) {
286
+            $wpi_userID = absint($_POST['user_id']); 
287 287
         }
288 288
 
289
-        $item       = new WPInv_Item( $item_id );
290
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
289
+        $item = new WPInv_Item($item_id);
290
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
291 291
             die();
292 292
         }
293 293
         
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
         
296 296
         $data                   = array();
297 297
         $data['invoice_id']     = $invoice_id;
298
-        $data['cart_discounts'] = $invoice->get_discounts( true );
298
+        $data['cart_discounts'] = $invoice->get_discounts(true);
299 299
         
300
-        wpinv_set_checkout_session( $data );
300
+        wpinv_set_checkout_session($data);
301 301
 
302 302
         $args = array(
303 303
             'id'         => $item_id,
@@ -305,21 +305,21 @@  discard block
 block discarded – undo
305 305
             'cart_index' => $cart_index
306 306
         );
307 307
 
308
-        $invoice->remove_item( $item_id, $args );
308
+        $invoice->remove_item($item_id, $args);
309 309
         $invoice->save();
310 310
         
311
-        if ( empty( $_POST['country'] ) ) {
311
+        if (empty($_POST['country'])) {
312 312
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
313 313
         }
314
-        if ( empty( $_POST['state'] ) ) {
314
+        if (empty($_POST['state'])) {
315 315
             $_POST['state'] = $invoice->state;
316 316
         }
317 317
          
318
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
319
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
318
+        $invoice->country   = sanitize_text_field($_POST['country']);
319
+        $invoice->state     = sanitize_text_field($_POST['state']);
320 320
         
321
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
322
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
321
+        $invoice->set('country', sanitize_text_field($_POST['country']));
322
+        $invoice->set('state', sanitize_text_field($_POST['state']));
323 323
         
324 324
         $wpinv_ip_address_country = $invoice->country;
325 325
         
@@ -327,7 +327,7 @@  discard block
 block discarded – undo
327 327
         
328 328
         $response                       = array();
329 329
         $response['success']            = true;
330
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
330
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
331 331
         $response['data']['subtotal']   = $invoice->get_subtotal();
332 332
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
333 333
         $response['data']['tax']        = $invoice->get_tax();
@@ -339,40 +339,40 @@  discard block
 block discarded – undo
339 339
         
340 340
         wpinv_set_checkout_session($checkout_session);
341 341
         
342
-        wp_send_json( $response );
342
+        wp_send_json($response);
343 343
     }
344 344
     
345 345
     public static function create_invoice_item() {
346
-        check_ajax_referer( 'invoice-item', '_nonce' );
347
-        if ( !current_user_can( 'manage_options' ) ) {
346
+        check_ajax_referer('invoice-item', '_nonce');
347
+        if (!current_user_can('manage_options')) {
348 348
             die(-1);
349 349
         }
350 350
         
351
-        $invoice_id = absint( $_POST['invoice_id'] );
351
+        $invoice_id = absint($_POST['invoice_id']);
352 352
 
353 353
         // Find the item
354
-        if ( !is_numeric( $invoice_id ) ) {
354
+        if (!is_numeric($invoice_id)) {
355 355
             die();
356 356
         }        
357 357
         
358
-        $invoice     = wpinv_get_invoice( $invoice_id );
359
-        if ( empty( $invoice ) ) {
358
+        $invoice = wpinv_get_invoice($invoice_id);
359
+        if (empty($invoice)) {
360 360
             die();
361 361
         }
362 362
         
363 363
         // Validate item before adding to invoice because recurring item must be paid individually.
364
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
364
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
365 365
             $response               = array();
366 366
             $response['success']    = false;
367
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
368
-            wp_send_json( $response );
367
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
368
+            wp_send_json($response);
369 369
         }        
370 370
         
371 371
         $save_item = $_POST['_wpinv_quick'];
372 372
         
373 373
         $meta               = array();
374 374
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
375
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
375
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
376 376
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
377 377
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
378 378
         
@@ -382,9 +382,9 @@  discard block
 block discarded – undo
382 382
         $data['meta']           = $meta;
383 383
         
384 384
         $item = new WPInv_Item();
385
-        $item->create( $data );
385
+        $item->create($data);
386 386
         
387
-        if ( !empty( $item ) ) {
387
+        if (!empty($item)) {
388 388
             $_POST['item_id']   = $item->ID;
389 389
             $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
390 390
             
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     }
395 395
     
396 396
     public static function get_billing_details() {
397
-        check_ajax_referer( 'get-billing-details', '_nonce' );
397
+        check_ajax_referer('get-billing-details', '_nonce');
398 398
         
399
-        if ( !current_user_can( 'manage_options' ) ) {
399
+        if (!current_user_can('manage_options')) {
400 400
             die(-1);
401 401
         }
402 402
 
403 403
         $user_id            = (int)$_POST['user_id'];
404 404
         $billing_details    = wpinv_get_user_address($user_id);
405
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
405
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
406 406
         
407 407
         if (isset($billing_details['user_id'])) {
408 408
             unset($billing_details['user_id']);
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
         $response['success']                    = true;
417 417
         $response['data']['billing_details']    = $billing_details;
418 418
         
419
-        wp_send_json( $response );
419
+        wp_send_json($response);
420 420
     }
421 421
     
422 422
     public static function admin_recalculate_totals() {
423 423
         global $wpi_userID, $wpinv_ip_address_country;
424 424
         
425
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
426
-        if ( !current_user_can( 'manage_options' ) ) {
425
+        check_ajax_referer('wpinv-nonce', '_nonce');
426
+        if (!current_user_can('manage_options')) {
427 427
             die(-1);
428 428
         }
429 429
         
430
-        $invoice_id = absint( $_POST['invoice_id'] );        
431
-        $invoice    = wpinv_get_invoice( $invoice_id );
432
-        if ( empty( $invoice ) ) {
430
+        $invoice_id = absint($_POST['invoice_id']);        
431
+        $invoice    = wpinv_get_invoice($invoice_id);
432
+        if (empty($invoice)) {
433 433
             die();
434 434
         }
435 435
         
@@ -437,23 +437,23 @@  discard block
 block discarded – undo
437 437
         
438 438
         $data                   = array();
439 439
         $data['invoice_id']     = $invoice_id;
440
-        $data['cart_discounts'] = $invoice->get_discounts( true );
440
+        $data['cart_discounts'] = $invoice->get_discounts(true);
441 441
         
442
-        wpinv_set_checkout_session( $data );
442
+        wpinv_set_checkout_session($data);
443 443
         
444
-        if ( !empty( $_POST['user_id'] ) ) {
445
-            $wpi_userID = absint( $_POST['user_id'] ); 
444
+        if (!empty($_POST['user_id'])) {
445
+            $wpi_userID = absint($_POST['user_id']); 
446 446
         }
447 447
         
448
-        if ( empty( $_POST['country'] ) ) {
448
+        if (empty($_POST['country'])) {
449 449
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
450 450
         }
451 451
             
452
-        $invoice->country = sanitize_text_field( $_POST['country'] );
453
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
454
-        if ( isset( $_POST['state'] ) ) {
455
-            $invoice->state = sanitize_text_field( $_POST['state'] );
456
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
452
+        $invoice->country = sanitize_text_field($_POST['country']);
453
+        $invoice->set('country', sanitize_text_field($_POST['country']));
454
+        if (isset($_POST['state'])) {
455
+            $invoice->state = sanitize_text_field($_POST['state']);
456
+            $invoice->set('state', sanitize_text_field($_POST['state']));
457 457
         }
458 458
         
459 459
         $wpinv_ip_address_country = $invoice->country;
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
         
463 463
         $response                       = array();
464 464
         $response['success']            = true;
465
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
465
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
466 466
         $response['data']['subtotal']   = $invoice->get_subtotal();
467 467
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
468 468
         $response['data']['tax']        = $invoice->get_tax();
@@ -474,25 +474,25 @@  discard block
 block discarded – undo
474 474
         
475 475
         wpinv_set_checkout_session($checkout_session);
476 476
         
477
-        wp_send_json( $response );
477
+        wp_send_json($response);
478 478
     }
479 479
     
480 480
     public static function admin_apply_discount() {
481 481
         global $wpi_userID;
482 482
         
483
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
484
-        if ( !current_user_can( 'manage_options' ) ) {
483
+        check_ajax_referer('wpinv-nonce', '_nonce');
484
+        if (!current_user_can('manage_options')) {
485 485
             die(-1);
486 486
         }
487 487
         
488
-        $invoice_id = absint( $_POST['invoice_id'] );
489
-        $discount_code = sanitize_text_field( $_POST['code'] );
490
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
488
+        $invoice_id = absint($_POST['invoice_id']);
489
+        $discount_code = sanitize_text_field($_POST['code']);
490
+        if (empty($invoice_id) || empty($discount_code)) {
491 491
             die();
492 492
         }
493 493
         
494
-        $invoice = wpinv_get_invoice( $invoice_id );
495
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
494
+        $invoice = wpinv_get_invoice($invoice_id);
495
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
496 496
             die();
497 497
         }
498 498
         
@@ -500,49 +500,49 @@  discard block
 block discarded – undo
500 500
         
501 501
         $data                   = array();
502 502
         $data['invoice_id']     = $invoice_id;
503
-        $data['cart_discounts'] = $invoice->get_discounts( true );
503
+        $data['cart_discounts'] = $invoice->get_discounts(true);
504 504
         
505
-        wpinv_set_checkout_session( $data );
505
+        wpinv_set_checkout_session($data);
506 506
         
507 507
         $response               = array();
508 508
         $response['success']    = false;
509
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
509
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
510 510
         $response['data']['code'] = $discount_code;
511 511
         
512
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
513
-            $discounts = wpinv_set_cart_discount( $discount_code );
512
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
513
+            $discounts = wpinv_set_cart_discount($discount_code);
514 514
             
515 515
             $response['success'] = true;
516
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
517
-        }  else {
516
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
517
+        } else {
518 518
             $errors = wpinv_get_errors();
519
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
519
+            if (!empty($errors['wpinv-discount-error'])) {
520 520
                 $response['msg'] = $errors['wpinv-discount-error'];
521 521
             }
522
-            wpinv_unset_error( 'wpinv-discount-error' );
522
+            wpinv_unset_error('wpinv-discount-error');
523 523
         }
524 524
         
525 525
         wpinv_set_checkout_session($checkout_session);
526 526
         
527
-        wp_send_json( $response );
527
+        wp_send_json($response);
528 528
     }
529 529
     
530 530
     public static function admin_remove_discount() {
531 531
         global $wpi_userID;
532 532
         
533
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
534
-        if ( !current_user_can( 'manage_options' ) ) {
533
+        check_ajax_referer('wpinv-nonce', '_nonce');
534
+        if (!current_user_can('manage_options')) {
535 535
             die(-1);
536 536
         }
537 537
         
538
-        $invoice_id = absint( $_POST['invoice_id'] );
539
-        $discount_code = sanitize_text_field( $_POST['code'] );
540
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
538
+        $invoice_id = absint($_POST['invoice_id']);
539
+        $discount_code = sanitize_text_field($_POST['code']);
540
+        if (empty($invoice_id) || empty($discount_code)) {
541 541
             die();
542 542
         }
543 543
         
544
-        $invoice = wpinv_get_invoice( $invoice_id );
545
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
544
+        $invoice = wpinv_get_invoice($invoice_id);
545
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
546 546
             die();
547 547
         }
548 548
         
@@ -550,38 +550,38 @@  discard block
 block discarded – undo
550 550
         
551 551
         $data                   = array();
552 552
         $data['invoice_id']     = $invoice_id;
553
-        $data['cart_discounts'] = $invoice->get_discounts( true );
553
+        $data['cart_discounts'] = $invoice->get_discounts(true);
554 554
         
555
-        wpinv_set_checkout_session( $data );
555
+        wpinv_set_checkout_session($data);
556 556
         
557 557
         $response               = array();
558 558
         $response['success']    = false;
559 559
         $response['msg']        = NULL;
560 560
         
561
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
561
+        $discounts = wpinv_unset_cart_discount($discount_code);
562 562
         $response['success'] = true;
563
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
563
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
564 564
         
565 565
         wpinv_set_checkout_session($checkout_session);
566 566
         
567
-        wp_send_json( $response );
567
+        wp_send_json($response);
568 568
     }
569 569
     
570 570
     public static function check_email() {
571
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
572
-        if ( !current_user_can( 'manage_options' ) ) {
571
+        check_ajax_referer('wpinv-nonce', '_nonce');
572
+        if (!current_user_can('manage_options')) {
573 573
             die(-1);
574 574
         }
575 575
         
576
-        $email = sanitize_text_field( $_POST['email'] );
576
+        $email = sanitize_text_field($_POST['email']);
577 577
         
578 578
         $response = array();
579
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
579
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
580 580
             $user_id            = $user_data->ID;
581 581
             $user_login         = $user_data->user_login;
582 582
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
583 583
             $billing_details    = wpinv_get_user_address($user_id);
584
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
584
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
585 585
             
586 586
             if (isset($billing_details['user_id'])) {
587 587
                 unset($billing_details['user_id']);
@@ -597,54 +597,54 @@  discard block
 block discarded – undo
597 597
             $response['data']['billing_details']    = $billing_details;
598 598
         }
599 599
         
600
-        wp_send_json( $response );
600
+        wp_send_json($response);
601 601
     }
602 602
     
603 603
     public static function run_tool() {
604
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
605
-        if ( !current_user_can( 'manage_options' ) ) {
604
+        check_ajax_referer('wpinv-nonce', '_nonce');
605
+        if (!current_user_can('manage_options')) {
606 606
             die(-1);
607 607
         }
608 608
         
609
-        $tool = sanitize_text_field( $_POST['tool'] );
609
+        $tool = sanitize_text_field($_POST['tool']);
610 610
         
611
-        do_action( 'wpinv_run_tool' );
611
+        do_action('wpinv_run_tool');
612 612
         
613
-        if ( !empty( $tool ) ) {
614
-            do_action( 'wpinv_tool_' . $tool );
613
+        if (!empty($tool)) {
614
+            do_action('wpinv_tool_' . $tool);
615 615
         }
616 616
     }
617 617
     
618 618
     public static function apply_discount() {
619 619
         global $wpi_userID;
620 620
         
621
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
621
+        check_ajax_referer('wpinv-nonce', '_nonce');
622 622
         
623 623
         $response = array();
624 624
         
625
-        if ( isset( $_POST['code'] ) ) {
626
-            $discount_code = sanitize_text_field( $_POST['code'] );
625
+        if (isset($_POST['code'])) {
626
+            $discount_code = sanitize_text_field($_POST['code']);
627 627
 
628 628
             $response['success']        = false;
629 629
             $response['msg']            = '';
630 630
             $response['data']['code']   = $discount_code;
631 631
             
632 632
             $invoice = wpinv_get_invoice_cart();
633
-            if ( empty( $invoice->ID ) ) {
634
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
635
-                wp_send_json( $response );
633
+            if (empty($invoice->ID)) {
634
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
635
+                wp_send_json($response);
636 636
             }
637 637
 
638 638
             $wpi_userID = $invoice->get_user_id();
639 639
 
640
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
641
-                $discount       = wpinv_get_discount_by_code( $discount_code );
642
-                $discounts      = wpinv_set_cart_discount( $discount_code );
643
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
644
-                $total          = wpinv_get_cart_total( null, $discounts );
645
-                $cart_totals    = wpinv_recalculate_tax( true );
640
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
641
+                $discount       = wpinv_get_discount_by_code($discount_code);
642
+                $discounts      = wpinv_set_cart_discount($discount_code);
643
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
644
+                $total          = wpinv_get_cart_total(null, $discounts);
645
+                $cart_totals    = wpinv_recalculate_tax(true);
646 646
             
647
-                if ( !empty( $cart_totals ) ) {
647
+                if (!empty($cart_totals)) {
648 648
                     $response['success']        = true;
649 649
                     $response['data']           = $cart_totals;
650 650
                     $response['data']['code']   = $discount_code;
@@ -653,29 +653,29 @@  discard block
 block discarded – undo
653 653
                 }
654 654
             } else {
655 655
                 $errors = wpinv_get_errors();
656
-                $response['msg']  = $errors['wpinv-discount-error'];
657
-                wpinv_unset_error( 'wpinv-discount-error' );
656
+                $response['msg'] = $errors['wpinv-discount-error'];
657
+                wpinv_unset_error('wpinv-discount-error');
658 658
             }
659 659
 
660 660
             // Allow for custom discount code handling
661
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
661
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
662 662
         }
663 663
         
664
-        wp_send_json( $response );
664
+        wp_send_json($response);
665 665
     }
666 666
     
667 667
     public static function remove_discount() {
668
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
668
+        check_ajax_referer('wpinv-nonce', '_nonce');
669 669
         
670 670
         $response = array();
671 671
         
672
-        if ( isset( $_POST['code'] ) ) {
673
-            $discount_code  = sanitize_text_field( $_POST['code'] );
674
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
675
-            $total          = wpinv_get_cart_total( null, $discounts );
676
-            $cart_totals    = wpinv_recalculate_tax( true );
672
+        if (isset($_POST['code'])) {
673
+            $discount_code  = sanitize_text_field($_POST['code']);
674
+            $discounts      = wpinv_unset_cart_discount($discount_code);
675
+            $total          = wpinv_get_cart_total(null, $discounts);
676
+            $cart_totals    = wpinv_recalculate_tax(true);
677 677
             
678
-            if ( !empty( $cart_totals ) ) {
678
+            if (!empty($cart_totals)) {
679 679
                 $response['success']        = true;
680 680
                 $response['data']           = $cart_totals;
681 681
                 $response['data']['code']   = $discount_code;
@@ -684,10 +684,10 @@  discard block
 block discarded – undo
684 684
             }
685 685
             
686 686
             // Allow for custom discount code handling
687
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
687
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
688 688
         }
689 689
         
690
-        wp_send_json( $response );
690
+        wp_send_json($response);
691 691
     }
692 692
 
693 693
 
@@ -699,53 +699,53 @@  discard block
 block discarded – undo
699 699
     public static function buy_items() {
700 700
         $user_id = get_current_user_id();
701 701
 
702
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
703
-            wp_send_json( array(
704
-                'success' => wp_login_url( wp_get_referer() )
705
-            ) );
702
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
703
+            wp_send_json(array(
704
+                'success' => wp_login_url(wp_get_referer())
705
+            ));
706 706
         } else {
707 707
             // Only check nonce if logged in as it could be cached when logged out.
708
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
709
-                wp_send_json( array(
710
-                    'error' => __( 'Security checks failed.', 'invoicing' )
711
-                ) );
708
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
709
+                wp_send_json(array(
710
+                    'error' => __('Security checks failed.', 'invoicing')
711
+                ));
712 712
                 wp_die();
713 713
             }
714 714
 
715 715
             // allow to set a custom price through post_id
716 716
             $items = $_POST['items'];
717
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
718
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
717
+            $related_post_id = isset($_POST['post_id']) ? (int)$_POST['post_id'] : 0;
718
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
719 719
 
720 720
             $cart_items = array();
721
-            if ( $items ) {
722
-                $items = explode( ',', $items );
721
+            if ($items) {
722
+                $items = explode(',', $items);
723 723
 
724
-                foreach( $items as $item ) {
724
+                foreach ($items as $item) {
725 725
                     $item_id = $item;
726 726
                     $quantity = 1;
727 727
 
728
-                    if ( strpos( $item, '|' ) !== false ) {
729
-                        $item_parts = explode( '|', $item );
728
+                    if (strpos($item, '|') !== false) {
729
+                        $item_parts = explode('|', $item);
730 730
                         $item_id = $item_parts[0];
731 731
                         $quantity = $item_parts[1];
732 732
                     }
733 733
 
734
-                    if ( $item_id && $quantity ) {
734
+                    if ($item_id && $quantity) {
735 735
                         $cart_items_arr = array(
736 736
                             'id'            => (int)$item_id,
737 737
                             'quantity'      => (int)$quantity
738 738
                         );
739 739
 
740 740
                         // If there is a related post id then add it to meta
741
-                        if ( $related_post_id ) {
741
+                        if ($related_post_id) {
742 742
                             $cart_items_arr['meta'] = array(
743 743
                                 'post_id'   => $related_post_id
744 744
                             );
745 745
                         }
746 746
 
747 747
                         // If there is a custom price then set it.
748
-                        if ( $custom_item_price ) {
748
+                        if ($custom_item_price) {
749 749
                             $cart_items_arr['custom_price'] = $custom_item_price;
750 750
                         }
751 751
 
@@ -761,37 +761,37 @@  discard block
 block discarded – undo
761 761
              * @param int $related_post_id The related post id if any.
762 762
              * @since 1.0.0
763 763
              */
764
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
764
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
765 765
 
766 766
             // Make sure its not in the cart already, if it is then redirect to checkout.
767 767
             $cart_invoice = wpinv_get_invoice_cart();
768 768
 
769
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
770
-                wp_send_json( array(
769
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
770
+                wp_send_json(array(
771 771
                     'success' =>  $cart_invoice->get_checkout_payment_url()
772
-                ) );
772
+                ));
773 773
                 wp_die();
774 774
             }
775 775
 
776 776
             // Check if user has invoice with same items waiting to be paid.
777
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
778
-            if ( !empty( $user_invoices ) ) {
779
-                foreach( $user_invoices as $user_invoice ) {
777
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
778
+            if (!empty($user_invoices)) {
779
+                foreach ($user_invoices as $user_invoice) {
780 780
                     $user_cart_details = array();
781
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
781
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
782 782
                     $cart_details = $invoice->get_cart_details();
783 783
 
784
-                    if ( !empty( $cart_details ) ) {
785
-                        foreach ( $cart_details as $invoice_item ) {
784
+                    if (!empty($cart_details)) {
785
+                        foreach ($cart_details as $invoice_item) {
786 786
                             $ii_arr = array();
787 787
                             $ii_arr['id'] = (int)$invoice_item['id'];
788 788
                             $ii_arr['quantity'] = (int)$invoice_item['quantity'];
789 789
 
790
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
790
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
791 791
                                 $ii_arr['meta'] = $invoice_item['meta'];
792 792
                             }
793 793
 
794
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
794
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
795 795
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
796 796
                             }
797 797
 
@@ -799,17 +799,17 @@  discard block
 block discarded – undo
799 799
                         }
800 800
                     }
801 801
 
802
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
803
-                        wp_send_json( array(
802
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
803
+                        wp_send_json(array(
804 804
                             'success' =>  $invoice->get_checkout_payment_url()
805
-                        ) );
805
+                        ));
806 806
                         wp_die();
807 807
                     }
808 808
                 }
809 809
             }
810 810
 
811 811
             // Create invoice and send user to checkout
812
-            if ( !empty( $cart_items ) ) {
812
+            if (!empty($cart_items)) {
813 813
                 $invoice_data = array(
814 814
                     'status'        =>  'wpi-pending',
815 815
                     'created_via'   =>  'wpi',
@@ -817,21 +817,21 @@  discard block
 block discarded – undo
817 817
                     'cart_details'  =>  $cart_items,
818 818
                 );
819 819
 
820
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
820
+                $invoice = wpinv_insert_invoice($invoice_data, true);
821 821
 
822
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
823
-                    wp_send_json( array(
822
+                if (!empty($invoice) && isset($invoice->ID)) {
823
+                    wp_send_json(array(
824 824
                         'success' =>  $invoice->get_checkout_payment_url()
825
-                    ) );
825
+                    ));
826 826
                 } else {
827
-                    wp_send_json( array(
828
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
829
-                    ) );
827
+                    wp_send_json(array(
828
+                        'error' => __('Invoice failed to create', 'invoicing')
829
+                    ));
830 830
                 }
831 831
             } else {
832
-                wp_send_json( array(
833
-                    'error' => __( 'Items not valid.', 'invoicing' )
834
-                ) );
832
+                wp_send_json(array(
833
+                    'error' => __('Items not valid.', 'invoicing')
834
+                ));
835 835
             }
836 836
         }
837 837
 
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float)wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,27 +383,27 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
391
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
391
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
392 392
     
393 393
     $setting['paypal_sandbox'] = array(
394 394
             'type' => 'checkbox',
395 395
             'id'   => 'paypal_sandbox',
396
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
397
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
396
+            'name' => __('PayPal Sandbox', 'invoicing'),
397
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
398 398
             'std'  => 1
399 399
         );
400 400
         
401 401
     $setting['paypal_email'] = array(
402 402
             'type' => 'text',
403 403
             'id'   => 'paypal_email',
404
-            'name' => __( 'PayPal Email', 'invoicing' ),
405
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
406
-            'std' => __( '[email protected]', 'invoicing' ),
404
+            'name' => __('PayPal Email', 'invoicing'),
405
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
406
+            'std' => __('[email protected]', 'invoicing'),
407 407
         );
408 408
     /*
409 409
     $setting['paypal_ipn_url'] = array(
@@ -417,123 +417,123 @@  discard block
 block discarded – undo
417 417
         
418 418
     return $setting;
419 419
 }
420
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
420
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
421 421
 
422 422
 // Pre Bank Transfer settings
423
-function wpinv_gateway_settings_bank_transfer( $setting ) {
424
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
423
+function wpinv_gateway_settings_bank_transfer($setting) {
424
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
425 425
     
426 426
     $setting['bank_transfer_ac_name'] = array(
427 427
             'type' => 'text',
428 428
             'id' => 'bank_transfer_ac_name',
429
-            'name' => __( 'Account Name', 'invoicing' ),
430
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
431
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
429
+            'name' => __('Account Name', 'invoicing'),
430
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
431
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
432 432
         );
433 433
     
434 434
     $setting['bank_transfer_ac_no'] = array(
435 435
             'type' => 'text',
436 436
             'id' => 'bank_transfer_ac_no',
437
-            'name' => __( 'Account Number', 'invoicing' ),
438
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
439
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
437
+            'name' => __('Account Number', 'invoicing'),
438
+            'desc' => __('Enter your bank account number.', 'invoicing'),
439
+            'std'  =>  __('TEST1234567890', 'invoicing'),
440 440
         );
441 441
     
442 442
     $setting['bank_transfer_bank_name'] = array(
443 443
             'type' => 'text',
444 444
             'id'   => 'bank_transfer_bank_name',
445
-            'name' => __( 'Bank Name', 'invoicing' ),
446
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
447
-            'std' => __( 'ICICI Bank', 'invoicing' ),
445
+            'name' => __('Bank Name', 'invoicing'),
446
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
447
+            'std' => __('ICICI Bank', 'invoicing'),
448 448
         );
449 449
     
450 450
     $setting['bank_transfer_ifsc'] = array(
451 451
             'type' => 'text',
452 452
             'id'   => 'bank_transfer_ifsc',
453
-            'name' => __( 'IFSC Code', 'invoicing' ),
454
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
455
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
453
+            'name' => __('IFSC Code', 'invoicing'),
454
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
455
+            'std'  =>  __('ICIC0001234', 'invoicing'),
456 456
         );
457 457
         
458 458
     $setting['bank_transfer_iban'] = array(
459 459
             'type' => 'text',
460 460
             'id'   => 'bank_transfer_iban',
461
-            'name' => __( 'IBAN', 'invoicing' ),
462
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
463
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
461
+            'name' => __('IBAN', 'invoicing'),
462
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
463
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
464 464
         );
465 465
         
466 466
     $setting['bank_transfer_bic'] = array(
467 467
             'type' => 'text',
468 468
             'id'   => 'bank_transfer_bic',
469
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
470
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
469
+            'name' => __('BIC/Swift Code', 'invoicing'),
470
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
471 471
         );
472 472
 
473 473
     $setting['bank_transfer_sort_code'] = array(
474 474
         'type' => 'text',
475 475
         'id'   => 'bank_transfer_sort_code',
476
-        'name' => __( 'Sort Code', 'invoicing' ),
477
-        'std'  =>  __( '12-34-56', 'invoicing' ),
476
+        'name' => __('Sort Code', 'invoicing'),
477
+        'std'  =>  __('12-34-56', 'invoicing'),
478 478
     );
479 479
         
480 480
     $setting['bank_transfer_info'] = array(
481 481
             'id'   => 'bank_transfer_info',
482
-            'name' => __( 'Instructions', 'invoicing' ),
483
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
482
+            'name' => __('Instructions', 'invoicing'),
483
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
484 484
             'type' => 'textarea',
485
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
485
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
486 486
             'cols' => 37,
487 487
             'rows' => 5
488 488
         );
489 489
         
490 490
     return $setting;
491 491
 }
492
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
492
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
493 493
 
494 494
 // Authorize.Net settings
495
-function wpinv_gateway_settings_authorizenet( $setting ) {
496
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
497
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' );
495
+function wpinv_gateway_settings_authorizenet($setting) {
496
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
497
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing');
498 498
     
499 499
     $setting['authorizenet_sandbox'] = array(
500 500
             'type' => 'checkbox',
501 501
             'id'   => 'authorizenet_sandbox',
502
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
503
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
502
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
503
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
504 504
             'std'  => 1
505 505
         );
506 506
         
507 507
     $setting['authorizenet_login_id'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_login_id',
510
-            'name' => __( 'API Login ID', 'invoicing' ),
511
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
510
+            'name' => __('API Login ID', 'invoicing'),
511
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
512 512
             'std' => '2j4rBekUnD',
513 513
         );
514 514
     
515 515
     $setting['authorizenet_transaction_key'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_transaction_key',
518
-            'name' => __( 'Transaction Key', 'invoicing' ),
519
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
518
+            'name' => __('Transaction Key', 'invoicing'),
519
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
520 520
             'std' => '4vyBUOJgR74679xa',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_md5_hash'] = array(
524 524
             'type' => 'text',
525 525
             'id'   => 'authorizenet_md5_hash',
526
-            'name' => __( 'MD5-Hash', 'invoicing' ),
527
-            'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
526
+            'name' => __('MD5-Hash', 'invoicing'),
527
+            'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
528 528
             'std' => '',
529 529
         );
530 530
         
531 531
     $setting['authorizenet_ipn_url'] = array(
532 532
             'type' => 'ipn_url',
533 533
             'id'   => 'authorizenet_ipn_url',
534
-            'name' => __( 'Silent Post URL', 'invoicing' ),
535
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
536
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
534
+            'name' => __('Silent Post URL', 'invoicing'),
535
+            'std' => wpinv_get_ipn_url('authorizenet'),
536
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
537 537
             'size' => 'large',
538 538
             'custom' => 'authorizenet',
539 539
             'readonly' => true
@@ -541,26 +541,26 @@  discard block
 block discarded – undo
541 541
         
542 542
     return $setting;
543 543
 }
544
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
544
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
545 545
 
546 546
 // Worldpay settings
547
-function wpinv_gateway_settings_worldpay( $setting ) {
548
-    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' );
549
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' );
547
+function wpinv_gateway_settings_worldpay($setting) {
548
+    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing');
549
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing');
550 550
     
551 551
     $setting['worldpay_sandbox'] = array(
552 552
             'type' => 'checkbox',
553 553
             'id'   => 'worldpay_sandbox',
554
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
555
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
554
+            'name' => __('Worldpay Test Mode', 'invoicing'),
555
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
556 556
             'std'  => 1
557 557
         );
558 558
         
559 559
     $setting['worldpay_instId'] = array(
560 560
             'type' => 'text',
561 561
             'id'   => 'worldpay_instId',
562
-            'name' => __( 'Installation Id', 'invoicing' ),
563
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
562
+            'name' => __('Installation Id', 'invoicing'),
563
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
564 564
             'std' => '211616',
565 565
         );
566 566
     /*
@@ -576,9 +576,9 @@  discard block
 block discarded – undo
576 576
     $setting['worldpay_ipn_url'] = array(
577 577
             'type' => 'ipn_url',
578 578
             'id'   => 'worldpay_ipn_url',
579
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
580
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
581
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
579
+            'name' => __('Worldpay Callback Url', 'invoicing'),
580
+            'std' => wpinv_get_ipn_url('worldpay'),
581
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
582 582
             'size' => 'large',
583 583
             'custom' => 'worldpay',
584 584
             'readonly' => true
@@ -586,99 +586,99 @@  discard block
 block discarded – undo
586 586
         
587 587
     return $setting;
588 588
 }
589
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
589
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
590 590
 
591
-function wpinv_ipn_url_callback( $args ) {    
592
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
591
+function wpinv_ipn_url_callback($args) {    
592
+    $sanitize_id = wpinv_sanitize_key($args['id']);
593 593
     
594 594
     $attrs = $args['readonly'] ? ' readonly' : '';
595 595
 
596
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
597
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
596
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
597
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
598 598
 
599 599
     echo $html;
600 600
 }
601 601
 
602
-function wpinv_is_test_mode( $gateway = '' ) {
603
-    if ( empty( $gateway ) ) {
602
+function wpinv_is_test_mode($gateway = '') {
603
+    if (empty($gateway)) {
604 604
         return false;
605 605
     }
606 606
     
607
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
607
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
608 608
     
609
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
609
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
610 610
 }
611 611
 
612
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
613
-    $data = array( 'wpi-listener' => 'IPN' );
612
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
613
+    $data = array('wpi-listener' => 'IPN');
614 614
     
615
-    if ( !empty( $gateway ) ) {
616
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
615
+    if (!empty($gateway)) {
616
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
617 617
     }
618 618
     
619
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
619
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
620 620
     
621
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
621
+    $ipn_url = add_query_arg($args, home_url('index.php'));
622 622
     
623
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
623
+    return apply_filters('wpinv_ipn_url', $ipn_url);
624 624
 }
625 625
 
626 626
 function wpinv_listen_for_payment_ipn() {
627 627
     // Regular PayPal IPN
628
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
629
-        do_action( 'wpinv_verify_payment_ipn' );
628
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
629
+        do_action('wpinv_verify_payment_ipn');
630 630
         
631
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
632
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
633
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
631
+        if (!empty($_GET['wpi-gateway'])) {
632
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
633
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
634 634
         }
635 635
     }
636 636
 }
637
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
637
+add_action('init', 'wpinv_listen_for_payment_ipn');
638 638
 
639 639
 function wpinv_get_bank_instructions() {
640
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
640
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
641 641
     
642
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
642
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
643 643
 }
644 644
 
645
-function wpinv_get_bank_info( $filtered = false ) {
645
+function wpinv_get_bank_info($filtered = false) {
646 646
     $bank_fields = array(
647
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
648
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
649
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
650
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
651
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
652
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
653
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
647
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
648
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
649
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
650
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
651
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
652
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
653
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
654 654
     );
655 655
     
656 656
     $bank_info = array();
657
-    foreach ( $bank_fields as $field => $label ) {
658
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
657
+    foreach ($bank_fields as $field => $label) {
658
+        if ($filtered && !($value = wpinv_get_option($field))) {
659 659
             continue;
660 660
         }
661 661
         
662
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
662
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
663 663
     }
664 664
     
665
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
665
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
666 666
 }
667 667
 
668
-function wpinv_get_post_data( $method = 'request' ) {
668
+function wpinv_get_post_data($method = 'request') {
669 669
     $data       = array();
670 670
     $request    = $_REQUEST;
671 671
     
672
-    if ( $method == 'post' ) {
673
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
672
+    if ($method == 'post') {
673
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
674 674
             return $data;
675 675
         }
676 676
         
677 677
         $request = $_POST;
678 678
     }
679 679
     
680
-    if ( $method == 'get' ) {
681
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
680
+    if ($method == 'get') {
681
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
682 682
             return $data;
683 683
         }
684 684
         
@@ -689,11 +689,11 @@  discard block
 block discarded – undo
689 689
     $post_data = '';
690 690
     
691 691
     // Fallback just in case post_max_size is lower than needed
692
-    if ( ini_get( 'allow_url_fopen' ) ) {
693
-        $post_data = file_get_contents( 'php://input' );
692
+    if (ini_get('allow_url_fopen')) {
693
+        $post_data = file_get_contents('php://input');
694 694
     } else {
695 695
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
696
-        ini_set( 'post_max_size', '12M' );
696
+        ini_set('post_max_size', '12M');
697 697
     }
698 698
     // Start the encoded data collection with notification command
699 699
     $encoded_data = 'cmd=_notify-validate';
@@ -702,58 +702,58 @@  discard block
 block discarded – undo
702 702
     $arg_separator = wpinv_get_php_arg_separator_output();
703 703
 
704 704
     // Verify there is a post_data
705
-    if ( $post_data || strlen( $post_data ) > 0 ) {
705
+    if ($post_data || strlen($post_data) > 0) {
706 706
         // Append the data
707 707
         $encoded_data .= $arg_separator . $post_data;
708 708
     } else {
709 709
         // Check if POST is empty
710
-        if ( empty( $request ) ) {
710
+        if (empty($request)) {
711 711
             // Nothing to do
712 712
             return;
713 713
         } else {
714 714
             // Loop through each POST
715
-            foreach ( $request as $key => $value ) {
715
+            foreach ($request as $key => $value) {
716 716
                 // Encode the value and append the data
717
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
717
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
718 718
             }
719 719
         }
720 720
     }
721 721
 
722 722
     // Convert collected post data to an array
723
-    parse_str( $encoded_data, $data );
723
+    parse_str($encoded_data, $data);
724 724
 
725
-    foreach ( $data as $key => $value ) {
726
-        if ( false !== strpos( $key, 'amp;' ) ) {
727
-            $new_key = str_replace( '&amp;', '&', $key );
728
-            $new_key = str_replace( 'amp;', '&' , $new_key );
725
+    foreach ($data as $key => $value) {
726
+        if (false !== strpos($key, 'amp;')) {
727
+            $new_key = str_replace('&amp;', '&', $key);
728
+            $new_key = str_replace('amp;', '&', $new_key);
729 729
 
730
-            unset( $data[ $key ] );
731
-            $data[ $new_key ] = sanitize_text_field( $value );
730
+            unset($data[$key]);
731
+            $data[$new_key] = sanitize_text_field($value);
732 732
         }
733 733
     }
734 734
     
735 735
     return $data;
736 736
 }
737 737
 
738
-function wpinv_gateway_support_subscription( $gateway ) {
738
+function wpinv_gateway_support_subscription($gateway) {
739 739
     $return = false;
740 740
     
741
-    if ( wpinv_is_gateway_active( $gateway ) ) {
742
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
741
+    if (wpinv_is_gateway_active($gateway)) {
742
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
743 743
     }
744 744
     
745 745
     return $return;
746 746
 }
747 747
 
748
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
749
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
750
-        foreach ( $gateways as $gateway => $info ) {
751
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
752
-                unset( $gateways[$gateway] );
748
+function wpinv_payment_gateways_on_cart($gateways = array()) {
749
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
750
+        foreach ($gateways as $gateway => $info) {
751
+            if (!wpinv_gateway_support_subscription($gateway)) {
752
+                unset($gateways[$gateway]);
753 753
             }
754 754
         }
755 755
     }
756 756
     
757 757
     return $gateways;
758 758
 }
759
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
760 759
\ No newline at end of file
760
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
761 761
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -31,31 +31,31 @@  discard block
 block discarded – undo
31 31
     }
32 32
     
33 33
     public function define_constants() {
34
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
35
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
34
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
35
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
36 36
     }
37 37
     
38 38
     private function actions() {
39 39
         /* Internationalize the text strings used. */
40
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
40
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
41 41
         
42 42
         /* Perform actions on admin initialization. */
43
-        add_action( 'admin_init', array( &$this, 'admin_init') );
44
-        add_action( 'init', array( &$this, 'init' ), 3 );
45
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
46
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
43
+        add_action('admin_init', array(&$this, 'admin_init'));
44
+        add_action('init', array(&$this, 'init'), 3);
45
+        add_action('init', array('WPInv_Shortcodes', 'init'));
46
+        add_action('init', array(&$this, 'wpinv_actions'));
47 47
         
48
-        if ( class_exists( 'BuddyPress' ) ) {
49
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
48
+        if (class_exists('BuddyPress')) {
49
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
50 50
         }
51 51
 
52
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
52
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
53 53
         
54
-        if ( is_admin() ) {
55
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
56
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
54
+        if (is_admin()) {
55
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
56
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
57 57
         } else {
58
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
58
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
59 59
         }
60 60
         
61 61
         /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
          *
66 66
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
67 67
          */
68
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
68
+        do_action_ref_array('wpinv_actions', array(&$this));
69 69
 
70
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
70
+        add_action('admin_init', array(&$this, 'activation_redirect'));
71 71
     }
72 72
     
73 73
     public function plugins_loaded() {
74 74
         /* Internationalize the text strings used. */
75 75
         $this->load_textdomain();
76 76
 
77
-        do_action( 'wpinv_loaded' );
77
+        do_action('wpinv_loaded');
78 78
     }
79 79
     
80 80
     /**
@@ -83,205 +83,205 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
87
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
86
+        $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
87
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
88 88
         
89
-        unload_textdomain( 'invoicing' );
90
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
91
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
89
+        unload_textdomain('invoicing');
90
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
91
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
92 92
         
93 93
         /**
94 94
          * Define language constants.
95 95
          */
96
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
96
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
97 97
     }
98 98
         
99 99
     public function includes() {
100 100
         global $wpinv_options;
101 101
         
102
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
102
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
103 103
         $wpinv_options = wpinv_get_settings();
104 104
         
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
118
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
129
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
130
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
131
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
132
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
133
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
134
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
135
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
118
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
129
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
130
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
131
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
132
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
133
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
134
+        if (!class_exists('WPInv_EUVat')) {
135
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
136 136
         }
137 137
         
138
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
139
-        if ( !empty( $gateways ) ) {
140
-            foreach ( $gateways as $gateway ) {
141
-                if ( $gateway == 'manual' ) {
138
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
139
+        if (!empty($gateways)) {
140
+            foreach ($gateways as $gateway) {
141
+                if ($gateway == 'manual') {
142 142
                     continue;
143 143
                 }
144 144
                 
145 145
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
146 146
                 
147
-                if ( file_exists( $gateway_file ) ) {
148
-                    require_once( $gateway_file );
147
+                if (file_exists($gateway_file)) {
148
+                    require_once($gateway_file);
149 149
                 }
150 150
             }
151 151
         }
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
153 153
         
154
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
154
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
158 158
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
159
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
160
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
161
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
162
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
163
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
159
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
160
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
161
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
162
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
163
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
164 164
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
165 165
         }
166 166
         
167 167
         // include css inliner
168
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
169
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
168
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
169
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
170 170
         }
171 171
         
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
173 173
     }
174 174
     
175 175
     public function init() {
176 176
     }
177 177
     
178 178
     public function admin_init() {
179
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
179
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
180 180
         }
181 181
         
182
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
182
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
183 183
     }
184 184
 
185 185
     public function activation_redirect() {
186 186
         // Bail if no activation redirect
187
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
187
+        if (!get_transient('_wpinv_activation_redirect')) {
188 188
             return;
189 189
         }
190 190
 
191 191
         // Delete the redirect transient
192
-        delete_transient( '_wpinv_activation_redirect' );
192
+        delete_transient('_wpinv_activation_redirect');
193 193
 
194 194
         // Bail if activating from network, or bulk
195
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
195
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
196 196
             return;
197 197
         }
198 198
 
199
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
199
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
200 200
         exit;
201 201
     }
202 202
     
203 203
     public function enqueue_scripts() {
204
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
204
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
205 205
         
206
-        wp_deregister_style( 'font-awesome' );
207
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
208
-        wp_enqueue_style( 'font-awesome' );
206
+        wp_deregister_style('font-awesome');
207
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
208
+        wp_enqueue_style('font-awesome');
209 209
         
210
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
211
-        wp_enqueue_style( 'wpinv_front_style' );
210
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
211
+        wp_enqueue_style('wpinv_front_style');
212 212
                
213 213
         // Register scripts
214
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
215
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
214
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
215
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
216 216
         
217 217
         $localize                         = array();
218
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
219
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
218
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
219
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
220 220
         $localize['currency_symbol']      = wpinv_currency_symbol();
221 221
         $localize['currency_pos']         = wpinv_currency_position();
222 222
         $localize['thousand_sep']         = wpinv_thousands_separator();
223 223
         $localize['decimal_sep']          = wpinv_decimal_separator();
224 224
         $localize['decimals']             = wpinv_decimals();
225
-        $localize['txtComplete']          = __( 'Complete', 'invoicing' );
225
+        $localize['txtComplete']          = __('Complete', 'invoicing');
226 226
         
227
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
227
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
228 228
         
229
-        wp_enqueue_script( 'jquery-blockui' );
229
+        wp_enqueue_script('jquery-blockui');
230 230
         $autofill_api = wpinv_get_option('address_autofill_api');
231 231
         $autofill_active = wpinv_get_option('address_autofill_active');
232
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
233
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
234
-                wp_dequeue_script( 'google-maps-api' );
232
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
233
+            if (wp_script_is('google-maps-api', 'enqueued')) {
234
+                wp_dequeue_script('google-maps-api');
235 235
             }
236
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
237
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
236
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
237
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
238 238
         }
239
-        wp_enqueue_script( 'wpinv-front-script' );
240
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
239
+        wp_enqueue_script('wpinv-front-script');
240
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
241 241
     }
242 242
 
243 243
     public function admin_enqueue_scripts() {
244 244
         global $post, $pagenow;
245 245
         
246 246
         $post_type  = wpinv_admin_post_type();
247
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
248
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
247
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
248
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
249 249
 
250
-        wp_deregister_style( 'font-awesome' );
251
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
252
-        wp_enqueue_style( 'font-awesome' );
250
+        wp_deregister_style('font-awesome');
251
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
252
+        wp_enqueue_style('font-awesome');
253 253
         
254 254
         $jquery_ui_css = false;
255
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
255
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
256 256
             $jquery_ui_css = true;
257
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
257
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
258 258
             $jquery_ui_css = true;
259 259
         }
260
-        if ( $jquery_ui_css ) {
261
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
262
-            wp_enqueue_style( 'jquery-ui-css' );
260
+        if ($jquery_ui_css) {
261
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
262
+            wp_enqueue_style('jquery-ui-css');
263 263
         }
264 264
 
265
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
266
-        wp_enqueue_style( 'wpinv_meta_box_style' );
265
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
266
+        wp_enqueue_style('wpinv_meta_box_style');
267 267
         
268
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
269
-        wp_enqueue_style( 'wpinv_admin_style' );
268
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
269
+        wp_enqueue_style('wpinv_admin_style');
270 270
 
271
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
272
-        if ( $page == 'wpinv-subscriptions' ) {
273
-            wp_enqueue_script( 'jquery-ui-datepicker' );
271
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
272
+        if ($page == 'wpinv-subscriptions') {
273
+            wp_enqueue_script('jquery-ui-datepicker');
274 274
         }
275
-        $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue );
275
+        $enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue);
276 276
         
277
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
278
-            wp_enqueue_script( 'jquery-ui-datepicker' );
277
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
278
+            wp_enqueue_script('jquery-ui-datepicker');
279 279
         }
280 280
 
281
-        wp_enqueue_style( 'wp-color-picker' );
282
-        wp_enqueue_script( 'wp-color-picker' );
281
+        wp_enqueue_style('wp-color-picker');
282
+        wp_enqueue_script('wp-color-picker');
283 283
         
284
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
284
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
285 285
 
286 286
         if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
287 287
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -292,17 +292,17 @@  discard block
 block discarded – undo
292 292
             }
293 293
         }
294 294
 
295
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  WPINV_VERSION );
296
-        wp_enqueue_script( 'wpinv-admin-script' );
295
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION);
296
+        wp_enqueue_script('wpinv-admin-script');
297 297
         
298 298
         $localize                               = array();
299
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
300
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
301
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
302
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
303
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
304
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
305
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
299
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
300
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
301
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
302
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
303
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
304
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
305
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
306 306
         $localize['tax']                        = wpinv_tax_amount();
307 307
         $localize['discount']                   = wpinv_discount_amount();
308 308
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -310,69 +310,69 @@  discard block
 block discarded – undo
310 310
         $localize['thousand_sep']               = wpinv_thousands_separator();
311 311
         $localize['decimal_sep']                = wpinv_decimal_separator();
312 312
         $localize['decimals']                   = wpinv_decimals();
313
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
314
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
315
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
316
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
317
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
318
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
319
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
320
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
321
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
322
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
323
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
324
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
325
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
326
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
313
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
314
+        $localize['status_publish']             = wpinv_status_nicename('publish');
315
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
316
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
317
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
318
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
319
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
320
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
321
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
322
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
323
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
324
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
325
+        $localize['action_edit']                = __('Edit', 'invoicing');
326
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
327 327
 
328
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
328
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
329 329
 
330
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
330
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
331 331
 
332
-        if ( $page == 'wpinv-subscriptions' ) {
333
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
334
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
332
+        if ($page == 'wpinv-subscriptions') {
333
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions' . $suffix . '.js', array('wpinv-admin-script'), WPINV_VERSION);
334
+            wp_enqueue_script('wpinv-sub-admin-script');
335 335
         }
336 336
     }
337 337
     
338
-    public function admin_body_class( $classes ) {
338
+    public function admin_body_class($classes) {
339 339
         global $pagenow, $post, $current_screen;
340 340
         
341
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
341
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) {
342 342
             $classes .= ' wpinv-cpt';
343 343
         }
344 344
         
345
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
345
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
346 346
 
347
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
348
-        if ( $add_class ) {
349
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
347
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
348
+        if ($add_class) {
349
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
350 350
         }
351 351
         
352 352
         $settings_class = array();
353
-        if ( $page == 'wpinv-settings' ) {
354
-            if ( !empty( $_REQUEST['tab'] ) ) {
355
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
353
+        if ($page == 'wpinv-settings') {
354
+            if (!empty($_REQUEST['tab'])) {
355
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
356 356
             }
357 357
             
358
-            if ( !empty( $_REQUEST['section'] ) ) {
359
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
358
+            if (!empty($_REQUEST['section'])) {
359
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
360 360
             }
361 361
             
362
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
362
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
363 363
         }
364 364
         
365
-        if ( !empty( $settings_class ) ) {
366
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
365
+        if (!empty($settings_class)) {
366
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
367 367
         }
368 368
         
369 369
         $post_type = wpinv_admin_post_type();
370 370
 
371
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
371
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
372 372
             return $classes .= ' wpinv';
373 373
         }
374 374
         
375
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
375
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
376 376
             $classes .= ' wpi-editable-n';
377 377
         }
378 378
 
@@ -384,20 +384,20 @@  discard block
 block discarded – undo
384 384
     }
385 385
     
386 386
     public function wpinv_actions() {
387
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
388
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
387
+        if (isset($_REQUEST['wpi_action'])) {
388
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
389 389
         }
390 390
     }
391 391
     
392
-    public function pre_get_posts( $wp_query ) {
393
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
394
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
392
+    public function pre_get_posts($wp_query) {
393
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
394
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
395 395
         }
396 396
         
397 397
         return $wp_query;
398 398
     }
399 399
     
400 400
     public function bp_invoicing_init() {
401
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
401
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
402 402
     }
403 403
 }
404 404
\ No newline at end of file
Please login to merge, or discard this patch.