Passed
Pull Request — master (#371)
by Brian
101:52
created
includes/admin/admin-meta-boxes.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@
 block discarded – undo
36 36
         add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
37 37
     }
38 38
 
39
-	remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
39
+    remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
40 40
 }
41 41
 add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
42 42
 
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -1,129 +1,129 @@  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-payment-form-design', __( 'Payment Form', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
29
-    add_meta_box( 'wpinv-payment-form-shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side' );
28
+    add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
29
+    add_meta_box('wpinv-payment-form-shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_shortcode', 'wpi_payment_form', 'side');
30 30
    
31
-    add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high' );
32
-    add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high' );
33
-    add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high' );
31
+    add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'WPInv_Meta_Box_Billing_Details::output', 'wpi_invoice', 'normal', 'high');
32
+    add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'WPInv_Meta_Box_Items::output', 'wpi_invoice', 'normal', 'high');
33
+    add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'normal', 'high');
34 34
     
35
-    if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
36
-        add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' );
35
+    if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
36
+        add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high');
37 37
     }
38 38
 
39 39
 	remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
40 40
 }
41
-add_action( 'add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2 );
41
+add_action('add_meta_boxes', 'wpinv_add_meta_boxes', 30, 2);
42 42
 
43
-function wpinv_save_meta_boxes( $post_id, $post, $update = false ) {
44
-    remove_action( 'save_post', __FUNCTION__ );
43
+function wpinv_save_meta_boxes($post_id, $post, $update = false) {
44
+    remove_action('save_post', __FUNCTION__);
45 45
     
46 46
     // $post_id and $post are required
47
-    if ( empty( $post_id ) || empty( $post ) ) {
47
+    if (empty($post_id) || empty($post)) {
48 48
         return;
49 49
     }
50 50
         
51
-    if ( !current_user_can( 'edit_post', $post_id ) || empty( $post->post_type ) ) {
51
+    if (!current_user_can('edit_post', $post_id) || empty($post->post_type)) {
52 52
         return;
53 53
     }
54 54
     
55 55
     // Dont' save meta boxes for revisions or autosaves
56
-    if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
56
+    if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
57 57
         return;
58 58
     }
59 59
         
60
-    if ( $post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote' ) {
61
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
60
+    if ($post->post_type == 'wpi_invoice' or $post->post_type == 'wpi_quote') {
61
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
62 62
             return;
63 63
         }
64 64
     
65
-        if ( isset( $_POST['wpinv_save_invoice'] ) && wp_verify_nonce( $_POST['wpinv_save_invoice'], 'wpinv_save_invoice' ) ) {
66
-            WPInv_Meta_Box_Items::save( $post_id, $_POST, $post );
65
+        if (isset($_POST['wpinv_save_invoice']) && wp_verify_nonce($_POST['wpinv_save_invoice'], 'wpinv_save_invoice')) {
66
+            WPInv_Meta_Box_Items::save($post_id, $_POST, $post);
67 67
         }
68
-    } else if ( $post->post_type == 'wpi_item' ) {
69
-        GetPaid_Meta_Box_Item_Details::save( $post_id );
68
+    } else if ($post->post_type == 'wpi_item') {
69
+        GetPaid_Meta_Box_Item_Details::save($post_id);
70 70
     }
71 71
 }
72
-add_action( 'save_post', 'wpinv_save_meta_boxes', 10, 3 );
72
+add_action('save_post', 'wpinv_save_meta_boxes', 10, 3);
73 73
 
74 74
 function wpinv_register_item_meta_boxes() {    
75 75
     global $wpinv_euvat;
76 76
 
77 77
     // Registers the item details metabox.
78
-    add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
78
+    add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
79 79
 
80
-    if ( $wpinv_euvat->allow_vat_rules() ) {
81
-        add_meta_box( 'wpinv_field_vat_rules', __( 'VAT rules type to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high' );
80
+    if ($wpinv_euvat->allow_vat_rules()) {
81
+        add_meta_box('wpinv_field_vat_rules', __('VAT rules type to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_rules', 'wpi_item', 'normal', 'high');
82 82
     }
83 83
     
84
-    if ( $wpinv_euvat->allow_vat_classes() ) {
85
-        add_meta_box( 'wpinv_field_vat_classes', __( 'VAT rates class to use', 'invoicing' ), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high' );
84
+    if ($wpinv_euvat->allow_vat_classes()) {
85
+        add_meta_box('wpinv_field_vat_classes', __('VAT rates class to use', 'invoicing'), 'WPInv_Meta_Box_Items::vat_classes', 'wpi_item', 'normal', 'high');
86 86
     }
87 87
     
88
-    add_meta_box( 'wpinv_field_item_shortcode', __( 'Shortcode', 'invoicing' ), 'WPInv_Meta_Box_Items::shortcode', 'wpi_item', 'side', 'core' );
89
-    add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core' );
90
-    add_meta_box( 'wpinv_field_meta_values', __( 'Item Meta Values', 'invoicing' ), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core' );
88
+    add_meta_box('wpinv_field_item_shortcode', __('Shortcode', 'invoicing'), 'WPInv_Meta_Box_Items::shortcode', 'wpi_item', 'side', 'core');
89
+    add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'WPInv_Meta_Box_Items::item_info', 'wpi_item', 'side', 'core');
90
+    add_meta_box('wpinv_field_meta_values', __('Item Meta Values', 'invoicing'), 'WPInv_Meta_Box_Items::meta_values', 'wpi_item', 'side', 'core');
91 91
 }
92 92
 
93 93
 function wpinv_register_discount_meta_boxes() {
94
-    add_meta_box( 'wpinv_discount_fields', __( 'Discount Details', 'invoicing' ), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high' );
94
+    add_meta_box('wpinv_discount_fields', __('Discount Details', 'invoicing'), 'wpinv_discount_metabox_details', 'wpi_discount', 'normal', 'high');
95 95
 }
96 96
 
97
-function wpinv_discount_metabox_details( $post ) {
97
+function wpinv_discount_metabox_details($post) {
98 98
     $discount_id    = $post->ID;
99
-    $discount       = wpinv_get_discount( $discount_id );
99
+    $discount       = wpinv_get_discount($discount_id);
100 100
     
101
-    $type               = wpinv_get_discount_type( $discount_id );
102
-    $item_reqs          = wpinv_get_discount_item_reqs( $discount_id );
103
-    $excluded_items     = wpinv_get_discount_excluded_items( $discount_id );
104
-    $min_total          = wpinv_get_discount_min_total( $discount_id );
105
-    $max_total          = wpinv_get_discount_max_total( $discount_id );
106
-    $max_uses           = wpinv_get_discount_max_uses( $discount_id );
107
-    $single_use         = wpinv_discount_is_single_use( $discount_id );
108
-    $recurring          = (bool)wpinv_discount_is_recurring( $discount_id );
109
-    $start_date         = wpinv_get_discount_start_date( $discount_id );
110
-    $expiration_date    = wpinv_get_discount_expiration( $discount_id );
101
+    $type               = wpinv_get_discount_type($discount_id);
102
+    $item_reqs          = wpinv_get_discount_item_reqs($discount_id);
103
+    $excluded_items     = wpinv_get_discount_excluded_items($discount_id);
104
+    $min_total          = wpinv_get_discount_min_total($discount_id);
105
+    $max_total          = wpinv_get_discount_max_total($discount_id);
106
+    $max_uses           = wpinv_get_discount_max_uses($discount_id);
107
+    $single_use         = wpinv_discount_is_single_use($discount_id);
108
+    $recurring          = (bool) wpinv_discount_is_recurring($discount_id);
109
+    $start_date         = wpinv_get_discount_start_date($discount_id);
110
+    $expiration_date    = wpinv_get_discount_expiration($discount_id);
111 111
     
112
-    if ( ! empty( $start_date ) && strpos( $start_date, '0000' ) === false ) {
113
-        $start_time         = strtotime( $start_date );
114
-        $start_h            = date_i18n( 'H', $start_time );
115
-        $start_m            = date_i18n( 'i', $start_time );
116
-        $start_date         = date_i18n( 'Y-m-d', $start_time );
112
+    if (!empty($start_date) && strpos($start_date, '0000') === false) {
113
+        $start_time         = strtotime($start_date);
114
+        $start_h            = date_i18n('H', $start_time);
115
+        $start_m            = date_i18n('i', $start_time);
116
+        $start_date         = date_i18n('Y-m-d', $start_time);
117 117
     } else {
118 118
         $start_h            = '00';
119 119
         $start_m            = '00';
120 120
     }
121 121
 
122
-    if ( ! empty( $expiration_date ) && strpos( $expiration_date, '0000' ) === false ) {
123
-        $expiration_time    = strtotime( $expiration_date );
124
-        $expiration_h       = date_i18n( 'H', $expiration_time );
125
-        $expiration_m       = date_i18n( 'i', $expiration_time );
126
-        $expiration_date    = date_i18n( 'Y-m-d', $expiration_time );
122
+    if (!empty($expiration_date) && strpos($expiration_date, '0000') === false) {
123
+        $expiration_time    = strtotime($expiration_date);
124
+        $expiration_h       = date_i18n('H', $expiration_time);
125
+        $expiration_m       = date_i18n('i', $expiration_time);
126
+        $expiration_date    = date_i18n('Y-m-d', $expiration_time);
127 127
     } else {
128 128
         $expiration_h       = '23';
129 129
         $expiration_m       = '59';
@@ -133,220 +133,220 @@  discard block
 block discarded – undo
133 133
     $max_total          = $max_total > 0 ? $max_total : '';
134 134
     $max_uses           = $max_uses > 0 ? $max_uses : '';
135 135
 ?>
136
-<?php do_action( 'wpinv_discount_form_top', $post ); ?>
137
-<?php wp_nonce_field( 'wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce' ); ;?>
136
+<?php do_action('wpinv_discount_form_top', $post); ?>
137
+<?php wp_nonce_field('wpinv_discount_metabox_nonce', 'wpinv_discount_metabox_nonce'); ;?>
138 138
 <table class="form-table wpi-form-table">
139 139
     <tbody>
140
-        <?php do_action( 'wpinv_discount_form_first', $post ); ?>
141
-        <?php do_action( 'wpinv_discount_form_before_code', $post ); ?>
140
+        <?php do_action('wpinv_discount_form_first', $post); ?>
141
+        <?php do_action('wpinv_discount_form_before_code', $post); ?>
142 142
         <tr>
143 143
             <th valign="top" scope="row">
144
-                <label for="wpinv_discount_code"><?php _e( 'Discount Code', 'invoicing' ); ?></label>
144
+                <label for="wpinv_discount_code"><?php _e('Discount Code', 'invoicing'); ?></label>
145 145
             </th>
146 146
             <td>
147
-                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr( wpinv_get_discount_code( $discount_id ) ); ?>" required>
148
-                <p class="description"><?php _e( 'Enter a code for this discount, such as 10OFF', 'invoicing' ); ?></p>
147
+                <input type="text" name="code" id="wpinv_discount_code" class="medium-text" value="<?php echo esc_attr(wpinv_get_discount_code($discount_id)); ?>" required>
148
+                <p class="description"><?php _e('Enter a code for this discount, such as 10OFF', 'invoicing'); ?></p>
149 149
             </td>
150 150
         </tr>
151
-        <?php do_action( 'wpinv_discount_form_before_type', $post ); ?>
151
+        <?php do_action('wpinv_discount_form_before_type', $post); ?>
152 152
         <tr>
153 153
             <th valign="top" scope="row">
154
-                <label for="wpinv_discount_type"><?php _e( 'Discount Type', 'invoicing' ); ?></label>
154
+                <label for="wpinv_discount_type"><?php _e('Discount Type', 'invoicing'); ?></label>
155 155
             </th>
156 156
             <td>
157 157
                 <select id="wpinv_discount_type" name="type" class="medium-text wpi_select2">
158
-                    <?php foreach ( wpinv_get_discount_types() as $value => $label ) { ?>
159
-                    <option value="<?php echo $value ;?>" <?php selected( $type, $value ); ?>><?php echo $label; ?></option>
158
+                    <?php foreach (wpinv_get_discount_types() as $value => $label) { ?>
159
+                    <option value="<?php echo $value; ?>" <?php selected($type, $value); ?>><?php echo $label; ?></option>
160 160
                     <?php } ?>
161 161
                 </select>
162
-                <p class="description"><?php _e( 'The kind of discount to apply for this discount.', 'invoicing' ); ?></p>
162
+                <p class="description"><?php _e('The kind of discount to apply for this discount.', 'invoicing'); ?></p>
163 163
             </td>
164 164
         </tr>
165
-        <?php do_action( 'wpinv_discount_form_before_amount', $post ); ?>
165
+        <?php do_action('wpinv_discount_form_before_amount', $post); ?>
166 166
         <tr>
167 167
             <th valign="top" scope="row">
168
-                <label for="wpinv_discount_amount"><?php _e( 'Amount', 'invoicing' ); ?></label>
168
+                <label for="wpinv_discount_amount"><?php _e('Amount', 'invoicing'); ?></label>
169 169
             </th>
170 170
             <td>
171
-                <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>
172
-                <p style="display:none;" class="description"><?php _e( 'Enter the discount amount in USD', 'invoicing' ); ?></p>
173
-                <p class="description"><?php _e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?></p>
171
+                <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>
172
+                <p style="display:none;" class="description"><?php _e('Enter the discount amount in USD', 'invoicing'); ?></p>
173
+                <p class="description"><?php _e('Enter the discount value. Ex: 10', 'invoicing'); ?></p>
174 174
             </td>
175 175
         </tr>
176
-        <?php do_action( 'wpinv_discount_form_before_items', $post ); ?>
176
+        <?php do_action('wpinv_discount_form_before_items', $post); ?>
177 177
         <tr>
178 178
             <th valign="top" scope="row">
179
-                <label for="wpinv_discount_items"><?php _e( 'Items', 'invoicing' ); ?></label>
179
+                <label for="wpinv_discount_items"><?php _e('Items', 'invoicing'); ?></label>
180 180
             </th>
181 181
             <td>
182
-                <p><?php echo wpinv_item_dropdown( array(
182
+                <p><?php echo wpinv_item_dropdown(array(
183 183
                         'name'              => 'items[]',
184 184
                         'id'                => 'items',
185 185
                         'selected'          => $item_reqs,
186 186
                         'multiple'          => true,
187 187
                         'class'             => 'medium-text wpi_select2',
188
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
188
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
189 189
                         'show_recurring'    => true,
190
-                    ) ); ?>
190
+                    )); ?>
191 191
                 </p>
192
-                <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>
192
+                <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>
193 193
             </td>
194 194
         </tr>
195
-        <?php do_action( 'wpinv_discount_form_before_excluded_items', $post ); ?>
195
+        <?php do_action('wpinv_discount_form_before_excluded_items', $post); ?>
196 196
         <tr>
197 197
             <th valign="top" scope="row">
198
-                <label for="wpinv_discount_excluded_items"><?php _e( 'Excluded Items', 'invoicing' ); ?></label>
198
+                <label for="wpinv_discount_excluded_items"><?php _e('Excluded Items', 'invoicing'); ?></label>
199 199
             </th>
200 200
             <td>
201
-                <p><?php echo wpinv_item_dropdown( array(
201
+                <p><?php echo wpinv_item_dropdown(array(
202 202
                         'name'              => 'excluded_items[]',
203 203
                         'id'                => 'excluded_items',
204 204
                         'selected'          => $excluded_items,
205 205
                         'multiple'          => true,
206 206
                         'class'             => 'medium-text wpi_select2',
207
-                        'placeholder'       => __( 'Select one or more Items', 'invoicing' ),
207
+                        'placeholder'       => __('Select one or more Items', 'invoicing'),
208 208
                         'show_recurring'    => true,
209
-                    ) ); ?>
209
+                    )); ?>
210 210
                 </p>
211
-                <p class="description"><?php _e( 'Items which are NOT allowed to use this discount.', 'invoicing' ); ?></p>
211
+                <p class="description"><?php _e('Items which are NOT allowed to use this discount.', 'invoicing'); ?></p>
212 212
             </td>
213 213
         </tr>
214
-        <?php do_action( 'wpinv_discount_form_before_start', $post ); ?>
214
+        <?php do_action('wpinv_discount_form_before_start', $post); ?>
215 215
         <tr>
216 216
             <th valign="top" scope="row">
217
-                <label for="wpinv_discount_start"><?php _e( 'Start Date', 'invoicing' ); ?></label>
217
+                <label for="wpinv_discount_start"><?php _e('Start Date', 'invoicing'); ?></label>
218 218
             </th>
219 219
             <td>
220
-                <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">
221
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
222
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_h ); ?>><?php echo $value;?></option>
220
+                <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">
221
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
222
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_h); ?>><?php echo $value; ?></option>
223 223
                     <?php } ?>
224 224
                 </select> : <select id="wpinv_discount_start_m" name="start_m">
225
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
226
-                    <option value="<?php echo $value;?>" <?php selected( $value, $start_m ); ?>><?php echo $value;?></option>
225
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
226
+                    <option value="<?php echo $value; ?>" <?php selected($value, $start_m); ?>><?php echo $value; ?></option>
227 227
                     <?php } ?>
228 228
                 </select>
229
-                <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>
229
+                <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>
230 230
             </td>
231 231
         </tr>
232
-        <?php do_action( 'wpinv_discount_form_before_expiration', $post ); ?>
232
+        <?php do_action('wpinv_discount_form_before_expiration', $post); ?>
233 233
         <tr>
234 234
             <th valign="top" scope="row">
235
-                <label for="wpinv_discount_expiration"><?php _e( 'Expiration Date', 'invoicing' ); ?></label>
235
+                <label for="wpinv_discount_expiration"><?php _e('Expiration Date', 'invoicing'); ?></label>
236 236
             </th>
237 237
             <td>
238
-                <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">
239
-                    <?php for ( $i = 0; $i <= 23; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
240
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_h ); ?>><?php echo $value;?></option>
238
+                <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">
239
+                    <?php for ($i = 0; $i <= 23; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
240
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_h); ?>><?php echo $value; ?></option>
241 241
                     <?php } ?>
242 242
                 </select> : <select id="wpinv_discount_expiration_m" name="expiration_m">
243
-                    <?php for ( $i = 0; $i <= 59; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
244
-                    <option value="<?php echo $value;?>" <?php selected( $value, $expiration_m ); ?>><?php echo $value;?></option>
243
+                    <?php for ($i = 0; $i <= 59; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
244
+                    <option value="<?php echo $value; ?>" <?php selected($value, $expiration_m); ?>><?php echo $value; ?></option>
245 245
                     <?php } ?>
246 246
                 </select>
247
-                <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>
247
+                <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>
248 248
             </td>
249 249
         </tr>
250
-        <?php do_action( 'wpinv_discount_form_before_min_total', $post ); ?>
250
+        <?php do_action('wpinv_discount_form_before_min_total', $post); ?>
251 251
         <tr>
252 252
             <th valign="top" scope="row">
253
-                <label for="wpinv_discount_min_total"><?php _e( 'Minimum Amount', 'invoicing' ); ?></label>
253
+                <label for="wpinv_discount_min_total"><?php _e('Minimum Amount', 'invoicing'); ?></label>
254 254
             </th>
255 255
             <td>
256 256
                 <input type="text" name="min_total" id="wpinv_discount_min_total" class="wpi-field-price wpi-price" value="<?php echo $min_total; ?>">
257
-                <p class="description"><?php _e( 'This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
257
+                <p class="description"><?php _e('This allows you to set the minimum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
258 258
             </td>
259 259
         </tr>
260
-        <?php do_action( 'wpinv_discount_form_before_max_total', $post ); ?>
260
+        <?php do_action('wpinv_discount_form_before_max_total', $post); ?>
261 261
         <tr>
262 262
             <th valign="top" scope="row">
263
-                <label for="wpinv_discount_max_total"><?php _e( 'Maximum Amount', 'invoicing' ); ?></label>
263
+                <label for="wpinv_discount_max_total"><?php _e('Maximum Amount', 'invoicing'); ?></label>
264 264
             </th>
265 265
             <td>
266 266
                 <input type="text" name="max_total" id="wpinv_discount_max_total" class="wpi-field-price wpi-price" value="<?php echo $max_total; ?>">
267
-                <p class="description"><?php _e( 'This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing' ); ?></p>
267
+                <p class="description"><?php _e('This allows you to set the maximum amount (subtotal, including taxes) allowed when using the discount.', 'invoicing'); ?></p>
268 268
             </td>
269 269
         </tr>
270
-        <?php do_action( 'wpinv_discount_form_before_recurring', $post ); ?>
270
+        <?php do_action('wpinv_discount_form_before_recurring', $post); ?>
271 271
         <tr>
272 272
             <th valign="top" scope="row">
273
-                <label for="wpinv_discount_recurring"><?php _e( 'For recurring apply to', 'invoicing' ); ?></label>
273
+                <label for="wpinv_discount_recurring"><?php _e('For recurring apply to', 'invoicing'); ?></label>
274 274
             </th>
275 275
             <td>
276 276
                 <select id="wpinv_discount_recurring" name="recurring" class="medium-text wpi_select2">
277
-                    <option value="0" <?php selected( false, $recurring ); ?>><?php _e( 'First payment only', 'invoicing' ); ?></option>
278
-                    <option value="1" <?php selected( true, $recurring ); ?>><?php _e( 'All payments', 'invoicing' ); ?></option>
277
+                    <option value="0" <?php selected(false, $recurring); ?>><?php _e('First payment only', 'invoicing'); ?></option>
278
+                    <option value="1" <?php selected(true, $recurring); ?>><?php _e('All payments', 'invoicing'); ?></option>
279 279
                 </select>
280
-                <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>
280
+                <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>
281 281
             </td>
282 282
         </tr>
283
-        <?php do_action( 'wpinv_discount_form_before_max_uses', $post ); ?>
283
+        <?php do_action('wpinv_discount_form_before_max_uses', $post); ?>
284 284
         <tr>
285 285
             <th valign="top" scope="row">
286
-                <label for="wpinv_discount_max_uses"><?php _e( 'Max Uses', 'invoicing' ); ?></label>
286
+                <label for="wpinv_discount_max_uses"><?php _e('Max Uses', 'invoicing'); ?></label>
287 287
             </th>
288 288
             <td>
289 289
                 <input type="number" min="0" step="1" id="wpinv_discount_max_uses" name="max_uses" class="medium-text" value="<?php echo $max_uses; ?>">
290
-                <p class="description"><?php _e( 'The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing' ); ?></p>
290
+                <p class="description"><?php _e('The maximum number of times this discount can be used. Leave blank for unlimited.', 'invoicing'); ?></p>
291 291
             </td>
292 292
         </tr>
293
-        <?php do_action( 'wpinv_discount_form_before_single_use', $post ); ?>
293
+        <?php do_action('wpinv_discount_form_before_single_use', $post); ?>
294 294
         <tr>
295 295
             <th valign="top" scope="row">
296
-                <label for="wpinv_discount_single_use"><?php _e( 'Use Once Per User', 'invoicing' ); ?></label>
296
+                <label for="wpinv_discount_single_use"><?php _e('Use Once Per User', 'invoicing'); ?></label>
297 297
             </th>
298 298
             <td>
299
-                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked( true, $single_use ); ?>>
300
-                <span class="description"><?php _e( 'Limit this discount to a single use per user?', 'invoicing' ); ?></span>
299
+                <input type="checkbox" value="1" name="single_use" id="wpinv_discount_single_use" <?php checked(true, $single_use); ?>>
300
+                <span class="description"><?php _e('Limit this discount to a single use per user?', 'invoicing'); ?></span>
301 301
             </td>
302 302
         </tr>
303
-        <?php do_action( 'wpinv_discount_form_last', $post ); ?>
303
+        <?php do_action('wpinv_discount_form_last', $post); ?>
304 304
     </tbody>
305 305
 </table>
306
-<?php do_action( 'wpinv_discount_form_bottom', $post ); ?>
306
+<?php do_action('wpinv_discount_form_bottom', $post); ?>
307 307
     <?php
308 308
 }
309 309
 
310
-function wpinv_discount_metabox_save( $post_id, $post, $update = false ) {
311
-    $post_type = !empty( $post ) ? $post->post_type : '';
310
+function wpinv_discount_metabox_save($post_id, $post, $update = false) {
311
+    $post_type = !empty($post) ? $post->post_type : '';
312 312
     
313
-    if ( $post_type != 'wpi_discount' ) {
313
+    if ($post_type != 'wpi_discount') {
314 314
         return;
315 315
     }
316 316
     
317
-    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' ) ) ) {
317
+    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'))) {
318 318
         return;
319 319
     }
320 320
     
321
-    if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
321
+    if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || (defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
322 322
         return;
323 323
     }
324 324
     
325
-    if ( !current_user_can( wpinv_get_capability(), $post_id ) ) {
325
+    if (!current_user_can(wpinv_get_capability(), $post_id)) {
326 326
         return;
327 327
     }
328 328
     
329
-    if ( !empty( $_POST['start'] ) && isset( $_POST['start_h'] ) && isset( $_POST['start_m'] ) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '' ) {
329
+    if (!empty($_POST['start']) && isset($_POST['start_h']) && isset($_POST['start_m']) && $_POST['start_h'] !== '' && $_POST['start_m'] !== '') {
330 330
         $_POST['start'] = $_POST['start'] . ' ' . $_POST['start_h'] . ':' . $_POST['start_m'];
331 331
     }
332 332
 
333
-    if ( !empty( $_POST['expiration'] ) && isset( $_POST['expiration_h'] ) && isset( $_POST['expiration_m'] ) ) {
333
+    if (!empty($_POST['expiration']) && isset($_POST['expiration_h']) && isset($_POST['expiration_m'])) {
334 334
         $_POST['expiration'] = $_POST['expiration'] . ' ' . $_POST['expiration_h'] . ':' . $_POST['expiration_m'];
335 335
     }
336 336
     
337
-    return /** @scrutinizer ignore-call */ wpinv_store_discount( $post_id, $_POST, $post, $update );
337
+    return /** @scrutinizer ignore-call */ wpinv_store_discount($post_id, $_POST, $post, $update);
338 338
 }
339
-add_action( 'save_post', 'wpinv_discount_metabox_save', 10, 3 );
339
+add_action('save_post', 'wpinv_discount_metabox_save', 10, 3);
340 340
 
341 341
 /**
342 342
  * Remove trash link from the default form.
343 343
  */
344
-function getpaid_remove_action_link( $actions, $post ) {
345
-    $post = get_post( $post );
346
-    if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
347
-        unset( $actions['trash'] );
348
-        unset( $actions['inline hide-if-no-js'] );
344
+function getpaid_remove_action_link($actions, $post) {
345
+    $post = get_post($post);
346
+    if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
347
+        unset($actions['trash']);
348
+        unset($actions['inline hide-if-no-js']);
349 349
     }
350 350
     return $actions;
351 351
 }
352
-add_filter( 'post_row_actions', 'getpaid_remove_action_link', 10, 2 );
352
+add_filter('post_row_actions', 'getpaid_remove_action_link', 10, 2);
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
  * @param mixed  $value Value.
709 709
  */
710 710
 function getpaid_maybe_define_constant( $name, $value ) {
711
-	if ( ! defined( $name ) ) {
712
-		define( $name, $value );
713
-	}
711
+    if ( ! defined( $name ) ) {
712
+        define( $name, $value );
713
+    }
714 714
 }
715 715
 
716 716
 function wpinv_get_php_arg_separator_output() {
717
-	return ini_get( 'arg_separator.output' );
717
+    return ini_get( 'arg_separator.output' );
718 718
 }
719 719
 
720 720
 function wpinv_rgb_from_hex( $color ) {
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
  * @return array Sanitized array of values.
1059 1059
  */
1060 1060
 function wpinv_parse_list( $list ) {
1061
-	if ( ! is_array( $list ) ) {
1062
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
-	}
1061
+    if ( ! is_array( $list ) ) {
1062
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
+    }
1064 1064
 
1065
-	return $list;
1065
+    return $list;
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1082,9 +1082,9 @@  discard block
 block discarded – undo
1082 1082
     }
1083 1083
 
1084 1084
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1085
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1085
+    wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1086 1086
 
1087
-	return $data;
1087
+    return $data;
1088 1088
 }
1089 1089
 
1090 1090
 /**
@@ -1113,17 +1113,17 @@  discard block
 block discarded – undo
1113 1113
  */
1114 1114
 function wpinv_clean( $var ) {
1115 1115
 
1116
-	if ( is_array( $var ) ) {
1117
-		return array_map( 'wpinv_clean', $var );
1116
+    if ( is_array( $var ) ) {
1117
+        return array_map( 'wpinv_clean', $var );
1118 1118
     }
1119 1119
 
1120 1120
     if ( is_object( $var ) ) {
1121
-		$object_vars = get_object_vars( $var );
1122
-		foreach ( $object_vars as $property_name => $property_value ) {
1123
-			$var->$property_name = wpinv_clean( $property_value );
1121
+        $object_vars = get_object_vars( $var );
1122
+        foreach ( $object_vars as $property_name => $property_value ) {
1123
+            $var->$property_name = wpinv_clean( $property_value );
1124 1124
         }
1125 1125
         return $var;
1126
-	}
1126
+    }
1127 1127
     
1128 1128
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1129 1129
 }
1130 1130
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +414 added lines, -414 removed lines patch added patch discarded remove patch
@@ -7,132 +7,132 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
92
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
93 93
     global $post;
94 94
 
95 95
     $invoice_statuses = array(
96
-        'wpi-pending' => __( 'Pending Payment', 'invoicing' ),
97
-        'publish' => __( 'Paid', 'invoicing'),
98
-        'wpi-processing' => __( 'Processing', 'invoicing' ),
99
-        'wpi-onhold' => __( 'On Hold', 'invoicing' ),
100
-        'wpi-refunded' => __( 'Refunded', 'invoicing' ),
101
-        'wpi-cancelled' => __( 'Cancelled', 'invoicing' ),
102
-        'wpi-failed' => __( 'Failed', 'invoicing' ),
103
-        'wpi-renewal' => __( 'Renewal Payment', 'invoicing' )
96
+        'wpi-pending' => __('Pending Payment', 'invoicing'),
97
+        'publish' => __('Paid', 'invoicing'),
98
+        'wpi-processing' => __('Processing', 'invoicing'),
99
+        'wpi-onhold' => __('On Hold', 'invoicing'),
100
+        'wpi-refunded' => __('Refunded', 'invoicing'),
101
+        'wpi-cancelled' => __('Cancelled', 'invoicing'),
102
+        'wpi-failed' => __('Failed', 'invoicing'),
103
+        'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
 
106
-    if ( $draft ) {
107
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
106
+    if ($draft) {
107
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
108 108
     }
109 109
 
110
-    if ( $trashed ) {
111
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
110
+    if ($trashed) {
111
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
112 112
     }
113 113
 
114
-    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
114
+    return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
115 115
 }
116 116
 
117
-function wpinv_status_nicename( $status ) {
118
-    $statuses = wpinv_get_invoice_statuses( true, true );
119
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
117
+function wpinv_status_nicename($status) {
118
+    $statuses = wpinv_get_invoice_statuses(true, true);
119
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
120 120
 
121 121
     return $status;
122 122
 }
123 123
 
124 124
 function wpinv_get_currency() {
125
-    $currency = wpinv_get_option( 'currency', 'USD' );
125
+    $currency = wpinv_get_option('currency', 'USD');
126 126
     
127
-    return apply_filters( 'wpinv_currency', $currency );
127
+    return apply_filters('wpinv_currency', $currency);
128 128
 }
129 129
 
130
-function wpinv_currency_symbol( $currency = '' ) {
131
-    if ( empty( $currency ) ) {
130
+function wpinv_currency_symbol($currency = '') {
131
+    if (empty($currency)) {
132 132
         $currency = wpinv_get_currency();
133 133
     }
134 134
     
135
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
135
+    $symbols = apply_filters('wpinv_currency_symbols', array(
136 136
         'AED' => '&#x62f;.&#x625;',
137 137
         'AFN' => '&#x60b;',
138 138
         'ALL' => 'L',
@@ -295,209 +295,209 @@  discard block
 block discarded – undo
295 295
         'YER' => '&#xfdfc;',
296 296
         'ZAR' => '&#82;',
297 297
         'ZMW' => 'ZK',
298
-    ) );
298
+    ));
299 299
 
300
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
300
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
301 301
 
302
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
302
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
303 303
 }
304 304
 
305 305
 function wpinv_currency_position() {
306
-    $position = wpinv_get_option( 'currency_position', 'left' );
306
+    $position = wpinv_get_option('currency_position', 'left');
307 307
     
308
-    return apply_filters( 'wpinv_currency_position', $position );
308
+    return apply_filters('wpinv_currency_position', $position);
309 309
 }
310 310
 
311 311
 function wpinv_thousands_separator() {
312
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
312
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
313 313
     
314
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
314
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
315 315
 }
316 316
 
317 317
 function wpinv_decimal_separator() {
318
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
318
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
319 319
     
320
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
320
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
321 321
 }
322 322
 
323 323
 function wpinv_decimals() {
324
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
324
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
325 325
     
326
-    return absint( $decimals );
326
+    return absint($decimals);
327 327
 }
328 328
 
329 329
 function wpinv_get_currencies() {
330 330
     $currencies = array(
331
-        'USD' => __( 'US Dollar', 'invoicing' ),
332
-        'EUR' => __( 'Euro', 'invoicing' ),
333
-        'GBP' => __( 'Pound Sterling', 'invoicing' ),
334
-        'AED' => __( 'United Arab Emirates', 'invoicing' ),
335
-        'AFN' => __( 'Afghan Afghani', 'invoicing' ),
336
-        'ALL' => __( 'Albanian Lek', 'invoicing' ),
337
-        'AMD' => __( 'Armenian Dram', 'invoicing' ),
338
-        'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ),
339
-        'AOA' => __( 'Angolan Kwanza', 'invoicing' ),
340
-        'ARS' => __( 'Argentine Peso', 'invoicing' ),
341
-        'AUD' => __( 'Australian Dollar', 'invoicing' ),
342
-        'AWG' => __( 'Aruban Florin', 'invoicing' ),
343
-        'AZN' => __( 'Azerbaijani Manat', 'invoicing' ),
344
-        'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ),
345
-        'BBD' => __( 'Barbadian Dollar', 'invoicing' ),
346
-        'BDT' => __( 'Bangladeshi Taka', 'invoicing' ),
347
-        'BGN' => __( 'Bulgarian Lev', 'invoicing' ),
348
-        'BHD' => __( 'Bahraini Dinar', 'invoicing' ),
349
-        'BIF' => __( 'Burundian Franc', 'invoicing' ),
350
-        'BMD' => __( 'Bermudian Dollar', 'invoicing' ),
351
-        'BND' => __( 'Brunei Dollar', 'invoicing' ),
352
-        'BOB' => __( 'Bolivian Boliviano', 'invoicing' ),
353
-        'BRL' => __( 'Brazilian Real', 'invoicing' ),
354
-        'BSD' => __( 'Bahamian Dollar', 'invoicing' ),
355
-        'BTC' => __( 'Bitcoin', 'invoicing' ),
356
-        'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ),
357
-        'BWP' => __( 'Botswana Pula', 'invoicing' ),
358
-        'BYN' => __( 'Belarusian Ruble', 'invoicing' ),
359
-        'BZD' => __( 'Belize Dollar', 'invoicing' ),
360
-        'CAD' => __( 'Canadian Dollar', 'invoicing' ),
361
-        'CDF' => __( 'Congolese Franc', 'invoicing' ),
362
-        'CHF' => __( 'Swiss Franc', 'invoicing' ),
363
-        'CLP' => __( 'Chilean Peso', 'invoicing' ),
364
-        'CNY' => __( 'Chinese Yuan', 'invoicing' ),
365
-        'COP' => __( 'Colombian Peso', 'invoicing' ),
366
-        'CRC' => __( 'Costa Rican Colon', 'invoicing' ),
367
-        'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ),
368
-        'CUP' => __( 'Cuban Peso', 'invoicing' ),
369
-        'CVE' => __( 'Cape Verdean escudo', 'invoicing' ),
370
-        'CZK' => __( 'Czech Koruna', 'invoicing' ),
371
-        'DJF' => __( 'Djiboutian Franc', 'invoicing' ),
372
-        'DKK' => __( 'Danish Krone', 'invoicing' ),
373
-        'DOP' => __( 'Dominican Peso', 'invoicing' ),
374
-        'DZD' => __( 'Algerian Dinar', 'invoicing' ),
375
-        'EGP' => __( 'Egyptian Pound', 'invoicing' ),
376
-        'ERN' => __( 'Eritrean Nakfa', 'invoicing' ),
377
-        'ETB' => __( 'Ethiopian Irr', 'invoicing' ),
378
-        'FJD' => __( 'Fijian Dollar', 'invoicing' ),
379
-        'FKP' => __( 'Falkland Islands Pound', 'invoicing' ),
380
-        'GEL' => __( 'Georgian Lari', 'invoicing' ),
381
-        'GGP' => __( 'Guernsey Pound', 'invoicing' ),
382
-        'GHS' => __( 'Ghana Cedi', 'invoicing' ),
383
-        'GIP' => __( 'Gibraltar Pound', 'invoicing' ),
384
-        'GMD' => __( 'Gambian Dalasi', 'invoicing' ),
385
-        'GNF' => __( 'Guinean Franc', 'invoicing' ),
386
-        'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ),
387
-        'GYD' => __( 'Guyanese Dollar', 'invoicing' ),
388
-        'HKD' => __( 'Hong Kong Dollar', 'invoicing' ),
389
-        'HNL' => __( 'Honduran Lempira', 'invoicing' ),
390
-        'HRK' => __( 'Croatian Kuna', 'invoicing' ),
391
-        'HTG' => __( 'Haitian Gourde', 'invoicing' ),
392
-        'HUF' => __( 'Hungarian Forint', 'invoicing' ),
393
-        'IDR' => __( 'Indonesian Rupiah', 'invoicing' ),
394
-        'ILS' => __( 'Israeli New Shekel', 'invoicing' ),
395
-        'IMP' => __( 'Manx Pound', 'invoicing' ),
396
-        'INR' => __( 'Indian Rupee', 'invoicing' ),
397
-        'IQD' => __( 'Iraqi Dinar', 'invoicing' ),
398
-        'IRR' => __( 'Iranian Rial', 'invoicing' ),
399
-        'IRT' => __( 'Iranian Toman', 'invoicing' ),
400
-        'ISK' => __( 'Icelandic Krona', 'invoicing' ),
401
-        'JEP' => __( 'Jersey Pound', 'invoicing' ),
402
-        'JMD' => __( 'Jamaican Dollar', 'invoicing' ),
403
-        'JOD' => __( 'Jordanian Dinar', 'invoicing' ),
404
-        'JPY' => __( 'Japanese Yen', 'invoicing' ),
405
-        'KES' => __( 'Kenyan Shilling', 'invoicing' ),
406
-        'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ),
407
-        'KHR' => __( 'Cambodian Riel', 'invoicing' ),
408
-        'KMF' => __( 'Comorian Franc', 'invoicing' ),
409
-        'KPW' => __( 'North Korean Won', 'invoicing' ),
410
-        'KRW' => __( 'South Korean Won', 'invoicing' ),
411
-        'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ),
412
-        'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ),
413
-        'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ),
414
-        'LAK' => __( 'Lao Kip', 'invoicing' ),
415
-        'LBP' => __( 'Lebanese Pound', 'invoicing' ),
416
-        'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ),
417
-        'LRD' => __( 'Liberian Dollar', 'invoicing' ),
418
-        'LSL' => __( 'Lesotho Loti', 'invoicing' ),
419
-        'LYD' => __( 'Libyan Dinar', 'invoicing' ),
420
-        'MAD' => __( 'Moroccan Dirham', 'invoicing' ),
421
-        'MDL' => __( 'Moldovan Leu', 'invoicing' ),
422
-        'MGA' => __( 'Malagasy Ariary', 'invoicing' ),
423
-        'MKD' => __( 'Macedonian Denar', 'invoicing' ),
424
-        'MMK' => __( 'Burmese Kyat', 'invoicing' ),
425
-        'MNT' => __( 'Mongolian Tughrik', 'invoicing' ),
426
-        'MOP' => __( 'Macanese Pataca', 'invoicing' ),
427
-        'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ),
428
-        'MUR' => __( 'Mauritian Rupee', 'invoicing' ),
429
-        'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ),
430
-        'MWK' => __( 'Malawian Kwacha', 'invoicing' ),
431
-        'MXN' => __( 'Mexican Peso', 'invoicing' ),
432
-        'MYR' => __( 'Malaysian Ringgit', 'invoicing' ),
433
-        'MZN' => __( 'Mozambican Metical', 'invoicing' ),
434
-        'NAD' => __( 'Namibian Dollar', 'invoicing' ),
435
-        'NGN' => __( 'Nigerian Naira', 'invoicing' ),
436
-        'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ),
437
-        'NOK' => __( 'Norwegian Krone', 'invoicing' ),
438
-        'NPR' => __( 'Nepalese Rupee', 'invoicing' ),
439
-        'NZD' => __( 'New Zealand Dollar', 'invoicing' ),
440
-        'OMR' => __( 'Omani Rial', 'invoicing' ),
441
-        'PAB' => __( 'Panamanian Balboa', 'invoicing' ),
442
-        'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ),
443
-        'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ),
444
-        'PHP' => __( 'Philippine Peso', 'invoicing' ),
445
-        'PKR' => __( 'Pakistani Rupee', 'invoicing' ),
446
-        'PLN' => __( 'Polish Zloty', 'invoicing' ),
447
-        'PRB' => __( 'Transnistrian Ruble', 'invoicing' ),
448
-        'PYG' => __( 'Paraguayan Guarani', 'invoicing' ),
449
-        'QAR' => __( 'Qatari Riyal', 'invoicing' ),
450
-        'RON' => __( 'Romanian Leu', 'invoicing' ),
451
-        'RSD' => __( 'Serbian Dinar', 'invoicing' ),
452
-        'RUB' => __( 'Russian Ruble', 'invoicing' ),
453
-        'RWF' => __( 'Rwandan Franc', 'invoicing' ),
454
-        'SAR' => __( 'Saudi Riyal', 'invoicing' ),
455
-        'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ),
456
-        'SCR' => __( 'Seychellois Rupee', 'invoicing' ),
457
-        'SDG' => __( 'Sudanese Pound', 'invoicing' ),
458
-        'SEK' => __( 'Swedish Krona', 'invoicing' ),
459
-        'SGD' => __( 'Singapore Dollar', 'invoicing' ),
460
-        'SHP' => __( 'Saint Helena Pound', 'invoicing' ),
461
-        'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ),
462
-        'SOS' => __( 'Somali Shilling', 'invoicing' ),
463
-        'SRD' => __( 'Surinamese Dollar', 'invoicing' ),
464
-        'SSP' => __( 'South Sudanese Pound', 'invoicing' ),
465
-        'STD' => __( 'Sao Tomean Dobra', 'invoicing' ),
466
-        'SYP' => __( 'Syrian Pound', 'invoicing' ),
467
-        'SZL' => __( 'Swazi Lilangeni', 'invoicing' ),
468
-        'THB' => __( 'Thai Baht', 'invoicing' ),
469
-        'TJS' => __( 'Tajikistani Somoni', 'invoicing' ),
470
-        'TMT' => __( 'Turkmenistan Manat', 'invoicing' ),
471
-        'TND' => __( 'Tunisian Dinar', 'invoicing' ),
472
-        'TOP' => __( 'Tongan Pa&#x2bb;anga', 'invoicing' ),
473
-        'TRY' => __( 'Turkish Lira', 'invoicing' ),
474
-        'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ),
475
-        'TWD' => __( 'New Taiwan Dollar', 'invoicing' ),
476
-        'TZS' => __( 'Tanzanian Shilling', 'invoicing' ),
477
-        'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ),
478
-        'UGX' => __( 'Ugandan Shilling', 'invoicing' ),
479
-        'UYU' => __( 'Uruguayan Peso', 'invoicing' ),
480
-        'UZS' => __( 'Uzbekistani Som', 'invoicing' ),
481
-        'VEF' => __( 'Venezuelan Bol&iacute;var', 'invoicing' ),
482
-        'VND' => __( 'Vietnamese Dong', 'invoicing' ),
483
-        'VUV' => __( 'Vanuatu Vatu', 'invoicing' ),
484
-        'WST' => __( 'Samoan Tala', 'invoicing' ),
485
-        'XAF' => __( 'Central African CFA Franc', 'invoicing' ),
486
-        'XCD' => __( 'East Caribbean Dollar', 'invoicing' ),
487
-        'XOF' => __( 'West African CFA Franc', 'invoicing' ),
488
-        'XPF' => __( 'CFP Franc', 'invoicing' ),
489
-        'YER' => __( 'Yemeni Rial', 'invoicing' ),
490
-        'ZAR' => __( 'South African Rand', 'invoicing' ),
491
-        'ZMW' => __( 'Zambian Kwacha', 'invoicing' ),
331
+        'USD' => __('US Dollar', 'invoicing'),
332
+        'EUR' => __('Euro', 'invoicing'),
333
+        'GBP' => __('Pound Sterling', 'invoicing'),
334
+        'AED' => __('United Arab Emirates', 'invoicing'),
335
+        'AFN' => __('Afghan Afghani', 'invoicing'),
336
+        'ALL' => __('Albanian Lek', 'invoicing'),
337
+        'AMD' => __('Armenian Dram', 'invoicing'),
338
+        'ANG' => __('Netherlands Antillean Guilder', 'invoicing'),
339
+        'AOA' => __('Angolan Kwanza', 'invoicing'),
340
+        'ARS' => __('Argentine Peso', 'invoicing'),
341
+        'AUD' => __('Australian Dollar', 'invoicing'),
342
+        'AWG' => __('Aruban Florin', 'invoicing'),
343
+        'AZN' => __('Azerbaijani Manat', 'invoicing'),
344
+        'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'),
345
+        'BBD' => __('Barbadian Dollar', 'invoicing'),
346
+        'BDT' => __('Bangladeshi Taka', 'invoicing'),
347
+        'BGN' => __('Bulgarian Lev', 'invoicing'),
348
+        'BHD' => __('Bahraini Dinar', 'invoicing'),
349
+        'BIF' => __('Burundian Franc', 'invoicing'),
350
+        'BMD' => __('Bermudian Dollar', 'invoicing'),
351
+        'BND' => __('Brunei Dollar', 'invoicing'),
352
+        'BOB' => __('Bolivian Boliviano', 'invoicing'),
353
+        'BRL' => __('Brazilian Real', 'invoicing'),
354
+        'BSD' => __('Bahamian Dollar', 'invoicing'),
355
+        'BTC' => __('Bitcoin', 'invoicing'),
356
+        'BTN' => __('Bhutanese Ngultrum', 'invoicing'),
357
+        'BWP' => __('Botswana Pula', 'invoicing'),
358
+        'BYN' => __('Belarusian Ruble', 'invoicing'),
359
+        'BZD' => __('Belize Dollar', 'invoicing'),
360
+        'CAD' => __('Canadian Dollar', 'invoicing'),
361
+        'CDF' => __('Congolese Franc', 'invoicing'),
362
+        'CHF' => __('Swiss Franc', 'invoicing'),
363
+        'CLP' => __('Chilean Peso', 'invoicing'),
364
+        'CNY' => __('Chinese Yuan', 'invoicing'),
365
+        'COP' => __('Colombian Peso', 'invoicing'),
366
+        'CRC' => __('Costa Rican Colon', 'invoicing'),
367
+        'CUC' => __('Cuban Convertible Peso', 'invoicing'),
368
+        'CUP' => __('Cuban Peso', 'invoicing'),
369
+        'CVE' => __('Cape Verdean escudo', 'invoicing'),
370
+        'CZK' => __('Czech Koruna', 'invoicing'),
371
+        'DJF' => __('Djiboutian Franc', 'invoicing'),
372
+        'DKK' => __('Danish Krone', 'invoicing'),
373
+        'DOP' => __('Dominican Peso', 'invoicing'),
374
+        'DZD' => __('Algerian Dinar', 'invoicing'),
375
+        'EGP' => __('Egyptian Pound', 'invoicing'),
376
+        'ERN' => __('Eritrean Nakfa', 'invoicing'),
377
+        'ETB' => __('Ethiopian Irr', 'invoicing'),
378
+        'FJD' => __('Fijian Dollar', 'invoicing'),
379
+        'FKP' => __('Falkland Islands Pound', 'invoicing'),
380
+        'GEL' => __('Georgian Lari', 'invoicing'),
381
+        'GGP' => __('Guernsey Pound', 'invoicing'),
382
+        'GHS' => __('Ghana Cedi', 'invoicing'),
383
+        'GIP' => __('Gibraltar Pound', 'invoicing'),
384
+        'GMD' => __('Gambian Dalasi', 'invoicing'),
385
+        'GNF' => __('Guinean Franc', 'invoicing'),
386
+        'GTQ' => __('Guatemalan Quetzal', 'invoicing'),
387
+        'GYD' => __('Guyanese Dollar', 'invoicing'),
388
+        'HKD' => __('Hong Kong Dollar', 'invoicing'),
389
+        'HNL' => __('Honduran Lempira', 'invoicing'),
390
+        'HRK' => __('Croatian Kuna', 'invoicing'),
391
+        'HTG' => __('Haitian Gourde', 'invoicing'),
392
+        'HUF' => __('Hungarian Forint', 'invoicing'),
393
+        'IDR' => __('Indonesian Rupiah', 'invoicing'),
394
+        'ILS' => __('Israeli New Shekel', 'invoicing'),
395
+        'IMP' => __('Manx Pound', 'invoicing'),
396
+        'INR' => __('Indian Rupee', 'invoicing'),
397
+        'IQD' => __('Iraqi Dinar', 'invoicing'),
398
+        'IRR' => __('Iranian Rial', 'invoicing'),
399
+        'IRT' => __('Iranian Toman', 'invoicing'),
400
+        'ISK' => __('Icelandic Krona', 'invoicing'),
401
+        'JEP' => __('Jersey Pound', 'invoicing'),
402
+        'JMD' => __('Jamaican Dollar', 'invoicing'),
403
+        'JOD' => __('Jordanian Dinar', 'invoicing'),
404
+        'JPY' => __('Japanese Yen', 'invoicing'),
405
+        'KES' => __('Kenyan Shilling', 'invoicing'),
406
+        'KGS' => __('Kyrgyzstani Som', 'invoicing'),
407
+        'KHR' => __('Cambodian Riel', 'invoicing'),
408
+        'KMF' => __('Comorian Franc', 'invoicing'),
409
+        'KPW' => __('North Korean Won', 'invoicing'),
410
+        'KRW' => __('South Korean Won', 'invoicing'),
411
+        'KWD' => __('Kuwaiti Dinar', 'invoicing'),
412
+        'KYD' => __('Cayman Islands Dollar', 'invoicing'),
413
+        'KZT' => __('Kazakhstani Tenge', 'invoicing'),
414
+        'LAK' => __('Lao Kip', 'invoicing'),
415
+        'LBP' => __('Lebanese Pound', 'invoicing'),
416
+        'LKR' => __('Sri Lankan Rupee', 'invoicing'),
417
+        'LRD' => __('Liberian Dollar', 'invoicing'),
418
+        'LSL' => __('Lesotho Loti', 'invoicing'),
419
+        'LYD' => __('Libyan Dinar', 'invoicing'),
420
+        'MAD' => __('Moroccan Dirham', 'invoicing'),
421
+        'MDL' => __('Moldovan Leu', 'invoicing'),
422
+        'MGA' => __('Malagasy Ariary', 'invoicing'),
423
+        'MKD' => __('Macedonian Denar', 'invoicing'),
424
+        'MMK' => __('Burmese Kyat', 'invoicing'),
425
+        'MNT' => __('Mongolian Tughrik', 'invoicing'),
426
+        'MOP' => __('Macanese Pataca', 'invoicing'),
427
+        'MRO' => __('Mauritanian Ouguiya', 'invoicing'),
428
+        'MUR' => __('Mauritian Rupee', 'invoicing'),
429
+        'MVR' => __('Maldivian Rufiyaa', 'invoicing'),
430
+        'MWK' => __('Malawian Kwacha', 'invoicing'),
431
+        'MXN' => __('Mexican Peso', 'invoicing'),
432
+        'MYR' => __('Malaysian Ringgit', 'invoicing'),
433
+        'MZN' => __('Mozambican Metical', 'invoicing'),
434
+        'NAD' => __('Namibian Dollar', 'invoicing'),
435
+        'NGN' => __('Nigerian Naira', 'invoicing'),
436
+        'NIO' => __('Nicaraguan Cordoba', 'invoicing'),
437
+        'NOK' => __('Norwegian Krone', 'invoicing'),
438
+        'NPR' => __('Nepalese Rupee', 'invoicing'),
439
+        'NZD' => __('New Zealand Dollar', 'invoicing'),
440
+        'OMR' => __('Omani Rial', 'invoicing'),
441
+        'PAB' => __('Panamanian Balboa', 'invoicing'),
442
+        'PEN' => __('Peruvian Nuevo Sol', 'invoicing'),
443
+        'PGK' => __('Papua New Guinean Kina', 'invoicing'),
444
+        'PHP' => __('Philippine Peso', 'invoicing'),
445
+        'PKR' => __('Pakistani Rupee', 'invoicing'),
446
+        'PLN' => __('Polish Zloty', 'invoicing'),
447
+        'PRB' => __('Transnistrian Ruble', 'invoicing'),
448
+        'PYG' => __('Paraguayan Guarani', 'invoicing'),
449
+        'QAR' => __('Qatari Riyal', 'invoicing'),
450
+        'RON' => __('Romanian Leu', 'invoicing'),
451
+        'RSD' => __('Serbian Dinar', 'invoicing'),
452
+        'RUB' => __('Russian Ruble', 'invoicing'),
453
+        'RWF' => __('Rwandan Franc', 'invoicing'),
454
+        'SAR' => __('Saudi Riyal', 'invoicing'),
455
+        'SBD' => __('Solomon Islands Dollar', 'invoicing'),
456
+        'SCR' => __('Seychellois Rupee', 'invoicing'),
457
+        'SDG' => __('Sudanese Pound', 'invoicing'),
458
+        'SEK' => __('Swedish Krona', 'invoicing'),
459
+        'SGD' => __('Singapore Dollar', 'invoicing'),
460
+        'SHP' => __('Saint Helena Pound', 'invoicing'),
461
+        'SLL' => __('Sierra Leonean Leone', 'invoicing'),
462
+        'SOS' => __('Somali Shilling', 'invoicing'),
463
+        'SRD' => __('Surinamese Dollar', 'invoicing'),
464
+        'SSP' => __('South Sudanese Pound', 'invoicing'),
465
+        'STD' => __('Sao Tomean Dobra', 'invoicing'),
466
+        'SYP' => __('Syrian Pound', 'invoicing'),
467
+        'SZL' => __('Swazi Lilangeni', 'invoicing'),
468
+        'THB' => __('Thai Baht', 'invoicing'),
469
+        'TJS' => __('Tajikistani Somoni', 'invoicing'),
470
+        'TMT' => __('Turkmenistan Manat', 'invoicing'),
471
+        'TND' => __('Tunisian Dinar', 'invoicing'),
472
+        'TOP' => __('Tongan Pa&#x2bb;anga', 'invoicing'),
473
+        'TRY' => __('Turkish Lira', 'invoicing'),
474
+        'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'),
475
+        'TWD' => __('New Taiwan Dollar', 'invoicing'),
476
+        'TZS' => __('Tanzanian Shilling', 'invoicing'),
477
+        'UAH' => __('Ukrainian Hryvnia', 'invoicing'),
478
+        'UGX' => __('Ugandan Shilling', 'invoicing'),
479
+        'UYU' => __('Uruguayan Peso', 'invoicing'),
480
+        'UZS' => __('Uzbekistani Som', 'invoicing'),
481
+        'VEF' => __('Venezuelan Bol&iacute;var', 'invoicing'),
482
+        'VND' => __('Vietnamese Dong', 'invoicing'),
483
+        'VUV' => __('Vanuatu Vatu', 'invoicing'),
484
+        'WST' => __('Samoan Tala', 'invoicing'),
485
+        'XAF' => __('Central African CFA Franc', 'invoicing'),
486
+        'XCD' => __('East Caribbean Dollar', 'invoicing'),
487
+        'XOF' => __('West African CFA Franc', 'invoicing'),
488
+        'XPF' => __('CFP Franc', 'invoicing'),
489
+        'YER' => __('Yemeni Rial', 'invoicing'),
490
+        'ZAR' => __('South African Rand', 'invoicing'),
491
+        'ZMW' => __('Zambian Kwacha', 'invoicing'),
492 492
     );
493 493
     
494 494
     //asort( $currencies ); // this
495 495
 
496
-    return apply_filters( 'wpinv_currencies', $currencies );
496
+    return apply_filters('wpinv_currencies', $currencies);
497 497
 }
498 498
 
499
-function wpinv_price( $amount = '', $currency = '' ) {
500
-    if( empty( $currency ) ) {
499
+function wpinv_price($amount = '', $currency = '') {
500
+    if (empty($currency)) {
501 501
         $currency = wpinv_get_currency();
502 502
     }
503 503
 
@@ -505,14 +505,14 @@  discard block
 block discarded – undo
505 505
 
506 506
     $negative = $amount < 0;
507 507
 
508
-    if ( $negative ) {
509
-        $amount = substr( $amount, 1 );
508
+    if ($negative) {
509
+        $amount = substr($amount, 1);
510 510
     }
511 511
 
512
-    $symbol = wpinv_currency_symbol( $currency );
512
+    $symbol = wpinv_currency_symbol($currency);
513 513
 
514
-    if ( $position == 'left' || $position == 'left_space' ) {
515
-        switch ( $currency ) {
514
+    if ($position == 'left' || $position == 'left_space') {
515
+        switch ($currency) {
516 516
             case "GBP" :
517 517
             case "BRL" :
518 518
             case "EUR" :
@@ -524,15 +524,15 @@  discard block
 block discarded – undo
524 524
             case "NZD" :
525 525
             case "SGD" :
526 526
             case "JPY" :
527
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
527
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
528 528
                 break;
529 529
             default :
530 530
                 //$price = $currency . ' ' . $amount;
531
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
531
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
532 532
                 break;
533 533
         }
534 534
     } else {
535
-        switch ( $currency ) {
535
+        switch ($currency) {
536 536
             case "GBP" :
537 537
             case "BRL" :
538 538
             case "EUR" :
@@ -543,83 +543,83 @@  discard block
 block discarded – undo
543 543
             case "MXN" :
544 544
             case "SGD" :
545 545
             case "JPY" :
546
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
546
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
547 547
                 break;
548 548
             default :
549 549
                 //$price = $amount . ' ' . $currency;
550
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
550
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
551 551
                 break;
552 552
         }
553 553
     }
554 554
     
555
-    if ( $negative ) {
555
+    if ($negative) {
556 556
         $price = '-' . $price;
557 557
     }
558 558
     
559
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
559
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
560 560
 
561 561
     return $price;
562 562
 }
563 563
 
564
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
564
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
565 565
     $thousands_sep = wpinv_thousands_separator();
566 566
     $decimal_sep   = wpinv_decimal_separator();
567 567
 
568
-    if ( $decimals === NULL ) {
568
+    if ($decimals === NULL) {
569 569
         $decimals = wpinv_decimals();
570 570
     }
571 571
 
572
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
573
-        $whole = substr( $amount, 0, $sep_found );
574
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
572
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
573
+        $whole = substr($amount, 0, $sep_found);
574
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
575 575
         $amount = $whole . '.' . $part;
576 576
     }
577 577
 
578
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
579
-        $amount = str_replace( ',', '', $amount );
578
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
579
+        $amount = str_replace(',', '', $amount);
580 580
     }
581 581
 
582
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
583
-        $amount = str_replace( ' ', '', $amount );
582
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
583
+        $amount = str_replace(' ', '', $amount);
584 584
     }
585 585
 
586
-    if ( empty( $amount ) ) {
586
+    if (empty($amount)) {
587 587
         $amount = 0;
588 588
     }
589 589
     
590
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
591
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
590
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
591
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
592 592
     
593
-    if ( $calculate ) {
594
-        if ( $thousands_sep === "," ) {
595
-            $formatted = str_replace( ",", "", $formatted );
593
+    if ($calculate) {
594
+        if ($thousands_sep === ",") {
595
+            $formatted = str_replace(",", "", $formatted);
596 596
         }
597 597
         
598
-        if ( $decimal_sep === "," ) {
599
-            $formatted = str_replace( ",", ".", $formatted );
598
+        if ($decimal_sep === ",") {
599
+            $formatted = str_replace(",", ".", $formatted);
600 600
         }
601 601
     }
602 602
 
603
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
603
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
604 604
 }
605
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
605
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
606 606
 
607
-function wpinv_sanitize_key( $key ) {
607
+function wpinv_sanitize_key($key) {
608 608
     $raw_key = $key;
609
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
609
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
610 610
 
611
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
611
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
612 612
 }
613 613
 
614
-function wpinv_get_file_extension( $str ) {
615
-    $parts = explode( '.', $str );
616
-    return end( $parts );
614
+function wpinv_get_file_extension($str) {
615
+    $parts = explode('.', $str);
616
+    return end($parts);
617 617
 }
618 618
 
619
-function wpinv_string_is_image_url( $str ) {
620
-    $ext = wpinv_get_file_extension( $str );
619
+function wpinv_string_is_image_url($str) {
620
+    $ext = wpinv_get_file_extension($str);
621 621
 
622
-    switch ( strtolower( $ext ) ) {
622
+    switch (strtolower($ext)) {
623 623
         case 'jpeg';
624 624
         case 'jpg';
625 625
             $return = true;
@@ -635,33 +635,33 @@  discard block
 block discarded – undo
635 635
             break;
636 636
     }
637 637
 
638
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
638
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
639 639
 }
640 640
 
641
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
642
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
641
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
642
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
643 643
     
644
-    if ( true === $should_log ) {
644
+    if (true === $should_log) {
645 645
         $label = '';
646
-        if ( $file && $file !== '' ) {
647
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
646
+        if ($file && $file !== '') {
647
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
648 648
         }
649 649
         
650
-        if ( $title && $title !== '' ) {
650
+        if ($title && $title !== '') {
651 651
             $label = $label !== '' ? $label . ' ' : '';
652 652
             $label .= $title . ' ';
653 653
         }
654 654
         
655
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
655
+        $label = $label !== '' ? trim($label) . ' : ' : '';
656 656
         
657
-        if ( is_array( $log ) || is_object( $log ) ) {
658
-            error_log( $label . print_r( $log, true ) );
657
+        if (is_array($log) || is_object($log)) {
658
+            error_log($label . print_r($log, true));
659 659
         } else {
660
-            error_log( $label . $log );
660
+            error_log($label . $log);
661 661
         }
662 662
 
663
-        error_log( wp_debug_backtrace_summary() );
664
-        if ( $exit ) {
663
+        error_log(wp_debug_backtrace_summary());
664
+        if ($exit) {
665 665
             exit;
666 666
         }
667 667
     }
@@ -669,32 +669,32 @@  discard block
 block discarded – undo
669 669
 
670 670
 function wpinv_is_ajax_disabled() {
671 671
     $retval = false;
672
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
672
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
673 673
 }
674 674
 
675
-function wpinv_get_current_page_url( $nocache = false ) {
675
+function wpinv_get_current_page_url($nocache = false) {
676 676
     global $wp;
677 677
 
678
-    if ( get_option( 'permalink_structure' ) ) {
679
-        $base = trailingslashit( home_url( $wp->request ) );
678
+    if (get_option('permalink_structure')) {
679
+        $base = trailingslashit(home_url($wp->request));
680 680
     } else {
681
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
682
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
681
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
682
+        $base = remove_query_arg(array('post_type', 'name'), $base);
683 683
     }
684 684
 
685 685
     $scheme = is_ssl() ? 'https' : 'http';
686
-    $uri    = set_url_scheme( $base, $scheme );
686
+    $uri    = set_url_scheme($base, $scheme);
687 687
 
688
-    if ( is_front_page() ) {
689
-        $uri = home_url( '/' );
690
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
688
+    if (is_front_page()) {
689
+        $uri = home_url('/');
690
+    } elseif (wpinv_is_checkout(array(), false)) {
691 691
         $uri = wpinv_get_checkout_uri();
692 692
     }
693 693
 
694
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
694
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
695 695
 
696
-    if ( $nocache ) {
697
-        $uri = wpinv_add_cache_busting( $uri );
696
+    if ($nocache) {
697
+        $uri = wpinv_add_cache_busting($uri);
698 698
     }
699 699
 
700 700
     return $uri;
@@ -707,46 +707,46 @@  discard block
 block discarded – undo
707 707
  * @param string $name  Constant name.
708 708
  * @param mixed  $value Value.
709 709
  */
710
-function getpaid_maybe_define_constant( $name, $value ) {
711
-	if ( ! defined( $name ) ) {
712
-		define( $name, $value );
710
+function getpaid_maybe_define_constant($name, $value) {
711
+	if (!defined($name)) {
712
+		define($name, $value);
713 713
 	}
714 714
 }
715 715
 
716 716
 function wpinv_get_php_arg_separator_output() {
717
-	return ini_get( 'arg_separator.output' );
717
+	return ini_get('arg_separator.output');
718 718
 }
719 719
 
720
-function wpinv_rgb_from_hex( $color ) {
721
-    $color = str_replace( '#', '', $color );
720
+function wpinv_rgb_from_hex($color) {
721
+    $color = str_replace('#', '', $color);
722 722
 
723 723
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
724
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
725
-    if ( empty( $color ) ) {
724
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
725
+    if (empty($color)) {
726 726
         return NULL;
727 727
     }
728 728
 
729
-    $color = str_split( $color );
729
+    $color = str_split($color);
730 730
 
731 731
     $rgb      = array();
732
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
733
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
734
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
732
+    $rgb['R'] = hexdec($color[0] . $color[1]);
733
+    $rgb['G'] = hexdec($color[2] . $color[3]);
734
+    $rgb['B'] = hexdec($color[4] . $color[5]);
735 735
 
736 736
     return $rgb;
737 737
 }
738 738
 
739
-function wpinv_hex_darker( $color, $factor = 30 ) {
740
-    $base  = wpinv_rgb_from_hex( $color );
739
+function wpinv_hex_darker($color, $factor = 30) {
740
+    $base  = wpinv_rgb_from_hex($color);
741 741
     $color = '#';
742 742
 
743
-    foreach ( $base as $k => $v ) {
743
+    foreach ($base as $k => $v) {
744 744
         $amount      = $v / 100;
745
-        $amount      = round( $amount * $factor );
745
+        $amount      = round($amount * $factor);
746 746
         $new_decimal = $v - $amount;
747 747
 
748
-        $new_hex_component = dechex( $new_decimal );
749
-        if ( strlen( $new_hex_component ) < 2 ) {
748
+        $new_hex_component = dechex($new_decimal);
749
+        if (strlen($new_hex_component) < 2) {
750 750
             $new_hex_component = "0" . $new_hex_component;
751 751
         }
752 752
         $color .= $new_hex_component;
@@ -755,18 +755,18 @@  discard block
 block discarded – undo
755 755
     return $color;
756 756
 }
757 757
 
758
-function wpinv_hex_lighter( $color, $factor = 30 ) {
759
-    $base  = wpinv_rgb_from_hex( $color );
758
+function wpinv_hex_lighter($color, $factor = 30) {
759
+    $base  = wpinv_rgb_from_hex($color);
760 760
     $color = '#';
761 761
 
762
-    foreach ( $base as $k => $v ) {
762
+    foreach ($base as $k => $v) {
763 763
         $amount      = 255 - $v;
764 764
         $amount      = $amount / 100;
765
-        $amount      = round( $amount * $factor );
765
+        $amount      = round($amount * $factor);
766 766
         $new_decimal = $v + $amount;
767 767
 
768
-        $new_hex_component = dechex( $new_decimal );
769
-        if ( strlen( $new_hex_component ) < 2 ) {
768
+        $new_hex_component = dechex($new_decimal);
769
+        if (strlen($new_hex_component) < 2) {
770 770
             $new_hex_component = "0" . $new_hex_component;
771 771
         }
772 772
         $color .= $new_hex_component;
@@ -775,22 +775,22 @@  discard block
 block discarded – undo
775 775
     return $color;
776 776
 }
777 777
 
778
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
779
-    $hex = str_replace( '#', '', $color );
778
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
779
+    $hex = str_replace('#', '', $color);
780 780
 
781
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
782
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
783
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
781
+    $c_r = hexdec(substr($hex, 0, 2));
782
+    $c_g = hexdec(substr($hex, 2, 2));
783
+    $c_b = hexdec(substr($hex, 4, 2));
784 784
 
785
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
785
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
786 786
 
787 787
     return $brightness > 155 ? $dark : $light;
788 788
 }
789 789
 
790
-function wpinv_format_hex( $hex ) {
791
-    $hex = trim( str_replace( '#', '', $hex ) );
790
+function wpinv_format_hex($hex) {
791
+    $hex = trim(str_replace('#', '', $hex));
792 792
 
793
-    if ( strlen( $hex ) == 3 ) {
793
+    if (strlen($hex) == 3) {
794 794
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
795 795
     }
796 796
 
@@ -810,12 +810,12 @@  discard block
 block discarded – undo
810 810
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
811 811
  * @return string
812 812
  */
813
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
814
-    if ( function_exists( 'mb_strimwidth' ) ) {
815
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
813
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
814
+    if (function_exists('mb_strimwidth')) {
815
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
816 816
     }
817 817
     
818
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
818
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
819 819
 }
820 820
 
821 821
 /**
@@ -827,28 +827,28 @@  discard block
 block discarded – undo
827 827
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
828 828
  * @return int Returns the number of characters in string.
829 829
  */
830
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
831
-    if ( function_exists( 'mb_strlen' ) ) {
832
-        return mb_strlen( $str, $encoding );
830
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
831
+    if (function_exists('mb_strlen')) {
832
+        return mb_strlen($str, $encoding);
833 833
     }
834 834
         
835
-    return strlen( $str );
835
+    return strlen($str);
836 836
 }
837 837
 
838
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
839
-    if ( function_exists( 'mb_strtolower' ) ) {
840
-        return mb_strtolower( $str, $encoding );
838
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
839
+    if (function_exists('mb_strtolower')) {
840
+        return mb_strtolower($str, $encoding);
841 841
     }
842 842
     
843
-    return strtolower( $str );
843
+    return strtolower($str);
844 844
 }
845 845
 
846
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
847
-    if ( function_exists( 'mb_strtoupper' ) ) {
848
-        return mb_strtoupper( $str, $encoding );
846
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
847
+    if (function_exists('mb_strtoupper')) {
848
+        return mb_strtoupper($str, $encoding);
849 849
     }
850 850
     
851
-    return strtoupper( $str );
851
+    return strtoupper($str);
852 852
 }
853 853
 
854 854
 /**
@@ -862,12 +862,12 @@  discard block
 block discarded – undo
862 862
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
863 863
  * @return int Returns the position of the first occurrence of search in the string.
864 864
  */
865
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
866
-    if ( function_exists( 'mb_strpos' ) ) {
867
-        return mb_strpos( $str, $find, $offset, $encoding );
865
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
866
+    if (function_exists('mb_strpos')) {
867
+        return mb_strpos($str, $find, $offset, $encoding);
868 868
     }
869 869
         
870
-    return strpos( $str, $find, $offset );
870
+    return strpos($str, $find, $offset);
871 871
 }
872 872
 
873 873
 /**
@@ -881,12 +881,12 @@  discard block
 block discarded – undo
881 881
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
882 882
  * @return int Returns the position of the last occurrence of search.
883 883
  */
884
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
885
-    if ( function_exists( 'mb_strrpos' ) ) {
886
-        return mb_strrpos( $str, $find, $offset, $encoding );
884
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
885
+    if (function_exists('mb_strrpos')) {
886
+        return mb_strrpos($str, $find, $offset, $encoding);
887 887
     }
888 888
         
889
-    return strrpos( $str, $find, $offset );
889
+    return strrpos($str, $find, $offset);
890 890
 }
891 891
 
892 892
 /**
@@ -901,16 +901,16 @@  discard block
 block discarded – undo
901 901
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
902 902
  * @return string
903 903
  */
904
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
905
-    if ( function_exists( 'mb_substr' ) ) {
906
-        if ( $length === null ) {
907
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
904
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
905
+    if (function_exists('mb_substr')) {
906
+        if ($length === null) {
907
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
908 908
         } else {
909
-            return mb_substr( $str, $start, $length, $encoding );
909
+            return mb_substr($str, $start, $length, $encoding);
910 910
         }
911 911
     }
912 912
         
913
-    return substr( $str, $start, $length );
913
+    return substr($str, $start, $length);
914 914
 }
915 915
 
916 916
 /**
@@ -922,48 +922,48 @@  discard block
 block discarded – undo
922 922
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
923 923
  * @return string The width of string.
924 924
  */
925
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
926
-    if ( function_exists( 'mb_strwidth' ) ) {
927
-        return mb_strwidth( $str, $encoding );
925
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
926
+    if (function_exists('mb_strwidth')) {
927
+        return mb_strwidth($str, $encoding);
928 928
     }
929 929
     
930
-    return wpinv_utf8_strlen( $str, $encoding );
930
+    return wpinv_utf8_strlen($str, $encoding);
931 931
 }
932 932
 
933
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
934
-    if ( function_exists( 'mb_strlen' ) ) {
935
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
933
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
934
+    if (function_exists('mb_strlen')) {
935
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
936 936
         $str_end = "";
937 937
         
938
-        if ( $lower_str_end ) {
939
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
938
+        if ($lower_str_end) {
939
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
940 940
         } else {
941
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
941
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
942 942
         }
943 943
 
944 944
         return $first_letter . $str_end;
945 945
     }
946 946
     
947
-    return ucfirst( $str );
947
+    return ucfirst($str);
948 948
 }
949 949
 
950
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
951
-    if ( function_exists( 'mb_convert_case' ) ) {
952
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
950
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
951
+    if (function_exists('mb_convert_case')) {
952
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
953 953
     }
954 954
     
955
-    return ucwords( $str );
955
+    return ucwords($str);
956 956
 }
957 957
 
958
-function wpinv_period_in_days( $period, $unit ) {
959
-    $period = absint( $period );
958
+function wpinv_period_in_days($period, $unit) {
959
+    $period = absint($period);
960 960
     
961
-    if ( $period > 0 ) {
962
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
961
+    if ($period > 0) {
962
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
963 963
             $period = $period * 7;
964
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
964
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
965 965
             $period = $period * 30;
966
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
966
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
967 967
             $period = $period * 365;
968 968
         }
969 969
     }
@@ -971,14 +971,14 @@  discard block
 block discarded – undo
971 971
     return $period;
972 972
 }
973 973
 
974
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
975
-    if ( function_exists( 'cal_days_in_month' ) ) {
976
-        return cal_days_in_month( $calendar, $month, $year );
974
+function wpinv_cal_days_in_month($calendar, $month, $year) {
975
+    if (function_exists('cal_days_in_month')) {
976
+        return cal_days_in_month($calendar, $month, $year);
977 977
     }
978 978
 
979 979
     // Fallback in case the calendar extension is not loaded in PHP
980 980
     // Only supports Gregorian calendar
981
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
981
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
982 982
 }
983 983
 
984 984
 /**
@@ -989,11 +989,11 @@  discard block
 block discarded – undo
989 989
  *
990 990
  * @return string
991 991
  */
992
-function wpi_help_tip( $tip, $allow_html = false ) {
993
-    if ( $allow_html ) {
994
-        $tip = wpi_sanitize_tooltip( $tip );
992
+function wpi_help_tip($tip, $allow_html = false) {
993
+    if ($allow_html) {
994
+        $tip = wpi_sanitize_tooltip($tip);
995 995
     } else {
996
-        $tip = esc_attr( $tip );
996
+        $tip = esc_attr($tip);
997 997
     }
998 998
 
999 999
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -1007,8 +1007,8 @@  discard block
 block discarded – undo
1007 1007
  * @param string $var
1008 1008
  * @return string
1009 1009
  */
1010
-function wpi_sanitize_tooltip( $var ) {
1011
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1010
+function wpi_sanitize_tooltip($var) {
1011
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1012 1012
         'br'     => array(),
1013 1013
         'em'     => array(),
1014 1014
         'strong' => array(),
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
         'li'     => array(),
1019 1019
         'ol'     => array(),
1020 1020
         'p'      => array(),
1021
-    ) ) );
1021
+    )));
1022 1022
 }
1023 1023
 
1024 1024
 /**
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
  */
1029 1029
 function wpinv_get_screen_ids() {
1030 1030
 
1031
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
1031
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
1032 1032
 
1033 1033
     $screen_ids = array(
1034 1034
         'toplevel_page_' . $screen_id,
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
         'invoicing_page_wpi-addons',
1047 1047
     );
1048 1048
 
1049
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
1049
+    return apply_filters('wpinv_screen_ids', $screen_ids);
1050 1050
 }
1051 1051
 
1052 1052
 /**
@@ -1057,9 +1057,9 @@  discard block
 block discarded – undo
1057 1057
  * @param array|string $list List of values.
1058 1058
  * @return array Sanitized array of values.
1059 1059
  */
1060
-function wpinv_parse_list( $list ) {
1061
-	if ( ! is_array( $list ) ) {
1062
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1060
+function wpinv_parse_list($list) {
1061
+	if (!is_array($list)) {
1062
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
1063 1063
 	}
1064 1064
 
1065 1065
 	return $list;
@@ -1073,16 +1073,16 @@  discard block
 block discarded – undo
1073 1073
  * @param string $key Type of data to fetch.
1074 1074
  * @return mixed Fetched data.
1075 1075
  */
1076
-function wpinv_get_data( $key ) {
1076
+function wpinv_get_data($key) {
1077 1077
     
1078 1078
     // Try fetching it from the cache.
1079
-    $data = wp_cache_get( "wpinv-$key", 'wpinv' );
1080
-    if( $data ) {
1079
+    $data = wp_cache_get("wpinv-$key", 'wpinv');
1080
+    if ($data) {
1081 1081
         return $data;
1082 1082
     }
1083 1083
 
1084
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1085
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1084
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
1085
+	wp_cache_set("wpinv-$key", $data, 'wpinv');
1086 1086
 
1087 1087
 	return $data;
1088 1088
 }
@@ -1096,10 +1096,10 @@  discard block
 block discarded – undo
1096 1096
  * @param bool $first_empty Whether or not the first item in the list should be empty
1097 1097
  * @return mixed Fetched data.
1098 1098
  */
1099
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
1099
+function wpinv_maybe_add_empty_option($options, $first_empty) {
1100 1100
 
1101
-    if ( ! empty( $options ) && $first_empty ) {
1102
-        return array_merge( array( '' => '' ), $options );
1101
+    if (!empty($options) && $first_empty) {
1102
+        return array_merge(array('' => ''), $options);
1103 1103
     }
1104 1104
     return $options;
1105 1105
 
@@ -1111,19 +1111,19 @@  discard block
 block discarded – undo
1111 1111
  * @param mixed $var Data to sanitize.
1112 1112
  * @return string|array
1113 1113
  */
1114
-function wpinv_clean( $var ) {
1114
+function wpinv_clean($var) {
1115 1115
 
1116
-	if ( is_array( $var ) ) {
1117
-		return array_map( 'wpinv_clean', $var );
1116
+	if (is_array($var)) {
1117
+		return array_map('wpinv_clean', $var);
1118 1118
     }
1119 1119
 
1120
-    if ( is_object( $var ) ) {
1121
-		$object_vars = get_object_vars( $var );
1122
-		foreach ( $object_vars as $property_name => $property_value ) {
1123
-			$var->$property_name = wpinv_clean( $property_value );
1120
+    if (is_object($var)) {
1121
+		$object_vars = get_object_vars($var);
1122
+		foreach ($object_vars as $property_name => $property_value) {
1123
+			$var->$property_name = wpinv_clean($property_value);
1124 1124
         }
1125 1125
         return $var;
1126 1126
 	}
1127 1127
     
1128
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1128
+    return is_string($var) ? sanitize_text_field($var) : $var;
1129 1129
 }
1130 1130
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-error-functions.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
         ) );
14 14
         echo '<div class="' . implode( ' ', $classes ) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
16
+            foreach ( $errors as $error_id => $error ) {
17 17
                 echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
18
-           }
18
+            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function getpaid_doing_it_wrong( $function, $message, $version ) {
81 81
 
82
-	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
82
+    $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
83 83
 
84
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
86
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
87
-	} else {
88
-		_doing_it_wrong( $function, $message, $version );
89
-	}
84
+    if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
+        do_action( 'doing_it_wrong_run', $function, $message, $version );
86
+        error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
87
+    } else {
88
+        _doing_it_wrong( $function, $message, $version );
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,61 +1,61 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_print_errors() {
8 8
     $errors = wpinv_get_errors();
9 9
 
10
-    if ( $errors ) {
11
-        $classes = apply_filters( 'wpinv_error_class', array(
10
+    if ($errors) {
11
+        $classes = apply_filters('wpinv_error_class', array(
12 12
             'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error'
13
-        ) );
14
-        echo '<div class="' . implode( ' ', $classes ) . '">';
13
+        ));
14
+        echo '<div class="' . implode(' ', $classes) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
17
-                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
16
+           foreach ($errors as $error_id => $error) {
17
+                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>';
18 18
            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
22 22
 }
23
-add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' );
24
-add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' );
23
+add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors');
24
+add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors');
25 25
 
26 26
 function wpinv_get_errors() {
27 27
     global $wpi_session;
28 28
     
29
-    return $wpi_session->get( 'wpinv_errors' );
29
+    return $wpi_session->get('wpinv_errors');
30 30
 }
31 31
 
32
-function wpinv_set_error( $error_id, $error_message ) {
32
+function wpinv_set_error($error_id, $error_message) {
33 33
     global $wpi_session;
34 34
     
35 35
     $errors = wpinv_get_errors();
36 36
 
37
-    if ( ! $errors ) {
37
+    if (!$errors) {
38 38
         $errors = array();
39 39
     }
40 40
 
41
-    $errors[ $error_id ] = $error_message;
42
-    $wpi_session->set( 'wpinv_errors', $errors );
41
+    $errors[$error_id] = $error_message;
42
+    $wpi_session->set('wpinv_errors', $errors);
43 43
 }
44 44
 
45 45
 function wpinv_clear_errors() {
46 46
     global $wpi_session;
47 47
     
48
-    $wpi_session->set( 'wpinv_errors', null );
48
+    $wpi_session->set('wpinv_errors', null);
49 49
 }
50 50
 
51
-function wpinv_unset_error( $error_id ) {
51
+function wpinv_unset_error($error_id) {
52 52
     global $wpi_session;
53 53
     
54 54
     $errors = wpinv_get_errors();
55 55
 
56
-    if ( $errors ) {
57
-        unset( $errors[ $error_id ] );
58
-        $wpi_session->set( 'wpinv_errors', $errors );
56
+    if ($errors) {
57
+        unset($errors[$error_id]);
58
+        $wpi_session->set('wpinv_errors', $errors);
59 59
     }
60 60
 }
61 61
 
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
     die();
64 64
 }
65 65
 
66
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
67
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
68
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
69
-    wp_die( $message, $title, array( 'response' => $status ));
66
+function wpinv_die($message = '', $title = '', $status = 400) {
67
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
68
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
69
+    wp_die($message, $title, array('response' => $status));
70 70
 }
71 71
 
72 72
 /**
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
  * @param string $message Message to log.
78 78
  * @param string $version Version the message was added in.
79 79
  */
80
-function getpaid_doing_it_wrong( $function, $message, $version ) {
80
+function getpaid_doing_it_wrong($function, $message, $version) {
81 81
 
82 82
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
83 83
 
84
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
86
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
84
+	if (is_ajax() || defined('REST_REQUEST')) {
85
+		do_action('doing_it_wrong_run', $function, $message, $version);
86
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
87 87
 	} else {
88
-		_doing_it_wrong( $function, $message, $version );
88
+		_doing_it_wrong($function, $message, $version);
89 89
 	}
90 90
 
91 91
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store.php 2 patches
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Data store class.
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param string $object_type Name of object.
55 55
 	 */
56
-	public function __construct( $object_type ) {
56
+	public function __construct($object_type) {
57 57
 		$this->object_type = $object_type;
58
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
58
+		$this->stores      = apply_filters('getpaid_data_stores', $this->stores);
59 59
 
60 60
 		// If this object type can't be found, check to see if we can load one
61 61
 		// level up (so if item-type isn't found, we try item).
62
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
-			$pieces      = explode( '-', $object_type );
62
+		if (!array_key_exists($object_type, $this->stores)) {
63
+			$pieces      = explode('-', $object_type);
64 64
 			$object_type = $pieces[0];
65 65
 		}
66 66
 
67
-		if ( array_key_exists( $object_type, $this->stores ) ) {
68
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
-			if ( is_object( $store ) ) {
70
-				$this->current_class_name = get_class( $store );
67
+		if (array_key_exists($object_type, $this->stores)) {
68
+			$store = apply_filters('getpaid_' . $object_type . '_data_store', $this->stores[$object_type]);
69
+			if (is_object($store)) {
70
+				$this->current_class_name = get_class($store);
71 71
 				$this->instance           = $store;
72 72
 			} else {
73
-				if ( ! class_exists( $store ) ) {
74
-					throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
73
+				if (!class_exists($store)) {
74
+					throw new Exception(__('Invalid data store.', 'invoicing'));
75 75
 				}
76 76
 				$this->current_class_name = $store;
77 77
 				$this->instance           = new $store();
78 78
 			}
79 79
 		} else {
80
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
80
+			throw new Exception(__('Invalid data store.', 'invoicing'));
81 81
 		}
82 82
 	}
83 83
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @return array
88 88
 	 */
89 89
 	public function __sleep() {
90
-		return array( 'object_type' );
90
+		return array('object_type');
91 91
 	}
92 92
 
93 93
 	/**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @throws Exception When validation fails.
97 97
 	 */
98 98
 	public function __wakeup() {
99
-		$this->__construct( $this->object_type );
99
+		$this->__construct($this->object_type);
100 100
 	}
101 101
 
102 102
 	/**
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 * @throws Exception When validation fails.
109 109
 	 * @return GetPaid_Data_Store
110 110
 	 */
111
-	public static function load( $object_type ) {
112
-		return new GetPaid_Data_Store( $object_type );
111
+	public static function load($object_type) {
112
+		return new GetPaid_Data_Store($object_type);
113 113
 	}
114 114
 
115 115
 	/**
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @since 1.0.19
129 129
 	 * @param GetPaid_Data $data GetPaid data instance.
130 130
 	 */
131
-	public function read( &$data ) {
132
-		$this->instance->read( $data );
131
+	public function read(&$data) {
132
+		$this->instance->read($data);
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	 * @since 1.0.19
139 139
 	 * @param GetPaid_Data $data GetPaid data instance.
140 140
 	 */
141
-	public function create( &$data ) {
142
-		$this->instance->create( $data );
141
+	public function create(&$data) {
142
+		$this->instance->create($data);
143 143
 	}
144 144
 
145 145
 	/**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @since 1.0.19
149 149
 	 * @param GetPaid_Data $data GetPaid data instance.
150 150
 	 */
151
-	public function update( &$data ) {
152
-		$this->instance->update( $data );
151
+	public function update(&$data) {
152
+		$this->instance->update($data);
153 153
 	}
154 154
 
155 155
 	/**
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 	 * @param GetPaid_Data $data GetPaid data instance.
160 160
 	 * @param array   $args Array of args to pass to the delete method.
161 161
 	 */
162
-	public function delete( &$data, $args = array() ) {
163
-		$this->instance->delete( $data, $args );
162
+	public function delete(&$data, $args = array()) {
163
+		$this->instance->delete($data, $args);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 * @param string $method     Method.
172 172
 	 * @return mixed
173 173
 	 */
174
-	public function __call( $method, $parameters ) {
175
-		if ( is_callable( array( $this->instance, $method ) ) ) {
176
-			$object     = array_shift( $parameters );
177
-			$parameters = array_merge( array( &$object ), $parameters );
178
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
174
+	public function __call($method, $parameters) {
175
+		if (is_callable(array($this->instance, $method))) {
176
+			$object     = array_shift($parameters);
177
+			$parameters = array_merge(array(&$object), $parameters);
178
+			return call_user_func_array(array($this->instance, $method), $parameters);
179 179
 		}
180 180
 	}
181 181
 }
Please login to merge, or discard this patch.
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -11,171 +11,171 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Data_Store {
13 13
 
14
-	/**
15
-	 * Contains an instance of the data store class that we are working with.
16
-	 *
17
-	 * @var GetPaid_Data_Store
18
-	 */
19
-	private $instance = null;
20
-
21
-	/**
22
-	 * Contains an array of default GetPaid supported data stores.
23
-	 * Format of object name => class name.
24
-	 * Example: 'item' => 'GetPaid_Item_Data_Store'
25
-	 * You can also pass something like item-<type> for item stores and
26
-	 * that type will be used first when available, if a store is requested like
27
-	 * this and doesn't exist, then the store would fall back to 'item'.
28
-	 * Ran through `getpaid_data_stores`.
29
-	 *
30
-	 * @var array
31
-	 */
32
-	private $stores = array(
33
-		'item' => 'GetPaid_Item_Data_Store',
34
-	);
35
-
36
-	/**
37
-	 * Contains the name of the current data store's class name.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	private $current_class_name = '';
42
-
43
-	/**
44
-	 * The object type this store works with.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	private $object_type = '';
49
-
50
-	/**
51
-	 * Tells GetPaid_Data_Store which object
52
-	 * store we want to work with.
53
-	 *
54
-	 * @param string $object_type Name of object.
55
-	 */
56
-	public function __construct( $object_type ) {
57
-		$this->object_type = $object_type;
58
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
59
-
60
-		// If this object type can't be found, check to see if we can load one
61
-		// level up (so if item-type isn't found, we try item).
62
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
-			$pieces      = explode( '-', $object_type );
64
-			$object_type = $pieces[0];
65
-		}
66
-
67
-		if ( array_key_exists( $object_type, $this->stores ) ) {
68
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
-			if ( is_object( $store ) ) {
70
-				$this->current_class_name = get_class( $store );
71
-				$this->instance           = $store;
72
-			} else {
73
-				if ( ! class_exists( $store ) ) {
74
-					throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
75
-				}
76
-				$this->current_class_name = $store;
77
-				$this->instance           = new $store();
78
-			}
79
-		} else {
80
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
81
-		}
82
-	}
83
-
84
-	/**
85
-	 * Only store the object type to avoid serializing the data store instance.
86
-	 *
87
-	 * @return array
88
-	 */
89
-	public function __sleep() {
90
-		return array( 'object_type' );
91
-	}
92
-
93
-	/**
94
-	 * Re-run the constructor with the object type.
95
-	 *
96
-	 * @throws Exception When validation fails.
97
-	 */
98
-	public function __wakeup() {
99
-		$this->__construct( $this->object_type );
100
-	}
101
-
102
-	/**
103
-	 * Loads a data store.
104
-	 *
105
-	 * @param string $object_type Name of object.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @throws Exception When validation fails.
109
-	 * @return GetPaid_Data_Store
110
-	 */
111
-	public static function load( $object_type ) {
112
-		return new GetPaid_Data_Store( $object_type );
113
-	}
114
-
115
-	/**
116
-	 * Returns the class name of the current data store.
117
-	 *
118
-	 * @since 1.0.19
119
-	 * @return string
120
-	 */
121
-	public function get_current_class_name() {
122
-		return $this->current_class_name;
123
-	}
124
-
125
-	/**
126
-	 * Reads an object from the data store.
127
-	 *
128
-	 * @since 1.0.19
129
-	 * @param GetPaid_Data $data GetPaid data instance.
130
-	 */
131
-	public function read( &$data ) {
132
-		$this->instance->read( $data );
133
-	}
134
-
135
-	/**
136
-	 * Create an object in the data store.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param GetPaid_Data $data GetPaid data instance.
140
-	 */
141
-	public function create( &$data ) {
142
-		$this->instance->create( $data );
143
-	}
144
-
145
-	/**
146
-	 * Update an object in the data store.
147
-	 *
148
-	 * @since 1.0.19
149
-	 * @param GetPaid_Data $data GetPaid data instance.
150
-	 */
151
-	public function update( &$data ) {
152
-		$this->instance->update( $data );
153
-	}
154
-
155
-	/**
156
-	 * Delete an object from the data store.
157
-	 *
158
-	 * @since 1.0.19
159
-	 * @param GetPaid_Data $data GetPaid data instance.
160
-	 * @param array   $args Array of args to pass to the delete method.
161
-	 */
162
-	public function delete( &$data, $args = array() ) {
163
-		$this->instance->delete( $data, $args );
164
-	}
165
-
166
-	/**
167
-	 * Data stores can define additional function. This passes
168
-	 * through to the instance if that function exists.
169
-	 *
170
-	 * @since 1.0.19
171
-	 * @param string $method     Method.
172
-	 * @return mixed
173
-	 */
174
-	public function __call( $method, $parameters ) {
175
-		if ( is_callable( array( $this->instance, $method ) ) ) {
176
-			$object     = array_shift( $parameters );
177
-			$parameters = array_merge( array( &$object ), $parameters );
178
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
179
-		}
180
-	}
14
+    /**
15
+     * Contains an instance of the data store class that we are working with.
16
+     *
17
+     * @var GetPaid_Data_Store
18
+     */
19
+    private $instance = null;
20
+
21
+    /**
22
+     * Contains an array of default GetPaid supported data stores.
23
+     * Format of object name => class name.
24
+     * Example: 'item' => 'GetPaid_Item_Data_Store'
25
+     * You can also pass something like item-<type> for item stores and
26
+     * that type will be used first when available, if a store is requested like
27
+     * this and doesn't exist, then the store would fall back to 'item'.
28
+     * Ran through `getpaid_data_stores`.
29
+     *
30
+     * @var array
31
+     */
32
+    private $stores = array(
33
+        'item' => 'GetPaid_Item_Data_Store',
34
+    );
35
+
36
+    /**
37
+     * Contains the name of the current data store's class name.
38
+     *
39
+     * @var string
40
+     */
41
+    private $current_class_name = '';
42
+
43
+    /**
44
+     * The object type this store works with.
45
+     *
46
+     * @var string
47
+     */
48
+    private $object_type = '';
49
+
50
+    /**
51
+     * Tells GetPaid_Data_Store which object
52
+     * store we want to work with.
53
+     *
54
+     * @param string $object_type Name of object.
55
+     */
56
+    public function __construct( $object_type ) {
57
+        $this->object_type = $object_type;
58
+        $this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
59
+
60
+        // If this object type can't be found, check to see if we can load one
61
+        // level up (so if item-type isn't found, we try item).
62
+        if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
+            $pieces      = explode( '-', $object_type );
64
+            $object_type = $pieces[0];
65
+        }
66
+
67
+        if ( array_key_exists( $object_type, $this->stores ) ) {
68
+            $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
+            if ( is_object( $store ) ) {
70
+                $this->current_class_name = get_class( $store );
71
+                $this->instance           = $store;
72
+            } else {
73
+                if ( ! class_exists( $store ) ) {
74
+                    throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
75
+                }
76
+                $this->current_class_name = $store;
77
+                $this->instance           = new $store();
78
+            }
79
+        } else {
80
+            throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
81
+        }
82
+    }
83
+
84
+    /**
85
+     * Only store the object type to avoid serializing the data store instance.
86
+     *
87
+     * @return array
88
+     */
89
+    public function __sleep() {
90
+        return array( 'object_type' );
91
+    }
92
+
93
+    /**
94
+     * Re-run the constructor with the object type.
95
+     *
96
+     * @throws Exception When validation fails.
97
+     */
98
+    public function __wakeup() {
99
+        $this->__construct( $this->object_type );
100
+    }
101
+
102
+    /**
103
+     * Loads a data store.
104
+     *
105
+     * @param string $object_type Name of object.
106
+     *
107
+     * @since 1.0.19
108
+     * @throws Exception When validation fails.
109
+     * @return GetPaid_Data_Store
110
+     */
111
+    public static function load( $object_type ) {
112
+        return new GetPaid_Data_Store( $object_type );
113
+    }
114
+
115
+    /**
116
+     * Returns the class name of the current data store.
117
+     *
118
+     * @since 1.0.19
119
+     * @return string
120
+     */
121
+    public function get_current_class_name() {
122
+        return $this->current_class_name;
123
+    }
124
+
125
+    /**
126
+     * Reads an object from the data store.
127
+     *
128
+     * @since 1.0.19
129
+     * @param GetPaid_Data $data GetPaid data instance.
130
+     */
131
+    public function read( &$data ) {
132
+        $this->instance->read( $data );
133
+    }
134
+
135
+    /**
136
+     * Create an object in the data store.
137
+     *
138
+     * @since 1.0.19
139
+     * @param GetPaid_Data $data GetPaid data instance.
140
+     */
141
+    public function create( &$data ) {
142
+        $this->instance->create( $data );
143
+    }
144
+
145
+    /**
146
+     * Update an object in the data store.
147
+     *
148
+     * @since 1.0.19
149
+     * @param GetPaid_Data $data GetPaid data instance.
150
+     */
151
+    public function update( &$data ) {
152
+        $this->instance->update( $data );
153
+    }
154
+
155
+    /**
156
+     * Delete an object from the data store.
157
+     *
158
+     * @since 1.0.19
159
+     * @param GetPaid_Data $data GetPaid data instance.
160
+     * @param array   $args Array of args to pass to the delete method.
161
+     */
162
+    public function delete( &$data, $args = array() ) {
163
+        $this->instance->delete( $data, $args );
164
+    }
165
+
166
+    /**
167
+     * Data stores can define additional function. This passes
168
+     * through to the instance if that function exists.
169
+     *
170
+     * @since 1.0.19
171
+     * @param string $method     Method.
172
+     * @return mixed
173
+     */
174
+    public function __call( $method, $parameters ) {
175
+        if ( is_callable( array( $this->instance, $method ) ) ) {
176
+            $object     = array_shift( $parameters );
177
+            $parameters = array_merge( array( &$object ), $parameters );
178
+            return call_user_func_array( array( $this->instance, $method ), $parameters );
179
+        }
180
+    }
181 181
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-cache-helper.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -11,121 +11,121 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Cache_Helper {
13 13
 
14
-	/**
15
-	 * Transients to delete on shutdown.
16
-	 *
17
-	 * @var array Array of transient keys.
18
-	 */
19
-	private static $delete_transients = array();
20
-
21
-	/**
22
-	 * Hook in methods.
23
-	 */
24
-	public static function init() {
25
-		add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
-		add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
27
-	}
28
-
29
-	/**
30
-	 * Add a transient to delete on shutdown.
31
-	 *
32
-	 * @since 1.0.19
33
-	 * @param string|array $keys Transient key or keys.
34
-	 */
35
-	public static function queue_delete_transient( $keys ) {
36
-		self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
37
-	}
38
-
39
-	/**
40
-	 * Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
41
-	 *
42
-	 * @since 1.0.19
43
-	 */
44
-	public static function delete_transients_on_shutdown() {
45
-		if ( self::$delete_transients ) {
46
-			foreach ( self::$delete_transients as $key ) {
47
-				delete_transient( $key );
48
-			}
49
-			self::$delete_transients = array();
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
55
-	 *
56
-	 * @param  string $group Group of cache to get.
57
-	 * @return string
58
-	 */
59
-	public static function get_cache_prefix( $group ) {
60
-		// Get cache key.
61
-		$prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
62
-
63
-		if ( false === $prefix ) {
64
-			$prefix = microtime();
65
-			wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
66
-		}
67
-
68
-		return 'getpaid_cache_' . $prefix . '_';
69
-	}
70
-
71
-	/**
72
-	 * Invalidate cache group.
73
-	 *
74
-	 * @param string $group Group of cache to clear.
75
-	 * @since 1.0.19
76
-	 */
77
-	public static function invalidate_cache_group( $group ) {
78
-		wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
79
-	}
80
-
81
-	/**
82
-	 * Prevent caching on certain pages
83
-	 */
84
-	public static function prevent_caching() {
85
-		if ( ! is_blog_installed() ) {
86
-			return;
87
-		}
88
-
89
-		if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
90
-			self::set_nocache_constants();
91
-			nocache_headers();
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Get transient version.
98
-	 *
99
-	 *
100
-	 * @param  string  $group   Name for the group of transients we need to invalidate.
101
-	 * @param  boolean $refresh true to force a new version.
102
-	 * @return string transient version based on time(), 10 digits.
103
-	 */
104
-	public static function get_transient_version( $group, $refresh = false ) {
105
-		$transient_name  = $group . '-transient-version';
106
-		$transient_value = get_transient( $transient_name );
107
-
108
-		if ( false === $transient_value || true === $refresh ) {
109
-			$transient_value = (string) time();
110
-
111
-			set_transient( $transient_name, $transient_value );
112
-		}
113
-
114
-		return $transient_value;
115
-	}
116
-
117
-	/**
118
-	 * Set constants to prevent caching by some plugins.
119
-	 *
120
-	 * @param  mixed $return Value to return. Previously hooked into a filter.
121
-	 * @return mixed
122
-	 */
123
-	public static function set_nocache_constants( $return = true ) {
124
-		getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
-		getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
-		getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
127
-		return $return;
128
-	}
14
+    /**
15
+     * Transients to delete on shutdown.
16
+     *
17
+     * @var array Array of transient keys.
18
+     */
19
+    private static $delete_transients = array();
20
+
21
+    /**
22
+     * Hook in methods.
23
+     */
24
+    public static function init() {
25
+        add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
+        add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
27
+    }
28
+
29
+    /**
30
+     * Add a transient to delete on shutdown.
31
+     *
32
+     * @since 1.0.19
33
+     * @param string|array $keys Transient key or keys.
34
+     */
35
+    public static function queue_delete_transient( $keys ) {
36
+        self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
37
+    }
38
+
39
+    /**
40
+     * Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
41
+     *
42
+     * @since 1.0.19
43
+     */
44
+    public static function delete_transients_on_shutdown() {
45
+        if ( self::$delete_transients ) {
46
+            foreach ( self::$delete_transients as $key ) {
47
+                delete_transient( $key );
48
+            }
49
+            self::$delete_transients = array();
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
55
+     *
56
+     * @param  string $group Group of cache to get.
57
+     * @return string
58
+     */
59
+    public static function get_cache_prefix( $group ) {
60
+        // Get cache key.
61
+        $prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
62
+
63
+        if ( false === $prefix ) {
64
+            $prefix = microtime();
65
+            wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
66
+        }
67
+
68
+        return 'getpaid_cache_' . $prefix . '_';
69
+    }
70
+
71
+    /**
72
+     * Invalidate cache group.
73
+     *
74
+     * @param string $group Group of cache to clear.
75
+     * @since 1.0.19
76
+     */
77
+    public static function invalidate_cache_group( $group ) {
78
+        wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
79
+    }
80
+
81
+    /**
82
+     * Prevent caching on certain pages
83
+     */
84
+    public static function prevent_caching() {
85
+        if ( ! is_blog_installed() ) {
86
+            return;
87
+        }
88
+
89
+        if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
90
+            self::set_nocache_constants();
91
+            nocache_headers();
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Get transient version.
98
+     *
99
+     *
100
+     * @param  string  $group   Name for the group of transients we need to invalidate.
101
+     * @param  boolean $refresh true to force a new version.
102
+     * @return string transient version based on time(), 10 digits.
103
+     */
104
+    public static function get_transient_version( $group, $refresh = false ) {
105
+        $transient_name  = $group . '-transient-version';
106
+        $transient_value = get_transient( $transient_name );
107
+
108
+        if ( false === $transient_value || true === $refresh ) {
109
+            $transient_value = (string) time();
110
+
111
+            set_transient( $transient_name, $transient_value );
112
+        }
113
+
114
+        return $transient_value;
115
+    }
116
+
117
+    /**
118
+     * Set constants to prevent caching by some plugins.
119
+     *
120
+     * @param  mixed $return Value to return. Previously hooked into a filter.
121
+     * @return mixed
122
+     */
123
+    public static function set_nocache_constants( $return = true ) {
124
+        getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
+        getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
+        getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
127
+        return $return;
128
+    }
129 129
 
130 130
 }
131 131
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * GetPaid_Cache_Helper.
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	 * Hook in methods.
23 23
 	 */
24 24
 	public static function init() {
25
-		add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
-		add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
25
+		add_action('shutdown', array(__CLASS__, 'delete_transients_on_shutdown'), 10);
26
+		add_action('wp', array(__CLASS__, 'prevent_caching'));
27 27
 	}
28 28
 
29 29
 	/**
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	 * @since 1.0.19
33 33
 	 * @param string|array $keys Transient key or keys.
34 34
 	 */
35
-	public static function queue_delete_transient( $keys ) {
36
-		self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
35
+	public static function queue_delete_transient($keys) {
36
+		self::$delete_transients = array_unique(array_merge(is_array($keys) ? $keys : array($keys), self::$delete_transients));
37 37
 	}
38 38
 
39 39
 	/**
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	 * @since 1.0.19
43 43
 	 */
44 44
 	public static function delete_transients_on_shutdown() {
45
-		if ( self::$delete_transients ) {
46
-			foreach ( self::$delete_transients as $key ) {
47
-				delete_transient( $key );
45
+		if (self::$delete_transients) {
46
+			foreach (self::$delete_transients as $key) {
47
+				delete_transient($key);
48 48
 			}
49 49
 			self::$delete_transients = array();
50 50
 		}
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 	 * @param  string $group Group of cache to get.
57 57
 	 * @return string
58 58
 	 */
59
-	public static function get_cache_prefix( $group ) {
59
+	public static function get_cache_prefix($group) {
60 60
 		// Get cache key.
61
-		$prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
61
+		$prefix = wp_cache_get('getpaid_' . $group . '_cache_prefix', $group);
62 62
 
63
-		if ( false === $prefix ) {
63
+		if (false === $prefix) {
64 64
 			$prefix = microtime();
65
-			wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
65
+			wp_cache_set('getpaid_' . $group . '_cache_prefix', $prefix, $group);
66 66
 		}
67 67
 
68 68
 		return 'getpaid_cache_' . $prefix . '_';
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
 	 * @param string $group Group of cache to clear.
75 75
 	 * @since 1.0.19
76 76
 	 */
77
-	public static function invalidate_cache_group( $group ) {
78
-		wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
77
+	public static function invalidate_cache_group($group) {
78
+		wp_cache_set('getpaid_' . $group . '_cache_prefix', microtime(), $group);
79 79
 	}
80 80
 
81 81
 	/**
82 82
 	 * Prevent caching on certain pages
83 83
 	 */
84 84
 	public static function prevent_caching() {
85
-		if ( ! is_blog_installed() ) {
85
+		if (!is_blog_installed()) {
86 86
 			return;
87 87
 		}
88 88
 
89
-		if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
89
+		if (wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page()) {
90 90
 			self::set_nocache_constants();
91 91
 			nocache_headers();
92 92
 		}
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 	 * @param  boolean $refresh true to force a new version.
102 102
 	 * @return string transient version based on time(), 10 digits.
103 103
 	 */
104
-	public static function get_transient_version( $group, $refresh = false ) {
104
+	public static function get_transient_version($group, $refresh = false) {
105 105
 		$transient_name  = $group . '-transient-version';
106
-		$transient_value = get_transient( $transient_name );
106
+		$transient_value = get_transient($transient_name);
107 107
 
108
-		if ( false === $transient_value || true === $refresh ) {
108
+		if (false === $transient_value || true === $refresh) {
109 109
 			$transient_value = (string) time();
110 110
 
111
-			set_transient( $transient_name, $transient_value );
111
+			set_transient($transient_name, $transient_value);
112 112
 		}
113 113
 
114 114
 		return $transient_value;
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
 	 * @param  mixed $return Value to return. Previously hooked into a filter.
121 121
 	 * @return mixed
122 122
 	 */
123
-	public static function set_nocache_constants( $return = true ) {
124
-		getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
-		getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
-		getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
123
+	public static function set_nocache_constants($return = true) {
124
+		getpaid_maybe_define_constant('DONOTCACHEPAGE', true);
125
+		getpaid_maybe_define_constant('DONOTCACHEOBJECT', true);
126
+		getpaid_maybe_define_constant('DONOTCACHEDB', true);
127 127
 		return $return;
128 128
 	}
129 129
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store-wp.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,217 +12,217 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Data_Store_WP {
14 14
 
15
-	/**
16
-	 * Meta type. This should match up with
17
-	 * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
18
-	 * WP defines 'post', 'user', 'comment', and 'term'.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $meta_type = 'post';
23
-
24
-	/**
25
-	 * This only needs set if you are using a custom metadata type (for example payment tokens.
26
-	 *
27
-	 * @var string
28
-	 */
29
-	protected $object_id_field_for_meta = '';
30
-
31
-	/**
32
-	 * Data stored in meta keys, but not considered "meta" for an object.
33
-	 *
34
-	 * @since 1.0.19
35
-	 *
36
-	 * @var array
37
-	 */
38
-	protected $internal_meta_keys = array();
39
-
40
-	/**
41
-	 * Meta data which should exist in the DB, even if empty.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $must_exist_meta_keys = array();
48
-
49
-	/**
50
-	 * Returns an array of meta for an object.
51
-	 *
52
-	 * @since  1.0.19
53
-	 * @param  GetPaid_Data $object GetPaid_Data object.
54
-	 * @return array
55
-	 */
56
-	public function read_meta( &$object ) {
57
-		global $wpdb;
58
-		$db_info       = $this->get_db_info();
59
-		$raw_meta_data = $wpdb->get_results(
60
-			$wpdb->prepare(
61
-				"SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
15
+    /**
16
+     * Meta type. This should match up with
17
+     * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
18
+     * WP defines 'post', 'user', 'comment', and 'term'.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $meta_type = 'post';
23
+
24
+    /**
25
+     * This only needs set if you are using a custom metadata type (for example payment tokens.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $object_id_field_for_meta = '';
30
+
31
+    /**
32
+     * Data stored in meta keys, but not considered "meta" for an object.
33
+     *
34
+     * @since 1.0.19
35
+     *
36
+     * @var array
37
+     */
38
+    protected $internal_meta_keys = array();
39
+
40
+    /**
41
+     * Meta data which should exist in the DB, even if empty.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $must_exist_meta_keys = array();
48
+
49
+    /**
50
+     * Returns an array of meta for an object.
51
+     *
52
+     * @since  1.0.19
53
+     * @param  GetPaid_Data $object GetPaid_Data object.
54
+     * @return array
55
+     */
56
+    public function read_meta( &$object ) {
57
+        global $wpdb;
58
+        $db_info       = $this->get_db_info();
59
+        $raw_meta_data = $wpdb->get_results(
60
+            $wpdb->prepare(
61
+                "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
62 62
 				FROM {$db_info['table']}
63 63
 				WHERE {$db_info['object_id_field']} = %d
64 64
 				ORDER BY {$db_info['meta_id_field']}",
65
-				$object->get_id()
66
-			)
67
-		);
68
-
69
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
72
-	}
73
-
74
-	/**
75
-	 * Deletes meta based on meta ID.
76
-	 *
77
-	 * @since  1.0.19
78
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
79
-	 * @param  stdClass $meta (containing at least ->id).
80
-	 */
81
-	public function delete_meta( &$object, $meta ) {
82
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
83
-	}
84
-
85
-	/**
86
-	 * Add new piece of meta.
87
-	 *
88
-	 * @since  1.0.19
89
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
90
-	 * @param  stdClass $meta (containing ->key and ->value).
91
-	 * @return int meta ID
92
-	 */
93
-	public function add_meta( &$object, $meta ) {
94
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
95
-	}
96
-
97
-	/**
98
-	 * Update meta.
99
-	 *
100
-	 * @since  1.0.19
101
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
102
-	 * @param  stdClass $meta (containing ->id, ->key and ->value).
103
-	 */
104
-	public function update_meta( &$object, $meta ) {
105
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
106
-	}
107
-
108
-	/**
109
-	 * Table structure is slightly different between meta types, this function will return what we need to know.
110
-	 *
111
-	 * @since  1.0.19
112
-	 * @return array Array elements: table, object_id_field, meta_id_field
113
-	 */
114
-	protected function get_db_info() {
115
-		global $wpdb;
116
-
117
-		$meta_id_field = 'meta_id'; // for some reason users calls this umeta_id so we need to track this as well.
118
-		$table         = $wpdb->prefix;
119
-
120
-		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
122
-			$table .= 'getpaid_';
123
-		}
124
-
125
-		$table          .= $this->meta_type . 'meta';
126
-		$object_id_field = $this->meta_type . '_id';
127
-
128
-		// Figure out our field names.
129
-		if ( 'user' === $this->meta_type ) {
130
-			$meta_id_field = 'umeta_id';
131
-			$table         = $wpdb->usermeta;
132
-		}
133
-
134
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
135
-			$object_id_field = $this->object_id_field_for_meta;
136
-		}
137
-
138
-		return array(
139
-			'table'           => $table,
140
-			'object_id_field' => $object_id_field,
141
-			'meta_id_field'   => $meta_id_field,
142
-		);
143
-	}
144
-
145
-	/**
146
-	 * Internal meta keys we don't want exposed as part of meta_data. This is in
147
-	 * addition to all data props with _ prefix.
148
-	 *
149
-	 * @since 1.0.19
150
-	 *
151
-	 * @param string $key Prefix to be added to meta keys.
152
-	 * @return string
153
-	 */
154
-	protected function prefix_key( $key ) {
155
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
156
-	}
157
-
158
-	/**
159
-	 * Callback to remove unwanted meta data.
160
-	 *
161
-	 * @param object $meta Meta object to check if it should be excluded or not.
162
-	 * @return bool
163
-	 */
164
-	protected function exclude_internal_meta_keys( $meta ) {
165
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
166
-	}
167
-
168
-	/**
169
-	 * Gets a list of props and meta keys that need updated based on change state
170
-	 * or if they are present in the database or not.
171
-	 *
172
-	 * @param  GetPaid_Data $object         The GetPaid_Data object.
173
-	 * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
174
-	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175
-	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176
-	 */
177
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
178
-		$props_to_update = array();
179
-		$changed_props   = $object->get_changes();
180
-
181
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
182
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
-				$props_to_update[ $meta_key ] = $prop;
185
-			}
186
-		}
187
-
188
-		return $props_to_update;
189
-	}
190
-
191
-	/**
192
-	 * Update meta data in, or delete it from, the database.
193
-	 *
194
-	 * Avoids storing meta when it's either an empty string or empty array or null.
195
-	 * Other empty values such as numeric 0 should still be stored.
196
-	 * Data-stores can force meta to exist using `must_exist_meta_keys`.
197
-	 *
198
-	 * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
199
-	 *
200
-	 * @param GetPaid_Data $object The GetPaid_Data object.
201
-	 * @param string  $meta_key Meta key to update.
202
-	 * @param mixed   $meta_value Value to save.
203
-	 *
204
-	 * @since 1.0.19 Added to prevent empty meta being stored unless required.
205
-	 *
206
-	 * @return bool True if updated/deleted.
207
-	 */
208
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
211
-		} else {
212
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
213
-		}
214
-
215
-		return (bool) $updated;
216
-	}
217
-
218
-	/**
219
-	 * Return list of internal meta keys.
220
-	 *
221
-	 * @since 1.0.19
222
-	 * @return array
223
-	 */
224
-	public function get_internal_meta_keys() {
225
-		return $this->internal_meta_keys;
226
-	}
65
+                $object->get_id()
66
+            )
67
+        );
68
+
69
+        $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
+        $meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
+        return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
72
+    }
73
+
74
+    /**
75
+     * Deletes meta based on meta ID.
76
+     *
77
+     * @since  1.0.19
78
+     * @param  GetPaid_Data  $object GetPaid_Data object.
79
+     * @param  stdClass $meta (containing at least ->id).
80
+     */
81
+    public function delete_meta( &$object, $meta ) {
82
+        delete_metadata_by_mid( $this->meta_type, $meta->id );
83
+    }
84
+
85
+    /**
86
+     * Add new piece of meta.
87
+     *
88
+     * @since  1.0.19
89
+     * @param  GetPaid_Data  $object GetPaid_Data object.
90
+     * @param  stdClass $meta (containing ->key and ->value).
91
+     * @return int meta ID
92
+     */
93
+    public function add_meta( &$object, $meta ) {
94
+        return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
95
+    }
96
+
97
+    /**
98
+     * Update meta.
99
+     *
100
+     * @since  1.0.19
101
+     * @param  GetPaid_Data  $object GetPaid_Data object.
102
+     * @param  stdClass $meta (containing ->id, ->key and ->value).
103
+     */
104
+    public function update_meta( &$object, $meta ) {
105
+        update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
106
+    }
107
+
108
+    /**
109
+     * Table structure is slightly different between meta types, this function will return what we need to know.
110
+     *
111
+     * @since  1.0.19
112
+     * @return array Array elements: table, object_id_field, meta_id_field
113
+     */
114
+    protected function get_db_info() {
115
+        global $wpdb;
116
+
117
+        $meta_id_field = 'meta_id'; // for some reason users calls this umeta_id so we need to track this as well.
118
+        $table         = $wpdb->prefix;
119
+
120
+        // If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
+        if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
122
+            $table .= 'getpaid_';
123
+        }
124
+
125
+        $table          .= $this->meta_type . 'meta';
126
+        $object_id_field = $this->meta_type . '_id';
127
+
128
+        // Figure out our field names.
129
+        if ( 'user' === $this->meta_type ) {
130
+            $meta_id_field = 'umeta_id';
131
+            $table         = $wpdb->usermeta;
132
+        }
133
+
134
+        if ( ! empty( $this->object_id_field_for_meta ) ) {
135
+            $object_id_field = $this->object_id_field_for_meta;
136
+        }
137
+
138
+        return array(
139
+            'table'           => $table,
140
+            'object_id_field' => $object_id_field,
141
+            'meta_id_field'   => $meta_id_field,
142
+        );
143
+    }
144
+
145
+    /**
146
+     * Internal meta keys we don't want exposed as part of meta_data. This is in
147
+     * addition to all data props with _ prefix.
148
+     *
149
+     * @since 1.0.19
150
+     *
151
+     * @param string $key Prefix to be added to meta keys.
152
+     * @return string
153
+     */
154
+    protected function prefix_key( $key ) {
155
+        return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
156
+    }
157
+
158
+    /**
159
+     * Callback to remove unwanted meta data.
160
+     *
161
+     * @param object $meta Meta object to check if it should be excluded or not.
162
+     * @return bool
163
+     */
164
+    protected function exclude_internal_meta_keys( $meta ) {
165
+        return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
166
+    }
167
+
168
+    /**
169
+     * Gets a list of props and meta keys that need updated based on change state
170
+     * or if they are present in the database or not.
171
+     *
172
+     * @param  GetPaid_Data $object         The GetPaid_Data object.
173
+     * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
174
+     * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175
+     * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176
+     */
177
+    protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
178
+        $props_to_update = array();
179
+        $changed_props   = $object->get_changes();
180
+
181
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
182
+        foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
+            if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
+                $props_to_update[ $meta_key ] = $prop;
185
+            }
186
+        }
187
+
188
+        return $props_to_update;
189
+    }
190
+
191
+    /**
192
+     * Update meta data in, or delete it from, the database.
193
+     *
194
+     * Avoids storing meta when it's either an empty string or empty array or null.
195
+     * Other empty values such as numeric 0 should still be stored.
196
+     * Data-stores can force meta to exist using `must_exist_meta_keys`.
197
+     *
198
+     * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
199
+     *
200
+     * @param GetPaid_Data $object The GetPaid_Data object.
201
+     * @param string  $meta_key Meta key to update.
202
+     * @param mixed   $meta_value Value to save.
203
+     *
204
+     * @since 1.0.19 Added to prevent empty meta being stored unless required.
205
+     *
206
+     * @return bool True if updated/deleted.
207
+     */
208
+    protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
+        if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
+            $updated = delete_post_meta( $object->get_id(), $meta_key );
211
+        } else {
212
+            $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
213
+        }
214
+
215
+        return (bool) $updated;
216
+    }
217
+
218
+    /**
219
+     * Return list of internal meta keys.
220
+     *
221
+     * @since 1.0.19
222
+     * @return array
223
+     */
224
+    public function get_internal_meta_keys() {
225
+        return $this->internal_meta_keys;
226
+    }
227 227
 
228 228
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Data_Store_WP class.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @param  GetPaid_Data $object GetPaid_Data object.
54 54
 	 * @return array
55 55
 	 */
56
-	public function read_meta( &$object ) {
56
+	public function read_meta(&$object) {
57 57
 		global $wpdb;
58 58
 		$db_info       = $this->get_db_info();
59 59
 		$raw_meta_data = $wpdb->get_results(
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 			)
67 67
 		);
68 68
 
69
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
69
+		$this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys);
70
+		$meta_data                = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys'));
71
+		return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this);
72 72
 	}
73 73
 
74 74
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
79 79
 	 * @param  stdClass $meta (containing at least ->id).
80 80
 	 */
81
-	public function delete_meta( &$object, $meta ) {
82
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
81
+	public function delete_meta(&$object, $meta) {
82
+		delete_metadata_by_mid($this->meta_type, $meta->id);
83 83
 	}
84 84
 
85 85
 	/**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @param  stdClass $meta (containing ->key and ->value).
91 91
 	 * @return int meta ID
92 92
 	 */
93
-	public function add_meta( &$object, $meta ) {
94
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
93
+	public function add_meta(&$object, $meta) {
94
+		return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false);
95 95
 	}
96 96
 
97 97
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
102 102
 	 * @param  stdClass $meta (containing ->id, ->key and ->value).
103 103
 	 */
104
-	public function update_meta( &$object, $meta ) {
105
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
104
+	public function update_meta(&$object, $meta) {
105
+		update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
106 106
 	}
107 107
 
108 108
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$table         = $wpdb->prefix;
119 119
 
120 120
 		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
121
+		if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) {
122 122
 			$table .= 'getpaid_';
123 123
 		}
124 124
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 		$object_id_field = $this->meta_type . '_id';
127 127
 
128 128
 		// Figure out our field names.
129
-		if ( 'user' === $this->meta_type ) {
129
+		if ('user' === $this->meta_type) {
130 130
 			$meta_id_field = 'umeta_id';
131 131
 			$table         = $wpdb->usermeta;
132 132
 		}
133 133
 
134
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
134
+		if (!empty($this->object_id_field_for_meta)) {
135 135
 			$object_id_field = $this->object_id_field_for_meta;
136 136
 		}
137 137
 
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	 * @param string $key Prefix to be added to meta keys.
152 152
 	 * @return string
153 153
 	 */
154
-	protected function prefix_key( $key ) {
155
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
154
+	protected function prefix_key($key) {
155
+		return '_' === substr($key, 0, 1) ? $key : '_' . $key;
156 156
 	}
157 157
 
158 158
 	/**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param object $meta Meta object to check if it should be excluded or not.
162 162
 	 * @return bool
163 163
 	 */
164
-	protected function exclude_internal_meta_keys( $meta ) {
165
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
164
+	protected function exclude_internal_meta_keys($meta) {
165
+		return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_');
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175 175
 	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176 176
 	 */
177
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
177
+	protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') {
178 178
 		$props_to_update = array();
179 179
 		$changed_props   = $object->get_changes();
180 180
 
181 181
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
182
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
-				$props_to_update[ $meta_key ] = $prop;
182
+		foreach ($meta_key_to_props as $meta_key => $prop) {
183
+			if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) {
184
+				$props_to_update[$meta_key] = $prop;
185 185
 			}
186 186
 		}
187 187
 
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 	 *
206 206
 	 * @return bool True if updated/deleted.
207 207
 	 */
208
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
208
+	protected function update_or_delete_post_meta($object, $meta_key, $meta_value) {
209
+		if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) {
210
+			$updated = delete_post_meta($object->get_id(), $meta_key);
211 211
 		} else {
212
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
212
+			$updated = update_post_meta($object->get_id(), $meta_key, $meta_value);
213 213
 		}
214 214
 
215 215
 		return (bool) $updated;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-meta-data.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -15,104 +15,104 @@
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Meta_Data implements JsonSerializable {
17 17
 
18
-	/**
19
-	 * Current data for metadata
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $current_data;
18
+    /**
19
+     * Current data for metadata
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $current_data;
25 25
 
26
-	/**
27
-	 * Metadata data
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data;
26
+    /**
27
+     * Metadata data
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data;
33 33
 
34
-	/**
35
-	 * Constructor.
36
-	 *
37
-	 * @param array $meta Data to wrap behind this function.
38
-	 */
39
-	public function __construct( $meta = array() ) {
40
-		$this->current_data = $meta;
41
-		$this->apply_changes();
42
-	}
34
+    /**
35
+     * Constructor.
36
+     *
37
+     * @param array $meta Data to wrap behind this function.
38
+     */
39
+    public function __construct( $meta = array() ) {
40
+        $this->current_data = $meta;
41
+        $this->apply_changes();
42
+    }
43 43
 
44
-	/**
45
-	 * When converted to JSON.
46
-	 *
47
-	 * @return object|array
48
-	 */
49
-	public function jsonSerialize() {
50
-		return $this->get_data();
51
-	}
44
+    /**
45
+     * When converted to JSON.
46
+     *
47
+     * @return object|array
48
+     */
49
+    public function jsonSerialize() {
50
+        return $this->get_data();
51
+    }
52 52
 
53
-	/**
54
-	 * Merge changes with data and clear.
55
-	 */
56
-	public function apply_changes() {
57
-		$this->data = $this->current_data;
58
-	}
53
+    /**
54
+     * Merge changes with data and clear.
55
+     */
56
+    public function apply_changes() {
57
+        $this->data = $this->current_data;
58
+    }
59 59
 
60
-	/**
61
-	 * Creates or updates a property in the metadata object.
62
-	 *
63
-	 * @param string $key Key to set.
64
-	 * @param mixed  $value Value to set.
65
-	 */
66
-	public function __set( $key, $value ) {
67
-		$this->current_data[ $key ] = $value;
68
-	}
60
+    /**
61
+     * Creates or updates a property in the metadata object.
62
+     *
63
+     * @param string $key Key to set.
64
+     * @param mixed  $value Value to set.
65
+     */
66
+    public function __set( $key, $value ) {
67
+        $this->current_data[ $key ] = $value;
68
+    }
69 69
 
70
-	/**
71
-	 * Checks if a given key exists in our data. This is called internally
72
-	 * by `empty` and `isset`.
73
-	 *
74
-	 * @param string $key Key to check if set.
75
-	 *
76
-	 * @return bool
77
-	 */
78
-	public function __isset( $key ) {
79
-		return array_key_exists( $key, $this->current_data );
80
-	}
70
+    /**
71
+     * Checks if a given key exists in our data. This is called internally
72
+     * by `empty` and `isset`.
73
+     *
74
+     * @param string $key Key to check if set.
75
+     *
76
+     * @return bool
77
+     */
78
+    public function __isset( $key ) {
79
+        return array_key_exists( $key, $this->current_data );
80
+    }
81 81
 
82
-	/**
83
-	 * Returns the value of any property.
84
-	 *
85
-	 * @param string $key Key to get.
86
-	 * @return mixed Property value or NULL if it does not exists
87
-	 */
88
-	public function __get( $key ) {
89
-		if ( array_key_exists( $key, $this->current_data ) ) {
90
-			return $this->current_data[ $key ];
91
-		}
92
-		return null;
93
-	}
82
+    /**
83
+     * Returns the value of any property.
84
+     *
85
+     * @param string $key Key to get.
86
+     * @return mixed Property value or NULL if it does not exists
87
+     */
88
+    public function __get( $key ) {
89
+        if ( array_key_exists( $key, $this->current_data ) ) {
90
+            return $this->current_data[ $key ];
91
+        }
92
+        return null;
93
+    }
94 94
 
95
-	/**
96
-	 * Return data changes only.
97
-	 *
98
-	 * @return array
99
-	 */
100
-	public function get_changes() {
101
-		$changes = array();
102
-		foreach ( $this->current_data as $id => $value ) {
103
-			if ( ! array_key_exists( $id, $this->data ) || $value !== $this->data[ $id ] ) {
104
-				$changes[ $id ] = $value;
105
-			}
106
-		}
107
-		return $changes;
108
-	}
95
+    /**
96
+     * Return data changes only.
97
+     *
98
+     * @return array
99
+     */
100
+    public function get_changes() {
101
+        $changes = array();
102
+        foreach ( $this->current_data as $id => $value ) {
103
+            if ( ! array_key_exists( $id, $this->data ) || $value !== $this->data[ $id ] ) {
104
+                $changes[ $id ] = $value;
105
+            }
106
+        }
107
+        return $changes;
108
+    }
109 109
 
110
-	/**
111
-	 * Return all data as an array.
112
-	 *
113
-	 * @return array
114
-	 */
115
-	public function get_data() {
116
-		return $this->data;
117
-	}
110
+    /**
111
+     * Return all data as an array.
112
+     *
113
+     * @return array
114
+     */
115
+    public function get_data() {
116
+        return $this->data;
117
+    }
118 118
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Meta data class.
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 	 *
37 37
 	 * @param array $meta Data to wrap behind this function.
38 38
 	 */
39
-	public function __construct( $meta = array() ) {
39
+	public function __construct($meta = array()) {
40 40
 		$this->current_data = $meta;
41 41
 		$this->apply_changes();
42 42
 	}
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param string $key Key to set.
64 64
 	 * @param mixed  $value Value to set.
65 65
 	 */
66
-	public function __set( $key, $value ) {
67
-		$this->current_data[ $key ] = $value;
66
+	public function __set($key, $value) {
67
+		$this->current_data[$key] = $value;
68 68
 	}
69 69
 
70 70
 	/**
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return bool
77 77
 	 */
78
-	public function __isset( $key ) {
79
-		return array_key_exists( $key, $this->current_data );
78
+	public function __isset($key) {
79
+		return array_key_exists($key, $this->current_data);
80 80
 	}
81 81
 
82 82
 	/**
@@ -85,9 +85,9 @@  discard block
 block discarded – undo
85 85
 	 * @param string $key Key to get.
86 86
 	 * @return mixed Property value or NULL if it does not exists
87 87
 	 */
88
-	public function __get( $key ) {
89
-		if ( array_key_exists( $key, $this->current_data ) ) {
90
-			return $this->current_data[ $key ];
88
+	public function __get($key) {
89
+		if (array_key_exists($key, $this->current_data)) {
90
+			return $this->current_data[$key];
91 91
 		}
92 92
 		return null;
93 93
 	}
@@ -99,9 +99,9 @@  discard block
 block discarded – undo
99 99
 	 */
100 100
 	public function get_changes() {
101 101
 		$changes = array();
102
-		foreach ( $this->current_data as $id => $value ) {
103
-			if ( ! array_key_exists( $id, $this->data ) || $value !== $this->data[ $id ] ) {
104
-				$changes[ $id ] = $value;
102
+		foreach ($this->current_data as $id => $value) {
103
+			if (!array_key_exists($id, $this->data) || $value !== $this->data[$id]) {
104
+				$changes[$id] = $value;
105 105
 			}
106 106
 		}
107 107
 		return $changes;
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -1,121 +1,121 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_use_taxes() {
8
-    $ret = wpinv_get_option( 'enable_taxes', false );
8
+    $ret = wpinv_get_option('enable_taxes', false);
9 9
     
10
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
10
+    return (bool) apply_filters('wpinv_use_taxes', $ret);
11 11
 }
12 12
 
13 13
 function wpinv_get_tax_rates() {
14
-    $rates = get_option( 'wpinv_tax_rates', array() );
14
+    $rates = get_option('wpinv_tax_rates', array());
15 15
     
16
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
16
+    return apply_filters('wpinv_get_tax_rates', $rates);
17 17
 }
18 18
 
19
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
19
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
20 20
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
21
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
21
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
22 22
     
23
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
23
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
24 24
         return $wpi_tax_rates[$item_id];
25 25
     }
26 26
     
27
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
27
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
28 28
         $wpi_tax_rates[$item_id] = 0;
29 29
         return 0;
30 30
     }
31 31
 
32 32
     $is_global = false;
33
-    if ( $item_id == 'global' ) {
33
+    if ($item_id == 'global') {
34 34
         $is_global = true;
35 35
         $item_id = 0;
36 36
     }
37 37
     
38
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
39
-    $user_address   = wpinv_get_user_address( $wpi_userID );
38
+    $rate           = (float) wpinv_get_option('tax_rate', 0);
39
+    $user_address   = wpinv_get_user_address($wpi_userID);
40 40
     
41
-    if( empty( $country ) ) {
42
-        if( !empty( $_POST['wpinv_country'] ) ) {
41
+    if (empty($country)) {
42
+        if (!empty($_POST['wpinv_country'])) {
43 43
             $country = $_POST['wpinv_country'];
44
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
44
+        } elseif (!empty($_POST['wpinv_country'])) {
45 45
             $country = $_POST['wpinv_country'];
46
-        } elseif( !empty( $_POST['country'] ) ) {
46
+        } elseif (!empty($_POST['country'])) {
47 47
             $country = $_POST['country'];
48
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
48
+        } elseif (is_user_logged_in() && !empty($user_address)) {
49 49
             $country = $user_address['country'];
50 50
         }
51
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
51
+        $country = !empty($country) ? $country : wpinv_get_default_country();
52 52
     }
53 53
 
54
-    if( empty( $state ) ) {
55
-        if( !empty( $_POST['wpinv_state'] ) ) {
54
+    if (empty($state)) {
55
+        if (!empty($_POST['wpinv_state'])) {
56 56
             $state = $_POST['wpinv_state'];
57
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
57
+        } elseif (!empty($_POST['wpinv_state'])) {
58 58
             $state = $_POST['wpinv_state'];
59
-        } elseif( !empty( $_POST['state'] ) ) {
59
+        } elseif (!empty($_POST['state'])) {
60 60
             $state = $_POST['state'];
61
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
61
+        } elseif (is_user_logged_in() && !empty($user_address)) {
62 62
             $state = $user_address['state'];
63 63
         }
64
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
64
+        $state = !empty($state) ? $state : wpinv_get_default_state();
65 65
     }
66 66
     
67
-    if( !empty( $country ) ) {
68
-        $tax_rates   = wpinv_get_tax_rates();
67
+    if (!empty($country)) {
68
+        $tax_rates = wpinv_get_tax_rates();
69 69
 
70
-        if( !empty( $tax_rates ) ) {
70
+        if (!empty($tax_rates)) {
71 71
             // Locate the tax rate for this country / state, if it exists
72
-            foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
72
+            foreach ($tax_rates as $key => $tax_rate) {
73
+                if ($country != $tax_rate['country'])
74 74
                     continue;
75 75
 
76
-                if( !empty( $tax_rate['global'] ) ) {
77
-                    if( !empty( $tax_rate['rate'] ) ) {
78
-                        $rate = number_format( $tax_rate['rate'], 4 );
76
+                if (!empty($tax_rate['global'])) {
77
+                    if (!empty($tax_rate['rate'])) {
78
+                        $rate = number_format($tax_rate['rate'], 4);
79 79
                     }
80 80
                 } else {
81 81
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
82
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
83 83
                         continue;
84 84
 
85 85
                     $state_rate = $tax_rate['rate'];
86
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
87
-                        $rate = number_format( $state_rate, 4 );
86
+                    if (0 !== $state_rate || !empty($state_rate)) {
87
+                        $rate = number_format($state_rate, 4);
88 88
                     }
89 89
                 }
90 90
             }
91 91
         }
92 92
     }
93 93
     
94
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
94
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
95 95
     
96
-    if ( !empty( $item_id ) ) {
96
+    if (!empty($item_id)) {
97 97
         $wpi_tax_rates[$item_id] = $rate;
98
-    } else if ( $is_global ) {
98
+    } else if ($is_global) {
99 99
         $wpi_tax_rates['global'] = $rate;
100 100
     }
101 101
     
102 102
     return $rate;
103 103
 }
104 104
 
105
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
106
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
107
-    $rate = round( $rate, 4 );
105
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
106
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
107
+    $rate = round($rate, 4);
108 108
     $formatted = $rate .= '%';
109
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
109
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
110 110
 }
111 111
 
112
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
113
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
112
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
113
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
114 114
     $tax  = 0.00;
115 115
 
116
-    if ( wpinv_use_taxes() ) {        
117
-        if ( wpinv_prices_include_tax() ) {
118
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
116
+    if (wpinv_use_taxes()) {        
117
+        if (wpinv_prices_include_tax()) {
118
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
119 119
             $tax     = $amount - $pre_tax;
120 120
         } else {
121 121
             $tax = $amount * $rate * 0.01;
@@ -123,46 +123,46 @@  discard block
 block discarded – undo
123 123
 
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
126
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
127 127
 }
128 128
 
129 129
 function wpinv_prices_include_tax() {
130 130
     return false; // TODO
131
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
131
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
132 132
 
133
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
133
+    return apply_filters('wpinv_prices_include_tax', $ret);
134 134
 }
135 135
 
136
-function wpinv_sales_tax_for_year( $year = null ) {
137
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
136
+function wpinv_sales_tax_for_year($year = null) {
137
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
138 138
 }
139 139
 
140
-function wpinv_get_sales_tax_for_year( $year = null ) {
140
+function wpinv_get_sales_tax_for_year($year = null) {
141 141
     global $wpdb;
142 142
 
143 143
     // Start at zero
144 144
     $tax = 0;
145 145
 
146
-    if ( ! empty( $year ) ) {
146
+    if (!empty($year)) {
147 147
         $args = array(
148 148
             'post_type'      => 'wpi_invoice',
149
-            'post_status'    => array( 'publish' ),
149
+            'post_status'    => array('publish'),
150 150
             'posts_per_page' => -1,
151 151
             'year'           => $year,
152 152
             'fields'         => 'ids'
153 153
         );
154 154
 
155
-        $payments    = get_posts( $args );
156
-        $payment_ids = implode( ',', $payments );
155
+        $payments    = get_posts($args);
156
+        $payment_ids = implode(',', $payments);
157 157
 
158
-        if ( count( $payments ) > 0 ) {
158
+        if (count($payments) > 0) {
159 159
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
160
-            $tax = $wpdb->get_var( $sql );
160
+            $tax = $wpdb->get_var($sql);
161 161
         }
162 162
 
163 163
     }
164 164
 
165
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
165
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
166 166
 }
167 167
 
168 168
 function wpinv_is_cart_taxed() {
@@ -171,33 +171,33 @@  discard block
 block discarded – undo
171 171
 
172 172
 function wpinv_prices_show_tax_on_checkout() {
173 173
     return false; // TODO
174
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
174
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
175 175
 
176
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
176
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
177 177
 }
178 178
 
179 179
 function wpinv_display_tax_rate() {
180
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
180
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
181 181
 
182
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
182
+    return apply_filters('wpinv_display_tax_rate', $ret);
183 183
 }
184 184
 
185 185
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
186
+    if (!wpinv_is_cart_taxed())
187 187
         return false;
188 188
 
189
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
189
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
190 190
 }
191 191
 
192
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
193
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
194
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
192
+function wpinv_item_is_tax_exclusive($item_id = 0) {
193
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
194
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
195 195
 }
196 196
 
197
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
197
+function wpinv_currency_decimal_filter($decimals = 2) {
198 198
     $currency = wpinv_get_currency();
199 199
 
200
-    switch ( $currency ) {
200
+    switch ($currency) {
201 201
         case 'RIAL' :
202 202
         case 'JPY' :
203 203
         case 'TWD' :
@@ -206,48 +206,48 @@  discard block
 block discarded – undo
206 206
             break;
207 207
     }
208 208
 
209
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
209
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
210 210
 }
211 211
 
212 212
 function wpinv_tax_amount() {
213 213
     $output = 0.00;
214 214
     
215
-    return apply_filters( 'wpinv_tax_amount', $output );
215
+    return apply_filters('wpinv_tax_amount', $output);
216 216
 }
217 217
 
218 218
 function wpinv_recalculated_tax() {
219
-    define( 'WPINV_RECALCTAX', true );
219
+    define('WPINV_RECALCTAX', true);
220 220
 }
221
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 );
221
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1);
222 222
 
223
-function wpinv_recalculate_tax( $return = false ) {
224
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
225
-    if ( empty( $invoice_id ) ) {
223
+function wpinv_recalculate_tax($return = false) {
224
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
225
+    if (empty($invoice_id)) {
226 226
         return false;
227 227
     }
228 228
     
229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
230 230
 
231
-    if ( empty( $invoice ) ) {
231
+    if (empty($invoice)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    if ( empty( $_POST['country'] ) ) {
235
+    if (empty($_POST['country'])) {
236 236
         $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
     }
238 238
         
239 239
     $invoice->country = sanitize_text_field($_POST['country']);
240
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
+    $invoice->set('country', sanitize_text_field($_POST['country']));
241 241
     if (isset($_POST['state'])) {
242 242
         $invoice->state = sanitize_text_field($_POST['state']);
243
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('state', sanitize_text_field($_POST['state']));
244 244
     }
245 245
 
246 246
     $invoice->cart_details  = wpinv_get_cart_content_details();
247 247
     
248
-    $subtotal               = wpinv_get_cart_subtotal( $invoice->cart_details );
249
-    $tax                    = wpinv_get_cart_tax( $invoice->cart_details );
250
-    $total                  = wpinv_get_cart_total( $invoice->cart_details );
248
+    $subtotal               = wpinv_get_cart_subtotal($invoice->cart_details);
249
+    $tax                    = wpinv_get_cart_tax($invoice->cart_details);
250
+    $total                  = wpinv_get_cart_total($invoice->cart_details);
251 251
 
252 252
     $invoice->tax           = $tax;
253 253
     $invoice->subtotal      = $subtotal;
@@ -255,61 +255,61 @@  discard block
 block discarded – undo
255 255
 
256 256
     $invoice->save();
257 257
     
258
-    if ( $invoice->is_free_trial() ) {
258
+    if ($invoice->is_free_trial()) {
259 259
         $total = 0;
260 260
     }
261 261
     
262 262
     $response = array(
263
-        'total'        => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
263
+        'total'        => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'),
264 264
         'total_raw'    => $total,
265
-        'free'         => !( (float)$total > 0 ) && $invoice->is_free() ? true : false,
266
-        'html'         => wpinv_checkout_cart( $invoice->cart_details, false ),
265
+        'free'         => !((float) $total > 0) && $invoice->is_free() ? true : false,
266
+        'html'         => wpinv_checkout_cart($invoice->cart_details, false),
267 267
     );
268 268
     
269
-    if ( $return ) {
269
+    if ($return) {
270 270
         return $response;
271 271
     }
272 272
 
273
-    wp_send_json( $response );
273
+    wp_send_json($response);
274 274
 }
275
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
276
-add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
275
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
276
+add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
277 277
 
278 278
 // VAT Settings
279
-function wpinv_vat_rate_add_callback( $args ) {
279
+function wpinv_vat_rate_add_callback($args) {
280 280
     ?>
281
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
281
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
282 282
     <?php
283 283
 }
284 284
 
285
-function wpinv_vat_rate_delete_callback( $args ) {
285
+function wpinv_vat_rate_delete_callback($args) {
286 286
     global $wpinv_euvat;
287 287
     
288 288
     $vat_classes = $wpinv_euvat->get_rate_classes();
289
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
290
-    if ( isset( $vat_classes[$vat_class] ) ) {
289
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
290
+    if (isset($vat_classes[$vat_class])) {
291 291
     ?>
292
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
292
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
293 293
     <?php
294 294
     }
295 295
 }
296 296
 
297
-function wpinv_vat_rates_callback( $args ) {
297
+function wpinv_vat_rates_callback($args) {
298 298
     global $wpinv_euvat;
299 299
     
300 300
     $vat_classes    = $wpinv_euvat->get_rate_classes();
301
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
301
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
302 302
     
303 303
     $eu_states      = $wpinv_euvat->get_eu_states();
304 304
     $countries      = wpinv_get_country_list();
305 305
     $vat_groups     = $wpinv_euvat->get_vat_groups();
306
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
306
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
307 307
     ob_start();
308 308
 ?>
309 309
 </td><tr>
310 310
     <td colspan="2" class="wpinv_vat_tdbox">
311
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
312
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
311
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
312
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
313 313
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
314 314
         <colgroup>
315 315
             <col width="50px" />
@@ -321,43 +321,43 @@  discard block
 block discarded – undo
321 321
         </colgroup>
322 322
         <thead>
323 323
             <tr>
324
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
325
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
326
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
327
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
328
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
324
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
325
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
326
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
327
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
328
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
329 329
             </tr>
330 330
         </thead>
331 331
         <tbody>
332
-        <?php if( !empty( $eu_states ) ) { ?>
332
+        <?php if (!empty($eu_states)) { ?>
333 333
         <?php 
334
-        foreach ( $eu_states as $state ) { 
335
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
334
+        foreach ($eu_states as $state) { 
335
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
336 336
             
337 337
             // Filter the rate for each country
338
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
338
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
339 339
             
340 340
             // If one does not exist create a default
341
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
341
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
342 342
             
343
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
344
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
345
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
346
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
343
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
344
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
345
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
346
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
347 347
         ?>
348 348
         <tr>
349 349
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
350 350
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
351 351
             <td class="wpinv_vat_global">
352
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
353
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
354
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
352
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
353
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
354
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
355 355
             </td>
356
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
356
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
358 358
             <td class="wpinv_vat_group">
359 359
             <?php
360
-            echo wpinv_html_select( array(
360
+            echo wpinv_html_select(array(
361 361
                                         'name'             => 'vat_rates[' . $state . '][group]',
362 362
                                         'selected'         => $vat_group,
363 363
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
                                         'multiple'         => false,
367 367
                                         'show_option_all'  => false,
368 368
                                         'show_option_none' => false
369
-                                    ) );
369
+                                    ));
370 370
             ?>
371 371
             </td>
372 372
         </tr>
373 373
         <?php } ?>
374 374
         <tr>
375 375
             <td colspan="6" style="background-color:#fafafa;">
376
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
376
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
377 377
             </td>
378 378
         </tr>
379 379
         <?php } ?>
@@ -385,35 +385,35 @@  discard block
 block discarded – undo
385 385
     echo $content;
386 386
 }
387 387
 
388
-function wpinv_vat_number_callback( $args ) {
388
+function wpinv_vat_number_callback($args) {
389 389
     global $wpinv_euvat;
390 390
     
391 391
     $vat_number     = $wpinv_euvat->get_vat_number();
392 392
     $vat_valid      = $wpinv_euvat->is_vat_validated();
393 393
 
394
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
395
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
394
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
395
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
396 396
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
397 397
     
398
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
399
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
400
-    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
402
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
398
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
399
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
400
+    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
402
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
403 403
 
404 404
     echo $html;
405 405
 }
406 406
 
407
-function wpinv_eu_fallback_rate_callback( $args ) {
407
+function wpinv_eu_fallback_rate_callback($args) {
408 408
     global $wpinv_options;
409 409
 
410
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
411
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
410
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
411
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
412 412
     
413
-    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
414
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
415
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
416
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
413
+    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
414
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
415
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
416
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
417 417
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
418 418
     echo $html;
419 419
     ?>
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
     <?php
422 422
 }
423 423
 
424
-function wpinv_vat_ip_lookup_callback( $args ) {
424
+function wpinv_vat_ip_lookup_callback($args) {
425 425
     global $wpinv_options, $wpinv_euvat;
426 426
 
427
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
427
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
428 428
     
429 429
     $options = array();
430
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
431
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
430
+    if (function_exists('geoip_country_code_by_name')) {
431
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
432 432
     }
433 433
     
434 434
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
435 435
     
436
-    if ( !function_exists( 'bcadd' ) ) {
437
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
436
+    if (!function_exists('bcadd')) {
437
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
438 438
     } else {
439
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
439
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
440 440
     }
441 441
     
442
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
443
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
442
+    if ($geoip2_database !== false && empty($geoip2_message)) {
443
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
444 444
     }
445 445
     
446
-    if ( function_exists( 'simplexml_load_file' ) ) {
447
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
446
+    if (function_exists('simplexml_load_file')) {
447
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
448 448
     }
449 449
     
450
-    $options['site']    = __( 'Use default country', 'invoicing' );
451
-    $options['default'] = __( 'Auto', 'invoicing' );
450
+    $options['site']    = __('Use default country', 'invoicing');
451
+    $options['default'] = __('Auto', 'invoicing');
452 452
 
453
-    $html = wpinv_html_select( array(
453
+    $html = wpinv_html_select(array(
454 454
         'name'             => "wpinv_settings[{$args['id']}]",
455 455
         'selected'         => $value,
456 456
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -462,23 +462,23 @@  discard block
 block discarded – undo
462 462
     ));
463 463
     
464 464
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
465
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
465
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
466 466
     $desc .= '<p>';
467
-    if ( empty( $geoip2_message ) ) {
468
-        if ( $geoip2_database ) {
467
+    if (empty($geoip2_message)) {
468
+        if ($geoip2_database) {
469 469
             $last_updated = '';
470
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
471
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
472
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
470
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
471
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
472
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
473 473
             }
474
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~30MB)', 'invoicing' ) . '"></input>';
474
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~30MB)', 'invoicing') . '"></input>';
475 475
         } else {
476
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~30MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
476
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~30MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
477 477
         }
478 478
     } else {
479 479
         $desc .= $geoip2_message;
480 480
     }
481
-    $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
481
+    $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
482 482
     $desc .= '</label>';
483 483
     
484 484
     $html .= $desc;
@@ -494,23 +494,23 @@  discard block
 block discarded – undo
494 494
  * 
495 495
  * @param string|bool|null $vat_rule
496 496
  */
497
-function getpaid_filter_vat_rule( $vat_rule ) {
497
+function getpaid_filter_vat_rule($vat_rule) {
498 498
     global $wpinv_euvat;
499 499
 
500
-    if ( empty( $vat_rule ) ) {        
500
+    if (empty($vat_rule)) {        
501 501
         return $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
502 502
     }
503 503
 
504 504
     return $vat_rule;
505 505
 }
506
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
506
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
507 507
 
508 508
 /**
509 509
  * Filters the VAT class to ensure that each item has a VAT class.
510 510
  * 
511 511
  * @param string|bool|null $vat_rule
512 512
  */
513
-function getpaid_filter_vat_class( $vat_class ) {
514
-    return empty( $vat_class ) ? '_standard' : $vat_class;
513
+function getpaid_filter_vat_class($vat_class) {
514
+    return empty($vat_class) ? '_standard' : $vat_class;
515 515
 }
516
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
517 516
\ No newline at end of file
517
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
518 518
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php 2 patches
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@
 block discarded – undo
7 7
  * Bail if we are not in WP.
8 8
  */
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit;
10
+    exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16 16
 add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
18
-	$this_version = "0.1.18";
19
-	if(version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
22
-	}
17
+    global $ayecode_ui_version,$ayecode_ui_file_key;
18
+    $this_version = "0.1.18";
19
+    if(version_compare($this_version , $ayecode_ui_version, '>')){
20
+        $ayecode_ui_version = $this_version ;
21
+        $ayecode_ui_file_key = wp_hash( __FILE__ );
22
+    }
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28 28
 add_action('after_setup_theme', function () {
29
-	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
-	}
29
+    global $ayecode_ui_file_key;
30
+    if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
+        include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
+        include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
33
+    }
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39 39
 if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
42
-			return false;
43
-		}
44
-		return AUI::instance();
45
-	}
40
+    function aui(){
41
+        if(!class_exists("AUI",false)){
42
+            return false;
43
+        }
44
+        return AUI::instance();
45
+    }
46 46
 }
47 47
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -6,39 +6,39 @@
 block discarded – undo
6 6
 /**
7 7
  * Bail if we are not in WP.
8 8
  */
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit;
11 11
 }
12 12
 
13 13
 /**
14 14
  * Set the version only if its the current newest while loading.
15 15
  */
16
-add_action('after_setup_theme', function () {
17
-	global $ayecode_ui_version,$ayecode_ui_file_key;
16
+add_action('after_setup_theme', function() {
17
+	global $ayecode_ui_version, $ayecode_ui_file_key;
18 18
 	$this_version = "0.1.18";
19
-	if(version_compare($this_version , $ayecode_ui_version, '>')){
20
-		$ayecode_ui_version = $this_version ;
21
-		$ayecode_ui_file_key = wp_hash( __FILE__ );
19
+	if (version_compare($this_version, $ayecode_ui_version, '>')) {
20
+		$ayecode_ui_version = $this_version;
21
+		$ayecode_ui_file_key = wp_hash(__FILE__);
22 22
 	}
23 23
 },0);
24 24
 
25 25
 /**
26 26
  * Load this version of WP Bootstrap Settings only if the file hash is the current one.
27 27
  */
28
-add_action('after_setup_theme', function () {
28
+add_action('after_setup_theme', function() {
29 29
 	global $ayecode_ui_file_key;
30
-	if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){
31
-		include_once( dirname( __FILE__ ) . '/includes/class-aui.php' );
32
-		include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' );
30
+	if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) {
31
+		include_once(dirname(__FILE__) . '/includes/class-aui.php');
32
+		include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php');
33 33
 	}
34 34
 },1);
35 35
 
36 36
 /**
37 37
  * Add the function that calls the class.
38 38
  */
39
-if(!function_exists('aui')){
40
-	function aui(){
41
-		if(!class_exists("AUI",false)){
39
+if (!function_exists('aui')) {
40
+	function aui() {
41
+		if (!class_exists("AUI", false)) {
42 42
 			return false;
43 43
 		}
44 44
 		return AUI::instance();
Please login to merge, or discard this patch.