Passed
Push — master ( 5bb76a...9b8253 )
by Brian
09:28 queued 05:23
created
includes/class-wpinv-bp-core.php 1 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 $invoice->get_status_label_html() ; ?>
118
+                                        <?php elseif ('invoice-status' === $column_id) : ?>
119
+                                            <?php echo $invoice->get_status_label_html(); ?>
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/data-stores/class-getpaid-data.php 1 patch
Spacing   +161 added lines, -161 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * If the object no longer exists, remove the ID.
138 138
 	 */
139 139
 	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
140
+		$this->__construct(absint($this->id));
141 141
 
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
142
+		if (!empty($this->last_error)) {
143
+			$this->set_id(0);
144 144
 		}
145 145
 
146 146
 	}
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store && $this->get_id() ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store && $this->get_id()) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 326
 	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
327
+	protected function is_internal_meta_key($key) {
328
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
329 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 340
 		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
341
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key") ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 363
 			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 382
 				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 409
 		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
410
+		$_key = str_replace('_wpinv', '', $key);
411
+		$_key = str_replace('wpinv', '', $_key);
412
+		if ($this->is_internal_meta_key($_key)) {
413 413
 			$function = 'get_' . $_key;
414 414
 
415
-			if ( is_callable( array( $this, $function ) ) ) {
415
+			if (is_callable(array($this, $function))) {
416 416
 				return $this->{$function}();
417 417
 			}
418 418
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 		// Read the meta data if not yet read.
421 421
 		$this->maybe_read_meta_data();
422 422
 		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
423
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
424 424
 		$value      = $single ? '' : array();
425 425
 
426
-		if ( ! empty( $array_keys ) ) {
426
+		if (!empty($array_keys)) {
427 427
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
428
+			if ($single) {
429
+				$value = $meta_data[current($array_keys)]->value;
430 430
 			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
431
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+		if ('view' === $context) {
436
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
437 437
 		}
438 438
 
439 439
 		return $value;
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $key Meta Key.
447 447
 	 * @return boolean
448 448
 	 */
449
-	public function meta_exists( $key = '' ) {
449
+	public function meta_exists($key = '') {
450 450
 		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
451
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
452
+		return in_array($key, $array_keys, true);
453 453
 	}
454 454
 
455 455
 	/**
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 	 * @since 1.0.19
459 459
 	 * @param array $data Key/Value pairs.
460 460
 	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
+	public function set_meta_data($data) {
462
+		if (!empty($data) && is_array($data)) {
463 463
 			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
464
+			foreach ($data as $meta) {
465 465
 				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
466
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
467 467
 					$this->meta_data[] = new GetPaid_Meta_Data(
468 468
 						array(
469 469
 							'id'    => $meta['id'],
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param string|array $value Meta value.
486 486
 	 * @param bool         $unique Should this be a unique key?.
487 487
 	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
488
+	public function add_meta_data($key, $value, $unique = false) {
489
+		if ($this->is_internal_meta_key($key)) {
490 490
 			$function = 'set_' . $key;
491 491
 
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
492
+			if (is_callable(array($this, $function))) {
493
+				return $this->{$function}($value);
494 494
 			}
495 495
 		}
496 496
 
497 497
 		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
498
+		if ($unique) {
499
+			$this->delete_meta_data($key);
500 500
 		}
501 501
 		$this->meta_data[] = new GetPaid_Meta_Data(
502 502
 			array(
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
 	 * @param  string|array $value Meta value.
516 516
 	 * @param  int          $meta_id Meta ID.
517 517
 	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
518
+	public function update_meta_data($key, $value, $meta_id = 0) {
519
+		if ($this->is_internal_meta_key($key)) {
520 520
 			$function = 'set_' . $key;
521 521
 
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
522
+			if (is_callable(array($this, $function))) {
523
+				return $this->{$function}($value);
524 524
 			}
525 525
 		}
526 526
 
@@ -528,33 +528,33 @@  discard block
 block discarded – undo
528 528
 
529 529
 		$array_key = false;
530 530
 
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
531
+		if ($meta_id) {
532
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
533
+			$array_key  = $array_keys ? current($array_keys) : false;
534 534
 		} else {
535 535
 			// Find matches by key.
536 536
 			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
537
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
538
+				if ($meta->key === $key) {
539 539
 					$matches[] = $meta_data_array_key;
540 540
 				}
541 541
 			}
542 542
 
543
-			if ( ! empty( $matches ) ) {
543
+			if (!empty($matches)) {
544 544
 				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
545
+				foreach ($matches as $meta_data_array_key) {
546
+					$this->meta_data[$meta_data_array_key]->value = null;
547 547
 				}
548
-				$array_key = current( $matches );
548
+				$array_key = current($matches);
549 549
 			}
550 550
 		}
551 551
 
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
552
+		if (false !== $array_key) {
553
+			$meta        = $this->meta_data[$array_key];
554 554
 			$meta->key   = $key;
555 555
 			$meta->value = $value;
556 556
 		} else {
557
-			$this->add_meta_data( $key, $value, true );
557
+			$this->add_meta_data($key, $value, true);
558 558
 		}
559 559
 	}
560 560
 
@@ -564,13 +564,13 @@  discard block
 block discarded – undo
564 564
 	 * @since 1.0.19
565 565
 	 * @param string $key Meta key.
566 566
 	 */
567
-	public function delete_meta_data( $key ) {
567
+	public function delete_meta_data($key) {
568 568
 		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
569
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
570 570
 
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
571
+		if ($array_keys) {
572
+			foreach ($array_keys as $array_key) {
573
+				$this->meta_data[$array_key]->value = null;
574 574
 			}
575 575
 		}
576 576
 	}
@@ -581,13 +581,13 @@  discard block
 block discarded – undo
581 581
 	 * @since 1.0.19
582 582
 	 * @param int $mid Meta ID.
583 583
 	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
584
+	public function delete_meta_data_by_mid($mid) {
585 585
 		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
586
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
587 587
 
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
588
+		if ($array_keys) {
589
+			foreach ($array_keys as $array_key) {
590
+				$this->meta_data[$array_key]->value = null;
591 591
 			}
592 592
 		}
593 593
 	}
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 * @since 1.0.19
599 599
 	 */
600 600
 	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
601
+		if (is_null($this->meta_data)) {
602 602
 			$this->read_meta_data();
603 603
 		}
604 604
 	}
@@ -610,42 +610,42 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param bool $force_read True to force a new DB read (and update cache).
612 612
 	 */
613
-	public function read_meta_data( $force_read = false ) {
613
+	public function read_meta_data($force_read = false) {
614 614
 
615 615
 		// Reset meta data.
616 616
 		$this->meta_data = array();
617 617
 
618 618
 		// Maybe abort early.
619
-		if ( ! $this->get_id() || ! $this->data_store ) {
619
+		if (!$this->get_id() || !$this->data_store) {
620 620
 			return;
621 621
 		}
622 622
 
623 623
 		// Only read from cache if the cache key is set.
624 624
 		$cache_key = null;
625
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
626
-			$cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
625
+		if (!$force_read && !empty($this->cache_group)) {
626
+			$cache_key     = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
627
+			$raw_meta_data = wp_cache_get($cache_key, $this->cache_group);
628 628
 		}
629 629
 
630 630
 		// Should we force read?
631
-		if ( empty( $raw_meta_data ) ) {
632
-			$raw_meta_data = $this->data_store->read_meta( $this );
631
+		if (empty($raw_meta_data)) {
632
+			$raw_meta_data = $this->data_store->read_meta($this);
633 633
 
634
-			if ( ! empty( $cache_key ) ) {
635
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
634
+			if (!empty($cache_key)) {
635
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
636 636
 			}
637 637
 
638 638
 		}
639 639
 
640 640
 		// Set meta data.
641
-		if ( is_array( $raw_meta_data ) ) {
641
+		if (is_array($raw_meta_data)) {
642 642
 
643
-			foreach ( $raw_meta_data as $meta ) {
643
+			foreach ($raw_meta_data as $meta) {
644 644
 				$this->meta_data[] = new GetPaid_Meta_Data(
645 645
 					array(
646 646
 						'id'    => (int) $meta->meta_id,
647 647
 						'key'   => $meta->meta_key,
648
-						'value' => maybe_unserialize( $meta->meta_value ),
648
+						'value' => maybe_unserialize($meta->meta_value),
649 649
 					)
650 650
 				);
651 651
 			}
@@ -660,28 +660,28 @@  discard block
 block discarded – undo
660 660
 	 * @since 1.0.19
661 661
 	 */
662 662
 	public function save_meta_data() {
663
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
663
+		if (!$this->data_store || is_null($this->meta_data)) {
664 664
 			return;
665 665
 		}
666
-		foreach ( $this->meta_data as $array_key => $meta ) {
667
-			if ( is_null( $meta->value ) ) {
668
-				if ( ! empty( $meta->id ) ) {
669
-					$this->data_store->delete_meta( $this, $meta );
670
-					unset( $this->meta_data[ $array_key ] );
666
+		foreach ($this->meta_data as $array_key => $meta) {
667
+			if (is_null($meta->value)) {
668
+				if (!empty($meta->id)) {
669
+					$this->data_store->delete_meta($this, $meta);
670
+					unset($this->meta_data[$array_key]);
671 671
 				}
672
-			} elseif ( empty( $meta->id ) ) {
673
-				$meta->id = $this->data_store->add_meta( $this, $meta );
672
+			} elseif (empty($meta->id)) {
673
+				$meta->id = $this->data_store->add_meta($this, $meta);
674 674
 				$meta->apply_changes();
675 675
 			} else {
676
-				if ( $meta->get_changes() ) {
677
-					$this->data_store->update_meta( $this, $meta );
676
+				if ($meta->get_changes()) {
677
+					$this->data_store->update_meta($this, $meta);
678 678
 					$meta->apply_changes();
679 679
 				}
680 680
 			}
681 681
 		}
682
-		if ( ! empty( $this->cache_group ) ) {
683
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
684
-			wp_cache_delete( $cache_key, $this->cache_group );
682
+		if (!empty($this->cache_group)) {
683
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
684
+			wp_cache_delete($cache_key, $this->cache_group);
685 685
 		}
686 686
 	}
687 687
 
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 	 * @since 1.0.19
692 692
 	 * @param int $id ID.
693 693
 	 */
694
-	public function set_id( $id ) {
695
-		$this->id = absint( $id );
694
+	public function set_id($id) {
695
+		$this->id = absint($id);
696 696
 	}
697 697
 
698 698
 	/**
@@ -702,10 +702,10 @@  discard block
 block discarded – undo
702 702
 	 * @param string $status New status.
703 703
 	 * @return array details of change.
704 704
 	 */
705
-	public function set_status( $status ) {
705
+	public function set_status($status) {
706 706
         $old_status = $this->get_status();
707 707
 
708
-		$this->set_prop( 'status', $status );
708
+		$this->set_prop('status', $status);
709 709
 
710 710
 		return array(
711 711
 			'from' => $old_status,
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	public function set_defaults() {
722 722
 		$this->data    = $this->default_data;
723 723
 		$this->changes = array();
724
-		$this->set_object_read( false );
724
+		$this->set_object_read(false);
725 725
 	}
726 726
 
727 727
 	/**
@@ -730,7 +730,7 @@  discard block
 block discarded – undo
730 730
 	 * @since 1.0.19
731 731
 	 * @param boolean $read Should read?.
732 732
 	 */
733
-	public function set_object_read( $read = true ) {
733
+	public function set_object_read($read = true) {
734 734
 		$this->object_read = (bool) $read;
735 735
 	}
736 736
 
@@ -755,32 +755,32 @@  discard block
 block discarded – undo
755 755
 	 *
756 756
 	 * @return bool|WP_Error
757 757
 	 */
758
-	public function set_props( $props, $context = 'set' ) {
758
+	public function set_props($props, $context = 'set') {
759 759
 		$errors = false;
760 760
 
761
-		foreach ( $props as $prop => $value ) {
761
+		foreach ($props as $prop => $value) {
762 762
 			try {
763 763
 				/**
764 764
 				 * Checks if the prop being set is allowed, and the value is not null.
765 765
 				 */
766
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
766
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
767 767
 					continue;
768 768
 				}
769 769
 				$setter = "set_$prop";
770 770
 
771
-				if ( is_callable( array( $this, $setter ) ) ) {
772
-					$this->{$setter}( $value );
771
+				if (is_callable(array($this, $setter))) {
772
+					$this->{$setter}($value);
773 773
 				}
774
-			} catch ( Exception $e ) {
775
-				if ( ! $errors ) {
774
+			} catch (Exception $e) {
775
+				if (!$errors) {
776 776
 					$errors = new WP_Error();
777 777
 				}
778
-				$errors->add( $e->getCode(), $e->getMessage() );
778
+				$errors->add($e->getCode(), $e->getMessage());
779 779
 				$this->last_error = $e->getMessage();
780 780
 			}
781 781
 		}
782 782
 
783
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
783
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
784 784
 	}
785 785
 
786 786
 	/**
@@ -793,14 +793,14 @@  discard block
 block discarded – undo
793 793
 	 * @param string $prop Name of prop to set.
794 794
 	 * @param mixed  $value Value of the prop.
795 795
 	 */
796
-	protected function set_prop( $prop, $value ) {
797
-		if ( array_key_exists( $prop, $this->data ) ) {
798
-			if ( true === $this->object_read ) {
799
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
800
-					$this->changes[ $prop ] = $value;
796
+	protected function set_prop($prop, $value) {
797
+		if (array_key_exists($prop, $this->data)) {
798
+			if (true === $this->object_read) {
799
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
800
+					$this->changes[$prop] = $value;
801 801
 				}
802 802
 			} else {
803
-				$this->data[ $prop ] = $value;
803
+				$this->data[$prop] = $value;
804 804
 			}
805 805
 		}
806 806
 	}
@@ -821,7 +821,7 @@  discard block
 block discarded – undo
821 821
 	 * @since 1.0.19
822 822
 	 */
823 823
 	public function apply_changes() {
824
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
824
+		$this->data    = array_replace_recursive($this->data, $this->changes);
825 825
 		$this->changes = array();
826 826
 	}
827 827
 
@@ -846,14 +846,14 @@  discard block
 block discarded – undo
846 846
 	 * @param  string $context What the value is for. Valid values are view and edit.
847 847
 	 * @return mixed
848 848
 	 */
849
-	protected function get_prop( $prop, $context = 'view' ) {
849
+	protected function get_prop($prop, $context = 'view') {
850 850
 		$value = null;
851 851
 
852
-		if ( array_key_exists( $prop, $this->data ) ) {
853
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
852
+		if (array_key_exists($prop, $this->data)) {
853
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
854 854
 
855
-			if ( 'view' === $context ) {
856
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
855
+			if ('view' === $context) {
856
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
857 857
 			}
858 858
 		}
859 859
 
@@ -867,13 +867,13 @@  discard block
 block discarded – undo
867 867
 	 * @param string         $prop Name of prop to set.
868 868
 	 * @param string|integer $value Value of the prop.
869 869
 	 */
870
-	protected function set_date_prop( $prop, $value ) {
870
+	protected function set_date_prop($prop, $value) {
871 871
 
872
-		if ( empty( $value ) ) {
873
-			$this->set_prop( $prop, null );
872
+		if (empty($value)) {
873
+			$this->set_prop($prop, null);
874 874
 			return;
875 875
 		}
876
-		$this->set_prop( $prop, $value );
876
+		$this->set_prop($prop, $value);
877 877
 
878 878
 	}
879 879
 
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @param string $code             Error code.
885 885
 	 * @param string $message          Error message.
886 886
 	 */
887
-	protected function error( $code, $message ) {
887
+	protected function error($code, $message) {
888 888
 		$this->last_error = $message;
889 889
 	}
890 890
 
@@ -896,7 +896,7 @@  discard block
 block discarded – undo
896 896
 	 */
897 897
 	public function exists() {
898 898
 		$id = $this->get_id();
899
-		return ! empty( $id );
899
+		return !empty($id);
900 900
 	}
901 901
 
902 902
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Subscription_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -50,29 +50,29 @@  discard block
 block discarded – undo
50 50
 	 *
51 51
 	 * @param WPInv_Subscription $subscription Subscription object.
52 52
 	 */
53
-	public function create( &$subscription ) {
53
+	public function create(&$subscription) {
54 54
 		global $wpdb;
55 55
 
56 56
 		$values  = array();
57 57
 		$formats = array();
58 58
 
59 59
 		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
60
+		unset($fields['id']);
61 61
 
62
-		foreach ( $fields as $key => $format ) {
62
+		foreach ($fields as $key => $format) {
63 63
 			$method       = "get_$key";
64
-			$values[$key] = $subscription->$method( 'edit' );
64
+			$values[$key] = $subscription->$method('edit');
65 65
 			$formats[]    = $format;
66 66
 		}
67 67
 
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats );
68
+		$result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats);
69 69
 
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
70
+		if ($result) {
71
+			$subscription->set_id($wpdb->insert_id);
72 72
 			$subscription->apply_changes();
73 73
 			$subscription->clear_cache();
74
-			update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() );
75
-			do_action( 'getpaid_new_subscription', $subscription );
74
+			update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id());
75
+			do_action('getpaid_new_subscription', $subscription);
76 76
 			return true;
77 77
 		}
78 78
 
@@ -85,22 +85,22 @@  discard block
 block discarded – undo
85 85
 	 * @param WPInv_Subscription $subscription Subscription object.
86 86
 	 *
87 87
 	 */
88
-	public function read( &$subscription ) {
88
+	public function read(&$subscription) {
89 89
 		global $wpdb;
90 90
 
91 91
 		$subscription->set_defaults();
92 92
 
93
-		if ( ! $subscription->get_id() ) {
94
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
95
-			$subscription->set_id( 0 );
93
+		if (!$subscription->get_id()) {
94
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
95
+			$subscription->set_id(0);
96 96
 			return false;
97 97
 		}
98 98
 
99 99
 		// Maybe retrieve from the cache.
100
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+		$raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions');
101 101
 
102 102
 		// If not found, retrieve from the db.
103
-		if ( false === $raw_subscription ) {
103
+		if (false === $raw_subscription) {
104 104
 
105 105
 			$raw_subscription = $wpdb->get_row(
106 106
 				$wpdb->prepare(
@@ -110,22 +110,22 @@  discard block
 block discarded – undo
110 110
 			);
111 111
 
112 112
 			// Update the cache with our data
113
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+			wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions');
114 114
 
115 115
 		}
116 116
 
117
-		if ( ! $raw_subscription ) {
118
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
117
+		if (!$raw_subscription) {
118
+			$subscription->last_error = __('Invalid subscription ID.', 'invoicing');
119 119
 			return false;
120 120
 		}
121 121
 
122
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
123
-			$method     = "set_$key";
124
-			$subscription->$method( $raw_subscription->$key );
122
+		foreach (array_keys($this->database_fields_to_data_type) as $key) {
123
+			$method = "set_$key";
124
+			$subscription->$method($raw_subscription->$key);
125 125
 		}
126 126
 
127
-		$subscription->set_object_read( true );
128
-		do_action( 'getpaid_read_subscription', $subscription );
127
+		$subscription->set_object_read(true);
128
+		do_action('getpaid_read_subscription', $subscription);
129 129
 
130 130
 	}
131 131
 
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @param WPInv_Subscription $subscription Subscription object.
136 136
 	 */
137
-	public function update( &$subscription ) {
137
+	public function update(&$subscription) {
138 138
 		global $wpdb;
139 139
 
140 140
 		$changes = $subscription->get_changes();
141 141
 		$values  = array();
142 142
 		$format  = array();
143 143
 
144
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
145
-			if ( array_key_exists( $key, $changes ) ) {
144
+		foreach ($this->database_fields_to_data_type as $key => $format) {
145
+			if (array_key_exists($key, $changes)) {
146 146
 				$method       = "get_$key";
147
-				$values[$key] = $subscription->$method( 'edit' );
147
+				$values[$key] = $subscription->$method('edit');
148 148
 				$formats[]    = $format;
149 149
 			}
150 150
 		}
151 151
 
152
-		if ( empty( $values ) ) {
152
+		if (empty($values)) {
153 153
 			return;
154 154
 		}
155 155
 
@@ -169,10 +169,10 @@  discard block
 block discarded – undo
169 169
 		// Delete cache.
170 170
 		$subscription->clear_cache();
171 171
 
172
-		update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() );
172
+		update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id());
173 173
 
174 174
 		// Fire a hook.
175
-		do_action( 'getpaid_update_subscription', $subscription );
175
+		do_action('getpaid_update_subscription', $subscription);
176 176
 
177 177
 	}
178 178
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 	 *
182 182
 	 * @param WPInv_Subscription $subscription
183 183
 	 */
184
-	public function delete( &$subscription ) {
184
+	public function delete(&$subscription) {
185 185
 		global $wpdb;
186 186
 
187 187
 		$wpdb->query(
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
 			)
193 193
 		);
194 194
 
195
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' );
196
-		delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' );
195
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id');
196
+		delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id');
197 197
 
198 198
 		// Delete cache.
199 199
 		$subscription->clear_cache();
200 200
 
201 201
 		// Fire a hook.
202
-		do_action( 'getpaid_delete_subscription', $subscription );
202
+		do_action('getpaid_delete_subscription', $subscription);
203 203
 
204
-		$subscription->set_id( 0 );
204
+		$subscription->set_id(0);
205 205
 	}
206 206
 
207 207
 	/*
Please login to merge, or discard this patch.
includes/api/class-getpaid-rest-crud-controller.php 1 patch
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * GetPaid REST CRUD controller class.
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @see register_rest_route()
40 40
 	 */
41
-	public function register_namespace_routes( $namespace ) {
41
+	public function register_namespace_routes($namespace) {
42 42
 
43 43
 		register_rest_route(
44 44
 			$namespace,
@@ -46,22 +46,22 @@  discard block
 block discarded – undo
46 46
 			array(
47 47
 				array(
48 48
 					'methods'             => WP_REST_Server::READABLE,
49
-					'callback'            => array( $this, 'get_items' ),
50
-					'permission_callback' => array( $this, 'get_items_permissions_check' ),
49
+					'callback'            => array($this, 'get_items'),
50
+					'permission_callback' => array($this, 'get_items_permissions_check'),
51 51
 					'args'                => $this->get_collection_params(),
52 52
 				),
53 53
 				array(
54 54
 					'methods'             => WP_REST_Server::CREATABLE,
55
-					'callback'            => array( $this, 'create_item' ),
56
-					'permission_callback' => array( $this, 'create_item_permissions_check' ),
57
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ),
55
+					'callback'            => array($this, 'create_item'),
56
+					'permission_callback' => array($this, 'create_item_permissions_check'),
57
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE),
58 58
 				),
59
-				'schema' => array( $this, 'get_public_item_schema' ),
59
+				'schema' => array($this, 'get_public_item_schema'),
60 60
 			)
61 61
 		);
62 62
 
63 63
 		$get_item_args = array(
64
-			'context' => $this->get_context_param( array( 'default' => 'view' ) ),
64
+			'context' => $this->get_context_param(array('default' => 'view')),
65 65
 		);
66 66
 
67 67
 		register_rest_route(
@@ -70,35 +70,35 @@  discard block
 block discarded – undo
70 70
 			array(
71 71
 				'args'   => array(
72 72
 					'id' => array(
73
-						'description' => __( 'Unique identifier for the object.', 'invoicing' ),
73
+						'description' => __('Unique identifier for the object.', 'invoicing'),
74 74
 						'type'        => 'integer',
75 75
 					),
76 76
 				),
77 77
 				array(
78 78
 					'methods'             => WP_REST_Server::READABLE,
79
-					'callback'            => array( $this, 'get_item' ),
80
-					'permission_callback' => array( $this, 'get_item_permissions_check' ),
79
+					'callback'            => array($this, 'get_item'),
80
+					'permission_callback' => array($this, 'get_item_permissions_check'),
81 81
 					'args'                => $get_item_args,
82 82
 				),
83 83
 				array(
84 84
 					'methods'             => WP_REST_Server::EDITABLE,
85
-					'callback'            => array( $this, 'update_item' ),
86
-					'permission_callback' => array( $this, 'update_item_permissions_check' ),
87
-					'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
85
+					'callback'            => array($this, 'update_item'),
86
+					'permission_callback' => array($this, 'update_item_permissions_check'),
87
+					'args'                => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE),
88 88
 				),
89 89
 				array(
90 90
 					'methods'             => WP_REST_Server::DELETABLE,
91
-					'callback'            => array( $this, 'delete_item' ),
92
-					'permission_callback' => array( $this, 'delete_item_permissions_check' ),
91
+					'callback'            => array($this, 'delete_item'),
92
+					'permission_callback' => array($this, 'delete_item_permissions_check'),
93 93
 					'args'                => array(
94 94
 						'force' => array(
95 95
 							'type'        => 'boolean',
96 96
 							'default'     => false,
97
-							'description' => __( 'Whether to bypass Trash and force deletion.', 'invoicing' ),
97
+							'description' => __('Whether to bypass Trash and force deletion.', 'invoicing'),
98 98
 						),
99 99
 					),
100 100
 				),
101
-				'schema' => array( $this, 'get_public_item_schema' ),
101
+				'schema' => array($this, 'get_public_item_schema'),
102 102
 			)
103 103
 		);
104 104
 
@@ -110,14 +110,14 @@  discard block
 block discarded – undo
110 110
 	 * @param GetPaid_Data $object Object to save.
111 111
 	 * @return WP_Error|GetPaid_Data
112 112
 	 */
113
-	protected function save_object( $object ) {
113
+	protected function save_object($object) {
114 114
 		$object->save();
115 115
 
116
-		if ( ! empty( $object->last_error ) ) {
117
-			return new WP_Error( 'rest_cannot_save', $object->last_error, array( 'status' => 400 ) );
116
+		if (!empty($object->last_error)) {
117
+			return new WP_Error('rest_cannot_save', $object->last_error, array('status' => 400));
118 118
 		}
119 119
 
120
-		return new $this->crud_class( $object->get_id() );
120
+		return new $this->crud_class($object->get_id());
121 121
 	}
122 122
 
123 123
 	/**
@@ -128,21 +128,21 @@  discard block
 block discarded – undo
128 128
 	 * @param int|WP_Post $object_id Supplied ID.
129 129
 	 * @return GetPaid_Data|WP_Error GetPaid_Data object if ID is valid, WP_Error otherwise.
130 130
 	 */
131
-	protected function get_object( $object_id ) {
131
+	protected function get_object($object_id) {
132 132
 
133 133
 		// Do we have an object?
134
-		if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) {
135
-			return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) );
134
+		if (empty($this->crud_class) || !class_exists($this->crud_class)) {
135
+			return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing'));
136 136
 		}
137 137
 
138 138
 		// Fetch the object.
139
-		$object = new $this->crud_class( $object_id );
140
-		if ( ! empty( $object->last_error ) ) {
141
-			return new WP_Error( 'rest_object_invalid_id', $object->last_error, array( 'status' => 404 ) );
139
+		$object = new $this->crud_class($object_id);
140
+		if (!empty($object->last_error)) {
141
+			return new WP_Error('rest_object_invalid_id', $object->last_error, array('status' => 404));
142 142
 		}
143 143
 
144 144
 		$this->data_object = $object;
145
-		return $object->get_id() ? $object : new WP_Error( 'rest_object_invalid_id', __( 'Invalid ID.', 'invoicing' ), array( 'status' => 404 ) );
145
+		return $object->get_id() ? $object : new WP_Error('rest_object_invalid_id', __('Invalid ID.', 'invoicing'), array('status' => 404));
146 146
 
147 147
 	}
148 148
 
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
 	 * @param WP_REST_Request $request Full details about the request.
153 153
 	 * @return WP_Error|WP_REST_Response
154 154
 	 */
155
-	public function get_item( $request ) {
155
+	public function get_item($request) {
156 156
 
157 157
 		// Fetch the item.
158
-		$object = $this->get_object( $request['id'] );
158
+		$object = $this->get_object($request['id']);
159 159
 
160
-		if ( is_wp_error( $object ) ) {
160
+		if (is_wp_error($object)) {
161 161
 			return $object;
162 162
 		}
163 163
 
164 164
 		// Generate a response.
165
-		return rest_ensure_response( $this->prepare_item_for_response( $object, $request ) );
165
+		return rest_ensure_response($this->prepare_item_for_response($object, $request));
166 166
 
167 167
 	}
168 168
 
@@ -172,38 +172,38 @@  discard block
 block discarded – undo
172 172
 	 * @param WP_REST_Request $request Full details about the request.
173 173
 	 * @return WP_Error|WP_REST_Response
174 174
 	 */
175
-	public function create_item( $request ) {
175
+	public function create_item($request) {
176 176
 
177 177
 		// Can not create an existing item.
178
-		if ( ! empty( $request['id'] ) ) {
178
+		if (!empty($request['id'])) {
179 179
 			/* translators: %s: post type */
180
-			return new WP_Error( "getpaid_rest_{$this->rest_base}_exists", __( 'Cannot create existing resource.', 'invoicing' ), array( 'status' => 400 ) );
180
+			return new WP_Error("getpaid_rest_{$this->rest_base}_exists", __('Cannot create existing resource.', 'invoicing'), array('status' => 400));
181 181
 		}
182 182
 
183 183
 		// Generate a GetPaid_Data object from the request.
184
-		$object = $this->prepare_item_for_database( $request );
185
-		if ( is_wp_error( $object ) ) {
184
+		$object = $this->prepare_item_for_database($request);
185
+		if (is_wp_error($object)) {
186 186
 			return $object;
187 187
 		}
188 188
 
189 189
 		// Save the object.
190
-		$object = $this->save_object( $object );
191
-		if ( is_wp_error( $object ) ) {
190
+		$object = $this->save_object($object);
191
+		if (is_wp_error($object)) {
192 192
 			return $object;
193 193
 		}
194 194
 
195 195
 		// Save special fields.
196
-		$save_special = $this->update_additional_fields_for_object( $object, $request );
197
-		if ( is_wp_error( $save_special ) ) {
198
-			$object->delete( true );
196
+		$save_special = $this->update_additional_fields_for_object($object, $request);
197
+		if (is_wp_error($save_special)) {
198
+			$object->delete(true);
199 199
 			return $save_special;
200 200
 		}
201 201
 
202
-		$request->set_param( 'context', 'edit' );
203
-		$response = $this->prepare_item_for_response( $object, $request );
204
-		$response = rest_ensure_response( $response );
205
-		$response->set_status( 201 );
206
-		$response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) );
202
+		$request->set_param('context', 'edit');
203
+		$response = $this->prepare_item_for_response($object, $request);
204
+		$response = rest_ensure_response($response);
205
+		$response->set_status(201);
206
+		$response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())));
207 207
 
208 208
 		return $response;
209 209
 	}
@@ -214,35 +214,35 @@  discard block
 block discarded – undo
214 214
 	 * @param WP_REST_Request $request Full details about the request.
215 215
 	 * @return WP_Error|WP_REST_Response
216 216
 	 */
217
-	public function update_item( $request ) {
217
+	public function update_item($request) {
218 218
 
219 219
 		// Fetch the item.
220
-		$object = $this->get_object( $request['id'] );
221
-		if ( is_wp_error( $object ) ) {
220
+		$object = $this->get_object($request['id']);
221
+		if (is_wp_error($object)) {
222 222
 			return $object;
223 223
 		}
224 224
 
225 225
 		// Prepare the item for saving.
226
-		$object = $this->prepare_item_for_database( $request );
227
-		if ( is_wp_error( $object ) ) {
226
+		$object = $this->prepare_item_for_database($request);
227
+		if (is_wp_error($object)) {
228 228
 			return $object;
229 229
 		}
230 230
 
231 231
 		// Save the item.
232
-		$object = $this->save_object( $object );
233
-		if ( is_wp_error( $object ) ) {
232
+		$object = $this->save_object($object);
233
+		if (is_wp_error($object)) {
234 234
 			return $object;
235 235
 		}
236 236
 
237 237
 		// Save special fields (those added via hooks).
238
-		$save_special = $this->update_additional_fields_for_object( $object, $request );
239
-		if ( is_wp_error( $save_special ) ) {
238
+		$save_special = $this->update_additional_fields_for_object($object, $request);
239
+		if (is_wp_error($save_special)) {
240 240
 			return $save_special;
241 241
 		}
242 242
 
243
-		$request->set_param( 'context', 'edit' );
244
-		$response = $this->prepare_item_for_response( $object, $request );
245
-		return rest_ensure_response( $response );
243
+		$request->set_param('context', 'edit');
244
+		$response = $this->prepare_item_for_response($object, $request);
245
+		return rest_ensure_response($response);
246 246
 	}
247 247
 
248 248
 	/**
@@ -251,14 +251,14 @@  discard block
 block discarded – undo
251 251
 	 * @param GetPaid_Data    $object GetPaid_Data object.
252 252
 	 * @return array Links for the given object.
253 253
 	 */
254
-	protected function prepare_links( $object ) {
254
+	protected function prepare_links($object) {
255 255
 
256 256
 		$links = array(
257 257
 			'self'       => array(
258
-				'href'   => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ),
258
+				'href'   => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())),
259 259
 			),
260 260
 			'collection' => array(
261
-				'href'   => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ),
261
+				'href'   => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)),
262 262
 			),
263 263
 		);
264 264
 
@@ -282,8 +282,8 @@  discard block
 block discarded – undo
282 282
 	 * @param  array $schema Schema.
283 283
 	 * @return bool
284 284
 	 */
285
-	public function filter_writable_props( $schema ) {
286
-		return empty( $schema['readonly'] );
285
+	public function filter_writable_props($schema) {
286
+		return empty($schema['readonly']);
287 287
 	}
288 288
 
289 289
 	/**
@@ -293,43 +293,43 @@  discard block
 block discarded – undo
293 293
 	 * @param  WP_REST_Request $request Request object.
294 294
 	 * @return GetPaid_Data|WP_Error Data object or WP_Error.
295 295
 	 */
296
-	protected function prepare_item_for_database( $request ) {
296
+	protected function prepare_item_for_database($request) {
297 297
 
298 298
 		// Do we have an object?
299
-		if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) {
300
-			return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) );
299
+		if (empty($this->crud_class) || !class_exists($this->crud_class)) {
300
+			return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing'));
301 301
 		}
302 302
 
303 303
 		// Prepare the object.
304
-		$id        = isset( $request['id'] ) ? absint( $request['id'] ) : 0;
305
-		$object    = new $this->crud_class( $id );
304
+		$id        = isset($request['id']) ? absint($request['id']) : 0;
305
+		$object    = new $this->crud_class($id);
306 306
 
307 307
 		// Abort if an error exists.
308
-		if ( ! empty( $object->last_error ) ) {
309
-			return new WP_Error( 'invalid_item', $object->last_error );
308
+		if (!empty($object->last_error)) {
309
+			return new WP_Error('invalid_item', $object->last_error);
310 310
 		}
311 311
 
312 312
 		$schema    = $this->get_item_schema();
313
-		$data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) );
313
+		$data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props')));
314 314
 
315 315
 		// Handle all writable props.
316
-		foreach ( $data_keys as $key ) {
317
-			$value = $request[ $key ];
316
+		foreach ($data_keys as $key) {
317
+			$value = $request[$key];
318 318
 
319
-			if ( ! is_null( $value ) ) {
320
-				switch ( $key ) {
319
+			if (!is_null($value)) {
320
+				switch ($key) {
321 321
 
322 322
 					case 'meta_data':
323
-						if ( is_array( $value ) ) {
324
-							foreach ( $value as $meta ) {
325
-								$object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' );
323
+						if (is_array($value)) {
324
+							foreach ($value as $meta) {
325
+								$object->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : '');
326 326
 							}
327 327
 						}
328 328
 						break;
329 329
 
330 330
 					default:
331
-						if ( is_callable( array( $object, "set_{$key}" ) ) ) {
332
-							$object->{"set_{$key}"}( $value );
331
+						if (is_callable(array($object, "set_{$key}"))) {
332
+							$object->{"set_{$key}"}($value);
333 333
 						}
334 334
 						break;
335 335
 				}
@@ -338,7 +338,7 @@  discard block
 block discarded – undo
338 338
 		}
339 339
 
340 340
 		// Filters an object before it is inserted via the REST API..
341
-		return apply_filters( "getpaid_rest_pre_insert_{$this->rest_base}_object", $object, $request );
341
+		return apply_filters("getpaid_rest_pre_insert_{$this->rest_base}_object", $object, $request);
342 342
 	}
343 343
 
344 344
 	/**
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
 	 * @param  GetPaid_Meta_Data[]    $meta_data  meta data objects.
349 349
 	 * @return array
350 350
 	 */
351
-	protected function prepare_object_meta_data( $meta_data ) {
351
+	protected function prepare_object_meta_data($meta_data) {
352 352
 		$meta = array();
353 353
 
354
-		foreach( $meta_data as $object ) {
354
+		foreach ($meta_data as $object) {
355 355
 			$meta[] = $object->get_data();
356 356
 		}
357 357
 
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
 	 * @param array            $fields Fields to include.
367 367
 	 * @return array
368 368
 	 */
369
-	protected function prepare_invoice_items( $invoice ) {
369
+	protected function prepare_invoice_items($invoice) {
370 370
 		$items = array();
371 371
 
372
-		foreach( $invoice->get_items() as $item ) {
372
+		foreach ($invoice->get_items() as $item) {
373 373
 
374 374
 			$item_data = $item->prepare_data_for_saving();
375 375
 
376
-			if ( 'amount' == $invoice->get_template() ) {
376
+			if ('amount' == $invoice->get_template()) {
377 377
 				$item_data['quantity'] = 1;
378 378
 			}
379 379
 
@@ -392,52 +392,52 @@  discard block
 block discarded – undo
392 392
 	 * @param string           $context either view or edit.
393 393
 	 * @return array
394 394
 	 */
395
-	protected function prepare_object_data( $object, $fields, $context = 'view' ) {
395
+	protected function prepare_object_data($object, $fields, $context = 'view') {
396 396
 
397 397
 		$data = array();
398 398
 
399 399
 		// Handle all writable props.
400
-		foreach ( array_keys( $this->get_schema_properties() ) as $key ) {
400
+		foreach (array_keys($this->get_schema_properties()) as $key) {
401 401
 
402 402
 			// Abort if it is not included.
403
-			if ( ! empty( $fields ) && ! $this->is_field_included( $key, $fields ) ) {
403
+			if (!empty($fields) && !$this->is_field_included($key, $fields)) {
404 404
 				continue;
405 405
 			}
406 406
 
407 407
 			// Or this current object does not support the field.
408
-			if ( ! $this->object_supports_field( $object, $key ) ) {
408
+			if (!$this->object_supports_field($object, $key)) {
409 409
 				continue;
410 410
 			}
411 411
 
412 412
 			// Handle meta data.
413
-			if ( $key == 'meta_data' ) {
414
-				$data['meta_data'] = $this->prepare_object_meta_data( $object->get_meta_data() );
413
+			if ($key == 'meta_data') {
414
+				$data['meta_data'] = $this->prepare_object_meta_data($object->get_meta_data());
415 415
 				continue;
416 416
 			}
417 417
 
418 418
 			// Handle items.
419
-			if ( $key == 'items' && is_a( $object, 'WPInv_Invoice' )  ) {
420
-				$data['items'] = $this->prepare_invoice_items( $object );
419
+			if ($key == 'items' && is_a($object, 'WPInv_Invoice')) {
420
+				$data['items'] = $this->prepare_invoice_items($object);
421 421
 				continue;
422 422
 			}
423 423
 
424 424
 			// Booleans.
425
-			if ( is_callable( array( $object, $key ) ) ) {
426
-				$data[ $key ] = $object->$key( $context );
425
+			if (is_callable(array($object, $key))) {
426
+				$data[$key] = $object->$key($context);
427 427
 				continue;
428 428
 			}
429 429
 
430 430
 			// Get object value.
431
-			if ( is_callable( array( $object, "get_{$key}" ) ) ) {
432
-				$value = $object->{"get_{$key}"}( $context );
431
+			if (is_callable(array($object, "get_{$key}"))) {
432
+				$value = $object->{"get_{$key}"}($context);
433 433
 
434 434
 				// If the value is an instance of GetPaid_Data...
435
-				if ( is_a( $value, 'GetPaid_Data' ) ) {
436
-					$value = $value->get_data( $context );
435
+				if (is_a($value, 'GetPaid_Data')) {
436
+					$value = $value->get_data($context);
437 437
 				}
438 438
 
439 439
 				// For objects, retrieves it's properties.
440
-				$data[ $key ] = is_object( $value ) ? get_object_vars( $value ) :  $value ;
440
+				$data[$key] = is_object($value) ? get_object_vars($value) : $value;
441 441
 				continue;
442 442
 			}
443 443
 
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string       $field_key The key to check for.
455 455
 	 * @return bool
456 456
 	 */
457
-	public function object_supports_field( $object, $field_key ) {
458
-		return apply_filters( 'getpaid_rest_object_supports_key', true, $object, $field_key );
457
+	public function object_supports_field($object, $field_key) {
458
+		return apply_filters('getpaid_rest_object_supports_key', true, $object, $field_key);
459 459
 	}
460 460
 
461 461
 	/**
@@ -466,27 +466,27 @@  discard block
 block discarded – undo
466 466
 	 * @param  WP_REST_Request $request Request object.
467 467
 	 * @return WP_REST_Response
468 468
 	 */
469
-	public function prepare_item_for_response( $object, $request ) {
470
-		remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 );
469
+	public function prepare_item_for_response($object, $request) {
470
+		remove_filter('rest_post_dispatch', 'rest_filter_response_fields', 10);
471 471
 
472 472
 		$this->data_object = $object;
473 473
 
474 474
 		// Fetch the fields to include in this response.
475
-		$fields = $this->get_fields_for_response( $request );
475
+		$fields = $this->get_fields_for_response($request);
476 476
 
477 477
 		// Prepare object data.
478
-		$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
479
-		$data    = $this->prepare_object_data( $object, $fields, $context );
480
-		$data    = $this->add_additional_fields_to_object( $data, $request );
481
-		$data    = $this->limit_object_to_requested_fields( $data, $fields );
482
-		$data    = $this->filter_response_by_context( $data, $context );
478
+		$context = !empty($request['context']) ? $request['context'] : 'view';
479
+		$data    = $this->prepare_object_data($object, $fields, $context);
480
+		$data    = $this->add_additional_fields_to_object($data, $request);
481
+		$data    = $this->limit_object_to_requested_fields($data, $fields);
482
+		$data    = $this->filter_response_by_context($data, $context);
483 483
 
484 484
 		// Prepare the response.
485
-		$response = rest_ensure_response( $data );
486
-		$response->add_links( $this->prepare_links( $object, $request ) );
485
+		$response = rest_ensure_response($data);
486
+		$response->add_links($this->prepare_links($object, $request));
487 487
 
488 488
 		// Filter item response.
489
-		return apply_filters( "getpaid_rest_prepare_{$this->rest_base}_object", $response, $object, $request );
489
+		return apply_filters("getpaid_rest_prepare_{$this->rest_base}_object", $response, $object, $request);
490 490
 	}
491 491
 
492 492
 }
Please login to merge, or discard this patch.
includes/class-getpaid-subscriptions-query.php 1 patch
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -97,9 +97,9 @@  discard block
 block discarded – undo
97 97
 	 *
98 98
 	 * @param null|string|array $query Optional. The query variables.
99 99
 	 */
100
-	public function __construct( $query = null ) {
101
-		if ( ! is_null( $query ) ) {
102
-			$this->prepare_query( $query );
100
+	public function __construct($query = null) {
101
+		if (!is_null($query)) {
102
+			$this->prepare_query($query);
103 103
 			$this->query();
104 104
 		}
105 105
 	}
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 	 * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113 113
 	 * @return array Complete query variables with undefined ones filled in with defaults.
114 114
 	 */
115
-	public static function fill_query_vars( $args ) {
115
+	public static function fill_query_vars($args) {
116 116
 		$defaults = array(
117 117
 			'status'            => 'all',
118 118
 			'customer_in'       => array(),
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 			'fields'            => 'all',
131 131
 		);
132 132
 
133
-		return wp_parse_args( $args, $defaults );
133
+		return wp_parse_args($args, $defaults);
134 134
 	}
135 135
 
136 136
 	/**
@@ -182,45 +182,45 @@  discard block
 block discarded – undo
182 182
 	 *                                             Use 'all' for all fields. Default 'all'.
183 183
 	 * }
184 184
 	 */
185
-	public function prepare_query( $query = array() ) {
185
+	public function prepare_query($query = array()) {
186 186
 		global $wpdb;
187 187
 
188
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
188
+		if (empty($this->query_vars) || !empty($query)) {
189 189
 			$this->query_limit = null;
190
-			$this->query_vars  = $this->fill_query_vars( $query );
190
+			$this->query_vars  = $this->fill_query_vars($query);
191 191
 		}
192 192
 
193
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
194
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
193
+		if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) {
194
+			$this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']);
195 195
 		}
196 196
 
197
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
197
+		do_action('getpaid_pre_get_subscriptions', array(&$this));
198 198
 
199 199
 		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
200
-		$qv                =& $this->query_vars;
201
-		$qv                = $this->fill_query_vars( $qv );
200
+		$qv                = & $this->query_vars;
201
+		$qv                = $this->fill_query_vars($qv);
202 202
 		$table             = $wpdb->prefix . 'wpinv_subscriptions';
203 203
 		$this->query_from  = "FROM $table";
204 204
 
205 205
 		// Prepare query fields.
206
-		$this->prepare_query_fields( $qv, $table );
206
+		$this->prepare_query_fields($qv, $table);
207 207
 
208 208
 		// Prepare query where.
209
-		$this->prepare_query_where( $qv, $table );
209
+		$this->prepare_query_where($qv, $table);
210 210
 
211 211
 		// Prepare query order.
212
-		$this->prepare_query_order( $qv, $table );
212
+		$this->prepare_query_order($qv, $table);
213 213
 
214 214
 		// limit
215
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
216
-			if ( $qv['offset'] ) {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
215
+		if (isset($qv['number']) && $qv['number'] > 0) {
216
+			if ($qv['offset']) {
217
+				$this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']);
218 218
 			} else {
219
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
219
+				$this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']);
220 220
 			}
221 221
 		}
222 222
 
223
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
223
+		do_action_ref_array('getpaid_after_subscriptions_query', array(&$this));
224 224
 	}
225 225
 
226 226
 	/**
@@ -231,22 +231,22 @@  discard block
 block discarded – undo
231 231
 	 * @param array $qv Query vars.
232 232
 	 * @param string $table Table name.
233 233
 	 */
234
-	protected function prepare_query_fields( &$qv, $table ) {
234
+	protected function prepare_query_fields(&$qv, $table) {
235 235
 
236
-		if ( is_array( $qv['fields'] ) ) {
237
-			$qv['fields'] = array_unique( $qv['fields'] );
236
+		if (is_array($qv['fields'])) {
237
+			$qv['fields'] = array_unique($qv['fields']);
238 238
 
239 239
 			$query_fields = array();
240
-			foreach ( $qv['fields'] as $field ) {
241
-				$field          = sanitize_key( $field );
240
+			foreach ($qv['fields'] as $field) {
241
+				$field          = sanitize_key($field);
242 242
 				$query_fields[] = "$table.`$field`";
243 243
 			}
244
-			$this->query_fields = implode( ',', $query_fields );
244
+			$this->query_fields = implode(',', $query_fields);
245 245
 		} else {
246 246
 			$this->query_fields = "$table.*";
247 247
 		}
248 248
 
249
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
249
+		if (isset($qv['count_total']) && $qv['count_total']) {
250 250
 			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
251 251
 		}
252 252
 
@@ -260,58 +260,58 @@  discard block
 block discarded – undo
260 260
 	 * @param array $qv Query vars.
261 261
 	 * @param string $table Table name.
262 262
 	 */
263
-	protected function prepare_query_where( &$qv, $table ) {
263
+	protected function prepare_query_where(&$qv, $table) {
264 264
 		global $wpdb;
265 265
 		$this->query_where = 'WHERE 1=1';
266 266
 
267 267
 		// Status.
268
-		if ( 'all' !== $qv['status'] ) {
269
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
270
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
271
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
268
+		if ('all' !== $qv['status']) {
269
+			$statuses           = wpinv_clean(wpinv_parse_list($qv['status']));
270
+			$prepared_statuses  = join(',', array_fill(0, count($statuses), '%s'));
271
+			$this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $prepared_statuses )", $statuses);
272 272
 		}
273 273
 
274
-		if ( ! empty( $qv['customer_in'] ) ) {
275
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
274
+		if (!empty($qv['customer_in'])) {
275
+			$customer_in        = implode(',', wp_parse_id_list($qv['customer_in']));
276 276
 			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
277
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
278
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
277
+		} elseif (!empty($qv['customer_not_in'])) {
278
+			$customer_not_in    = implode(',', wp_parse_id_list($qv['customer_not_in']));
279 279
 			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
280 280
 		}
281 281
 
282
-		if ( ! empty( $qv['product_in'] ) ) {
283
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
282
+		if (!empty($qv['product_in'])) {
283
+			$product_in         = implode(',', wp_parse_id_list($qv['product_in']));
284 284
 			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
285
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
286
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
285
+		} elseif (!empty($qv['product_not_in'])) {
286
+			$product_not_in     = implode(',', wp_parse_id_list($qv['product_not_in']));
287 287
 			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
288 288
 		}
289 289
 
290
-		if ( ! empty( $qv['invoice_in'] ) ) {
291
-			$invoice_in         = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) );
290
+		if (!empty($qv['invoice_in'])) {
291
+			$invoice_in         = implode(',', wp_parse_id_list($qv['invoice_in']));
292 292
 			$this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)";
293
-		} elseif ( ! empty( $qv['invoice_not_in'] ) ) {
294
-			$invoice_not_in     = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) );
293
+		} elseif (!empty($qv['invoice_not_in'])) {
294
+			$invoice_not_in     = implode(',', wp_parse_id_list($qv['invoice_not_in']));
295 295
 			$this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)";
296 296
 		}
297 297
 
298
-		if ( ! empty( $qv['include'] ) ) {
299
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
298
+		if (!empty($qv['include'])) {
299
+			$include            = implode(',', wp_parse_id_list($qv['include']));
300 300
 			$this->query_where .= " AND $table.`id` IN ($include)";
301
-		} elseif ( ! empty( $qv['exclude'] ) ) {
302
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
301
+		} elseif (!empty($qv['exclude'])) {
302
+			$exclude            = implode(',', wp_parse_id_list($qv['exclude']));
303 303
 			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
304 304
 		}
305 305
 
306 306
 		// Date queries are allowed for the subscription creation date.
307
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
308
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
307
+		if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) {
308
+			$date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.created");
309 309
 			$this->query_where .= $date_created_query->get_sql();
310 310
 		}
311 311
 
312 312
 		// Date queries are also allowed for the subscription expiration date.
313
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
314
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
313
+		if (!empty($qv['date_expires_query']) && is_array($qv['date_expires_query'])) {
314
+			$date_expires_query = new WP_Date_Query($qv['date_expires_query'], "$table.expiration");
315 315
 			$this->query_where .= $date_expires_query->get_sql();
316 316
 		}
317 317
 
@@ -325,24 +325,24 @@  discard block
 block discarded – undo
325 325
 	 * @param array $qv Query vars.
326 326
 	 * @param string $table Table name.
327 327
 	 */
328
-	protected function prepare_query_order( &$qv, $table ) {
328
+	protected function prepare_query_order(&$qv, $table) {
329 329
 
330 330
 		// sorting.
331
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
332
-		$order       = $this->parse_order( $qv['order'] );
331
+		$qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : '';
332
+		$order       = $this->parse_order($qv['order']);
333 333
 
334 334
 		// Default order is by 'id' (latest subscriptions).
335
-		if ( empty( $qv['orderby'] ) ) {
336
-			$qv['orderby'] = array( 'id' );
335
+		if (empty($qv['orderby'])) {
336
+			$qv['orderby'] = array('id');
337 337
 		}
338 338
 
339 339
 		// 'orderby' values may be an array, comma- or space-separated list.
340
-		$ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
340
+		$ordersby      = array_filter(wpinv_parse_list($qv['orderby']));
341 341
 
342 342
 		$orderby_array = array();
343
-		foreach ( $ordersby as $_key => $_value ) {
343
+		foreach ($ordersby as $_key => $_value) {
344 344
 
345
-			if ( is_int( $_key ) ) {
345
+			if (is_int($_key)) {
346 346
 				// Integer key means this is a flat array of 'orderby' fields.
347 347
 				$_orderby = $_value;
348 348
 				$_order   = $order;
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 				$_order   = $_value;
353 353
 			}
354 354
 
355
-			$parsed = $this->parse_orderby( $_orderby, $table );
355
+			$parsed = $this->parse_orderby($_orderby, $table);
356 356
 
357
-			if ( $parsed ) {
358
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
357
+			if ($parsed) {
358
+				$orderby_array[] = $parsed . ' ' . $this->parse_order($_order);
359 359
 			}
360 360
 
361 361
 		}
362 362
 
363 363
 		// If no valid clauses were found, order by id.
364
-		if ( empty( $orderby_array ) ) {
364
+		if (empty($orderby_array)) {
365 365
 			$orderby_array[] = "id $order";
366 366
 		}
367 367
 
368
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
368
+		$this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array);
369 369
 
370 370
 	}
371 371
 
@@ -379,34 +379,34 @@  discard block
 block discarded – undo
379 379
 	public function query() {
380 380
 		global $wpdb;
381 381
 
382
-		$qv =& $this->query_vars;
382
+		$qv = & $this->query_vars;
383 383
 
384 384
 		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
385 385
 		// total_subscriptions property.
386
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
386
+		$this->results = apply_filters_ref_array('getpaid_subscriptions_pre_query', array(null, &$this));
387 387
 
388
-		if ( null === $this->results ) {
388
+		if (null === $this->results) {
389 389
 			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
390 390
 
391
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
392
-				$this->results = $wpdb->get_results( $this->request );
391
+			if ((is_array($qv['fields']) && 1 != count($qv['fields'])) || 'all' == $qv['fields']) {
392
+				$this->results = $wpdb->get_results($this->request);
393 393
 			} else {
394
-				$this->results = $wpdb->get_col( $this->request );
394
+				$this->results = $wpdb->get_col($this->request);
395 395
 			}
396 396
 
397
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
398
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
399
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
397
+			if (isset($qv['count_total']) && $qv['count_total']) {
398
+				$found_subscriptions_query = apply_filters('getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this);
399
+				$this->total_subscriptions = (int) $wpdb->get_var($found_subscriptions_query);
400 400
 			}
401 401
 		}
402 402
 
403
-		if ( 'all' == $qv['fields'] ) {
404
-			foreach ( $this->results as $key => $subscription ) {
405
-				wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' );
406
-				wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' );
407
-				wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
408
-				wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' );
409
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
403
+		if ('all' == $qv['fields']) {
404
+			foreach ($this->results as $key => $subscription) {
405
+				wp_cache_set($subscription->id, $subscription, 'getpaid_subscriptions');
406
+				wp_cache_set($subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids');
407
+				wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids');
408
+				wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids');
409
+				$this->results[$key] = new WPInv_Subscription($subscription);
410 410
 			}
411 411
 		}
412 412
 
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
 	 * @param string $query_var Query variable key.
421 421
 	 * @return mixed
422 422
 	 */
423
-	public function get( $query_var ) {
424
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
425
-			return $this->query_vars[ $query_var ];
423
+	public function get($query_var) {
424
+		if (isset($this->query_vars[$query_var])) {
425
+			return $this->query_vars[$query_var];
426 426
 		}
427 427
 
428 428
 		return null;
@@ -436,8 +436,8 @@  discard block
 block discarded – undo
436 436
 	 * @param string $query_var Query variable key.
437 437
 	 * @param mixed $value Query variable value.
438 438
 	 */
439
-	public function set( $query_var, $value ) {
440
-		$this->query_vars[ $query_var ] = $value;
439
+	public function set($query_var, $value) {
440
+		$this->query_vars[$query_var] = $value;
441 441
 	}
442 442
 
443 443
 	/**
@@ -471,16 +471,16 @@  discard block
 block discarded – undo
471 471
 	 *  @param string $table The current table.
472 472
 	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
473 473
 	 */
474
-	protected function parse_orderby( $orderby, $table ) {
474
+	protected function parse_orderby($orderby, $table) {
475 475
 
476 476
 		$_orderby = '';
477
-		if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
477
+		if (in_array($orderby, array('customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id'))) {
478 478
 			$_orderby = "$table.`$orderby`";
479
-		} elseif ( 'id' === strtolower( $orderby ) ) {
479
+		} elseif ('id' === strtolower($orderby)) {
480 480
 			$_orderby = "$table.id";
481
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
482
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
483
-			$include_sql = implode( ',', $include );
481
+		} elseif ('include' === $orderby && !empty($this->query_vars['include'])) {
482
+			$include     = wp_parse_id_list($this->query_vars['include']);
483
+			$include_sql = implode(',', $include);
484 484
 			$_orderby    = "FIELD( $table.id, $include_sql )";
485 485
 		}
486 486
 
@@ -495,12 +495,12 @@  discard block
 block discarded – undo
495 495
 	 * @param string $order The 'order' query variable.
496 496
 	 * @return string The sanitized 'order' query variable.
497 497
 	 */
498
-	protected function parse_order( $order ) {
499
-		if ( ! is_string( $order ) || empty( $order ) ) {
498
+	protected function parse_order($order) {
499
+		if (!is_string($order) || empty($order)) {
500 500
 			return 'DESC';
501 501
 		}
502 502
 
503
-		if ( 'ASC' === strtoupper( $order ) ) {
503
+		if ('ASC' === strtoupper($order)) {
504 504
 			return 'ASC';
505 505
 		} else {
506 506
 			return 'DESC';
Please login to merge, or discard this patch.
widgets/subscriptions.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.0
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Contains the subscriptions widget.
@@ -27,15 +27,15 @@  discard block
 block discarded – undo
27 27
 			'block-keywords'=> "['invoicing','subscriptions', 'getpaid']",
28 28
 			'class_name'     => __CLASS__,
29 29
 			'base_id'       => 'wpinv_subscriptions',
30
-			'name'          => __( 'GetPaid > Subscriptions', 'invoicing' ),
30
+			'name'          => __('GetPaid > Subscriptions', 'invoicing'),
31 31
 			'widget_ops'    => array(
32 32
 				'classname'   => 'getpaid-subscriptions bsui',
33
-				'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ),
33
+				'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'),
34 34
 			),
35 35
 			'arguments'     => array(
36 36
 				'title'  => array(
37
-					'title'       => __( 'Widget title', 'invoicing' ),
38
-					'desc'        => __( 'Enter widget title.', 'invoicing' ),
37
+					'title'       => __('Widget title', 'invoicing'),
38
+					'desc'        => __('Enter widget title.', 'invoicing'),
39 39
 					'type'        => 'text',
40 40
 					'desc_tip'    => true,
41 41
 					'default'     => '',
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		);
47 47
 
48 48
 
49
-		parent::__construct( $options );
49
+		parent::__construct($options);
50 50
 	}
51 51
 
52 52
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	public function get_subscriptions() {
58 58
 
59 59
 		// Prepare license args.
60
-		$args  = array(
60
+		$args = array(
61 61
 			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
+			'paged'       => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
63 63
 		);
64 64
 
65
-		return new GetPaid_Subscriptions_Query( $args );
65
+		return new GetPaid_Subscriptions_Query($args);
66 66
 
67 67
 	}
68 68
 
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return mixed|string|bool
77 77
 	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
+	public function output($args = array(), $widget_args = array(), $content = '') {
79 79
 
80 80
 		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
81
+		if (!is_user_logged_in()) {
82 82
 
83 83
 			return aui()->alert(
84 84
 				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
+					'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')),
86 86
 					'type'    => 'error',
87 87
 				)
88 88
 			);
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 		}
91 91
 
92 92
 		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( trim( $_GET['subscription'] ) );
93
+		if (isset($_GET['subscription'])) {
94
+			return $this->display_single_subscription(trim($_GET['subscription']));
95 95
 		}
96 96
 
97 97
 		// Retrieve the user's subscriptions.
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
 		ob_start();
102 102
 
103 103
 		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
104
+		do_action('wpinv_before_user_subscriptions');
105 105
 
106 106
 		// Display errors and notices.
107 107
 		wpinv_print_errors();
108 108
 
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
+		do_action('getpaid_license_manager_before_subscriptions', $subscriptions);
110 110
 
111 111
 		// Print the table header.
112 112
 		$this->print_table_header();
113 113
 
114 114
 		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
115
+		$this->print_table_body($subscriptions->get_results());
116 116
 
117 117
 		// Print table footer.
118 118
 		$this->print_table_footer();
119 119
 
120 120
 		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
121
+		$this->print_navigation($subscriptions->get_total());
122 122
 
123 123
 		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
124
+		do_action('wpinv_after_user_subscriptions');
125 125
 
126 126
 		// Return the output.
127 127
 		return ob_get_clean();
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	public function get_subscriptions_table_columns() {
137 137
 
138 138
 		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
139
+			'subscription'   => __('Subscription', 'invoicing'),
140
+			'amount'         => __('Amount', 'invoicing'),
141
+			'renewal-date'   => __('Next payment', 'invoicing'),
142
+			'status'         => __('Status', 'invoicing'),
143 143
 		);
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
+		return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns);
146 146
 	}
147 147
 
148 148
 	/**
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
 				<thead>
159 159
 					<tr>
160
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
161
-							<th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>">
162
-								<?php echo sanitize_text_field( $label ); ?>
160
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
161
+							<th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>">
162
+								<?php echo sanitize_text_field($label); ?>
163 163
 							</th>
164 164
 						<?php endforeach; ?>
165 165
 					</tr>
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @param WPInv_Subscription[] $subscriptions
176 176
 	 */
177
-	public function print_table_body( $subscriptions ) {
177
+	public function print_table_body($subscriptions) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
179
+		if (empty($subscriptions)) {
180 180
 			$this->print_table_body_no_subscriptions();
181 181
 		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
182
+			$this->print_table_body_subscriptions($subscriptions);
183 183
 		}
184 184
 
185 185
 	}
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197
-				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
197
+				<td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>">
198 198
 
199 199
 					<?php
200 200
 						echo aui()->alert(
201 201
 							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+								'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')),
203 203
 								'type'    => 'warning',
204 204
 							)
205 205
 						);
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param WPInv_Subscription[] $subscriptions
219 219
 	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
220
+	public function print_table_body_subscriptions($subscriptions) {
221 221
 
222 222
 		?>
223 223
 		<tbody>
224 224
 
225
-			<?php foreach ( $subscriptions as $subscription ) : ?>
225
+			<?php foreach ($subscriptions as $subscription) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228 228
 						wpinv_get_template(
@@ -248,27 +248,27 @@  discard block
 block discarded – undo
248 248
 	 * @since       1.0.0
249 249
 	 * @return      string
250 250
 	 */
251
-	public function add_row_actions( $content, $subscription ) {
251
+	public function add_row_actions($content, $subscription) {
252 252
 
253 253
 		// Prepare row actions.
254 254
 		$actions = array();
255 255
 
256 256
 		// View subscription action.
257
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) );
258
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
257
+		$view_url        = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page'))));
258
+		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>';
259 259
 
260 260
 		// Filter the actions.
261
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
261
+		$actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription);
262 262
 
263
-		$sanitized  = array();
264
-		foreach ( $actions as $key => $action ) {
265
-			$key         = sanitize_html_class( $key );
266
-			$action      = wp_kses_post( $action );
263
+		$sanitized = array();
264
+		foreach ($actions as $key => $action) {
265
+			$key         = sanitize_html_class($key);
266
+			$action      = wp_kses_post($action);
267 267
 			$sanitized[] = "<span class='$key'>$action</span>";
268 268
 		}
269 269
 
270 270
 		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
271
-		$row_actions .= implode( ' | ', $sanitized );
271
+		$row_actions .= implode(' | ', $sanitized);
272 272
 		$row_actions .= '</small>';
273 273
 
274 274
 		return $content . $row_actions;
@@ -284,9 +284,9 @@  discard block
 block discarded – undo
284 284
 
285 285
 				<tfoot>
286 286
 					<tr>
287
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
288
-							<th class="getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>">
289
-								<?php echo sanitize_text_field( $label ); ?>
287
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
288
+							<th class="getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>">
289
+								<?php echo sanitize_text_field($label); ?>
290 290
 							</th>
291 291
 						<?php endforeach; ?>
292 292
 					</tr>
@@ -302,22 +302,22 @@  discard block
 block discarded – undo
302 302
 	 *
303 303
 	 * @param int $total
304 304
 	 */
305
-	public function print_navigation( $total ) {
305
+	public function print_navigation($total) {
306 306
 
307
-		if ( $total < 1 ) {
307
+		if ($total < 1) {
308 308
 
309 309
 			// Out-of-bounds, run the query again without LIMIT for total count.
310
-			$args  = array(
310
+			$args = array(
311 311
 				'customer_in' => get_current_user_id(),
312 312
 				'fields'      => 'id',
313 313
 			);
314 314
 
315
-			$count_query = new GetPaid_Subscriptions_Query( $args );
315
+			$count_query = new GetPaid_Subscriptions_Query($args);
316 316
 			$total       = $count_query->get_total();
317 317
 		}
318 318
 
319 319
 		// Abort if we do not have pages.
320
-		if ( 2 > $total ) {
320
+		if (2 > $total) {
321 321
 			return;
322 322
 		}
323 323
 
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 
330 330
 				echo getpaid_paginate_links(
331 331
 					array(
332
-						'base'    => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
332
+						'base'    => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
333 333
 						'format'  => '?paged=%#%',
334
-						'total'   => (int) ceil( $total / 10 ),
334
+						'total'   => (int) ceil($total / 10),
335 335
 					)
336 336
 				);
337 337
 			?>
@@ -347,29 +347,29 @@  discard block
 block discarded – undo
347 347
 	 *
348 348
 	 * @return array
349 349
 	 */
350
-	public function get_single_subscription_columns( $subscription ) {
350
+	public function get_single_subscription_columns($subscription) {
351 351
 
352 352
 		// Prepare subscription detail columns.
353 353
 		$fields = apply_filters(
354 354
 			'getpaid_single_subscription_details_fields',
355 355
 			array(
356
-				'status'           => __( 'Status', 'invoicing' ),
357
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
358
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
359
-				'start_date'       => __( 'Start date', 'invoicing' ),
360
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
361
-				'payments'         => __( 'Payments', 'invoicing' ),
362
-				'item'             => __( 'Item', 'invoicing' ),
356
+				'status'           => __('Status', 'invoicing'),
357
+				'initial_amount'   => __('Initial amount', 'invoicing'),
358
+				'recurring_amount' => __('Recurring amount', 'invoicing'),
359
+				'start_date'       => __('Start date', 'invoicing'),
360
+				'expiry_date'      => __('Next payment', 'invoicing'),
361
+				'payments'         => __('Payments', 'invoicing'),
362
+				'item'             => __('Item', 'invoicing'),
363 363
 			),
364 364
 			$subscription
365 365
 		);
366 366
 
367
-		if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
368
-			$fields['expiry_date'] = __( 'End date', 'invoicing' );
367
+		if (!$subscription->is_active() || $subscription->is_last_renewal()) {
368
+			$fields['expiry_date'] = __('End date', 'invoicing');
369 369
 		}
370 370
 
371
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
372
-			unset( $fields['initial_amount'] );
371
+		if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) {
372
+			unset($fields['initial_amount']);
373 373
 		}
374 374
 
375 375
 		return $fields;
@@ -382,16 +382,16 @@  discard block
 block discarded – undo
382 382
 	 *
383 383
 	 * @return string
384 384
 	 */
385
-	public function display_single_subscription( $subscription ) {
385
+	public function display_single_subscription($subscription) {
386 386
 
387 387
 		// Fetch the subscription.
388
-		$subscription = new WPInv_Subscription( (int) $subscription );
388
+		$subscription = new WPInv_Subscription((int) $subscription);
389 389
 
390
-		if ( ! $subscription->get_id() ) {
390
+		if (!$subscription->get_id()) {
391 391
 
392 392
 			return aui()->alert(
393 393
 				array(
394
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
394
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
395 395
 					'type'    => 'error',
396 396
 				)
397 397
 			);
@@ -399,11 +399,11 @@  discard block
 block discarded – undo
399 399
 		}
400 400
 
401 401
 		// Ensure that the user owns this subscription key.
402
-		if ( get_current_user_id() != $subscription->get_customer_id() ) {
402
+		if (get_current_user_id() != $subscription->get_customer_id()) {
403 403
 
404 404
 			return aui()->alert(
405 405
 				array(
406
-					'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ),
406
+					'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')),
407 407
 					'type'    => 'error',
408 408
 				)
409 409
 			);
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-resend-invoice.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-if ( ! defined( 'ABSPATH' ) ) {
8
+if (!defined('ABSPATH')) {
9 9
 	exit; // Exit if accessed directly
10 10
 }
11 11
 
@@ -19,12 +19,12 @@  discard block
 block discarded – undo
19 19
 	 *
20 20
 	 * @param WP_Post $post
21 21
 	 */
22
-    public static function output( $post ) {
22
+    public static function output($post) {
23 23
 
24 24
         // Fetch the invoice.
25
-        $invoice = new WPInv_Invoice( $post );
25
+        $invoice = new WPInv_Invoice($post);
26 26
 
27
-        do_action( 'wpinv_metabox_resend_invoice_before', $invoice );
27
+        do_action('wpinv_metabox_resend_invoice_before', $invoice);
28 28
 
29 29
         $email_url = esc_url(
30 30
             add_query_arg(
@@ -50,12 +50,12 @@  discard block
 block discarded – undo
50 50
         );
51 51
 
52 52
         ?>
53
-            <p class="wpi-meta-row wpi-resend-info"><?php _e( "This will send a copy of the invoice to the customer's email address.", 'invoicing' ); ?></p>
54
-            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e( 'Resend Invoice', 'invoicing' ); ?></a></p>
55
-            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
53
+            <p class="wpi-meta-row wpi-resend-info"><?php _e("This will send a copy of the invoice to the customer's email address.", 'invoicing'); ?></p>
54
+            <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e('Resend Invoice', 'invoicing'); ?></a></p>
55
+            <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
56 56
         <?php
57 57
 
58
-        do_action( 'wpinv_metabox_resend_invoice_after', $invoice );
58
+        do_action('wpinv_metabox_resend_invoice_after', $invoice);
59 59
 
60 60
     }
61 61
 
Please login to merge, or discard this patch.
includes/class-wpinv-legacy-invoice.php 1 patch
Spacing   +626 added lines, -626 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  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
 final class WPInv_Legacy_Invoice {
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * Invoice id.
18 18
      */
19
-    public $ID  = 0;
19
+    public $ID = 0;
20 20
 
21 21
     /**
22 22
      * The title of the invoice. Usually the invoice number.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     /**
133 133
      * The invoice status.
134 134
      */
135
-    public $status      = 'wpi-pending';
135
+    public $status = 'wpi-pending';
136 136
 
137 137
     /**
138 138
      * Same as self::$status.
@@ -259,17 +259,17 @@  discard block
 block discarded – undo
259 259
      */
260 260
     public $parent_invoice = 0;
261 261
     
262
-    public function __construct( $invoice_id = false ) {
263
-        if( empty( $invoice_id ) ) {
262
+    public function __construct($invoice_id = false) {
263
+        if (empty($invoice_id)) {
264 264
             return false;
265 265
         }
266 266
 
267
-        $this->setup_invoice( $invoice_id );
267
+        $this->setup_invoice($invoice_id);
268 268
     }
269 269
 
270
-    public function get( $key ) {
271
-        if ( method_exists( $this, 'get_' . $key ) ) {
272
-            $value = call_user_func( array( $this, 'get_' . $key ) );
270
+    public function get($key) {
271
+        if (method_exists($this, 'get_' . $key)) {
272
+            $value = call_user_func(array($this, 'get_' . $key));
273 273
         } else {
274 274
             $value = $this->$key;
275 275
         }
@@ -277,51 +277,51 @@  discard block
 block discarded – undo
277 277
         return $value;
278 278
     }
279 279
 
280
-    public function set( $key, $value ) {
281
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
280
+    public function set($key, $value) {
281
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
282 282
 
283
-        if ( $key === 'status' ) {
283
+        if ($key === 'status') {
284 284
             $this->old_status = $this->status;
285 285
         }
286 286
 
287
-        if ( ! in_array( $key, $ignore ) ) {
288
-            $this->pending[ $key ] = $value;
287
+        if (!in_array($key, $ignore)) {
288
+            $this->pending[$key] = $value;
289 289
         }
290 290
 
291
-        if( '_ID' !== $key ) {
291
+        if ('_ID' !== $key) {
292 292
             $this->$key = $value;
293 293
         }
294 294
     }
295 295
 
296
-    public function _isset( $name ) {
297
-        if ( property_exists( $this, $name) ) {
298
-            return false === empty( $this->$name );
296
+    public function _isset($name) {
297
+        if (property_exists($this, $name)) {
298
+            return false === empty($this->$name);
299 299
         } else {
300 300
             return null;
301 301
         }
302 302
     }
303 303
 
304
-    private function setup_invoice( $invoice_id ) {
304
+    private function setup_invoice($invoice_id) {
305 305
         $this->pending = array();
306 306
 
307
-        if ( empty( $invoice_id ) ) {
307
+        if (empty($invoice_id)) {
308 308
             return false;
309 309
         }
310 310
 
311
-        $invoice = get_post( $invoice_id );
311
+        $invoice = get_post($invoice_id);
312 312
 
313
-        if( !$invoice || is_wp_error( $invoice ) ) {
313
+        if (!$invoice || is_wp_error($invoice)) {
314 314
             return false;
315 315
         }
316 316
 
317
-        if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) {
317
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
318 318
             return false;
319 319
         }
320 320
 
321
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id );
321
+        do_action('wpinv_pre_setup_invoice', $this, $invoice_id);
322 322
 
323 323
         // Primary Identifier
324
-        $this->ID              = absint( $invoice_id );
324
+        $this->ID              = absint($invoice_id);
325 325
         $this->post_type       = $invoice->post_type;
326 326
 
327 327
         // We have a payment, get the generic payment_meta item to reduce calls to it
@@ -331,14 +331,14 @@  discard block
 block discarded – undo
331 331
         $this->completed_date  = $this->setup_completed_date();
332 332
         $this->status          = $invoice->post_status;
333 333
 
334
-        if ( 'future' == $this->status ) {
334
+        if ('future' == $this->status) {
335 335
             $this->status = 'publish';
336 336
         }
337 337
 
338 338
         $this->post_status     = $this->status;
339 339
         $this->mode            = $this->setup_mode();
340 340
         $this->parent_invoice  = $invoice->post_parent;
341
-        $this->post_name       = $this->setup_post_name( $invoice );
341
+        $this->post_name       = $this->setup_post_name($invoice);
342 342
         $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
343 343
 
344 344
         // Items
@@ -361,8 +361,8 @@  discard block
 block discarded – undo
361 361
         
362 362
         // User based
363 363
         $this->ip              = $this->setup_ip();
364
-        $this->user_id         = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id();
365
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
364
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id();
365
+        $this->email           = get_the_author_meta('email', $this->user_id);
366 366
 
367 367
         $this->user_info       = $this->setup_user_info();
368 368
 
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
         $this->company         = $this->user_info['company'];
372 372
         $this->vat_number      = $this->user_info['vat_number'];
373 373
         $this->vat_rate        = $this->user_info['vat_rate'];
374
-        $this->adddress_confirmed  = $this->user_info['adddress_confirmed'];
374
+        $this->adddress_confirmed = $this->user_info['adddress_confirmed'];
375 375
         $this->address         = $this->user_info['address'];
376 376
         $this->city            = $this->user_info['city'];
377 377
         $this->country         = $this->user_info['country'];
@@ -386,39 +386,39 @@  discard block
 block discarded – undo
386 386
         // Other Identifiers
387 387
         $this->key             = $this->setup_invoice_key();
388 388
         $this->number          = $this->setup_invoice_number();
389
-        $this->title           = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
389
+        $this->title           = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
390 390
         
391
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
391
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
392 392
         
393 393
         // Allow extensions to add items to this object via hook
394
-        do_action( 'wpinv_setup_invoice', $this, $invoice_id );
394
+        do_action('wpinv_setup_invoice', $this, $invoice_id);
395 395
 
396 396
         return true;
397 397
     }
398 398
 
399
-    private function setup_status_nicename( $status ) {
400
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
399
+    private function setup_status_nicename($status) {
400
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
401 401
 
402
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
403
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
402
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
403
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
404 404
         }
405
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
405
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
406 406
 
407
-        return apply_filters( 'setup_status_nicename', $status );
407
+        return apply_filters('setup_status_nicename', $status);
408 408
     }
409 409
 
410
-    private function setup_post_name( $post = NULL ) {
410
+    private function setup_post_name($post = NULL) {
411 411
         global $wpdb;
412 412
         
413 413
         $post_name = '';
414 414
         
415
-        if ( !empty( $post ) ) {
416
-            if( !empty( $post->post_name ) ) {
415
+        if (!empty($post)) {
416
+            if (!empty($post->post_name)) {
417 417
                 $post_name = $post->post_name;
418
-            } else if ( !empty( $post->ID ) ) {
419
-                $post_name = wpinv_generate_post_name( $post->ID );
418
+            } else if (!empty($post->ID)) {
419
+                $post_name = wpinv_generate_post_name($post->ID);
420 420
 
421
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
421
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
422 422
             }
423 423
         }
424 424
 
@@ -426,12 +426,12 @@  discard block
 block discarded – undo
426 426
     }
427 427
     
428 428
     private function setup_due_date() {
429
-        $due_date = $this->get_meta( '_wpinv_due_date' );
429
+        $due_date = $this->get_meta('_wpinv_due_date');
430 430
         
431
-        if ( empty( $due_date ) ) {
432
-            $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) );
433
-            $due_date = date_i18n( 'Y-m-d', $overdue_time );
434
-        } else if ( $due_date == 'none' ) {
431
+        if (empty($due_date)) {
432
+            $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days')));
433
+            $due_date = date_i18n('Y-m-d', $overdue_time);
434
+        } else if ($due_date == 'none') {
435 435
             $due_date = '';
436 436
         }
437 437
         
@@ -439,67 +439,67 @@  discard block
 block discarded – undo
439 439
     }
440 440
     
441 441
     private function setup_completed_date() {
442
-        $invoice = get_post( $this->ID );
442
+        $invoice = get_post($this->ID);
443 443
 
444
-        if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) {
444
+        if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) {
445 445
             return false; // This invoice was never paid
446 446
         }
447 447
 
448
-        $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date;
448
+        $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date;
449 449
 
450 450
         return $date;
451 451
     }
452 452
     
453 453
     private function setup_cart_details() {
454
-        $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array();
454
+        $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array();
455 455
         return $cart_details;
456 456
     }
457 457
     
458 458
     public function array_convert() {
459
-        return get_object_vars( $this );
459
+        return get_object_vars($this);
460 460
     }
461 461
     
462 462
     private function setup_items() {
463
-        $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array();
463
+        $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array();
464 464
         return $items;
465 465
     }
466 466
     
467 467
     private function setup_fees() {
468
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
468
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
469 469
         return $payment_fees;
470 470
     }
471 471
         
472 472
     private function setup_currency() {
473
-        $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this );
473
+        $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this);
474 474
         return $currency;
475 475
     }
476 476
     
477 477
     private function setup_discount() {
478 478
         //$discount = $this->get_meta( '_wpinv_discount', true );
479
-        $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total );
480
-        if ( $discount < 0 ) {
479
+        $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total);
480
+        if ($discount < 0) {
481 481
             $discount = 0;
482 482
         }
483
-        $discount = wpinv_round_amount( $discount );
483
+        $discount = wpinv_round_amount($discount);
484 484
         
485 485
         return $discount;
486 486
     }
487 487
     
488 488
     private function setup_discount_code() {
489
-        $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true );
489
+        $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true);
490 490
         return $discount_code;
491 491
     }
492 492
     
493 493
     private function setup_tax() {
494 494
 
495
-        $tax = $this->get_meta( '_wpinv_tax', true );
495
+        $tax = $this->get_meta('_wpinv_tax', true);
496 496
 
497 497
         // We don't have tax as it's own meta and no meta was passed
498
-        if ( '' === $tax ) {            
499
-            $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0;
498
+        if ('' === $tax) {            
499
+            $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0;
500 500
         }
501 501
         
502
-        if ( $tax < 0 || ! $this->is_taxable() ) {
502
+        if ($tax < 0 || !$this->is_taxable()) {
503 503
             $tax = 0;
504 504
         }
505 505
 
@@ -510,16 +510,16 @@  discard block
 block discarded – undo
510 510
      * If taxes are enabled, allow users to enable/disable taxes per invoice.
511 511
      */
512 512
     private function setup_is_taxable() {
513
-        return (int) $this->get_meta( '_wpinv_disable_taxes', true );
513
+        return (int) $this->get_meta('_wpinv_disable_taxes', true);
514 514
     }
515 515
 
516 516
     private function setup_subtotal() {
517 517
         $subtotal     = 0;
518 518
         $cart_details = $this->cart_details;
519 519
 
520
-        if ( is_array( $cart_details ) ) {
521
-            foreach ( $cart_details as $item ) {
522
-                if ( isset( $item['subtotal'] ) ) {
520
+        if (is_array($cart_details)) {
521
+            foreach ($cart_details as $item) {
522
+                if (isset($item['subtotal'])) {
523 523
                     $subtotal += $item['subtotal'];
524 524
                 }
525 525
             }
@@ -533,23 +533,23 @@  discard block
 block discarded – undo
533 533
     }
534 534
 
535 535
     private function setup_discounts() {
536
-        $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array();
536
+        $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array();
537 537
         return $discounts;
538 538
     }
539 539
     
540 540
     private function setup_total() {
541
-        $amount = $this->get_meta( '_wpinv_total', true );
541
+        $amount = $this->get_meta('_wpinv_total', true);
542 542
 
543
-        if ( empty( $amount ) && '0.00' != $amount ) {
544
-            $meta   = $this->get_meta( '_wpinv_payment_meta', true );
545
-            $meta   = maybe_unserialize( $meta );
543
+        if (empty($amount) && '0.00' != $amount) {
544
+            $meta   = $this->get_meta('_wpinv_payment_meta', true);
545
+            $meta   = maybe_unserialize($meta);
546 546
 
547
-            if ( isset( $meta['amount'] ) ) {
547
+            if (isset($meta['amount'])) {
548 548
                 $amount = $meta['amount'];
549 549
             }
550 550
         }
551 551
 
552
-        if($amount < 0){
552
+        if ($amount < 0) {
553 553
             $amount = 0;
554 554
         }
555 555
 
@@ -557,13 +557,13 @@  discard block
 block discarded – undo
557 557
     }
558 558
     
559 559
     private function setup_mode() {
560
-        return $this->get_meta( '_wpinv_mode' );
560
+        return $this->get_meta('_wpinv_mode');
561 561
     }
562 562
 
563 563
     private function setup_gateway() {
564
-        $gateway = $this->get_meta( '_wpinv_gateway' );
564
+        $gateway = $this->get_meta('_wpinv_gateway');
565 565
         
566
-        if ( empty( $gateway ) && 'publish' === $this->status ) {
566
+        if (empty($gateway) && 'publish' === $this->status) {
567 567
             $gateway = 'manual';
568 568
         }
569 569
         
@@ -571,23 +571,23 @@  discard block
 block discarded – undo
571 571
     }
572 572
 
573 573
     private function setup_gateway_title() {
574
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
574
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
575 575
         return $gateway_title;
576 576
     }
577 577
 
578 578
     private function setup_transaction_id() {
579
-        $transaction_id = $this->get_meta( '_wpinv_transaction_id' );
579
+        $transaction_id = $this->get_meta('_wpinv_transaction_id');
580 580
 
581
-        if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) {
581
+        if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) {
582 582
             $gateway        = $this->gateway;
583
-            $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID );
583
+            $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID);
584 584
         }
585 585
 
586 586
         return $transaction_id;
587 587
     }
588 588
 
589 589
     private function setup_ip() {
590
-        $ip = $this->get_meta( '_wpinv_user_ip' );
590
+        $ip = $this->get_meta('_wpinv_user_ip');
591 591
         return $ip;
592 592
     }
593 593
 
@@ -597,62 +597,62 @@  discard block
 block discarded – undo
597 597
     ///}
598 598
         
599 599
     private function setup_first_name() {
600
-        $first_name = $this->get_meta( '_wpinv_first_name' );
600
+        $first_name = $this->get_meta('_wpinv_first_name');
601 601
         return $first_name;
602 602
     }
603 603
     
604 604
     private function setup_last_name() {
605
-        $last_name = $this->get_meta( '_wpinv_last_name' );
605
+        $last_name = $this->get_meta('_wpinv_last_name');
606 606
         return $last_name;
607 607
     }
608 608
     
609 609
     private function setup_company() {
610
-        $company = $this->get_meta( '_wpinv_company' );
610
+        $company = $this->get_meta('_wpinv_company');
611 611
         return $company;
612 612
     }
613 613
     
614 614
     private function setup_vat_number() {
615
-        $vat_number = $this->get_meta( '_wpinv_vat_number' );
615
+        $vat_number = $this->get_meta('_wpinv_vat_number');
616 616
         return $vat_number;
617 617
     }
618 618
     
619 619
     private function setup_vat_rate() {
620
-        $vat_rate = $this->get_meta( '_wpinv_vat_rate' );
620
+        $vat_rate = $this->get_meta('_wpinv_vat_rate');
621 621
         return $vat_rate;
622 622
     }
623 623
     
624 624
     private function setup_adddress_confirmed() {
625
-        $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' );
625
+        $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed');
626 626
         return $adddress_confirmed;
627 627
     }
628 628
     
629 629
     private function setup_phone() {
630
-        $phone = $this->get_meta( '_wpinv_phone' );
630
+        $phone = $this->get_meta('_wpinv_phone');
631 631
         return $phone;
632 632
     }
633 633
     
634 634
     private function setup_address() {
635
-        $address = $this->get_meta( '_wpinv_address', true );
635
+        $address = $this->get_meta('_wpinv_address', true);
636 636
         return $address;
637 637
     }
638 638
     
639 639
     private function setup_city() {
640
-        $city = $this->get_meta( '_wpinv_city', true );
640
+        $city = $this->get_meta('_wpinv_city', true);
641 641
         return $city;
642 642
     }
643 643
     
644 644
     private function setup_country() {
645
-        $country = $this->get_meta( '_wpinv_country', true );
645
+        $country = $this->get_meta('_wpinv_country', true);
646 646
         return $country;
647 647
     }
648 648
     
649 649
     private function setup_state() {
650
-        $state = $this->get_meta( '_wpinv_state', true );
650
+        $state = $this->get_meta('_wpinv_state', true);
651 651
         return $state;
652 652
     }
653 653
     
654 654
     private function setup_zip() {
655
-        $zip = $this->get_meta( '_wpinv_zip', true );
655
+        $zip = $this->get_meta('_wpinv_zip', true);
656 656
         return $zip;
657 657
     }
658 658
 
@@ -661,7 +661,7 @@  discard block
 block discarded – undo
661 661
             'user_id'        => $this->user_id,
662 662
             'first_name'     => $this->first_name,
663 663
             'last_name'      => $this->last_name,
664
-            'email'          => get_the_author_meta( 'email', $this->user_id ),
664
+            'email'          => get_the_author_meta('email', $this->user_id),
665 665
             'phone'          => $this->phone,
666 666
             'address'        => $this->address,
667 667
             'city'           => $this->city,
@@ -676,12 +676,12 @@  discard block
 block discarded – undo
676 676
         );
677 677
         
678 678
         $user_info = array();
679
-        if ( isset( $this->payment_meta['user_info'] ) ) {
680
-            $user_info = maybe_unserialize( $this->payment_meta['user_info'] );
679
+        if (isset($this->payment_meta['user_info'])) {
680
+            $user_info = maybe_unserialize($this->payment_meta['user_info']);
681 681
             
682
-            if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) {
682
+            if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) {
683 683
                 $this->user_id = $post->post_author;
684
-                $this->email = get_the_author_meta( 'email', $this->user_id );
684
+                $this->email = get_the_author_meta('email', $this->user_id);
685 685
                 
686 686
                 $user_info['user_id'] = $this->user_id;
687 687
                 $user_info['email'] = $this->email;
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
             }
691 691
         }
692 692
         
693
-        $user_info    = wp_parse_args( $user_info, $defaults );
693
+        $user_info = wp_parse_args($user_info, $defaults);
694 694
         
695 695
         // Get the user, but only if it's been created
696
-        $user = get_userdata( $this->user_id );
696
+        $user = get_userdata($this->user_id);
697 697
         
698
-        if ( !empty( $user ) && $user->ID > 0 ) {
699
-            if ( empty( $user_info ) ) {
698
+        if (!empty($user) && $user->ID > 0) {
699
+            if (empty($user_info)) {
700 700
                 $user_info = array(
701 701
                     'user_id'    => $user->ID,
702 702
                     'first_name' => $user->first_name,
@@ -705,23 +705,23 @@  discard block
 block discarded – undo
705 705
                     'discount'   => '',
706 706
                 );
707 707
             } else {
708
-                foreach ( $user_info as $key => $value ) {
709
-                    if ( ! empty( $value ) ) {
708
+                foreach ($user_info as $key => $value) {
709
+                    if (!empty($value)) {
710 710
                         continue;
711 711
                     }
712 712
 
713
-                    switch( $key ) {
713
+                    switch ($key) {
714 714
                         case 'user_id':
715
-                            $user_info[ $key ] = $user->ID;
715
+                            $user_info[$key] = $user->ID;
716 716
                             break;
717 717
                         case 'first_name':
718
-                            $user_info[ $key ] = $user->first_name;
718
+                            $user_info[$key] = $user->first_name;
719 719
                             break;
720 720
                         case 'last_name':
721
-                            $user_info[ $key ] = $user->last_name;
721
+                            $user_info[$key] = $user->last_name;
722 722
                             break;
723 723
                         case 'email':
724
-                            $user_info[ $key ] = $user->user_email;
724
+                            $user_info[$key] = $user->user_email;
725 725
                             break;
726 726
                     }
727 727
                 }
@@ -732,25 +732,25 @@  discard block
 block discarded – undo
732 732
     }
733 733
 
734 734
     private function setup_invoice_key() {
735
-        $key = $this->get_meta( '_wpinv_key', true );
735
+        $key = $this->get_meta('_wpinv_key', true);
736 736
         
737 737
         return $key;
738 738
     }
739 739
 
740 740
     private function setup_invoice_number() {
741
-        $number = $this->get_meta( '_wpinv_number', true );
741
+        $number = $this->get_meta('_wpinv_number', true);
742 742
 
743
-        if ( !$number ) {
743
+        if (!$number) {
744 744
             $number = $this->ID;
745 745
 
746
-            if ( $this->status == 'auto-draft' ) {
747
-                if ( wpinv_sequential_number_active( $this->post_type ) ) {
748
-                    $next_number = wpinv_get_next_invoice_number( $this->post_type );
746
+            if ($this->status == 'auto-draft') {
747
+                if (wpinv_sequential_number_active($this->post_type)) {
748
+                    $next_number = wpinv_get_next_invoice_number($this->post_type);
749 749
                     $number      = $next_number;
750 750
                 }
751 751
             }
752 752
             
753
-            $number = wpinv_format_invoice_number( $number, $this->post_type );
753
+            $number = wpinv_format_invoice_number($number, $this->post_type);
754 754
         }
755 755
 
756 756
         return $number;
@@ -759,10 +759,10 @@  discard block
 block discarded – undo
759 759
     private function insert_invoice() {
760 760
         global $wpdb;
761 761
 
762
-        if ( empty( $this->post_type ) ) {
763
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
762
+        if (empty($this->post_type)) {
763
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
764 764
                 $this->post_type = $post_type;
765
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
765
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
766 766
                 $this->post_type = $post_type;
767 767
             } else {
768 768
                 $this->post_type = 'wpi_invoice';
@@ -770,16 +770,16 @@  discard block
 block discarded – undo
770 770
         }
771 771
 
772 772
         $invoice_number = $this->ID;
773
-        if ( $number = $this->get_meta( '_wpinv_number', true ) ) {
773
+        if ($number = $this->get_meta('_wpinv_number', true)) {
774 774
             $invoice_number = $number;
775 775
         }
776 776
 
777
-        if ( empty( $this->key ) ) {
777
+        if (empty($this->key)) {
778 778
             $this->key = self::generate_key();
779 779
             $this->pending['key'] = $this->key;
780 780
         }
781 781
 
782
-        if ( empty( $this->ip ) ) {
782
+        if (empty($this->ip)) {
783 783
             $this->ip = wpinv_get_ip();
784 784
             $this->pending['ip'] = $this->ip;
785 785
         }
@@ -816,60 +816,60 @@  discard block
 block discarded – undo
816 816
                         'post_status'   => $this->status,
817 817
                         'post_author'   => $this->user_id,
818 818
                         'post_type'     => $this->post_type,
819
-                        'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
820
-                        'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
819
+                        'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
820
+                        'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
821 821
                         'post_parent'   => $this->parent_invoice,
822 822
                     );
823
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
823
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
824 824
 
825 825
         // Create a blank invoice
826
-        if ( !empty( $this->ID ) ) {
827
-            $args['ID']         = $this->ID;
826
+        if (!empty($this->ID)) {
827
+            $args['ID'] = $this->ID;
828 828
 
829
-            $invoice_id = wp_update_post( $args, true );
829
+            $invoice_id = wp_update_post($args, true);
830 830
         } else {
831
-            $invoice_id = wp_insert_post( $args, true );
831
+            $invoice_id = wp_insert_post($args, true);
832 832
         }
833 833
 
834
-        if ( is_wp_error( $invoice_id ) ) {
834
+        if (is_wp_error($invoice_id)) {
835 835
             return false;
836 836
         }
837 837
 
838
-        if ( !empty( $invoice_id ) ) {
838
+        if (!empty($invoice_id)) {
839 839
             $this->ID  = $invoice_id;
840 840
             $this->_ID = $invoice_id;
841 841
 
842
-            $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data );
843
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
844
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
845
-                foreach( $this->fees as $fee ) {
846
-                    $this->increase_fees( $fee['amount'] );
842
+            $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data);
843
+            if (!empty($this->payment_meta['fees'])) {
844
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
845
+                foreach ($this->fees as $fee) {
846
+                    $this->increase_fees($fee['amount']);
847 847
                 }
848 848
             }
849 849
 
850
-            $this->update_meta( '_wpinv_payment_meta', $this->payment_meta );    
850
+            $this->update_meta('_wpinv_payment_meta', $this->payment_meta);    
851 851
             $this->new = true;
852 852
         }
853 853
 
854 854
         return $this->ID;
855 855
     }
856 856
 
857
-    public function save( $setup = false ) {
857
+    public function save($setup = false) {
858 858
         
859 859
         $saved = false;
860
-        if ( empty( $this->items ) ) {
860
+        if (empty($this->items)) {
861 861
             return $saved; // Don't save empty invoice.
862 862
         }
863 863
         
864
-        if ( empty( $this->key ) ) {
864
+        if (empty($this->key)) {
865 865
             $this->key = self::generate_key();
866 866
             $this->pending['key'] = $this->key;
867 867
         }
868 868
         
869
-        if ( empty( $this->ID ) ) {
869
+        if (empty($this->ID)) {
870 870
             $invoice_id = $this->insert_invoice();
871 871
 
872
-            if ( false === $invoice_id ) {
872
+            if (false === $invoice_id) {
873 873
                 $saved = false;
874 874
             } else {
875 875
                 $this->ID = $invoice_id;
@@ -877,27 +877,27 @@  discard block
 block discarded – undo
877 877
         }
878 878
 
879 879
         // If we have something pending, let's save it
880
-        if ( !empty( $this->pending ) ) {
880
+        if (!empty($this->pending)) {
881 881
             $total_increase = 0;
882 882
             $total_decrease = 0;
883 883
 
884
-            foreach ( $this->pending as $key => $value ) {
885
-                switch( $key ) {
884
+            foreach ($this->pending as $key => $value) {
885
+                switch ($key) {
886 886
                     case 'items':
887 887
                         // Update totals for pending items
888
-                        foreach ( $this->pending[ $key ] as $item ) {
889
-                            switch( $item['action'] ) {
888
+                        foreach ($this->pending[$key] as $item) {
889
+                            switch ($item['action']) {
890 890
                                 case 'add':
891 891
                                     $price = $item['price'];
892 892
                                     $taxes = $item['tax'];
893 893
 
894
-                                    if ( 'publish' === $this->status ) {
894
+                                    if ('publish' === $this->status) {
895 895
                                         $total_increase += $price;
896 896
                                     }
897 897
                                     break;
898 898
 
899 899
                                 case 'remove':
900
-                                    if ( 'publish' === $this->status ) {
900
+                                    if ('publish' === $this->status) {
901 901
                                         $total_decrease += $item['price'];
902 902
                                     }
903 903
                                     break;
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
                         }
906 906
                         break;
907 907
                     case 'fees':
908
-                        if ( 'publish' !== $this->status ) {
908
+                        if ('publish' !== $this->status) {
909 909
                             break;
910 910
                         }
911 911
 
912
-                        if ( empty( $this->pending[ $key ] ) ) {
912
+                        if (empty($this->pending[$key])) {
913 913
                             break;
914 914
                         }
915 915
 
916
-                        foreach ( $this->pending[ $key ] as $fee ) {
917
-                            switch( $fee['action'] ) {
916
+                        foreach ($this->pending[$key] as $fee) {
917
+                            switch ($fee['action']) {
918 918
                                 case 'add':
919 919
                                     $total_increase += $fee['amount'];
920 920
                                     break;
@@ -926,86 +926,86 @@  discard block
 block discarded – undo
926 926
                         }
927 927
                         break;
928 928
                     case 'status':
929
-                        $this->update_status( $this->status );
929
+                        $this->update_status($this->status);
930 930
                         break;
931 931
                     case 'gateway':
932
-                        $this->update_meta( '_wpinv_gateway', $this->gateway );
932
+                        $this->update_meta('_wpinv_gateway', $this->gateway);
933 933
                         break;
934 934
                     case 'mode':
935
-                        $this->update_meta( '_wpinv_mode', $this->mode );
935
+                        $this->update_meta('_wpinv_mode', $this->mode);
936 936
                         break;
937 937
                     case 'transaction_id':
938
-                        $this->update_meta( '_wpinv_transaction_id', $this->transaction_id );
938
+                        $this->update_meta('_wpinv_transaction_id', $this->transaction_id);
939 939
                         break;
940 940
                     case 'ip':
941
-                        $this->update_meta( '_wpinv_user_ip', $this->ip );
941
+                        $this->update_meta('_wpinv_user_ip', $this->ip);
942 942
                         break;
943 943
                     ///case 'user_id':
944 944
                         ///$this->update_meta( '_wpinv_user_id', $this->user_id );
945 945
                         ///$this->user_info['user_id'] = $this->user_id;
946 946
                         ///break;
947 947
                     case 'first_name':
948
-                        $this->update_meta( '_wpinv_first_name', $this->first_name );
948
+                        $this->update_meta('_wpinv_first_name', $this->first_name);
949 949
                         $this->user_info['first_name'] = $this->first_name;
950 950
                         break;
951 951
                     case 'last_name':
952
-                        $this->update_meta( '_wpinv_last_name', $this->last_name );
952
+                        $this->update_meta('_wpinv_last_name', $this->last_name);
953 953
                         $this->user_info['last_name'] = $this->last_name;
954 954
                         break;
955 955
                     case 'phone':
956
-                        $this->update_meta( '_wpinv_phone', $this->phone );
956
+                        $this->update_meta('_wpinv_phone', $this->phone);
957 957
                         $this->user_info['phone'] = $this->phone;
958 958
                         break;
959 959
                     case 'address':
960
-                        $this->update_meta( '_wpinv_address', $this->address );
960
+                        $this->update_meta('_wpinv_address', $this->address);
961 961
                         $this->user_info['address'] = $this->address;
962 962
                         break;
963 963
                     case 'city':
964
-                        $this->update_meta( '_wpinv_city', $this->city );
964
+                        $this->update_meta('_wpinv_city', $this->city);
965 965
                         $this->user_info['city'] = $this->city;
966 966
                         break;
967 967
                     case 'country':
968
-                        $this->update_meta( '_wpinv_country', $this->country );
968
+                        $this->update_meta('_wpinv_country', $this->country);
969 969
                         $this->user_info['country'] = $this->country;
970 970
                         break;
971 971
                     case 'state':
972
-                        $this->update_meta( '_wpinv_state', $this->state );
972
+                        $this->update_meta('_wpinv_state', $this->state);
973 973
                         $this->user_info['state'] = $this->state;
974 974
                         break;
975 975
                     case 'zip':
976
-                        $this->update_meta( '_wpinv_zip', $this->zip );
976
+                        $this->update_meta('_wpinv_zip', $this->zip);
977 977
                         $this->user_info['zip'] = $this->zip;
978 978
                         break;
979 979
                     case 'company':
980
-                        $this->update_meta( '_wpinv_company', $this->company );
980
+                        $this->update_meta('_wpinv_company', $this->company);
981 981
                         $this->user_info['company'] = $this->company;
982 982
                         break;
983 983
                     case 'vat_number':
984
-                        $this->update_meta( '_wpinv_vat_number', $this->vat_number );
984
+                        $this->update_meta('_wpinv_vat_number', $this->vat_number);
985 985
                         $this->user_info['vat_number'] = $this->vat_number;
986 986
                         
987
-                        $vat_info = getpaid_session()->get( 'user_vat_data' );
988
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
989
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
990
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
991
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
987
+                        $vat_info = getpaid_session()->get('user_vat_data');
988
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
989
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
990
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
991
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
992 992
                         }
993 993
     
994 994
                         break;
995 995
                     case 'vat_rate':
996
-                        $this->update_meta( '_wpinv_vat_rate', $this->vat_rate );
996
+                        $this->update_meta('_wpinv_vat_rate', $this->vat_rate);
997 997
                         $this->user_info['vat_rate'] = $this->vat_rate;
998 998
                         break;
999 999
                     case 'adddress_confirmed':
1000
-                        $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed );
1000
+                        $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed);
1001 1001
                         $this->user_info['adddress_confirmed'] = $this->adddress_confirmed;
1002 1002
                         break;
1003 1003
                     
1004 1004
                     case 'key':
1005
-                        $this->update_meta( '_wpinv_key', $this->key );
1005
+                        $this->update_meta('_wpinv_key', $this->key);
1006 1006
                         break;
1007 1007
                     case 'disable_taxes':
1008
-                        $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes );
1008
+                        $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes);
1009 1009
                         break;
1010 1010
                     case 'date':
1011 1011
                         $args = array(
@@ -1014,49 +1014,49 @@  discard block
 block discarded – undo
1014 1014
                             'edit_date' => true,
1015 1015
                         );
1016 1016
 
1017
-                        wp_update_post( $args );
1017
+                        wp_update_post($args);
1018 1018
                         break;
1019 1019
                     case 'due_date':
1020
-                        if ( empty( $this->due_date ) ) {
1020
+                        if (empty($this->due_date)) {
1021 1021
                             $this->due_date = 'none';
1022 1022
                         }
1023 1023
                         
1024
-                        $this->update_meta( '_wpinv_due_date', $this->due_date );
1024
+                        $this->update_meta('_wpinv_due_date', $this->due_date);
1025 1025
                         break;
1026 1026
                     case 'completed_date':
1027
-                        $this->update_meta( '_wpinv_completed_date', $this->completed_date );
1027
+                        $this->update_meta('_wpinv_completed_date', $this->completed_date);
1028 1028
                         break;
1029 1029
                     case 'discounts':
1030
-                        if ( ! is_array( $this->discounts ) ) {
1031
-                            $this->discounts = explode( ',', $this->discounts );
1030
+                        if (!is_array($this->discounts)) {
1031
+                            $this->discounts = explode(',', $this->discounts);
1032 1032
                         }
1033 1033
 
1034
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
1034
+                        $this->user_info['discount'] = implode(',', $this->discounts);
1035 1035
                         break;
1036 1036
                     case 'discount':
1037
-                        $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) );
1037
+                        $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount));
1038 1038
                         break;
1039 1039
                     case 'discount_code':
1040
-                        $this->update_meta( '_wpinv_discount_code', $this->discount_code );
1040
+                        $this->update_meta('_wpinv_discount_code', $this->discount_code);
1041 1041
                         break;
1042 1042
                     case 'parent_invoice':
1043 1043
                         $args = array(
1044 1044
                             'ID'          => $this->ID,
1045 1045
                             'post_parent' => $this->parent_invoice,
1046 1046
                         );
1047
-                        wp_update_post( $args );
1047
+                        wp_update_post($args);
1048 1048
                         break;
1049 1049
                     default:
1050
-                        do_action( 'wpinv_save', $this, $key );
1050
+                        do_action('wpinv_save', $this, $key);
1051 1051
                         break;
1052 1052
                 }
1053 1053
             }
1054 1054
 
1055
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1056
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1057
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1055
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1056
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1057
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1058 1058
             
1059
-            $this->items    = array_values( $this->items );
1059
+            $this->items = array_values($this->items);
1060 1060
             
1061 1061
             $new_meta = array(
1062 1062
                 'items'         => $this->items,
@@ -1067,12 +1067,12 @@  discard block
 block discarded – undo
1067 1067
             );
1068 1068
             
1069 1069
             $meta        = $this->get_meta();
1070
-            $merged_meta = array_merge( $meta, $new_meta );
1070
+            $merged_meta = array_merge($meta, $new_meta);
1071 1071
 
1072 1072
             // Only save the payment meta if it's changed
1073
-            if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) {
1074
-                $updated     = $this->update_meta( '_wpinv_payment_meta', $merged_meta );
1075
-                if ( false !== $updated ) {
1073
+            if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
1074
+                $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta);
1075
+                if (false !== $updated) {
1076 1076
                     $saved = true;
1077 1077
                 }
1078 1078
             }
@@ -1080,15 +1080,15 @@  discard block
 block discarded – undo
1080 1080
             $this->pending = array();
1081 1081
             $saved         = true;
1082 1082
         } else {
1083
-            $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) );
1084
-            $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) );
1085
-            $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) );
1083
+            $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal));
1084
+            $this->update_meta('_wpinv_total', wpinv_round_amount($this->total));
1085
+            $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax));
1086 1086
         }
1087 1087
         
1088
-        do_action( 'wpinv_invoice_save', $this, $saved );
1088
+        do_action('wpinv_invoice_save', $this, $saved);
1089 1089
 
1090
-        if ( true === $saved || $setup ) {
1091
-            $this->setup_invoice( $this->ID );
1090
+        if (true === $saved || $setup) {
1091
+            $this->setup_invoice($this->ID);
1092 1092
         }
1093 1093
         
1094 1094
         $this->refresh_item_ids();
@@ -1096,7 +1096,7 @@  discard block
 block discarded – undo
1096 1096
         return $saved;
1097 1097
     }
1098 1098
     
1099
-    public function add_fee( $args, $global = true ) {
1099
+    public function add_fee($args, $global = true) {
1100 1100
         $default_args = array(
1101 1101
             'label'       => '',
1102 1102
             'amount'      => 0,
@@ -1106,75 +1106,75 @@  discard block
 block discarded – undo
1106 1106
             'item_id'     => 0,
1107 1107
         );
1108 1108
 
1109
-        $fee = wp_parse_args( $args, $default_args );
1109
+        $fee = wp_parse_args($args, $default_args);
1110 1110
         
1111
-        if ( empty( $fee['label'] ) ) {
1111
+        if (empty($fee['label'])) {
1112 1112
             return false;
1113 1113
         }
1114 1114
         
1115
-        $fee['id']  = sanitize_title( $fee['label'] );
1115
+        $fee['id'] = sanitize_title($fee['label']);
1116 1116
         
1117
-        $this->fees[]               = $fee;
1117
+        $this->fees[] = $fee;
1118 1118
         
1119 1119
         $added_fee               = $fee;
1120 1120
         $added_fee['action']     = 'add';
1121 1121
         $this->pending['fees'][] = $added_fee;
1122
-        reset( $this->fees );
1122
+        reset($this->fees);
1123 1123
 
1124
-        $this->increase_fees( $fee['amount'] );
1124
+        $this->increase_fees($fee['amount']);
1125 1125
         return true;
1126 1126
     }
1127 1127
 
1128
-    public function remove_fee( $key ) {
1128
+    public function remove_fee($key) {
1129 1129
         $removed = false;
1130 1130
 
1131
-        if ( is_numeric( $key ) ) {
1132
-            $removed = $this->remove_fee_by( 'index', $key );
1131
+        if (is_numeric($key)) {
1132
+            $removed = $this->remove_fee_by('index', $key);
1133 1133
         }
1134 1134
 
1135 1135
         return $removed;
1136 1136
     }
1137 1137
 
1138
-    public function remove_fee_by( $key, $value, $global = false ) {
1139
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
1138
+    public function remove_fee_by($key, $value, $global = false) {
1139
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
1140 1140
             'index', 'label', 'amount', 'type',
1141
-        ) );
1141
+        ));
1142 1142
 
1143
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
1143
+        if (!in_array($key, $allowed_fee_keys)) {
1144 1144
             return false;
1145 1145
         }
1146 1146
 
1147 1147
         $removed = false;
1148
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
1149
-            $removed_fee             = $this->fees[ $value ];
1148
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
1149
+            $removed_fee             = $this->fees[$value];
1150 1150
             $removed_fee['action']   = 'remove';
1151 1151
             $this->pending['fees'][] = $removed_fee;
1152 1152
 
1153
-            $this->decrease_fees( $removed_fee['amount'] );
1153
+            $this->decrease_fees($removed_fee['amount']);
1154 1154
 
1155
-            unset( $this->fees[ $value ] );
1155
+            unset($this->fees[$value]);
1156 1156
             $removed = true;
1157
-        } else if ( 'index' !== $key ) {
1158
-            foreach ( $this->fees as $index => $fee ) {
1159
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
1157
+        } else if ('index' !== $key) {
1158
+            foreach ($this->fees as $index => $fee) {
1159
+                if (isset($fee[$key]) && $fee[$key] == $value) {
1160 1160
                     $removed_fee             = $fee;
1161 1161
                     $removed_fee['action']   = 'remove';
1162 1162
                     $this->pending['fees'][] = $removed_fee;
1163 1163
 
1164
-                    $this->decrease_fees( $removed_fee['amount'] );
1164
+                    $this->decrease_fees($removed_fee['amount']);
1165 1165
 
1166
-                    unset( $this->fees[ $index ] );
1166
+                    unset($this->fees[$index]);
1167 1167
                     $removed = true;
1168 1168
 
1169
-                    if ( false === $global ) {
1169
+                    if (false === $global) {
1170 1170
                         break;
1171 1171
                     }
1172 1172
                 }
1173 1173
             }
1174 1174
         }
1175 1175
 
1176
-        if ( true === $removed ) {
1177
-            $this->fees = array_values( $this->fees );
1176
+        if (true === $removed) {
1177
+            $this->fees = array_values($this->fees);
1178 1178
         }
1179 1179
 
1180 1180
         return $removed;
@@ -1182,35 +1182,35 @@  discard block
 block discarded – undo
1182 1182
 
1183 1183
     
1184 1184
 
1185
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
1185
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
1186 1186
         // Bail if no note specified
1187
-        if( !$note ) {
1187
+        if (!$note) {
1188 1188
             return false;
1189 1189
         }
1190 1190
 
1191
-        if ( empty( $this->ID ) )
1191
+        if (empty($this->ID))
1192 1192
             return false;
1193 1193
         
1194
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
1195
-            $user                 = get_user_by( 'id', get_current_user_id() );
1194
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
1195
+            $user                 = get_user_by('id', get_current_user_id());
1196 1196
             $comment_author       = $user->display_name;
1197 1197
             $comment_author_email = $user->user_email;
1198 1198
         } else {
1199 1199
             $comment_author       = 'System';
1200 1200
             $comment_author_email = 'system@';
1201
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1202
-            $comment_author_email = sanitize_email( $comment_author_email );
1201
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1202
+            $comment_author_email = sanitize_email($comment_author_email);
1203 1203
         }
1204 1204
 
1205
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1205
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1206 1206
 
1207
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1207
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1208 1208
             'comment_post_ID'      => $this->ID,
1209 1209
             'comment_content'      => $note,
1210 1210
             'comment_agent'        => 'WPInvoicing',
1211 1211
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1212
-            'comment_date'         => current_time( 'mysql' ),
1213
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1212
+            'comment_date'         => current_time('mysql'),
1213
+            'comment_date_gmt'     => current_time('mysql', 1),
1214 1214
             'comment_approved'     => 1,
1215 1215
             'comment_parent'       => 0,
1216 1216
             'comment_author'       => $comment_author,
@@ -1218,53 +1218,53 @@  discard block
 block discarded – undo
1218 1218
             'comment_author_url'   => '',
1219 1219
             'comment_author_email' => $comment_author_email,
1220 1220
             'comment_type'         => 'wpinv_note'
1221
-        ) ) );
1221
+        )));
1222 1222
 
1223
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1223
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1224 1224
         
1225
-        if ( $customer_type ) {
1226
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1225
+        if ($customer_type) {
1226
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1227 1227
 
1228
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1228
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1229 1229
         }
1230 1230
 
1231 1231
         return $note_id;
1232 1232
     }
1233 1233
 
1234
-    private function increase_subtotal( $amount = 0.00 ) {
1234
+    private function increase_subtotal($amount = 0.00) {
1235 1235
         $amount          = (float) $amount;
1236 1236
         $this->subtotal += $amount;
1237
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1237
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1238 1238
 
1239 1239
         $this->recalculate_total();
1240 1240
     }
1241 1241
 
1242
-    private function decrease_subtotal( $amount = 0.00 ) {
1242
+    private function decrease_subtotal($amount = 0.00) {
1243 1243
         $amount          = (float) $amount;
1244 1244
         $this->subtotal -= $amount;
1245
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1245
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1246 1246
 
1247
-        if ( $this->subtotal < 0 ) {
1247
+        if ($this->subtotal < 0) {
1248 1248
             $this->subtotal = 0;
1249 1249
         }
1250 1250
 
1251 1251
         $this->recalculate_total();
1252 1252
     }
1253 1253
 
1254
-    private function increase_fees( $amount = 0.00 ) {
1255
-        $amount            = (float)$amount;
1254
+    private function increase_fees($amount = 0.00) {
1255
+        $amount            = (float) $amount;
1256 1256
         $this->fees_total += $amount;
1257
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1257
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1258 1258
 
1259 1259
         $this->recalculate_total();
1260 1260
     }
1261 1261
 
1262
-    private function decrease_fees( $amount = 0.00 ) {
1262
+    private function decrease_fees($amount = 0.00) {
1263 1263
         $amount            = (float) $amount;
1264 1264
         $this->fees_total -= $amount;
1265
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1265
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1266 1266
 
1267
-        if ( $this->fees_total < 0 ) {
1267
+        if ($this->fees_total < 0) {
1268 1268
             $this->fees_total = 0;
1269 1269
         }
1270 1270
 
@@ -1275,54 +1275,54 @@  discard block
 block discarded – undo
1275 1275
         global $wpi_nosave;
1276 1276
         
1277 1277
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1278
-        $this->total = wpinv_round_amount( $this->total );
1278
+        $this->total = wpinv_round_amount($this->total);
1279 1279
         
1280
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1280
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1281 1281
     }
1282 1282
     
1283
-    public function increase_tax( $amount = 0.00 ) {
1283
+    public function increase_tax($amount = 0.00) {
1284 1284
         $amount       = (float) $amount;
1285 1285
         $this->tax   += $amount;
1286 1286
 
1287 1287
         $this->recalculate_total();
1288 1288
     }
1289 1289
 
1290
-    public function decrease_tax( $amount = 0.00 ) {
1290
+    public function decrease_tax($amount = 0.00) {
1291 1291
         $amount     = (float) $amount;
1292 1292
         $this->tax -= $amount;
1293 1293
 
1294
-        if ( $this->tax < 0 ) {
1294
+        if ($this->tax < 0) {
1295 1295
             $this->tax = 0;
1296 1296
         }
1297 1297
 
1298 1298
         $this->recalculate_total();
1299 1299
     }
1300 1300
 
1301
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1302
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1301
+    public function update_status($new_status = false, $note = '', $manual = false) {
1302
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1303 1303
 
1304
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1304
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1305 1305
             return false; // Don't permit status changes that aren't changes
1306 1306
         }
1307 1307
 
1308
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1308
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1309 1309
         $updated = false;
1310 1310
 
1311
-        if ( $do_change ) {
1312
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1311
+        if ($do_change) {
1312
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1313 1313
 
1314 1314
             $update_post_data                   = array();
1315 1315
             $update_post_data['ID']             = $this->ID;
1316 1316
             $update_post_data['post_status']    = $new_status;
1317
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1318
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1317
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1318
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1319 1319
             
1320
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1320
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1321 1321
 
1322
-            $updated = wp_update_post( $update_post_data );     
1322
+            $updated = wp_update_post($update_post_data);     
1323 1323
            
1324 1324
             // Process any specific status functions
1325
-            switch( $new_status ) {
1325
+            switch ($new_status) {
1326 1326
                 case 'wpi-refunded':
1327 1327
                     $this->process_refund();
1328 1328
                     break;
@@ -1335,9 +1335,9 @@  discard block
 block discarded – undo
1335 1335
             }
1336 1336
             
1337 1337
             // Status was changed.
1338
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1339
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1340
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1338
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1339
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1340
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1341 1341
         }
1342 1342
 
1343 1343
         return $updated;
@@ -1351,20 +1351,20 @@  discard block
 block discarded – undo
1351 1351
         $this->save();
1352 1352
     }
1353 1353
 
1354
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1355
-        if ( empty( $meta_key ) ) {
1354
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1355
+        if (empty($meta_key)) {
1356 1356
             return false;
1357 1357
         }
1358 1358
 
1359
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1359
+        if ($meta_key == 'key' || $meta_key == 'date') {
1360 1360
             $current_meta = $this->get_meta();
1361
-            $current_meta[ $meta_key ] = $meta_value;
1361
+            $current_meta[$meta_key] = $meta_value;
1362 1362
 
1363 1363
             $meta_key     = '_wpinv_payment_meta';
1364 1364
             $meta_value   = $current_meta;
1365 1365
         }
1366 1366
 
1367
-        $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1367
+        $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1368 1368
         
1369 1369
         // Do not update created date on invoice marked as paid.
1370 1370
         /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) {
@@ -1379,45 +1379,45 @@  discard block
 block discarded – undo
1379 1379
             wp_update_post( $args );
1380 1380
         }*/
1381 1381
         
1382
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1382
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1383 1383
     }
1384 1384
 
1385 1385
     private function process_refund() {
1386 1386
         $process_refund = true;
1387 1387
 
1388 1388
         // If the payment was not in publish, don't decrement stats as they were never incremented
1389
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1389
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1390 1390
             $process_refund = false;
1391 1391
         }
1392 1392
 
1393 1393
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1394
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1394
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1395 1395
 
1396
-        if ( false === $process_refund ) {
1396
+        if (false === $process_refund) {
1397 1397
             return;
1398 1398
         }
1399 1399
 
1400
-        do_action( 'wpinv_pre_refund_invoice', $this );
1400
+        do_action('wpinv_pre_refund_invoice', $this);
1401 1401
         
1402
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1403
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1404
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1402
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1403
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1404
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1405 1405
         
1406
-        do_action( 'wpinv_post_refund_invoice', $this );
1406
+        do_action('wpinv_post_refund_invoice', $this);
1407 1407
     }
1408 1408
 
1409 1409
     private function process_failure() {
1410 1410
         $discounts = $this->discounts;
1411
-        if ( empty( $discounts ) ) {
1411
+        if (empty($discounts)) {
1412 1412
             return;
1413 1413
         }
1414 1414
 
1415
-        if ( ! is_array( $discounts ) ) {
1416
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1415
+        if (!is_array($discounts)) {
1416
+            $discounts = array_map('trim', explode(',', $discounts));
1417 1417
         }
1418 1418
 
1419
-        foreach ( $discounts as $discount ) {
1420
-            wpinv_decrease_discount_usage( $discount );
1419
+        foreach ($discounts as $discount) {
1420
+            wpinv_decrease_discount_usage($discount);
1421 1421
         }
1422 1422
     }
1423 1423
     
@@ -1425,92 +1425,92 @@  discard block
 block discarded – undo
1425 1425
         $process_pending = true;
1426 1426
 
1427 1427
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1428
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1428
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1429 1429
             $process_pending = false;
1430 1430
         }
1431 1431
 
1432 1432
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1433
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1433
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1434 1434
 
1435
-        if ( false === $process_pending ) {
1435
+        if (false === $process_pending) {
1436 1436
             return;
1437 1437
         }
1438 1438
 
1439
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1440
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1441
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1439
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1440
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1441
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1442 1442
 
1443 1443
         $this->completed_date = '';
1444
-        $this->update_meta( '_wpinv_completed_date', '' );
1444
+        $this->update_meta('_wpinv_completed_date', '');
1445 1445
     }
1446 1446
     
1447 1447
     // get data
1448
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1449
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1448
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1449
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1450 1450
 
1451
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1451
+        if ($meta_key === '_wpinv_payment_meta') {
1452 1452
 
1453
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1453
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1454 1454
 
1455
-            if ( empty( $meta['key'] ) ) {
1455
+            if (empty($meta['key'])) {
1456 1456
                 $meta['key'] = $this->setup_invoice_key();
1457 1457
             }
1458 1458
 
1459
-            if ( empty( $meta['date'] ) ) {
1460
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1459
+            if (empty($meta['date'])) {
1460
+                $meta['date'] = get_post_field('post_date', $this->ID);
1461 1461
             }
1462 1462
         }
1463 1463
 
1464
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1464
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1465 1465
 
1466
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1466
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1467 1467
     }
1468 1468
     
1469 1469
     public function get_description() {
1470
-        $post = get_post( $this->ID );
1470
+        $post = get_post($this->ID);
1471 1471
         
1472
-        $description = !empty( $post ) ? $post->post_content : '';
1473
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1472
+        $description = !empty($post) ? $post->post_content : '';
1473
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1474 1474
     }
1475 1475
     
1476
-    public function get_status( $nicename = false ) {
1477
-        if ( !$nicename ) {
1476
+    public function get_status($nicename = false) {
1477
+        if (!$nicename) {
1478 1478
             $status = $this->status;
1479 1479
         } else {
1480 1480
             $status = $this->status_nicename;
1481 1481
         }
1482 1482
         
1483
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1483
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1484 1484
     }
1485 1485
     
1486 1486
     public function get_cart_details() {
1487
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1487
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1488 1488
     }
1489 1489
     
1490
-    public function get_subtotal( $currency = false ) {
1491
-        $subtotal = wpinv_round_amount( $this->subtotal );
1490
+    public function get_subtotal($currency = false) {
1491
+        $subtotal = wpinv_round_amount($this->subtotal);
1492 1492
         
1493
-        if ( $currency ) {
1494
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1493
+        if ($currency) {
1494
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1495 1495
         }
1496 1496
         
1497
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1497
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1498 1498
     }
1499 1499
     
1500
-    public function get_total( $currency = false ) {        
1501
-        if ( $this->is_free_trial() ) {
1502
-            $total = wpinv_round_amount( 0 );
1500
+    public function get_total($currency = false) {        
1501
+        if ($this->is_free_trial()) {
1502
+            $total = wpinv_round_amount(0);
1503 1503
         } else {
1504
-            $total = wpinv_round_amount( $this->total );
1504
+            $total = wpinv_round_amount($this->total);
1505 1505
         }
1506
-        if ( $currency ) {
1507
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1506
+        if ($currency) {
1507
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1508 1508
         }
1509 1509
         
1510
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1510
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1511 1511
     }
1512 1512
     
1513
-    public function get_recurring_details( $field = '', $currency = false ) {        
1513
+    public function get_recurring_details($field = '', $currency = false) {        
1514 1514
         $data                 = array();
1515 1515
         $data['cart_details'] = $this->cart_details;
1516 1516
         $data['subtotal']     = $this->get_subtotal();
@@ -1518,119 +1518,119 @@  discard block
 block discarded – undo
1518 1518
         $data['tax']          = $this->get_tax();
1519 1519
         $data['total']        = $this->get_total();
1520 1520
     
1521
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1521
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1522 1522
             $is_free_trial = $this->is_free_trial();
1523
-            $discounts = $this->get_discounts( true );
1523
+            $discounts = $this->get_discounts(true);
1524 1524
             
1525
-            if ( $is_free_trial || !empty( $discounts ) ) {
1525
+            if ($is_free_trial || !empty($discounts)) {
1526 1526
                 $first_use_only = false;
1527 1527
                 
1528
-                if ( !empty( $discounts ) ) {
1529
-                    foreach ( $discounts as $key => $code ) {
1530
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1528
+                if (!empty($discounts)) {
1529
+                    foreach ($discounts as $key => $code) {
1530
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1531 1531
                             $first_use_only = true;
1532 1532
                             break;
1533 1533
                         }
1534 1534
                     }
1535 1535
                 }
1536 1536
                     
1537
-                if ( !$first_use_only ) {
1538
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1539
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1540
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1541
-                    $data['total']    = wpinv_round_amount( $this->total );
1537
+                if (!$first_use_only) {
1538
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1539
+                    $data['discount'] = wpinv_round_amount($this->discount);
1540
+                    $data['tax']      = wpinv_round_amount($this->tax);
1541
+                    $data['total']    = wpinv_round_amount($this->total);
1542 1542
                 } else {
1543 1543
                     $cart_subtotal   = 0;
1544 1544
                     $cart_discount   = $this->discount;
1545 1545
                     $cart_tax        = 0;
1546 1546
 
1547
-                    foreach ( $this->cart_details as $key => $item ) {
1548
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1549
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1547
+                    foreach ($this->cart_details as $key => $item) {
1548
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1549
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1550 1550
                         $item_discount  = 0;
1551
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1551
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1552 1552
                         
1553
-                        if ( wpinv_prices_include_tax() ) {
1554
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1553
+                        if (wpinv_prices_include_tax()) {
1554
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1555 1555
                         }
1556 1556
                         
1557 1557
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1558 1558
                         // Do not allow totals to go negative
1559
-                        if ( $item_total < 0 ) {
1559
+                        if ($item_total < 0) {
1560 1560
                             $item_total = 0;
1561 1561
                         }
1562 1562
                         
1563
-                        $cart_subtotal  += (float)($item_subtotal);
1564
-                        $cart_discount  += (float)($item_discount);
1565
-                        $cart_tax       += (float)($item_tax);
1563
+                        $cart_subtotal  += (float) ($item_subtotal);
1564
+                        $cart_discount  += (float) ($item_discount);
1565
+                        $cart_tax       += (float) ($item_tax);
1566 1566
                         
1567
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1568
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1569
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1567
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1568
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1569
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1570 1570
                     }
1571 1571
 
1572 1572
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1573
-	                if ( $total < 0 ) {
1573
+	                if ($total < 0) {
1574 1574
 		                $total = 0;
1575 1575
 	                }
1576 1576
 
1577
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1578
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1579
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1580
-                    $data['total']    = wpinv_round_amount( $total );
1577
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1578
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1579
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1580
+                    $data['total']    = wpinv_round_amount($total);
1581 1581
                 }
1582 1582
             }
1583 1583
         }
1584 1584
         
1585
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1585
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1586 1586
 
1587
-        if ( isset( $data[$field] ) ) {
1588
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1587
+        if (isset($data[$field])) {
1588
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1589 1589
         }
1590 1590
         
1591 1591
         return $data;
1592 1592
     }
1593 1593
     
1594
-    public function get_final_tax( $currency = false ) {        
1595
-        $final_total = wpinv_round_amount( $this->tax );
1596
-        if ( $currency ) {
1597
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1594
+    public function get_final_tax($currency = false) {        
1595
+        $final_total = wpinv_round_amount($this->tax);
1596
+        if ($currency) {
1597
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1598 1598
         }
1599 1599
         
1600
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1600
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1601 1601
     }
1602 1602
     
1603
-    public function get_discounts( $array = false ) {
1603
+    public function get_discounts($array = false) {
1604 1604
         $discounts = $this->discounts;
1605
-        if ( $array && $discounts ) {
1606
-            $discounts = explode( ',', $discounts );
1605
+        if ($array && $discounts) {
1606
+            $discounts = explode(',', $discounts);
1607 1607
         }
1608
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1608
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1609 1609
     }
1610 1610
     
1611
-    public function get_discount( $currency = false, $dash = false ) {
1612
-        if ( !empty( $this->discounts ) ) {
1611
+    public function get_discount($currency = false, $dash = false) {
1612
+        if (!empty($this->discounts)) {
1613 1613
             global $ajax_cart_details;
1614 1614
             $ajax_cart_details = $this->get_cart_details();
1615 1615
             
1616
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1616
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1617 1617
                 $cart_items = $ajax_cart_details;
1618 1618
             } else {
1619 1619
                 $cart_items = $this->items;
1620 1620
             }
1621 1621
 
1622
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1622
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1623 1623
         }
1624
-        $discount   = wpinv_round_amount( $this->discount );
1624
+        $discount   = wpinv_round_amount($this->discount);
1625 1625
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1626 1626
         
1627
-        if ( $currency ) {
1628
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1627
+        if ($currency) {
1628
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1629 1629
         }
1630 1630
         
1631
-        $discount   = $dash . $discount;
1631
+        $discount = $dash . $discount;
1632 1632
         
1633
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1633
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1634 1634
     }
1635 1635
     
1636 1636
     public function get_discount_code() {
@@ -1642,49 +1642,49 @@  discard block
 block discarded – undo
1642 1642
         return (int) $this->disable_taxes === 0;
1643 1643
     }
1644 1644
 
1645
-    public function get_tax( $currency = false ) {
1646
-        $tax = wpinv_round_amount( $this->tax );
1645
+    public function get_tax($currency = false) {
1646
+        $tax = wpinv_round_amount($this->tax);
1647 1647
 
1648
-        if ( $currency ) {
1649
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1648
+        if ($currency) {
1649
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1650 1650
         }
1651 1651
 
1652
-        if ( ! $this->is_taxable() ) {
1653
-            $tax = wpinv_round_amount( 0.00 );
1652
+        if (!$this->is_taxable()) {
1653
+            $tax = wpinv_round_amount(0.00);
1654 1654
         }
1655 1655
 
1656
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1656
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1657 1657
     }
1658 1658
     
1659
-    public function get_fees( $type = 'all' ) {
1660
-        $fees    = array();
1659
+    public function get_fees($type = 'all') {
1660
+        $fees = array();
1661 1661
 
1662
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1663
-            foreach ( $this->fees as $fee ) {
1664
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1662
+        if (!empty($this->fees) && is_array($this->fees)) {
1663
+            foreach ($this->fees as $fee) {
1664
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1665 1665
                     continue;
1666 1666
                 }
1667 1667
 
1668
-                $fee['label'] = stripslashes( $fee['label'] );
1669
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1670
-                $fees[]    = $fee;
1668
+                $fee['label'] = stripslashes($fee['label']);
1669
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1670
+                $fees[] = $fee;
1671 1671
             }
1672 1672
         }
1673 1673
 
1674
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1674
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1675 1675
     }
1676 1676
     
1677
-    public function get_fees_total( $type = 'all' ) {
1677
+    public function get_fees_total($type = 'all') {
1678 1678
         $fees_total = (float) 0.00;
1679 1679
 
1680
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1681
-        if ( ! empty( $payment_fees ) ) {
1682
-            foreach ( $payment_fees as $fee ) {
1680
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1681
+        if (!empty($payment_fees)) {
1682
+            foreach ($payment_fees as $fee) {
1683 1683
                 $fees_total += (float) $fee['amount'];
1684 1684
             }
1685 1685
         }
1686 1686
 
1687
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1687
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1688 1688
         /*
1689 1689
         $fees = $this->get_fees( $type );
1690 1690
 
@@ -1704,116 +1704,116 @@  discard block
 block discarded – undo
1704 1704
     }
1705 1705
 
1706 1706
     public function get_user_id() {
1707
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1707
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1708 1708
     }
1709 1709
     
1710 1710
     public function get_first_name() {
1711
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1711
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1712 1712
     }
1713 1713
     
1714 1714
     public function get_last_name() {
1715
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1715
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1716 1716
     }
1717 1717
     
1718 1718
     public function get_user_full_name() {
1719
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1719
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1720 1720
     }
1721 1721
     
1722 1722
     public function get_user_info() {
1723
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1723
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1724 1724
     }
1725 1725
     
1726 1726
     public function get_email() {
1727
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1727
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1728 1728
     }
1729 1729
     
1730 1730
     public function get_address() {
1731
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1731
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1732 1732
     }
1733 1733
     
1734 1734
     public function get_phone() {
1735
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1735
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1736 1736
     }
1737 1737
     
1738 1738
     public function get_number() {
1739
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1739
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1740 1740
     }
1741 1741
     
1742 1742
     public function get_items() {
1743
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1743
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1744 1744
     }
1745 1745
     
1746 1746
     public function get_key() {
1747
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1747
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1748 1748
     }
1749 1749
     
1750 1750
     public function get_transaction_id() {
1751
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1751
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1752 1752
     }
1753 1753
     
1754 1754
     public function get_gateway() {
1755
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1755
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1756 1756
     }
1757 1757
     
1758 1758
     public function get_gateway_title() {
1759
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1759
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1760 1760
         
1761
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1761
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1762 1762
     }
1763 1763
     
1764 1764
     public function get_currency() {
1765
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1765
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1766 1766
     }
1767 1767
     
1768 1768
     public function get_created_date() {
1769
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1769
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1770 1770
     }
1771 1771
     
1772
-    public function get_due_date( $display = false ) {
1773
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1772
+    public function get_due_date($display = false) {
1773
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1774 1774
 
1775
-        if ( ! $display ) {
1775
+        if (!$display) {
1776 1776
             return $due_date;
1777 1777
         }
1778 1778
         
1779
-        return getpaid_format_date( $this->due_date );
1779
+        return getpaid_format_date($this->due_date);
1780 1780
     }
1781 1781
     
1782 1782
     public function get_completed_date() {
1783
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1783
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1784 1784
     }
1785 1785
     
1786
-    public function get_invoice_date( $formatted = true ) {
1786
+    public function get_invoice_date($formatted = true) {
1787 1787
         $date_completed = $this->completed_date;
1788 1788
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1789 1789
         
1790
-        if ( $invoice_date == '' ) {
1790
+        if ($invoice_date == '') {
1791 1791
             $date_created   = $this->date;
1792 1792
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1793 1793
         }
1794 1794
         
1795
-        if ( $formatted && $invoice_date ) {
1796
-            $invoice_date   = getpaid_format_date( $invoice_date );
1795
+        if ($formatted && $invoice_date) {
1796
+            $invoice_date = getpaid_format_date($invoice_date);
1797 1797
         }
1798 1798
 
1799
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1799
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1800 1800
     }
1801 1801
     
1802 1802
     public function get_ip() {
1803
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1803
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1804 1804
     }
1805 1805
         
1806
-    public function has_status( $status ) {
1807
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1806
+    public function has_status($status) {
1807
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1808 1808
     }
1809 1809
     
1810
-    public function add_item( $item_id = 0, $args = array() ) {
1810
+    public function add_item($item_id = 0, $args = array()) {
1811 1811
         global $wpi_current_id, $wpi_item_id;
1812 1812
         
1813
-        $item = new WPInv_Item( $item_id );
1813
+        $item = new WPInv_Item($item_id);
1814 1814
 
1815 1815
         // Bail if this post isn't a item
1816
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1816
+        if (!$item || $item->post_type !== 'wpi_item') {
1817 1817
             return false;
1818 1818
         }
1819 1819
         
@@ -1832,8 +1832,8 @@  discard block
 block discarded – undo
1832 1832
             'fees'          => array()
1833 1833
         );
1834 1834
 
1835
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1836
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1835
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1836
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1837 1837
 
1838 1838
         $wpi_current_id         = $this->ID;
1839 1839
         $wpi_item_id            = $item->ID;
@@ -1845,19 +1845,19 @@  discard block
 block discarded – undo
1845 1845
         $found_cart_key         = false;
1846 1846
         
1847 1847
         if ($has_quantities) {
1848
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1848
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1849 1849
             
1850
-            foreach ( $this->items as $key => $cart_item ) {
1851
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1850
+            foreach ($this->items as $key => $cart_item) {
1851
+                if ((int) $item_id !== (int) $cart_item['id']) {
1852 1852
                     continue;
1853 1853
                 }
1854 1854
 
1855
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1855
+                $this->items[$key]['quantity'] += $args['quantity'];
1856 1856
                 break;
1857 1857
             }
1858 1858
             
1859
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1860
-                if ( $item_id != $cart_item['id'] ) {
1859
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1860
+                if ($item_id != $cart_item['id']) {
1861 1861
                     continue;
1862 1862
                 }
1863 1863
 
@@ -1869,29 +1869,29 @@  discard block
 block discarded – undo
1869 1869
         if ($has_quantities && $found_cart_key !== false) {
1870 1870
             $cart_item          = $this->cart_details[$found_cart_key];
1871 1871
             $item_price         = $cart_item['item_price'];
1872
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1873
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1872
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1873
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1874 1874
             
1875 1875
             $new_quantity       = $quantity + $args['quantity'];
1876 1876
             $subtotal           = $item_price * $new_quantity;
1877 1877
             
1878 1878
             $args['quantity']   = $new_quantity;
1879
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1880
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1879
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1880
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1881 1881
             
1882
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1883
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1882
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1883
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1884 1884
             // The total increase equals the number removed * the item_price
1885
-            $total_increased    = wpinv_round_amount( $item_price );
1885
+            $total_increased    = wpinv_round_amount($item_price);
1886 1886
             
1887
-            if ( wpinv_prices_include_tax() ) {
1888
-                $subtotal -= wpinv_round_amount( $tax );
1887
+            if (wpinv_prices_include_tax()) {
1888
+                $subtotal -= wpinv_round_amount($tax);
1889 1889
             }
1890 1890
 
1891
-            $total              = $subtotal - $discount + $tax;
1891
+            $total = $subtotal - $discount + $tax;
1892 1892
 
1893 1893
             // Do not allow totals to go negative
1894
-            if( $total < 0 ) {
1894
+            if ($total < 0) {
1895 1895
                 $total = 0;
1896 1896
             }
1897 1897
             
@@ -1907,25 +1907,25 @@  discard block
 block discarded – undo
1907 1907
             $this->cart_details[$found_cart_key] = $cart_item;
1908 1908
         } else {
1909 1909
             // Set custom price.
1910
-            if ( $args['custom_price'] !== '' ) {
1910
+            if ($args['custom_price'] !== '') {
1911 1911
                 $item_price = $args['custom_price'];
1912 1912
             } else {
1913 1913
                 // Allow overriding the price
1914
-                if ( false !== $args['item_price'] ) {
1914
+                if (false !== $args['item_price']) {
1915 1915
                     $item_price = $args['item_price'];
1916 1916
                 } else {
1917
-                    $item_price = wpinv_get_item_price( $item->ID );
1917
+                    $item_price = wpinv_get_item_price($item->ID);
1918 1918
                 }
1919 1919
             }
1920 1920
 
1921 1921
             // Sanitizing the price here so we don't have a dozen calls later
1922
-            $item_price = wpinv_sanitize_amount( $item_price );
1923
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1922
+            $item_price = wpinv_sanitize_amount($item_price);
1923
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1924 1924
         
1925
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1926
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1927
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1928
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1925
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1926
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1927
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1928
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1929 1929
 
1930 1930
             // Setup the items meta item
1931 1931
             $new_item = array(
@@ -1933,29 +1933,29 @@  discard block
 block discarded – undo
1933 1933
                 'quantity' => $args['quantity'],
1934 1934
             );
1935 1935
 
1936
-            $this->items[]  = $new_item;
1936
+            $this->items[] = $new_item;
1937 1937
 
1938
-            if ( wpinv_prices_include_tax() ) {
1939
-                $subtotal -= wpinv_round_amount( $tax );
1938
+            if (wpinv_prices_include_tax()) {
1939
+                $subtotal -= wpinv_round_amount($tax);
1940 1940
             }
1941 1941
 
1942
-            $total      = $subtotal - $discount + $tax;
1942
+            $total = $subtotal - $discount + $tax;
1943 1943
 
1944 1944
             // Do not allow totals to go negative
1945
-            if( $total < 0 ) {
1945
+            if ($total < 0) {
1946 1946
                 $total = 0;
1947 1947
             }
1948 1948
         
1949 1949
             $this->cart_details[] = array(
1950 1950
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1951 1951
                 'id'            => $item->ID,
1952
-                'item_price'    => wpinv_round_amount( $item_price ),
1953
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1952
+                'item_price'    => wpinv_round_amount($item_price),
1953
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1954 1954
                 'quantity'      => $args['quantity'],
1955 1955
                 'discount'      => $discount,
1956
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1957
-                'tax'           => wpinv_round_amount( $tax ),
1958
-                'price'         => wpinv_round_amount( $total ),
1956
+                'subtotal'      => wpinv_round_amount($subtotal),
1957
+                'tax'           => wpinv_round_amount($tax),
1958
+                'price'         => wpinv_round_amount($total),
1959 1959
                 'vat_rate'      => $tax_rate,
1960 1960
                 'vat_class'     => $tax_class,
1961 1961
                 'meta'          => $args['meta'],
@@ -1965,18 +1965,18 @@  discard block
 block discarded – undo
1965 1965
             $subtotal = $subtotal - $discount;
1966 1966
         }
1967 1967
         
1968
-        $added_item = end( $this->cart_details );
1969
-        $added_item['action']  = 'add';
1968
+        $added_item = end($this->cart_details);
1969
+        $added_item['action'] = 'add';
1970 1970
         
1971 1971
         $this->pending['items'][] = $added_item;
1972 1972
         
1973
-        $this->increase_subtotal( $subtotal );
1974
-        $this->increase_tax( $tax );
1973
+        $this->increase_subtotal($subtotal);
1974
+        $this->increase_tax($tax);
1975 1975
 
1976 1976
         return true;
1977 1977
     }
1978 1978
     
1979
-    public function remove_item( $item_id, $args = array() ) {
1979
+    public function remove_item($item_id, $args = array()) {
1980 1980
         // Set some defaults
1981 1981
         $defaults = array(
1982 1982
             'quantity'      => 1,
@@ -1984,51 +1984,51 @@  discard block
 block discarded – undo
1984 1984
             'custom_price'  => '',
1985 1985
             'cart_index'    => false,
1986 1986
         );
1987
-        $args = wp_parse_args( $args, $defaults );
1987
+        $args = wp_parse_args($args, $defaults);
1988 1988
 
1989 1989
         // Bail if this post isn't a item
1990
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1990
+        if (get_post_type($item_id) !== 'wpi_item') {
1991 1991
             return false;
1992 1992
         }
1993 1993
         
1994
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1994
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1995 1995
 
1996
-        foreach ( $this->items as $key => $item ) {
1997
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1996
+        foreach ($this->items as $key => $item) {
1997
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1998 1998
                 continue;
1999 1999
             }
2000 2000
 
2001
-            if ( false !== $args['cart_index'] ) {
2002
-                $cart_index = absint( $args['cart_index'] );
2003
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
2001
+            if (false !== $args['cart_index']) {
2002
+                $cart_index = absint($args['cart_index']);
2003
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
2004 2004
 
2005
-                if ( ! empty( $cart_item ) ) {
2005
+                if (!empty($cart_item)) {
2006 2006
                     // If the cart index item isn't the same item ID, don't remove it
2007
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
2007
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
2008 2008
                         continue;
2009 2009
                     }
2010 2010
                 }
2011 2011
             }
2012 2012
 
2013
-            $item_quantity = $this->items[ $key ]['quantity'];
2014
-            if ( $item_quantity > $args['quantity'] ) {
2015
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
2013
+            $item_quantity = $this->items[$key]['quantity'];
2014
+            if ($item_quantity > $args['quantity']) {
2015
+                $this->items[$key]['quantity'] -= $args['quantity'];
2016 2016
                 break;
2017 2017
             } else {
2018
-                unset( $this->items[ $key ] );
2018
+                unset($this->items[$key]);
2019 2019
                 break;
2020 2020
             }
2021 2021
         }
2022 2022
 
2023 2023
         $found_cart_key = false;
2024
-        if ( false === $args['cart_index'] ) {
2025
-            foreach ( $this->cart_details as $cart_key => $item ) {
2026
-                if ( $item_id != $item['id'] ) {
2024
+        if (false === $args['cart_index']) {
2025
+            foreach ($this->cart_details as $cart_key => $item) {
2026
+                if ($item_id != $item['id']) {
2027 2027
                     continue;
2028 2028
                 }
2029 2029
 
2030
-                if ( false !== $args['item_price'] ) {
2031
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
2030
+                if (false !== $args['item_price']) {
2031
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
2032 2032
                         continue;
2033 2033
                     }
2034 2034
                 }
@@ -2037,13 +2037,13 @@  discard block
 block discarded – undo
2037 2037
                 break;
2038 2038
             }
2039 2039
         } else {
2040
-            $cart_index = absint( $args['cart_index'] );
2040
+            $cart_index = absint($args['cart_index']);
2041 2041
 
2042
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
2042
+            if (!array_key_exists($cart_index, $this->cart_details)) {
2043 2043
                 return false; // Invalid cart index passed.
2044 2044
             }
2045 2045
 
2046
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
2046
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
2047 2047
                 return false; // We still need the proper Item ID to be sure.
2048 2048
             }
2049 2049
 
@@ -2051,41 +2051,41 @@  discard block
 block discarded – undo
2051 2051
         }
2052 2052
         
2053 2053
         $cart_item  = $this->cart_details[$found_cart_key];
2054
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
2054
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
2055 2055
         
2056
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
2056
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
2057 2057
             //return false; // Invoice must contain at least one item.
2058 2058
         }
2059 2059
         
2060
-        $discounts  = $this->get_discounts();
2060
+        $discounts = $this->get_discounts();
2061 2061
         
2062
-        if ( $quantity > $args['quantity'] ) {
2062
+        if ($quantity > $args['quantity']) {
2063 2063
             $item_price         = $cart_item['item_price'];
2064
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
2064
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
2065 2065
             
2066
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
2066
+            $new_quantity       = max($quantity - $args['quantity'], 1);
2067 2067
             $subtotal           = $item_price * $new_quantity;
2068 2068
             
2069 2069
             $args['quantity']   = $new_quantity;
2070
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2071
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2070
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2071
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2072 2072
             
2073
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
2074
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
2075
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
2076
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
2073
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
2074
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
2075
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
2076
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
2077 2077
             
2078 2078
             // The total increase equals the number removed * the item_price
2079
-            $total_decrease     = wpinv_round_amount( $item_price );
2079
+            $total_decrease     = wpinv_round_amount($item_price);
2080 2080
             
2081
-            if ( wpinv_prices_include_tax() ) {
2082
-                $subtotal -= wpinv_round_amount( $tax );
2081
+            if (wpinv_prices_include_tax()) {
2082
+                $subtotal -= wpinv_round_amount($tax);
2083 2083
             }
2084 2084
 
2085
-            $total              = $subtotal - $discount + $tax;
2085
+            $total = $subtotal - $discount + $tax;
2086 2086
 
2087 2087
             // Do not allow totals to go negative
2088
-            if( $total < 0 ) {
2088
+            if ($total < 0) {
2089 2089
                 $total = 0;
2090 2090
             }
2091 2091
             
@@ -2104,16 +2104,16 @@  discard block
 block discarded – undo
2104 2104
             
2105 2105
             $this->cart_details[$found_cart_key] = $cart_item;
2106 2106
             
2107
-            $remove_item = end( $this->cart_details );
2107
+            $remove_item = end($this->cart_details);
2108 2108
         } else {
2109 2109
             $item_price     = $cart_item['item_price'];
2110
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
2111
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
2110
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
2111
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
2112 2112
         
2113
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
2113
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
2114 2114
             $tax_decrease       = $tax;
2115 2115
 
2116
-            unset( $this->cart_details[$found_cart_key] );
2116
+            unset($this->cart_details[$found_cart_key]);
2117 2117
             
2118 2118
             $remove_item             = $args;
2119 2119
             $remove_item['id']       = $item_id;
@@ -2124,8 +2124,8 @@  discard block
 block discarded – undo
2124 2124
         $remove_item['action']      = 'remove';
2125 2125
         $this->pending['items'][]   = $remove_item;
2126 2126
                
2127
-        $this->decrease_subtotal( $subtotal_decrease );
2128
-        $this->decrease_tax( $tax_decrease );
2127
+        $this->decrease_subtotal($subtotal_decrease);
2128
+        $this->decrease_tax($tax_decrease);
2129 2129
         
2130 2130
         return true;
2131 2131
     }
@@ -2133,7 +2133,7 @@  discard block
 block discarded – undo
2133 2133
     public function update_items($temp = false) {
2134 2134
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
2135 2135
         
2136
-        if ( !empty( $this->cart_details ) ) {
2136
+        if (!empty($this->cart_details)) {
2137 2137
             $wpi_nosave             = $temp;
2138 2138
             $cart_subtotal          = 0;
2139 2139
             $cart_discount          = 0;
@@ -2143,65 +2143,65 @@  discard block
 block discarded – undo
2143 2143
             $_POST['wpinv_country'] = $this->country;
2144 2144
             $_POST['wpinv_state']   = $this->state;
2145 2145
 
2146
-            foreach ( $this->cart_details as $key => $item ) {
2146
+            foreach ($this->cart_details as $key => $item) {
2147 2147
                 $item_price = $item['item_price'];
2148
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
2149
-                $amount     = wpinv_round_amount( $item_price * $quantity );
2148
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
2149
+                $amount     = wpinv_round_amount($item_price * $quantity);
2150 2150
                 $subtotal   = $item_price * $quantity;
2151 2151
                 
2152 2152
                 $wpi_current_id         = $this->ID;
2153 2153
                 $wpi_item_id            = $item['id'];
2154 2154
                 
2155
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
2155
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
2156 2156
                 
2157
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
2158
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
2159
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2157
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
2158
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
2159
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2160 2160
 
2161
-                if ( ! $this->is_taxable() ) {
2161
+                if (!$this->is_taxable()) {
2162 2162
                     $tax = 0;
2163 2163
                 }
2164 2164
 
2165
-                if ( wpinv_prices_include_tax() ) {
2166
-                    $subtotal -= wpinv_round_amount( $tax );
2165
+                if (wpinv_prices_include_tax()) {
2166
+                    $subtotal -= wpinv_round_amount($tax);
2167 2167
                 }
2168 2168
 
2169
-                $total      = $subtotal - $discount + $tax;
2169
+                $total = $subtotal - $discount + $tax;
2170 2170
 
2171 2171
                 // Do not allow totals to go negative
2172
-                if( $total < 0 ) {
2172
+                if ($total < 0) {
2173 2173
                     $total = 0;
2174 2174
                 }
2175 2175
 
2176 2176
                 $cart_details[] = array(
2177 2177
                     'id'          => $item['id'],
2178 2178
                     'name'        => $item['name'],
2179
-                    'item_price'  => wpinv_round_amount( $item_price ),
2180
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
2179
+                    'item_price'  => wpinv_round_amount($item_price),
2180
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
2181 2181
                     'quantity'    => $quantity,
2182 2182
                     'discount'    => $discount,
2183
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
2184
-                    'tax'         => wpinv_round_amount( $tax ),
2185
-                    'price'       => wpinv_round_amount( $total ),
2183
+                    'subtotal'    => wpinv_round_amount($subtotal),
2184
+                    'tax'         => wpinv_round_amount($tax),
2185
+                    'price'       => wpinv_round_amount($total),
2186 2186
                     'vat_rate'    => $tax_rate,
2187 2187
                     'vat_class'   => $tax_class,
2188 2188
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
2189 2189
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
2190 2190
                 );
2191 2191
 
2192
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
2193
-                $cart_discount  += (float)($discount);
2194
-                $cart_tax       += (float)($tax);
2192
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
2193
+                $cart_discount  += (float) ($discount);
2194
+                $cart_tax       += (float) ($tax);
2195 2195
             }
2196
-            if ( $cart_subtotal < 0 ) {
2196
+            if ($cart_subtotal < 0) {
2197 2197
                 $cart_subtotal = 0;
2198 2198
             }
2199
-            if ( $cart_tax < 0 ) {
2199
+            if ($cart_tax < 0) {
2200 2200
                 $cart_tax = 0;
2201 2201
             }
2202
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2203
-            $this->tax      = wpinv_round_amount( $cart_tax );
2204
-            $this->discount = wpinv_round_amount( $cart_discount );
2202
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2203
+            $this->tax      = wpinv_round_amount($cart_tax);
2204
+            $this->discount = wpinv_round_amount($cart_discount);
2205 2205
             
2206 2206
             $this->recalculate_total();
2207 2207
             
@@ -2213,177 +2213,177 @@  discard block
 block discarded – undo
2213 2213
     
2214 2214
     public function recalculate_totals($temp = false) {        
2215 2215
         $this->update_items($temp);
2216
-        $this->save( true );
2216
+        $this->save(true);
2217 2217
         
2218 2218
         return $this;
2219 2219
     }
2220 2220
     
2221 2221
     public function needs_payment() {
2222
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2222
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2223 2223
 
2224
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2224
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2225 2225
             $needs_payment = true;
2226 2226
         } else {
2227 2227
             $needs_payment = false;
2228 2228
         }
2229 2229
 
2230
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2230
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2231 2231
     }
2232 2232
     
2233
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2233
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2234 2234
         $pay_url = wpinv_get_checkout_uri();
2235 2235
 
2236
-        if ( is_ssl() ) {
2237
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2236
+        if (is_ssl()) {
2237
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2238 2238
         }
2239 2239
         
2240 2240
         $key = $this->get_key();
2241 2241
 
2242
-        if ( $with_key ) {
2243
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2242
+        if ($with_key) {
2243
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2244 2244
         } else {
2245
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2245
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2246 2246
         }
2247 2247
         
2248
-        if ( $secret ) {
2249
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2248
+        if ($secret) {
2249
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2250 2250
         }
2251 2251
 
2252
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2252
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2253 2253
     }
2254 2254
     
2255
-    public function get_view_url( $with_key = false ) {
2256
-        $invoice_url = get_permalink( $this->ID );
2255
+    public function get_view_url($with_key = false) {
2256
+        $invoice_url = get_permalink($this->ID);
2257 2257
 
2258
-        if ( $with_key ) {
2259
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2258
+        if ($with_key) {
2259
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2260 2260
         }
2261 2261
 
2262
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2262
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2263 2263
     }
2264 2264
     
2265
-    public function generate_key( $string = '' ) {
2266
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2267
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2265
+    public function generate_key($string = '') {
2266
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2267
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2268 2268
     }
2269 2269
     
2270 2270
     public function is_recurring() {
2271
-        if ( empty( $this->cart_details ) ) {
2271
+        if (empty($this->cart_details)) {
2272 2272
             return false;
2273 2273
         }
2274 2274
         
2275 2275
         $has_subscription = false;
2276
-        foreach( $this->cart_details as $cart_item ) {
2277
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2276
+        foreach ($this->cart_details as $cart_item) {
2277
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2278 2278
                 $has_subscription = true;
2279 2279
                 break;
2280 2280
             }
2281 2281
         }
2282 2282
         
2283
-        if ( count( $this->cart_details ) > 1 ) {
2283
+        if (count($this->cart_details) > 1) {
2284 2284
             $has_subscription = false;
2285 2285
         }
2286 2286
 
2287
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2287
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2288 2288
     }
2289 2289
 
2290 2290
     public function is_free_trial() {
2291 2291
         $is_free_trial = false;
2292 2292
         
2293
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2294
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2293
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2294
+            if (!empty($item) && $item->has_free_trial()) {
2295 2295
                 $is_free_trial = true;
2296 2296
             }
2297 2297
         }
2298 2298
 
2299
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2299
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2300 2300
     }
2301 2301
 
2302 2302
     public function is_initial_free() {
2303 2303
         $is_initial_free = false;
2304 2304
         
2305
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2305
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2306 2306
             $is_initial_free = true;
2307 2307
         }
2308 2308
 
2309
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2309
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2310 2310
     }
2311 2311
     
2312
-    public function get_recurring( $object = false ) {
2312
+    public function get_recurring($object = false) {
2313 2313
         $item = NULL;
2314 2314
         
2315
-        if ( empty( $this->cart_details ) ) {
2315
+        if (empty($this->cart_details)) {
2316 2316
             return $item;
2317 2317
         }
2318 2318
         
2319
-        foreach( $this->cart_details as $cart_item ) {
2320
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2319
+        foreach ($this->cart_details as $cart_item) {
2320
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2321 2321
                 $item = $cart_item['id'];
2322 2322
                 break;
2323 2323
             }
2324 2324
         }
2325 2325
         
2326
-        if ( $object ) {
2327
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2326
+        if ($object) {
2327
+            $item = $item ? new WPInv_Item($item) : NULL;
2328 2328
             
2329
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2329
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2330 2330
         }
2331 2331
 
2332
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2332
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2333 2333
     }
2334 2334
 
2335 2335
     public function get_subscription_name() {
2336
-        $item = $this->get_recurring( true );
2336
+        $item = $this->get_recurring(true);
2337 2337
 
2338
-        if ( empty( $item ) ) {
2338
+        if (empty($item)) {
2339 2339
             return NULL;
2340 2340
         }
2341 2341
 
2342
-        if ( !($name = $item->get_name()) ) {
2342
+        if (!($name = $item->get_name())) {
2343 2343
             $name = $item->post_name;
2344 2344
         }
2345 2345
 
2346
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2346
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2347 2347
     }
2348 2348
 
2349 2349
     public function get_subscription_id() {
2350
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2350
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2351 2351
 
2352
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2353
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2352
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2353
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2354 2354
 
2355
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2355
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2356 2356
         }
2357 2357
         
2358 2358
         return $subscription_id;
2359 2359
     }
2360 2360
     
2361 2361
     public function is_parent() {
2362
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2362
+        $is_parent = empty($this->parent_invoice) ? true : false;
2363 2363
 
2364
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2364
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2365 2365
     }
2366 2366
     
2367 2367
     public function is_renewal() {
2368 2368
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2369 2369
 
2370
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2370
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2371 2371
     }
2372 2372
     
2373 2373
     public function get_parent_payment() {
2374 2374
         $parent_payment = NULL;
2375 2375
         
2376
-        if ( $this->is_renewal() ) {
2377
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2376
+        if ($this->is_renewal()) {
2377
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2378 2378
         }
2379 2379
         
2380 2380
         return $parent_payment;
2381 2381
     }
2382 2382
     
2383 2383
     public function is_paid() {
2384
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2384
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2385 2385
 
2386
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2386
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2387 2387
     }
2388 2388
 
2389 2389
     /**
@@ -2396,23 +2396,23 @@  discard block
 block discarded – undo
2396 2396
     }
2397 2397
     
2398 2398
     public function is_refunded() {
2399
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2399
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2400 2400
 
2401
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2401
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2402 2402
     }
2403 2403
     
2404 2404
     public function is_free() {
2405 2405
         $is_free = false;
2406 2406
         
2407
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2408
-            if ( $this->is_parent() && $this->is_recurring() ) {
2409
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2407
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2408
+            if ($this->is_parent() && $this->is_recurring()) {
2409
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2410 2410
             } else {
2411 2411
                 $is_free = true;
2412 2412
             }
2413 2413
         }
2414 2414
         
2415
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2415
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2416 2416
     }
2417 2417
     
2418 2418
     public function has_vat() {
@@ -2420,41 +2420,41 @@  discard block
 block discarded – undo
2420 2420
         
2421 2421
         $requires_vat = false;
2422 2422
         
2423
-        if ( $this->country ) {
2423
+        if ($this->country) {
2424 2424
             $wpi_country        = $this->country;
2425 2425
             
2426
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2426
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2427 2427
         }
2428 2428
         
2429
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2429
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2430 2430
     }
2431 2431
     
2432 2432
     public function refresh_item_ids() {
2433 2433
         $item_ids = array();
2434 2434
         
2435
-        if ( !empty( $this->cart_details ) ) {
2436
-            foreach ( $this->cart_details as $key => $item ) {
2437
-                if ( !empty( $item['id'] ) ) {
2435
+        if (!empty($this->cart_details)) {
2436
+            foreach ($this->cart_details as $key => $item) {
2437
+                if (!empty($item['id'])) {
2438 2438
                     $item_ids[] = $item['id'];
2439 2439
                 }
2440 2440
             }
2441 2441
         }
2442 2442
         
2443
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2443
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2444 2444
         
2445
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2445
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2446 2446
     }
2447 2447
     
2448
-    public function get_invoice_quote_type( $post_id ) {
2449
-        if ( empty( $post_id ) ) {
2448
+    public function get_invoice_quote_type($post_id) {
2449
+        if (empty($post_id)) {
2450 2450
             return '';
2451 2451
         }
2452 2452
 
2453
-        $type = get_post_type( $post_id );
2453
+        $type = get_post_type($post_id);
2454 2454
 
2455
-        if ( 'wpi_invoice' === $type ) {
2455
+        if ('wpi_invoice' === $type) {
2456 2456
             $post_type = __('Invoice', 'invoicing');
2457
-        } else{
2457
+        } else {
2458 2458
             $post_type = __('Quote', 'invoicing');
2459 2459
         }
2460 2460
 
Please login to merge, or discard this patch.
includes/subscription-functions.php 1 patch
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -15,26 +15,26 @@  discard block
 block discarded – undo
15 15
  *
16 16
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
17 17
  */
18
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
18
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
19 19
 
20 20
 	// Do not retrieve all fields if we just want the count.
21
-	if ( 'count' == $return ) {
21
+	if ('count' == $return) {
22 22
 		$args['fields'] = 'id';
23 23
 		$args['number'] = 1;
24 24
 	}
25 25
 
26 26
 	// Do not count all matches if we just want the results.
27
-	if ( 'results' == $return ) {
27
+	if ('results' == $return) {
28 28
 		$args['count_total'] = false;
29 29
 	}
30 30
 
31
-	$query = new GetPaid_Subscriptions_Query( $args );
31
+	$query = new GetPaid_Subscriptions_Query($args);
32 32
 
33
-	if ( 'results' == $return ) {
33
+	if ('results' == $return) {
34 34
 		return $query->get_results();
35 35
 	}
36 36
 
37
-	if ( 'count' == $return ) {
37
+	if ('count' == $return) {
38 38
 		return $query->get_total();
39 39
 	}
40 40
 
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
 	return apply_filters(
52 52
 		'getpaid_get_subscription_statuses',
53 53
 		array(
54
-			'pending'    => __( 'Pending', 'invoicing' ),
55
-			'trialling'  => __( 'Trialing', 'invoicing' ),
56
-			'active'     => __( 'Active', 'invoicing' ),
57
-			'failing'    => __( 'Failing', 'invoicing' ),
58
-			'expired'    => __( 'Expired', 'invoicing' ),
59
-			'completed'  => __( 'Complete', 'invoicing' ),
60
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
54
+			'pending'    => __('Pending', 'invoicing'),
55
+			'trialling'  => __('Trialing', 'invoicing'),
56
+			'active'     => __('Active', 'invoicing'),
57
+			'failing'    => __('Failing', 'invoicing'),
58
+			'expired'    => __('Expired', 'invoicing'),
59
+			'completed'  => __('Complete', 'invoicing'),
60
+			'cancelled'  => __('Cancelled', 'invoicing'),
61 61
 		)
62 62
 	);
63 63
 
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
  *
69 69
  * @return string
70 70
  */
71
-function getpaid_get_subscription_status_label( $status ) {
71
+function getpaid_get_subscription_status_label($status) {
72 72
 	$statuses = getpaid_get_subscription_statuses();
73
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
73
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
74 74
 }
75 75
 
76 76
 /**
@@ -100,14 +100,14 @@  discard block
 block discarded – undo
100 100
  *
101 101
  * @return array
102 102
  */
103
-function getpaid_get_subscription_status_counts( $args = array() ) {
103
+function getpaid_get_subscription_status_counts($args = array()) {
104 104
 
105
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
105
+	$statuses = array_keys(getpaid_get_subscription_statuses());
106 106
 	$counts   = array();
107 107
 
108
-	foreach ( $statuses as $status ) {
109
-		$_args             = wp_parse_args( "status=$status", $args );
110
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
108
+	foreach ($statuses as $status) {
109
+		$_args             = wp_parse_args("status=$status", $args);
110
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
111 111
 	}
112 112
 
113 113
 	return $counts;
@@ -126,23 +126,23 @@  discard block
 block discarded – undo
126 126
 		array(
127 127
 
128 128
 			'day'   => array(
129
-				'singular' => __( '%s day', 'invoicing' ),
130
-				'plural'   => __( '%d days', 'invoicing' ),
129
+				'singular' => __('%s day', 'invoicing'),
130
+				'plural'   => __('%d days', 'invoicing'),
131 131
 			),
132 132
 
133 133
 			'week'   => array(
134
-				'singular' => __( '%s week', 'invoicing' ),
135
-				'plural'   => __( '%d weeks', 'invoicing' ),
134
+				'singular' => __('%s week', 'invoicing'),
135
+				'plural'   => __('%d weeks', 'invoicing'),
136 136
 			),
137 137
 
138 138
 			'month'   => array(
139
-				'singular' => __( '%s month', 'invoicing' ),
140
-				'plural'   => __( '%d months', 'invoicing' ),
139
+				'singular' => __('%s month', 'invoicing'),
140
+				'plural'   => __('%d months', 'invoicing'),
141 141
 			),
142 142
 
143 143
 			'year'   => array(
144
-				'singular' => __( '%s year', 'invoicing' ),
145
-				'plural'   => __( '%d years', 'invoicing' ),
144
+				'singular' => __('%s year', 'invoicing'),
145
+				'plural'   => __('%d years', 'invoicing'),
146 146
 			),
147 147
 
148 148
 		)
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
  * @param string $trial_period
157 157
  * @return int
158 158
  */
159
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
160
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
159
+function getpaid_get_subscription_trial_period_interval($trial_period) {
160
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
161 161
 }
162 162
 
163 163
 /**
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
  * @param string $trial_period
167 167
  * @return string
168 168
  */
169
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
170
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
169
+function getpaid_get_subscription_trial_period_period($trial_period) {
170
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
171 171
 }
172 172
 
173 173
 /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
  * @param int $interval
178 178
  * @return string
179 179
  */
180
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
181
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
182
-	return strtolower( sanitize_text_field( $label ) );
180
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
181
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
182
+	return strtolower(sanitize_text_field($label));
183 183
 }
184 184
 
185 185
 /**
@@ -188,19 +188,19 @@  discard block
 block discarded – undo
188 188
  * @param string $period
189 189
  * @return string
190 190
  */
191
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
191
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
192 192
 
193 193
 	$periods = getpaid_get_subscription_periods();
194
-	$period  = strtolower( $period );
194
+	$period  = strtolower($period);
195 195
 
196
-	if ( isset( $periods[ $period ] ) ) {
197
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
196
+	if (isset($periods[$period])) {
197
+		return sprintf($periods[$period]['singular'], $singular_prefix);
198 198
 	}
199 199
 
200 200
 	// Backwards compatibility.
201
-	foreach ( $periods as $key => $data ) {
202
-		if ( strpos( $key, $period ) === 0 ) {
203
-			return sprintf( $data['singular'], $singular_prefix );
201
+	foreach ($periods as $key => $data) {
202
+		if (strpos($key, $period) === 0) {
203
+			return sprintf($data['singular'], $singular_prefix);
204 204
 		}
205 205
 	}
206 206
 
@@ -215,19 +215,19 @@  discard block
 block discarded – undo
215 215
  * @param int $interval
216 216
  * @return string
217 217
  */
218
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
218
+function getpaid_get_plural_subscription_period_label($period, $interval) {
219 219
 
220 220
 	$periods = getpaid_get_subscription_periods();
221
-	$period  = strtolower( $period );
221
+	$period  = strtolower($period);
222 222
 
223
-	if ( isset( $periods[ $period ] ) ) {
224
-		return sprintf( $periods[ $period ]['plural'], $interval );
223
+	if (isset($periods[$period])) {
224
+		return sprintf($periods[$period]['plural'], $interval);
225 225
 	}
226 226
 
227 227
 	// Backwards compatibility.
228
-	foreach ( $periods as $key => $data ) {
229
-		if ( strpos( $key, $period ) === 0 ) {
230
-			return sprintf( $data['plural'], $interval );
228
+	foreach ($periods as $key => $data) {
229
+		if (strpos($key, $period) === 0) {
230
+			return sprintf($data['plural'], $interval);
231 231
 		}
232 232
 	}
233 233
 
@@ -241,23 +241,23 @@  discard block
 block discarded – undo
241 241
  * @param WPInv_Subscription $subscription
242 242
  * @return string
243 243
  */
244
-function getpaid_get_formatted_subscription_amount( $subscription ) {
244
+function getpaid_get_formatted_subscription_amount($subscription) {
245 245
 
246
-	$initial   = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() );
247
-	$recurring = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() );
248
-	$period    = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
246
+	$initial   = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency());
247
+	$recurring = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency());
248
+	$period    = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
249 249
 
250 250
 	// Trial periods.
251
-	if ( $subscription->has_trial_period() ) {
251
+	if ($subscription->has_trial_period()) {
252 252
 
253
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
254
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
253
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
254
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
255 255
 		return sprintf(
256 256
 
257 257
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
258
-			_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
258
+			_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
259 259
 			$initial,
260
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
260
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
261 261
 			$recurring,
262 262
 			$period
263 263
 
@@ -265,12 +265,12 @@  discard block
 block discarded – undo
265 265
 
266 266
 	}
267 267
 
268
-	if ( $initial != $recurring ) {
268
+	if ($initial != $recurring) {
269 269
 
270 270
 		return sprintf(
271 271
 
272 272
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
273
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
273
+			_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
274 274
 			$initial,
275 275
 			$recurring,
276 276
 			$period
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	return sprintf(
283 283
 
284 284
 		// translators: $1: is the recurring amount, $2: is the recurring period
285
-		_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
285
+		_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
286 286
 		$initial,
287 287
 		$period
288 288
 
@@ -296,8 +296,8 @@  discard block
 block discarded – undo
296 296
  * @param WPInv_Invoice $invoice
297 297
  * @return WPInv_Subscription|bool
298 298
  */
299
-function getpaid_get_invoice_subscription( $invoice ) {
300
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
299
+function getpaid_get_invoice_subscription($invoice) {
300
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
301 301
 }
302 302
 
303 303
 /**
@@ -305,9 +305,9 @@  discard block
 block discarded – undo
305 305
  *
306 306
  * @param WPInv_Invoice $invoice
307 307
  */
308
-function getpaid_activate_invoice_subscription( $invoice ) {
309
-	$subscription = getpaid_get_invoice_subscription( $invoice );
310
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
308
+function getpaid_activate_invoice_subscription($invoice) {
309
+	$subscription = getpaid_get_invoice_subscription($invoice);
310
+	if (is_a($subscription, 'WPInv_Subscription')) {
311 311
 		$subscription->activate();
312 312
 	}
313 313
 }
@@ -318,7 +318,7 @@  discard block
 block discarded – undo
318 318
  * @return WPInv_Subscriptions
319 319
  */
320 320
 function getpaid_subscriptions() {
321
-	return getpaid()->get( 'subscriptions' );
321
+	return getpaid()->get('subscriptions');
322 322
 }
323 323
 
324 324
 /**
@@ -326,13 +326,13 @@  discard block
 block discarded – undo
326 326
  *
327 327
  * @return WPInv_Subscription|bool
328 328
  */
329
-function wpinv_get_subscription( $invoice ) {
329
+function wpinv_get_subscription($invoice) {
330 330
 
331 331
     // Retrieve the invoice.
332
-    $invoice = new WPInv_Invoice( $invoice );
332
+    $invoice = new WPInv_Invoice($invoice);
333 333
 
334 334
     // Ensure it is a recurring invoice.
335
-    if ( ! $invoice->is_recurring() ) {
335
+    if (!$invoice->is_recurring()) {
336 336
         return false;
337 337
     }
338 338
 
@@ -344,6 +344,6 @@  discard block
 block discarded – undo
344 344
 		)
345 345
 	);
346 346
 
347
-	return empty( $subscription ) ? false : $subscription[0];
347
+	return empty($subscription) ? false : $subscription[0];
348 348
 
349 349
 }
Please login to merge, or discard this patch.