Passed
Push — master ( a83567...99d634 )
by Stiofan
05:05
created
templates/emails/wpinv-email-footer.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-$email_footer = apply_filters( 'wpinv_email_footer_text', wpinv_get_option( 'email_footer_text' ) );
7
-$email_footer = $email_footer ? wpautop( wp_kses_post( wptexturize( $email_footer ) ) ) : '';
6
+$email_footer = apply_filters('wpinv_email_footer_text', wpinv_get_option('email_footer_text'));
7
+$email_footer = $email_footer ? wpautop(wp_kses_post(wptexturize($email_footer))) : '';
8 8
 ?>
9 9
                                                             </div>
10 10
                                                         </td>
Please login to merge, or discard this patch.
templates/emails/wpinv-email-header.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6
-if ( !isset( $email_heading ) ) {
6
+if (!isset($email_heading)) {
7 7
     global $email_heading;
8 8
 }
9 9
 ?>
10 10
 <!DOCTYPE html>
11 11
 <html dir="<?php echo is_rtl() ? 'rtl' : 'ltr'?>">
12 12
     <head>
13
-        <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo( 'charset' ); ?>" />
13
+        <meta http-equiv="Content-Type" content="text/html; charset=<?php bloginfo('charset'); ?>" />
14 14
         <meta name="viewport" content="width=device-width, initial-scale=1">
15 15
         <meta name="robots" content="noindex,nofollow">
16 16
         <title><?php echo wpinv_get_blogname(); ?></title>
@@ -22,13 +22,13 @@  discard block
 block discarded – undo
22 22
                     <td align="center" valign="top">
23 23
                         <div id="template_header_image">
24 24
                         <?php
25
-                            if ( $img = wpinv_get_option( 'email_header_image' ) ) {
26
-                                echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url( $img ) . '" alt="' . esc_attr( wpinv_get_blogname() ) . '" /></p>';
25
+                            if ($img = wpinv_get_option('email_header_image')) {
26
+                                echo '<p style="margin-top:0;"><img style="max-width:100%" src="' . esc_url($img) . '" alt="' . esc_attr(wpinv_get_blogname()) . '" /></p>';
27 27
                             }
28 28
                         ?>
29 29
                         </div>
30 30
                         <table border="0" cellpadding="0" cellspacing="0" width="100%" id="template_container">
31
-                            <?php if ( !empty( $email_heading ) ) { ?>
31
+                            <?php if (!empty($email_heading)) { ?>
32 32
                             <tr>
33 33
                                 <td align="center" valign="top">
34 34
                                     <!-- Header -->
Please login to merge, or discard this patch.
templates/wpinv-payment-processing.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -2,11 +2,11 @@
 block discarded – undo
2 2
 global $wpi_invoice;
3 3
 
4 4
 $success_page_uri = wpinv_get_success_page_uri();
5
-if ( !empty( $wpi_invoice ) ) {
6
-    $success_page_uri = add_query_arg( 'invoice_key', $wpi_invoice->get_key(), $success_page_uri );
5
+if (!empty($wpi_invoice)) {
6
+    $success_page_uri = add_query_arg('invoice_key', $wpi_invoice->get_key(), $success_page_uri);
7 7
 }
8 8
 ?>
9 9
 <div id="wpinv-payment-processing">
10
-    <p><?php echo wp_sprintf( __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ), $success_page_uri ); ?> <i class="fa fa-spin fa-refresh"></i></p>
10
+    <p><?php echo wp_sprintf(__('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'), $success_page_uri); ?> <i class="fa fa-spin fa-refresh"></i></p>
11 11
     <script type="text/javascript">setTimeout(function(){ window.location = '<?php echo $success_page_uri; ?>'; }, 10000);</script>
12 12
 </div>
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-bp-core.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -348,7 +348,7 @@
 block discarded – undo
348 348
 
349 349
         $query_args     = array( 'user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true );
350 350
         if ( !empty( $status ) && $status != 'all' ) {
351
-           $query_args['status'] = $status;
351
+            $query_args['status'] = $status;
352 352
         }
353 353
         $invoices  = wpinv_get_invoices( apply_filters( 'wpinv_bp_user_invoices_query', $query_args ) );
354 354
         
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 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
 
@@ -9,42 +9,42 @@  discard block
 block discarded – undo
9 9
     
10 10
     public function __construct() {
11 11
 
12
-        if ( !defined( 'WPINV_BP_SLUG' ) ) {
13
-            define( 'WPINV_BP_SLUG', 'invoices' );
12
+        if (!defined('WPINV_BP_SLUG')) {
13
+            define('WPINV_BP_SLUG', 'invoices');
14 14
         }
15 15
 
16
-        add_action( 'wp_ajax_invoicing_filter', array( $this, 'invoices_content' ) );
17
-        add_action( 'wp_ajax_nopriv_invoicing_filter', array( $this, 'invoices_content' ) );
18
-        add_filter( 'wpinv_settings_sections_general', array( $this, 'bp_section' ), 10, 1 );
19
-        add_filter( 'wpinv_settings_general', array( $this, 'bp_settings' ), 10, 1 );
20
-        add_filter( 'wp_nav_menu_objects', array( $this, 'wp_nav_menu_objects' ), 10, 2 );
16
+        add_action('wp_ajax_invoicing_filter', array($this, 'invoices_content'));
17
+        add_action('wp_ajax_nopriv_invoicing_filter', array($this, 'invoices_content'));
18
+        add_filter('wpinv_settings_sections_general', array($this, 'bp_section'), 10, 1);
19
+        add_filter('wpinv_settings_general', array($this, 'bp_settings'), 10, 1);
20
+        add_filter('wp_nav_menu_objects', array($this, 'wp_nav_menu_objects'), 10, 2);
21 21
         add_action('bp_setup_nav', array($this, 'setup_nav'), 15);
22 22
         
23
-        $position       = wpinv_get_option( 'wpinv_menu_position' );
23
+        $position       = wpinv_get_option('wpinv_menu_position');
24 24
         $position       = $position !== '' && $position !== false ? $position : 91;
25
-        $this->position = apply_filters( 'wpinv_bp_nav_position', $position );
26
-        $this->id     = WPINV_BP_SLUG;
25
+        $this->position = apply_filters('wpinv_bp_nav_position', $position);
26
+        $this->id = WPINV_BP_SLUG;
27 27
     }
28 28
 
29 29
     public function setup_nav() {
30 30
 
31
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) || !is_user_logged_in()) {
31
+        if (wpinv_get_option('wpinv_bp_hide_menu') || !is_user_logged_in()) {
32 32
             return;
33 33
         }
34 34
 
35
-        if(bp_displayed_user_id() != bp_loggedin_user_id() && !current_user_can('administrator')){
35
+        if (bp_displayed_user_id() != bp_loggedin_user_id() && !current_user_can('administrator')) {
36 36
             return;
37 37
         }
38 38
 
39 39
         $count = $this->get_invoice_count();
40
-        $class = ( 0 === $count ) ? 'no-count' : 'count';
40
+        $class = (0 === $count) ? 'no-count' : 'count';
41 41
 
42 42
         $main_nav_name = sprintf(
43
-            __( 'My Invoices %s', 'invoicing' ),
43
+            __('My Invoices %s', 'invoicing'),
44 44
             sprintf(
45 45
                 '<span class="%s">%s</span>',
46
-                esc_attr( $class ),
47
-                bp_core_number_format( $count )
46
+                esc_attr($class),
47
+                bp_core_number_format($count)
48 48
             )
49 49
         );
50 50
 
@@ -52,31 +52,31 @@  discard block
 block discarded – undo
52 52
             'name'                => $main_nav_name,
53 53
             'slug'                => WPINV_BP_SLUG,
54 54
             'position'            => $this->position,
55
-            'screen_function'     => array( $this, 'invoices_screen' ),
55
+            'screen_function'     => array($this, 'invoices_screen'),
56 56
             'default_subnav_slug' => 'invoices',
57 57
             'item_css_id'         => $this->id
58 58
         );
59 59
 
60
-        bp_core_new_nav_item( $main_nav );
60
+        bp_core_new_nav_item($main_nav);
61 61
     }
62 62
     
63 63
     public function invoices_screen() {
64
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) {
64
+        if (wpinv_get_option('wpinv_bp_hide_menu')) {
65 65
             return;
66 66
         }
67 67
         
68
-        add_action( 'bp_template_content', array( $this, 'invoices_content' ) );
68
+        add_action('bp_template_content', array($this, 'invoices_content'));
69 69
 
70
-        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
70
+        $template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
71 71
         
72
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
72
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
73 73
     }
74 74
     
75 75
     public function invoices_content() {
76
-        if ( $this->has_invoices( bp_ajax_querystring( 'invoices' ) ) ) {
76
+        if ($this->has_invoices(bp_ajax_querystring('invoices'))) {
77 77
             global $invoices_template;
78 78
             
79
-            do_action( 'wpinv_bp_invoices_before_content' );
79
+            do_action('wpinv_bp_invoices_before_content');
80 80
             ?>
81 81
             <div class="wpi-g wpi-bp-invoices invoices invoicing" style="position:relative">
82 82
                 <div id="pag-top" class="pagination">
@@ -90,61 +90,61 @@  discard block
 block discarded – undo
90 90
                 <table class="table table-bordered table-hover table-responsive wpi-user-invoices" style="margin:0">
91 91
                     <thead>
92 92
                         <tr>
93
-                            <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
94
-                                <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>
93
+                            <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
94
+                                <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>
95 95
                             <?php endforeach; ?>
96 96
                         </tr>
97 97
                     </thead>
98 98
                     <tbody>
99
-                        <?php foreach ( $invoices_template->invoices as $invoice ) {
99
+                        <?php foreach ($invoices_template->invoices as $invoice) {
100 100
                             ?>
101 101
                             <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
102
-                                <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
103
-                                    <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'] ); ?>">
104
-                                        <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
105
-                                            <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
106
-
107
-                                        <?php elseif ( 'invoice-number' === $column_id ) : ?>
108
-                                            <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
109
-                                                <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
102
+                                <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
103
+                                    <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']); ?>">
104
+                                        <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
105
+                                            <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
106
+
107
+                                        <?php elseif ('invoice-number' === $column_id) : ?>
108
+                                            <a href="<?php echo esc_url($invoice->get_view_url()); ?>">
109
+                                                <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
110 110
                                             </a>
111 111
 
112
-                                        <?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' ); ?>
113
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
112
+                                        <?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'); ?>
113
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
114 114
 
115
-                                        <?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 ); ?>
116
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
115
+                                        <?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); ?>
116
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
117 117
 
118
-                                        <?php elseif ( 'invoice-status' === $column_id ) : ?>
119
-                                            <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
118
+                                        <?php elseif ('invoice-status' === $column_id) : ?>
119
+                                            <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
120 120
 
121
-                                        <?php elseif ( 'invoice-total' === $column_id ) : ?>
122
-                                            <?php echo $invoice->get_total( true ); ?>
121
+                                        <?php elseif ('invoice-total' === $column_id) : ?>
122
+                                            <?php echo $invoice->get_total(true); ?>
123 123
 
124
-                                        <?php elseif ( 'invoice-actions' === $column_id ) : ?>
124
+                                        <?php elseif ('invoice-actions' === $column_id) : ?>
125 125
                                             <?php
126 126
                                                 $actions = array(
127 127
                                                     'pay'    => array(
128 128
                                                         'url'  => $invoice->get_checkout_payment_url(),
129
-                                                        'name' => __( 'Pay Now', 'invoicing' ),
129
+                                                        'name' => __('Pay Now', 'invoicing'),
130 130
                                                         'class' => 'btn-success'
131 131
                                                     ),
132 132
                                                     'print'   => array(
133 133
                                                         'url'  => $invoice->get_view_url(),
134
-                                                        'name' => __( 'Print', 'invoicing' ),
134
+                                                        'name' => __('Print', 'invoicing'),
135 135
                                                         'class' => 'btn-primary',
136 136
                                                         'attrs' => 'target="_blank"'
137 137
                                                     )
138 138
                                                 );
139 139
 
140
-                                                if ( ! $invoice->needs_payment() ) {
141
-                                                    unset( $actions['pay'] );
140
+                                                if (!$invoice->needs_payment()) {
141
+                                                    unset($actions['pay']);
142 142
                                                 }
143 143
 
144
-                                                if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
145
-                                                    foreach ( $actions as $key => $action ) {
144
+                                                if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
145
+                                                    foreach ($actions as $key => $action) {
146 146
                                                         $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
147
-                                                        echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
147
+                                                        echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
148 148
                                                     }
149 149
                                                 }
150 150
                                             ?>
@@ -172,64 +172,64 @@  discard block
 block discarded – undo
172 172
             </div>
173 173
             <?php
174 174
         
175
-            do_action( 'wpinv_bp_invoices_after_content' );
175
+            do_action('wpinv_bp_invoices_after_content');
176 176
         } else {
177 177
             ?>
178 178
             <div id="message" class="info">
179
-                <p><?php _e( 'No invoice has been made yet.', 'invoicing' ); ?></p>
179
+                <p><?php _e('No invoice has been made yet.', 'invoicing'); ?></p>
180 180
             </div>
181 181
             <?php
182 182
         }
183 183
         
184
-        if ( defined( 'DOING_AJAX' ) ) {
184
+        if (defined('DOING_AJAX')) {
185 185
             exit;
186 186
         }
187 187
     }
188 188
     
189
-    public function has_invoices( $args = '' ) {
189
+    public function has_invoices($args = '') {
190 190
         global $invoices_template;
191 191
 
192
-        $per_page = absint( wpinv_get_option( 'wpinv_bp_per_page' ) );
192
+        $per_page = absint(wpinv_get_option('wpinv_bp_per_page'));
193 193
         // Parse arguments.
194
-        $r = bp_parse_args( $args, array(
194
+        $r = bp_parse_args($args, array(
195 195
             'status'            => 'all',
196 196
             'page_arg'          => 'bpage',
197 197
             'page'              => 1,
198 198
             'per_page'          => $per_page > 0 ? $per_page : 20,
199 199
             'max'               => false,
200 200
             'user_id'           => bp_displayed_user_id(),
201
-        ), 'has_invoices' );
201
+        ), 'has_invoices');
202 202
 
203 203
 
204
-        if ( ! empty( $r['max'] ) && ( (int)$r['per_page'] > (int)$r['max'] ) ) {
205
-            $r['per_page'] = (int)$r['max'];
204
+        if (!empty($r['max']) && ((int) $r['per_page'] > (int) $r['max'])) {
205
+            $r['per_page'] = (int) $r['max'];
206 206
         }
207 207
 
208 208
         // Get the invoices.
209
-        $invoices_template = new WPInv_BP_Invoices_Template( $r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg'] );
209
+        $invoices_template = new WPInv_BP_Invoices_Template($r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg']);
210 210
 
211
-        return apply_filters( 'wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r );
211
+        return apply_filters('wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r);
212 212
     }
213 213
     
214 214
     public function get_invoice_count() {
215
-        $query      = apply_filters( 'wpinv_user_invoices_count_query', array( 'status' => 'all','user' => bp_displayed_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false ) );
216
-        $invoices   = wpinv_get_invoices( $query );
215
+        $query      = apply_filters('wpinv_user_invoices_count_query', array('status' => 'all', 'user' => bp_displayed_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false));
216
+        $invoices   = wpinv_get_invoices($query);
217 217
         
218
-        return !empty( $invoices ) ? count( $invoices ) : 0;
218
+        return !empty($invoices) ? count($invoices) : 0;
219 219
     }
220 220
     
221 221
     public function pagination_count() {
222 222
         global $invoices_template;
223 223
 
224
-        $start_num = intval( ( $invoices_template->pag_page - 1 ) * $invoices_template->pag_num ) + 1;
225
-        $from_num  = bp_core_number_format( $start_num );
226
-        $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 ) );
227
-        $total     = bp_core_number_format( $invoices_template->total_invoice_count );
224
+        $start_num = intval(($invoices_template->pag_page - 1) * $invoices_template->pag_num) + 1;
225
+        $from_num  = bp_core_number_format($start_num);
226
+        $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));
227
+        $total     = bp_core_number_format($invoices_template->total_invoice_count);
228 228
 
229
-        if ( 1 == $invoices_template->total_invoice_count ) {
230
-            $message = __( 'Viewing 1 invoice', 'invoicing' );
229
+        if (1 == $invoices_template->total_invoice_count) {
230
+            $message = __('Viewing 1 invoice', 'invoicing');
231 231
         } else {
232
-            $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 );
232
+            $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);
233 233
         }
234 234
 
235 235
         return $message;
@@ -238,32 +238,32 @@  discard block
 block discarded – undo
238 238
     function pagination_links() {
239 239
         global $invoices_template;
240 240
 
241
-        return apply_filters( 'wpinv_bp_get_pagination_links', $invoices_template->pag_links );
241
+        return apply_filters('wpinv_bp_get_pagination_links', $invoices_template->pag_links);
242 242
     }
243 243
     
244
-    public function bp_section( $settings = array() ) {
245
-        $settings['wpinv_bp'] = __( 'BuddyPress Integration', 'invoicing' );
244
+    public function bp_section($settings = array()) {
245
+        $settings['wpinv_bp'] = __('BuddyPress Integration', 'invoicing');
246 246
         return $settings;
247 247
     }
248 248
     
249
-    public function bp_settings( $settings = array() ) {
249
+    public function bp_settings($settings = array()) {
250 250
         $settings['wpinv_bp'] = array(
251 251
             'wpinv_bp_labels' => array(
252 252
                 'id'   => 'wpinv_bp_settings',
253
-                'name' => '<h3>' . __( 'BuddyPress Integration', 'invoicing' ) . '</h3>',
253
+                'name' => '<h3>' . __('BuddyPress Integration', 'invoicing') . '</h3>',
254 254
                 'desc' => '',
255 255
                 'type' => 'header',
256 256
             ),
257 257
             'wpinv_bp_hide_menu' => array(
258 258
                 'id'   => 'wpinv_bp_hide_menu',
259
-                'name' => __( 'Hide Invoices link', 'invoicing' ),
260
-                'desc' => __( 'Hide Invoices link from BP Profile menu.', 'invoicing' ),
259
+                'name' => __('Hide Invoices link', 'invoicing'),
260
+                'desc' => __('Hide Invoices link from BP Profile menu.', 'invoicing'),
261 261
                 'type' => 'checkbox',
262 262
             ),
263 263
             'wpinv_menu_position' => array(
264 264
                 'id'   => 'wpinv_menu_position',
265
-                'name' => __( 'Menu position', 'invoicing' ),
266
-                'desc' => __( 'Menu position for the Invoices link in BP Profile menu.', 'invoicing' ),
265
+                'name' => __('Menu position', 'invoicing'),
266
+                'desc' => __('Menu position for the Invoices link in BP Profile menu.', 'invoicing'),
267 267
                 'type' => 'number',
268 268
                 'size' => 'small',
269 269
                 'min'  => '1',
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
             ),
274 274
             'wpinv_bp_per_page' => array(
275 275
                 'id'   => 'wpinv_bp_per_page',
276
-                'name' => __( 'Max invoices per page', 'invoicing' ),
277
-                'desc' => __( 'Enter a number to lists the invoices for each page.', 'invoicing' ),
276
+                'name' => __('Max invoices per page', 'invoicing'),
277
+                'desc' => __('Enter a number to lists the invoices for each page.', 'invoicing'),
278 278
                 'type' => 'number',
279 279
                 'size' => 'small',
280 280
                 'min'  => '1',
@@ -287,20 +287,20 @@  discard block
 block discarded – undo
287 287
         return $settings;
288 288
     }
289 289
 
290
-    public function wp_nav_menu_objects($items, $args){
291
-        if(!is_user_logged_in()){
290
+    public function wp_nav_menu_objects($items, $args) {
291
+        if (!is_user_logged_in()) {
292 292
             return $items;
293 293
         }
294 294
 
295
-        if(!apply_filters('wpinv_bp_invoice_history_redirect', true, $items, $args)){
295
+        if (!apply_filters('wpinv_bp_invoice_history_redirect', true, $items, $args)) {
296 296
             return $items;
297 297
         }
298 298
 
299 299
         $user_id = get_current_user_id();
300
-        $link = bp_core_get_user_domain( $user_id ).WPINV_BP_SLUG;
300
+        $link = bp_core_get_user_domain($user_id) . WPINV_BP_SLUG;
301 301
         $history_link = wpinv_get_history_page_uri();
302
-        foreach ( $items as $item ) {
303
-            $item->url = str_replace( $history_link, $link, $item->url );
302
+        foreach ($items as $item) {
303
+            $item->url = str_replace($history_link, $link, $item->url);
304 304
         }
305 305
 
306 306
         return $items;
@@ -318,78 +318,78 @@  discard block
 block discarded – undo
318 318
     public $pag_links = '';
319 319
     public $total_invoice_count = 0;
320 320
     
321
-    public function __construct( $status, $page, $per_page, $max, $user_id, $page_arg = 'bpage' ) {
322
-        $this->invoices = array( 'invoices' => array(), 'total' => 0 );
321
+    public function __construct($status, $page, $per_page, $max, $user_id, $page_arg = 'bpage') {
322
+        $this->invoices = array('invoices' => array(), 'total' => 0);
323 323
         
324
-        $this->pag_arg  = sanitize_key( $page_arg );
325
-        $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page );
326
-        $this->pag_num  = bp_sanitize_pagination_arg( 'num', $per_page );
324
+        $this->pag_arg  = sanitize_key($page_arg);
325
+        $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page);
326
+        $this->pag_num  = bp_sanitize_pagination_arg('num', $per_page);
327 327
 
328
-        $query_args     = array( 'user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true );
329
-        if ( !empty( $status ) && $status != 'all' ) {
328
+        $query_args     = array('user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true);
329
+        if (!empty($status) && $status != 'all') {
330 330
            $query_args['status'] = $status;
331 331
         }
332
-        $invoices  = wpinv_get_invoices( apply_filters( 'wpinv_bp_user_invoices_query', $query_args ) );
332
+        $invoices = wpinv_get_invoices(apply_filters('wpinv_bp_user_invoices_query', $query_args));
333 333
         
334
-        if ( !empty( $invoices ) && !empty( $invoices->found_posts ) ) {
335
-            $this->invoices['invoices'] = array_map( 'wpinv_get_invoice', $invoices->posts );
334
+        if (!empty($invoices) && !empty($invoices->found_posts)) {
335
+            $this->invoices['invoices'] = array_map('wpinv_get_invoice', $invoices->posts);
336 336
             $this->invoices['total']    = $invoices->found_posts;
337 337
         }
338 338
 
339
-        if ( empty( $max ) || ( $max >= (int)$this->invoices['total'] ) ) {
340
-            $this->total_invoice_count = (int)$this->invoices['total'];
339
+        if (empty($max) || ($max >= (int) $this->invoices['total'])) {
340
+            $this->total_invoice_count = (int) $this->invoices['total'];
341 341
         } else {
342
-            $this->total_invoice_count = (int)$max;
342
+            $this->total_invoice_count = (int) $max;
343 343
         }
344 344
 
345 345
         $this->invoices = $this->invoices['invoices'];
346 346
 
347
-        $invoice_count = count( $this->invoices );
347
+        $invoice_count = count($this->invoices);
348 348
 
349
-        if ( empty( $max ) || ( $max >= (int)$invoice_count ) ) {
350
-            $this->invoice_count = (int)$invoice_count;
349
+        if (empty($max) || ($max >= (int) $invoice_count)) {
350
+            $this->invoice_count = (int) $invoice_count;
351 351
         } else {
352
-            $this->invoice_count = (int)$max;
352
+            $this->invoice_count = (int) $max;
353 353
         }
354 354
         
355
-        if ( ! empty( $this->total_invoice_count ) && ! empty( $this->pag_num ) ) {
356
-            $this->pag_links = paginate_links( array(
357
-                'base'      => add_query_arg( $this->pag_arg, '%#%' ),
355
+        if (!empty($this->total_invoice_count) && !empty($this->pag_num)) {
356
+            $this->pag_links = paginate_links(array(
357
+                'base'      => add_query_arg($this->pag_arg, '%#%'),
358 358
                 'format'    => '',
359
-                'total'     => ceil( (int)$this->total_invoice_count / (int)$this->pag_num ),
360
-                'current'   => (int)$this->pag_page,
361
-                'prev_text' => _x( '&larr;', 'Invoice pagination previous text', 'invoicing' ),
362
-                'next_text' => _x( '&rarr;', 'Invoice pagination next text',     'invoicing' ),
359
+                'total'     => ceil((int) $this->total_invoice_count / (int) $this->pag_num),
360
+                'current'   => (int) $this->pag_page,
361
+                'prev_text' => _x('&larr;', 'Invoice pagination previous text', 'invoicing'),
362
+                'next_text' => _x('&rarr;', 'Invoice pagination next text', 'invoicing'),
363 363
                 'mid_size'  => 1,
364 364
                 'add_args'  => array(),
365
-            ) );
365
+            ));
366 366
         }
367 367
     }
368 368
 
369 369
     public function has_invoices() {
370
-        return (bool) ! empty( $this->invoice_count );
370
+        return (bool) !empty($this->invoice_count);
371 371
     }
372 372
 
373 373
     public function next_invoice() {
374 374
         $this->current_invoice++;
375
-        $this->invoice = $this->invoices[ $this->current_invoice ];
375
+        $this->invoice = $this->invoices[$this->current_invoice];
376 376
 
377 377
         return $this->invoice;
378 378
     }
379 379
 
380 380
     public function rewind_invoices() {
381 381
         $this->current_invoice = -1;
382
-        if ( $this->invoice_count > 0 ) {
382
+        if ($this->invoice_count > 0) {
383 383
             $this->invoice = $this->invoices[0];
384 384
         }
385 385
     }
386 386
 
387 387
     public function invoices() {
388
-        if ( ( $this->current_invoice + 1 ) < $this->invoice_count ) {
388
+        if (($this->current_invoice + 1) < $this->invoice_count) {
389 389
             return true;
390
-        } elseif ( ( $this->current_invoice + 1 ) === $this->invoice_count ) {
390
+        } elseif (($this->current_invoice + 1) === $this->invoice_count) {
391 391
 
392
-            do_action( 'wpinv_bp_invoice_loop_end' );
392
+            do_action('wpinv_bp_invoice_loop_end');
393 393
             
394 394
             $this->rewind_invoices();
395 395
         }
@@ -403,19 +403,19 @@  discard block
 block discarded – undo
403 403
         $this->in_the_loop = true;
404 404
         $this->invoice     = $this->next_invoice();
405 405
 
406
-        if ( 0 === $this->current_invoice ) {
407
-            do_action( 'wpinv_bp_invoice_loop_start' );
406
+        if (0 === $this->current_invoice) {
407
+            do_action('wpinv_bp_invoice_loop_start');
408 408
         }
409 409
     }
410 410
 }
411 411
 
412 412
 function wpinv_bp_setup_component() {
413 413
 
414
-    if(!class_exists( 'BuddyPress' )){
414
+    if (!class_exists('BuddyPress')) {
415 415
         return;
416 416
     }
417 417
 
418 418
     new WPInv_BP_Component();
419 419
 
420 420
 }
421
-add_action( 'bp_loaded', 'wpinv_bp_setup_component' );
422 421
\ No newline at end of file
422
+add_action('bp_loaded', 'wpinv_bp_setup_component');
423 423
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-error-functions.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@
 block discarded – undo
13 13
         ) );
14 14
         echo '<div class="' . implode( ' ', $classes ) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
16
+            foreach ( $errors as $error_id => $error ) {
17 17
                 echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
18
-           }
18
+            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -1,61 +1,61 @@  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
 function wpinv_print_errors() {
8 8
     $errors = wpinv_get_errors();
9 9
 
10
-    if ( $errors ) {
11
-        $classes = apply_filters( 'wpinv_error_class', array(
10
+    if ($errors) {
11
+        $classes = apply_filters('wpinv_error_class', array(
12 12
             'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error'
13
-        ) );
14
-        echo '<div class="' . implode( ' ', $classes ) . '">';
13
+        ));
14
+        echo '<div class="' . implode(' ', $classes) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
17
-                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
16
+           foreach ($errors as $error_id => $error) {
17
+                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>';
18 18
            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
22 22
 }
23
-add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' );
24
-add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' );
23
+add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors');
24
+add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors');
25 25
 
26 26
 function wpinv_get_errors() {
27 27
     global $wpi_session;
28 28
     
29
-    return $wpi_session->get( 'wpinv_errors' );
29
+    return $wpi_session->get('wpinv_errors');
30 30
 }
31 31
 
32
-function wpinv_set_error( $error_id, $error_message ) {
32
+function wpinv_set_error($error_id, $error_message) {
33 33
     global $wpi_session;
34 34
     
35 35
     $errors = wpinv_get_errors();
36 36
 
37
-    if ( ! $errors ) {
37
+    if (!$errors) {
38 38
         $errors = array();
39 39
     }
40 40
 
41
-    $errors[ $error_id ] = $error_message;
42
-    $wpi_session->set( 'wpinv_errors', $errors );
41
+    $errors[$error_id] = $error_message;
42
+    $wpi_session->set('wpinv_errors', $errors);
43 43
 }
44 44
 
45 45
 function wpinv_clear_errors() {
46 46
     global $wpi_session;
47 47
     
48
-    $wpi_session->set( 'wpinv_errors', null );
48
+    $wpi_session->set('wpinv_errors', null);
49 49
 }
50 50
 
51
-function wpinv_unset_error( $error_id ) {
51
+function wpinv_unset_error($error_id) {
52 52
     global $wpi_session;
53 53
     
54 54
     $errors = wpinv_get_errors();
55 55
 
56
-    if ( $errors ) {
57
-        unset( $errors[ $error_id ] );
58
-        $wpi_session->set( 'wpinv_errors', $errors );
56
+    if ($errors) {
57
+        unset($errors[$error_id]);
58
+        $wpi_session->set('wpinv_errors', $errors);
59 59
     }
60 60
 }
61 61
 
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
     die();
64 64
 }
65 65
 
66
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
67
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
68
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
69
-    wp_die( $message, $title, array( 'response' => $status ));
66
+function wpinv_die($message = '', $title = '', $status = 400) {
67
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
68
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
69
+    wp_die($message, $title, array('response' => $status));
70 70
 }
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 2 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -286,26 +286,26 @@  discard block
 block discarded – undo
286 286
 }
287 287
 
288 288
 function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
289
+    $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
290 290
 
291 291
     $chosen = false;
292 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 );
300
-	}
298
+    if ( false !== $chosen ) {
299
+        $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
300
+    }
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
-		$enabled_gateway = 'manual';
306
-	} else {
307
-		$enabled_gateway = wpinv_get_default_gateway();
308
-	}
302
+    if ( ! empty ( $chosen ) ) {
303
+        $enabled_gateway = urldecode( $chosen );
304
+    } else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
+        $enabled_gateway = 'manual';
306
+    } else {
307
+        $enabled_gateway = wpinv_get_default_gateway();
308
+    }
309 309
     
310 310
     if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311 311
         if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
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 322
 function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 }
325 325
 
326 326
 function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
327
-	$ret  = 0;
328
-	$args = array(
329
-		'meta_key'    => '_wpinv_gateway',
330
-		'meta_value'  => $gateway_id,
331
-		'nopaging'    => true,
332
-		'post_type'   => 'wpi_invoice',
333
-		'post_status' => $status,
334
-		'fields'      => 'ids'
335
-	);
336
-
337
-	$payments = new WP_Query( $args );
338
-
339
-	if( $payments )
340
-		$ret = $payments->post_count;
341
-	return $ret;
327
+    $ret  = 0;
328
+    $args = array(
329
+        'meta_key'    => '_wpinv_gateway',
330
+        'meta_value'  => $gateway_id,
331
+        'nopaging'    => true,
332
+        'post_type'   => 'wpi_invoice',
333
+        'post_status' => $status,
334
+        'fields'      => 'ids'
335
+    );
336
+
337
+    $payments = new WP_Query( $args );
338
+
339
+    if( $payments )
340
+        $ret = $payments->post_count;
341
+    return $ret;
342 342
 }
343 343
 
344 344
 function wpinv_settings_update_gateways( $input ) {
Please login to merge, or discard this patch.
Spacing   +258 added lines, -258 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,139 +417,139 @@  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 to authenticate transaction responses from the Authorize.Net for recurring payments. 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 to authenticate transaction responses from the Authorize.Net for recurring payments. 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_transaction_type'] = array(
532 532
         'id'          => 'authorizenet_transaction_type',
533
-        'name'        => __( 'Transaction Type', 'invoicing' ),
534
-        'desc'        => __( 'Choose transaction type.', 'invoicing' ),
533
+        'name'        => __('Transaction Type', 'invoicing'),
534
+        'desc'        => __('Choose transaction type.', 'invoicing'),
535 535
         'type'        => 'select',
536 536
         'class'       => 'wpi_select2',
537 537
         'options'     => array(
538
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
539
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
538
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
539
+            'authorize_only' => __('Authorize Only', 'invoicing'),
540 540
         ),
541 541
         'std'         => 'authorize_capture'
542 542
     );
543 543
 
544 544
     $setting['authorizenet_transaction_type_recurring'] = array(
545 545
         'id'          => 'authorizenet_transaction_type_recurring',
546
-        'name'        => __( 'Transaction Type for Recurring', 'invoicing' ),
547
-        'desc'        => __( 'Choose transaction type for recurring payments.', 'invoicing' ),
546
+        'name'        => __('Transaction Type for Recurring', 'invoicing'),
547
+        'desc'        => __('Choose transaction type for recurring payments.', 'invoicing'),
548 548
         'type'        => 'select',
549 549
         'class'       => 'wpi_select2',
550 550
         'options'     => array(
551
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
552
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
551
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
552
+            'authorize_only' => __('Authorize Only', 'invoicing'),
553 553
         ),
554 554
         'std'         => 'authorize_only'
555 555
     );
@@ -557,9 +557,9 @@  discard block
 block discarded – undo
557 557
     $setting['authorizenet_ipn_url'] = array(
558 558
             'type' => 'ipn_url',
559 559
             'id'   => 'authorizenet_ipn_url',
560
-            'name' => __( 'Silent Post URL', 'invoicing' ),
561
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
562
-            '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' ),
560
+            'name' => __('Silent Post URL', 'invoicing'),
561
+            'std' => wpinv_get_ipn_url('authorizenet'),
562
+            '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'),
563 563
             'size' => 'large',
564 564
             'custom' => 'authorizenet',
565 565
             'readonly' => true
@@ -567,26 +567,26 @@  discard block
 block discarded – undo
567 567
         
568 568
     return $setting;
569 569
 }
570
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
570
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
571 571
 
572 572
 // Worldpay settings
573
-function wpinv_gateway_settings_worldpay( $setting ) {
574
-    $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' );
575
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' );
573
+function wpinv_gateway_settings_worldpay($setting) {
574
+    $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');
575
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing');
576 576
     
577 577
     $setting['worldpay_sandbox'] = array(
578 578
             'type' => 'checkbox',
579 579
             'id'   => 'worldpay_sandbox',
580
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
581
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
580
+            'name' => __('Worldpay Test Mode', 'invoicing'),
581
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
582 582
             'std'  => 1
583 583
         );
584 584
         
585 585
     $setting['worldpay_instId'] = array(
586 586
             'type' => 'text',
587 587
             'id'   => 'worldpay_instId',
588
-            'name' => __( 'Installation Id', 'invoicing' ),
589
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
588
+            'name' => __('Installation Id', 'invoicing'),
589
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
590 590
             'std' => '211616',
591 591
         );
592 592
     /*
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
     $setting['worldpay_ipn_url'] = array(
603 603
             'type' => 'ipn_url',
604 604
             'id'   => 'worldpay_ipn_url',
605
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
606
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
607
-            '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>' ),
605
+            'name' => __('Worldpay Callback Url', 'invoicing'),
606
+            'std' => wpinv_get_ipn_url('worldpay'),
607
+            '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>'),
608 608
             'size' => 'large',
609 609
             'custom' => 'worldpay',
610 610
             'readonly' => true
@@ -612,99 +612,99 @@  discard block
 block discarded – undo
612 612
         
613 613
     return $setting;
614 614
 }
615
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
615
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
616 616
 
617
-function wpinv_ipn_url_callback( $args ) {    
618
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
617
+function wpinv_ipn_url_callback($args) {    
618
+    $sanitize_id = wpinv_sanitize_key($args['id']);
619 619
     
620 620
     $attrs = $args['readonly'] ? ' readonly' : '';
621 621
 
622
-    $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">';
623
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
622
+    $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">';
623
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
624 624
 
625 625
     echo $html;
626 626
 }
627 627
 
628
-function wpinv_is_test_mode( $gateway = '' ) {
629
-    if ( empty( $gateway ) ) {
628
+function wpinv_is_test_mode($gateway = '') {
629
+    if (empty($gateway)) {
630 630
         return false;
631 631
     }
632 632
     
633
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
633
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
634 634
     
635
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
635
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
636 636
 }
637 637
 
638
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
639
-    $data = array( 'wpi-listener' => 'IPN' );
638
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
639
+    $data = array('wpi-listener' => 'IPN');
640 640
     
641
-    if ( !empty( $gateway ) ) {
642
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
641
+    if (!empty($gateway)) {
642
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
643 643
     }
644 644
     
645
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
645
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
646 646
     
647
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
647
+    $ipn_url = add_query_arg($args, home_url('index.php'));
648 648
     
649
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
649
+    return apply_filters('wpinv_ipn_url', $ipn_url);
650 650
 }
651 651
 
652 652
 function wpinv_listen_for_payment_ipn() {
653 653
     // Regular PayPal IPN
654
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
655
-        do_action( 'wpinv_verify_payment_ipn' );
654
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
655
+        do_action('wpinv_verify_payment_ipn');
656 656
         
657
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
658
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
659
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
657
+        if (!empty($_GET['wpi-gateway'])) {
658
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
659
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
660 660
         }
661 661
     }
662 662
 }
663
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
663
+add_action('init', 'wpinv_listen_for_payment_ipn');
664 664
 
665 665
 function wpinv_get_bank_instructions() {
666
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
666
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
667 667
     
668
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
668
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
669 669
 }
670 670
 
671
-function wpinv_get_bank_info( $filtered = false ) {
671
+function wpinv_get_bank_info($filtered = false) {
672 672
     $bank_fields = array(
673
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
674
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
675
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
676
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
677
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
678
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
679
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
673
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
674
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
675
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
676
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
677
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
678
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
679
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
680 680
     );
681 681
     
682 682
     $bank_info = array();
683
-    foreach ( $bank_fields as $field => $label ) {
684
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
683
+    foreach ($bank_fields as $field => $label) {
684
+        if ($filtered && !($value = wpinv_get_option($field))) {
685 685
             continue;
686 686
         }
687 687
         
688
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
688
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
689 689
     }
690 690
     
691
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
691
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
692 692
 }
693 693
 
694
-function wpinv_get_post_data( $method = 'request' ) {
694
+function wpinv_get_post_data($method = 'request') {
695 695
     $data       = array();
696 696
     $request    = $_REQUEST;
697 697
     
698
-    if ( $method == 'post' ) {
699
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
698
+    if ($method == 'post') {
699
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
700 700
             return $data;
701 701
         }
702 702
         
703 703
         $request = $_POST;
704 704
     }
705 705
     
706
-    if ( $method == 'get' ) {
707
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
706
+    if ($method == 'get') {
707
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
708 708
             return $data;
709 709
         }
710 710
         
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
     $post_data = '';
716 716
     
717 717
     // Fallback just in case post_max_size is lower than needed
718
-    if ( ini_get( 'allow_url_fopen' ) ) {
719
-        $post_data = file_get_contents( 'php://input' );
718
+    if (ini_get('allow_url_fopen')) {
719
+        $post_data = file_get_contents('php://input');
720 720
     } else {
721 721
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
722
-        ini_set( 'post_max_size', '12M' );
722
+        ini_set('post_max_size', '12M');
723 723
     }
724 724
     // Start the encoded data collection with notification command
725 725
     $encoded_data = 'cmd=_notify-validate';
@@ -728,58 +728,58 @@  discard block
 block discarded – undo
728 728
     $arg_separator = wpinv_get_php_arg_separator_output();
729 729
 
730 730
     // Verify there is a post_data
731
-    if ( $post_data || strlen( $post_data ) > 0 ) {
731
+    if ($post_data || strlen($post_data) > 0) {
732 732
         // Append the data
733 733
         $encoded_data .= $arg_separator . $post_data;
734 734
     } else {
735 735
         // Check if POST is empty
736
-        if ( empty( $request ) ) {
736
+        if (empty($request)) {
737 737
             // Nothing to do
738 738
             return;
739 739
         } else {
740 740
             // Loop through each POST
741
-            foreach ( $request as $key => $value ) {
741
+            foreach ($request as $key => $value) {
742 742
                 // Encode the value and append the data
743
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
743
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
744 744
             }
745 745
         }
746 746
     }
747 747
 
748 748
     // Convert collected post data to an array
749
-    wp_parse_str( $encoded_data, $data );
749
+    wp_parse_str($encoded_data, $data);
750 750
 
751
-    foreach ( $data as $key => $value ) {
752
-        if ( false !== strpos( $key, 'amp;' ) ) {
753
-            $new_key = str_replace( '&amp;', '&', $key );
754
-            $new_key = str_replace( 'amp;', '&' , $new_key );
751
+    foreach ($data as $key => $value) {
752
+        if (false !== strpos($key, 'amp;')) {
753
+            $new_key = str_replace('&amp;', '&', $key);
754
+            $new_key = str_replace('amp;', '&', $new_key);
755 755
 
756
-            unset( $data[ $key ] );
757
-            $data[ $new_key ] = sanitize_text_field( $value );
756
+            unset($data[$key]);
757
+            $data[$new_key] = sanitize_text_field($value);
758 758
         }
759 759
     }
760 760
     
761 761
     return $data;
762 762
 }
763 763
 
764
-function wpinv_gateway_support_subscription( $gateway ) {
764
+function wpinv_gateway_support_subscription($gateway) {
765 765
     $return = false;
766 766
     
767
-    if ( wpinv_is_gateway_active( $gateway ) ) {
768
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
767
+    if (wpinv_is_gateway_active($gateway)) {
768
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
769 769
     }
770 770
     
771 771
     return $return;
772 772
 }
773 773
 
774
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
775
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
776
-        foreach ( $gateways as $gateway => $info ) {
777
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
778
-                unset( $gateways[$gateway] );
774
+function wpinv_payment_gateways_on_cart($gateways = array()) {
775
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
776
+        foreach ($gateways as $gateway => $info) {
777
+            if (!wpinv_gateway_support_subscription($gateway)) {
778
+                unset($gateways[$gateway]);
779 779
             }
780 780
         }
781 781
     }
782 782
     
783 783
     return $gateways;
784 784
 }
785
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
786 785
\ No newline at end of file
786
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
787 787
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -887,8 +887,8 @@
 block discarded – undo
887 887
     if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888 888
         unset( $data['cart_discounts'] );
889 889
         
890
-         wpinv_set_checkout_session( $data );
891
-         return true;
890
+            wpinv_set_checkout_session( $data );
891
+            return true;
892 892
     }
893 893
     
894 894
     return false;
Please login to merge, or discard this patch.
Spacing   +480 added lines, -480 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@  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_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array) apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!wpinv_current_user_can_manage_invoicing()) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!wpinv_current_user_can_manage_invoicing()) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!wpinv_current_user_can_manage_invoicing()) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
97 97
     return false;
98 98
 }
99 99
 
100
-function wpinv_get_all_discounts( $args = array() ) {
100
+function wpinv_get_all_discounts($args = array()) {
101 101
 
102
-    $args = wp_parse_args( $args, array(
103
-        'status'         => array( 'publish' ),
104
-        'limit'          => get_option( 'posts_per_page' ),
102
+    $args = wp_parse_args($args, array(
103
+        'status'         => array('publish'),
104
+        'limit'          => get_option('posts_per_page'),
105 105
         'page'           => 1,
106 106
         'exclude'        => array(),
107 107
         'orderby'        => 'date',
108 108
         'order'          => 'DESC',
109
-        'type'           => array_keys( wpinv_get_discount_types() ),
109
+        'type'           => array_keys(wpinv_get_discount_types()),
110 110
         'meta_query'     => array(),
111 111
         'return'         => 'objects',
112 112
         'paginate'       => false,
113
-    ) );
113
+    ));
114 114
 
115 115
     $wp_query_args = array(
116 116
         'post_type'      => 'wpi_discount',
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
         'fields'         => 'ids',
121 121
         'orderby'        => $args['orderby'],
122 122
         'order'          => $args['order'],
123
-        'paged'          => absint( $args['page'] ),
123
+        'paged'          => absint($args['page']),
124 124
     );
125 125
 
126
-    if ( ! empty( $args['exclude'] ) ) {
127
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
126
+    if (!empty($args['exclude'])) {
127
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
128 128
     }
129 129
 
130
-    if ( ! $args['paginate' ] ) {
130
+    if (!$args['paginate']) {
131 131
         $wp_query_args['no_found_rows'] = true;
132 132
     }
133 133
 
134
-    if ( ! empty( $args['search'] ) ) {
134
+    if (!empty($args['search'])) {
135 135
 
136 136
         $wp_query_args['meta_query'][] = array(
137 137
             'key'     => '_wpi_discount_code',
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 
142 142
     }
143 143
     
144
-    if ( ! empty( $args['type'] ) ) {
145
-        $types = wpinv_parse_list( $args['type'] );
144
+    if (!empty($args['type'])) {
145
+        $types = wpinv_parse_list($args['type']);
146 146
         $wp_query_args['meta_query'][] = array(
147 147
             'key'     => '_wpi_discount_type',
148
-            'value'   => implode( ',', $types ),
148
+            'value'   => implode(',', $types),
149 149
             'compare' => 'IN',
150 150
         );
151 151
     }
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
     $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args);
154 154
 
155 155
     // Get results.
156
-    $discounts = new WP_Query( $wp_query_args );
156
+    $discounts = new WP_Query($wp_query_args);
157 157
 
158
-    if ( 'objects' === $args['return'] ) {
159
-        $return = array_map( 'get_post', $discounts->posts );
160
-    } elseif ( 'self' === $args['return'] ) {
158
+    if ('objects' === $args['return']) {
159
+        $return = array_map('get_post', $discounts->posts);
160
+    } elseif ('self' === $args['return']) {
161 161
         return $discounts;
162 162
     } else {
163 163
         $return = $discounts->posts;
164 164
     }
165 165
 
166
-    if ( $args['paginate' ] ) {
166
+    if ($args['paginate']) {
167 167
         return (object) array(
168 168
             'discounts'      => $return,
169 169
             'total'         => $discounts->found_posts,
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 
181 181
     $discounts  = wpinv_get_discounts();
182 182
 
183
-    if ( $discounts) {
184
-        foreach ( $discounts as $discount ) {
185
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
183
+    if ($discounts) {
184
+        foreach ($discounts as $discount) {
185
+            if (wpinv_is_discount_active($discount->ID)) {
186 186
                 $has_active = true;
187 187
                 break;
188 188
             }
@@ -191,38 +191,38 @@  discard block
 block discarded – undo
191 191
     return $has_active;
192 192
 }
193 193
 
194
-function wpinv_get_discount( $discount_id = 0 ) {
195
-    if( empty( $discount_id ) ) {
194
+function wpinv_get_discount($discount_id = 0) {
195
+    if (empty($discount_id)) {
196 196
         return false;
197 197
     }
198 198
     
199
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
199
+    if (get_post_type($discount_id) != 'wpi_discount') {
200 200
         return false;
201 201
     }
202 202
 
203
-    $discount = get_post( $discount_id );
203
+    $discount = get_post($discount_id);
204 204
 
205 205
     return $discount;
206 206
 }
207 207
 
208
-function wpinv_get_discount_by_code( $code = '' ) {
209
-    if( empty( $code ) || ! is_string( $code ) ) {
208
+function wpinv_get_discount_by_code($code = '') {
209
+    if (empty($code) || !is_string($code)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    return wpinv_get_discount_by( 'code', $code );
213
+    return wpinv_get_discount_by('code', $code);
214 214
 }
215 215
 
216
-function wpinv_get_discount_by( $field = '', $value = '' ) {
217
-    if( empty( $field ) || empty( $value ) ) {
216
+function wpinv_get_discount_by($field = '', $value = '') {
217
+    if (empty($field) || empty($value)) {
218 218
         return false;
219 219
     }
220 220
 
221
-    if( ! is_string( $field ) ) {
221
+    if (!is_string($field)) {
222 222
         return false;
223 223
     }
224 224
 
225
-    switch( strtolower( $field ) ) {
225
+    switch (strtolower($field)) {
226 226
 
227 227
         case 'code':
228 228
             $meta_query     = array();
@@ -232,32 +232,32 @@  discard block
 block discarded – undo
232 232
                 'compare' => '='
233 233
             );
234 234
             
235
-            $discount = wpinv_get_discounts( array(
235
+            $discount = wpinv_get_discounts(array(
236 236
                 'posts_per_page' => 1,
237 237
                 'post_status'    => 'any',
238 238
                 'meta_query'     => $meta_query,
239
-            ) );
239
+            ));
240 240
             
241
-            if( $discount ) {
241
+            if ($discount) {
242 242
                 $discount = $discount[0];
243 243
             }
244 244
 
245 245
             break;
246 246
 
247 247
         case 'id':
248
-            $discount = wpinv_get_discount( $value );
248
+            $discount = wpinv_get_discount($value);
249 249
 
250 250
             break;
251 251
 
252 252
         case 'name':
253
-            $discount = get_posts( array(
253
+            $discount = get_posts(array(
254 254
                 'post_type'      => 'wpi_discount',
255 255
                 'name'           => $value,
256 256
                 'posts_per_page' => 1,
257 257
                 'post_status'    => 'any'
258
-            ) );
258
+            ));
259 259
 
260
-            if( $discount ) {
260
+            if ($discount) {
261 261
                 $discount = $discount[0];
262 262
             }
263 263
 
@@ -267,96 +267,96 @@  discard block
 block discarded – undo
267 267
             return false;
268 268
     }
269 269
 
270
-    if( ! empty( $discount ) ) {
270
+    if (!empty($discount)) {
271 271
         return $discount;
272 272
     }
273 273
 
274 274
     return false;
275 275
 }
276 276
 
277
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
277
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
278 278
     $meta = array(
279
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
280
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
281
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
282
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
283
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
284
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
285
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
286
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
287
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
288
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
289
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
290
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
291
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
279
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
280
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
281
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
282
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
283
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
284
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
285
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
286
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
287
+        'items'             => isset($data['items']) ? $data['items'] : array(),
288
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
289
+        'is_recurring'      => isset($data['recurring']) ? (bool) $data['recurring'] : false,
290
+        'is_single_use'     => isset($data['single_use']) ? (bool) $data['single_use'] : false,
291
+        'uses'              => isset($data['uses']) ? (int) $data['uses'] : false,
292 292
     );
293 293
 
294
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
294
+    if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) {
295 295
         $meta['amount'] = 100;
296 296
     }
297 297
 
298
-    if ( !empty( $meta['start'] ) ) {
299
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
298
+    if (!empty($meta['start'])) {
299
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
300 300
     }
301 301
 
302
-    if ( !empty( $meta['expiration'] ) ) {
303
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
302
+    if (!empty($meta['expiration'])) {
303
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
304 304
 
305
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
305
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
306 306
             $meta['expiration'] = $meta['start'];
307 307
         }
308 308
     }
309 309
     
310
-    if ( $meta['uses'] === false ) {
311
-        unset( $meta['uses'] );
310
+    if ($meta['uses'] === false) {
311
+        unset($meta['uses']);
312 312
     }
313 313
     
314
-    if ( ! empty( $meta['items'] ) ) {
315
-        foreach ( $meta['items'] as $key => $item ) {
316
-            if ( 0 === intval( $item ) ) {
317
-                unset( $meta['items'][ $key ] );
314
+    if (!empty($meta['items'])) {
315
+        foreach ($meta['items'] as $key => $item) {
316
+            if (0 === intval($item)) {
317
+                unset($meta['items'][$key]);
318 318
             }
319 319
         }
320 320
     }
321 321
     
322
-    if ( ! empty( $meta['excluded_items'] ) ) {
323
-        foreach ( $meta['excluded_items'] as $key => $item ) {
324
-            if ( 0 === intval( $item ) ) {
325
-                unset( $meta['excluded_items'][ $key ] );
322
+    if (!empty($meta['excluded_items'])) {
323
+        foreach ($meta['excluded_items'] as $key => $item) {
324
+            if (0 === intval($item)) {
325
+                unset($meta['excluded_items'][$key]);
326 326
             }
327 327
         }
328 328
     }
329 329
     
330
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
330
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
331 331
     
332
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
332
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
333 333
     
334
-    foreach( $meta as $key => $value ) {
335
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
334
+    foreach ($meta as $key => $value) {
335
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
336 336
     }
337 337
     
338
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
338
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
339 339
     
340 340
     return $post_id;
341 341
 }
342 342
 
343
-function wpinv_remove_discount( $discount_id = 0 ) {
344
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
343
+function wpinv_remove_discount($discount_id = 0) {
344
+    do_action('wpinv_pre_delete_discount', $discount_id);
345 345
 
346
-    wp_delete_post( $discount_id, true );
346
+    wp_delete_post($discount_id, true);
347 347
 
348
-    do_action( 'wpinv_post_delete_discount', $discount_id );
348
+    do_action('wpinv_post_delete_discount', $discount_id);
349 349
 }
350 350
 
351
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
352
-    $discount = wpinv_get_discount(  $code_id );
351
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
352
+    $discount = wpinv_get_discount($code_id);
353 353
 
354
-    if ( $discount ) {
355
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
354
+    if ($discount) {
355
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
356 356
 
357
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
357
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
358 358
 
359
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
359
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
360 360
 
361 361
         return true;
362 362
     }
@@ -364,173 +364,173 @@  discard block
 block discarded – undo
364 364
     return false;
365 365
 }
366 366
 
367
-function wpinv_discount_exists( $code_id ) {
368
-    if ( wpinv_get_discount(  $code_id ) ) {
367
+function wpinv_discount_exists($code_id) {
368
+    if (wpinv_get_discount($code_id)) {
369 369
         return true;
370 370
     }
371 371
 
372 372
     return false;
373 373
 }
374 374
 
375
-function wpinv_is_discount_active( $code_id = null ) {
376
-    $discount = wpinv_get_discount(  $code_id );
375
+function wpinv_is_discount_active($code_id = null) {
376
+    $discount = wpinv_get_discount($code_id);
377 377
     $return   = false;
378 378
 
379
-    if ( $discount ) {
380
-        if ( wpinv_is_discount_expired( $code_id ) ) {
381
-            if( defined( 'DOING_AJAX' ) ) {
382
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
379
+    if ($discount) {
380
+        if (wpinv_is_discount_expired($code_id)) {
381
+            if (defined('DOING_AJAX')) {
382
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
383 383
             }
384
-        } elseif ( $discount->post_status == 'publish' ) {
384
+        } elseif ($discount->post_status == 'publish') {
385 385
             $return = true;
386 386
         } else {
387
-            if( defined( 'DOING_AJAX' ) ) {
388
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
387
+            if (defined('DOING_AJAX')) {
388
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
389 389
             }
390 390
         }
391 391
     }
392 392
 
393
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
393
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
394 394
 }
395 395
 
396
-function wpinv_get_discount_code( $code_id = null ) {
397
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
396
+function wpinv_get_discount_code($code_id = null) {
397
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
398 398
 
399
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
399
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
400 400
 }
401 401
 
402
-function wpinv_get_discount_start_date( $code_id = null ) {
403
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
402
+function wpinv_get_discount_start_date($code_id = null) {
403
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
404 404
 
405
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
405
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
406 406
 }
407 407
 
408
-function wpinv_get_discount_expiration( $code_id = null ) {
409
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
408
+function wpinv_get_discount_expiration($code_id = null) {
409
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
410 410
 
411
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
411
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_max_uses( $code_id = null ) {
415
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
414
+function wpinv_get_discount_max_uses($code_id = null) {
415
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
416 416
 
417
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
417
+    return (int) apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
418 418
 }
419 419
 
420
-function wpinv_get_discount_uses( $code_id = null ) {
421
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
420
+function wpinv_get_discount_uses($code_id = null) {
421
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
422 422
 
423
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
423
+    return (int) apply_filters('wpinv_get_discount_uses', $uses, $code_id);
424 424
 }
425 425
 
426
-function wpinv_get_discount_min_total( $code_id = null ) {
427
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
426
+function wpinv_get_discount_min_total($code_id = null) {
427
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
428 428
 
429
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
429
+    return (float) apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
430 430
 }
431 431
 
432
-function wpinv_get_discount_max_total( $code_id = null ) {
433
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
432
+function wpinv_get_discount_max_total($code_id = null) {
433
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
434 434
 
435
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
435
+    return (float) apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
436 436
 }
437 437
 
438
-function wpinv_get_discount_amount( $code_id = null ) {
439
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
438
+function wpinv_get_discount_amount($code_id = null) {
439
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
440 440
 
441
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
441
+    return (float) apply_filters('wpinv_get_discount_amount', $amount, $code_id);
442 442
 }
443 443
 
444
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
445
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
444
+function wpinv_get_discount_type($code_id = null, $name = false) {
445
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
446 446
     
447
-    if ( $name ) {
448
-        $name = wpinv_get_discount_type_name( $type );
447
+    if ($name) {
448
+        $name = wpinv_get_discount_type_name($type);
449 449
         
450
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
450
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
451 451
     }
452 452
 
453
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
453
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
454 454
 }
455 455
 
456
-function wpinv_discount_status( $status ) {
457
-    switch( $status ){
456
+function wpinv_discount_status($status) {
457
+    switch ($status) {
458 458
         case 'expired' :
459
-            $name = __( 'Expired', 'invoicing' );
459
+            $name = __('Expired', 'invoicing');
460 460
             break;
461 461
         case 'publish' :
462 462
         case 'active' :
463
-            $name = __( 'Active', 'invoicing' );
463
+            $name = __('Active', 'invoicing');
464 464
             break;
465 465
         default :
466
-            $name = __( 'Inactive', 'invoicing' );
466
+            $name = __('Inactive', 'invoicing');
467 467
             break;
468 468
     }
469 469
     return $name;
470 470
 }
471 471
 
472
-function wpinv_get_discount_excluded_items( $code_id = null ) {
473
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
472
+function wpinv_get_discount_excluded_items($code_id = null) {
473
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
474 474
 
475
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
475
+    if (empty($excluded_items) || !is_array($excluded_items)) {
476 476
         $excluded_items = array();
477 477
     }
478 478
 
479
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
479
+    return (array) apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
480 480
 }
481 481
 
482
-function wpinv_get_discount_item_reqs( $code_id = null ) {
483
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
482
+function wpinv_get_discount_item_reqs($code_id = null) {
483
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
484 484
 
485
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
485
+    if (empty($item_reqs) || !is_array($item_reqs)) {
486 486
         $item_reqs = array();
487 487
     }
488 488
 
489
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
489
+    return (array) apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
490 490
 }
491 491
 
492
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
493
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
492
+function wpinv_get_discount_item_condition($code_id = 0) {
493
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
494 494
 }
495 495
 
496
-function wpinv_is_discount_not_global( $code_id = 0 ) {
497
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
496
+function wpinv_is_discount_not_global($code_id = 0) {
497
+    return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true);
498 498
 }
499 499
 
500
-function wpinv_is_discount_expired( $code_id = null ) {
501
-    $discount = wpinv_get_discount(  $code_id );
500
+function wpinv_is_discount_expired($code_id = null) {
501
+    $discount = wpinv_get_discount($code_id);
502 502
     $return   = false;
503 503
 
504
-    if ( $discount ) {
505
-        $expiration = wpinv_get_discount_expiration( $code_id );
506
-        if ( $expiration ) {
507
-            $expiration = strtotime( $expiration );
508
-            if ( $expiration < current_time( 'timestamp' ) ) {
504
+    if ($discount) {
505
+        $expiration = wpinv_get_discount_expiration($code_id);
506
+        if ($expiration) {
507
+            $expiration = strtotime($expiration);
508
+            if ($expiration < current_time('timestamp')) {
509 509
                 // Discount is expired
510
-                wpinv_update_discount_status( $code_id, 'pending' );
510
+                wpinv_update_discount_status($code_id, 'pending');
511 511
                 $return = true;
512 512
             }
513 513
         }
514 514
     }
515 515
 
516
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
516
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
517 517
 }
518 518
 
519
-function wpinv_is_discount_started( $code_id = null ) {
520
-    $discount = wpinv_get_discount(  $code_id );
519
+function wpinv_is_discount_started($code_id = null) {
520
+    $discount = wpinv_get_discount($code_id);
521 521
     $return   = false;
522 522
 
523
-    if ( $discount ) {
524
-        $start_date = wpinv_get_discount_start_date( $code_id );
523
+    if ($discount) {
524
+        $start_date = wpinv_get_discount_start_date($code_id);
525 525
 
526
-        if ( $start_date ) {
527
-            $start_date = strtotime( $start_date );
526
+        if ($start_date) {
527
+            $start_date = strtotime($start_date);
528 528
 
529
-            if ( $start_date < current_time( 'timestamp' ) ) {
529
+            if ($start_date < current_time('timestamp')) {
530 530
                 // Discount has past the start date
531 531
                 $return = true;
532 532
             } else {
533
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
533
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
534 534
             }
535 535
         } else {
536 536
             // No start date for this discount, so has to be true
@@ -538,159 +538,159 @@  discard block
 block discarded – undo
538 538
         }
539 539
     }
540 540
 
541
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
541
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
542 542
 }
543 543
 
544
-function wpinv_check_discount_dates( $code_id = null ) {
545
-    $discount = wpinv_get_discount(  $code_id );
544
+function wpinv_check_discount_dates($code_id = null) {
545
+    $discount = wpinv_get_discount($code_id);
546 546
     $return   = false;
547 547
 
548
-    if ( $discount ) {
549
-        $start_date = wpinv_get_discount_start_date( $code_id );
548
+    if ($discount) {
549
+        $start_date = wpinv_get_discount_start_date($code_id);
550 550
 
551
-        if ( $start_date ) {
552
-            $start_date = strtotime( $start_date );
551
+        if ($start_date) {
552
+            $start_date = strtotime($start_date);
553 553
 
554
-            if ( $start_date < current_time( 'timestamp' ) ) {
554
+            if ($start_date < current_time('timestamp')) {
555 555
                 // Discount has past the start date
556 556
                 $return = true;
557 557
             } else {
558
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
558
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
559 559
             }
560 560
         } else {
561 561
             // No start date for this discount, so has to be true
562 562
             $return = true;
563 563
         }
564 564
         
565
-        if ( $return ) {
566
-            $expiration = wpinv_get_discount_expiration( $code_id );
565
+        if ($return) {
566
+            $expiration = wpinv_get_discount_expiration($code_id);
567 567
             
568
-            if ( $expiration ) {
569
-                $expiration = strtotime( $expiration );
570
-                if ( $expiration < current_time( 'timestamp' ) ) {
568
+            if ($expiration) {
569
+                $expiration = strtotime($expiration);
570
+                if ($expiration < current_time('timestamp')) {
571 571
                     // Discount is expired
572
-                    wpinv_update_discount_status( $code_id, 'pending' );
572
+                    wpinv_update_discount_status($code_id, 'pending');
573 573
                     $return = true;
574 574
                 }
575 575
             }
576 576
         }
577 577
     }
578 578
     
579
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
579
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
580 580
 }
581 581
 
582
-function wpinv_is_discount_maxed_out( $code_id = null ) {
583
-    $discount = wpinv_get_discount(  $code_id );
582
+function wpinv_is_discount_maxed_out($code_id = null) {
583
+    $discount = wpinv_get_discount($code_id);
584 584
     $return   = false;
585 585
 
586
-    if ( $discount ) {
587
-        $uses = wpinv_get_discount_uses( $code_id );
586
+    if ($discount) {
587
+        $uses = wpinv_get_discount_uses($code_id);
588 588
         // Large number that will never be reached
589
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
589
+        $max_uses = wpinv_get_discount_max_uses($code_id);
590 590
         // Should never be greater than, but just in case
591
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
591
+        if ($uses >= $max_uses && !empty($max_uses)) {
592 592
             // Discount is maxed out
593
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
593
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
594 594
             $return = true;
595 595
         }
596 596
     }
597 597
 
598
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
598
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
599 599
 }
600 600
 
601
-function wpinv_discount_is_min_met( $code_id = null ) {
602
-    $discount = wpinv_get_discount( $code_id );
601
+function wpinv_discount_is_min_met($code_id = null) {
602
+    $discount = wpinv_get_discount($code_id);
603 603
     $return   = false;
604 604
 
605
-    if ( $discount ) {
606
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
607
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
605
+    if ($discount) {
606
+        $min         = (float) wpinv_get_discount_min_total($code_id);
607
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
608 608
 
609
-        if ( !$min > 0 || $cart_amount >= $min ) {
609
+        if (!$min > 0 || $cart_amount >= $min) {
610 610
             // Minimum has been met
611 611
             $return = true;
612 612
         } else {
613
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
613
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
614 614
         }
615 615
     }
616 616
 
617
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
617
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
618 618
 }
619 619
 
620
-function wpinv_discount_is_max_met( $code_id = null ) {
621
-    $discount = wpinv_get_discount( $code_id );
620
+function wpinv_discount_is_max_met($code_id = null) {
621
+    $discount = wpinv_get_discount($code_id);
622 622
     $return   = false;
623 623
 
624
-    if ( $discount ) {
625
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
626
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
624
+    if ($discount) {
625
+        $max         = (float) wpinv_get_discount_max_total($code_id);
626
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
627 627
 
628
-        if ( !$max > 0 || $cart_amount <= $max ) {
628
+        if (!$max > 0 || $cart_amount <= $max) {
629 629
             // Minimum has been met
630 630
             $return = true;
631 631
         } else {
632
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
632
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
633 633
         }
634 634
     }
635 635
 
636
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
636
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
637 637
 }
638 638
 
639
-function wpinv_discount_is_single_use( $code_id = 0 ) {
640
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
641
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
639
+function wpinv_discount_is_single_use($code_id = 0) {
640
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
641
+    return (bool) apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
642 642
 }
643 643
 
644
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
645
-    if ( $code ) {
646
-        $discount = wpinv_get_discount_by_code( $code_id );
644
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
645
+    if ($code) {
646
+        $discount = wpinv_get_discount_by_code($code_id);
647 647
         
648
-        if ( !empty( $discount ) ) {
648
+        if (!empty($discount)) {
649 649
             $code_id = $discount->ID;
650 650
         }
651 651
     }
652 652
     
653
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
653
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
654 654
     
655
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
655
+    return (bool) apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
656 656
 }
657 657
 
658
-function wpinv_discount_item_reqs_met( $code_id = null ) {
659
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
660
-    $condition    = wpinv_get_discount_item_condition( $code_id );
661
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
658
+function wpinv_discount_item_reqs_met($code_id = null) {
659
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
660
+    $condition    = wpinv_get_discount_item_condition($code_id);
661
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
662 662
     $cart_items   = wpinv_get_cart_contents();
663
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
663
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
664 664
     $ret          = false;
665 665
 
666
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
666
+    if (empty($item_reqs) && empty($excluded_ps)) {
667 667
         $ret = true;
668 668
     }
669 669
 
670 670
     // Normalize our data for item requirements, exclusions and cart data
671 671
     // First absint the items, then sort, and reset the array keys
672
-    $item_reqs = array_map( 'absint', $item_reqs );
673
-    asort( $item_reqs );
674
-    $item_reqs = array_values( $item_reqs );
672
+    $item_reqs = array_map('absint', $item_reqs);
673
+    asort($item_reqs);
674
+    $item_reqs = array_values($item_reqs);
675 675
 
676
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
677
-    asort( $excluded_ps );
678
-    $excluded_ps  = array_values( $excluded_ps );
676
+    $excluded_ps  = array_map('absint', $excluded_ps);
677
+    asort($excluded_ps);
678
+    $excluded_ps  = array_values($excluded_ps);
679 679
 
680
-    $cart_ids     = array_map( 'absint', $cart_ids );
681
-    asort( $cart_ids );
682
-    $cart_ids     = array_values( $cart_ids );
680
+    $cart_ids     = array_map('absint', $cart_ids);
681
+    asort($cart_ids);
682
+    $cart_ids     = array_values($cart_ids);
683 683
 
684 684
     // Ensure we have requirements before proceeding
685
-    if ( !$ret && ! empty( $item_reqs ) ) {
686
-        switch( $condition ) {
685
+    if (!$ret && !empty($item_reqs)) {
686
+        switch ($condition) {
687 687
             case 'all' :
688 688
                 // Default back to true
689 689
                 $ret = true;
690 690
 
691
-                foreach ( $item_reqs as $item_id ) {
692
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
693
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
691
+                foreach ($item_reqs as $item_id) {
692
+                    if (!wpinv_item_in_cart($item_id)) {
693
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
694 694
                         $ret = false;
695 695
                         break;
696 696
                     }
@@ -699,15 +699,15 @@  discard block
 block discarded – undo
699 699
                 break;
700 700
 
701 701
             default : // Any
702
-                foreach ( $item_reqs as $item_id ) {
703
-                    if ( wpinv_item_in_cart( $item_id ) ) {
702
+                foreach ($item_reqs as $item_id) {
703
+                    if (wpinv_item_in_cart($item_id)) {
704 704
                         $ret = true;
705 705
                         break;
706 706
                     }
707 707
                 }
708 708
 
709
-                if( ! $ret ) {
710
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
709
+                if (!$ret) {
710
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
711 711
                 }
712 712
 
713 713
                 break;
@@ -716,70 +716,70 @@  discard block
 block discarded – undo
716 716
         $ret = true;
717 717
     }
718 718
 
719
-    if( ! empty( $excluded_ps ) ) {
719
+    if (!empty($excluded_ps)) {
720 720
         // Check that there are items other than excluded ones in the cart
721
-        if( $cart_ids == $excluded_ps ) {
722
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
721
+        if ($cart_ids == $excluded_ps) {
722
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
723 723
             $ret = false;
724 724
         }
725 725
     }
726 726
 
727
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
727
+    return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
728 728
 }
729 729
 
730
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
730
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
731 731
     global $wpi_checkout_id;
732 732
     
733 733
     $return = false;
734 734
 
735
-    if ( empty( $code_id ) ) {
736
-        $code_id = wpinv_get_discount_id_by_code( $code );
735
+    if (empty($code_id)) {
736
+        $code_id = wpinv_get_discount_id_by_code($code);
737 737
         
738
-        if( empty( $code_id ) ) {
738
+        if (empty($code_id)) {
739 739
             return false; // No discount was found
740 740
         }
741 741
     }
742 742
 
743
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
743
+    if (wpinv_discount_is_single_use($code_id)) {
744 744
         $payments = array();
745 745
 
746 746
         $user_id = 0;
747
-        if ( is_int( $user ) ) {
748
-            $user_id = absint( $user );
749
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
747
+        if (is_int($user)) {
748
+            $user_id = absint($user);
749
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
750 750
             $user_id = $user_data->ID;
751
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
751
+        } else if ($user_data = get_user_by('login', $user)) {
752 752
             $user_id = $user_data->ID;
753
-        } else if ( absint( $user ) > 0 ) {
754
-            $user_id = absint( $user );
753
+        } else if (absint($user) > 0) {
754
+            $user_id = absint($user);
755 755
         }
756 756
 
757
-        if ( !empty( $user_id ) ) {
758
-            $query    = array( 'user' => $user_id, 'limit' => false );
759
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
757
+        if (!empty($user_id)) {
758
+            $query    = array('user' => $user_id, 'limit' => false);
759
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
760 760
         }
761 761
 
762
-        if ( $payments ) {
763
-            foreach ( $payments as $payment ) {
762
+        if ($payments) {
763
+            foreach ($payments as $payment) {
764 764
                 // Don't count discount used for current invoice chekcout.
765
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
765
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
766 766
                     continue;
767 767
                 }
768 768
                 
769
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
769
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
770 770
                     continue;
771 771
                 }
772 772
 
773
-                $discounts = $payment->get_discounts( true );
774
-                if ( empty( $discounts ) ) {
773
+                $discounts = $payment->get_discounts(true);
774
+                if (empty($discounts)) {
775 775
                     continue;
776 776
                 }
777 777
 
778
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
778
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
779 779
 
780
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
781
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
782
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
780
+                if (!empty($discounts) && is_array($discounts)) {
781
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
782
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
783 783
                         $return = true;
784 784
                         break;
785 785
                     }
@@ -788,61 +788,61 @@  discard block
 block discarded – undo
788 788
         }
789 789
     }
790 790
 
791
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
791
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
792 792
 }
793 793
 
794
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
794
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
795 795
     $return      = false;
796
-    $discount_id = wpinv_get_discount_id_by_code( $code );
797
-    $user        = trim( $user );
796
+    $discount_id = wpinv_get_discount_id_by_code($code);
797
+    $user        = trim($user);
798 798
 
799
-    if ( wpinv_get_cart_contents() ) {
800
-        if ( $discount_id ) {
799
+    if (wpinv_get_cart_contents()) {
800
+        if ($discount_id) {
801 801
             if (
802
-                wpinv_is_discount_active( $discount_id ) &&
803
-                wpinv_check_discount_dates( $discount_id ) &&
804
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
805
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
806
-                wpinv_discount_is_min_met( $discount_id ) &&
807
-                wpinv_discount_is_max_met( $discount_id ) &&
808
-                wpinv_discount_item_reqs_met( $discount_id )
802
+                wpinv_is_discount_active($discount_id) &&
803
+                wpinv_check_discount_dates($discount_id) &&
804
+                !wpinv_is_discount_maxed_out($discount_id) &&
805
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
806
+                wpinv_discount_is_min_met($discount_id) &&
807
+                wpinv_discount_is_max_met($discount_id) &&
808
+                wpinv_discount_item_reqs_met($discount_id)
809 809
             ) {
810 810
                 $return = true;
811 811
             }
812
-        } elseif( $set_error ) {
813
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
812
+        } elseif ($set_error) {
813
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
814 814
         }
815 815
     }
816 816
 
817
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
817
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
818 818
 }
819 819
 
820
-function wpinv_get_discount_id_by_code( $code ) {
821
-    $discount = wpinv_get_discount_by_code( $code );
822
-    if( $discount ) {
820
+function wpinv_get_discount_id_by_code($code) {
821
+    $discount = wpinv_get_discount_by_code($code);
822
+    if ($discount) {
823 823
         return $discount->ID;
824 824
     }
825 825
     return false;
826 826
 }
827 827
 
828
-function wpinv_get_discounted_amount( $code, $base_price ) {
828
+function wpinv_get_discounted_amount($code, $base_price) {
829 829
     $amount      = $base_price;
830
-    $discount_id = wpinv_get_discount_id_by_code( $code );
830
+    $discount_id = wpinv_get_discount_id_by_code($code);
831 831
 
832
-    if( $discount_id ) {
833
-        $type        = wpinv_get_discount_type( $discount_id );
834
-        $rate        = wpinv_get_discount_amount( $discount_id );
832
+    if ($discount_id) {
833
+        $type        = wpinv_get_discount_type($discount_id);
834
+        $rate        = wpinv_get_discount_amount($discount_id);
835 835
 
836
-        if ( $type == 'flat' ) {
836
+        if ($type == 'flat') {
837 837
             // Set amount
838 838
             $amount = $base_price - $rate;
839
-            if ( $amount < 0 ) {
839
+            if ($amount < 0) {
840 840
                 $amount = 0;
841 841
             }
842 842
 
843 843
         } else {
844 844
             // Percentage discount
845
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
845
+            $amount = $base_price - ($base_price * ($rate / 100));
846 846
         }
847 847
 
848 848
     } else {
@@ -851,108 +851,108 @@  discard block
 block discarded – undo
851 851
 
852 852
     }
853 853
 
854
-    return apply_filters( 'wpinv_discounted_amount', $amount );
854
+    return apply_filters('wpinv_discounted_amount', $amount);
855 855
 }
856 856
 
857
-function wpinv_increase_discount_usage( $code ) {
857
+function wpinv_increase_discount_usage($code) {
858 858
 
859
-    $id   = wpinv_get_discount_id_by_code( $code );
860
-    $uses = wpinv_get_discount_uses( $id );
859
+    $id   = wpinv_get_discount_id_by_code($code);
860
+    $uses = wpinv_get_discount_uses($id);
861 861
 
862
-    if ( $uses ) {
862
+    if ($uses) {
863 863
         $uses++;
864 864
     } else {
865 865
         $uses = 1;
866 866
     }
867 867
 
868
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
868
+    update_post_meta($id, '_wpi_discount_uses', $uses);
869 869
 
870
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
870
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
871 871
 
872 872
     return $uses;
873 873
 
874 874
 }
875 875
 
876
-function wpinv_decrease_discount_usage( $code ) {
876
+function wpinv_decrease_discount_usage($code) {
877 877
 
878
-    $id   = wpinv_get_discount_id_by_code( $code );
879
-    $uses = wpinv_get_discount_uses( $id );
878
+    $id   = wpinv_get_discount_id_by_code($code);
879
+    $uses = wpinv_get_discount_uses($id);
880 880
 
881
-    if ( $uses ) {
881
+    if ($uses) {
882 882
         $uses--;
883 883
     }
884 884
 
885
-    if ( $uses < 0 ) {
885
+    if ($uses < 0) {
886 886
         $uses = 0;
887 887
     }
888 888
 
889
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
889
+    update_post_meta($id, '_wpi_discount_uses', $uses);
890 890
 
891
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
891
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
892 892
 
893 893
     return $uses;
894 894
 
895 895
 }
896 896
 
897
-function wpinv_format_discount_rate( $type, $amount ) {
898
-    if ( $type == 'flat' ) {
899
-        return wpinv_price( wpinv_format_amount( $amount ) );
897
+function wpinv_format_discount_rate($type, $amount) {
898
+    if ($type == 'flat') {
899
+        return wpinv_price(wpinv_format_amount($amount));
900 900
     } else {
901 901
         return $amount . '%';
902 902
     }
903 903
 }
904 904
 
905
-function wpinv_set_cart_discount( $code = '' ) {    
906
-    if ( wpinv_multiple_discounts_allowed() ) {
905
+function wpinv_set_cart_discount($code = '') {    
906
+    if (wpinv_multiple_discounts_allowed()) {
907 907
         // Get all active cart discounts
908 908
         $discounts = wpinv_get_cart_discounts();
909 909
     } else {
910 910
         $discounts = false; // Only one discount allowed per purchase, so override any existing
911 911
     }
912 912
 
913
-    if ( $discounts ) {
914
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
915
-        if( false !== $key ) {
916
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
913
+    if ($discounts) {
914
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
915
+        if (false !== $key) {
916
+            unset($discounts[$key]); // Can't set the same discount more than once
917 917
         }
918 918
         $discounts[] = $code;
919 919
     } else {
920 920
         $discounts = array();
921 921
         $discounts[] = $code;
922 922
     }
923
-    $discounts = array_values( $discounts );
923
+    $discounts = array_values($discounts);
924 924
     
925 925
     $data = wpinv_get_checkout_session();
926
-    if ( empty( $data ) ) {
926
+    if (empty($data)) {
927 927
         $data = array();
928 928
     } else {
929
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
930
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
931
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
929
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
930
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
931
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
932 932
         }
933 933
     }
934 934
     $data['cart_discounts'] = $discounts;
935 935
     
936
-    wpinv_set_checkout_session( $data );
936
+    wpinv_set_checkout_session($data);
937 937
     
938 938
     return $discounts;
939 939
 }
940 940
 
941
-function wpinv_unset_cart_discount( $code = '' ) {    
941
+function wpinv_unset_cart_discount($code = '') {    
942 942
     $discounts = wpinv_get_cart_discounts();
943 943
 
944
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
945
-        $key = array_search( $code, $discounts );
946
-        unset( $discounts[ $key ] );
944
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
945
+        $key = array_search($code, $discounts);
946
+        unset($discounts[$key]);
947 947
             
948 948
         $data = wpinv_get_checkout_session();
949 949
         $data['cart_discounts'] = $discounts;
950
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
951
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
952
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
950
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
951
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
952
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
953 953
         }
954 954
         
955
-        wpinv_set_checkout_session( $data );
955
+        wpinv_set_checkout_session($data);
956 956
     }
957 957
 
958 958
     return $discounts;
@@ -961,27 +961,27 @@  discard block
 block discarded – undo
961 961
 function wpinv_unset_all_cart_discounts() {
962 962
     $data = wpinv_get_checkout_session();
963 963
     
964
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
965
-        unset( $data['cart_discounts'] );
964
+    if (!empty($data) && isset($data['cart_discounts'])) {
965
+        unset($data['cart_discounts']);
966 966
         
967
-         wpinv_set_checkout_session( $data );
967
+         wpinv_set_checkout_session($data);
968 968
          return true;
969 969
     }
970 970
     
971 971
     return false;
972 972
 }
973 973
 
974
-function wpinv_get_cart_discounts( $items = array() ) {
974
+function wpinv_get_cart_discounts($items = array()) {
975 975
     $session = wpinv_get_checkout_session();
976 976
     
977
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
977
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
978 978
     return $discounts;
979 979
 }
980 980
 
981
-function wpinv_cart_has_discounts( $items = array() ) {
981
+function wpinv_cart_has_discounts($items = array()) {
982 982
     $ret = false;
983 983
 
984
-    if ( wpinv_get_cart_discounts( $items ) ) {
984
+    if (wpinv_get_cart_discounts($items)) {
985 985
         $ret = true;
986 986
     }
987 987
     
@@ -992,131 +992,131 @@  discard block
 block discarded – undo
992 992
     }
993 993
     */
994 994
 
995
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
995
+    return apply_filters('wpinv_cart_has_discounts', $ret);
996 996
 }
997 997
 
998
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
998
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
999 999
     $amount = 0.00;
1000
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1000
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
1001 1001
 
1002
-    if ( $items ) {
1003
-        $discounts = wp_list_pluck( $items, 'discount' );
1002
+    if ($items) {
1003
+        $discounts = wp_list_pluck($items, 'discount');
1004 1004
 
1005
-        if ( is_array( $discounts ) ) {
1006
-            $discounts = array_map( 'floatval', $discounts );
1007
-            $amount    = array_sum( $discounts );
1005
+        if (is_array($discounts)) {
1006
+            $discounts = array_map('floatval', $discounts);
1007
+            $amount    = array_sum($discounts);
1008 1008
         }
1009 1009
     }
1010 1010
 
1011
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
1011
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
1012 1012
 }
1013 1013
 
1014
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
1015
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1014
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
1015
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1016 1016
     
1017
-    if ( empty( $discount ) || empty( $items ) ) {
1017
+    if (empty($discount) || empty($items)) {
1018 1018
         return 0;
1019 1019
     }
1020 1020
 
1021 1021
     $amount = 0;
1022 1022
     
1023
-    foreach ( $items as $item ) {
1024
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
1023
+    foreach ($items as $item) {
1024
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
1025 1025
     }
1026 1026
     
1027
-    $amount = wpinv_round_amount( $amount );
1027
+    $amount = wpinv_round_amount($amount);
1028 1028
 
1029 1029
     return $amount;
1030 1030
 }
1031 1031
 
1032
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
1032
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
1033 1033
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
1034 1034
     
1035 1035
     $amount = 0;
1036 1036
 
1037
-    if ( empty( $item ) || empty( $item['id'] ) ) {
1037
+    if (empty($item) || empty($item['id'])) {
1038 1038
         return $amount;
1039 1039
     }
1040 1040
 
1041
-    if ( empty( $item['quantity'] ) ) {
1041
+    if (empty($item['quantity'])) {
1042 1042
         return $amount;
1043 1043
     }
1044 1044
 
1045
-    if ( empty( $item['options'] ) ) {
1045
+    if (empty($item['options'])) {
1046 1046
         $item['options'] = array();
1047 1047
     }
1048 1048
 
1049
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
1049
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
1050 1050
     $discounted_price = $price;
1051 1051
 
1052 1052
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
1053
-    if ( empty( $discounts ) ) {
1053
+    if (empty($discounts)) {
1054 1054
         return $amount;
1055 1055
     }
1056 1056
 
1057
-    if ( $discounts ) {
1058
-        if ( is_array( $discounts ) ) {
1059
-            $discounts = array_values( $discounts );
1057
+    if ($discounts) {
1058
+        if (is_array($discounts)) {
1059
+            $discounts = array_values($discounts);
1060 1060
         } else {
1061
-            $discounts = explode( ',', $discounts );
1061
+            $discounts = explode(',', $discounts);
1062 1062
         }
1063 1063
     }
1064 1064
 
1065
-    if( $discounts ) {
1066
-        foreach ( $discounts as $discount ) {
1067
-            $code_id = wpinv_get_discount_id_by_code( $discount );
1065
+    if ($discounts) {
1066
+        foreach ($discounts as $discount) {
1067
+            $code_id = wpinv_get_discount_id_by_code($discount);
1068 1068
 
1069 1069
             // Check discount exists
1070
-            if( ! $code_id ) {
1070
+            if (!$code_id) {
1071 1071
                 continue;
1072 1072
             }
1073 1073
 
1074
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
1075
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
1074
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
1075
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
1076 1076
 
1077 1077
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1078
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1079
-                foreach ( $reqs as $item_id ) {
1080
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1081
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1078
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1079
+                foreach ($reqs as $item_id) {
1080
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1081
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1082 1082
                     }
1083 1083
                 }
1084 1084
             } else {
1085 1085
                 // This is a global cart discount
1086
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1087
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1086
+                if (!in_array($item['id'], $excluded_items)) {
1087
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1088 1088
                         $items_subtotal    = 0.00;
1089 1089
                         $cart_items        = wpinv_get_cart_contents();
1090 1090
                         
1091
-                        foreach ( $cart_items as $cart_item ) {
1092
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1093
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1094
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1091
+                        foreach ($cart_items as $cart_item) {
1092
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1093
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1094
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1095 1095
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1096 1096
                             }
1097 1097
                         }
1098 1098
 
1099
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1100
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1099
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1100
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1101 1101
                         $discounted_amount = $code_amount * $subtotal_percent;
1102 1102
                         $discounted_price -= $discounted_amount;
1103 1103
 
1104
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1104
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1105 1105
 
1106
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1106
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1107 1107
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1108 1108
                             $discounted_price -= $adjustment;
1109 1109
                         }
1110 1110
                     } else {
1111
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1111
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1112 1112
                     }
1113 1113
                 }
1114 1114
             }
1115 1115
         }
1116 1116
 
1117
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1117
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1118 1118
 
1119
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1119
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1120 1120
             $amount = $amount * $item['quantity'];
1121 1121
         }
1122 1122
     }
@@ -1124,59 +1124,59 @@  discard block
 block discarded – undo
1124 1124
     return $amount;
1125 1125
 }
1126 1126
 
1127
-function wpinv_cart_discounts_html( $items = array() ) {
1128
-    echo wpinv_get_cart_discounts_html( $items );
1127
+function wpinv_cart_discounts_html($items = array()) {
1128
+    echo wpinv_get_cart_discounts_html($items);
1129 1129
 }
1130 1130
 
1131
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1131
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1132 1132
     global $wpi_cart_columns;
1133 1133
     
1134
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1134
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1135 1135
     
1136
-    if ( !$discounts ) {
1137
-        $discounts = wpinv_get_cart_discounts( $items );
1136
+    if (!$discounts) {
1137
+        $discounts = wpinv_get_cart_discounts($items);
1138 1138
     }
1139 1139
 
1140
-    if ( !$discounts ) {
1140
+    if (!$discounts) {
1141 1141
         return;
1142 1142
     }
1143 1143
     
1144
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1144
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1145 1145
     
1146 1146
     $html = '';
1147 1147
 
1148
-    foreach ( $discounts as $discount ) {
1149
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1150
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1151
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1152
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1153
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1148
+    foreach ($discounts as $discount) {
1149
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1150
+        $discount_value = wpinv_get_discount_amount($discount_id);
1151
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1152
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1153
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1154 1154
         
1155 1155
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1156 1156
         ob_start();
1157
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1157
+        do_action('wpinv_checkout_table_discount_first', $items);
1158 1158
         $html .= ob_get_clean();
1159
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1159
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1160 1160
         ob_start();
1161
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1161
+        do_action('wpinv_checkout_table_discount_last', $items);
1162 1162
         $html .= ob_get_clean();
1163 1163
         $html .= '</tr>';
1164 1164
     }
1165 1165
 
1166
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1166
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1169
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1170 1170
     $discounts = wpinv_get_cart_discounts();
1171 1171
 
1172
-    if ( empty( $discounts ) ) {
1172
+    if (empty($discounts)) {
1173 1173
         return false;
1174 1174
     }
1175 1175
 
1176
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1177
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1176
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1177
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1178 1178
 
1179
-    if ( $echo ) {
1179
+    if ($echo) {
1180 1180
         echo $amount;
1181 1181
     }
1182 1182
 
@@ -1184,101 +1184,101 @@  discard block
 block discarded – undo
1184 1184
 }
1185 1185
 
1186 1186
 function wpinv_remove_cart_discount() {
1187
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1187
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1188 1188
         return;
1189 1189
     }
1190 1190
 
1191
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1191
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1192 1192
 
1193
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1193
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1194 1194
 
1195
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1195
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1196 1196
 
1197
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1197
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1198 1198
 }
1199
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1199
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1200 1200
 
1201
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1201
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1202 1202
     $discounts = wpinv_get_cart_discounts();
1203 1203
 
1204
-    if ( !$discounts ) {
1204
+    if (!$discounts) {
1205 1205
         return;
1206 1206
     }
1207 1207
 
1208
-    foreach ( $discounts as $discount ) {
1209
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1210
-            wpinv_unset_cart_discount( $discount );
1208
+    foreach ($discounts as $discount) {
1209
+        if (!wpinv_is_discount_valid($discount)) {
1210
+            wpinv_unset_cart_discount($discount);
1211 1211
         }
1212 1212
     }
1213 1213
 }
1214
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1214
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1215 1215
 
1216 1216
 function wpinv_multiple_discounts_allowed() {
1217
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1218
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1217
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1218
+    return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret);
1219 1219
 }
1220 1220
 
1221
-function wpinv_get_discount_label( $code, $echo = true ) {
1222
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1223
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1221
+function wpinv_get_discount_label($code, $echo = true) {
1222
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1223
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1224 1224
 
1225
-    if ( $echo ) {
1225
+    if ($echo) {
1226 1226
         echo $label;
1227 1227
     } else {
1228 1228
         return $label;
1229 1229
     }
1230 1230
 }
1231 1231
 
1232
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1233
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
1234
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1232
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1233
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
1234
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1235 1235
 
1236
-    if ( $echo ) {
1236
+    if ($echo) {
1237 1237
         echo $label;
1238 1238
     } else {
1239 1239
         return $label;
1240 1240
     }
1241 1241
 }
1242 1242
 
1243
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1244
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1243
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1244
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1245 1245
         return true;
1246 1246
     }
1247 1247
     
1248 1248
     return $check;
1249 1249
 }
1250
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1250
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1251 1251
 
1252 1252
 function wpinv_checkout_form_validate_discounts() {
1253 1253
     global $wpi_checkout_id;
1254 1254
     
1255 1255
     $discounts = wpinv_get_cart_discounts();
1256 1256
     
1257
-    if ( !empty( $discounts ) ) {
1257
+    if (!empty($discounts)) {
1258 1258
         $invalid = false;
1259 1259
         
1260
-        foreach ( $discounts as $key => $code ) {
1261
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1260
+        foreach ($discounts as $key => $code) {
1261
+            if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) {
1262 1262
                 $invalid = true;
1263 1263
                 
1264
-                wpinv_unset_cart_discount( $code );
1264
+                wpinv_unset_cart_discount($code);
1265 1265
             }
1266 1266
         }
1267 1267
         
1268
-        if ( $invalid ) {
1268
+        if ($invalid) {
1269 1269
             $errors = wpinv_get_errors();
1270
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1272
-            wpinv_set_error( 'wpinv-discount-error', $error );
1270
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1272
+            wpinv_set_error('wpinv-discount-error', $error);
1273 1273
             
1274
-            wpinv_recalculate_tax( true );
1274
+            wpinv_recalculate_tax(true);
1275 1275
         }
1276 1276
     }
1277 1277
 }
1278
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1278
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1279 1279
 
1280 1280
 function wpinv_discount_amount() {
1281 1281
     $output = 0.00;
1282 1282
     
1283
-    return apply_filters( 'wpinv_discount_amount', $output );
1283
+    return apply_filters('wpinv_discount_amount', $output);
1284 1284
 }
1285 1285
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 
141 141
 function wpinv_get_default_labels() {
142 142
     $defaults = array(
143
-       'singular' => __( 'Invoice', 'invoicing' ),
144
-       'plural'   => __( 'Invoices', 'invoicing' )
143
+        'singular' => __( 'Invoice', 'invoicing' ),
144
+        'plural'   => __( 'Invoices', 'invoicing' )
145 145
     );
146 146
     
147 147
     return apply_filters( 'wpinv_default_invoices_name', $defaults );
@@ -160,20 +160,20 @@  discard block
 block discarded – undo
160 160
 }
161 161
 
162 162
 function wpinv_change_default_title( $title ) {
163
-     if ( !is_admin() ) {
163
+        if ( !is_admin() ) {
164 164
         $label = wpinv_get_label_singular();
165 165
         $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
166 166
         return $title;
167
-     }
167
+        }
168 168
 
169
-     $screen = get_current_screen();
169
+        $screen = get_current_screen();
170 170
 
171
-     if ( 'wpi_invoice' == $screen->post_type ) {
171
+        if ( 'wpi_invoice' == $screen->post_type ) {
172 172
         $label = wpinv_get_label_singular();
173 173
         $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
174
-     }
174
+        }
175 175
 
176
-     return $title;
176
+        return $title;
177 177
 }
178 178
 add_filter( 'enter_title_here', 'wpinv_change_default_title' );
179 179
 
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -7,38 +7,38 @@  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
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {
16 16
     
17 17
     $labels = array(
18
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
19
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
20
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
21
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
22
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
23
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
24
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
25
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
26
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
27
-        'all_items'          => __( 'Invoices', 'invoicing' ),
28
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
29
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
30
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
31
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
18
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
19
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
20
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
21
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
22
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
23
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
24
+        'new_item'           => __('New Invoice', 'invoicing'),
25
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
26
+        'view_item'          => __('View Invoice', 'invoicing'),
27
+        'all_items'          => __('Invoices', 'invoicing'),
28
+        'search_items'       => __('Search Invoices', 'invoicing'),
29
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
30
+        'not_found'          => __('No invoices found.', 'invoicing'),
31
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
32 32
     );
33
-    $labels = apply_filters( 'wpinv_labels', $labels );
33
+    $labels = apply_filters('wpinv_labels', $labels);
34 34
     
35 35
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
36
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
36
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
37 37
 
38 38
     $cap_type = 'wpi_invoice';
39 39
     $args = array(
40 40
         'labels'             => $labels,
41
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
41
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
42 42
         'public'             => true,
43 43
         'can_export'         => true,
44 44
         '_builtin'           => false,
@@ -71,30 +71,30 @@  discard block
 block discarded – undo
71 71
         'has_archive'        => false,
72 72
         'hierarchical'       => false,
73 73
         'menu_position'      => null,
74
-        'supports'           => array( 'title', 'author' ),
74
+        'supports'           => array('title', 'author'),
75 75
         'menu_icon'          => 'dashicons-media-spreadsheet',
76 76
     );
77 77
             
78
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
78
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
79 79
     
80
-    register_post_type( 'wpi_invoice', $args );
80
+    register_post_type('wpi_invoice', $args);
81 81
     
82 82
     $items_labels = array(
83
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
84
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
85
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
86
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
87
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
88
-        'new_item'           => __( 'New Item', 'invoicing' ),
89
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
90
-        'view_item'          => __( 'View Item', 'invoicing' ),
91
-        'all_items'          => __( 'Items', 'invoicing' ),
92
-        'search_items'       => __( 'Search Items', 'invoicing' ),
83
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
84
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
85
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
86
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
87
+        'add_new_item'       => __('Add New Item', 'invoicing'),
88
+        'new_item'           => __('New Item', 'invoicing'),
89
+        'edit_item'          => __('Edit Item', 'invoicing'),
90
+        'view_item'          => __('View Item', 'invoicing'),
91
+        'all_items'          => __('Items', 'invoicing'),
92
+        'search_items'       => __('Search Items', 'invoicing'),
93 93
         'parent_item_colon'  => '',
94
-        'not_found'          => __( 'No items found.', 'invoicing' ),
95
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
94
+        'not_found'          => __('No items found.', 'invoicing'),
95
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
96 96
     );
97
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
97
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
98 98
 
99 99
     $cap_type = 'wpi_item';
100 100
     $invoice_item_args = array(
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
         'show_ui'               => true,
104 104
         'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
105 105
         'show_in_nav_menus'     => false,
106
-        'supports'              => array( 'title', 'excerpt' ),
106
+        'supports'              => array('title', 'excerpt'),
107 107
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
108 108
         'rewrite'               => false,
109 109
         'query_var'             => false,
@@ -128,33 +128,33 @@  discard block
 block discarded – undo
128 128
         ),
129 129
         'can_export'            => true,
130 130
     );
131
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
131
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
132 132
 
133
-    register_post_type( 'wpi_item', $invoice_item_args );
133
+    register_post_type('wpi_item', $invoice_item_args);
134 134
     
135 135
     $labels = array(
136
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
137
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
138
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
139
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
140
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
141
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
142
-        'new_item'           => __( 'New Discount', 'invoicing' ),
143
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
144
-        'view_item'          => __( 'View Discount', 'invoicing' ),
145
-        'all_items'          => __( 'Discounts', 'invoicing' ),
146
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
147
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
148
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
149
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
136
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
137
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
138
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
139
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
140
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
141
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
142
+        'new_item'           => __('New Discount', 'invoicing'),
143
+        'edit_item'          => __('Edit Discount', 'invoicing'),
144
+        'view_item'          => __('View Discount', 'invoicing'),
145
+        'all_items'          => __('Discounts', 'invoicing'),
146
+        'search_items'       => __('Search Discounts', 'invoicing'),
147
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
148
+        'not_found'          => __('No discounts found.', 'invoicing'),
149
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
150 150
     );
151
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
151
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
152 152
 
153 153
     $cap_type = 'wpi_discount';
154 154
     
155 155
     $args = array(
156 156
         'labels'             => $labels,
157
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
157
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
158 158
         'public'             => false,
159 159
         'can_export'         => true,
160 160
         '_builtin'           => false,
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
         ),
186 186
         'has_archive'        => false,
187 187
         'hierarchical'       => false,
188
-        'supports'           => array( 'title', 'excerpt' ),
188
+        'supports'           => array('title', 'excerpt'),
189 189
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
190 190
         'show_in_nav_menus'  => false,
191 191
         'show_in_admin_bar'  => true,
@@ -193,106 +193,106 @@  discard block
 block discarded – undo
193 193
         'menu_position'      => null,
194 194
     );
195 195
             
196
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
196
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
197 197
     
198
-    register_post_type( 'wpi_discount', $args );
198
+    register_post_type('wpi_discount', $args);
199 199
 }
200 200
 
201 201
 function wpinv_get_default_labels() {
202 202
     $defaults = array(
203
-       'singular' => __( 'Invoice', 'invoicing' ),
204
-       'plural'   => __( 'Invoices', 'invoicing' )
203
+       'singular' => __('Invoice', 'invoicing'),
204
+       'plural'   => __('Invoices', 'invoicing')
205 205
     );
206 206
     
207
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
207
+    return apply_filters('wpinv_default_invoices_name', $defaults);
208 208
 }
209 209
 
210
-function wpinv_get_label_singular( $lowercase = false ) {
210
+function wpinv_get_label_singular($lowercase = false) {
211 211
     $defaults = wpinv_get_default_labels();
212 212
     
213
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
213
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
214 214
 }
215 215
 
216
-function wpinv_get_label_plural( $lowercase = false ) {
216
+function wpinv_get_label_plural($lowercase = false) {
217 217
     $defaults = wpinv_get_default_labels();
218 218
     
219
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
219
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
220 220
 }
221 221
 
222
-function wpinv_change_default_title( $title ) {
223
-     if ( !is_admin() ) {
222
+function wpinv_change_default_title($title) {
223
+     if (!is_admin()) {
224 224
         $label = wpinv_get_label_singular();
225
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
225
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
226 226
         return $title;
227 227
      }
228 228
 
229 229
      $screen = get_current_screen();
230 230
 
231
-     if ( 'wpi_invoice' == $screen->post_type ) {
231
+     if ('wpi_invoice' == $screen->post_type) {
232 232
         $label = wpinv_get_label_singular();
233
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
233
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
234 234
      }
235 235
 
236 236
      return $title;
237 237
 }
238
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
238
+add_filter('enter_title_here', 'wpinv_change_default_title');
239 239
 
240 240
 function wpinv_register_post_status() {
241
-    register_post_status( 'wpi-pending', array(
242
-        'label'                     => _x( 'Pending', 'Invoice status', 'invoicing' ),
241
+    register_post_status('wpi-pending', array(
242
+        'label'                     => _x('Pending', 'Invoice status', 'invoicing'),
243 243
         'public'                    => true,
244 244
         'exclude_from_search'       => true,
245 245
         'show_in_admin_all_list'    => true,
246 246
         'show_in_admin_status_list' => true,
247
-        'label_count'               => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' )
248
-    ) );
249
-    register_post_status( 'wpi-processing', array(
250
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
247
+        'label_count'               => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing')
248
+    ));
249
+    register_post_status('wpi-processing', array(
250
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
251 251
         'public'                    => true,
252 252
         'exclude_from_search'       => true,
253 253
         'show_in_admin_all_list'    => true,
254 254
         'show_in_admin_status_list' => true,
255
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
256
-    ) );
257
-    register_post_status( 'wpi-onhold', array(
258
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
255
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
256
+    ));
257
+    register_post_status('wpi-onhold', array(
258
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
259 259
         'public'                    => true,
260 260
         'exclude_from_search'       => true,
261 261
         'show_in_admin_all_list'    => true,
262 262
         'show_in_admin_status_list' => true,
263
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
264
-    ) );
265
-    register_post_status( 'wpi-cancelled', array(
266
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
263
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
264
+    ));
265
+    register_post_status('wpi-cancelled', array(
266
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
267 267
         'public'                    => true,
268 268
         'exclude_from_search'       => true,
269 269
         'show_in_admin_all_list'    => true,
270 270
         'show_in_admin_status_list' => true,
271
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
272
-    ) );
273
-    register_post_status( 'wpi-refunded', array(
274
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
271
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
272
+    ));
273
+    register_post_status('wpi-refunded', array(
274
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
275 275
         'public'                    => true,
276 276
         'exclude_from_search'       => true,
277 277
         'show_in_admin_all_list'    => true,
278 278
         'show_in_admin_status_list' => true,
279
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
280
-    ) );
281
-    register_post_status( 'wpi-failed', array(
282
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
279
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
280
+    ));
281
+    register_post_status('wpi-failed', array(
282
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
283 283
         'public'                    => true,
284 284
         'exclude_from_search'       => true,
285 285
         'show_in_admin_all_list'    => true,
286 286
         'show_in_admin_status_list' => true,
287
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
288
-    ) );
289
-    register_post_status( 'wpi-renewal', array(
290
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
287
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
288
+    ));
289
+    register_post_status('wpi-renewal', array(
290
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
291 291
         'public'                    => true,
292 292
         'exclude_from_search'       => true,
293 293
         'show_in_admin_all_list'    => true,
294 294
         'show_in_admin_status_list' => true,
295
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
296
-    ) );
295
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
296
+    ));
297 297
 }
298
-add_action( 'init', 'wpinv_register_post_status', 10 );
298
+add_action('init', 'wpinv_register_post_status', 10);
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 2 patches
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -166,13 +166,13 @@
 block discarded – undo
166 166
             $is_writeable   = $is_dir && is_writeable( $this->export_dir );
167 167
             
168 168
             if ( $is_dir && $is_writeable ) {
169
-               return true;
169
+                return true;
170 170
             } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
173
-               }
171
+                if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
+                    return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
173
+                }
174 174
                
175
-               return true;
175
+                return true;
176 176
             } else {
177 177
                 if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178 178
                     return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
Please login to merge, or discard this patch.
Spacing   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,166 +21,166 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
         
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
         
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
     
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
     
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81
-            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>">
81
+            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
89 89
     }
90 90
     
91 91
     public function export() {
92
-        $statuses = wpinv_get_invoice_statuses( true );
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
92
+        $statuses = wpinv_get_invoice_statuses(true);
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => 'wpi_select2',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,127 +188,127 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201
-        $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
201
+        $_REQUEST = (array) $data;
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array();
258 258
         
259
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
259
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
260 260
     }
261 261
     
262 262
     protected function get_export_file() {
263 263
         $file = '';
264 264
 
265
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
266
-            $file = $this->wp_filesystem->get_contents( $this->file );
265
+        if ($this->wp_filesystem->exists($this->file)) {
266
+            $file = $this->wp_filesystem->get_contents($this->file);
267 267
         } else {
268
-            $this->wp_filesystem->put_contents( $this->file, '' );
268
+            $this->wp_filesystem->put_contents($this->file, '');
269 269
         }
270 270
 
271 271
         return $file;
272 272
     }
273 273
     
274
-    protected function attach_export_data( $data = '' ) {
275
-        $filedata   = $this->get_export_file();
276
-        $filedata   .= $data;
274
+    protected function attach_export_data($data = '') {
275
+        $filedata = $this->get_export_file();
276
+        $filedata .= $data;
277 277
         
278
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
278
+        $this->wp_filesystem->put_contents($this->file, $filedata);
279 279
 
280
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
280
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
281 281
         $columns    = $this->get_columns();
282
-        $columns    = empty( $columns ) ? 0 : 1;
282
+        $columns    = empty($columns) ? 0 : 1;
283 283
 
284
-        $this->empty = count( $rows ) == $columns ? true : false;
284
+        $this->empty = count($rows) == $columns ? true : false;
285 285
     }
286 286
     
287 287
     public function print_columns() {
288 288
         $column_data    = '';
289 289
         $columns        = $this->get_columns();
290 290
         $i              = 1;
291
-        foreach( $columns as $key => $column ) {
292
-            $column_data .= '"' . addslashes( $column ) . '"';
293
-            $column_data .= $i == count( $columns ) ? '' : ',';
291
+        foreach ($columns as $key => $column) {
292
+            $column_data .= '"' . addslashes($column) . '"';
293
+            $column_data .= $i == count($columns) ? '' : ',';
294 294
             $i++;
295 295
         }
296 296
         $column_data .= "\r\n";
297 297
 
298
-        $this->attach_export_data( $column_data );
298
+        $this->attach_export_data($column_data);
299 299
 
300 300
         return $column_data;
301 301
     }
302 302
     
303 303
     public function process_export_step() {
304
-        if ( $this->step < 2 ) {
305
-            /** @scrutinizer ignore-unhandled */ @unlink( $this->file );
304
+        if ($this->step < 2) {
305
+            /** @scrutinizer ignore-unhandled */ @unlink($this->file);
306 306
             $this->print_columns();
307 307
         }
308 308
         
309 309
         $return = $this->print_rows();
310 310
         
311
-        if ( $return ) {
311
+        if ($return) {
312 312
             return true;
313 313
         } else {
314 314
             return false;
@@ -317,14 +317,14 @@  discard block
 block discarded – undo
317 317
     
318 318
     public function get_export_status() {
319 319
         $status = 100;
320
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
320
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
321 321
     }
322 322
     
323 323
     public function get_export_data() {
324 324
         $data = array();
325 325
 
326
-        $data = apply_filters( 'wpinv_export_get_data', $data );
327
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
326
+        $data = apply_filters('wpinv_export_get_data', $data);
327
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
328 328
 
329 329
         return $data;
330 330
     }
@@ -334,20 +334,20 @@  discard block
 block discarded – undo
334 334
         $data       = $this->get_export_data();
335 335
         $columns    = $this->get_columns();
336 336
 
337
-        if ( $data ) {
338
-            foreach ( $data as $row ) {
337
+        if ($data) {
338
+            foreach ($data as $row) {
339 339
                 $i = 1;
340
-                foreach ( $row as $key => $column ) {
341
-                    if ( array_key_exists( $key, $columns ) ) {
342
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
343
-                        $row_data .= $i == count( $columns ) ? '' : ',';
340
+                foreach ($row as $key => $column) {
341
+                    if (array_key_exists($key, $columns)) {
342
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
343
+                        $row_data .= $i == count($columns) ? '' : ',';
344 344
                         $i++;
345 345
                     }
346 346
                 }
347 347
                 $row_data .= "\r\n";
348 348
             }
349 349
 
350
-            $this->attach_export_data( $row_data );
350
+            $this->attach_export_data($row_data);
351 351
 
352 352
             return $row_data;
353 353
         }
@@ -356,48 +356,48 @@  discard block
 block discarded – undo
356 356
     }
357 357
     
358 358
     // Export Invoices.
359
-    public function set_invoices_export( $request ) {
360
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
361
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
362
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
359
+    public function set_invoices_export($request) {
360
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
361
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
362
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
363 363
     }
364 364
     
365
-    public function get_invoices_columns( $columns = array() ) {
365
+    public function get_invoices_columns($columns = array()) {
366 366
         $columns = array(
367
-            'id'            => __( 'ID',   'invoicing' ),
368
-            'number'        => __( 'Number',   'invoicing' ),
369
-            'date'          => __( 'Date', 'invoicing' ),
370
-            'due_date'      => __( 'Due Date', 'invoicing' ),
371
-            'completed_date'=> __( 'Payment Done Date', 'invoicing' ),
372
-            'amount'        => __( 'Amount', 'invoicing' ),
373
-            'currency'      => __( 'Currency', 'invoicing' ),
374
-            'items'        => __( 'Items', 'invoicing' ),
375
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
376
-            'status'        => __( 'Status', 'invoicing' ),
377
-            'tax'           => __( 'Tax', 'invoicing' ),
378
-            'discount'      => __( 'Discount', 'invoicing' ),
379
-            'user_id'       => __( 'User ID', 'invoicing' ),
380
-            'email'         => __( 'Email', 'invoicing' ),
381
-            'first_name'    => __( 'First Name', 'invoicing' ),
382
-            'last_name'     => __( 'Last Name', 'invoicing' ),
383
-            'address'       => __( 'Address', 'invoicing' ),
384
-            'city'          => __( 'City', 'invoicing' ),
385
-            'state'         => __( 'State', 'invoicing' ),
386
-            'country'       => __( 'Country', 'invoicing' ),
387
-            'zip'           => __( 'Zipcode', 'invoicing' ),
388
-            'phone'         => __( 'Phone', 'invoicing' ),
389
-            'company'       => __( 'Company', 'invoicing' ),
390
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
391
-            'ip'            => __( 'IP', 'invoicing' ),
392
-            'gateway'       => __( 'Gateway', 'invoicing' ),
393
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
394
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
367
+            'id'            => __('ID', 'invoicing'),
368
+            'number'        => __('Number', 'invoicing'),
369
+            'date'          => __('Date', 'invoicing'),
370
+            'due_date'      => __('Due Date', 'invoicing'),
371
+            'completed_date'=> __('Payment Done Date', 'invoicing'),
372
+            'amount'        => __('Amount', 'invoicing'),
373
+            'currency'      => __('Currency', 'invoicing'),
374
+            'items'        => __('Items', 'invoicing'),
375
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
376
+            'status'        => __('Status', 'invoicing'),
377
+            'tax'           => __('Tax', 'invoicing'),
378
+            'discount'      => __('Discount', 'invoicing'),
379
+            'user_id'       => __('User ID', 'invoicing'),
380
+            'email'         => __('Email', 'invoicing'),
381
+            'first_name'    => __('First Name', 'invoicing'),
382
+            'last_name'     => __('Last Name', 'invoicing'),
383
+            'address'       => __('Address', 'invoicing'),
384
+            'city'          => __('City', 'invoicing'),
385
+            'state'         => __('State', 'invoicing'),
386
+            'country'       => __('Country', 'invoicing'),
387
+            'zip'           => __('Zipcode', 'invoicing'),
388
+            'phone'         => __('Phone', 'invoicing'),
389
+            'company'       => __('Company', 'invoicing'),
390
+            'vat_number'    => __('Vat Number', 'invoicing'),
391
+            'ip'            => __('IP', 'invoicing'),
392
+            'gateway'       => __('Gateway', 'invoicing'),
393
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
394
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
395 395
         );
396 396
 
397 397
         return $columns;
398 398
     }
399 399
         
400
-    public function get_invoices_data( $response = array() ) {
400
+    public function get_invoices_data($response = array()) {
401 401
         $args = array(
402 402
             'limit'    => $this->per_page,
403 403
             'page'     => $this->step,
@@ -405,42 +405,42 @@  discard block
 block discarded – undo
405 405
             'orderby'  => 'date',
406 406
         );
407 407
         
408
-        if ( $this->status != 'any' ) {
408
+        if ($this->status != 'any') {
409 409
             $args['status'] = $this->status;
410 410
         } else {
411
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
411
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
412 412
         }
413 413
 
414
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
414
+        if (!empty($this->from_date) || !empty($this->to_date)) {
415 415
             $args['date_query'] = array(
416 416
                 array(
417
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
418
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
417
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
418
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
419 419
                     'inclusive' => true
420 420
                 )
421 421
             );
422 422
         }
423 423
 
424
-        $invoices = wpinv_get_invoices( $args );
424
+        $invoices = wpinv_get_invoices($args);
425 425
         
426 426
         $data = array();
427 427
         
428
-        if ( !empty( $invoices ) ) {
429
-            foreach ( $invoices as $invoice ) {
428
+        if (!empty($invoices)) {
429
+            foreach ($invoices as $invoice) {
430 430
                 $items = $this->get_invoice_items($invoice);
431 431
                 $row = array(
432 432
                     'id'            => $invoice->ID,
433 433
                     'number'        => $invoice->get_number(),
434
-                    'date'          => $invoice->get_invoice_date( false ),
435
-                    'due_date'      => $invoice->get_due_date( false ),
434
+                    'date'          => $invoice->get_invoice_date(false),
435
+                    'due_date'      => $invoice->get_due_date(false),
436 436
                     'completed_date'=> $invoice->get_completed_date(),
437
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
437
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
438 438
                     'currency'      => $invoice->get_currency(),
439 439
                     'items'         => $items,
440
-                    'status_nicename' => $invoice->get_status( true ),
440
+                    'status_nicename' => $invoice->get_status(true),
441 441
                     'status'        => $invoice->get_status(),
442
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
443
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
442
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
443
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
444 444
                     'user_id'       => $invoice->get_user_id(),
445 445
                     'email'         => $invoice->get_email(),
446 446
                     'first_name'    => $invoice->get_first_name(),
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
                     'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '',
460 460
                 );
461 461
                 
462
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
462
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
463 463
             }
464 464
 
465 465
             return $data;
@@ -475,44 +475,44 @@  discard block
 block discarded – undo
475 475
             'return'   => 'ids',
476 476
         );
477 477
         
478
-        if ( $this->status != 'any' ) {
478
+        if ($this->status != 'any') {
479 479
             $args['status'] = $this->status;
480 480
         } else {
481
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
481
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
482 482
         }
483 483
 
484
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
484
+        if (!empty($this->from_date) || !empty($this->to_date)) {
485 485
             $args['date_query'] = array(
486 486
                 array(
487
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
488
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
487
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
488
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
489 489
                     'inclusive' => true
490 490
                 )
491 491
             );
492 492
         }
493 493
 
494
-        $invoices   = wpinv_get_invoices( $args );
495
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
494
+        $invoices   = wpinv_get_invoices($args);
495
+        $total      = !empty($invoices) ? count($invoices) : 0;
496 496
         $status     = 100;
497 497
 
498
-        if ( $total > 0 ) {
499
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
498
+        if ($total > 0) {
499
+            $status = (($this->per_page * $this->step) / $total) * 100;
500 500
         }
501 501
 
502
-        if ( $status > 100 ) {
502
+        if ($status > 100) {
503 503
             $status = 100;
504 504
         }
505 505
 
506 506
         return $status;
507 507
     }
508 508
 
509
-    public function get_invoice_items($invoice){
510
-        if(!$invoice){
509
+    public function get_invoice_items($invoice) {
510
+        if (!$invoice) {
511 511
             return '';
512 512
         }
513 513
 
514 514
         $cart_details = $invoice->get_cart_details();
515
-        if(!empty($cart_details)){
515
+        if (!empty($cart_details)) {
516 516
             $cart_details = maybe_serialize($cart_details);
517 517
         } else {
518 518
             $cart_details = '';
Please login to merge, or discard this patch.