Passed
Push — master ( def67b...f4bb32 )
by Stiofan
08:12 queued 04:13
created
includes/gateways/manual.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_manual_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/worldpay.php 1 patch
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_worldpay_cc_form', '__return_false' );
5
+add_action('wpinv_worldpay_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_worldpay_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_worldpay_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
     
12 12
     // Collect payment data
@@ -24,132 +24,132 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
29
+    if (!empty($invoice)) {
30 30
         $quantities_enabled = wpinv_item_quantities_enabled();
31 31
         
32
-        $instId     = wpinv_get_option( 'worldpay_instId', false );
32
+        $instId     = wpinv_get_option('worldpay_instId', false);
33 33
         $cartId     = $invoice->get_number();
34
-        $testMode   = wpinv_is_test_mode( 'worldpay' ) ? 100 : 0;
34
+        $testMode   = wpinv_is_test_mode('worldpay') ? 100 : 0;
35 35
         $name       = $invoice->get_user_full_name();
36
-        $address    = wp_strip_all_tags( $invoice->get_address(), true );
36
+        $address    = wp_strip_all_tags($invoice->get_address(), true);
37 37
         $postcode   = $invoice->zip;
38 38
         $tel        = $invoice->phone;
39 39
         $email      = $invoice->get_email();
40 40
         $country    = $invoice->country;
41
-        $amount     = wpinv_sanitize_amount( $invoice->get_total() );
41
+        $amount     = wpinv_sanitize_amount($invoice->get_total());
42 42
         $currency   = wpinv_get_currency();
43 43
         
44 44
         $items      = array();
45
-        foreach ( $invoice->get_cart_details() as $item ) {
45
+        foreach ($invoice->get_cart_details() as $item) {
46 46
             $item_desc  = $item['name'];
47
-            $quantity   = !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
-            $item_desc .= ' (' . ( $quantities_enabled ? $quantity . 'x ' : '' ) . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
47
+            $quantity   = !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
48
+            $item_desc .= ' (' . ($quantities_enabled ? $quantity . 'x ' : '') . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
49 49
             
50 50
             $items[] = $item_desc;
51 51
         }
52 52
         
53
-        $desc = implode( ', ', $items );
54
-        if ( wpinv_use_taxes() && $invoice->get_tax() > 0 ) {
55
-            $desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
53
+        $desc = implode(', ', $items);
54
+        if (wpinv_use_taxes() && $invoice->get_tax() > 0) {
55
+            $desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
56 56
         }
57 57
         
58 58
         $extra_params                   = array();
59 59
         $extra_params['MC_description'] = $desc;
60
-        $extra_params['MC_callback']    = wpinv_get_ipn_url( 'worldpay' );
60
+        $extra_params['MC_callback']    = wpinv_get_ipn_url('worldpay');
61 61
         $extra_params['MC_key']         = $invoice->get_key();
62 62
         $extra_params['MC_invoice_id']  = $invoice->ID;
63 63
         $extra_params['address1']       = $address;
64 64
         $extra_params['town']           = $invoice->city;
65 65
         $extra_params['region']         = $invoice->state;
66
-        $extra_params['amountString']   = $invoice->get_total( true );
67
-        $extra_params['countryString']  = wpinv_country_name( $invoice->country );
66
+        $extra_params['amountString']   = $invoice->get_total(true);
67
+        $extra_params['countryString']  = wpinv_country_name($invoice->country);
68 68
         $extra_params['compName']       = $invoice->company;
69 69
         
70
-        $extra_params   = apply_filters( 'wpinv_worldpay_form_extra_parameters', $extra_params, $invoice );
70
+        $extra_params   = apply_filters('wpinv_worldpay_form_extra_parameters', $extra_params, $invoice);
71 71
         
72
-        $redirect_text  = __( 'Redirecting to Worldpay site, click on button if not redirected.', 'invoicing' );
73
-        $redirect_text  = apply_filters( 'wpinv_worldpay_redirect_text', $redirect_text, $invoice );
72
+        $redirect_text  = __('Redirecting to Worldpay site, click on button if not redirected.', 'invoicing');
73
+        $redirect_text  = apply_filters('wpinv_worldpay_redirect_text', $redirect_text, $invoice);
74 74
         
75 75
         // Empty the shopping cart
76 76
         wpinv_empty_cart();
77 77
         ?>
78 78
 <div class="wpi-worldpay-form" style="padding:20px;font-family:arial,sans-serif;text-align:center;color:#555">
79
-<?php do_action( 'wpinv_worldpay_form_before', $invoice ); ?>
80
-<h3><?php echo $redirect_text ;?></h3>
79
+<?php do_action('wpinv_worldpay_form_before', $invoice); ?>
80
+<h3><?php echo $redirect_text; ?></h3>
81 81
 <form action="<?php echo wpinv_get_worldpay_redirect(); ?>" name="wpi_worldpay_form" method="POST">
82
-    <input type="hidden" value="<?php echo $amount;?>" name="amount">
83
-    <input type="hidden" value="<?php echo esc_attr( $cartId );?>" name="cartId">
84
-    <input type="hidden" value="<?php echo $currency;?>" name="currency">
85
-    <input type="hidden" value="<?php echo $instId;?>" name="instId">
86
-    <input type="hidden" value="<?php echo $testMode;?>" name="testMode">
87
-    <input type="hidden" value="<?php echo esc_attr( $name );?>" name="name">
88
-    <input type="hidden" value="<?php echo esc_attr( $address );?>" name="address">
89
-    <input type="hidden" value="<?php echo esc_attr( $postcode );?>" name="postcode">
90
-    <input type="hidden" value="<?php echo esc_attr( $tel );?>" name="tel">
91
-    <input type="hidden" value="<?php echo esc_attr( $email );?>" name="email">
92
-    <input type="hidden" value="<?php echo esc_attr( $country );?>" name="country">
93
-    <input type="hidden" value="<?php echo esc_attr( $desc );?>" name="desc">
94
-    <?php foreach ( $extra_params as $param => $value ) { ?>
95
-        <?php if ( !empty( $value !== false ) ) { ?>
96
-    <input type="hidden" value="<?php echo esc_attr( $value );?>" name="<?php echo esc_attr( $param );?>">
82
+    <input type="hidden" value="<?php echo $amount; ?>" name="amount">
83
+    <input type="hidden" value="<?php echo esc_attr($cartId); ?>" name="cartId">
84
+    <input type="hidden" value="<?php echo $currency; ?>" name="currency">
85
+    <input type="hidden" value="<?php echo $instId; ?>" name="instId">
86
+    <input type="hidden" value="<?php echo $testMode; ?>" name="testMode">
87
+    <input type="hidden" value="<?php echo esc_attr($name); ?>" name="name">
88
+    <input type="hidden" value="<?php echo esc_attr($address); ?>" name="address">
89
+    <input type="hidden" value="<?php echo esc_attr($postcode); ?>" name="postcode">
90
+    <input type="hidden" value="<?php echo esc_attr($tel); ?>" name="tel">
91
+    <input type="hidden" value="<?php echo esc_attr($email); ?>" name="email">
92
+    <input type="hidden" value="<?php echo esc_attr($country); ?>" name="country">
93
+    <input type="hidden" value="<?php echo esc_attr($desc); ?>" name="desc">
94
+    <?php foreach ($extra_params as $param => $value) { ?>
95
+        <?php if (!empty($value !== false)) { ?>
96
+    <input type="hidden" value="<?php echo esc_attr($value); ?>" name="<?php echo esc_attr($param); ?>">
97 97
         <?php } ?>
98 98
     <?php } ?>
99
-    <?php do_action( 'wpinv_worldpay_form_parameters', $invoice ); ?>
100
-    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e( 'Pay by Debit/Credit Card (WorldPay)', 'invoicing' ) ;?>">
99
+    <?php do_action('wpinv_worldpay_form_parameters', $invoice); ?>
100
+    <input type="submit" name="wpi_worldpay_submit" value="<?php esc_attr_e('Pay by Debit/Credit Card (WorldPay)', 'invoicing'); ?>">
101 101
 </form>
102 102
 <script type="text/javascript">document.wpi_worldpay_form.submit();</script>
103
-<?php do_action( 'wpinv_worldpay_form_after', $invoice ); ?>
103
+<?php do_action('wpinv_worldpay_form_after', $invoice); ?>
104 104
 </div>
105 105
         <?php
106 106
     } else {
107
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
107
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a worldpay payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
108 108
         // If errors are present, send the user back to the purchase page so they can be corrected
109
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
109
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
110 110
     }
111 111
 }
112
-add_action( 'wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment' );
112
+add_action('wpinv_gateway_worldpay', 'wpinv_process_worldpay_payment');
113 113
 
114 114
 function wpinv_get_worldpay_redirect() {
115
-    $redirect = wpinv_is_test_mode( 'worldpay' ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
115
+    $redirect = wpinv_is_test_mode('worldpay') ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
116 116
     
117
-    return apply_filters( 'wpinv_worldpay_redirect', $redirect );
117
+    return apply_filters('wpinv_worldpay_redirect', $redirect);
118 118
 }
119 119
 
120 120
 function wpinv_process_worldpay_ipn() {
121
-    $request = wpinv_get_post_data( 'post' );
121
+    $request = wpinv_get_post_data('post');
122 122
     
123
-    if ( !empty( $request['cartId'] ) && !empty( $request['transStatus'] ) && !empty( $request['installation'] ) && isset( $request['testMode'] ) && isset( $request['MC_invoice_id'] ) && isset( $request['MC_key'] ) ) {
123
+    if (!empty($request['cartId']) && !empty($request['transStatus']) && !empty($request['installation']) && isset($request['testMode']) && isset($request['MC_invoice_id']) && isset($request['MC_key'])) {
124 124
         $invoice_id = $request['MC_invoice_id'];
125 125
         
126
-        if ( $invoice_id == wpinv_get_invoice_id_by_key( $request['MC_key'] ) && $invoice = wpinv_get_invoice( $invoice_id ) ) {
127
-            if ( $request['transStatus'] == 'Y' ) {                
128
-                wpinv_update_payment_status( $invoice_id, 'publish' );
129
-                wpinv_set_payment_transaction_id( $invoice_id, $request['transId'] );
130
-                wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Worldpay Transaction ID: %s', 'invoicing' ), $request['transId'] ) );
126
+        if ($invoice_id == wpinv_get_invoice_id_by_key($request['MC_key']) && $invoice = wpinv_get_invoice($invoice_id)) {
127
+            if ($request['transStatus'] == 'Y') {                
128
+                wpinv_update_payment_status($invoice_id, 'publish');
129
+                wpinv_set_payment_transaction_id($invoice_id, $request['transId']);
130
+                wpinv_insert_payment_note($invoice_id, sprintf(__('Worldpay Transaction ID: %s', 'invoicing'), $request['transId']));
131 131
                 return;
132
-            } else if ( $request['transStatus'] == 'C' ) {
133
-                wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
134
-                wpinv_insert_payment_note( $invoice_id, __( 'Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing' ) );
132
+            } else if ($request['transStatus'] == 'C') {
133
+                wpinv_update_payment_status($invoice_id, 'wpi-failed');
134
+                wpinv_insert_payment_note($invoice_id, __('Payment transaction failed while processing Worldpay payment, kindly check IPN log.', 'invoicing'));
135 135
                 
136
-                wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing' ), json_encode( $request ) ), $invoice_id );
136
+                wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Payment transaction failed while processing Worldpay payment. IPN data: %s', 'invoicing'), json_encode($request)), $invoice_id);
137 137
                 return;
138 138
             }
139 139
         }
140 140
     }
141 141
     return;
142 142
 }
143
-add_action( 'wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn' );
143
+add_action('wpinv_verify_worldpay_ipn', 'wpinv_process_worldpay_ipn');
144 144
 
145 145
 function wpinv_is_worldpay_valid_for_use() {
146
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_worldpay_supported_currencies', array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' )));
146
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_worldpay_supported_currencies', array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR')));
147 147
 }
148 148
 
149
-function wpinv_check_worldpay_currency_support( $gateway_list ) {
150
-    if ( isset( $gateway_list['worldpay'] ) && ! wpinv_is_worldpay_valid_for_use() ) {
151
-        unset( $gateway_list['worldpay'] );
149
+function wpinv_check_worldpay_currency_support($gateway_list) {
150
+    if (isset($gateway_list['worldpay']) && !wpinv_is_worldpay_valid_for_use()) {
151
+        unset($gateway_list['worldpay']);
152 152
     }
153 153
     return $gateway_list;
154 154
 }
155
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1 );
156 155
\ No newline at end of file
156
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_worldpay_currency_support', 10, 1);
157 157
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-subscriptions-db.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 /**
6 6
  * The Subscriptions DB Class
@@ -68,8 +68,8 @@  discard block
 block discarded – undo
68 68
             'transaction_id'    => '',
69 69
             'parent_payment_id' => 0,
70 70
             'product_id'        => 0,
71
-            'created'           => date( 'Y-m-d H:i:s' ),
72
-            'expiration'        => date( 'Y-m-d H:i:s' ),
71
+            'created'           => date('Y-m-d H:i:s'),
72
+            'expiration'        => date('Y-m-d H:i:s'),
73 73
             'trial_period'      => '',
74 74
             'status'            => '',
75 75
             'profile_id'        => '',
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
      * @access  public
83 83
      * @since   1.0.0
84 84
      */
85
-    public function get_subscriptions( $args = array() ) {
85
+    public function get_subscriptions($args = array()) {
86 86
         global $wpdb;
87 87
 
88 88
         $defaults = array(
89
-            'number'       => get_option( 'posts_per_page' ),
89
+            'number'       => get_option('posts_per_page'),
90 90
             'offset'       => 0,
91 91
             'search'       => '',
92 92
             'customer_id'  => 0,
@@ -94,21 +94,21 @@  discard block
 block discarded – undo
94 94
             'order'        => 'DESC'
95 95
         );
96 96
 
97
-        $args  = wp_parse_args( $args, $defaults );
97
+        $args = wp_parse_args($args, $defaults);
98 98
 
99
-        if( $args['number'] < 1 ) {
99
+        if ($args['number'] < 1) {
100 100
             $args['number'] = 999999999999;
101 101
         }
102 102
 
103 103
         $where = ' WHERE 1=1 ';
104 104
 
105 105
         // specific customers
106
-        if( ! empty( $args['id'] ) ) {
106
+        if (!empty($args['id'])) {
107 107
 
108
-            if( is_array( $args['id'] ) ) {
109
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
108
+            if (is_array($args['id'])) {
109
+                $ids = implode(',', array_map('intval', $args['id']));
110 110
             } else {
111
-                $ids = intval( $args['id'] );
111
+                $ids = intval($args['id']);
112 112
             }
113 113
 
114 114
             $where .= " AND `id` IN( {$ids} ) ";
@@ -116,12 +116,12 @@  discard block
 block discarded – undo
116 116
         }
117 117
 
118 118
         // Specific products
119
-        if( ! empty( $args['product_id'] ) ) {
119
+        if (!empty($args['product_id'])) {
120 120
 
121
-            if( is_array( $args['product_id'] ) ) {
122
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
121
+            if (is_array($args['product_id'])) {
122
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
123 123
             } else {
124
-                $product_ids = intval( $args['product_id'] );
124
+                $product_ids = intval($args['product_id']);
125 125
             }
126 126
 
127 127
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -129,12 +129,12 @@  discard block
 block discarded – undo
129 129
         }
130 130
 
131 131
         // Specific parent payments
132
-        if( ! empty( $args['parent_payment_id'] ) ) {
132
+        if (!empty($args['parent_payment_id'])) {
133 133
 
134
-            if( is_array( $args['parent_payment_id'] ) ) {
135
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
134
+            if (is_array($args['parent_payment_id'])) {
135
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
136 136
             } else {
137
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
137
+                $parent_payment_ids = intval($args['parent_payment_id']);
138 138
             }
139 139
 
140 140
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
         }
143 143
 
144 144
         // Specific transaction IDs
145
-        if( ! empty( $args['transaction_id'] ) ) {
145
+        if (!empty($args['transaction_id'])) {
146 146
 
147
-            if( is_array( $args['transaction_id'] ) ) {
148
-                $transaction_ids = implode( "','", array_map('sanitize_text_field', $args['transaction_id'] ) );
147
+            if (is_array($args['transaction_id'])) {
148
+                $transaction_ids = implode("','", array_map('sanitize_text_field', $args['transaction_id']));
149 149
             } else {
150
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
150
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
151 151
             }
152 152
 
153 153
             $where .= " AND `transaction_id` IN ( '{$transaction_ids}' ) ";
@@ -155,12 +155,12 @@  discard block
 block discarded – undo
155 155
         }
156 156
 
157 157
         // Subscriptoins for specific customers
158
-        if( ! empty( $args['customer_id'] ) ) {
158
+        if (!empty($args['customer_id'])) {
159 159
 
160
-            if( is_array( $args['customer_id'] ) ) {
161
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
160
+            if (is_array($args['customer_id'])) {
161
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
162 162
             } else {
163
-                $customer_ids = intval( $args['customer_id'] );
163
+                $customer_ids = intval($args['customer_id']);
164 164
             }
165 165
 
166 166
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -168,12 +168,12 @@  discard block
 block discarded – undo
168 168
         }
169 169
 
170 170
         // Subscriptions for specific profile IDs
171
-        if( ! empty( $args['profile_id'] ) ) {
171
+        if (!empty($args['profile_id'])) {
172 172
 
173
-            if( is_array( $args['profile_id'] ) ) {
174
-                $profile_ids = implode( "','", array_map('sanitize_text_field', $args['profile_id'] ) );
173
+            if (is_array($args['profile_id'])) {
174
+                $profile_ids = implode("','", array_map('sanitize_text_field', $args['profile_id']));
175 175
             } else {
176
-                $profile_ids = sanitize_text_field( $args['profile_id'] );
176
+                $profile_ids = sanitize_text_field($args['profile_id']);
177 177
             }
178 178
 
179 179
             $where .= " AND `profile_id` IN( '{$profile_ids}' ) ";
@@ -181,12 +181,12 @@  discard block
 block discarded – undo
181 181
         }
182 182
 
183 183
         // Subscriptions for specific statuses
184
-        if( ! empty( $args['status'] ) ) {
184
+        if (!empty($args['status'])) {
185 185
 
186
-            if( is_array( $args['status'] ) ) {
187
-                $statuses = implode( "','", array_map( 'sanitize_text_field', $args['status'] ) );
186
+            if (is_array($args['status'])) {
187
+                $statuses = implode("','", array_map('sanitize_text_field', $args['status']));
188 188
             } else {
189
-                $statuses = sanitize_text_field( $args['status'] );
189
+                $statuses = sanitize_text_field($args['status']);
190 190
             }
191 191
 
192 192
             $where .= " AND `status` IN( '{$statuses}' ) ";
@@ -194,21 +194,21 @@  discard block
 block discarded – undo
194 194
         }
195 195
 
196 196
         // Subscriptions created for a specific date or in a date range
197
-        if( ! empty( $args['date'] ) ) {
197
+        if (!empty($args['date'])) {
198 198
 
199
-            if( is_array( $args['date'] ) ) {
199
+            if (is_array($args['date'])) {
200 200
 
201
-                if( ! empty( $args['date']['start'] ) ) {
201
+                if (!empty($args['date']['start'])) {
202 202
 
203
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
203
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
204 204
 
205 205
                     $where .= " AND `created` >= '{$start}'";
206 206
 
207 207
                 }
208 208
 
209
-                if( ! empty( $args['date']['end'] ) ) {
209
+                if (!empty($args['date']['end'])) {
210 210
 
211
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
211
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
212 212
 
213 213
                     $where .= " AND `created` <= '{$end}'";
214 214
 
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 
217 217
             } else {
218 218
 
219
-                $year  = date( 'Y', strtotime( $args['date'] ) );
220
-                $month = date( 'm', strtotime( $args['date'] ) );
221
-                $day   = date( 'd', strtotime( $args['date'] ) );
219
+                $year  = date('Y', strtotime($args['date']));
220
+                $month = date('m', strtotime($args['date']));
221
+                $day   = date('d', strtotime($args['date']));
222 222
 
223 223
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
224 224
             }
@@ -226,21 +226,21 @@  discard block
 block discarded – undo
226 226
         }
227 227
 
228 228
         // Subscriptions with a specific expiration date or in an expiration date range
229
-        if( ! empty( $args['expiration'] ) ) {
229
+        if (!empty($args['expiration'])) {
230 230
 
231
-            if( is_array( $args['expiration'] ) ) {
231
+            if (is_array($args['expiration'])) {
232 232
 
233
-                if( ! empty( $args['expiration']['start'] ) ) {
233
+                if (!empty($args['expiration']['start'])) {
234 234
 
235
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
235
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
236 236
 
237 237
                     $where .= " AND `expiration` >= '{$start}'";
238 238
 
239 239
                 }
240 240
 
241
-                if( ! empty( $args['expiration']['end'] ) ) {
241
+                if (!empty($args['expiration']['end'])) {
242 242
 
243
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
243
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
244 244
 
245 245
                     $where .= " AND `expiration` <= '{$end}'";
246 246
 
@@ -248,73 +248,73 @@  discard block
 block discarded – undo
248 248
 
249 249
             } else {
250 250
 
251
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
252
-                $month = date( 'm', strtotime( $args['expiration'] ) );
253
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
251
+                $year  = date('Y', strtotime($args['expiration']));
252
+                $month = date('m', strtotime($args['expiration']));
253
+                $day   = date('d', strtotime($args['expiration']));
254 254
 
255 255
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
256 256
             }
257 257
 
258 258
         }
259 259
 
260
-        if ( ! empty( $args['search'] ) ) {
260
+        if (!empty($args['search'])) {
261 261
 
262
-            if( false !== strpos( 'id:', $args['search'] ) ) {
262
+            if (false !== strpos('id:', $args['search'])) {
263 263
 
264
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
265
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
264
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
265
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
266 266
 
267
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
267
+            } else if (false !== strpos($args['search'], 'txn:')) {
268 268
 
269
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
270
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
269
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
270
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
271 271
 
272
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
272
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
273 273
 
274
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
275
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
274
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
275
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
276 276
 
277
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
277
+            } else if (false !== strpos($args['search'], 'product_id:')) {
278 278
 
279
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
280
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
279
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
280
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
281 281
 
282
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
282
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
283 283
 
284
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
285
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
284
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
285
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
286 286
 
287 287
             } else {
288 288
 
289
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
289
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
290 290
 
291 291
             }
292 292
 
293 293
         }
294 294
 
295
-        $args['orderby'] = ! array_key_exists( $args['orderby'], $this->get_columns() ) ? 'id' : $args['orderby'];
295
+        $args['orderby'] = !array_key_exists($args['orderby'], $this->get_columns()) ? 'id' : $args['orderby'];
296 296
 
297
-        if( 'amount' == $args['orderby'] ) {
297
+        if ('amount' == $args['orderby']) {
298 298
             $args['orderby'] = 'amount+0';
299 299
         }
300 300
 
301
-        $cache_key = md5( 'wpinv_subscriptions_' . serialize( $args ) );
301
+        $cache_key = md5('wpinv_subscriptions_' . serialize($args));
302 302
 
303
-        $subscriptions = wp_cache_get( $cache_key, 'subscriptions' );
303
+        $subscriptions = wp_cache_get($cache_key, 'subscriptions');
304 304
 
305
-        $args['orderby'] = esc_sql( $args['orderby'] );
306
-        $args['order']   = esc_sql( $args['order'] );
305
+        $args['orderby'] = esc_sql($args['orderby']);
306
+        $args['order']   = esc_sql($args['order']);
307 307
 
308
-        if( $subscriptions === false ) {
309
-            $subscriptions = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint( $args['offset'] ), absint( $args['number'] ) ), OBJECT );
308
+        if ($subscriptions === false) {
309
+            $subscriptions = $wpdb->get_results($wpdb->prepare("SELECT * FROM  $this->table_name $where ORDER BY {$args['orderby']} {$args['order']} LIMIT %d,%d;", absint($args['offset']), absint($args['number'])), OBJECT);
310 310
 
311
-            if( ! empty( $subscriptions ) ) {
311
+            if (!empty($subscriptions)) {
312 312
 
313
-                foreach( $subscriptions as $key => $subscription ) {
314
-                    $subscriptions[ $key ] = new WPInv_Subscription( $subscription );
313
+                foreach ($subscriptions as $key => $subscription) {
314
+                    $subscriptions[$key] = new WPInv_Subscription($subscription);
315 315
                 }
316 316
 
317
-                wp_cache_set( $cache_key, $subscriptions, 'subscriptions', 3600 );
317
+                wp_cache_set($cache_key, $subscriptions, 'subscriptions', 3600);
318 318
 
319 319
             }
320 320
 
@@ -329,19 +329,19 @@  discard block
 block discarded – undo
329 329
      * @access  public
330 330
      * @since   1.0.0
331 331
      */
332
-    public function count( $args = array() ) {
332
+    public function count($args = array()) {
333 333
 
334 334
         global $wpdb;
335 335
 
336 336
         $where = ' WHERE 1=1 ';
337 337
 
338 338
         // specific customers
339
-        if( ! empty( $args['id'] ) ) {
339
+        if (!empty($args['id'])) {
340 340
 
341
-            if( is_array( $args['id'] ) ) {
342
-                $ids = implode( ',', array_map('intval', $args['id'] ) );
341
+            if (is_array($args['id'])) {
342
+                $ids = implode(',', array_map('intval', $args['id']));
343 343
             } else {
344
-                $ids = intval( $args['id'] );
344
+                $ids = intval($args['id']);
345 345
             }
346 346
 
347 347
             $where .= " AND `id` IN( {$ids} ) ";
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
         }
350 350
 
351 351
         // Specific products
352
-        if( ! empty( $args['product_id'] ) ) {
352
+        if (!empty($args['product_id'])) {
353 353
 
354
-            if( is_array( $args['product_id'] ) ) {
355
-                $product_ids = implode( ',', array_map('intval', $args['product_id'] ) );
354
+            if (is_array($args['product_id'])) {
355
+                $product_ids = implode(',', array_map('intval', $args['product_id']));
356 356
             } else {
357
-                $product_ids = intval( $args['product_id'] );
357
+                $product_ids = intval($args['product_id']);
358 358
             }
359 359
 
360 360
             $where .= " AND `product_id` IN( {$product_ids} ) ";
@@ -362,12 +362,12 @@  discard block
 block discarded – undo
362 362
         }
363 363
 
364 364
         // Specific parent payments
365
-        if( ! empty( $args['parent_payment_id'] ) ) {
365
+        if (!empty($args['parent_payment_id'])) {
366 366
 
367
-            if( is_array( $args['parent_payment_id'] ) ) {
368
-                $parent_payment_ids = implode( ',', array_map('intval', $args['parent_payment_id'] ) );
367
+            if (is_array($args['parent_payment_id'])) {
368
+                $parent_payment_ids = implode(',', array_map('intval', $args['parent_payment_id']));
369 369
             } else {
370
-                $parent_payment_ids = intval( $args['parent_payment_id'] );
370
+                $parent_payment_ids = intval($args['parent_payment_id']);
371 371
             }
372 372
 
373 373
             $where .= " AND `parent_payment_id` IN( {$parent_payment_ids} ) ";
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
         }
376 376
 
377 377
         // Subscriptoins for specific customers
378
-        if( ! empty( $args['customer_id'] ) ) {
378
+        if (!empty($args['customer_id'])) {
379 379
 
380
-            if( is_array( $args['customer_id'] ) ) {
381
-                $customer_ids = implode( ',', array_map('intval', $args['customer_id'] ) );
380
+            if (is_array($args['customer_id'])) {
381
+                $customer_ids = implode(',', array_map('intval', $args['customer_id']));
382 382
             } else {
383
-                $customer_ids = intval( $args['customer_id'] );
383
+                $customer_ids = intval($args['customer_id']);
384 384
             }
385 385
 
386 386
             $where .= " AND `customer_id` IN( {$customer_ids} ) ";
@@ -388,12 +388,12 @@  discard block
 block discarded – undo
388 388
         }
389 389
 
390 390
         // Subscriptions for specific profile IDs
391
-        if( ! empty( $args['profile_id'] ) ) {
391
+        if (!empty($args['profile_id'])) {
392 392
 
393
-            if( is_array( $args['profile_id'] ) ) {
394
-                $profile_ids = implode( ',', array_map('intval', $args['profile_id'] ) );
393
+            if (is_array($args['profile_id'])) {
394
+                $profile_ids = implode(',', array_map('intval', $args['profile_id']));
395 395
             } else {
396
-                $profile_ids = intval( $args['profile_id'] );
396
+                $profile_ids = intval($args['profile_id']);
397 397
             }
398 398
 
399 399
             $where .= " AND `profile_id` IN( {$profile_ids} ) ";
@@ -401,12 +401,12 @@  discard block
 block discarded – undo
401 401
         }
402 402
 
403 403
         // Specific transaction IDs
404
-        if( ! empty( $args['transaction_id'] ) ) {
404
+        if (!empty($args['transaction_id'])) {
405 405
 
406
-            if( is_array( $args['transaction_id'] ) ) {
407
-                $transaction_ids = implode( ',', array_map('sanitize_text_field', $args['transaction_id'] ) );
406
+            if (is_array($args['transaction_id'])) {
407
+                $transaction_ids = implode(',', array_map('sanitize_text_field', $args['transaction_id']));
408 408
             } else {
409
-                $transaction_ids = sanitize_text_field( $args['transaction_id'] );
409
+                $transaction_ids = sanitize_text_field($args['transaction_id']);
410 410
             }
411 411
 
412 412
             $where .= " AND `transaction_id` IN( {$transaction_ids} ) ";
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         // Subscriptions for specific statuses
417
-        if( ! empty( $args['status'] ) ) {
417
+        if (!empty($args['status'])) {
418 418
 
419
-            if( is_array( $args['status'] ) ) {
420
-                $statuses = implode( ',', $args['status'] );
419
+            if (is_array($args['status'])) {
420
+                $statuses = implode(',', $args['status']);
421 421
                 $where  .= " AND `status` IN( {$statuses} ) ";
422 422
             } else {
423 423
                 $statuses = $args['status'];
@@ -429,21 +429,21 @@  discard block
 block discarded – undo
429 429
         }
430 430
 
431 431
         // Subscriptions created for a specific date or in a date range
432
-        if( ! empty( $args['date'] ) ) {
432
+        if (!empty($args['date'])) {
433 433
 
434
-            if( is_array( $args['date'] ) ) {
434
+            if (is_array($args['date'])) {
435 435
 
436
-                if( ! empty( $args['date']['start'] ) ) {
436
+                if (!empty($args['date']['start'])) {
437 437
 
438
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['date']['start'] ) );
438
+                    $start = date('Y-m-d H:i:s', strtotime($args['date']['start']));
439 439
 
440 440
                     $where .= " AND `created` >= '{$start}'";
441 441
 
442 442
                 }
443 443
 
444
-                if( ! empty( $args['date']['end'] ) ) {
444
+                if (!empty($args['date']['end'])) {
445 445
 
446
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['date']['end'] ) );
446
+                    $end = date('Y-m-d H:i:s', strtotime($args['date']['end']));
447 447
 
448 448
                     $where .= " AND `created` <= '{$end}'";
449 449
 
@@ -451,9 +451,9 @@  discard block
 block discarded – undo
451 451
 
452 452
             } else {
453 453
 
454
-                $year  = date( 'Y', strtotime( $args['date'] ) );
455
-                $month = date( 'm', strtotime( $args['date'] ) );
456
-                $day   = date( 'd', strtotime( $args['date'] ) );
454
+                $year  = date('Y', strtotime($args['date']));
455
+                $month = date('m', strtotime($args['date']));
456
+                $day   = date('d', strtotime($args['date']));
457 457
 
458 458
                 $where .= " AND $year = YEAR ( created ) AND $month = MONTH ( created ) AND $day = DAY ( created )";
459 459
             }
@@ -461,21 +461,21 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         // Subscriptions with a specific expiration date or in an expiration date range
464
-        if( ! empty( $args['expiration'] ) ) {
464
+        if (!empty($args['expiration'])) {
465 465
 
466
-            if( is_array( $args['expiration'] ) ) {
466
+            if (is_array($args['expiration'])) {
467 467
 
468
-                if( ! empty( $args['expiration']['start'] ) ) {
468
+                if (!empty($args['expiration']['start'])) {
469 469
 
470
-                    $start = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['start'] ) );
470
+                    $start = date('Y-m-d H:i:s', strtotime($args['expiration']['start']));
471 471
 
472 472
                     $where .= " AND `expiration` >= '{$start}'";
473 473
 
474 474
                 }
475 475
 
476
-                if( ! empty( $args['expiration']['end'] ) ) {
476
+                if (!empty($args['expiration']['end'])) {
477 477
 
478
-                    $end = date( 'Y-m-d H:i:s', strtotime( $args['expiration']['end'] ) );
478
+                    $end = date('Y-m-d H:i:s', strtotime($args['expiration']['end']));
479 479
 
480 480
                     $where .= " AND `expiration` <= '{$end}'";
481 481
 
@@ -483,64 +483,64 @@  discard block
 block discarded – undo
483 483
 
484 484
             } else {
485 485
 
486
-                $year  = date( 'Y', strtotime( $args['expiration'] ) );
487
-                $month = date( 'm', strtotime( $args['expiration'] ) );
488
-                $day   = date( 'd', strtotime( $args['expiration'] ) );
486
+                $year  = date('Y', strtotime($args['expiration']));
487
+                $month = date('m', strtotime($args['expiration']));
488
+                $day   = date('d', strtotime($args['expiration']));
489 489
 
490 490
                 $where .= " AND $year = YEAR ( expiration ) AND $month = MONTH ( expiration ) AND $day = DAY ( expiration )";
491 491
             }
492 492
 
493 493
         }
494 494
 
495
-        if ( ! empty( $args['search'] ) ) {
495
+        if (!empty($args['search'])) {
496 496
 
497
-            if( false !== strpos( 'id:', $args['search'] ) ) {
497
+            if (false !== strpos('id:', $args['search'])) {
498 498
 
499
-                $args['search'] = trim( str_replace( 'id:', '', $args['search'] ) );
500
-                $where .= " AND `id` = '" . esc_sql( $args['search'] ) . "'";
499
+                $args['search'] = trim(str_replace('id:', '', $args['search']));
500
+                $where .= " AND `id` = '" . esc_sql($args['search']) . "'";
501 501
 
502
-            } else if( false !== strpos( $args['search'], 'txn:' ) ) {
502
+            } else if (false !== strpos($args['search'], 'txn:')) {
503 503
 
504
-                $args['search'] = trim( str_replace( 'txn:', '', $args['search'] ) );
505
-                $where .= " AND `transaction_id` = '" . esc_sql( $args['search'] ) . "'";
504
+                $args['search'] = trim(str_replace('txn:', '', $args['search']));
505
+                $where .= " AND `transaction_id` = '" . esc_sql($args['search']) . "'";
506 506
 
507
-            } else if( false !== strpos( $args['search'], 'profile_id:' ) ) {
507
+            } else if (false !== strpos($args['search'], 'profile_id:')) {
508 508
 
509
-                $args['search'] = trim( str_replace( 'profile_id:', '', $args['search'] ) );
510
-                $where .= " AND `profile_id` = '" . esc_sql( $args['search'] ) . "'";
509
+                $args['search'] = trim(str_replace('profile_id:', '', $args['search']));
510
+                $where .= " AND `profile_id` = '" . esc_sql($args['search']) . "'";
511 511
 
512
-            } else if( false !== strpos( $args['search'], 'product_id:' ) ) {
512
+            } else if (false !== strpos($args['search'], 'product_id:')) {
513 513
 
514
-                $args['search'] = trim( str_replace( 'product_id:', '', $args['search'] ) );
515
-                $where .= " AND `product_id` = '" . esc_sql( $args['search'] ) . "'";
514
+                $args['search'] = trim(str_replace('product_id:', '', $args['search']));
515
+                $where .= " AND `product_id` = '" . esc_sql($args['search']) . "'";
516 516
 
517
-            } else if( false !== strpos( $args['search'], 'customer_id:' ) ) {
517
+            } else if (false !== strpos($args['search'], 'customer_id:')) {
518 518
 
519
-                $args['search'] = trim( str_replace( 'customer_id:', '', $args['search'] ) );
520
-                $where .= " AND `customer_id` = '" . esc_sql( $args['search'] ) . "'";
519
+                $args['search'] = trim(str_replace('customer_id:', '', $args['search']));
520
+                $where .= " AND `customer_id` = '" . esc_sql($args['search']) . "'";
521 521
 
522 522
             } else {
523 523
 
524
-                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `profile_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `transaction_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `product_id` LIKE '%%" . esc_sql( $args['search'] ) . "%%' OR `id` = '" . esc_sql( $args['search'] ) . "' )";
524
+                $where .= " AND ( `parent_payment_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `profile_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `transaction_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `product_id` LIKE '%%" . esc_sql($args['search']) . "%%' OR `id` = '" . esc_sql($args['search']) . "' )";
525 525
 
526 526
             }
527 527
 
528 528
         }
529 529
 
530
-        $cache_key = md5( 'wpinv_subscriptions_count' . serialize( $args ) );
530
+        $cache_key = md5('wpinv_subscriptions_count' . serialize($args));
531 531
 
532
-        $count = wp_cache_get( $cache_key, 'subscriptions' );
532
+        $count = wp_cache_get($cache_key, 'subscriptions');
533 533
 
534
-        if( $count === false ) {
534
+        if ($count === false) {
535 535
 
536 536
             $sql   = "SELECT COUNT($this->primary_key) FROM " . $this->table_name . "{$where};";
537
-            $count = $wpdb->get_var( $sql );
537
+            $count = $wpdb->get_var($sql);
538 538
 
539
-            wp_cache_set( $cache_key, $count, 'subscriptions', 3600 );
539
+            wp_cache_set($cache_key, $count, 'subscriptions', 3600);
540 540
 
541 541
         }
542 542
 
543
-        return absint( $count );
543
+        return absint($count);
544 544
 
545 545
     }
546 546
 
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
     public function create_table() {
554 554
         global $wpdb;
555 555
 
556
-        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
556
+        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
557 557
 
558 558
         $sql = "CREATE TABLE " . $this->table_name . " (
559 559
         id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -578,9 +578,9 @@  discard block
 block discarded – undo
578 578
         KEY customer_and_status ( customer_id, status)
579 579
         ) CHARACTER SET utf8 COLLATE utf8_general_ci;";
580 580
 
581
-        dbDelta( $sql );
581
+        dbDelta($sql);
582 582
 
583
-        update_option( $this->table_name . '_db_version', $this->version );
583
+        update_option($this->table_name . '_db_version', $this->version);
584 584
     }
585 585
 
586 586
 }
587 587
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Spacing   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 // Exit if accessed directly
4
-if ( ! defined( 'ABSPATH' ) ) {
4
+if (!defined('ABSPATH')) {
5 5
 	exit;
6 6
 }
7 7
 
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
 	 * @since  1.0.0
39 39
 	 * @return void
40 40
 	 */
41
-	function __construct( $_id_or_object = 0, $_by_profile_id = false ) {
41
+	function __construct($_id_or_object = 0, $_by_profile_id = false) {
42 42
 
43 43
 		$this->subs_db = new WPInv_Subscriptions_DB;
44 44
 
45
-		if( $_by_profile_id ) {
45
+		if ($_by_profile_id) {
46 46
 
47
-			$_sub = $this->subs_db->get_by( 'profile_id', $_id_or_object );
47
+			$_sub = $this->subs_db->get_by('profile_id', $_id_or_object);
48 48
 
49
-			if( empty( $_sub ) ) {
49
+			if (empty($_sub)) {
50 50
 				return false;
51 51
 			}
52 52
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 
55 55
 		}
56 56
 
57
-		return $this->setup_subscription( $_id_or_object );
57
+		return $this->setup_subscription($_id_or_object);
58 58
 	}
59 59
 
60 60
 	/**
@@ -63,34 +63,34 @@  discard block
 block discarded – undo
63 63
 	 * @since  1.0.0
64 64
 	 * @return void
65 65
 	 */
66
-	private function setup_subscription( $id_or_object = 0 ) {
66
+	private function setup_subscription($id_or_object = 0) {
67 67
 
68
-		if( empty( $id_or_object ) ) {
68
+		if (empty($id_or_object)) {
69 69
 			return false;
70 70
 		}
71 71
 
72
-		if( is_numeric( $id_or_object ) ) {
72
+		if (is_numeric($id_or_object)) {
73 73
 
74
-			$sub = $this->subs_db->get( $id_or_object );
74
+			$sub = $this->subs_db->get($id_or_object);
75 75
 
76
-		} elseif( is_object( $id_or_object ) ) {
76
+		} elseif (is_object($id_or_object)) {
77 77
 
78 78
 			$sub = $id_or_object;
79 79
 
80 80
 		}
81 81
 
82
-		if( empty( $sub ) ) {
82
+		if (empty($sub)) {
83 83
 			return false;
84 84
 		}
85 85
 
86
-		foreach( $sub as $key => $value ) {
86
+		foreach ($sub as $key => $value) {
87 87
 			$this->$key = $value;
88 88
 		}
89 89
 
90
-		$this->customer = get_userdata( $this->customer_id );
91
-		$this->gateway  = wpinv_get_payment_gateway( $this->parent_payment_id );
90
+		$this->customer = get_userdata($this->customer_id);
91
+		$this->gateway  = wpinv_get_payment_gateway($this->parent_payment_id);
92 92
 
93
-		do_action( 'wpinv_recurring_setup_subscription', $this );
93
+		do_action('wpinv_recurring_setup_subscription', $this);
94 94
 
95 95
 		return $this;
96 96
 	}
@@ -100,15 +100,15 @@  discard block
 block discarded – undo
100 100
 	 *
101 101
 	 * @since 1.0.0
102 102
 	 */
103
-	public function __get( $key ) {
103
+	public function __get($key) {
104 104
 
105
-		if( method_exists( $this, 'get_' . $key ) ) {
105
+		if (method_exists($this, 'get_' . $key)) {
106 106
 
107
-			return call_user_func( array( $this, 'get_' . $key ) );
107
+			return call_user_func(array($this, 'get_' . $key));
108 108
 
109 109
 		} else {
110 110
 
111
-			return new WP_Error( 'wpinv-subscription-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
111
+			return new WP_Error('wpinv-subscription-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
112 112
 
113 113
 		}
114 114
 
@@ -121,9 +121,9 @@  discard block
 block discarded – undo
121 121
 	 * @param  array  $data Array of attributes for a subscription
122 122
 	 * @return mixed  false if data isn't passed and class not instantiated for creation
123 123
 	 */
124
-	public function create( $data = array() ) {
124
+	public function create($data = array()) {
125 125
 
126
-		if ( $this->id != 0 ) {
126
+		if ($this->id != 0) {
127 127
 			return false;
128 128
 		}
129 129
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 			'profile_id'        => '',
143 143
 		);
144 144
 
145
-		$args = wp_parse_args( $data, $defaults );
145
+		$args = wp_parse_args($data, $defaults);
146 146
 
147
-		if( $args['expiration'] && strtotime( 'NOW', current_time( 'timestamp' ) ) > strtotime( $args['expiration'], current_time( 'timestamp' ) ) ) {
147
+		if ($args['expiration'] && strtotime('NOW', current_time('timestamp')) > strtotime($args['expiration'], current_time('timestamp'))) {
148 148
 
149
-			if( 'active' == $args['status'] || 'trialling' == $args['status'] ) {
149
+			if ('active' == $args['status'] || 'trialling' == $args['status']) {
150 150
 
151 151
 				// Force an active subscription to expired if expiration date is in the past
152 152
 				$args['status'] = 'expired';
@@ -154,13 +154,13 @@  discard block
 block discarded – undo
154 154
 			}
155 155
 		}
156 156
 
157
-		do_action( 'wpinv_subscription_pre_create', $args );
157
+		do_action('wpinv_subscription_pre_create', $args);
158 158
 
159
-		$id = $this->subs_db->insert( $args, 'subscription' );
159
+		$id = $this->subs_db->insert($args, 'subscription');
160 160
 
161
-		do_action( 'wpinv_subscription_post_create', $id, $args );
161
+		do_action('wpinv_subscription_post_create', $id, $args);
162 162
 
163
-		return $this->setup_subscription( $id );
163
+		return $this->setup_subscription($id);
164 164
 
165 165
 	}
166 166
 
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 * @param  array $args Array of fields to update
172 172
 	 * @return bool
173 173
 	 */
174
-	public function update( $args = array() ) {
174
+	public function update($args = array()) {
175 175
 
176
-		$ret = $this->subs_db->update( $this->id, $args );
176
+		$ret = $this->subs_db->update($this->id, $args);
177 177
 
178
-		do_action( 'wpinv_recurring_update_subscription', $this->id, $args, $this );
178
+		do_action('wpinv_recurring_update_subscription', $this->id, $args, $this);
179 179
 
180 180
 		return $ret;
181 181
 
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
 	 * @return bool
189 189
 	 */
190 190
 	public function delete() {
191
-		return $this->subs_db->delete( $this->id );
191
+		return $this->subs_db->delete($this->id);
192 192
 	}
193 193
 
194 194
     /**
@@ -208,14 +208,14 @@  discard block
 block discarded – undo
208 208
      * @return array
209 209
      */
210 210
     public function get_child_payments() {
211
-        $payments = get_posts( array(
212
-            'post_parent'    => (int) $this->parent_payment_id,
211
+        $payments = get_posts(array(
212
+            'post_parent'    => (int)$this->parent_payment_id,
213 213
             'posts_per_page' => '999',
214
-            'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
214
+            'post_status'    => array('publish', 'wpi-processing', 'wpi-renewal'),
215 215
             'orderby'           => 'ID',
216 216
             'order'             => 'DESC',
217 217
             'post_type'      => 'wpi_invoice'
218
-        ) );
218
+        ));
219 219
 
220 220
         return $payments;
221 221
     }
@@ -228,9 +228,9 @@  discard block
 block discarded – undo
228 228
      */
229 229
     public function get_total_payments() {
230 230
         $child_payments = $this->get_child_payments();
231
-        $total_payments = !empty( $child_payments ) ? count( $child_payments ) : 0;
231
+        $total_payments = !empty($child_payments) ? count($child_payments) : 0;
232 232
 
233
-        if ( 'pending' != $this->status ) {
233
+        if ('pending' != $this->status) {
234 234
                 $total_payments++;
235 235
         }
236 236
 
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
     public function get_times_billed() {
247 247
         $times_billed = (int)$this->get_total_payments();
248 248
 
249
-        if ( ! empty( $this->trial_period ) && $times_billed > 0 ) {
249
+        if (!empty($this->trial_period) && $times_billed > 0) {
250 250
             $times_billed--;
251 251
         }
252 252
 
@@ -260,51 +260,51 @@  discard block
 block discarded – undo
260 260
      * @param  array $args Array of values for the payment, including amount and transaction ID
261 261
      * @return bool
262 262
      */
263
-    public function add_payment( $args = array() ) {
264
-        if ( ! $this->parent_payment_id ) {
263
+    public function add_payment($args = array()) {
264
+        if (!$this->parent_payment_id) {
265 265
             return false;
266 266
         }
267 267
 
268
-        $args = wp_parse_args( $args, array(
268
+        $args = wp_parse_args($args, array(
269 269
             'amount'         => '',
270 270
             'transaction_id' => '',
271 271
             'gateway'        => ''
272
-        ) );
272
+        ));
273 273
         
274
-        if ( empty( $args['transaction_id'] ) || $this->payment_exists( $args['transaction_id'] ) ) {
274
+        if (empty($args['transaction_id']) || $this->payment_exists($args['transaction_id'])) {
275 275
             return false;
276 276
         }
277 277
         
278
-        $parent_invoice = wpinv_get_invoice( $this->parent_payment_id );
279
-        if ( empty( $parent_invoice->ID ) ) {
278
+        $parent_invoice = wpinv_get_invoice($this->parent_payment_id);
279
+        if (empty($parent_invoice->ID)) {
280 280
             return false;
281 281
         }
282 282
 
283 283
         $invoice = new WPInv_Invoice();
284
-        $invoice->set( 'post_type', 'wpi_invoice' );
285
-        $invoice->set( 'parent_invoice', $this->parent_payment_id );
286
-        $invoice->set( 'currency', $parent_invoice->get_currency() );
287
-        $invoice->set( 'transaction_id', $args['transaction_id'] );
288
-        $invoice->set( 'key', $parent_invoice->generate_key() );
289
-        $invoice->set( 'ip', $parent_invoice->ip );
290
-        $invoice->set( 'user_id', $parent_invoice->get_user_id() );
291
-        $invoice->set( 'first_name', $parent_invoice->get_first_name() );
292
-        $invoice->set( 'last_name', $parent_invoice->get_last_name() );
293
-        $invoice->set( 'phone', $parent_invoice->phone );
294
-        $invoice->set( 'address', $parent_invoice->address );
295
-        $invoice->set( 'city', $parent_invoice->city );
296
-        $invoice->set( 'country', $parent_invoice->country );
297
-        $invoice->set( 'state', $parent_invoice->state );
298
-        $invoice->set( 'zip', $parent_invoice->zip );
299
-        $invoice->set( 'company', $parent_invoice->company );
300
-        $invoice->set( 'vat_number', $parent_invoice->vat_number );
301
-        $invoice->set( 'vat_rate', $parent_invoice->vat_rate );
302
-        $invoice->set( 'adddress_confirmed', $parent_invoice->adddress_confirmed );
303
-
304
-        if ( empty( $args['gateway'] ) ) {
305
-            $invoice->set( 'gateway', $parent_invoice->get_gateway() );
284
+        $invoice->set('post_type', 'wpi_invoice');
285
+        $invoice->set('parent_invoice', $this->parent_payment_id);
286
+        $invoice->set('currency', $parent_invoice->get_currency());
287
+        $invoice->set('transaction_id', $args['transaction_id']);
288
+        $invoice->set('key', $parent_invoice->generate_key());
289
+        $invoice->set('ip', $parent_invoice->ip);
290
+        $invoice->set('user_id', $parent_invoice->get_user_id());
291
+        $invoice->set('first_name', $parent_invoice->get_first_name());
292
+        $invoice->set('last_name', $parent_invoice->get_last_name());
293
+        $invoice->set('phone', $parent_invoice->phone);
294
+        $invoice->set('address', $parent_invoice->address);
295
+        $invoice->set('city', $parent_invoice->city);
296
+        $invoice->set('country', $parent_invoice->country);
297
+        $invoice->set('state', $parent_invoice->state);
298
+        $invoice->set('zip', $parent_invoice->zip);
299
+        $invoice->set('company', $parent_invoice->company);
300
+        $invoice->set('vat_number', $parent_invoice->vat_number);
301
+        $invoice->set('vat_rate', $parent_invoice->vat_rate);
302
+        $invoice->set('adddress_confirmed', $parent_invoice->adddress_confirmed);
303
+
304
+        if (empty($args['gateway'])) {
305
+            $invoice->set('gateway', $parent_invoice->get_gateway());
306 306
         } else {
307
-            $invoice->set( 'gateway', $args['gateway'] );
307
+            $invoice->set('gateway', $args['gateway']);
308 308
         }
309 309
         
310 310
         $recurring_details = $parent_invoice->get_recurring_details();
@@ -312,11 +312,11 @@  discard block
 block discarded – undo
312 312
         // increase the earnings for each item in the subscription
313 313
         $items = $recurring_details['cart_details'];
314 314
         
315
-        if ( $items ) {        
315
+        if ($items) {        
316 316
             $add_items      = array();
317 317
             $cart_details   = array();
318 318
             
319
-            foreach ( $items as $item ) {
319
+            foreach ($items as $item) {
320 320
                 $add_item             = array();
321 321
                 $add_item['id']       = $item['id'];
322 322
                 $add_item['quantity'] = $item['quantity'];
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
                 break;
327 327
             }
328 328
             
329
-            $invoice->set( 'items', $add_items );
329
+            $invoice->set('items', $add_items);
330 330
             $invoice->cart_details = $cart_details;
331 331
         }
332 332
         
@@ -336,29 +336,29 @@  discard block
 block discarded – undo
336 336
         $tax                = $recurring_details['tax'];
337 337
         $discount           = $recurring_details['discount'];
338 338
         
339
-        if ( $discount > 0 ) {
340
-            $invoice->set( 'discount_code', $parent_invoice->discount_code );
339
+        if ($discount > 0) {
340
+            $invoice->set('discount_code', $parent_invoice->discount_code);
341 341
         }
342 342
         
343
-        $invoice->subtotal = wpinv_round_amount( $subtotal );
344
-        $invoice->tax      = wpinv_round_amount( $tax );
345
-        $invoice->discount = wpinv_round_amount( $discount );
346
-        $invoice->total    = wpinv_round_amount( $total );
343
+        $invoice->subtotal = wpinv_round_amount($subtotal);
344
+        $invoice->tax      = wpinv_round_amount($tax);
345
+        $invoice->discount = wpinv_round_amount($discount);
346
+        $invoice->total    = wpinv_round_amount($total);
347 347
 
348
-        $invoice  = apply_filters( 'wpinv_subscription_add_payment_save', $invoice, $this, $args );
348
+        $invoice = apply_filters('wpinv_subscription_add_payment_save', $invoice, $this, $args);
349 349
 
350 350
         $invoice->save();
351
-        $invoice->update_meta( '_wpinv_subscription_id', $this->id );
351
+        $invoice->update_meta('_wpinv_subscription_id', $this->id);
352 352
         
353
-        if ( !empty( $invoice->ID ) ) {
354
-            wpinv_update_payment_status( $invoice->ID, 'publish' );
353
+        if (!empty($invoice->ID)) {
354
+            wpinv_update_payment_status($invoice->ID, 'publish');
355 355
             sleep(1);
356
-            wpinv_update_payment_status( $invoice->ID, 'wpi-renewal' );
356
+            wpinv_update_payment_status($invoice->ID, 'wpi-renewal');
357 357
             
358
-            $invoice = wpinv_get_invoice( $invoice->ID );
358
+            $invoice = wpinv_get_invoice($invoice->ID);
359 359
 
360
-            do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
361
-            do_action( 'wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id'] );
360
+            do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
361
+            do_action('wpinv_recurring_record_payment', $invoice->ID, $this->parent_payment_id, $args['amount'], $args['transaction_id']);
362 362
             
363 363
             return $invoice->ID;
364 364
         }
@@ -374,12 +374,12 @@  discard block
 block discarded – undo
374 374
 	 */
375 375
 	public function get_transaction_id() {
376 376
 
377
-		if( empty( $this->transaction_id ) ) {
377
+		if (empty($this->transaction_id)) {
378 378
 
379
-			$txn_id = wpinv_get_payment_transaction_id( $this->parent_payment_id );
379
+			$txn_id = wpinv_get_payment_transaction_id($this->parent_payment_id);
380 380
 
381
-			if( ! empty( $txn_id ) && (int) $this->parent_payment_id !== (int) $txn_id ) {
382
-				$this->set_transaction_id( $txn_id );
381
+			if (!empty($txn_id) && (int)$this->parent_payment_id !== (int)$txn_id) {
382
+				$this->set_transaction_id($txn_id);
383 383
 			}
384 384
 
385 385
 		}
@@ -394,8 +394,8 @@  discard block
 block discarded – undo
394 394
 	 * @since  1.0.0.4
395 395
 	 * @return bool
396 396
 	 */
397
-	public function set_transaction_id( $txn_id = '' ) {
398
-		$this->update( array( 'transaction_id' => $txn_id ) );
397
+	public function set_transaction_id($txn_id = '') {
398
+		$this->update(array('transaction_id' => $txn_id));
399 399
 		$this->transaction_id = $txn_id;
400 400
 	}
401 401
 
@@ -411,35 +411,35 @@  discard block
 block discarded – undo
411 411
 
412 412
 
413 413
 		// Determine what date to use as the start for the new expiration calculation
414
-		if( $expires > current_time( 'timestamp' ) && $this->is_active() ) {
414
+		if ($expires > current_time('timestamp') && $this->is_active()) {
415 415
 
416
-			$base_date  = $expires;
416
+			$base_date = $expires;
417 417
 
418 418
 		} else {
419 419
 
420
-			$base_date  = current_time( 'timestamp' );
420
+			$base_date = current_time('timestamp');
421 421
 
422 422
 		}
423 423
 
424
-		$last_day = wpinv_cal_days_in_month( CAL_GREGORIAN, date( 'n', $base_date ), date( 'Y', $base_date ) );
424
+		$last_day = wpinv_cal_days_in_month(CAL_GREGORIAN, date('n', $base_date), date('Y', $base_date));
425 425
 
426 426
 
427 427
 		$frequency = isset($this->frequency) ? $this->frequency : 1;
428
-		$expiration = date( 'Y-m-d H:i:s', strtotime( '+' . $frequency . ' ' . $this->period  . ' 23:59:59', $base_date ) );
428
+		$expiration = date('Y-m-d H:i:s', strtotime('+' . $frequency . ' ' . $this->period . ' 23:59:59', $base_date));
429 429
 
430
-		if( date( 'j', $base_date ) == $last_day && 'day' != $this->period ) {
431
-			$expiration = date( 'Y-m-d H:i:s', strtotime( $expiration . ' +2 days' ) );
430
+		if (date('j', $base_date) == $last_day && 'day' != $this->period) {
431
+			$expiration = date('Y-m-d H:i:s', strtotime($expiration . ' +2 days'));
432 432
 		}
433 433
 
434
-		$expiration  = apply_filters( 'wpinv_subscription_renewal_expiration', $expiration, $this->id, $this );
434
+		$expiration  = apply_filters('wpinv_subscription_renewal_expiration', $expiration, $this->id, $this);
435 435
 
436
-		do_action( 'wpinv_subscription_pre_renew', $this->id, $expiration, $this );
436
+		do_action('wpinv_subscription_pre_renew', $this->id, $expiration, $this);
437 437
 
438 438
 		$this->status = 'active';
439 439
 		$times_billed = $this->get_times_billed();
440 440
 
441 441
 		// Complete subscription if applicable
442
-		if ( $this->bill_times > 0 && $times_billed >= $this->bill_times ) {
442
+		if ($this->bill_times > 0 && $times_billed >= $this->bill_times) {
443 443
 			$this->complete();
444 444
 			$this->status = 'completed';
445 445
 		}
@@ -449,10 +449,10 @@  discard block
 block discarded – undo
449 449
 			'status'     => $this->status,
450 450
 		);
451 451
 
452
-        $this->subs_db->update( $this->id, $args );
452
+        $this->subs_db->update($this->id, $args);
453 453
 
454
-		do_action( 'wpinv_subscription_post_renew', $this->id, $expiration, $this );
455
-		do_action( 'wpinv_recurring_set_subscription_status', $this->id, $this->status, $this );
454
+		do_action('wpinv_subscription_post_renew', $this->id, $expiration, $this);
455
+		do_action('wpinv_recurring_set_subscription_status', $this->id, $this->status, $this);
456 456
 
457 457
 	}
458 458
 
@@ -467,7 +467,7 @@  discard block
 block discarded – undo
467 467
 	public function complete() {
468 468
 
469 469
 		// Only mark a subscription as complete if it's not already cancelled.
470
-		if ( 'cancelled' === $this->status ) {
470
+		if ('cancelled' === $this->status) {
471 471
 			return;
472 472
 		}
473 473
 
@@ -475,11 +475,11 @@  discard block
 block discarded – undo
475 475
 			'status' => 'completed'
476 476
 		);
477 477
 
478
-		if( $this->subs_db->update( $this->id, $args ) ) {
478
+		if ($this->subs_db->update($this->id, $args)) {
479 479
 
480 480
 			$this->status = 'completed';
481 481
 
482
-			do_action( 'wpinv_subscription_completed', $this->id, $this );
482
+			do_action('wpinv_subscription_completed', $this->id, $this);
483 483
 
484 484
 		}
485 485
 
@@ -494,15 +494,15 @@  discard block
 block discarded – undo
494 494
 	 * @param  $check_expiration bool True if expiration date should be checked with merchant processor before expiring
495 495
 	 * @return void
496 496
 	 */
497
-	public function expire( $check_expiration = false ) {
497
+	public function expire($check_expiration = false) {
498 498
 
499 499
 		$expiration = $this->expiration;
500 500
 
501
-		if( $check_expiration ) {
501
+		if ($check_expiration) {
502 502
 
503 503
 			// check_expiration() updates $this->expiration so compare to $expiration above
504 504
 
505
-			if( $expiration < $this->get_expiration() && current_time( 'timestamp' ) < $this->get_expiration_time() ) {
505
+			if ($expiration < $this->get_expiration() && current_time('timestamp') < $this->get_expiration_time()) {
506 506
 
507 507
 				return false; // Do not mark as expired since real expiration date is in the future
508 508
 			}
@@ -513,11 +513,11 @@  discard block
 block discarded – undo
513 513
 			'status' => 'expired'
514 514
 		);
515 515
 
516
-		if( $this->subs_db->update( $this->id, $args ) ) {
516
+		if ($this->subs_db->update($this->id, $args)) {
517 517
 
518 518
 			$this->status = 'expired';
519 519
 
520
-			do_action( 'wpinv_subscription_expired', $this->id, $this );
520
+			do_action('wpinv_subscription_expired', $this->id, $this);
521 521
 
522 522
 		}
523 523
 
@@ -535,11 +535,11 @@  discard block
 block discarded – undo
535 535
 			'status' => 'failing'
536 536
 		);
537 537
 
538
-		if( $this->subs_db->update( $this->id, $args ) ) {
538
+		if ($this->subs_db->update($this->id, $args)) {
539 539
 
540 540
 			$this->status = 'failing';
541 541
 
542
-			do_action( 'wpinv_subscription_failing', $this->id, $this );
542
+			do_action('wpinv_subscription_failing', $this->id, $this);
543 543
 
544 544
 
545 545
 		}
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
      * @return void
554 554
      */
555 555
     public function cancel() {
556
-        if ( 'cancelled' === $this->status ) {
556
+        if ('cancelled' === $this->status) {
557 557
             return; // Already cancelled
558 558
         }
559 559
 
@@ -561,20 +561,20 @@  discard block
 block discarded – undo
561 561
             'status' => 'cancelled'
562 562
         );
563 563
 
564
-        if ( $this->subs_db->update( $this->id, $args ) ) {
565
-            if ( is_user_logged_in() ) {
566
-                $userdata = get_userdata( get_current_user_id() );
564
+        if ($this->subs_db->update($this->id, $args)) {
565
+            if (is_user_logged_in()) {
566
+                $userdata = get_userdata(get_current_user_id());
567 567
                 $user     = $userdata->display_name;
568 568
             } else {
569
-                $user = __( 'gateway', 'invoicing' );
569
+                $user = __('gateway', 'invoicing');
570 570
             }
571 571
 
572
-            $note = sprintf( __( 'Subscription has been cancelled by %s', 'invoicing' ), $this->parent_payment_id, $user );
573
-            wpinv_insert_payment_note( $this->parent_payment_id, $note, '', '', true );
572
+            $note = sprintf(__('Subscription has been cancelled by %s', 'invoicing'), $this->parent_payment_id, $user);
573
+            wpinv_insert_payment_note($this->parent_payment_id, $note, '', '', true);
574 574
 
575 575
             $this->status = 'cancelled';
576 576
 
577
-            do_action( 'wpinv_subscription_cancelled', $this->id, $this );
577
+            do_action('wpinv_subscription_cancelled', $this->id, $this);
578 578
         }
579 579
     }
580 580
 
@@ -589,10 +589,10 @@  discard block
 block discarded – undo
589 589
 	 */
590 590
 	public function can_cancel() {
591 591
         $ret = false;
592
-	    if( $this->gateway === 'manual' || in_array( $this->status, $this->get_cancellable_statuses() ) ) {
592
+	    if ($this->gateway === 'manual' || in_array($this->status, $this->get_cancellable_statuses())) {
593 593
             $ret = true;
594 594
         }
595
-		return apply_filters( 'wpinv_subscription_can_cancel', $ret, $this );
595
+		return apply_filters('wpinv_subscription_can_cancel', $ret, $this);
596 596
 	}
597 597
 
598 598
     /**
@@ -603,7 +603,7 @@  discard block
 block discarded – undo
603 603
      * @return      array
604 604
      */
605 605
     public function get_cancellable_statuses() {
606
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
606
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
607 607
     }
608 608
 
609 609
 	/**
@@ -614,9 +614,9 @@  discard block
 block discarded – undo
614 614
 	 */
615 615
 	public function get_cancel_url() {
616 616
 
617
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-cancel' );
617
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'cancel_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-cancel');
618 618
 
619
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
619
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
620 620
 	}
621 621
 
622 622
 	/**
@@ -630,7 +630,7 @@  discard block
 block discarded – undo
630 630
 	 */
631 631
 	public function can_renew() {
632 632
 
633
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
633
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
634 634
 	}
635 635
 
636 636
 	/**
@@ -641,9 +641,9 @@  discard block
 block discarded – undo
641 641
 	 */
642 642
 	public function get_renew_url() {
643 643
 
644
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->id ) ), 'wpinv-recurring-renew' );
644
+		$url = wp_nonce_url(add_query_arg(array('wpinv_action' => 'renew_subscription', 'sub_id' => $this->id)), 'wpinv-recurring-renew');
645 645
 
646
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
646
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
647 647
 	}
648 648
 
649 649
 	/**
@@ -653,7 +653,7 @@  discard block
 block discarded – undo
653 653
 	 * @return bool
654 654
 	 */
655 655
 	public function can_update() {
656
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
656
+		return apply_filters('wpinv_subscription_can_update', false, $this);
657 657
 	}
658 658
 
659 659
 	/**
@@ -664,9 +664,9 @@  discard block
 block discarded – undo
664 664
 	 */
665 665
 	public function get_update_url() {
666 666
 
667
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->id ) );
667
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->id));
668 668
 
669
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
669
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
670 670
 	}
671 671
 
672 672
 	/**
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
 
680 680
 		$ret = false;
681 681
 
682
-		if( ! $this->is_expired() && ( $this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling' ) ) {
682
+		if (!$this->is_expired() && ($this->status == 'active' || $this->status == 'cancelled' || $this->status == 'trialling')) {
683 683
 			$ret = true;
684 684
 		}
685 685
 
686
-		return apply_filters( 'wpinv_subscription_is_active', $ret, $this->id, $this );
686
+		return apply_filters('wpinv_subscription_is_active', $ret, $this->id, $this);
687 687
 
688 688
 	}
689 689
 
@@ -697,26 +697,26 @@  discard block
 block discarded – undo
697 697
 
698 698
 		$ret = false;
699 699
 
700
-		if ( $this->status == 'expired' ) {
700
+		if ($this->status == 'expired') {
701 701
 
702 702
 			$ret = true;
703 703
 
704
-		} elseif( 'active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling'  ) {
704
+		} elseif ('active' === $this->status || 'cancelled' === $this->status || $this->status == 'trialling') {
705 705
 
706 706
 			$ret        = false;
707 707
 			$expiration = $this->get_expiration_time();
708 708
 
709
-			if( $expiration && strtotime( 'NOW', current_time( 'timestamp' ) ) > $expiration ) {
709
+			if ($expiration && strtotime('NOW', current_time('timestamp')) > $expiration) {
710 710
 				$ret = true;
711 711
 
712
-				if ( 'active' === $this->status || $this->status == 'trialling'  ) {
712
+				if ('active' === $this->status || $this->status == 'trialling') {
713 713
 					$this->expire();
714 714
 				}
715 715
 			}
716 716
 
717 717
 		}
718 718
 
719
-		return apply_filters( 'wpinv_subscription_is_expired', $ret, $this->id, $this );
719
+		return apply_filters('wpinv_subscription_is_expired', $ret, $this->id, $this);
720 720
 
721 721
 	}
722 722
 
@@ -737,7 +737,7 @@  discard block
 block discarded – undo
737 737
 	 * @return int
738 738
 	 */
739 739
 	public function get_expiration_time() {
740
-		return strtotime( $this->expiration, current_time( 'timestamp' ) );
740
+		return strtotime($this->expiration, current_time('timestamp'));
741 741
 	}
742 742
 
743 743
 	/**
@@ -761,37 +761,37 @@  discard block
 block discarded – undo
761 761
 	 */
762 762
 	public function get_status_label() {
763 763
 
764
-		switch( $this->get_status() ) {
764
+		switch ($this->get_status()) {
765 765
 			case 'active' :
766
-				$status = __( 'Active', 'invoicing' );
766
+				$status = __('Active', 'invoicing');
767 767
 				break;
768 768
 
769 769
 			case 'cancelled' :
770
-				$status = __( 'Cancelled', 'invoicing' );
770
+				$status = __('Cancelled', 'invoicing');
771 771
 				break;
772 772
 
773 773
 			case 'expired' :
774
-				$status = __( 'Expired', 'invoicing' );
774
+				$status = __('Expired', 'invoicing');
775 775
 				break;
776 776
 
777 777
 			case 'pending' :
778
-				$status = __( 'Pending', 'invoicing' );
778
+				$status = __('Pending', 'invoicing');
779 779
 				break;
780 780
 
781 781
 			case 'failing' :
782
-				$status = __( 'Failing', 'invoicing' );
782
+				$status = __('Failing', 'invoicing');
783 783
 				break;
784 784
 
785 785
 			case 'trialling' :
786
-				$status = __( 'Trialling', 'invoicing' );
786
+				$status = __('Trialling', 'invoicing');
787 787
 				break;
788 788
 
789 789
 			case 'completed' :
790
-				$status = __( 'Completed', 'invoicing' );
790
+				$status = __('Completed', 'invoicing');
791 791
 				break;
792 792
 
793 793
 			default:
794
-				$status = ucfirst( $this->get_status() );
794
+				$status = ucfirst($this->get_status());
795 795
 				break;
796 796
 		}
797 797
 
@@ -806,51 +806,51 @@  discard block
 block discarded – undo
806 806
      */
807 807
     public function get_status_label_html() {
808 808
 
809
-        switch( $get_status = $this->get_status() ) {
809
+        switch ($get_status = $this->get_status()) {
810 810
             case 'active' :
811
-                $status = __( 'Active', 'invoicing' );
811
+                $status = __('Active', 'invoicing');
812 812
                 $class = 'label-info';
813 813
                 break;
814 814
 
815 815
             case 'cancelled' :
816
-                $status = __( 'Cancelled', 'invoicing' );
816
+                $status = __('Cancelled', 'invoicing');
817 817
                 $class = 'label-danger';
818 818
                 break;
819 819
 
820 820
             case 'expired' :
821
-                $status = __( 'Expired', 'invoicing' );
821
+                $status = __('Expired', 'invoicing');
822 822
                 $class = 'label-default';
823 823
                 break;
824 824
 
825 825
             case 'pending' :
826
-                $status = __( 'Pending', 'invoicing' );
826
+                $status = __('Pending', 'invoicing');
827 827
                 $class = 'label-primary';
828 828
                 break;
829 829
 
830 830
             case 'failing' :
831
-                $status = __( 'Failing', 'invoicing' );
831
+                $status = __('Failing', 'invoicing');
832 832
                 $class = 'label-danger';
833 833
                 break;
834 834
 
835 835
             case 'trialling' :
836
-                $status = __( 'Trialling', 'invoicing' );
836
+                $status = __('Trialling', 'invoicing');
837 837
                 $class = 'label-info';
838 838
                 break;
839 839
 
840 840
             case 'completed' :
841
-                $status = __( 'Completed', 'invoicing' );
841
+                $status = __('Completed', 'invoicing');
842 842
                 $class = 'label-success';
843 843
                 break;
844 844
 
845 845
             default:
846
-                $status = ucfirst( $this->get_status() );
846
+                $status = ucfirst($this->get_status());
847 847
                 $class = 'label-default';
848 848
                 break;
849 849
         }
850 850
 
851 851
         $label = '<span class="sub-status label label-sub-' . $get_status . ' ' . $class . '">' . $status . '</span>';
852 852
 
853
-        return apply_filters( 'wpinv_subscription_status_label_html', $label, $get_status, $status );
853
+        return apply_filters('wpinv_subscription_status_label_html', $label, $get_status, $status);
854 854
     }
855 855
 
856 856
     /**
@@ -860,18 +860,18 @@  discard block
 block discarded – undo
860 860
      * @param  string $txn_id The transaction ID from the merchant processor
861 861
      * @return bool
862 862
      */
863
-    public function payment_exists( $txn_id = '' ) {
863
+    public function payment_exists($txn_id = '') {
864 864
         global $wpdb;
865 865
 
866
-        if ( empty( $txn_id ) ) {
866
+        if (empty($txn_id)) {
867 867
             return false;
868 868
         }
869 869
 
870
-        $txn_id = esc_sql( $txn_id );
870
+        $txn_id = esc_sql($txn_id);
871 871
 
872
-        $purchase = $wpdb->get_var( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1" );
872
+        $purchase = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = '{$txn_id}' LIMIT 1");
873 873
 
874
-        if ( $purchase != null ) {
874
+        if ($purchase != null) {
875 875
             return true;
876 876
         }
877 877
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +189 added lines, -189 removed lines patch added patch discarded remove patch
@@ -1,73 +1,73 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_action( 'admin_menu', 'wpinv_add_options_link', 10 );
7
+add_action('admin_menu', 'wpinv_add_options_link', 10);
8 8
 function wpinv_add_options_link() {
9 9
     global $menu;
10 10
 
11
-    if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
11
+    if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
12 12
         return;
13 13
     }
14 14
 
15
-    $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
15
+    $capability = apply_filters('invoicing_capability', 'manage_invoicing');
16 16
 
17
-    if ( current_user_can( 'manage_options' ) ) {
18
-        $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
17
+    if (current_user_can('manage_options')) {
18
+        $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
19 19
     }
20 20
 
21
-    $wpi_invoice = get_post_type_object( 'wpi_invoice' );
21
+    $wpi_invoice = get_post_type_object('wpi_invoice');
22 22
 
23
-    add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
23
+    add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
24 24
 
25
-    $wpi_settings_page   = add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', 'wpinv_options_page' );
25
+    $wpi_settings_page = add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', 'wpinv_options_page');
26 26
 }
27 27
 
28
-add_action( 'admin_menu', 'wpinv_remove_admin_submenus', 999 );
28
+add_action('admin_menu', 'wpinv_remove_admin_submenus', 999);
29 29
 function wpinv_remove_admin_submenus() {
30
-    remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
30
+    remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
31 31
 }
32 32
 
33
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
34
-function wpinv_discount_columns( $existing_columns ) {
33
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
34
+function wpinv_discount_columns($existing_columns) {
35 35
     $columns                = array();
36 36
     $columns['cb']          = $existing_columns['cb'];
37
-    $columns['name']        = __( 'Name', 'invoicing' );
38
-    $columns['code']        = __( 'Code', 'invoicing' );
39
-    $columns['amount']      = __( 'Amount', 'invoicing' );
40
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
41
-    $columns['start_date']  = __( 'Start Date', 'invoicing' );
42
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
43
-    $columns['status']      = __( 'Status', 'invoicing' );
37
+    $columns['name']        = __('Name', 'invoicing');
38
+    $columns['code']        = __('Code', 'invoicing');
39
+    $columns['amount']      = __('Amount', 'invoicing');
40
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
41
+    $columns['start_date']  = __('Start Date', 'invoicing');
42
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
43
+    $columns['status']      = __('Status', 'invoicing');
44 44
 
45 45
     return $columns;
46 46
 }
47 47
 
48
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
49
-function wpinv_discount_custom_column( $column ) {
48
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
49
+function wpinv_discount_custom_column($column) {
50 50
     global $post;
51 51
     
52 52
     $discount = $post;
53 53
 
54
-    switch ( $column ) {
54
+    switch ($column) {
55 55
         case 'name' :
56
-            echo get_the_title( $discount->ID );
56
+            echo get_the_title($discount->ID);
57 57
         break;
58 58
         case 'code' :
59
-            echo wpinv_get_discount_code( $discount->ID );
59
+            echo wpinv_get_discount_code($discount->ID);
60 60
         break;
61 61
         case 'amount' :
62
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
62
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
63 63
         break;
64 64
         case 'usage_limit' :
65
-            echo wpinv_get_discount_uses( $discount->ID );
65
+            echo wpinv_get_discount_uses($discount->ID);
66 66
         break;
67 67
         case 'usage' :
68
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
69
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
70
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
68
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
69
+            if (wpinv_get_discount_max_uses($discount->ID)) {
70
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
71 71
             } else {
72 72
                 $usage .= ' &infin;';
73 73
             }
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
             echo $usage;
76 76
         break;
77 77
         case 'start_date' :
78
-            if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) {
79
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) );
78
+            if ($start_date = wpinv_get_discount_start_date($discount->ID)) {
79
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date));
80 80
             } else {
81 81
                 $value = '-';
82 82
             }
@@ -84,163 +84,163 @@  discard block
 block discarded – undo
84 84
             echo $value;
85 85
         break;
86 86
         case 'expiry_date' :
87
-            if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) {
88
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) );
87
+            if ($expiration = wpinv_get_discount_expiration($discount->ID)) {
88
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration));
89 89
             } else {
90
-                $value = __( 'Never', 'invoicing' );
90
+                $value = __('Never', 'invoicing');
91 91
             }
92 92
                 
93 93
             echo $value;
94 94
         break;
95 95
         break;
96 96
         case 'description' :
97
-            echo wp_kses_post( $post->post_excerpt );
97
+            echo wp_kses_post($post->post_excerpt);
98 98
         break;
99 99
         case 'status' :
100
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
100
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
101 101
             
102
-            echo wpinv_discount_status( $status );
102
+            echo wpinv_discount_status($status);
103 103
         break;
104 104
     }
105 105
 }
106 106
 
107
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
108
-function wpinv_post_row_actions( $actions, $post ) {
109
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
107
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
108
+function wpinv_post_row_actions($actions, $post) {
109
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
110 110
     
111
-    if ( $post_type == 'wpi_invoice' ) {
111
+    if ($post_type == 'wpi_invoice') {
112 112
         $actions = array();
113 113
     }
114 114
     
115
-    if ( $post_type == 'wpi_discount' ) {
116
-        $actions = wpinv_discount_row_actions( $post, $actions );
115
+    if ($post_type == 'wpi_discount') {
116
+        $actions = wpinv_discount_row_actions($post, $actions);
117 117
     }
118 118
     
119 119
     return $actions;
120 120
 }
121 121
 
122
-function wpinv_discount_row_actions( $discount, $row_actions ) {
123
-    $row_actions  = array();
124
-    $edit_link = get_edit_post_link( $discount->ID );
125
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
122
+function wpinv_discount_row_actions($discount, $row_actions) {
123
+    $row_actions = array();
124
+    $edit_link = get_edit_post_link($discount->ID);
125
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
126 126
 
127
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
128
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
129
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
130
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
127
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
128
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
129
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
130
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
131 131
     }
132 132
 
133
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
134
-        if ( isset( $row_actions['delete'] ) ) {
135
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
133
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
134
+        if (isset($row_actions['delete'])) {
135
+            unset($row_actions['delete']); // Don't delete used discounts.
136 136
         }
137 137
     } else {
138
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
138
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
139 139
     }
140 140
     
141 141
 
142
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
142
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
143 143
 
144 144
     return $row_actions;
145 145
 }
146 146
 
147
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
148
-function wpinv_table_primary_column( $default, $screen_id ) {
149
-    if ( 'edit-wpi_invoice' === $screen_id ) {
147
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
148
+function wpinv_table_primary_column($default, $screen_id) {
149
+    if ('edit-wpi_invoice' === $screen_id) {
150 150
         return 'name';
151 151
     }
152 152
     
153 153
     return $default;
154 154
 }
155 155
 
156
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
157
-    if ( !$display ) {
156
+function wpinv_discount_bulk_actions($actions, $display = false) {    
157
+    if (!$display) {
158 158
         return array();
159 159
     }
160 160
     
161 161
     $actions = array(
162
-        'activate'   => __( 'Activate', 'invoicing' ),
163
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
164
-        'delete'     => __( 'Delete', 'invoicing' ),
162
+        'activate'   => __('Activate', 'invoicing'),
163
+        'deactivate' => __('Deactivate', 'invoicing'),
164
+        'delete'     => __('Delete', 'invoicing'),
165 165
     );
166 166
     $two = '';
167 167
     $which = 'top';
168 168
     echo '</div><div class="alignleft actions bulkactions">';
169
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
170
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
171
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
169
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
170
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
171
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
172 172
 
173
-    foreach ( $actions as $name => $title ) {
173
+    foreach ($actions as $name => $title) {
174 174
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
175 175
 
176 176
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
177 177
     }
178 178
     echo "</select>";
179 179
 
180
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
180
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
181 181
     
182 182
     echo '</div><div class="alignleft actions">';
183 183
 }
184
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
184
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
185 185
 
186
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
187
-    if ( $post_type == 'wpi_discount' ) {
186
+function wpinv_disable_months_dropdown($disable, $post_type) {
187
+    if ($post_type == 'wpi_discount') {
188 188
         $disable = true;
189 189
     }
190 190
     
191 191
     return $disable;
192 192
 }
193
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
193
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
194 194
 
195 195
 function wpinv_restrict_manage_posts() {
196 196
     global $typenow;
197 197
 
198
-    if( 'wpi_discount' == $typenow ) {
198
+    if ('wpi_discount' == $typenow) {
199 199
         wpinv_discount_filters();
200 200
     }
201 201
 }
202
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
202
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
203 203
 
204 204
 function wpinv_discount_filters() {
205
-    echo wpinv_discount_bulk_actions( array(), true );
205
+    echo wpinv_discount_bulk_actions(array(), true);
206 206
     
207 207
     ?>
208 208
     <select name="discount_type" id="dropdown_wpinv_discount_type">
209
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
209
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
210 210
         <?php
211 211
             $types = wpinv_get_discount_types();
212 212
 
213
-            foreach ( $types as $name => $type ) {
214
-                echo '<option value="' . esc_attr( $name ) . '"';
213
+            foreach ($types as $name => $type) {
214
+                echo '<option value="' . esc_attr($name) . '"';
215 215
 
216
-                if ( isset( $_GET['discount_type'] ) )
217
-                    selected( $name, $_GET['discount_type'] );
216
+                if (isset($_GET['discount_type']))
217
+                    selected($name, $_GET['discount_type']);
218 218
 
219
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
219
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
220 220
             }
221 221
         ?>
222 222
     </select>
223 223
     <?php
224 224
 }
225 225
 
226
-function wpinv_request( $vars ) {
226
+function wpinv_request($vars) {
227 227
     global $typenow, $wp_query, $wp_post_statuses;
228 228
 
229
-    if ( 'wpi_invoice' === $typenow ) {
230
-        if ( !isset( $vars['post_status'] ) ) {
229
+    if ('wpi_invoice' === $typenow) {
230
+        if (!isset($vars['post_status'])) {
231 231
             $post_statuses = wpinv_get_invoice_statuses();
232 232
 
233
-            foreach ( $post_statuses as $status => $value ) {
234
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
235
-                    unset( $post_statuses[ $status ] );
233
+            foreach ($post_statuses as $status => $value) {
234
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
235
+                    unset($post_statuses[$status]);
236 236
                 }
237 237
             }
238 238
 
239
-            $vars['post_status'] = array_keys( $post_statuses );
239
+            $vars['post_status'] = array_keys($post_statuses);
240 240
         }
241 241
         
242
-        if ( isset( $vars['orderby'] ) ) {
243
-            if ( 'amount' == $vars['orderby'] ) {
242
+        if (isset($vars['orderby'])) {
243
+            if ('amount' == $vars['orderby']) {
244 244
                 $vars = array_merge(
245 245
                     $vars,
246 246
                     array(
@@ -248,7 +248,7 @@  discard block
 block discarded – undo
248 248
                         'orderby'  => 'meta_value_num'
249 249
                     )
250 250
                 );
251
-            } else if ( 'customer' == $vars['orderby'] ) {
251
+            } else if ('customer' == $vars['orderby']) {
252 252
                 $vars = array_merge(
253 253
                     $vars,
254 254
                     array(
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
                         'orderby'  => 'meta_value'
257 257
                     )
258 258
                 );
259
-            } else if ( 'number' == $vars['orderby'] ) {
259
+            } else if ('number' == $vars['orderby']) {
260 260
                 $vars = array_merge(
261 261
                     $vars,
262 262
                     array(
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                         'orderby'  => 'meta_value'
265 265
                     )
266 266
                 );
267
-            } else if ( 'payment_date' == $vars['orderby'] ) {
267
+            } else if ('payment_date' == $vars['orderby']) {
268 268
                 $vars = array_merge(
269 269
                     $vars,
270 270
                     array(
@@ -274,9 +274,9 @@  discard block
 block discarded – undo
274 274
                 );
275 275
             }
276 276
         }
277
-    } else if ( 'wpi_item' == $typenow ) {
277
+    } else if ('wpi_item' == $typenow) {
278 278
         // Check if 'orderby' is set to "price"
279
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
279
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
280 280
             $vars = array_merge(
281 281
                 $vars,
282 282
                 array(
@@ -287,7 +287,7 @@  discard block
 block discarded – undo
287 287
         }
288 288
 
289 289
         // Check if "orderby" is set to "vat_rule"
290
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
290
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
291 291
             $vars = array_merge(
292 292
                 $vars,
293 293
                 array(
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
         }
299 299
 
300 300
         // Check if "orderby" is set to "vat_class"
301
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
301
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
302 302
             $vars = array_merge(
303 303
                 $vars,
304 304
                 array(
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
         }
310 310
         
311 311
         // Check if "orderby" is set to "type"
312
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
312
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
313 313
             $vars = array_merge(
314 314
                 $vars,
315 315
                 array(
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
         }
321 321
         
322 322
         // Check if "orderby" is set to "recurring"
323
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
323
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
324 324
             $vars = array_merge(
325 325
                 $vars,
326 326
                 array(
@@ -330,120 +330,120 @@  discard block
 block discarded – undo
330 330
             );
331 331
         }
332 332
 
333
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
333
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
334 334
         // Filter vat rule type
335
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
335
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
336 336
             $meta_query[] = array(
337 337
                     'key'   => '_wpinv_vat_rule',
338
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
338
+                    'value' => sanitize_text_field($_GET['vat_rule']),
339 339
                     'compare' => '='
340 340
                 );
341 341
         }
342 342
         
343 343
         // Filter vat class
344
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
344
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
345 345
             $meta_query[] = array(
346 346
                     'key'   => '_wpinv_vat_class',
347
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
347
+                    'value' => sanitize_text_field($_GET['vat_class']),
348 348
                     'compare' => '='
349 349
                 );
350 350
         }
351 351
         
352 352
         // Filter item type
353
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
353
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
354 354
             $meta_query[] = array(
355 355
                     'key'   => '_wpinv_type',
356
-                    'value' => sanitize_text_field( $_GET['type'] ),
356
+                    'value' => sanitize_text_field($_GET['type']),
357 357
                     'compare' => '='
358 358
                 );
359 359
         }
360 360
         
361
-        if ( !empty( $meta_query ) ) {
361
+        if (!empty($meta_query)) {
362 362
             $vars['meta_query'] = $meta_query;
363 363
         }
364
-    } else if ( 'wpi_discount' == $typenow ) {
365
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
364
+    } else if ('wpi_discount' == $typenow) {
365
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
366 366
         // Filter vat rule type
367
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
367
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
368 368
             $meta_query[] = array(
369 369
                     'key'   => '_wpi_discount_type',
370
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
370
+                    'value' => sanitize_text_field($_GET['discount_type']),
371 371
                     'compare' => '='
372 372
                 );
373 373
         }
374 374
         
375
-        if ( !empty( $meta_query ) ) {
375
+        if (!empty($meta_query)) {
376 376
             $vars['meta_query'] = $meta_query;
377 377
         }
378 378
     }
379 379
 
380 380
     return $vars;
381 381
 }
382
-add_filter( 'request', 'wpinv_request' );
382
+add_filter('request', 'wpinv_request');
383 383
 
384 384
 function wpinv_options_page() {
385
-    $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
385
+    $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
386 386
     
387
-    if ( $page !== 'wpinv-settings' ) {
387
+    if ($page !== 'wpinv-settings') {
388 388
         return;
389 389
     }
390 390
     
391 391
     $settings_tabs = wpinv_get_settings_tabs();
392 392
     $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
393
-    $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
394
-    $sections      = wpinv_get_settings_tab_sections( $active_tab );
393
+    $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
394
+    $sections      = wpinv_get_settings_tab_sections($active_tab);
395 395
     $key           = 'main';
396 396
 
397
-    if ( is_array( $sections ) ) {
398
-        $key = key( $sections );
397
+    if (is_array($sections)) {
398
+        $key = key($sections);
399 399
     }
400 400
 
401
-    $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
402
-    $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
401
+    $registered_sections = wpinv_get_settings_tab_sections($active_tab);
402
+    $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
403 403
     ob_start();
404 404
     ?>
405 405
     <div class="wrap">
406 406
         <h1 class="nav-tab-wrapper">
407 407
             <?php
408
-            foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
409
-                $tab_url = add_query_arg( array(
408
+            foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
409
+                $tab_url = add_query_arg(array(
410 410
                     'settings-updated' => false,
411 411
                     'tab' => $tab_id,
412
-                ) );
412
+                ));
413 413
 
414 414
                 // Remove the section from the tabs so we always end up at the main section
415
-                $tab_url = remove_query_arg( 'section', $tab_url );
416
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
415
+                $tab_url = remove_query_arg('section', $tab_url);
416
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
417 417
 
418 418
                 $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
419 419
 
420
-                echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
421
-                    echo esc_html( $tab_name );
420
+                echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
421
+                    echo esc_html($tab_name);
422 422
                 echo '</a>';
423 423
             }
424 424
             ?>
425 425
         </h1>
426 426
         <?php
427
-        $number_of_sections = count( $sections );
427
+        $number_of_sections = count($sections);
428 428
         $number = 0;
429
-        if ( $number_of_sections > 1 ) {
429
+        if ($number_of_sections > 1) {
430 430
             echo '<div><ul class="subsubsub">';
431
-            foreach( $sections as $section_id => $section_name ) {
431
+            foreach ($sections as $section_id => $section_name) {
432 432
                 echo '<li>';
433 433
                 $number++;
434
-                $tab_url = add_query_arg( array(
434
+                $tab_url = add_query_arg(array(
435 435
                     'settings-updated' => false,
436 436
                     'tab' => $active_tab,
437 437
                     'section' => $section_id
438
-                ) );
439
-                $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
438
+                ));
439
+                $tab_url = remove_query_arg('wpi_sub', $tab_url);
440 440
                 $class = '';
441
-                if ( $section == $section_id ) {
441
+                if ($section == $section_id) {
442 442
                     $class = 'current';
443 443
                 }
444
-                echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
444
+                echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
445 445
 
446
-                if ( $number != $number_of_sections ) {
446
+                if ($number != $number_of_sections) {
447 447
                     echo ' | ';
448 448
                 }
449 449
                 echo '</li>';
@@ -455,19 +455,19 @@  discard block
 block discarded – undo
455 455
             <form method="post" action="options.php">
456 456
                 <table class="form-table">
457 457
                 <?php
458
-                settings_fields( 'wpinv_settings' );
458
+                settings_fields('wpinv_settings');
459 459
 
460
-                if ( 'main' === $section ) {
461
-                    do_action( 'wpinv_settings_tab_top', $active_tab );
460
+                if ('main' === $section) {
461
+                    do_action('wpinv_settings_tab_top', $active_tab);
462 462
                 }
463 463
 
464
-                do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
465
-                do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
466
-                do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
464
+                do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
465
+                do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
466
+                do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
467 467
 
468 468
                 // For backwards compatibility
469
-                if ( 'main' === $section ) {
470
-                    do_action( 'wpinv_settings_tab_bottom', $active_tab );
469
+                if ('main' === $section) {
470
+                    do_action('wpinv_settings_tab_bottom', $active_tab);
471 471
                 }
472 472
                 ?>
473 473
                 </table>
@@ -480,53 +480,53 @@  discard block
 block discarded – undo
480 480
     echo $content;
481 481
 }
482 482
 
483
-function wpinv_item_type_class( $classes, $class, $post_id ) {
483
+function wpinv_item_type_class($classes, $class, $post_id) {
484 484
     global $pagenow, $typenow;
485 485
 
486
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
487
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
488
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
486
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
487
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
488
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
489 489
         }
490 490
         
491
-        if ( !wpinv_item_is_editable( $post_id ) ) {
491
+        if (!wpinv_item_is_editable($post_id)) {
492 492
             $classes[] = 'wpi-editable-n';
493 493
         }
494 494
     }
495 495
     return $classes;
496 496
 }
497
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
497
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
498 498
 
499 499
 function wpinv_check_quick_edit() {
500 500
     global $pagenow, $current_screen, $wpinv_item_screen;
501 501
 
502
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
503
-        if ( empty( $wpinv_item_screen ) ) {
504
-            if ( $current_screen->post_type == 'wpi_item' ) {
502
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
503
+        if (empty($wpinv_item_screen)) {
504
+            if ($current_screen->post_type == 'wpi_item') {
505 505
                 $wpinv_item_screen = 'y';
506 506
             } else {
507 507
                 $wpinv_item_screen = 'n';
508 508
             }
509 509
         }
510 510
 
511
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
512
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
513
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
511
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
512
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
513
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
514 514
         }
515 515
     }
516 516
 }
517
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
517
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
518 518
 
519
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
520
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
521
-        unset( $actions['inline hide-if-no-js'] );
519
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
520
+    if (isset($actions['inline hide-if-no-js'])) {
521
+        unset($actions['inline hide-if-no-js']);
522 522
     }
523 523
     
524
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
525
-        if ( isset( $actions['trash'] ) ) {
526
-            unset( $actions['trash'] );
524
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
525
+        if (isset($actions['trash'])) {
526
+            unset($actions['trash']);
527 527
         }
528
-        if ( isset( $actions['delete'] ) ) {
529
-            unset( $actions['delete'] );
528
+        if (isset($actions['delete'])) {
529
+            unset($actions['delete']);
530 530
         }
531 531
     }
532 532
 
@@ -543,19 +543,19 @@  discard block
 block discarded – undo
543 543
  * @param int $post_parent (default: 0) Parent for the new page
544 544
  * @return int page ID
545 545
  */
546
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
546
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
547 547
     global $wpdb;
548 548
 
549
-    $option_value = wpinv_get_option( $option );
549
+    $option_value = wpinv_get_option($option);
550 550
 
551
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
552
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
551
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
552
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
553 553
             // Valid page is already in place
554 554
             return $page_object->ID;
555 555
         }
556 556
     }
557 557
 
558
-    if(!empty($post_parent)){
558
+    if (!empty($post_parent)) {
559 559
         $page = get_page_by_path($post_parent);
560 560
         if ($page) {
561 561
             $post_parent = $page->ID;
@@ -564,40 +564,40 @@  discard block
 block discarded – undo
564 564
         }
565 565
     }
566 566
 
567
-    if ( strlen( $page_content ) > 0 ) {
567
+    if (strlen($page_content) > 0) {
568 568
         // Search for an existing page with the specified page content (typically a shortcode)
569
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
569
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
570 570
     } else {
571 571
         // Search for an existing page with the specified page slug
572
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
572
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
573 573
     }
574 574
 
575
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
575
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
576 576
 
577
-    if ( $valid_page_found ) {
578
-        if ( $option ) {
579
-            wpinv_update_option( $option, $valid_page_found );
577
+    if ($valid_page_found) {
578
+        if ($option) {
579
+            wpinv_update_option($option, $valid_page_found);
580 580
         }
581 581
         return $valid_page_found;
582 582
     }
583 583
 
584 584
     // Search for a matching valid trashed page
585
-    if ( strlen( $page_content ) > 0 ) {
585
+    if (strlen($page_content) > 0) {
586 586
         // Search for an existing page with the specified page content (typically a shortcode)
587
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
587
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
588 588
     } else {
589 589
         // Search for an existing page with the specified page slug
590
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
590
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
591 591
     }
592 592
 
593
-    if ( $trashed_page_found ) {
593
+    if ($trashed_page_found) {
594 594
         $page_id   = $trashed_page_found;
595 595
         $page_data = array(
596 596
             'ID'             => $page_id,
597 597
             'post_status'    => 'publish',
598 598
             'post_parent'    => $post_parent,
599 599
         );
600
-        wp_update_post( $page_data );
600
+        wp_update_post($page_data);
601 601
     } else {
602 602
         $page_data = array(
603 603
             'post_status'    => 'publish',
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
             'post_parent'    => $post_parent,
610 610
             'comment_status' => 'closed',
611 611
         );
612
-        $page_id = wp_insert_post( $page_data );
612
+        $page_id = wp_insert_post($page_data);
613 613
     }
614 614
 
615
-    if ( $option ) {
616
-        wpinv_update_option( $option, (int)$page_id );
615
+    if ($option) {
616
+        wpinv_update_option($option, (int)$page_id);
617 617
     }
618 618
 
619 619
     return $page_id;
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -8,11 +8,11 @@  discard block
 block discarded – undo
8 8
 
9 9
 
10 10
 // Exit if accessed directly
11
-if ( ! defined( 'ABSPATH' ) ) exit;
11
+if (!defined('ABSPATH')) exit;
12 12
 
13 13
 
14 14
 // Load WP_List_Table if not loaded
15
-if( ! class_exists( 'WP_List_Table' ) ) {
15
+if (!class_exists('WP_List_Table')) {
16 16
 	require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
17 17
 }
18 18
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 	public $pending_count   = 0;
36 36
 	public $expired_count   = 0;
37 37
 	public $completed_count = 0;
38
-	public $trialling_count  = 0;
38
+	public $trialling_count = 0;
39 39
 	public $cancelled_count = 0;
40 40
 	public $failing_count   = 0;
41 41
 
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
 	 * @since       1.0.0
47 47
 	 * @return      void
48 48
 	 */
49
-	function __construct(){
49
+	function __construct() {
50 50
 		global $status, $page;
51 51
 
52 52
 		// Set parent defaults
53
-		parent::__construct( array(
53
+		parent::__construct(array(
54 54
 			'singular'  => 'subscription',
55 55
 			'plural'    => 'subscriptions',
56 56
 			'ajax'      => false
57
-		) );
57
+		));
58 58
 
59 59
 		$this->get_subscription_counts();
60 60
 
@@ -69,28 +69,28 @@  discard block
 block discarded – undo
69 69
 	 */
70 70
 	public function get_views() {
71 71
 
72
-		$current         = isset( $_GET['status'] ) ? $_GET['status'] : '';
73
-		$total_count     = '&nbsp;<span class="count">(' . $this->total_count    . ')</span>';
72
+		$current         = isset($_GET['status']) ? $_GET['status'] : '';
73
+		$total_count     = '&nbsp;<span class="count">(' . $this->total_count . ')</span>';
74 74
 		$active_count    = '&nbsp;<span class="count">(' . $this->active_count . ')</span>';
75 75
 		$pending_count   = '&nbsp;<span class="count">(' . $this->pending_count . ')</span>';
76
-		$expired_count   = '&nbsp;<span class="count">(' . $this->expired_count  . ')</span>';
76
+		$expired_count   = '&nbsp;<span class="count">(' . $this->expired_count . ')</span>';
77 77
 		$completed_count = '&nbsp;<span class="count">(' . $this->completed_count . ')</span>';
78
-		$trialling_count  = '&nbsp;<span class="count">(' . $this->trialling_count   . ')</span>';
79
-		$cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count   . ')</span>';
80
-		$failing_count   = '&nbsp;<span class="count">(' . $this->failing_count   . ')</span>';
78
+		$trialling_count = '&nbsp;<span class="count">(' . $this->trialling_count . ')</span>';
79
+		$cancelled_count = '&nbsp;<span class="count">(' . $this->cancelled_count . ')</span>';
80
+		$failing_count   = '&nbsp;<span class="count">(' . $this->failing_count . ')</span>';
81 81
 
82 82
 		$views = array(
83
-			'all'       => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( 'status', 'paged' ) ), $current === 'all' || $current == '' ? ' class="current"' : '', __('All','invoicing' ) . $total_count ),
84
-			'active'    => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'active', 'paged' => FALSE ) ), $current === 'active' ? ' class="current"' : '', __('Active','invoicing' ) . $active_count ),
85
-			'pending'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'pending', 'paged' => FALSE ) ), $current === 'pending' ? ' class="current"' : '', __('Pending','invoicing' ) . $pending_count ),
86
-			'expired'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'expired', 'paged' => FALSE ) ), $current === 'expired' ? ' class="current"' : '', __('Expired','invoicing' ) . $expired_count ),
87
-			'completed' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'completed', 'paged' => FALSE ) ), $current === 'completed' ? ' class="current"' : '', __('Completed','invoicing' ) . $completed_count ),
88
-			'trialling'  => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'trialling', 'paged' => FALSE ) ), $current === 'trialling' ? ' class="current"' : '', __('Trialling','invoicing' ) . $trialling_count ),
89
-			'cancelled' => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'cancelled', 'paged' => FALSE ) ), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled','invoicing' ) . $cancelled_count ),
90
-			'failing'   => sprintf( '<a href="%s"%s>%s</a>', add_query_arg( array( 'status' => 'failing', 'paged' => FALSE ) ), $current === 'failing' ? ' class="current"' : '', __('Failing','invoicing' ) . $failing_count ),
83
+			'all'       => sprintf('<a href="%s"%s>%s</a>', remove_query_arg(array('status', 'paged')), $current === 'all' || $current == '' ? ' class="current"' : '', __('All', 'invoicing') . $total_count),
84
+			'active'    => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'active', 'paged' => FALSE)), $current === 'active' ? ' class="current"' : '', __('Active', 'invoicing') . $active_count),
85
+			'pending'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'pending', 'paged' => FALSE)), $current === 'pending' ? ' class="current"' : '', __('Pending', 'invoicing') . $pending_count),
86
+			'expired'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'expired', 'paged' => FALSE)), $current === 'expired' ? ' class="current"' : '', __('Expired', 'invoicing') . $expired_count),
87
+			'completed' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'completed', 'paged' => FALSE)), $current === 'completed' ? ' class="current"' : '', __('Completed', 'invoicing') . $completed_count),
88
+			'trialling'  => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'trialling', 'paged' => FALSE)), $current === 'trialling' ? ' class="current"' : '', __('Trialling', 'invoicing') . $trialling_count),
89
+			'cancelled' => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'cancelled', 'paged' => FALSE)), $current === 'cancelled' ? ' class="current"' : '', __('Cancelled', 'invoicing') . $cancelled_count),
90
+			'failing'   => sprintf('<a href="%s"%s>%s</a>', add_query_arg(array('status' => 'failing', 'paged' => FALSE)), $current === 'failing' ? ' class="current"' : '', __('Failing', 'invoicing') . $failing_count),
91 91
 		);
92 92
 
93
-		return apply_filters( 'wpinv_recurring_subscriptions_table_views', $views );
93
+		return apply_filters('wpinv_recurring_subscriptions_table_views', $views);
94 94
 	}
95 95
 
96 96
 	/**
@@ -104,27 +104,27 @@  discard block
 block discarded – undo
104 104
 	 *
105 105
 	 * @return void
106 106
 	 */
107
-	public function search_box( $text, $input_id ) {
107
+	public function search_box($text, $input_id) {
108 108
 
109
-		if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) {
109
+		if (empty($_REQUEST['s']) && !$this->has_items()) {
110 110
 			return;
111 111
 		}
112 112
 
113 113
 		$input_id = $input_id . '-search-input';
114 114
 
115
-		if ( ! empty( $_REQUEST['orderby'] ) ) {
116
-			echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
115
+		if (!empty($_REQUEST['orderby'])) {
116
+			echo '<input type="hidden" name="orderby" value="' . esc_attr($_REQUEST['orderby']) . '" />';
117 117
 		}
118 118
 
119
-		if ( ! empty( $_REQUEST['order'] ) ) {
120
-			echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
119
+		if (!empty($_REQUEST['order'])) {
120
+			echo '<input type="hidden" name="order" value="' . esc_attr($_REQUEST['order']) . '" />';
121 121
 		}
122 122
 ?>
123 123
 		<p class="search-box">
124
-			<?php do_action( 'wpinv_recurring_subscription_search_box' ); ?>
124
+			<?php do_action('wpinv_recurring_subscription_search_box'); ?>
125 125
 			<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
126 126
 			<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
127
-			<?php submit_button( $text, 'button', false, false, array('ID' => 'search-submit') ); ?><br/>
127
+			<?php submit_button($text, 'button', false, false, array('ID' => 'search-submit')); ?><br/>
128 128
 		</p>
129 129
 <?php
130 130
 	}
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
 	 * @since       1.0.0
137 137
 	 * @return      string
138 138
 	 */
139
-	function column_default( $item, $column_name ) {
139
+	function column_default($item, $column_name) {
140 140
 		return $item->$column_name;
141 141
 	}
142 142
 
@@ -147,8 +147,8 @@  discard block
 block discarded – undo
147 147
      * @since       1.0.0
148 148
      * @return      string
149 149
      */
150
-    function column_sub_id( $item ) {
151
-        return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" target="_blank">' . $item->id . '</a>';
150
+    function column_sub_id($item) {
151
+        return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" target="_blank">' . $item->id . '</a>';
152 152
     }
153 153
 
154 154
 	/**
@@ -158,11 +158,11 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	function column_customer_id( $item ) {
162
-		$subscriber = get_userdata( $item->customer_id );
163
-		$customer   = ! empty( $subscriber->display_name ) ? $subscriber->display_name : $subscriber->user_email;
161
+	function column_customer_id($item) {
162
+		$subscriber = get_userdata($item->customer_id);
163
+		$customer   = !empty($subscriber->display_name) ? $subscriber->display_name : $subscriber->user_email;
164 164
 
165
-		return '<a href="' . esc_url( get_edit_user_link( $item->customer_id ) ) . '" target="_blank">' . $customer . '</a>';
165
+		return '<a href="' . esc_url(get_edit_user_link($item->customer_id)) . '" target="_blank">' . $customer . '</a>';
166 166
 	}
167 167
 
168 168
 	/**
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
 	 * @since       1.0.0
173 173
 	 * @return      string
174 174
 	 */
175
-	function column_status( $item ) {
175
+	function column_status($item) {
176 176
 		return $item->get_status_label();
177 177
 	}
178 178
 
@@ -183,11 +183,11 @@  discard block
 block discarded – undo
183 183
 	 * @since       1.0.0
184 184
 	 * @return      string
185 185
 	 */
186
-	function column_period( $item ) {
186
+	function column_period($item) {
187 187
 
188
-		$period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $item->period,$item->frequency );
188
+		$period = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($item->period, $item->frequency);
189 189
 
190
-		return wpinv_price( wpinv_format_amount( $item->recurring_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) ) . ' / ' . $period;
190
+		return wpinv_price(wpinv_format_amount($item->recurring_amount), wpinv_get_invoice_currency_code($item->parent_payment_id)) . ' / ' . $period;
191 191
 	}
192 192
 
193 193
 	/**
@@ -197,8 +197,8 @@  discard block
 block discarded – undo
197 197
 	 * @since       1.0.0
198 198
 	 * @return      string
199 199
 	 */
200
-	function column_bill_times( $item ) {
201
-		return $item->get_times_billed() . ' / ' . ( ( $item->bill_times == 0 ) ? 'Until Cancelled' : $item->bill_times );
200
+	function column_bill_times($item) {
201
+		return $item->get_times_billed() . ' / ' . (($item->bill_times == 0) ? 'Until Cancelled' : $item->bill_times);
202 202
 	}
203 203
 
204 204
 	/**
@@ -208,8 +208,8 @@  discard block
 block discarded – undo
208 208
 	 * @since       1.0.0
209 209
 	 * @return      string
210 210
 	 */
211
-	function column_initial_amount( $item ) {
212
-		return wpinv_price( wpinv_format_amount( $item->initial_amount ), wpinv_get_invoice_currency_code( $item->parent_payment_id ) );
211
+	function column_initial_amount($item) {
212
+		return wpinv_price(wpinv_format_amount($item->initial_amount), wpinv_get_invoice_currency_code($item->parent_payment_id));
213 213
 	}
214 214
 
215 215
 	/**
@@ -219,8 +219,8 @@  discard block
 block discarded – undo
219 219
 	 * @since       1.0.0
220 220
 	 * @return      string
221 221
 	 */
222
-	function column_renewal_date( $item ) {
223
-		return $renewal_date = ! empty( $item->expiration ) ? date_i18n( get_option( 'date_format' ), strtotime( $item->expiration ) ) : __( 'N/A', 'invoicing' );
222
+	function column_renewal_date($item) {
223
+		return $renewal_date = !empty($item->expiration) ? date_i18n(get_option('date_format'), strtotime($item->expiration)) : __('N/A', 'invoicing');
224 224
 	}
225 225
 
226 226
 	/**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
 	 * @since       1.0.0
231 231
 	 * @return      string
232 232
 	 */
233
-	function column_parent_payment_id( $item ) {
234
-		return '<a href="' . get_edit_post_link( $item->parent_payment_id ) . '" target="_blank">' . wpinv_get_invoice_number( $item->parent_payment_id ) . '</a>';
233
+	function column_parent_payment_id($item) {
234
+		return '<a href="' . get_edit_post_link($item->parent_payment_id) . '" target="_blank">' . wpinv_get_invoice_number($item->parent_payment_id) . '</a>';
235 235
 	}
236 236
 
237 237
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @since       1.0.0
242 242
 	 * @return      string
243 243
 	 */
244
-	function column_product_id( $item ) {
245
-		return '<a href="' . esc_url( admin_url( 'post.php?action=edit&post=' . $item->product_id ) ) . '" target="_blank">' . get_the_title( $item->product_id ) . '</a>';
244
+	function column_product_id($item) {
245
+		return '<a href="' . esc_url(admin_url('post.php?action=edit&post=' . $item->product_id)) . '" target="_blank">' . get_the_title($item->product_id) . '</a>';
246 246
 	}
247 247
 
248 248
 	/**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @since       2.0
253 253
 	 * @return      string
254 254
 	 */
255
-	function column_actions( $item ) {
256
-		return '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $item->id ) ) . '" title="' . esc_attr( __( 'View or edit subscription', 'invoicing' ) ) . '" target="_blank">' . __( 'View', 'invoicing' ) . '</a>';
255
+	function column_actions($item) {
256
+		return '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $item->id)) . '" title="' . esc_attr(__('View or edit subscription', 'invoicing')) . '" target="_blank">' . __('View', 'invoicing') . '</a>';
257 257
 	}
258 258
 
259 259
 
@@ -265,21 +265,21 @@  discard block
 block discarded – undo
265 265
 	 * @return      array
266 266
 	 */
267 267
 
268
-	function get_columns(){
268
+	function get_columns() {
269 269
 		$columns = array(
270
-			'sub_id'            => __( 'ID', 'invoicing' ),
271
-			'customer_id'       => __( 'Customer', 'invoicing' ),
272
-			'status'            => __( 'Status', 'invoicing' ),
273
-			'period'            => __( 'Billing Cycle', 'invoicing' ),
274
-			'initial_amount'    => __( 'Initial Amount', 'invoicing' ),
275
-			'bill_times'        => __( 'Times Billed', 'invoicing' ),
276
-			'renewal_date'      => __( 'Renewal Date', 'invoicing' ),
277
-			'parent_payment_id' => __( 'Invoice', 'invoicing' ),
278
-			'product_id'        => __( 'Item', 'invoicing' ),
279
-			'actions'           => __( 'Actions', 'invoicing' ),
270
+			'sub_id'            => __('ID', 'invoicing'),
271
+			'customer_id'       => __('Customer', 'invoicing'),
272
+			'status'            => __('Status', 'invoicing'),
273
+			'period'            => __('Billing Cycle', 'invoicing'),
274
+			'initial_amount'    => __('Initial Amount', 'invoicing'),
275
+			'bill_times'        => __('Times Billed', 'invoicing'),
276
+			'renewal_date'      => __('Renewal Date', 'invoicing'),
277
+			'parent_payment_id' => __('Invoice', 'invoicing'),
278
+			'product_id'        => __('Item', 'invoicing'),
279
+			'actions'           => __('Actions', 'invoicing'),
280 280
 		);
281 281
 
282
-		return apply_filters( 'wpinv_report_subscription_columns', $columns );
282
+		return apply_filters('wpinv_report_subscription_columns', $columns);
283 283
 	}
284 284
 
285 285
 	/**
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @return      int
291 291
 	 */
292 292
 	function get_paged() {
293
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
293
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
294 294
 	}
295 295
 
296 296
 	/**
@@ -306,16 +306,16 @@  discard block
 block discarded – undo
306 306
 
307 307
 		$db = new WPInv_Subscriptions_DB;
308 308
 
309
-		$search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
309
+		$search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
310 310
 
311 311
 		$this->total_count     = $db->count();
312
-		$this->active_count    = $db->count( array( 'status' => 'active', 'search' => $search ) );
313
-		$this->pending_count   = $db->count( array( 'status' => 'pending', 'search' => $search ) );
314
-		$this->expired_count   = $db->count( array( 'status' => 'expired', 'search' => $search ) );
315
-		$this->trialling_count  = $db->count( array( 'status' => 'trialling', 'search' => $search ) );
316
-		$this->cancelled_count = $db->count( array( 'status' => 'cancelled', 'search' => $search ) );
317
-		$this->completed_count = $db->count( array( 'status' => 'completed', 'search' => $search ) );
318
-		$this->failing_count   = $db->count( array( 'status' => 'failing', 'search' => $search ) );
312
+		$this->active_count    = $db->count(array('status' => 'active', 'search' => $search));
313
+		$this->pending_count   = $db->count(array('status' => 'pending', 'search' => $search));
314
+		$this->expired_count   = $db->count(array('status' => 'expired', 'search' => $search));
315
+		$this->trialling_count = $db->count(array('status' => 'trialling', 'search' => $search));
316
+		$this->cancelled_count = $db->count(array('status' => 'cancelled', 'search' => $search));
317
+		$this->completed_count = $db->count(array('status' => 'completed', 'search' => $search));
318
+		$this->failing_count   = $db->count(array('status' => 'failing', 'search' => $search));
319 319
 
320 320
 	}
321 321
 
@@ -336,28 +336,28 @@  discard block
 block discarded – undo
336 336
 
337 337
 		$columns  = $this->get_columns();
338 338
 		$hidden   = array(); // No hidden columns
339
-		$status   = isset( $_GET['status'] ) ? $_GET['status'] : 'any';
339
+		$status   = isset($_GET['status']) ? $_GET['status'] : 'any';
340 340
 		$sortable = $this->get_sortable_columns();
341 341
 
342
-		$this->_column_headers = array( $columns, $hidden, $sortable );
342
+		$this->_column_headers = array($columns, $hidden, $sortable);
343 343
 
344 344
 		$current_page = $this->get_pagenum();
345 345
 
346 346
 		$db     = new WPInv_Subscriptions_DB;
347
-		$search = ! empty( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : '';
347
+		$search = !empty($_GET['s']) ? sanitize_text_field($_GET['s']) : '';
348 348
 		$args   = array(
349 349
 			'number' => $this->per_page,
350
-			'offset' => $this->per_page * ( $this->get_paged() - 1 ),
350
+			'offset' => $this->per_page * ($this->get_paged() - 1),
351 351
 			'search' => $search
352 352
 		);
353 353
 
354
-		if ( 'any' !== $status ) {
354
+		if ('any' !== $status) {
355 355
 			$args['status'] = $status;
356 356
 		}
357 357
 
358
-		$this->items = $db->get_subscriptions( $args );
358
+		$this->items = $db->get_subscriptions($args);
359 359
 
360
-		switch ( $status ) {
360
+		switch ($status) {
361 361
 			case 'active':
362 362
 				$total_items = $this->active_count;
363 363
 				break;
@@ -385,10 +385,10 @@  discard block
 block discarded – undo
385 385
 				break;
386 386
 		}
387 387
 
388
-		$this->set_pagination_args( array(
388
+		$this->set_pagination_args(array(
389 389
 			'total_items' => $total_items,
390 390
 			'per_page'    => $this->per_page,
391
-			'total_pages' => ceil( $total_items / $this->per_page )
392
-		) );
391
+			'total_pages' => ceil($total_items / $this->per_page)
392
+		));
393 393
 	}
394 394
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-items.php 1 patch
Spacing   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Items {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat, $ajax_cart_details;
10 10
 
11
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
12
-        $invoice            = new WPInv_Invoice( $post_id );
11
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
12
+        $invoice            = new WPInv_Invoice($post_id);
13 13
         $ajax_cart_details  = $invoice->get_cart_details();
14
-        $subtotal           = $invoice->get_subtotal( true );
14
+        $subtotal           = $invoice->get_subtotal(true);
15 15
         $discount_raw       = $invoice->get_discount();
16
-        $discount           = wpinv_price( $discount_raw, $invoice->get_currency() );
16
+        $discount           = wpinv_price($discount_raw, $invoice->get_currency());
17 17
         $discounts          = $discount_raw > 0 ? $invoice->get_discounts() : '';
18
-        $tax                = $invoice->get_tax( true );
19
-        $total              = $invoice->get_total( true );
18
+        $tax                = $invoice->get_tax(true);
19
+        $total              = $invoice->get_total(true);
20 20
         $item_quantities    = wpinv_item_quantities_enabled();
21 21
         $use_taxes          = wpinv_use_taxes();
22
-        if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
22
+        if (!$use_taxes && (float)$invoice->get_tax() > 0) {
23 23
             $use_taxes = true;
24 24
         }
25
-        $item_types         = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
25
+        $item_types         = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
26 26
         $is_recurring       = $invoice->is_recurring();
27 27
         $post_type_object   = get_post_type_object($invoice->post_type);
28 28
         $type_title         = $post_type_object->labels->singular_name;
29 29
 
30 30
         $cols = 5;
31
-        if ( $item_quantities ) {
31
+        if ($item_quantities) {
32 32
             $cols++;
33 33
         }
34
-        if ( $use_taxes ) {
34
+        if ($use_taxes) {
35 35
             $cols++;
36 36
         }
37 37
         $class = '';
38
-        if ( $invoice->is_paid() ) {
38
+        if ($invoice->is_paid()) {
39 39
             $class .= ' wpinv-paid';
40 40
         }
41
-        if ( $invoice->is_refunded() ) {
41
+        if ($invoice->is_refunded()) {
42 42
             $class .= ' wpinv-refunded';
43 43
         }
44
-        if ( $is_recurring ) {
44
+        if ($is_recurring) {
45 45
             $class .= ' wpi-recurring';
46 46
         }
47 47
         ?>
@@ -49,21 +49,21 @@  discard block
 block discarded – undo
49 49
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
50 50
                 <thead>
51 51
                     <tr>
52
-                        <th class="id"><?php _e( 'ID', 'invoicing' );?></th>
53
-                        <th class="title"><?php _e( 'Item', 'invoicing' );?></th>
54
-                        <th class="price"><?php _e( 'Price', 'invoicing' );?></th>
55
-                        <?php if ( $item_quantities ) { ?>
56
-                        <th class="qty"><?php _e( 'Qty', 'invoicing' );?></th>
52
+                        <th class="id"><?php _e('ID', 'invoicing'); ?></th>
53
+                        <th class="title"><?php _e('Item', 'invoicing'); ?></th>
54
+                        <th class="price"><?php _e('Price', 'invoicing'); ?></th>
55
+                        <?php if ($item_quantities) { ?>
56
+                        <th class="qty"><?php _e('Qty', 'invoicing'); ?></th>
57 57
                         <?php } ?>
58
-                        <th class="total"><?php _e( 'Total', 'invoicing' );?></th>
59
-                        <?php if ( $use_taxes ) { ?>
60
-                        <th class="tax"><?php _e( 'Tax (%)', 'invoicing' );?></th>
58
+                        <th class="total"><?php _e('Total', 'invoicing'); ?></th>
59
+                        <?php if ($use_taxes) { ?>
60
+                        <th class="tax"><?php _e('Tax (%)', 'invoicing'); ?></th>
61 61
                         <?php } ?>
62 62
                         <th class="action"></th>
63 63
                     </tr>
64 64
                 </thead>
65 65
                 <tbody class="wpinv-line-items">
66
-                    <?php echo wpinv_admin_get_line_items( $invoice ); ?>
66
+                    <?php echo wpinv_admin_get_line_items($invoice); ?>
67 67
                 </tbody>
68 68
                 <tfoot class="wpinv-totals">
69 69
                     <tr>
@@ -75,44 +75,44 @@  discard block
 block discarded – undo
75 75
                                         </td>
76 76
                                         <td class="title">
77 77
                                             <input type="text" class="regular-text" placeholder="Item name" value="" name="_wpinv_quick[name]">
78
-                                            <?php if ( $wpinv_euvat->allow_vat_rules() ) { ?>
78
+                                            <?php if ($wpinv_euvat->allow_vat_rules()) { ?>
79 79
                                             <div class="wp-clearfix">
80 80
                                                 <label class="wpi-vat-rule">
81
-                                                    <span class="title"><?php _e( 'VAT rule type', 'invoicing' );?></span>
81
+                                                    <span class="title"><?php _e('VAT rule type', 'invoicing'); ?></span>
82 82
                                                     <span class="input-text-wrap">
83
-                                                        <?php echo wpinv_html_select( array(
83
+                                                        <?php echo wpinv_html_select(array(
84 84
                                                             'options'          => $wpinv_euvat->get_rules(),
85 85
                                                             'name'             => '_wpinv_quick[vat_rule]',
86 86
                                                             'id'               => '_wpinv_quick_vat_rule',
87 87
                                                             'show_option_all'  => false,
88 88
                                                             'show_option_none' => false,
89 89
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
90
-                                                        ) ); ?>
90
+                                                        )); ?>
91 91
                                                     </span>
92 92
                                                 </label>
93 93
                                             </div>
94
-                                            <?php } if ( $wpinv_euvat->allow_vat_classes() ) { ?>
94
+                                            <?php } if ($wpinv_euvat->allow_vat_classes()) { ?>
95 95
                                             <div class="wp-clearfix">
96 96
                                                 <label class="wpi-vat-class">
97
-                                                    <span class="title"><?php _e( 'VAT class', 'invoicing' );?></span>
97
+                                                    <span class="title"><?php _e('VAT class', 'invoicing'); ?></span>
98 98
                                                     <span class="input-text-wrap">
99
-                                                        <?php echo wpinv_html_select( array(
99
+                                                        <?php echo wpinv_html_select(array(
100 100
                                                             'options'          => $wpinv_euvat->get_all_classes(),
101 101
                                                             'name'             => '_wpinv_quick[vat_class]',
102 102
                                                             'id'               => '_wpinv_quick_vat_class',
103 103
                                                             'show_option_all'  => false,
104 104
                                                             'show_option_none' => false,
105 105
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
106
-                                                        ) ); ?>
106
+                                                        )); ?>
107 107
                                                     </span>
108 108
                                                 </label>
109 109
                                             </div>
110 110
                                             <?php } ?>
111 111
                                             <div class="wp-clearfix">
112 112
                                                 <label class="wpi-item-type">
113
-                                                    <span class="title"><?php _e( 'Item type', 'invoicing' );?></span>
113
+                                                    <span class="title"><?php _e('Item type', 'invoicing'); ?></span>
114 114
                                                     <span class="input-text-wrap">
115
-                                                        <?php echo wpinv_html_select( array(
115
+                                                        <?php echo wpinv_html_select(array(
116 116
                                                             'options'          => $item_types,
117 117
                                                             'name'             => '_wpinv_quick[type]',
118 118
                                                             'id'               => '_wpinv_quick_type',
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                                                             'show_option_all'  => false,
121 121
                                                             'show_option_none' => false,
122 122
                                                             'class'            => 'gdmbx2-text-medium wpinv-quick-type',
123
-                                                        ) ); ?>
123
+                                                        )); ?>
124 124
                                                     </span>
125 125
                                                 </label>
126 126
                                             </div>
@@ -133,11 +133,11 @@  discard block
 block discarded – undo
133 133
                                             </div>
134 134
                                         </td>
135 135
                                         <td class="price"><input type="text" placeholder="0.00" class="wpi-field-price wpi-price" name="_wpinv_quick[price]" /></td>
136
-                                        <?php if ( $item_quantities ) { ?>
136
+                                        <?php if ($item_quantities) { ?>
137 137
                                         <td class="qty"><input type="number" class="small-text" step="1" min="1" value="1" name="_wpinv_quick[qty]" /></td>
138 138
                                         <?php } ?>
139 139
                                         <td class="total"></td>
140
-                                        <?php if ( $use_taxes ) { ?>
140
+                                        <?php if ($use_taxes) { ?>
141 141
                                         <td class="tax"></td>
142 142
                                         <?php } ?>
143 143
                                         <td class="action"></td>
@@ -150,29 +150,29 @@  discard block
 block discarded – undo
150 150
                         <td colspan="<?php echo $cols; ?>"></td>
151 151
                     </tr>
152 152
                     <tr class="totals">
153
-                        <td colspan="<?php echo ( $cols - 4 ); ?>"></td>
153
+                        <td colspan="<?php echo ($cols - 4); ?>"></td>
154 154
                         <td colspan="4">
155 155
                             <table cellspacing="0" cellpadding="0">
156 156
                                 <tr class="subtotal">
157
-                                    <td class="name"><?php _e( 'Sub Total:', 'invoicing' );?></td>
158
-                                    <td class="total"><?php echo $subtotal;?></td>
157
+                                    <td class="name"><?php _e('Sub Total:', 'invoicing'); ?></td>
158
+                                    <td class="total"><?php echo $subtotal; ?></td>
159 159
                                     <td class="action"></td>
160 160
                                 </tr>
161 161
                                 <tr class="discount">
162
-                                    <td class="name"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice->ID ) ); ?>:</td>
163
-                                    <td class="total"><?php echo wpinv_discount( $invoice->ID, true, true ); ?></td>
162
+                                    <td class="name"><?php wpinv_get_discount_label(wpinv_discount_code($invoice->ID)); ?>:</td>
163
+                                    <td class="total"><?php echo wpinv_discount($invoice->ID, true, true); ?></td>
164 164
                                     <td class="action"></td>
165 165
                                 </tr>
166
-                                <?php if ( $use_taxes ) { ?>
166
+                                <?php if ($use_taxes) { ?>
167 167
                                 <tr class="tax">
168
-                                    <td class="name"><?php _e( 'Tax:', 'invoicing' );?></td>
169
-                                    <td class="total"><?php echo $tax;?></td>
168
+                                    <td class="name"><?php _e('Tax:', 'invoicing'); ?></td>
169
+                                    <td class="total"><?php echo $tax; ?></td>
170 170
                                     <td class="action"></td>
171 171
                                 </tr>
172 172
                                 <?php } ?>
173 173
                                 <tr class="total">
174
-                                    <td class="name"><?php echo apply_filters( 'wpinv_invoice_items_total_label', __( 'Invoice Total:', 'invoicing' ), $invoice );?></td>
175
-                                    <td class="total"><?php echo $total;?></td>
174
+                                    <td class="name"><?php echo apply_filters('wpinv_invoice_items_total_label', __('Invoice Total:', 'invoicing'), $invoice); ?></td>
175
+                                    <td class="total"><?php echo $total; ?></td>
176 176
                                     <td class="action"></td>
177 177
                                 </tr>
178 178
                             </table>
@@ -183,89 +183,89 @@  discard block
 block discarded – undo
183 183
             <div class="wpinv-actions">
184 184
                 <?php ob_start(); ?>
185 185
                 <?php
186
-                    if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
187
-                        if ( !$invoice->is_recurring() ) {
188
-                            echo wpinv_item_dropdown( array(
186
+                    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
187
+                        if (!$invoice->is_recurring()) {
188
+                            echo wpinv_item_dropdown(array(
189 189
                                 'name'             => 'wpinv_invoice_item',
190 190
                                 'id'               => 'wpinv_invoice_item',
191 191
                                 'show_recurring'   => true,
192
-                            ) );
192
+                            ));
193 193
                     ?>
194
-                <input type="button" value="<?php echo sprintf(esc_attr__( 'Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e( 'Create new item', 'invoicing' );?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e( 'Recalculate Totals', 'invoicing' );?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
194
+                <input type="button" value="<?php echo sprintf(esc_attr__('Add item to %s', 'invoicing'), $type_title); ?>" class="button button-primary" id="wpinv-add-item"><input type="button" value="<?php esc_attr_e('Create new item', 'invoicing'); ?>" class="button button-primary" id="wpinv-new-item"><?php } ?><input type="button" value="<?php esc_attr_e('Recalculate Totals', 'invoicing'); ?>" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">
195 195
                     <?php } ?>
196
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
197
-                <?php $item_actions = ob_get_clean(); echo apply_filters( 'wpinv_invoice_items_actions_content', $item_actions, $invoice, $post ); ?>
196
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
197
+                <?php $item_actions = ob_get_clean(); echo apply_filters('wpinv_invoice_items_actions_content', $item_actions, $invoice, $post); ?>
198 198
             </div>
199 199
         </div>
200 200
         <?php
201 201
     }
202 202
 
203
-    public static function prices( $post ) {        
203
+    public static function prices($post) {        
204 204
         $symbol         = wpinv_currency_symbol();
205 205
         $position       = wpinv_currency_position();
206
-        $item           = new WPInv_Item( $post->ID );
206
+        $item           = new WPInv_Item($post->ID);
207 207
 
208 208
         $price          = $item->get_price();
209 209
         $is_recurring   = $item->is_recurring();
210 210
         $period         = $item->get_recurring_period();
211
-        $interval       = absint( $item->get_recurring_interval() );
212
-        $times          = absint( $item->get_recurring_limit() );
211
+        $interval       = absint($item->get_recurring_interval());
212
+        $times          = absint($item->get_recurring_limit());
213 213
         $free_trial     = $item->has_free_trial();
214 214
         $trial_interval = $item->get_trial_interval();
215 215
         $trial_period   = $item->get_trial_period();
216 216
 
217 217
         $intervals      = array();
218
-        for ( $i = 1; $i <= 90; $i++ ) {
218
+        for ($i = 1; $i <= 90; $i++) {
219 219
             $intervals[$i] = $i;
220 220
         }
221 221
 
222
-        $interval       = $interval > 0 ? $interval : 1;
222
+        $interval = $interval > 0 ? $interval : 1;
223 223
 
224 224
         $class = $is_recurring ? 'wpinv-recurring-y' : 'wpinv-recurring-n';
225 225
         ?>
226
-        <p class="wpinv-row-prices"><?php echo ( $position != 'right' ? $symbol . '&nbsp;' : '' );?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount( 0 ); ?>" value="<?php echo $price;?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled( $item->is_editable(), false ); ?> /><?php echo ( $position == 'right' ? '&nbsp;' . $symbol : '' );?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce( 'wpinv_item_meta_box_save' ) ;?>" />
227
-        <?php do_action( 'wpinv_prices_metabox_price', $item ); ?>
226
+        <p class="wpinv-row-prices"><?php echo ($position != 'right' ? $symbol . '&nbsp;' : ''); ?><input type="text" maxlength="12" placeholder="<?php echo wpinv_sanitize_amount(0); ?>" value="<?php echo $price; ?>" id="wpinv_item_price" name="wpinv_item_price" class="medium-text wpi-field-price wpi-price" <?php disabled($item->is_editable(), false); ?> /><?php echo ($position == 'right' ? '&nbsp;' . $symbol : ''); ?><input type="hidden" name="wpinv_vat_meta_box_nonce" value="<?php echo wp_create_nonce('wpinv_item_meta_box_save'); ?>" />
227
+        <?php do_action('wpinv_prices_metabox_price', $item); ?>
228 228
         </p>
229 229
         <p class="wpinv-row-is-recurring">
230 230
             <label for="wpinv_is_recurring">
231
-                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked( 1, $is_recurring ); ?> />
232
-                <?php echo apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Is Recurring Item?', 'invoicing' ) ); ?>
231
+                <input type="checkbox" name="wpinv_is_recurring" id="wpinv_is_recurring" value="1" <?php checked(1, $is_recurring); ?> />
232
+                <?php echo apply_filters('wpinv_is_recurring_toggle_text', __('Is Recurring Item?', 'invoicing')); ?>
233 233
             </label>
234
-            <?php do_action( 'wpinv_prices_metabox_is_recurring_field', $item ); ?>
234
+            <?php do_action('wpinv_prices_metabox_is_recurring_field', $item); ?>
235 235
         </p>
236
-        <p class="wpinv-row-recurring-fields <?php echo $class;?>">
237
-            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e( 'Recurring', 'invoicing' );?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e( 'day(s)', 'invoicing' ); ?>" <?php selected( 'D', $period );?>><?php _e( 'Daily', 'invoicing' ); ?></option><option value="W" data-text="<?php esc_attr_e( 'week(s)', 'invoicing' ); ?>" <?php selected( 'W', $period );?>><?php _e( 'Weekly', 'invoicing' ); ?></option><option value="M" data-text="<?php esc_attr_e( 'month(s)', 'invoicing' ); ?>" <?php selected( 'M', $period );?>><?php _e( 'Monthly', 'invoicing' ); ?></option><option value="Y" data-text="<?php esc_attr_e( 'year(s)', 'invoicing' ); ?>" <?php selected( 'Y', $period );?>><?php _e( 'Yearly', 'invoicing' ); ?></option></select></label>
238
-            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e( 'at every', 'invoicing' );?> <?php echo wpinv_html_select( array(
236
+        <p class="wpinv-row-recurring-fields <?php echo $class; ?>">
237
+            <label class="wpinv-period" for="wpinv_recurring_period"><?php _e('Recurring', 'invoicing'); ?> <select class="wpinv-select " id="wpinv_recurring_period" name="wpinv_recurring_period"><option value="D" data-text="<?php esc_attr_e('day(s)', 'invoicing'); ?>" <?php selected('D', $period); ?>><?php _e('Daily', 'invoicing'); ?></option><option value="W" data-text="<?php esc_attr_e('week(s)', 'invoicing'); ?>" <?php selected('W', $period); ?>><?php _e('Weekly', 'invoicing'); ?></option><option value="M" data-text="<?php esc_attr_e('month(s)', 'invoicing'); ?>" <?php selected('M', $period); ?>><?php _e('Monthly', 'invoicing'); ?></option><option value="Y" data-text="<?php esc_attr_e('year(s)', 'invoicing'); ?>" <?php selected('Y', $period); ?>><?php _e('Yearly', 'invoicing'); ?></option></select></label>
238
+            <label class="wpinv-interval" for="wpinv_recurring_interval"> <?php _e('at every', 'invoicing'); ?> <?php echo wpinv_html_select(array(
239 239
                 'options'          => $intervals,
240 240
                 'name'             => 'wpinv_recurring_interval',
241 241
                 'id'               => 'wpinv_recurring_interval',
242 242
                 'selected'         => $interval,
243 243
                 'show_option_all'  => false,
244 244
                 'show_option_none' => false
245
-            ) ); ?> <span id="wpinv_interval_text"><?php _e( 'day(s)', 'invoicing' );?></span></label>
246
-            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e( 'for', 'invoicing' );?> <input class="small-text" type="number" value="<?php echo $times;?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e( 'time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing' );?></label>
245
+            )); ?> <span id="wpinv_interval_text"><?php _e('day(s)', 'invoicing'); ?></span></label>
246
+            <label class="wpinv-times" for="wpinv_recurring_limit"> <?php _e('for', 'invoicing'); ?> <input class="small-text" type="number" value="<?php echo $times; ?>" size="4" id="wpinv_recurring_limit" name="wpinv_recurring_limit" step="1" min="0"> <?php _e('time(s) <i>(select 0 for recurring forever until cancelled</i>)', 'invoicing'); ?></label>
247 247
             <span class="clear wpi-trial-clr"></span>
248 248
             <label class="wpinv-free-trial" for="wpinv_free_trial">
249
-                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked( true, (bool)$free_trial ); ?> /> 
250
-                <?php echo __( 'Offer free trial for', 'invoicing' ); ?>
249
+                <input type="checkbox" name="wpinv_free_trial" id="wpinv_free_trial" value="1" <?php checked(true, (bool)$free_trial); ?> /> 
250
+                <?php echo __('Offer free trial for', 'invoicing'); ?>
251 251
             </label>
252 252
             <label class="wpinv-trial-interval" for="wpinv_trial_interval">
253
-                <input class="small-text" type="number" value="<?php echo $trial_interval;?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected( 'D', $trial_period );?>><?php _e( 'day(s)', 'invoicing' ); ?></option><option value="W" <?php selected( 'W', $trial_period );?>><?php _e( 'week(s)', 'invoicing' ); ?></option><option value="M" <?php selected( 'M', $trial_period );?>><?php _e( 'month(s)', 'invoicing' ); ?></option><option value="Y" <?php selected( 'Y', $trial_period );?>><?php _e( 'year(s)', 'invoicing' ); ?></option></select>
253
+                <input class="small-text" type="number" value="<?php echo $trial_interval; ?>" size="4" id="wpinv_trial_interval" name="wpinv_trial_interval" step="1" min="1"> <select class="wpinv-select" id="wpinv_trial_period" name="wpinv_trial_period"><option value="D" <?php selected('D', $trial_period); ?>><?php _e('day(s)', 'invoicing'); ?></option><option value="W" <?php selected('W', $trial_period); ?>><?php _e('week(s)', 'invoicing'); ?></option><option value="M" <?php selected('M', $trial_period); ?>><?php _e('month(s)', 'invoicing'); ?></option><option value="Y" <?php selected('Y', $trial_period); ?>><?php _e('year(s)', 'invoicing'); ?></option></select>
254 254
             </label>
255
-            <?php do_action( 'wpinv_prices_metabox_recurring_fields', $item ); ?>
255
+            <?php do_action('wpinv_prices_metabox_recurring_fields', $item); ?>
256 256
         </p>
257
-        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type( $post->ID ); ?>" />
258
-        <?php do_action( 'wpinv_item_price_field', $post->ID ); ?>
257
+        <input type="hidden" id="_wpi_current_type" value="<?php echo wpinv_get_item_type($post->ID); ?>" />
258
+        <?php do_action('wpinv_item_price_field', $post->ID); ?>
259 259
         <?php
260 260
     }
261 261
 
262
-    public static function vat_rules( $post ) {
262
+    public static function vat_rules($post) {
263 263
         global $wpinv_euvat;
264 264
 
265
-        $rule_type = $wpinv_euvat->get_item_rule( $post->ID );
265
+        $rule_type = $wpinv_euvat->get_item_rule($post->ID);
266 266
         ?>
267
-        <p><label for="wpinv_vat_rules"><strong><?php _e( 'Select how VAT rules will be applied:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
268
-        <?php echo wpinv_html_select( array(
267
+        <p><label for="wpinv_vat_rules"><strong><?php _e('Select how VAT rules will be applied:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
268
+        <?php echo wpinv_html_select(array(
269 269
                     'options'          => $wpinv_euvat->get_rules(),
270 270
                     'name'             => 'wpinv_vat_rules',
271 271
                     'id'               => 'wpinv_vat_rules',
@@ -273,19 +273,19 @@  discard block
 block discarded – undo
273 273
                     'show_option_all'  => false,
274 274
                     'show_option_none' => false,
275 275
                     'class'            => 'gdmbx2-text-medium wpinv-vat-rules',
276
-                ) ); ?>
276
+                )); ?>
277 277
         </p>
278
-        <p class="wpi-m0"><?php _e( 'When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing' ); ?></p>
279
-        <p class="wpi-m0"><?php _e( 'If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing' ); ?></p>
278
+        <p class="wpi-m0"><?php _e('When you select physical product rules, only consumers and businesses in your country will be charged VAT.  The VAT rate used will be the rate in your country.', 'invoicing'); ?></p>
279
+        <p class="wpi-m0"><?php _e('If you select Digital product rules, VAT will be charged at the rate that applies in the country of the consumer.  Only businesses in your country will be charged VAT.', 'invoicing'); ?></p>
280 280
         <?php
281 281
     }
282 282
 
283
-    public static function vat_classes( $post ) {
283
+    public static function vat_classes($post) {
284 284
         global $wpinv_euvat;
285 285
         
286
-        $vat_class = $wpinv_euvat->get_item_class( $post->ID );
286
+        $vat_class = $wpinv_euvat->get_item_class($post->ID);
287 287
         ?>
288
-        <p><?php echo wpinv_html_select( array(
288
+        <p><?php echo wpinv_html_select(array(
289 289
                     'options'          => $wpinv_euvat->get_all_classes(),
290 290
                     'name'             => 'wpinv_vat_class',
291 291
                     'id'               => 'wpinv_vat_class',
@@ -293,18 +293,18 @@  discard block
 block discarded – undo
293 293
                     'show_option_all'  => false,
294 294
                     'show_option_none' => false,
295 295
                     'class'            => 'gdmbx2-text-medium wpinv-vat-class',
296
-                ) ); ?>
296
+                )); ?>
297 297
         </p>
298
-        <p class="wpi-m0"><?php _e( 'Select the VAT rate class to use for this invoice item.', 'invoicing' ); ?></p>
298
+        <p class="wpi-m0"><?php _e('Select the VAT rate class to use for this invoice item.', 'invoicing'); ?></p>
299 299
         <?php
300 300
     }
301 301
 
302
-    public static function item_info( $post ) {
303
-        $item_type = wpinv_get_item_type( $post->ID );
304
-        do_action( 'wpinv_item_info_metabox_before', $post );
302
+    public static function item_info($post) {
303
+        $item_type = wpinv_get_item_type($post->ID);
304
+        do_action('wpinv_item_info_metabox_before', $post);
305 305
         ?>
306
-        <p><label for="wpinv_item_type"><strong><?php _e( 'Type:', 'invoicing' );?></strong></label>&nbsp;&nbsp;&nbsp;
307
-        <?php echo wpinv_html_select( array(
306
+        <p><label for="wpinv_item_type"><strong><?php _e('Type:', 'invoicing'); ?></strong></label>&nbsp;&nbsp;&nbsp;
307
+        <?php echo wpinv_html_select(array(
308 308
                     'options'          => wpinv_get_item_types(),
309 309
                     'name'             => 'wpinv_item_type',
310 310
                     'id'               => 'wpinv_item_type',
@@ -312,114 +312,114 @@  discard block
 block discarded – undo
312 312
                     'show_option_all'  => false,
313 313
                     'show_option_none' => false,
314 314
                     'class'            => 'gdmbx2-text-medium wpinv-item-type',
315
-                ) ); ?>
315
+                )); ?>
316 316
         </p>
317
-        <p class="wpi-m0"><?php _e( 'Select item type.', 'invoicing' );?><br><?php _e( '<b>Standard:</b> Standard item type', 'invoicing' );?><br><?php _e( '<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing' );?></p>
317
+        <p class="wpi-m0"><?php _e('Select item type.', 'invoicing'); ?><br><?php _e('<b>Standard:</b> Standard item type', 'invoicing'); ?><br><?php _e('<b>Fee:</b> Like Registration Fee, Sign up Fee etc.', 'invoicing'); ?></p>
318 318
         <?php
319
-        do_action( 'wpinv_item_info_metabox_after', $post );
319
+        do_action('wpinv_item_info_metabox_after', $post);
320 320
     }
321 321
 
322
-    public static function meta_values( $post ) {
323
-        $meta_keys = apply_filters( 'wpinv_show_meta_values_for_keys', array(
322
+    public static function meta_values($post) {
323
+        $meta_keys = apply_filters('wpinv_show_meta_values_for_keys', array(
324 324
             'type',
325 325
             'custom_id'
326
-        ) );
326
+        ));
327 327
 
328
-        if ( empty( $meta_keys ) ) {
328
+        if (empty($meta_keys)) {
329 329
             return;
330 330
         }
331 331
 
332
-        do_action( 'wpinv_meta_values_metabox_before', $post );
332
+        do_action('wpinv_meta_values_metabox_before', $post);
333 333
 
334
-        foreach ( $meta_keys as $meta_key ) {
334
+        foreach ($meta_keys as $meta_key) {
335 335
             ?>
336
-            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta( $post->ID, '_wpinv_' . $meta_key, true ); ?></label></p>
336
+            <p class="wpi-mtb05"><label><strong><?php echo $meta_key; ?></strong>: <?php echo get_post_meta($post->ID, '_wpinv_' . $meta_key, true); ?></label></p>
337 337
             <?php 
338 338
         }
339 339
 
340
-        do_action( 'wpinv_meta_values_metabox_after', $post );
340
+        do_action('wpinv_meta_values_metabox_after', $post);
341 341
     }
342 342
 
343
-    public static function save( $post_id, $data, $post ) {
344
-        $invoice        = new WPInv_Invoice( $post_id );
343
+    public static function save($post_id, $data, $post) {
344
+        $invoice        = new WPInv_Invoice($post_id);
345 345
 
346 346
         // Billing
347
-        $first_name     = sanitize_text_field( $data['wpinv_first_name'] );
348
-        $last_name      = sanitize_text_field( $data['wpinv_last_name'] );
349
-        $company        = sanitize_text_field( $data['wpinv_company'] );
350
-        $vat_number     = sanitize_text_field( $data['wpinv_vat_number'] );
351
-        $phone          = sanitize_text_field( $data['wpinv_phone'] );
352
-        $address        = sanitize_text_field( $data['wpinv_address'] );
353
-        $city           = sanitize_text_field( $data['wpinv_city'] );
354
-        $zip            = sanitize_text_field( $data['wpinv_zip'] );
355
-        $country        = sanitize_text_field( $data['wpinv_country'] );
356
-        $state          = sanitize_text_field( $data['wpinv_state'] );
347
+        $first_name     = sanitize_text_field($data['wpinv_first_name']);
348
+        $last_name      = sanitize_text_field($data['wpinv_last_name']);
349
+        $company        = sanitize_text_field($data['wpinv_company']);
350
+        $vat_number     = sanitize_text_field($data['wpinv_vat_number']);
351
+        $phone          = sanitize_text_field($data['wpinv_phone']);
352
+        $address        = sanitize_text_field($data['wpinv_address']);
353
+        $city           = sanitize_text_field($data['wpinv_city']);
354
+        $zip            = sanitize_text_field($data['wpinv_zip']);
355
+        $country        = sanitize_text_field($data['wpinv_country']);
356
+        $state          = sanitize_text_field($data['wpinv_state']);
357 357
 
358 358
         // Details
359
-        $status         = sanitize_text_field( $data['wpinv_status'] );
360
-        $old_status     = !empty( $data['original_post_status'] ) ? sanitize_text_field( $data['original_post_status'] ) : $status;
361
-        $number         = sanitize_text_field( $data['wpinv_number'] );
362
-        $due_date       = isset( $data['wpinv_due_date'] ) ? sanitize_text_field( $data['wpinv_due_date'] ) : '';
359
+        $status         = sanitize_text_field($data['wpinv_status']);
360
+        $old_status     = !empty($data['original_post_status']) ? sanitize_text_field($data['original_post_status']) : $status;
361
+        $number         = sanitize_text_field($data['wpinv_number']);
362
+        $due_date       = isset($data['wpinv_due_date']) ? sanitize_text_field($data['wpinv_due_date']) : '';
363 363
         //$discounts      = sanitize_text_field( $data['wpinv_discounts'] );
364 364
         //$discount       = sanitize_text_field( $data['wpinv_discount'] );
365 365
 
366
-        $ip             = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
366
+        $ip = $invoice->get_ip() ? $invoice->get_ip() : wpinv_get_ip();
367 367
 
368
-        $invoice->set( 'due_date', $due_date );
369
-        $invoice->set( 'first_name', $first_name );
370
-        $invoice->set( 'last_name', $last_name );
371
-        $invoice->set( 'company', $company );
372
-        $invoice->set( 'vat_number', $vat_number );
373
-        $invoice->set( 'phone', $phone );
374
-        $invoice->set( 'address', $address );
375
-        $invoice->set( 'city', $city );
376
-        $invoice->set( 'zip', $zip );
377
-        $invoice->set( 'country', $country );
378
-        $invoice->set( 'state', $state );
379
-        $invoice->set( 'status', $status );
368
+        $invoice->set('due_date', $due_date);
369
+        $invoice->set('first_name', $first_name);
370
+        $invoice->set('last_name', $last_name);
371
+        $invoice->set('company', $company);
372
+        $invoice->set('vat_number', $vat_number);
373
+        $invoice->set('phone', $phone);
374
+        $invoice->set('address', $address);
375
+        $invoice->set('city', $city);
376
+        $invoice->set('zip', $zip);
377
+        $invoice->set('country', $country);
378
+        $invoice->set('state', $state);
379
+        $invoice->set('status', $status);
380 380
         //$invoice->set( 'number', $number );
381 381
         //$invoice->set( 'discounts', $discounts );
382 382
         //$invoice->set( 'discount', $discount );
383
-        $invoice->set( 'ip', $ip );
383
+        $invoice->set('ip', $ip);
384 384
         $invoice->old_status = $_POST['original_post_status'];
385 385
         $invoice->currency = wpinv_get_currency();
386
-        if ( !empty( $data['wpinv_gateway'] ) ) {
387
-            $invoice->set( 'gateway', sanitize_text_field( $data['wpinv_gateway'] ) );
386
+        if (!empty($data['wpinv_gateway'])) {
387
+            $invoice->set('gateway', sanitize_text_field($data['wpinv_gateway']));
388 388
         }
389 389
         $saved = $invoice->save();
390 390
 
391 391
         // Check for payment notes
392
-        if ( !empty( $data['invoice_note'] ) ) {
393
-            $note               = wp_kses( $data['invoice_note'], array() );
394
-            $note_type          = sanitize_text_field( $data['invoice_note_type'] );
392
+        if (!empty($data['invoice_note'])) {
393
+            $note               = wp_kses($data['invoice_note'], array());
394
+            $note_type          = sanitize_text_field($data['invoice_note_type']);
395 395
             $is_customer_note   = $note_type == 'customer' ? 1 : 0;
396 396
 
397
-            wpinv_insert_payment_note( $invoice->ID, $note, $is_customer_note );
397
+            wpinv_insert_payment_note($invoice->ID, $note, $is_customer_note);
398 398
         }
399 399
 
400 400
         // Update user address if empty.
401
-        if ( $saved && !empty( $invoice ) ) {
402
-            if ( $user_id = $invoice->get_user_id() ) {
403
-                $user_address = wpinv_get_user_address( $user_id, false );
401
+        if ($saved && !empty($invoice)) {
402
+            if ($user_id = $invoice->get_user_id()) {
403
+                $user_address = wpinv_get_user_address($user_id, false);
404 404
 
405 405
                 if (empty($user_address['first_name'])) {
406
-                    update_user_meta( $user_id, '_wpinv_first_name', $first_name );
407
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
406
+                    update_user_meta($user_id, '_wpinv_first_name', $first_name);
407
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
408 408
                 } else if (empty($user_address['last_name']) && $user_address['first_name'] == $first_name) {
409
-                    update_user_meta( $user_id, '_wpinv_last_name', $last_name );
409
+                    update_user_meta($user_id, '_wpinv_last_name', $last_name);
410 410
                 }
411 411
 
412 412
                 if (empty($user_address['address']) || empty($user_address['city']) || empty($user_address['state']) || empty($user_address['country'])) {
413
-                    update_user_meta( $user_id, '_wpinv_address', $address );
414
-                    update_user_meta( $user_id, '_wpinv_city', $city );
415
-                    update_user_meta( $user_id, '_wpinv_state', $state );
416
-                    update_user_meta( $user_id, '_wpinv_country', $country );
417
-                    update_user_meta( $user_id, '_wpinv_zip', $zip );
418
-                    update_user_meta( $user_id, '_wpinv_phone', $phone );
413
+                    update_user_meta($user_id, '_wpinv_address', $address);
414
+                    update_user_meta($user_id, '_wpinv_city', $city);
415
+                    update_user_meta($user_id, '_wpinv_state', $state);
416
+                    update_user_meta($user_id, '_wpinv_country', $country);
417
+                    update_user_meta($user_id, '_wpinv_zip', $zip);
418
+                    update_user_meta($user_id, '_wpinv_phone', $phone);
419 419
                 }
420 420
             }
421 421
 
422
-            do_action( 'wpinv_invoice_metabox_saved', $invoice );
422
+            do_action('wpinv_invoice_metabox_saved', $invoice);
423 423
         }
424 424
 
425 425
         return $saved;
Please login to merge, or discard this patch.
includes/admin/admin-meta-boxes.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -1,65 +1,65 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_add_meta_boxes( $post_type, $post ) {
7
+function wpinv_add_meta_boxes($post_type, $post) {
8 8
     global $wpi_mb_invoice;
9
-    if ( $post_type == 'wpi_invoice' && !empty( $post->ID ) ) {
10
-        $wpi_mb_invoice = wpinv_get_invoice( $post->ID );
9
+    if ($post_type == 'wpi_invoice' && !empty($post->ID)) {
10
+        $wpi_mb_invoice = wpinv_get_invoice($post->ID);
11 11
     }
12 12
     
13
-    if ( !empty( $wpi_mb_invoice ) && !$wpi_mb_invoice->has_status( array( 'draft', 'auto-draft' ) ) ) {
14
-        add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high' );
13
+    if (!empty($wpi_mb_invoice) && !$wpi_mb_invoice->has_status(array('draft', 'auto-draft'))) {
14
+        add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'WPInv_Meta_Box_Details::resend_invoice', 'wpi_invoice', 'side', 'high');
15 15
     }
16 16
     
17
-    if ( !empty( $wpi_mb_invoice ) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent() ) {
18
-        add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscriptions', 'invoicing' ), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high' );
17
+    if (!empty($wpi_mb_invoice) && $wpi_mb_invoice->is_recurring() && $wpi_mb_invoice->is_parent()) {
18
+        add_meta_box('wpinv-mb-subscriptions', __('Subscriptions', 'invoicing'), 'WPInv_Meta_Box_Details::subscriptions', 'wpi_invoice', 'side', 'high');
19 19
     }
20 20
     
21
-    if ( wpinv_is_subscription_payment( $wpi_mb_invoice ) ) {
22
-        add_meta_box( 'wpinv-mb-renewals', __( 'Renewal Payment', 'invoicing' ), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high' );
21
+    if (wpinv_is_subscription_payment($wpi_mb_invoice)) {
22
+        add_meta_box('wpinv-mb-renewals', __('Renewal Payment', 'invoicing'), 'WPInv_Meta_Box_Details::renewals', 'wpi_invoice', 'side', 'high');
23 23
     }
24 24
     
25
-    add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default' );
26
-    add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default' );
25
+    add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'WPInv_Meta_Box_Details::output', 'wpi_invoice', 'side', 'default');
26
+    add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'WPInv_Meta_Box_Details::payment_meta', 'wpi_invoice', 'side', 'default');
27 27
    
28
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
29
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
30
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
28
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
29
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
30
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
31 31
 }
32
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
32
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
33 33
 
34
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
35
-    remove_action( 'save_post', __FUNCTION__ );
34
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
35
+    remove_action('save_post', __FUNCTION__);
36 36
     
37 37
     // $post_id and $post are required
38
-    if ( empty( $post_id ) || empty( $post ) ) {
38
+    if (empty($post_id) || empty($post)) {
39 39
         return;
40 40
     }
41 41
         
42
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
42
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
43 43
         return;
44 44
     }
45 45
     
46 46
     // Dont' save meta boxes for revisions or autosaves
47
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
47
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
52
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
51
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
52
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
53 53
             return;
54 54
         }
55 55
     
56
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
57
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
56
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
57
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
58 58
         }
59
-    } else if ( $post->post_type == 'wpi_item' ) {
59
+    } else if ($post->post_type == 'wpi_item') {
60 60
         // verify nonce
61
-        if ( isset( $_POST['wpinv_vat_meta_box_nonce'] ) && wp_verify_nonce( $_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save' ) ) {
62
-            $fields                                 = array();
61
+        if (isset($_POST['wpinv_vat_meta_box_nonce']) && wp_verify_nonce($_POST['wpinv_vat_meta_box_nonce'], 'wpinv_item_meta_box_save')) {
62
+            $fields = array();
63 63
             $fields['_wpinv_price']              = 'wpinv_item_price';
64 64
             $fields['_wpinv_vat_class']          = 'wpinv_vat_class';
65 65
             $fields['_wpinv_vat_rule']           = 'wpinv_vat_rules';
@@ -72,92 +72,92 @@  discard block
 block discarded – undo
72 72
             $fields['_wpinv_trial_period']       = 'wpinv_trial_period';
73 73
             $fields['_wpinv_trial_interval']     = 'wpinv_trial_interval';
74 74
             
75
-            if ( !isset( $_POST['wpinv_is_recurring'] ) ) {
75
+            if (!isset($_POST['wpinv_is_recurring'])) {
76 76
                 $_POST['wpinv_is_recurring'] = 0;
77 77
             }
78 78
             
79
-            if ( !isset( $_POST['wpinv_free_trial'] ) || empty( $_POST['wpinv_is_recurring'] ) ) {
79
+            if (!isset($_POST['wpinv_free_trial']) || empty($_POST['wpinv_is_recurring'])) {
80 80
                 $_POST['wpinv_free_trial'] = 0;
81 81
             }
82 82
             
83
-            foreach ( $fields as $field => $name ) {
84
-                if ( isset( $_POST[ $name ] ) ) {
85
-                    $allowed = apply_filters( 'wpinv_item_allowed_save_meta_value', true, $field, $post_id );
83
+            foreach ($fields as $field => $name) {
84
+                if (isset($_POST[$name])) {
85
+                    $allowed = apply_filters('wpinv_item_allowed_save_meta_value', true, $field, $post_id);
86 86
 
87
-                    if ( !$allowed ) {
87
+                    if (!$allowed) {
88 88
                         continue;
89 89
                     }
90 90
 
91
-                    if ( $field == '_wpinv_price' ) {
92
-                        $value = wpinv_sanitize_amount( $_POST[ $name ] );
91
+                    if ($field == '_wpinv_price') {
92
+                        $value = wpinv_sanitize_amount($_POST[$name]);
93 93
                     } else {
94
-                        $value = is_string( $_POST[ $name ] ) ? sanitize_text_field( $_POST[ $name ] ) : $_POST[ $name ];
94
+                        $value = is_string($_POST[$name]) ? sanitize_text_field($_POST[$name]) : $_POST[$name];
95 95
                     }
96 96
                     
97
-                    $value = apply_filters( 'wpinv_item_metabox_save_' . $field, $value, $name );
98
-                    update_post_meta( $post_id, $field, $value );
97
+                    $value = apply_filters('wpinv_item_metabox_save_' . $field, $value, $name);
98
+                    update_post_meta($post_id, $field, $value);
99 99
                 }
100 100
             }
101 101
             
102
-            if ( !get_post_meta( $post_id, '_wpinv_custom_id', true ) ) {
103
-                update_post_meta( $post_id, '_wpinv_custom_id', $post_id );
102
+            if (!get_post_meta($post_id, '_wpinv_custom_id', true)) {
103
+                update_post_meta($post_id, '_wpinv_custom_id', $post_id);
104 104
             }
105 105
         }
106 106
     }
107 107
 }
108
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
108
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
109 109
 
110 110
 function wpinv_register_item_meta_boxes() {    
111 111
     global $wpinv_euvat;
112 112
     
113
-    add_meta_box( 'wpinv_field_prices', __( 'Item Price', 'invoicing' ), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high' );
113
+    add_meta_box('wpinv_field_prices', __('Item Price', 'invoicing'), 'WPInv_Meta_Box_Items::prices', 'wpi_item', 'normal', 'high');
114 114
 
115
-    if ( $wpinv_euvat->allow_vat_rules() ) {
116
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
115
+    if ($wpinv_euvat->allow_vat_rules()) {
116
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
117 117
     }
118 118
     
119
-    if ( $wpinv_euvat->allow_vat_classes() ) {
120
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
119
+    if ($wpinv_euvat->allow_vat_classes()) {
120
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
121 121
     }
122 122
     
123
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
124
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
123
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
124
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
125 125
 }
126 126
 
127 127
 function wpinv_register_discount_meta_boxes() {
128
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
128
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
129 129
 }
130 130
 
131
-function wpinv_discount_metabox_details( $post ) {
131
+function wpinv_discount_metabox_details($post) {
132 132
     $discount_id    = $post->ID;
133
-    $discount       = wpinv_get_discount( $discount_id );
133
+    $discount       = wpinv_get_discount($discount_id);
134 134
     
135
-    $type               = wpinv_get_discount_type( $discount_id );
136
-    $item_reqs          = wpinv_get_discount_item_reqs( $discount_id );
137
-    $excluded_items     = wpinv_get_discount_excluded_items( $discount_id );
138
-    $min_total          = wpinv_get_discount_min_total( $discount_id );
139
-    $max_total          = wpinv_get_discount_max_total( $discount_id );
140
-    $max_uses           = wpinv_get_discount_max_uses( $discount_id );
141
-    $single_use         = wpinv_discount_is_single_use( $discount_id );
142
-    $recurring          = (bool)wpinv_discount_is_recurring( $discount_id );
143
-    $start_date         = wpinv_get_discount_start_date( $discount_id );
144
-    $expiration_date    = wpinv_get_discount_expiration( $discount_id );
135
+    $type               = wpinv_get_discount_type($discount_id);
136
+    $item_reqs          = wpinv_get_discount_item_reqs($discount_id);
137
+    $excluded_items     = wpinv_get_discount_excluded_items($discount_id);
138
+    $min_total          = wpinv_get_discount_min_total($discount_id);
139
+    $max_total          = wpinv_get_discount_max_total($discount_id);
140
+    $max_uses           = wpinv_get_discount_max_uses($discount_id);
141
+    $single_use         = wpinv_discount_is_single_use($discount_id);
142
+    $recurring          = (bool)wpinv_discount_is_recurring($discount_id);
143
+    $start_date         = wpinv_get_discount_start_date($discount_id);
144
+    $expiration_date    = wpinv_get_discount_expiration($discount_id);
145 145
     
146
-    if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) {
147
-        $start_time         = strtotime( $start_date );
148
-        $start_h            = date_i18n( 'H', $start_time );
149
-        $start_m            = date_i18n( 'i', $start_time );
150
-        $start_date         = date_i18n( 'Y-m-d', $start_time );
146
+    if (!empty($start_date) && strpos($start_date, '0000') === false) {
147
+        $start_time         = strtotime($start_date);
148
+        $start_h            = date_i18n('H', $start_time);
149
+        $start_m            = date_i18n('i', $start_time);
150
+        $start_date         = date_i18n('Y-m-d', $start_time);
151 151
     } else {
152 152
         $start_h            = '00';
153 153
         $start_m            = '00';
154 154
     }
155 155
 
156
-    if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) {
157
-        $expiration_time    = strtotime( $expiration_date );
158
-        $expiration_h       = date_i18n( 'H', $expiration_time );
159
-        $expiration_m       = date_i18n( 'i', $expiration_time );
160
-        $expiration_date    = date_i18n( 'Y-m-d', $expiration_time );
156
+    if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) {
157
+        $expiration_time    = strtotime($expiration_date);
158
+        $expiration_h       = date_i18n('H', $expiration_time);
159
+        $expiration_m       = date_i18n('i', $expiration_time);
160
+        $expiration_date    = date_i18n('Y-m-d', $expiration_time);
161 161
     } else {
162 162
         $expiration_h       = '23';
163 163
         $expiration_m       = '59';
@@ -167,207 +167,207 @@  discard block
 block discarded – undo
167 167
     $max_total          = $max_total > 0 ? $max_total : '';
168 168
     $max_uses           = $max_uses > 0 ? $max_uses : '';
169 169
 ?>
170
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
171
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
170
+<?php do_action('wpinv_discount_form_top', $post); ?>
171
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
172 172
 <table class="form-table wpi-form-table">
173 173
     <tbody>
174
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
175
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
174
+        <?php do_action('wpinv_discount_form_first', $post); ?>
175
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
176 176
         <tr>
177 177
             <th valign="top" scope="row">
178
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
178
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
179 179
             </th>
180 180
             <td>
181
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
182
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
181
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
182
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
183 183
             </td>
184 184
         </tr>
185
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
185
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
186 186
         <tr>
187 187
             <th valign="top" scope="row">
188
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
188
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
189 189
             </th>
190 190
             <td>
191 191
                 <select id="wpinv_discount_type" name="type" class="medium-text">
192
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
193
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
192
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
193
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
194 194
                     <?php } ?>
195 195
                 </select>
196
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
196
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
197 197
             </td>
198 198
         </tr>
199
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
199
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
200 200
         <tr>
201 201
             <th valign="top" scope="row">
202
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
202
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
203 203
             </th>
204 204
             <td>
205
-                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr( wpinv_get_discount_amount( $discount_id ) ); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol() ;?></font>
206
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
207
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
205
+                <input type="text" name="amount" id="wpinv_discount_amount" class="wpi-field-price wpi-price" value="<?php echo esc_attr(wpinv_get_discount_amount($discount_id)); ?>" required> <font class="wpi-discount-p">%</font><font class="wpi-discount-f" style="display:none;"><?php echo wpinv_currency_symbol(); ?></font>
206
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
207
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
208 208
             </td>
209 209
         </tr>
210
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
210
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
211 211
         <tr>
212 212
             <th valign="top" scope="row">
213
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
213
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
214 214
             </th>
215 215
             <td>
216
-                <p><?php echo wpinv_item_dropdown( array(
216
+                <p><?php echo wpinv_item_dropdown(array(
217 217
                         'name'              => 'items[]',
218 218
                         'id'                => 'items',
219 219
                         'selected'          => $item_reqs,
220 220
                         'multiple'          => true,
221 221
                         'class'             => 'medium-text',
222
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
222
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
223 223
                         'show_recurring'    => true,
224
-                    ) ); ?>
224
+                    )); ?>
225 225
                 </p>
226
-                <p class="description"><?php _e( 'Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing' ); ?></p>
226
+                <p class="description"><?php _e('Items which need to be in the cart to use this discount or, for "Item Discounts", which items are discounted. If left blank, this discount can be used on any item.', 'invoicing'); ?></p>
227 227
             </td>
228 228
         </tr>
229
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
229
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
230 230
         <tr>
231 231
             <th valign="top" scope="row">
232
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
232
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
233 233
             </th>
234 234
             <td>
235
-                <p><?php echo wpinv_item_dropdown( array(
235
+                <p><?php echo wpinv_item_dropdown(array(
236 236
                         'name'              => 'excluded_items[]',
237 237
                         'id'                => 'excluded_items',
238 238
                         'selected'          => $excluded_items,
239 239
                         'multiple'          => true,
240 240
                         'class'             => 'medium-text',
241
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
241
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
242 242
                         'show_recurring'    => true,
243
-                    ) ); ?>
243
+                    )); ?>
244 244
                 </p>
245
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
245
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
246 246
             </td>
247 247
         </tr>
248
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
248
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
249 249
         <tr>
250 250
             <th valign="top" scope="row">
251
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
251
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
252 252
             </th>
253 253
             <td>
254
-                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr( $start_date ); ?>"> @ <select id="wpinv_discount_start_h" name="start_h">
255
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
256
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option>
254
+                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_start" data-dateFormat="yy-mm-dd" name="start" value="<?php echo esc_attr($start_date); ?>"> @ <select id="wpinv_discount_start_h" name="start_h">
255
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
256
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option>
257 257
                     <?php } ?>
258 258
                 </select> : <select id="wpinv_discount_start_m" name="start_m">
259
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
260
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option>
259
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
260
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option>
261 261
                     <?php } ?>
262 262
                 </select>
263
-                <p class="description"><?php _e( 'Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?></p>
263
+                <p class="description"><?php _e('Enter the start date for this discount code in the format of yyyy-mm-dd. For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?></p>
264 264
             </td>
265 265
         </tr>
266
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
266
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
267 267
         <tr>
268 268
             <th valign="top" scope="row">
269
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
269
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
270 270
             </th>
271 271
             <td>
272
-                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr( $expiration_date ); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h">
273
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
274
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option>
272
+                <input type="text" class="w120 wpiDatepicker" id="wpinv_discount_expiration" data-dateFormat="yy-mm-dd" name="expiration" value="<?php echo esc_attr($expiration_date); ?>"> @ <select id="wpinv_discount_expiration_h" name="expiration_h">
273
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
274
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option>
275 275
                     <?php } ?>
276 276
                 </select> : <select id="wpinv_discount_expiration_m" name="expiration_m">
277
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
278
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option>
277
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
278
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option>
279 279
                     <?php } ?>
280 280
                 </select>
281
-                <p class="description"><?php _e( 'Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing' ); ?></p>
281
+                <p class="description"><?php _e('Enter the expiration date for this discount code in the format of yyyy-mm-dd. Leave blank for no expiration.', 'invoicing'); ?></p>
282 282
             </td>
283 283
         </tr>
284
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
284
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
285 285
         <tr>
286 286
             <th valign="top" scope="row">
287
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
287
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
288 288
             </th>
289 289
             <td>
290 290
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
291
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
291
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
292 292
             </td>
293 293
         </tr>
294
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
294
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
295 295
         <tr>
296 296
             <th valign="top" scope="row">
297
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
297
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
298 298
             </th>
299 299
             <td>
300 300
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
301
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
301
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
302 302
             </td>
303 303
         </tr>
304
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
304
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
305 305
         <tr>
306 306
             <th valign="top" scope="row">
307
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
307
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
308 308
             </th>
309 309
             <td>
310 310
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text">
311
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
312
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
311
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
312
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
313 313
                 </select>
314
-                <p class="description"><?php _e( '<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing' ); ?></p>
314
+                <p class="description"><?php _e('<b>All payments:</b> Apply this discount to all recurring payments of the recurring invoice. <br><b>First payment only:</b> Apply this discount to only first payment of the recurring invoice.', 'invoicing'); ?></p>
315 315
             </td>
316 316
         </tr>
317
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
317
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
318 318
         <tr>
319 319
             <th valign="top" scope="row">
320
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
320
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
321 321
             </th>
322 322
             <td>
323 323
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
324
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
324
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
325 325
             </td>
326 326
         </tr>
327
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
327
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
328 328
         <tr>
329 329
             <th valign="top" scope="row">
330
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
330
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
331 331
             </th>
332 332
             <td>
333
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
334
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
333
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
334
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
335 335
             </td>
336 336
         </tr>
337
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
337
+        <?php do_action('wpinv_discount_form_last', $post); ?>
338 338
     </tbody>
339 339
 </table>
340
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
340
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
341 341
     <?php
342 342
 }
343 343
 
344
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
345
-    $post_type = !empty( $post ) ? $post->post_type : '';
344
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
345
+    $post_type = !empty($post) ? $post->post_type : '';
346 346
     
347
-    if ( $post_type != 'wpi_discount' ) {
347
+    if ($post_type != 'wpi_discount') {
348 348
         return;
349 349
     }
350 350
     
351
-    if ( !isset( $_POST['wpinv_discount_metabox_nonce'] ) || ( isset( $_POST['wpinv_discount_metabox_nonce'] ) && !wp_verify_nonce( $_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce' ) ) ) {
351
+    if (!isset($_POST['wpinv_discount_metabox_nonce']) || (isset($_POST['wpinv_discount_metabox_nonce']) && !wp_verify_nonce($_POST['wpinv_discount_metabox_nonce'], 'wpinv_discount_metabox_nonce'))) {
352 352
         return;
353 353
     }
354 354
     
355
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
355
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
356 356
         return;
357 357
     }
358 358
     
359
-    if ( !current_user_can( 'manage_options', $post_id ) ) {
359
+    if (!current_user_can('manage_options', $post_id)) {
360 360
         return;
361 361
     }
362 362
     
363
-    if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) {
363
+    if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') {
364 364
         $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m'];
365 365
     }
366 366
 
367
-    if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) {
367
+    if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) {
368 368
         $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m'];
369 369
     }
370 370
     
371
-    return wpinv_store_discount( $post_id, $_POST, $post, $update );
371
+    return wpinv_store_discount($post_id, $_POST, $post, $update);
372 372
 }
373
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
374 373
\ No newline at end of file
374
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
375 375
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-bp-core.php 1 patch
Spacing   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -11,60 +11,60 @@  discard block
 block discarded – undo
11 11
     public function __construct() {
12 12
         global $bp;
13 13
         
14
-        if ( !defined( 'WPINV_BP_SLUG' ) ) {
15
-            define( 'WPINV_BP_SLUG', 'invoices' );
14
+        if (!defined('WPINV_BP_SLUG')) {
15
+            define('WPINV_BP_SLUG', 'invoices');
16 16
         }
17 17
         
18
-        $position       = wpinv_get_option( 'wpinv_menu_position' );
18
+        $position       = wpinv_get_option('wpinv_menu_position');
19 19
         $position       = $position !== '' && $position !== false ? $position : 91;
20
-        $this->position = apply_filters( 'wpinv_bp_nav_position', $position );
20
+        $this->position = apply_filters('wpinv_bp_nav_position', $position);
21 21
         $this->slug     = WPINV_BP_SLUG;
22 22
         
23 23
         parent::start(
24 24
             'invoicing',
25
-            _x( 'Invoices', 'Invoices screen page <title>', 'invoicing' ),
26
-            trailingslashit( dirname( __FILE__ ) ),
25
+            _x('Invoices', 'Invoices screen page <title>', 'invoicing'),
26
+            trailingslashit(dirname(__FILE__)),
27 27
             array(
28 28
                 'adminbar_myaccount_order' => $this->position
29 29
             )
30 30
         );
31 31
     }
32 32
     
33
-    public function includes( $includes = array() ) {
34
-        parent::includes( $includes );
33
+    public function includes($includes = array()) {
34
+        parent::includes($includes);
35 35
     }
36 36
     
37
-    public function setup_globals( $args = array() ) {
37
+    public function setup_globals($args = array()) {
38 38
         global $bp;
39 39
 
40 40
         $args = array(
41 41
             'slug' => $this->slug,
42 42
         );
43 43
 
44
-        parent::setup_globals( $args );
44
+        parent::setup_globals($args);
45 45
     }
46 46
     
47
-    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
48
-        if ( !bp_is_my_profile() ) {
47
+    public function setup_nav($main_nav = array(), $sub_nav = array()) {
48
+        if (!bp_is_my_profile()) {
49 49
             return;
50 50
         }
51 51
         
52
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) {
52
+        if (wpinv_get_option('wpinv_bp_hide_menu')) {
53 53
             return;
54 54
         }
55 55
         
56 56
         $this->setup_invoice_count();
57 57
 
58 58
         $user_domain    = bp_loggedin_user_domain();
59
-        $invoices_link  = trailingslashit( $user_domain . $this->slug );
60
-        $class          = ( 0 === $this->count ) ? 'no-count' : 'count';
59
+        $invoices_link  = trailingslashit($user_domain . $this->slug);
60
+        $class          = (0 === $this->count) ? 'no-count' : 'count';
61 61
 
62 62
         $main_nav_name = sprintf(
63
-            __( 'My Invoices %s', 'invoicing' ),
63
+            __('My Invoices %s', 'invoicing'),
64 64
             sprintf(
65 65
                 '<span class="%s">%s</span>',
66
-                esc_attr( $class ),
67
-                bp_core_number_format( $this->count )
66
+                esc_attr($class),
67
+                bp_core_number_format($this->count)
68 68
             )
69 69
         );
70 70
 
@@ -72,54 +72,54 @@  discard block
 block discarded – undo
72 72
             'name'                => $main_nav_name,
73 73
             'slug'                => $this->slug,
74 74
             'position'            => $this->position,
75
-            'screen_function'     => array( $this, 'invoices_screen' ),
75
+            'screen_function'     => array($this, 'invoices_screen'),
76 76
             'default_subnav_slug' => 'invoices',
77 77
             'item_css_id'         => $this->id
78 78
         );
79 79
         
80 80
         $sub_nav[] = array(
81
-            'name'            => _x( 'My Invoices', 'Invoices screen sub nav', 'invoicing' ),
81
+            'name'            => _x('My Invoices', 'Invoices screen sub nav', 'invoicing'),
82 82
             'slug'            => 'invoices',
83 83
             'parent_url'      => $invoices_link,
84 84
             'parent_slug'     => $this->slug,
85
-            'screen_function' => array( $this, 'invoices_screen' ),
85
+            'screen_function' => array($this, 'invoices_screen'),
86 86
             'position'        => 10,
87 87
             'item_css_id'     => 'invoices-my-invoices'
88 88
         );
89 89
 
90
-        parent::setup_nav( $main_nav, $sub_nav );
90
+        parent::setup_nav($main_nav, $sub_nav);
91 91
     }
92 92
     
93 93
     public function setup_title() {
94 94
         // Adjust title.
95
-        if ( (bool)bp_is_current_component( 'invoicing' ) ) {
95
+        if ((bool)bp_is_current_component('invoicing')) {
96 96
             global $bp;
97 97
             
98
-            $bp->bp_options_title = __( 'My Invoices', 'invoicing' );
98
+            $bp->bp_options_title = __('My Invoices', 'invoicing');
99 99
         }
100 100
 
101 101
         parent::setup_title();
102 102
     }
103 103
     
104 104
     public function invoices_screen() {
105
-        if ( wpinv_get_option( 'wpinv_bp_hide_menu' ) ) {
105
+        if (wpinv_get_option('wpinv_bp_hide_menu')) {
106 106
             return;
107 107
         }
108 108
         
109 109
         global $bp;
110 110
         
111
-        add_action( 'bp_template_content', array( $this, 'invoices_content' ) );
111
+        add_action('bp_template_content', array($this, 'invoices_content'));
112 112
 
113
-        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
113
+        $template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
114 114
         
115
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
115
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
116 116
     }
117 117
     
118 118
     public function invoices_content() {
119
-        if ( $this->has_invoices( bp_ajax_querystring( 'invoices' ) ) ) {
119
+        if ($this->has_invoices(bp_ajax_querystring('invoices'))) {
120 120
             global $invoices_template;
121 121
             
122
-            do_action( 'wpinv_bp_invoices_before_content' );
122
+            do_action('wpinv_bp_invoices_before_content');
123 123
             ?>
124 124
             <div class="wpi-bp-invoices invoices invoicing" style="position:relative">
125 125
                 <div id="pag-top" class="pagination">
@@ -133,61 +133,61 @@  discard block
 block discarded – undo
133 133
                 <table class="table table-bordered table-hover wpi-user-invoices" style="margin:0">
134 134
                     <thead>
135 135
                         <tr>
136
-                            <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
137
-                                <th class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>"><span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span></th>
136
+                            <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
137
+                                <th class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>"><span class="nobr"><?php echo esc_html($column_name['title']); ?></span></th>
138 138
                             <?php endforeach; ?>
139 139
                         </tr>
140 140
                     </thead>
141 141
                     <tbody>
142
-                        <?php foreach ( $invoices_template->invoices as $invoice ) {
142
+                        <?php foreach ($invoices_template->invoices as $invoice) {
143 143
                             ?>
144 144
                             <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>">
145
-                                <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?>
146
-                                    <td class="<?php echo esc_attr( $column_id ); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : '');?>" data-title="<?php echo esc_attr( $column_name['title'] ); ?>">
147
-                                        <?php if ( has_action( 'wpinv_user_invoices_column_' . $column_id ) ) : ?>
148
-                                            <?php do_action( 'wpinv_user_invoices_column_' . $column_id, $invoice ); ?>
149
-
150
-                                        <?php elseif ( 'invoice-number' === $column_id ) : ?>
151
-                                            <a href="<?php echo esc_url( $invoice->get_view_url() ); ?>">
152
-                                                <?php echo _x( '#', 'hash before invoice number', 'invoicing' ) . $invoice->get_number(); ?>
145
+                                <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?>
146
+                                    <td class="<?php echo esc_attr($column_id); ?> <?php echo (!empty($column_name['class']) ? $column_name['class'] : ''); ?>" data-title="<?php echo esc_attr($column_name['title']); ?>">
147
+                                        <?php if (has_action('wpinv_user_invoices_column_' . $column_id)) : ?>
148
+                                            <?php do_action('wpinv_user_invoices_column_' . $column_id, $invoice); ?>
149
+
150
+                                        <?php elseif ('invoice-number' === $column_id) : ?>
151
+                                            <a href="<?php echo esc_url($invoice->get_view_url()); ?>">
152
+                                                <?php echo _x('#', 'hash before invoice number', 'invoicing') . $invoice->get_number(); ?>
153 153
                                             </a>
154 154
 
155
-                                        <?php elseif ( 'created-date' === $column_id ) : $date = wpinv_get_date_created( $invoice->ID ); $dateYMD = wpinv_get_date_created( $invoice->ID, 'Y-m-d H:i:s' ); ?>
156
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
155
+                                        <?php elseif ('created-date' === $column_id) : $date = wpinv_get_date_created($invoice->ID); $dateYMD = wpinv_get_date_created($invoice->ID, 'Y-m-d H:i:s'); ?>
156
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
157 157
 
158
-                                        <?php elseif ( 'payment-date' === $column_id ) : $date = wpinv_get_invoice_date( $invoice->ID, '', false ); $dateYMD = wpinv_get_invoice_date( $invoice->ID, 'Y-m-d H:i:s', false ); ?>
159
-                                            <time datetime="<?php echo strtotime( $dateYMD ); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
158
+                                        <?php elseif ('payment-date' === $column_id) : $date = wpinv_get_invoice_date($invoice->ID, '', false); $dateYMD = wpinv_get_invoice_date($invoice->ID, 'Y-m-d H:i:s', false); ?>
159
+                                            <time datetime="<?php echo strtotime($dateYMD); ?>" title="<?php echo $dateYMD; ?>"><?php echo $date; ?></time>
160 160
 
161
-                                        <?php elseif ( 'invoice-status' === $column_id ) : ?>
162
-                                            <?php echo wpinv_invoice_status_label( $invoice_status, $invoice->get_status( true ) ) ; ?>
161
+                                        <?php elseif ('invoice-status' === $column_id) : ?>
162
+                                            <?php echo wpinv_invoice_status_label($invoice_status, $invoice->get_status(true)); ?>
163 163
 
164
-                                        <?php elseif ( 'invoice-total' === $column_id ) : ?>
165
-                                            <?php echo $invoice->get_total( true ); ?>
164
+                                        <?php elseif ('invoice-total' === $column_id) : ?>
165
+                                            <?php echo $invoice->get_total(true); ?>
166 166
 
167
-                                        <?php elseif ( 'invoice-actions' === $column_id ) : ?>
167
+                                        <?php elseif ('invoice-actions' === $column_id) : ?>
168 168
                                             <?php
169 169
                                                 $actions = array(
170 170
                                                     'pay'    => array(
171 171
                                                         'url'  => $invoice->get_checkout_payment_url(),
172
-                                                        'name' => __( 'Pay Now', 'invoicing' ),
172
+                                                        'name' => __('Pay Now', 'invoicing'),
173 173
                                                         'class' => 'btn-success'
174 174
                                                     ),
175 175
                                                     'print'   => array(
176 176
                                                         'url'  => $invoice->get_view_url(),
177
-                                                        'name' => __( 'Print', 'invoicing' ),
177
+                                                        'name' => __('Print', 'invoicing'),
178 178
                                                         'class' => 'btn-primary',
179 179
                                                         'attrs' => 'target="_blank"'
180 180
                                                     )
181 181
                                                 );
182 182
 
183
-                                                if ( ! $invoice->needs_payment() ) {
184
-                                                    unset( $actions['pay'] );
183
+                                                if (!$invoice->needs_payment()) {
184
+                                                    unset($actions['pay']);
185 185
                                                 }
186 186
 
187
-                                                if ( $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ) ) {
188
-                                                    foreach ( $actions as $key => $action ) {
187
+                                                if ($actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice)) {
188
+                                                    foreach ($actions as $key => $action) {
189 189
                                                         $class = !empty($action['class']) ? sanitize_html_class($action['class']) : '';
190
-                                                        echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>';
190
+                                                        echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>';
191 191
                                                     }
192 192
                                                 }
193 193
                                             ?>
@@ -215,64 +215,64 @@  discard block
 block discarded – undo
215 215
             </div>
216 216
             <?php
217 217
         
218
-            do_action( 'wpinv_bp_invoices_after_content' );
218
+            do_action('wpinv_bp_invoices_after_content');
219 219
         } else {
220 220
             ?>
221 221
             <div id="message" class="info">
222
-                <p><?php _e( 'No invoice has been made yet.', 'invoicing' ); ?></p>
222
+                <p><?php _e('No invoice has been made yet.', 'invoicing'); ?></p>
223 223
             </div>
224 224
             <?php
225 225
         }
226 226
         
227
-        if ( defined( 'DOING_AJAX' ) ) {
227
+        if (defined('DOING_AJAX')) {
228 228
             exit;
229 229
         }
230 230
     }
231 231
     
232
-    public function has_invoices( $args = '' ) {
232
+    public function has_invoices($args = '') {
233 233
         global $invoices_template;
234 234
 
235
-        $per_page = absint( wpinv_get_option( 'wpinv_bp_per_page' ) );
235
+        $per_page = absint(wpinv_get_option('wpinv_bp_per_page'));
236 236
         // Parse arguments.
237
-        $r = bp_parse_args( $args, array(
237
+        $r = bp_parse_args($args, array(
238 238
             'status'            => 'all',
239 239
             'page_arg'          => 'bpage',
240 240
             'page'              => 1,
241 241
             'per_page'          => $per_page > 0 ? $per_page : 20,
242 242
             'max'               => false,
243 243
             'user_id'           => bp_loggedin_user_id(),
244
-        ), 'has_invoices' );
244
+        ), 'has_invoices');
245 245
 
246 246
 
247
-        if ( ! empty( $r['max'] ) && ( (int)$r['per_page'] > (int)$r['max'] ) ) {
247
+        if (!empty($r['max']) && ((int)$r['per_page'] > (int)$r['max'])) {
248 248
             $r['per_page'] = (int)$r['max'];
249 249
         }
250 250
 
251 251
         // Get the invoices.
252
-        $invoices_template = new WPInv_BP_Invoices_Template( $r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg'] );
252
+        $invoices_template = new WPInv_BP_Invoices_Template($r['status'], $r['page'], $r['per_page'], $r['max'], $r['user_id'], $r['page_arg']);
253 253
 
254
-        return apply_filters( 'wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r );
254
+        return apply_filters('wpinv_bp_has_invoices', $invoices_template->has_invoices(), $invoices_template, $r);
255 255
     }
256 256
     
257 257
     public function setup_invoice_count() {
258
-        $query      = apply_filters( 'wpinv_user_invoices_count_query', array( 'user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false ) );
259
-        $invoices   = wpinv_get_invoices( $query );
258
+        $query      = apply_filters('wpinv_user_invoices_count_query', array('user' => bp_loggedin_user_id(), 'limit' => '-1', 'return' => 'ids', 'paginate' => false));
259
+        $invoices   = wpinv_get_invoices($query);
260 260
         
261
-        $this->count = !empty( $invoices ) ? count( $invoices ) : 0;
261
+        $this->count = !empty($invoices) ? count($invoices) : 0;
262 262
     }
263 263
     
264 264
     public function pagination_count() {
265 265
         global $invoices_template;
266 266
 
267
-        $start_num = intval( ( $invoices_template->pag_page - 1 ) * $invoices_template->pag_num ) + 1;
268
-        $from_num  = bp_core_number_format( $start_num );
269
-        $to_num    = bp_core_number_format( ( $start_num + ( $invoices_template->pag_num - 1 ) > $invoices_template->total_invoice_count ) ? $invoices_template->total_invoice_count : $start_num + ( $invoices_template->pag_num - 1 ) );
270
-        $total     = bp_core_number_format( $invoices_template->total_invoice_count );
267
+        $start_num = intval(($invoices_template->pag_page - 1) * $invoices_template->pag_num) + 1;
268
+        $from_num  = bp_core_number_format($start_num);
269
+        $to_num    = bp_core_number_format(($start_num + ($invoices_template->pag_num - 1) > $invoices_template->total_invoice_count) ? $invoices_template->total_invoice_count : $start_num + ($invoices_template->pag_num - 1));
270
+        $total     = bp_core_number_format($invoices_template->total_invoice_count);
271 271
 
272
-        if ( 1 == $invoices_template->total_invoice_count ) {
273
-            $message = __( 'Viewing 1 invoice', 'invoicing' );
272
+        if (1 == $invoices_template->total_invoice_count) {
273
+            $message = __('Viewing 1 invoice', 'invoicing');
274 274
         } else {
275
-            $message = sprintf( _n( 'Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing' ), $from_num, $to_num, $total );
275
+            $message = sprintf(_n('Viewing %1$s - %2$s of %3$s invoice', 'Viewing %1$s - %2$s of %3$s invoices', $invoices_template->total_invoice_count, 'invoicing'), $from_num, $to_num, $total);
276 276
         }
277 277
 
278 278
         return $message;
@@ -281,32 +281,32 @@  discard block
 block discarded – undo
281 281
     function pagination_links() {
282 282
         global $invoices_template;
283 283
 
284
-        return apply_filters( 'wpinv_bp_get_pagination_links', $invoices_template->pag_links );
284
+        return apply_filters('wpinv_bp_get_pagination_links', $invoices_template->pag_links);
285 285
     }
286 286
     
287
-    public function bp_section( $settings = array() ) {
288
-        $settings['wpinv_bp'] = __( 'BuddyPress Integration', 'invoicing' );
287
+    public function bp_section($settings = array()) {
288
+        $settings['wpinv_bp'] = __('BuddyPress Integration', 'invoicing');
289 289
         return $settings;
290 290
     }
291 291
     
292
-    public function bp_settings( $settings = array() ) {
292
+    public function bp_settings($settings = array()) {
293 293
         $settings['wpinv_bp'] = array(
294 294
             'wpinv_bp_labels' => array(
295 295
                 'id'   => 'wpinv_bp_settings',
296
-                'name' => '<h3>' . __( 'BuddyPress Integration', 'invoicing' ) . '</h3>',
296
+                'name' => '<h3>' . __('BuddyPress Integration', 'invoicing') . '</h3>',
297 297
                 'desc' => '',
298 298
                 'type' => 'header',
299 299
             ),
300 300
             'wpinv_bp_hide_menu' => array(
301 301
                 'id'   => 'wpinv_bp_hide_menu',
302
-                'name' => __( 'Hide Invoices link', 'invoicing' ),
303
-                'desc' => __( 'Hide Invoices link from BP Profile menu.', 'invoicing' ),
302
+                'name' => __('Hide Invoices link', 'invoicing'),
303
+                'desc' => __('Hide Invoices link from BP Profile menu.', 'invoicing'),
304 304
                 'type' => 'checkbox',
305 305
             ),
306 306
             'wpinv_menu_position' => array(
307 307
                 'id'   => 'wpinv_menu_position',
308
-                'name' => __( 'Menu position', 'invoicing' ),
309
-                'desc' => __( 'Menu position for the Invoices link in BP Profile menu.', 'invoicing' ),
308
+                'name' => __('Menu position', 'invoicing'),
309
+                'desc' => __('Menu position for the Invoices link in BP Profile menu.', 'invoicing'),
310 310
                 'type' => 'number',
311 311
                 'size' => 'small',
312 312
                 'min'  => '1',
@@ -316,8 +316,8 @@  discard block
 block discarded – undo
316 316
             ),
317 317
             'wpinv_bp_per_page' => array(
318 318
                 'id'   => 'wpinv_bp_per_page',
319
-                'name' => __( 'Max invoices per page', 'invoicing' ),
320
-                'desc' => __( 'Enter a number to lists the invoices for each page.', 'invoicing' ),
319
+                'name' => __('Max invoices per page', 'invoicing'),
320
+                'desc' => __('Enter a number to lists the invoices for each page.', 'invoicing'),
321 321
                 'type' => 'number',
322 322
                 'size' => 'small',
323 323
                 'min'  => '1',
@@ -342,25 +342,25 @@  discard block
 block discarded – undo
342 342
     public $pag_links = '';
343 343
     public $total_invoice_count = 0;
344 344
     
345
-    public function __construct( $status, $page, $per_page, $max, $user_id, $page_arg = 'bpage' ) {
346
-        $this->invoices = array( 'invoices' => array(), 'total' => 0 );
345
+    public function __construct($status, $page, $per_page, $max, $user_id, $page_arg = 'bpage') {
346
+        $this->invoices = array('invoices' => array(), 'total' => 0);
347 347
         
348
-        $this->pag_arg  = sanitize_key( $page_arg );
349
-        $this->pag_page = bp_sanitize_pagination_arg( $this->pag_arg, $page );
350
-        $this->pag_num  = bp_sanitize_pagination_arg( 'num', $per_page );
348
+        $this->pag_arg  = sanitize_key($page_arg);
349
+        $this->pag_page = bp_sanitize_pagination_arg($this->pag_arg, $page);
350
+        $this->pag_num  = bp_sanitize_pagination_arg('num', $per_page);
351 351
 
352
-        $query_args     = array( 'user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true );
353
-        if ( !empty( $status ) && $status != 'all' ) {
352
+        $query_args     = array('user' => $user_id, 'page' => $this->pag_page, 'limit' => $this->pag_num, 'return' => 'self', 'paginate' => true);
353
+        if (!empty($status) && $status != 'all') {
354 354
            $query_args['status'] = $status;
355 355
         }
356
-        $invoices  = wpinv_get_invoices( apply_filters( 'wpinv_bp_user_invoices_query', $query_args ) );
356
+        $invoices = wpinv_get_invoices(apply_filters('wpinv_bp_user_invoices_query', $query_args));
357 357
         
358
-        if ( !empty( $invoices ) && !empty( $invoices->found_posts ) ) {
359
-            $this->invoices['invoices'] = array_map( 'wpinv_get_invoice', $invoices->posts );
358
+        if (!empty($invoices) && !empty($invoices->found_posts)) {
359
+            $this->invoices['invoices'] = array_map('wpinv_get_invoice', $invoices->posts);
360 360
             $this->invoices['total']    = $invoices->found_posts;
361 361
         }
362 362
 
363
-        if ( empty( $max ) || ( $max >= (int)$this->invoices['total'] ) ) {
363
+        if (empty($max) || ($max >= (int)$this->invoices['total'])) {
364 364
             $this->total_invoice_count = (int)$this->invoices['total'];
365 365
         } else {
366 366
             $this->total_invoice_count = (int)$max;
@@ -368,52 +368,52 @@  discard block
 block discarded – undo
368 368
 
369 369
         $this->invoices = $this->invoices['invoices'];
370 370
 
371
-        $invoice_count = count( $this->invoices );
371
+        $invoice_count = count($this->invoices);
372 372
 
373
-        if ( empty( $max ) || ( $max >= (int)$invoice_count ) ) {
373
+        if (empty($max) || ($max >= (int)$invoice_count)) {
374 374
             $this->invoice_count = (int)$invoice_count;
375 375
         } else {
376 376
             $this->invoice_count = (int)$max;
377 377
         }
378 378
         
379
-        if ( ! empty( $this->total_invoice_count ) && ! empty( $this->pag_num ) ) {
380
-            $this->pag_links = paginate_links( array(
381
-                'base'      => add_query_arg( $this->pag_arg, '%#%' ),
379
+        if (!empty($this->total_invoice_count) && !empty($this->pag_num)) {
380
+            $this->pag_links = paginate_links(array(
381
+                'base'      => add_query_arg($this->pag_arg, '%#%'),
382 382
                 'format'    => '',
383
-                'total'     => ceil( (int)$this->total_invoice_count / (int)$this->pag_num ),
383
+                'total'     => ceil((int)$this->total_invoice_count / (int)$this->pag_num),
384 384
                 'current'   => (int)$this->pag_page,
385
-                'prev_text' => _x( '&larr;', 'Invoice pagination previous text', 'invoicing' ),
386
-                'next_text' => _x( '&rarr;', 'Invoice pagination next text',     'invoicing' ),
385
+                'prev_text' => _x('&larr;', 'Invoice pagination previous text', 'invoicing'),
386
+                'next_text' => _x('&rarr;', 'Invoice pagination next text', 'invoicing'),
387 387
                 'mid_size'  => 1,
388 388
                 'add_args'  => array(),
389
-            ) );
389
+            ));
390 390
         }
391 391
     }
392 392
 
393 393
     public function has_invoices() {
394
-        return (bool) ! empty( $this->invoice_count );
394
+        return (bool)!empty($this->invoice_count);
395 395
     }
396 396
 
397 397
     public function next_invoice() {
398 398
         $this->current_invoice++;
399
-        $this->invoice = $this->invoices[ $this->current_invoice ];
399
+        $this->invoice = $this->invoices[$this->current_invoice];
400 400
 
401 401
         return $this->invoice;
402 402
     }
403 403
 
404 404
     public function rewind_invoices() {
405 405
         $this->current_invoice = -1;
406
-        if ( $this->invoice_count > 0 ) {
406
+        if ($this->invoice_count > 0) {
407 407
             $this->invoice = $this->invoices[0];
408 408
         }
409 409
     }
410 410
 
411 411
     public function invoices() {
412
-        if ( ( $this->current_invoice + 1 ) < $this->invoice_count ) {
412
+        if (($this->current_invoice + 1) < $this->invoice_count) {
413 413
             return true;
414
-        } elseif ( ( $this->current_invoice + 1 ) === $this->invoice_count ) {
414
+        } elseif (($this->current_invoice + 1) === $this->invoice_count) {
415 415
 
416
-            do_action( 'wpinv_bp_invoice_loop_end' );
416
+            do_action('wpinv_bp_invoice_loop_end');
417 417
             
418 418
             $this->rewind_invoices();
419 419
         }
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
         $this->in_the_loop = true;
428 428
         $this->invoice     = $this->next_invoice();
429 429
 
430
-        if ( 0 === $this->current_invoice ) {
431
-            do_action( 'wpinv_bp_invoice_loop_start' );
430
+        if (0 === $this->current_invoice) {
431
+            do_action('wpinv_bp_invoice_loop_start');
432 432
         }
433 433
     }
434 434
 }
@@ -438,9 +438,9 @@  discard block
 block discarded – undo
438 438
 
439 439
     $bp->invoicing = new WPInv_BP_Component();
440 440
     
441
-    add_action( 'wp_ajax_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) );
442
-    add_action( 'wp_ajax_nopriv_invoicing_filter', array( $bp->invoicing, 'invoices_content' ) );
443
-    add_filter( 'wpinv_settings_sections_general', array( $bp->invoicing, 'bp_section' ), 10, 1 );
444
-    add_filter( 'wpinv_settings_general', array( $bp->invoicing, 'bp_settings' ), 10, 1 );
441
+    add_action('wp_ajax_invoicing_filter', array($bp->invoicing, 'invoices_content'));
442
+    add_action('wp_ajax_nopriv_invoicing_filter', array($bp->invoicing, 'invoices_content'));
443
+    add_filter('wpinv_settings_sections_general', array($bp->invoicing, 'bp_section'), 10, 1);
444
+    add_filter('wpinv_settings_general', array($bp->invoicing, 'bp_settings'), 10, 1);
445 445
 }
446
-add_action( 'bp_loaded', 'wpinv_bp_setup_component' );
447 446
\ No newline at end of file
447
+add_action('bp_loaded', 'wpinv_bp_setup_component');
448 448
\ No newline at end of file
Please login to merge, or discard this patch.