@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @package Invoicing |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves the current invoice. |
@@ -14,15 +14,15 @@ discard block |
||
14 | 14 | function getpaid_get_current_invoice_id() { |
15 | 15 | |
16 | 16 | // Ensure that we have an invoice key. |
17 | - if ( empty( $_GET['invoice_key'] ) ) { |
|
17 | + if (empty($_GET['invoice_key'])) { |
|
18 | 18 | return 0; |
19 | 19 | } |
20 | 20 | |
21 | 21 | // Retrieve an invoice using the key. |
22 | - $invoice = new WPInv_Invoice( $_GET['invoice_key'] ); |
|
22 | + $invoice = new WPInv_Invoice($_GET['invoice_key']); |
|
23 | 23 | |
24 | 24 | // Compare the invoice key and the parsed key. |
25 | - if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) { |
|
25 | + if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) { |
|
26 | 26 | return $invoice->get_id(); |
27 | 27 | } |
28 | 28 | |
@@ -32,42 +32,42 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Checks if the current user cna view an invoice. |
34 | 34 | */ |
35 | -function wpinv_user_can_view_invoice( $invoice ) { |
|
36 | - $invoice = new WPInv_Invoice( $invoice ); |
|
35 | +function wpinv_user_can_view_invoice($invoice) { |
|
36 | + $invoice = new WPInv_Invoice($invoice); |
|
37 | 37 | |
38 | 38 | // Abort if the invoice does not exist. |
39 | - if ( 0 == $invoice->get_id() ) { |
|
39 | + if (0 == $invoice->get_id()) { |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 | |
43 | 43 | // Don't allow trash, draft status |
44 | - if ( $invoice->is_draft() ) { |
|
44 | + if ($invoice->is_draft()) { |
|
45 | 45 | return false; |
46 | 46 | } |
47 | 47 | |
48 | 48 | // If users are not required to login to check out, compare the invoice keys. |
49 | - if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) { |
|
49 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) { |
|
50 | 50 | return true; |
51 | 51 | } |
52 | 52 | |
53 | 53 | // Always enable for admins.. |
54 | - if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user |
|
54 | + if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user |
|
55 | 55 | return true; |
56 | 56 | } |
57 | 57 | |
58 | 58 | // Else, ensure that this is their invoice. |
59 | - if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) { |
|
59 | + if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) { |
|
60 | 60 | return true; |
61 | 61 | } |
62 | 62 | |
63 | - return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice ); |
|
63 | + return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice); |
|
64 | 64 | } |
65 | 65 | |
66 | 66 | /** |
67 | 67 | * Checks if the current user cna view an invoice receipt. |
68 | 68 | */ |
69 | -function wpinv_can_view_receipt( $invoice ) { |
|
70 | - return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice ); |
|
69 | +function wpinv_can_view_receipt($invoice) { |
|
70 | + return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | */ |
78 | 78 | function getpaid_get_invoice_post_types() { |
79 | 79 | $post_types = array( |
80 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
81 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
80 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
81 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
82 | 82 | ); |
83 | 83 | |
84 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
84 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
85 | 85 | } |
86 | 86 | |
87 | 87 | /** |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | * |
91 | 91 | * @param string $post_type The post type to check for. |
92 | 92 | */ |
93 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
94 | - return ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
93 | +function getpaid_is_invoice_post_type($post_type) { |
|
94 | + return !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | /** |
@@ -101,9 +101,9 @@ discard block |
||
101 | 101 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
102 | 102 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
103 | 103 | */ |
104 | -function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) { |
|
105 | - $data[ 'invoice_id' ] = 0; |
|
106 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
104 | +function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) { |
|
105 | + $data['invoice_id'] = 0; |
|
106 | + return wpinv_insert_invoice($data, $wp_error); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | /** |
@@ -113,36 +113,36 @@ discard block |
||
113 | 113 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
114 | 114 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
115 | 115 | */ |
116 | -function wpinv_update_invoice( $data = array(), $wp_error = false ) { |
|
116 | +function wpinv_update_invoice($data = array(), $wp_error = false) { |
|
117 | 117 | |
118 | 118 | // Backwards compatibility. |
119 | - if ( ! empty( $data['ID'] ) ) { |
|
119 | + if (!empty($data['ID'])) { |
|
120 | 120 | $data['invoice_id'] = $data['ID']; |
121 | 121 | } |
122 | 122 | |
123 | 123 | // Do we have an invoice id? |
124 | - if ( empty( $data['invoice_id'] ) ) { |
|
125 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0; |
|
124 | + if (empty($data['invoice_id'])) { |
|
125 | + return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0; |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | // Retrieve the invoice. |
129 | - $invoice = wpinv_get_invoice( $data['invoice_id'] ); |
|
129 | + $invoice = wpinv_get_invoice($data['invoice_id']); |
|
130 | 130 | |
131 | 131 | // And abort if it does not exist. |
132 | - if ( empty( $invoice ) ) { |
|
133 | - return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0; |
|
132 | + if (empty($invoice)) { |
|
133 | + return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0; |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | // Do not update totals for paid / refunded invoices. |
137 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
137 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
138 | 138 | |
139 | - if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) { |
|
140 | - return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0; |
|
139 | + if (!empty($data['items']) || !empty($data['cart_details'])) { |
|
140 | + return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | } |
144 | 144 | |
145 | - return wpinv_insert_invoice( $data, $wp_error ); |
|
145 | + return wpinv_insert_invoice($data, $wp_error); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -153,34 +153,34 @@ discard block |
||
153 | 153 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
154 | 154 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
155 | 155 | */ |
156 | -function wpinv_insert_invoice( $data = array(), $wp_error = false ) { |
|
156 | +function wpinv_insert_invoice($data = array(), $wp_error = false) { |
|
157 | 157 | |
158 | 158 | // Ensure that we have invoice data. |
159 | - if ( empty( $data ) ) { |
|
159 | + if (empty($data)) { |
|
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | |
163 | 163 | // The invoice id will be provided when updating an invoice. |
164 | - $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false; |
|
164 | + $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false; |
|
165 | 165 | |
166 | 166 | // Retrieve the invoice. |
167 | - $invoice = new WPInv_Invoice( $data['invoice_id'] ); |
|
167 | + $invoice = new WPInv_Invoice($data['invoice_id']); |
|
168 | 168 | |
169 | 169 | // Do we have an error? |
170 | - if ( ! empty( $invoice->last_error ) ) { |
|
171 | - return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0; |
|
170 | + if (!empty($invoice->last_error)) { |
|
171 | + return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // Backwards compatibility (billing address). |
175 | - if ( ! empty( $data['user_info'] ) ) { |
|
175 | + if (!empty($data['user_info'])) { |
|
176 | 176 | |
177 | - foreach ( $data['user_info'] as $key => $value ) { |
|
177 | + foreach ($data['user_info'] as $key => $value) { |
|
178 | 178 | |
179 | - if ( $key == 'discounts' ) { |
|
179 | + if ($key == 'discounts') { |
|
180 | 180 | $value = (array) $value; |
181 | - $data[ 'discount_code' ] = empty( $value ) ? null : $value[0]; |
|
181 | + $data['discount_code'] = empty($value) ? null : $value[0]; |
|
182 | 182 | } else { |
183 | - $data[ $key ] = $value; |
|
183 | + $data[$key] = $value; |
|
184 | 184 | } |
185 | 185 | |
186 | 186 | } |
@@ -188,30 +188,30 @@ discard block |
||
188 | 188 | } |
189 | 189 | |
190 | 190 | // Backwards compatibility. |
191 | - if ( ! empty( $data['payment_details'] ) ) { |
|
191 | + if (!empty($data['payment_details'])) { |
|
192 | 192 | |
193 | - foreach ( $data['payment_details'] as $key => $value ) { |
|
194 | - $data[ $key ] = $value; |
|
193 | + foreach ($data['payment_details'] as $key => $value) { |
|
194 | + $data[$key] = $value; |
|
195 | 195 | } |
196 | 196 | |
197 | 197 | } |
198 | 198 | |
199 | 199 | // Set up the owner of the invoice. |
200 | - $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id(); |
|
200 | + $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id(); |
|
201 | 201 | |
202 | 202 | // Make sure the user exists. |
203 | - if ( ! get_userdata( $user_id ) ) { |
|
204 | - return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0; |
|
203 | + if (!get_userdata($user_id)) { |
|
204 | + return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0; |
|
205 | 205 | } |
206 | 206 | |
207 | - $address = wpinv_get_user_address( $user_id ); |
|
207 | + $address = wpinv_get_user_address($user_id); |
|
208 | 208 | |
209 | - foreach ( $address as $key => $value ) { |
|
209 | + foreach ($address as $key => $value) { |
|
210 | 210 | |
211 | - if ( $value == '' ) { |
|
212 | - $address[ $key ] = null; |
|
211 | + if ($value == '') { |
|
212 | + $address[$key] = null; |
|
213 | 213 | } else { |
214 | - $address[ $key ] = wpinv_clean( $value ); |
|
214 | + $address[$key] = wpinv_clean($value); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | } |
@@ -222,103 +222,103 @@ discard block |
||
222 | 222 | array( |
223 | 223 | |
224 | 224 | // Basic info. |
225 | - 'template' => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null, |
|
226 | - 'email_cc' => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null, |
|
227 | - 'date_created' => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null, |
|
228 | - 'due_date' => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null, |
|
229 | - 'date_completed' => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null, |
|
230 | - 'number' => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null, |
|
231 | - 'key' => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null, |
|
232 | - 'status' => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null, |
|
233 | - 'post_type' => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null, |
|
234 | - 'user_ip' => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(), |
|
235 | - 'parent_id' => isset( $data['parent'] ) ? intval( $data['parent'] ) : null, |
|
236 | - 'mode' => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null, |
|
237 | - 'description' => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null, |
|
225 | + 'template' => isset($data['template']) ? wpinv_clean($data['template']) : null, |
|
226 | + 'email_cc' => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null, |
|
227 | + 'date_created' => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null, |
|
228 | + 'due_date' => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null, |
|
229 | + 'date_completed' => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null, |
|
230 | + 'number' => isset($data['number']) ? wpinv_clean($data['number']) : null, |
|
231 | + 'key' => isset($data['key']) ? wpinv_clean($data['key']) : null, |
|
232 | + 'status' => isset($data['status']) ? wpinv_clean($data['status']) : null, |
|
233 | + 'post_type' => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null, |
|
234 | + 'user_ip' => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(), |
|
235 | + 'parent_id' => isset($data['parent']) ? intval($data['parent']) : null, |
|
236 | + 'mode' => isset($data['mode']) ? wpinv_clean($data['mode']) : null, |
|
237 | + 'description' => isset($data['description']) ? wp_kses_post($data['description']) : null, |
|
238 | 238 | |
239 | 239 | // Payment info. |
240 | - 'disable_taxes' => ! empty( $data['disable_taxes'] ), |
|
241 | - 'currency' => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(), |
|
242 | - 'gateway' => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null, |
|
243 | - 'transaction_id' => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null, |
|
244 | - 'discount_code' => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null, |
|
245 | - 'payment_form' => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null, |
|
246 | - 'submission_id' => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null, |
|
247 | - 'subscription_id' => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null, |
|
248 | - 'is_viewed' => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null, |
|
249 | - 'fees' => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null, |
|
250 | - 'discounts' => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null, |
|
251 | - 'taxes' => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null, |
|
240 | + 'disable_taxes' => !empty($data['disable_taxes']), |
|
241 | + 'currency' => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(), |
|
242 | + 'gateway' => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null, |
|
243 | + 'transaction_id' => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null, |
|
244 | + 'discount_code' => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null, |
|
245 | + 'payment_form' => isset($data['payment_form']) ? intval($data['payment_form']) : null, |
|
246 | + 'submission_id' => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null, |
|
247 | + 'subscription_id' => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null, |
|
248 | + 'is_viewed' => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null, |
|
249 | + 'fees' => isset($data['fees']) ? wpinv_clean($data['fees']) : null, |
|
250 | + 'discounts' => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null, |
|
251 | + 'taxes' => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null, |
|
252 | 252 | |
253 | 253 | |
254 | 254 | // Billing details. |
255 | 255 | 'user_id' => $data['user_id'], |
256 | - 'first_name' => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'], |
|
257 | - 'last_name' => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'], |
|
258 | - 'address' => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] , |
|
259 | - 'vat_number' => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'], |
|
260 | - 'company' => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'], |
|
261 | - 'zip' => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'], |
|
262 | - 'state' => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'], |
|
263 | - 'city' => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'], |
|
264 | - 'country' => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'], |
|
265 | - 'phone' => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'], |
|
266 | - 'address_confirmed' => ! empty( $data['address_confirmed'] ), |
|
256 | + 'first_name' => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'], |
|
257 | + 'last_name' => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'], |
|
258 | + 'address' => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'], |
|
259 | + 'vat_number' => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'], |
|
260 | + 'company' => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'], |
|
261 | + 'zip' => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'], |
|
262 | + 'state' => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'], |
|
263 | + 'city' => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'], |
|
264 | + 'country' => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'], |
|
265 | + 'phone' => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'], |
|
266 | + 'address_confirmed' => !empty($data['address_confirmed']), |
|
267 | 267 | |
268 | 268 | ) |
269 | 269 | |
270 | 270 | ); |
271 | 271 | |
272 | 272 | // Backwards compatibililty. |
273 | - if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) { |
|
273 | + if (!empty($data['cart_details']) && is_array($data['cart_details'])) { |
|
274 | 274 | $data['items'] = array(); |
275 | 275 | |
276 | - foreach( $data['cart_details'] as $_item ) { |
|
276 | + foreach ($data['cart_details'] as $_item) { |
|
277 | 277 | |
278 | 278 | // Ensure that we have an item id. |
279 | - if ( empty( $_item['id'] ) ) { |
|
279 | + if (empty($_item['id'])) { |
|
280 | 280 | continue; |
281 | 281 | } |
282 | 282 | |
283 | 283 | // Retrieve the item. |
284 | - $item = new GetPaid_Form_Item( $_item['id'] ); |
|
284 | + $item = new GetPaid_Form_Item($_item['id']); |
|
285 | 285 | |
286 | 286 | // Ensure that it is purchasable. |
287 | - if ( ! $item->can_purchase() ) { |
|
287 | + if (!$item->can_purchase()) { |
|
288 | 288 | continue; |
289 | 289 | } |
290 | 290 | |
291 | 291 | // Set quantity. |
292 | - if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) { |
|
293 | - $item->set_quantity( $_item['quantity'] ); |
|
292 | + if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) { |
|
293 | + $item->set_quantity($_item['quantity']); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | // Set price. |
297 | - if ( isset( $_item['item_price'] ) ) { |
|
298 | - $item->set_price( $_item['item_price'] ); |
|
297 | + if (isset($_item['item_price'])) { |
|
298 | + $item->set_price($_item['item_price']); |
|
299 | 299 | } |
300 | 300 | |
301 | - if ( isset( $_item['custom_price'] ) ) { |
|
302 | - $item->set_price( $_item['custom_price'] ); |
|
301 | + if (isset($_item['custom_price'])) { |
|
302 | + $item->set_price($_item['custom_price']); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | // Set name. |
306 | - if ( ! empty( $_item['name'] ) ) { |
|
307 | - $item->set_name( $_item['name'] ); |
|
306 | + if (!empty($_item['name'])) { |
|
307 | + $item->set_name($_item['name']); |
|
308 | 308 | } |
309 | 309 | |
310 | 310 | // Set description. |
311 | - if ( isset( $_item['description'] ) ) { |
|
312 | - $item->set_custom_description( $_item['description'] ); |
|
311 | + if (isset($_item['description'])) { |
|
312 | + $item->set_custom_description($_item['description']); |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | // Set meta. |
316 | - if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) { |
|
316 | + if (isset($_item['meta']) && is_array($_item['meta'])) { |
|
317 | 317 | |
318 | - $item->set_item_meta( $_item['meta'] ); |
|
318 | + $item->set_item_meta($_item['meta']); |
|
319 | 319 | |
320 | - if ( isset( $_item['meta']['description'] ) ) { |
|
321 | - $item->set_custom_description( $_item['meta']['description'] ); |
|
320 | + if (isset($_item['meta']['description'])) { |
|
321 | + $item->set_custom_description($_item['meta']['description']); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | } |
@@ -329,14 +329,14 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | // Add invoice items. |
332 | - if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) { |
|
332 | + if (!empty($data['items']) && is_array($data['items'])) { |
|
333 | 333 | |
334 | - $invoice->set_items( array() ); |
|
334 | + $invoice->set_items(array()); |
|
335 | 335 | |
336 | - foreach ( $data['items'] as $item ) { |
|
336 | + foreach ($data['items'] as $item) { |
|
337 | 337 | |
338 | - if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) { |
|
339 | - $invoice->add_item( $item ); |
|
338 | + if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) { |
|
339 | + $invoice->add_item($item); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | } |
@@ -346,30 +346,30 @@ discard block |
||
346 | 346 | // Save the invoice. |
347 | 347 | $invoice->save(); |
348 | 348 | |
349 | - if ( ! $invoice->get_id() ) { |
|
350 | - return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0; |
|
349 | + if (!$invoice->get_id()) { |
|
350 | + return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | // Add private note. |
354 | - if ( ! empty( $data['private_note'] ) ) { |
|
355 | - $invoice->add_note( $data['private_note'] ); |
|
354 | + if (!empty($data['private_note'])) { |
|
355 | + $invoice->add_note($data['private_note']); |
|
356 | 356 | } |
357 | 357 | |
358 | 358 | // User notes. |
359 | - if ( !empty( $data['user_note'] ) ) { |
|
360 | - $invoice->add_note( $data['user_note'], true ); |
|
359 | + if (!empty($data['user_note'])) { |
|
360 | + $invoice->add_note($data['user_note'], true); |
|
361 | 361 | } |
362 | 362 | |
363 | 363 | // Created via. |
364 | - if ( isset( $data['created_via'] ) ) { |
|
365 | - update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] ); |
|
364 | + if (isset($data['created_via'])) { |
|
365 | + update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | // Backwards compatiblity. |
369 | - if ( $invoice->is_quote() ) { |
|
369 | + if ($invoice->is_quote()) { |
|
370 | 370 | |
371 | - if ( isset( $data['valid_until'] ) ) { |
|
372 | - update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] ); |
|
371 | + if (isset($data['valid_until'])) { |
|
372 | + update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']); |
|
373 | 373 | } |
374 | 374 | return $invoice; |
375 | 375 | |
@@ -384,18 +384,18 @@ discard block |
||
384 | 384 | * @param $bool $deprecated |
385 | 385 | * @return WPInv_Invoice|null |
386 | 386 | */ |
387 | -function wpinv_get_invoice( $invoice = 0, $deprecated = false ) { |
|
387 | +function wpinv_get_invoice($invoice = 0, $deprecated = false) { |
|
388 | 388 | |
389 | 389 | // If we are retrieving the invoice from the cart... |
390 | - if ( $deprecated && empty( $invoice ) ) { |
|
390 | + if ($deprecated && empty($invoice)) { |
|
391 | 391 | $invoice = (int) getpaid_get_current_invoice_id(); |
392 | 392 | } |
393 | 393 | |
394 | 394 | // Retrieve the invoice. |
395 | - $invoice = new WPInv_Invoice( $invoice ); |
|
395 | + $invoice = new WPInv_Invoice($invoice); |
|
396 | 396 | |
397 | 397 | // Check if it exists. |
398 | - if ( $invoice->get_id() != 0 ) { |
|
398 | + if ($invoice->get_id() != 0) { |
|
399 | 399 | return $invoice; |
400 | 400 | } |
401 | 401 | |
@@ -408,15 +408,15 @@ discard block |
||
408 | 408 | * @param array $args Args to search for. |
409 | 409 | * @return WPInv_Invoice[]|int[]|object |
410 | 410 | */ |
411 | -function wpinv_get_invoices( $args ) { |
|
411 | +function wpinv_get_invoices($args) { |
|
412 | 412 | |
413 | 413 | // Prepare args. |
414 | 414 | $args = wp_parse_args( |
415 | 415 | $args, |
416 | 416 | array( |
417 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
417 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
418 | 418 | 'type' => 'wpi_invoice', |
419 | - 'limit' => get_option( 'posts_per_page' ), |
|
419 | + 'limit' => get_option('posts_per_page'), |
|
420 | 420 | 'return' => 'objects', |
421 | 421 | ) |
422 | 422 | ); |
@@ -434,24 +434,24 @@ discard block |
||
434 | 434 | 'post__in' => 'include', |
435 | 435 | ); |
436 | 436 | |
437 | - foreach ( $map_legacy as $to => $from ) { |
|
438 | - if ( isset( $args[ $from ] ) ) { |
|
439 | - $args[ $to ] = $args[ $from ]; |
|
440 | - unset( $args[ $from ] ); |
|
437 | + foreach ($map_legacy as $to => $from) { |
|
438 | + if (isset($args[$from])) { |
|
439 | + $args[$to] = $args[$from]; |
|
440 | + unset($args[$from]); |
|
441 | 441 | } |
442 | 442 | } |
443 | 443 | |
444 | 444 | // Backwards compatibility. |
445 | - if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) { |
|
445 | + if (!empty($args['email']) && empty($args['user'])) { |
|
446 | 446 | $args['user'] = $args['email']; |
447 | - unset( $args['email'] ); |
|
447 | + unset($args['email']); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | // Handle cases where the user is set as an email. |
451 | - if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) { |
|
452 | - $user = get_user_by( 'email', $args['user'] ); |
|
451 | + if (!empty($args['author']) && is_email($args['author'])) { |
|
452 | + $user = get_user_by('email', $args['user']); |
|
453 | 453 | |
454 | - if ( $user ) { |
|
454 | + if ($user) { |
|
455 | 455 | $args['author'] = $user->user_email; |
456 | 456 | } |
457 | 457 | |
@@ -462,31 +462,31 @@ discard block |
||
462 | 462 | |
463 | 463 | // Show all posts. |
464 | 464 | $paginate = true; |
465 | - if ( isset( $args['paginate'] ) ) { |
|
465 | + if (isset($args['paginate'])) { |
|
466 | 466 | |
467 | 467 | $paginate = $args['paginate']; |
468 | - $args['no_found_rows'] = empty( $args['paginate'] ); |
|
469 | - unset( $args['paginate'] ); |
|
468 | + $args['no_found_rows'] = empty($args['paginate']); |
|
469 | + unset($args['paginate']); |
|
470 | 470 | |
471 | 471 | } |
472 | 472 | |
473 | 473 | // Whether to return objects or fields. |
474 | 474 | $return = $args['return']; |
475 | - unset( $args['return'] ); |
|
475 | + unset($args['return']); |
|
476 | 476 | |
477 | 477 | // Get invoices. |
478 | - $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) ); |
|
478 | + $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args)); |
|
479 | 479 | |
480 | 480 | // Prepare the results. |
481 | - if ( 'objects' === $return ) { |
|
482 | - $results = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
483 | - } elseif ( 'self' === $return ) { |
|
481 | + if ('objects' === $return) { |
|
482 | + $results = array_map('wpinv_get_invoice', $invoices->posts); |
|
483 | + } elseif ('self' === $return) { |
|
484 | 484 | return $invoices; |
485 | 485 | } else { |
486 | 486 | $results = $invoices->posts; |
487 | 487 | } |
488 | 488 | |
489 | - if ( $paginate ) { |
|
489 | + if ($paginate) { |
|
490 | 490 | return (object) array( |
491 | 491 | 'invoices' => $results, |
492 | 492 | 'total' => $invoices->found_posts, |
@@ -504,8 +504,8 @@ discard block |
||
504 | 504 | * @param string $transaction_id The transaction id to check. |
505 | 505 | * @return int Invoice id on success or 0 on failure |
506 | 506 | */ |
507 | -function wpinv_get_id_by_transaction_id( $transaction_id ) { |
|
508 | - return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' ); |
|
507 | +function wpinv_get_id_by_transaction_id($transaction_id) { |
|
508 | + return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id'); |
|
509 | 509 | } |
510 | 510 | |
511 | 511 | /** |
@@ -514,8 +514,8 @@ discard block |
||
514 | 514 | * @param string $invoice_number The invoice number to check. |
515 | 515 | * @return int Invoice id on success or 0 on failure |
516 | 516 | */ |
517 | -function wpinv_get_id_by_invoice_number( $invoice_number ) { |
|
518 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' ); |
|
517 | +function wpinv_get_id_by_invoice_number($invoice_number) { |
|
518 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number'); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -524,8 +524,8 @@ discard block |
||
524 | 524 | * @param string $invoice_key The invoice key to check. |
525 | 525 | * @return int Invoice id on success or 0 on failure |
526 | 526 | */ |
527 | -function wpinv_get_invoice_id_by_key( $invoice_key ) { |
|
528 | - return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' ); |
|
527 | +function wpinv_get_invoice_id_by_key($invoice_key) { |
|
528 | + return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key'); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -535,19 +535,19 @@ discard block |
||
535 | 535 | * @param string $type Optionally filter by type i.e customer|system |
536 | 536 | * @return array|null |
537 | 537 | */ |
538 | -function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) { |
|
538 | +function wpinv_get_invoice_notes($invoice = 0, $type = '') { |
|
539 | 539 | |
540 | 540 | // Prepare the invoice. |
541 | - $invoice = wpinv_get_invoice( $invoice ); |
|
542 | - if ( empty( $invoice ) ) { |
|
541 | + $invoice = wpinv_get_invoice($invoice); |
|
542 | + if (empty($invoice)) { |
|
543 | 543 | return NULL; |
544 | 544 | } |
545 | 545 | |
546 | 546 | // Fetch notes. |
547 | - $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type ); |
|
547 | + $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type); |
|
548 | 548 | |
549 | 549 | // Filter the notes. |
550 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type ); |
|
550 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -557,27 +557,27 @@ discard block |
||
557 | 557 | $columns = array( |
558 | 558 | |
559 | 559 | 'invoice-number' => array( |
560 | - 'title' => __( 'Invoice', 'invoicing' ), |
|
560 | + 'title' => __('Invoice', 'invoicing'), |
|
561 | 561 | 'class' => 'text-left' |
562 | 562 | ), |
563 | 563 | |
564 | 564 | 'created-date' => array( |
565 | - 'title' => __( 'Created Date', 'invoicing' ), |
|
565 | + 'title' => __('Created Date', 'invoicing'), |
|
566 | 566 | 'class' => 'text-left' |
567 | 567 | ), |
568 | 568 | |
569 | 569 | 'payment-date' => array( |
570 | - 'title' => __( 'Payment Date', 'invoicing' ), |
|
570 | + 'title' => __('Payment Date', 'invoicing'), |
|
571 | 571 | 'class' => 'text-left' |
572 | 572 | ), |
573 | 573 | |
574 | 574 | 'invoice-status' => array( |
575 | - 'title' => __( 'Status', 'invoicing' ), |
|
575 | + 'title' => __('Status', 'invoicing'), |
|
576 | 576 | 'class' => 'text-center' |
577 | 577 | ), |
578 | 578 | |
579 | 579 | 'invoice-total' => array( |
580 | - 'title' => __( 'Total', 'invoicing' ), |
|
580 | + 'title' => __('Total', 'invoicing'), |
|
581 | 581 | 'class' => 'text-right' |
582 | 582 | ), |
583 | 583 | |
@@ -588,7 +588,7 @@ discard block |
||
588 | 588 | |
589 | 589 | ); |
590 | 590 | |
591 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
591 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
592 | 592 | } |
593 | 593 | |
594 | 594 | /** |
@@ -598,54 +598,54 @@ discard block |
||
598 | 598 | |
599 | 599 | // Find the invoice. |
600 | 600 | $invoice_id = getpaid_get_current_invoice_id(); |
601 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
601 | + $invoice = new WPInv_Invoice($invoice_id); |
|
602 | 602 | |
603 | 603 | // Abort if non was found. |
604 | - if ( empty( $invoice_id ) || $invoice->is_draft() ) { |
|
604 | + if (empty($invoice_id) || $invoice->is_draft()) { |
|
605 | 605 | |
606 | 606 | return aui()->alert( |
607 | 607 | array( |
608 | 608 | 'type' => 'warning', |
609 | - 'content' => __( 'We could not find your invoice', 'invoicing' ), |
|
609 | + 'content' => __('We could not find your invoice', 'invoicing'), |
|
610 | 610 | ) |
611 | 611 | ); |
612 | 612 | |
613 | 613 | } |
614 | 614 | |
615 | 615 | // Can the user view this invoice? |
616 | - if ( ! wpinv_can_view_receipt( $invoice_id ) ) { |
|
616 | + if (!wpinv_can_view_receipt($invoice_id)) { |
|
617 | 617 | |
618 | 618 | return aui()->alert( |
619 | 619 | array( |
620 | 620 | 'type' => 'warning', |
621 | - 'content' => __( 'You are not allowed to view this receipt', 'invoicing' ), |
|
621 | + 'content' => __('You are not allowed to view this receipt', 'invoicing'), |
|
622 | 622 | ) |
623 | 623 | ); |
624 | 624 | |
625 | 625 | } |
626 | 626 | |
627 | 627 | // Load the template. |
628 | - return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) ); |
|
628 | + return wpinv_get_template_html('invoice-receipt.php', compact('invoice')); |
|
629 | 629 | |
630 | 630 | } |
631 | 631 | |
632 | 632 | /** |
633 | 633 | * Displays the invoice history. |
634 | 634 | */ |
635 | -function getpaid_invoice_history( $user_id = 0 ) { |
|
635 | +function getpaid_invoice_history($user_id = 0) { |
|
636 | 636 | |
637 | 637 | // Ensure that we have a user id. |
638 | - if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { |
|
638 | + if (empty($user_id) || !is_numeric($user_id)) { |
|
639 | 639 | $user_id = get_current_user_id(); |
640 | 640 | } |
641 | 641 | |
642 | 642 | // View user id. |
643 | - if ( empty( $user_id ) ) { |
|
643 | + if (empty($user_id)) { |
|
644 | 644 | |
645 | 645 | return aui()->alert( |
646 | 646 | array( |
647 | 647 | 'type' => 'warning', |
648 | - 'content' => __( 'You must be logged in to view your invoice history.', 'invoicing' ), |
|
648 | + 'content' => __('You must be logged in to view your invoice history.', 'invoicing'), |
|
649 | 649 | ) |
650 | 650 | ); |
651 | 651 | |
@@ -655,55 +655,55 @@ discard block |
||
655 | 655 | $invoices = wpinv_get_invoices( |
656 | 656 | |
657 | 657 | array( |
658 | - 'page' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
658 | + 'page' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
659 | 659 | 'user' => $user_id, |
660 | 660 | 'paginate' => true, |
661 | 661 | ) |
662 | 662 | |
663 | 663 | ); |
664 | 664 | |
665 | - if ( empty( $invoices->total ) ) { |
|
665 | + if (empty($invoices->total)) { |
|
666 | 666 | |
667 | 667 | return aui()->alert( |
668 | 668 | array( |
669 | 669 | 'type' => 'info', |
670 | - 'content' => __( 'No invoices found.', 'invoicing' ), |
|
670 | + 'content' => __('No invoices found.', 'invoicing'), |
|
671 | 671 | ) |
672 | 672 | ); |
673 | 673 | |
674 | 674 | } |
675 | 675 | |
676 | 676 | // Load the template. |
677 | - return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices' ) ); |
|
677 | + return wpinv_get_template_html('invoice-history.php', compact('invoices')); |
|
678 | 678 | |
679 | 679 | } |
680 | 680 | |
681 | 681 | /** |
682 | 682 | * Formats an invoice number given an invoice type. |
683 | 683 | */ |
684 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
684 | +function wpinv_format_invoice_number($number, $type = '') { |
|
685 | 685 | |
686 | 686 | // Allow other plugins to overide this. |
687 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
688 | - if ( null !== $check ) { |
|
687 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
688 | + if (null !== $check) { |
|
689 | 689 | return $check; |
690 | 690 | } |
691 | 691 | |
692 | 692 | // Ensure that we have a numeric number. |
693 | - if ( ! is_numeric( $number ) ) { |
|
693 | + if (!is_numeric($number)) { |
|
694 | 694 | return $number; |
695 | 695 | } |
696 | 696 | |
697 | 697 | // Format the number. |
698 | - $padd = absint( (int) wpinv_get_option( 'invoice_number_padd' ) ); |
|
699 | - $prefix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) ); |
|
700 | - $postfix = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) ); |
|
701 | - $formatted_number = zeroise( absint( $number ), $padd ); |
|
698 | + $padd = absint((int) wpinv_get_option('invoice_number_padd')); |
|
699 | + $prefix = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-')); |
|
700 | + $postfix = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix')); |
|
701 | + $formatted_number = zeroise(absint($number), $padd); |
|
702 | 702 | |
703 | 703 | // Add the prefix and post fix. |
704 | 704 | $formatted_number = $prefix . $formatted_number . $postfix; |
705 | 705 | |
706 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
706 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
707 | 707 | } |
708 | 708 | |
709 | 709 | /** |
@@ -712,58 +712,58 @@ discard block |
||
712 | 712 | * @param string $type. |
713 | 713 | * @return int|null|bool |
714 | 714 | */ |
715 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
715 | +function wpinv_get_next_invoice_number($type = '') { |
|
716 | 716 | |
717 | 717 | // Allow plugins to overide this. |
718 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
719 | - if ( null !== $check ) { |
|
718 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
719 | + if (null !== $check) { |
|
720 | 720 | return $check; |
721 | 721 | } |
722 | 722 | |
723 | 723 | // Ensure sequential invoice numbers is active. |
724 | - if ( ! wpinv_sequential_number_active() ) { |
|
724 | + if (!wpinv_sequential_number_active()) { |
|
725 | 725 | return false; |
726 | 726 | } |
727 | 727 | |
728 | 728 | // Retrieve the current number and the start number. |
729 | - $number = (int) get_option( 'wpinv_last_invoice_number', 0 ); |
|
730 | - $start = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) ); |
|
729 | + $number = (int) get_option('wpinv_last_invoice_number', 0); |
|
730 | + $start = absint((int) wpinv_get_option('invoice_sequence_start', 1)); |
|
731 | 731 | |
732 | 732 | // Ensure that we are starting at a positive integer. |
733 | - $start = max( $start, 1 ); |
|
733 | + $start = max($start, 1); |
|
734 | 734 | |
735 | 735 | // If this is the first invoice, use the start number. |
736 | - $number = max( $start, $number ); |
|
736 | + $number = max($start, $number); |
|
737 | 737 | |
738 | 738 | // Format the invoice number. |
739 | - $formatted_number = wpinv_format_invoice_number( $number, $type ); |
|
739 | + $formatted_number = wpinv_format_invoice_number($number, $type); |
|
740 | 740 | |
741 | 741 | // Ensure that this number is unique. |
742 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' ); |
|
742 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number'); |
|
743 | 743 | |
744 | 744 | // We found a match. Nice. |
745 | - if ( empty( $invoice_id ) ) { |
|
746 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
747 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
745 | + if (empty($invoice_id)) { |
|
746 | + update_option('wpinv_last_invoice_number', $number); |
|
747 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
748 | 748 | } |
749 | 749 | |
750 | - update_option( 'wpinv_last_invoice_number', $number + 1 ); |
|
751 | - return wpinv_get_next_invoice_number( $type ); |
|
750 | + update_option('wpinv_last_invoice_number', $number + 1); |
|
751 | + return wpinv_get_next_invoice_number($type); |
|
752 | 752 | |
753 | 753 | } |
754 | 754 | |
755 | 755 | /** |
756 | 756 | * The prefix used for invoice paths. |
757 | 757 | */ |
758 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
759 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
758 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
759 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
760 | 760 | } |
761 | 761 | |
762 | -function wpinv_generate_post_name( $post_ID ) { |
|
763 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
764 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
762 | +function wpinv_generate_post_name($post_ID) { |
|
763 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
764 | + $post_name = sanitize_title($prefix . $post_ID); |
|
765 | 765 | |
766 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
766 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
767 | 767 | } |
768 | 768 | |
769 | 769 | /** |
@@ -771,8 +771,8 @@ discard block |
||
771 | 771 | * |
772 | 772 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
773 | 773 | */ |
774 | -function wpinv_is_invoice_viewed( $invoice ) { |
|
775 | - $invoice = new WPInv_Invoice( $invoice ); |
|
774 | +function wpinv_is_invoice_viewed($invoice) { |
|
775 | + $invoice = new WPInv_Invoice($invoice); |
|
776 | 776 | return (bool) $invoice->get_is_viewed(); |
777 | 777 | } |
778 | 778 | |
@@ -781,17 +781,17 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object. |
783 | 783 | */ |
784 | -function getpaid_maybe_mark_invoice_as_viewed( $invoice ) { |
|
785 | - $invoice = new WPInv_Invoice( $invoice ); |
|
784 | +function getpaid_maybe_mark_invoice_as_viewed($invoice) { |
|
785 | + $invoice = new WPInv_Invoice($invoice); |
|
786 | 786 | |
787 | - if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) { |
|
788 | - $invoice->set_is_viewed( true ); |
|
787 | + if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) { |
|
788 | + $invoice->set_is_viewed(true); |
|
789 | 789 | $invoice->save(); |
790 | 790 | } |
791 | 791 | |
792 | 792 | } |
793 | -add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
794 | -add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' ); |
|
793 | +add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
794 | +add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed'); |
|
795 | 795 | |
796 | 796 | /** |
797 | 797 | * Processes an invoice refund. |
@@ -801,27 +801,27 @@ discard block |
||
801 | 801 | * @param array $status_transition |
802 | 802 | * @todo: descrease customer/store earnings |
803 | 803 | */ |
804 | -function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) { |
|
804 | +function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) { |
|
805 | 805 | |
806 | - if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) { |
|
806 | + if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) { |
|
807 | 807 | return; |
808 | 808 | } |
809 | 809 | |
810 | 810 | $discount_code = $invoice->get_discount_code(); |
811 | - if ( ! empty( $discount_code ) ) { |
|
812 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
811 | + if (!empty($discount_code)) { |
|
812 | + $discount = wpinv_get_discount_obj($discount_code); |
|
813 | 813 | |
814 | - if ( $discount->exists() ) { |
|
814 | + if ($discount->exists()) { |
|
815 | 815 | $discount->increase_usage( -1 ); |
816 | 816 | } |
817 | 817 | |
818 | 818 | } |
819 | 819 | |
820 | - do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id ); |
|
821 | - do_action( 'wpinv_refund_invoice', $invoice, $invoice_id ); |
|
822 | - do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id ); |
|
820 | + do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id); |
|
821 | + do_action('wpinv_refund_invoice', $invoice, $invoice_id); |
|
822 | + do_action('wpinv_post_refund_invoice', $invoice, $invoice_id); |
|
823 | 823 | } |
824 | -add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 ); |
|
824 | +add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3); |
|
825 | 825 | |
826 | 826 | |
827 | 827 | /** |
@@ -829,48 +829,48 @@ discard block |
||
829 | 829 | * |
830 | 830 | * @param int $invoice_id |
831 | 831 | */ |
832 | -function getpaid_process_invoice_payment( $invoice_id ) { |
|
832 | +function getpaid_process_invoice_payment($invoice_id) { |
|
833 | 833 | |
834 | 834 | // Fetch the invoice. |
835 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
835 | + $invoice = new WPInv_Invoice($invoice_id); |
|
836 | 836 | |
837 | 837 | // We only want to do this once. |
838 | - if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) { |
|
838 | + if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) { |
|
839 | 839 | return; |
840 | 840 | } |
841 | 841 | |
842 | - update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 ); |
|
842 | + update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1); |
|
843 | 843 | |
844 | 844 | // Fires when processing a payment. |
845 | - do_action( 'getpaid_process_payment', $invoice ); |
|
845 | + do_action('getpaid_process_payment', $invoice); |
|
846 | 846 | |
847 | 847 | // Fire an action for each invoice item. |
848 | - foreach( $invoice->get_items() as $item ) { |
|
849 | - do_action( 'getpaid_process_item_payment', $item, $invoice ); |
|
848 | + foreach ($invoice->get_items() as $item) { |
|
849 | + do_action('getpaid_process_item_payment', $item, $invoice); |
|
850 | 850 | } |
851 | 851 | |
852 | 852 | // Increase discount usage. |
853 | 853 | $discount_code = $invoice->get_discount_code(); |
854 | - if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) { |
|
855 | - $discount = wpinv_get_discount_obj( $discount_code ); |
|
854 | + if (!empty($discount_code) && !$invoice->is_renewal()) { |
|
855 | + $discount = wpinv_get_discount_obj($discount_code); |
|
856 | 856 | |
857 | - if ( $discount->exists() ) { |
|
857 | + if ($discount->exists()) { |
|
858 | 858 | $discount->increase_usage(); |
859 | 859 | } |
860 | 860 | |
861 | 861 | } |
862 | 862 | |
863 | 863 | // Record reverse vat. |
864 | - if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) { |
|
864 | + if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) { |
|
865 | 865 | |
866 | - if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->get_country() ) ) { |
|
867 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
866 | + if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->get_country())) { |
|
867 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
868 | 868 | } |
869 | 869 | |
870 | 870 | } |
871 | 871 | |
872 | 872 | } |
873 | -add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' ); |
|
873 | +add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment'); |
|
874 | 874 | |
875 | 875 | /** |
876 | 876 | * Returns an array of invoice item columns |
@@ -878,13 +878,13 @@ discard block |
||
878 | 878 | * @param int|WPInv_Invoice $invoice |
879 | 879 | * @return array |
880 | 880 | */ |
881 | -function getpaid_invoice_item_columns( $invoice ) { |
|
881 | +function getpaid_invoice_item_columns($invoice) { |
|
882 | 882 | |
883 | 883 | // Prepare the invoice. |
884 | - $invoice = new WPInv_Invoice( $invoice ); |
|
884 | + $invoice = new WPInv_Invoice($invoice); |
|
885 | 885 | |
886 | 886 | // Abort if there is no invoice. |
887 | - if ( 0 == $invoice->get_id() ) { |
|
887 | + if (0 == $invoice->get_id()) { |
|
888 | 888 | return array(); |
889 | 889 | } |
890 | 890 | |
@@ -892,47 +892,47 @@ discard block |
||
892 | 892 | $columns = apply_filters( |
893 | 893 | 'getpaid_invoice_item_columns', |
894 | 894 | array( |
895 | - 'name' => __( 'Item', 'invoicing' ), |
|
896 | - 'price' => __( 'Price', 'invoicing' ), |
|
897 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
898 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
895 | + 'name' => __('Item', 'invoicing'), |
|
896 | + 'price' => __('Price', 'invoicing'), |
|
897 | + 'quantity' => __('Quantity', 'invoicing'), |
|
898 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
899 | 899 | ), |
900 | 900 | $invoice |
901 | 901 | ); |
902 | 902 | |
903 | 903 | // Quantities. |
904 | - if ( isset( $columns[ 'quantity' ] ) ) { |
|
904 | + if (isset($columns['quantity'])) { |
|
905 | 905 | |
906 | - if ( 'hours' == $invoice->get_template() ) { |
|
907 | - $columns[ 'quantity' ] = __( 'Hours', 'invoicing' ); |
|
906 | + if ('hours' == $invoice->get_template()) { |
|
907 | + $columns['quantity'] = __('Hours', 'invoicing'); |
|
908 | 908 | } |
909 | 909 | |
910 | - if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) { |
|
911 | - unset( $columns[ 'quantity' ] ); |
|
910 | + if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) { |
|
911 | + unset($columns['quantity']); |
|
912 | 912 | } |
913 | 913 | |
914 | 914 | } |
915 | 915 | |
916 | 916 | |
917 | 917 | // Price. |
918 | - if ( isset( $columns[ 'price' ] ) ) { |
|
918 | + if (isset($columns['price'])) { |
|
919 | 919 | |
920 | - if ( 'amount' == $invoice->get_template() ) { |
|
921 | - $columns[ 'price' ] = __( 'Amount', 'invoicing' ); |
|
920 | + if ('amount' == $invoice->get_template()) { |
|
921 | + $columns['price'] = __('Amount', 'invoicing'); |
|
922 | 922 | } |
923 | 923 | |
924 | - if ( 'hours' == $invoice->get_template() ) { |
|
925 | - $columns[ 'price' ] = __( 'Rate', 'invoicing' ); |
|
924 | + if ('hours' == $invoice->get_template()) { |
|
925 | + $columns['price'] = __('Rate', 'invoicing'); |
|
926 | 926 | } |
927 | 927 | |
928 | 928 | } |
929 | 929 | |
930 | 930 | |
931 | 931 | // Sub total. |
932 | - if ( isset( $columns[ 'subtotal' ] ) ) { |
|
932 | + if (isset($columns['subtotal'])) { |
|
933 | 933 | |
934 | - if ( 'amount' == $invoice->get_template() ) { |
|
935 | - unset( $columns[ 'subtotal' ] ); |
|
934 | + if ('amount' == $invoice->get_template()) { |
|
935 | + unset($columns['subtotal']); |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | } |
@@ -946,30 +946,30 @@ discard block |
||
946 | 946 | * @param int|WPInv_Invoice $invoice |
947 | 947 | * @return array |
948 | 948 | */ |
949 | -function getpaid_invoice_totals_rows( $invoice ) { |
|
949 | +function getpaid_invoice_totals_rows($invoice) { |
|
950 | 950 | |
951 | 951 | // Prepare the invoice. |
952 | - $invoice = new WPInv_Invoice( $invoice ); |
|
952 | + $invoice = new WPInv_Invoice($invoice); |
|
953 | 953 | |
954 | 954 | // Abort if there is no invoice. |
955 | - if ( 0 == $invoice->get_id() ) { |
|
955 | + if (0 == $invoice->get_id()) { |
|
956 | 956 | return array(); |
957 | 957 | } |
958 | 958 | |
959 | 959 | $totals = apply_filters( |
960 | 960 | 'getpaid_invoice_totals_rows', |
961 | 961 | array( |
962 | - 'subtotal' => __( 'Subtotal', 'invoicing' ), |
|
963 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
964 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
965 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
966 | - 'total' => __( 'Total', 'invoicing' ), |
|
962 | + 'subtotal' => __('Subtotal', 'invoicing'), |
|
963 | + 'tax' => __('Tax', 'invoicing'), |
|
964 | + 'fee' => __('Fee', 'invoicing'), |
|
965 | + 'discount' => __('Discount', 'invoicing'), |
|
966 | + 'total' => __('Total', 'invoicing'), |
|
967 | 967 | ), |
968 | 968 | $invoice |
969 | 969 | ); |
970 | 970 | |
971 | - if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) { |
|
972 | - unset( $totals['tax'] ); |
|
971 | + if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) { |
|
972 | + unset($totals['tax']); |
|
973 | 973 | } |
974 | 974 | |
975 | 975 | return $totals; |
@@ -980,46 +980,46 @@ discard block |
||
980 | 980 | * |
981 | 981 | * @param WPInv_Invoice $invoice |
982 | 982 | */ |
983 | -function getpaid_new_invoice( $invoice ) { |
|
983 | +function getpaid_new_invoice($invoice) { |
|
984 | 984 | |
985 | - if ( ! $invoice->get_status() ) { |
|
985 | + if (!$invoice->get_status()) { |
|
986 | 986 | return; |
987 | 987 | } |
988 | 988 | |
989 | 989 | // Add an invoice created note. |
990 | 990 | $invoice->add_note( |
991 | 991 | wp_sprintf( |
992 | - __( 'Invoice created with the status "%s".', 'invoicing' ), |
|
993 | - wpinv_status_nicename( $invoice->get_status() ) |
|
992 | + __('Invoice created with the status "%s".', 'invoicing'), |
|
993 | + wpinv_status_nicename($invoice->get_status()) |
|
994 | 994 | ) |
995 | 995 | ); |
996 | 996 | |
997 | 997 | } |
998 | -add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' ); |
|
998 | +add_action('getpaid_new_invoice', 'getpaid_new_invoice'); |
|
999 | 999 | |
1000 | 1000 | /** |
1001 | 1001 | * This function updates invoice caches. |
1002 | 1002 | * |
1003 | 1003 | * @param WPInv_Invoice $invoice |
1004 | 1004 | */ |
1005 | -function getpaid_update_invoice_caches( $invoice ) { |
|
1005 | +function getpaid_update_invoice_caches($invoice) { |
|
1006 | 1006 | |
1007 | 1007 | // Cache invoice number. |
1008 | - wp_cache_set( $invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids" ); |
|
1008 | + wp_cache_set($invoice->get_number(), $invoice->get_id(), "getpaid_invoice_numbers_to_invoice_ids"); |
|
1009 | 1009 | |
1010 | 1010 | // Cache invoice key. |
1011 | - wp_cache_set( $invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids" ); |
|
1011 | + wp_cache_set($invoice->get_key(), $invoice->get_id(), "getpaid_invoice_keys_to_invoice_ids"); |
|
1012 | 1012 | |
1013 | 1013 | // (Maybe) cache transaction id. |
1014 | 1014 | $transaction_id = $invoice->get_transaction_id(); |
1015 | 1015 | |
1016 | - if ( ! empty( $transaction_id ) ) { |
|
1017 | - wp_cache_set( $transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids" ); |
|
1016 | + if (!empty($transaction_id)) { |
|
1017 | + wp_cache_set($transaction_id, $invoice->get_id(), "getpaid_invoice_transaction_ids_to_invoice_ids"); |
|
1018 | 1018 | } |
1019 | 1019 | |
1020 | 1020 | } |
1021 | -add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1022 | -add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 ); |
|
1021 | +add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5); |
|
1022 | +add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5); |
|
1023 | 1023 | |
1024 | 1024 | /** |
1025 | 1025 | * Duplicates an invoice. |
@@ -1029,7 +1029,7 @@ discard block |
||
1029 | 1029 | * @param WPInv_Invoice $old_invoice The invoice to duplicate |
1030 | 1030 | * @return WPInv_Invoice The new invoice. |
1031 | 1031 | */ |
1032 | -function getpaid_duplicate_invoice( $old_invoice ) { |
|
1032 | +function getpaid_duplicate_invoice($old_invoice) { |
|
1033 | 1033 | |
1034 | 1034 | // Create the new invoice. |
1035 | 1035 | $invoice = new WPInv_Invoice(); |
@@ -1090,126 +1090,126 @@ discard block |
||
1090 | 1090 | * @param WPInv_Invoice $invoice |
1091 | 1091 | * @return array |
1092 | 1092 | */ |
1093 | -function getpaid_get_invoice_meta( $invoice ) { |
|
1093 | +function getpaid_get_invoice_meta($invoice) { |
|
1094 | 1094 | |
1095 | 1095 | // Load the invoice meta. |
1096 | 1096 | $meta = array( |
1097 | 1097 | |
1098 | 1098 | 'number' => array( |
1099 | 1099 | 'label' => sprintf( |
1100 | - __( '%s Number', 'invoicing' ), |
|
1101 | - ucfirst( $invoice->get_type() ) |
|
1100 | + __('%s Number', 'invoicing'), |
|
1101 | + ucfirst($invoice->get_type()) |
|
1102 | 1102 | ), |
1103 | - 'value' => sanitize_text_field( $invoice->get_number() ), |
|
1103 | + 'value' => sanitize_text_field($invoice->get_number()), |
|
1104 | 1104 | ), |
1105 | 1105 | |
1106 | 1106 | 'status' => array( |
1107 | 1107 | 'label' => sprintf( |
1108 | - __( '%s Status', 'invoicing' ), |
|
1109 | - ucfirst( $invoice->get_type() ) |
|
1108 | + __('%s Status', 'invoicing'), |
|
1109 | + ucfirst($invoice->get_type()) |
|
1110 | 1110 | ), |
1111 | 1111 | 'value' => $invoice->get_status_label_html(), |
1112 | 1112 | ), |
1113 | 1113 | |
1114 | 1114 | 'date' => array( |
1115 | 1115 | 'label' => sprintf( |
1116 | - __( '%s Date', 'invoicing' ), |
|
1117 | - ucfirst( $invoice->get_type() ) |
|
1116 | + __('%s Date', 'invoicing'), |
|
1117 | + ucfirst($invoice->get_type()) |
|
1118 | 1118 | ), |
1119 | - 'value' => getpaid_format_date( $invoice->get_created_date() ), |
|
1119 | + 'value' => getpaid_format_date($invoice->get_created_date()), |
|
1120 | 1120 | ), |
1121 | 1121 | |
1122 | 1122 | 'date_paid' => array( |
1123 | - 'label' => __( 'Paid On', 'invoicing' ), |
|
1124 | - 'value' => getpaid_format_date( $invoice->get_completed_date() ), |
|
1123 | + 'label' => __('Paid On', 'invoicing'), |
|
1124 | + 'value' => getpaid_format_date($invoice->get_completed_date()), |
|
1125 | 1125 | ), |
1126 | 1126 | |
1127 | 1127 | 'gateway' => array( |
1128 | - 'label' => __( 'Payment Method', 'invoicing' ), |
|
1129 | - 'value' => sanitize_text_field( $invoice->get_gateway_title() ), |
|
1128 | + 'label' => __('Payment Method', 'invoicing'), |
|
1129 | + 'value' => sanitize_text_field($invoice->get_gateway_title()), |
|
1130 | 1130 | ), |
1131 | 1131 | |
1132 | 1132 | 'transaction_id' => array( |
1133 | - 'label' => __( 'Transaction ID', 'invoicing' ), |
|
1134 | - 'value' => sanitize_text_field( $invoice->get_transaction_id() ), |
|
1133 | + 'label' => __('Transaction ID', 'invoicing'), |
|
1134 | + 'value' => sanitize_text_field($invoice->get_transaction_id()), |
|
1135 | 1135 | ), |
1136 | 1136 | |
1137 | 1137 | 'due_date' => array( |
1138 | - 'label' => __( 'Due Date', 'invoicing' ), |
|
1139 | - 'value' => getpaid_format_date( $invoice->get_due_date() ), |
|
1138 | + 'label' => __('Due Date', 'invoicing'), |
|
1139 | + 'value' => getpaid_format_date($invoice->get_due_date()), |
|
1140 | 1140 | ), |
1141 | 1141 | |
1142 | 1142 | 'vat_number' => array( |
1143 | 1143 | 'label' => sprintf( |
1144 | - __( '%s Number', 'invoicing' ), |
|
1144 | + __('%s Number', 'invoicing'), |
|
1145 | 1145 | getpaid_tax()->get_vat_name() |
1146 | 1146 | ), |
1147 | - 'value' => sanitize_text_field( $invoice->get_vat_number() ), |
|
1147 | + 'value' => sanitize_text_field($invoice->get_vat_number()), |
|
1148 | 1148 | ), |
1149 | 1149 | |
1150 | 1150 | ); |
1151 | 1151 | |
1152 | 1152 | // If it is not paid, remove the date of payment. |
1153 | - if ( ! $invoice->is_paid() ) { |
|
1154 | - unset( $meta[ 'date_paid' ] ); |
|
1155 | - unset( $meta[ 'transaction_id' ] ); |
|
1153 | + if (!$invoice->is_paid()) { |
|
1154 | + unset($meta['date_paid']); |
|
1155 | + unset($meta['transaction_id']); |
|
1156 | 1156 | } |
1157 | 1157 | |
1158 | - if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) { |
|
1159 | - unset( $meta[ 'gateway' ] ); |
|
1158 | + if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) { |
|
1159 | + unset($meta['gateway']); |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | // Only display the due date if due dates are enabled. |
1163 | - if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) { |
|
1164 | - unset( $meta[ 'due_date' ] ); |
|
1163 | + if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) { |
|
1164 | + unset($meta['due_date']); |
|
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | // Only display the vat number if taxes are enabled. |
1168 | - if ( ! wpinv_use_taxes() ) { |
|
1169 | - unset( $meta[ 'vat_number' ] ); |
|
1168 | + if (!wpinv_use_taxes()) { |
|
1169 | + unset($meta['vat_number']); |
|
1170 | 1170 | } |
1171 | 1171 | |
1172 | - if ( $invoice->is_recurring() ) { |
|
1172 | + if ($invoice->is_recurring()) { |
|
1173 | 1173 | |
1174 | 1174 | // Link to the parent invoice. |
1175 | - if ( $invoice->is_renewal() ) { |
|
1175 | + if ($invoice->is_renewal()) { |
|
1176 | 1176 | |
1177 | - $meta[ 'parent' ] = array( |
|
1177 | + $meta['parent'] = array( |
|
1178 | 1178 | |
1179 | 1179 | 'label' => sprintf( |
1180 | - __( 'Parent %s', 'invoicing' ), |
|
1181 | - ucfirst( $invoice->get_type() ) |
|
1180 | + __('Parent %s', 'invoicing'), |
|
1181 | + ucfirst($invoice->get_type()) |
|
1182 | 1182 | ), |
1183 | 1183 | |
1184 | - 'value' => wpinv_invoice_link( $invoice->get_parent_id() ), |
|
1184 | + 'value' => wpinv_invoice_link($invoice->get_parent_id()), |
|
1185 | 1185 | |
1186 | 1186 | ); |
1187 | 1187 | |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - $subscription = wpinv_get_subscription( $invoice ); |
|
1190 | + $subscription = wpinv_get_subscription($invoice); |
|
1191 | 1191 | |
1192 | - if ( ! empty ( $subscription ) ) { |
|
1192 | + if (!empty ($subscription)) { |
|
1193 | 1193 | |
1194 | 1194 | // Display the renewal date. |
1195 | - if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) { |
|
1195 | + if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) { |
|
1196 | 1196 | |
1197 | - $meta[ 'renewal_date' ] = array( |
|
1197 | + $meta['renewal_date'] = array( |
|
1198 | 1198 | |
1199 | - 'label' => __( 'Renews On', 'invoicing' ), |
|
1200 | - 'value' => getpaid_format_date( $subscription->get_expiration() ), |
|
1199 | + 'label' => __('Renews On', 'invoicing'), |
|
1200 | + 'value' => getpaid_format_date($subscription->get_expiration()), |
|
1201 | 1201 | |
1202 | 1202 | ); |
1203 | 1203 | |
1204 | 1204 | } |
1205 | 1205 | |
1206 | - if ( $invoice->is_parent() ) { |
|
1206 | + if ($invoice->is_parent()) { |
|
1207 | 1207 | |
1208 | 1208 | // Display the recurring amount. |
1209 | - $meta[ 'recurring_total' ] = array( |
|
1209 | + $meta['recurring_total'] = array( |
|
1210 | 1210 | |
1211 | - 'label' => __( 'Recurring Amount', 'invoicing' ), |
|
1212 | - 'value' => wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $invoice->get_currency() ), |
|
1211 | + 'label' => __('Recurring Amount', 'invoicing'), |
|
1212 | + 'value' => wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $invoice->get_currency()), |
|
1213 | 1213 | |
1214 | 1214 | ); |
1215 | 1215 | |
@@ -1219,15 +1219,15 @@ discard block |
||
1219 | 1219 | } |
1220 | 1220 | |
1221 | 1221 | // Add the invoice total to the meta. |
1222 | - $meta[ 'invoice_total' ] = array( |
|
1222 | + $meta['invoice_total'] = array( |
|
1223 | 1223 | |
1224 | - 'label' => __( 'Total Amount', 'invoicing' ), |
|
1225 | - 'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ), |
|
1224 | + 'label' => __('Total Amount', 'invoicing'), |
|
1225 | + 'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()), |
|
1226 | 1226 | |
1227 | 1227 | ); |
1228 | 1228 | |
1229 | 1229 | // Provide a way for third party plugins to filter the meta. |
1230 | - $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice ); |
|
1230 | + $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice); |
|
1231 | 1231 | |
1232 | 1232 | return $meta; |
1233 | 1233 |
@@ -12,432 +12,432 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Paypal_Gateway_IPN_Handler { |
14 | 14 | |
15 | - /** |
|
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - protected $id = 'paypal'; |
|
21 | - |
|
22 | - /** |
|
23 | - * Payment method object. |
|
24 | - * |
|
25 | - * @var GetPaid_Paypal_Gateway |
|
26 | - */ |
|
27 | - protected $gateway; |
|
28 | - |
|
29 | - /** |
|
30 | - * Class constructor. |
|
31 | - * |
|
32 | - * @param GetPaid_Paypal_Gateway $gateway |
|
33 | - */ |
|
34 | - public function __construct( $gateway ) { |
|
35 | - $this->gateway = $gateway; |
|
36 | - $this->verify_ipn(); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * Processes ipns and marks payments as complete. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function verify_ipn() { |
|
45 | - |
|
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | - |
|
48 | - // Validate the IPN. |
|
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | - } |
|
52 | - |
|
53 | - // Process the IPN. |
|
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | - |
|
57 | - // Abort if it was not paid by our gateway. |
|
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | - } |
|
62 | - |
|
63 | - $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | - |
|
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | - |
|
69 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
70 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
71 | - } |
|
72 | - |
|
73 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
74 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
75 | - wpinv_error_log( 'Done processing IPN' ); |
|
76 | - wp_die( 'Processed', 200 ); |
|
77 | - } |
|
78 | - |
|
79 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
80 | - wp_die( 'Unsupported IPN type', 200 ); |
|
81 | - |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Retrieves IPN Invoice. |
|
86 | - * |
|
87 | - * @param array $posted |
|
88 | - * @return WPInv_Invoice |
|
89 | - */ |
|
90 | - protected function get_ipn_invoice( $posted ) { |
|
91 | - |
|
92 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
93 | - |
|
94 | - if ( ! empty( $posted['custom'] ) ) { |
|
95 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
96 | - |
|
97 | - if ( $invoice->exists() ) { |
|
98 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
99 | - return $invoice; |
|
100 | - } |
|
101 | - |
|
102 | - } |
|
103 | - |
|
104 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
105 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Check PayPal IPN validity. |
|
110 | - */ |
|
111 | - protected function validate_ipn() { |
|
112 | - |
|
113 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
114 | - |
|
115 | - // Retrieve the associated invoice. |
|
116 | - $posted = wp_unslash( $_POST ); |
|
117 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
118 | - |
|
119 | - // Validate the IPN. |
|
120 | - $posted['cmd'] = '_notify-validate'; |
|
121 | - |
|
122 | - // Send back post vars to paypal. |
|
123 | - $params = array( |
|
124 | - 'body' => $posted, |
|
125 | - 'timeout' => 60, |
|
126 | - 'httpversion' => '1.1', |
|
127 | - 'compress' => false, |
|
128 | - 'decompress' => false, |
|
129 | - 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | - ); |
|
131 | - |
|
132 | - // Post back to get a response. |
|
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | - |
|
135 | - // Check to see if the request was valid. |
|
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | - return true; |
|
139 | - } |
|
140 | - |
|
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | - return false; |
|
144 | - } |
|
15 | + /** |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + protected $id = 'paypal'; |
|
21 | + |
|
22 | + /** |
|
23 | + * Payment method object. |
|
24 | + * |
|
25 | + * @var GetPaid_Paypal_Gateway |
|
26 | + */ |
|
27 | + protected $gateway; |
|
28 | + |
|
29 | + /** |
|
30 | + * Class constructor. |
|
31 | + * |
|
32 | + * @param GetPaid_Paypal_Gateway $gateway |
|
33 | + */ |
|
34 | + public function __construct( $gateway ) { |
|
35 | + $this->gateway = $gateway; |
|
36 | + $this->verify_ipn(); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * Processes ipns and marks payments as complete. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function verify_ipn() { |
|
45 | + |
|
46 | + wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
47 | + |
|
48 | + // Validate the IPN. |
|
49 | + if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | + wp_die( 'PayPal IPN Request Failure', 500 ); |
|
51 | + } |
|
52 | + |
|
53 | + // Process the IPN. |
|
54 | + $posted = wp_unslash( $_POST ); |
|
55 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
56 | + |
|
57 | + // Abort if it was not paid by our gateway. |
|
58 | + if ( $this->id != $invoice->get_gateway() ) { |
|
59 | + wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | + wp_die( 'Invoice not paid via PayPal', 500 ); |
|
61 | + } |
|
62 | + |
|
63 | + $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
64 | + $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
65 | + |
|
66 | + wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | + wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
68 | + |
|
69 | + if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
70 | + wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
71 | + } |
|
72 | + |
|
73 | + if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
74 | + call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
75 | + wpinv_error_log( 'Done processing IPN' ); |
|
76 | + wp_die( 'Processed', 200 ); |
|
77 | + } |
|
78 | + |
|
79 | + wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
80 | + wp_die( 'Unsupported IPN type', 200 ); |
|
81 | + |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Retrieves IPN Invoice. |
|
86 | + * |
|
87 | + * @param array $posted |
|
88 | + * @return WPInv_Invoice |
|
89 | + */ |
|
90 | + protected function get_ipn_invoice( $posted ) { |
|
91 | + |
|
92 | + wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
93 | + |
|
94 | + if ( ! empty( $posted['custom'] ) ) { |
|
95 | + $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
96 | + |
|
97 | + if ( $invoice->exists() ) { |
|
98 | + wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
99 | + return $invoice; |
|
100 | + } |
|
101 | + |
|
102 | + } |
|
103 | + |
|
104 | + wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
105 | + wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Check PayPal IPN validity. |
|
110 | + */ |
|
111 | + protected function validate_ipn() { |
|
112 | + |
|
113 | + wpinv_error_log( 'Validating PayPal IPN response' ); |
|
114 | + |
|
115 | + // Retrieve the associated invoice. |
|
116 | + $posted = wp_unslash( $_POST ); |
|
117 | + $invoice = $this->get_ipn_invoice( $posted ); |
|
118 | + |
|
119 | + // Validate the IPN. |
|
120 | + $posted['cmd'] = '_notify-validate'; |
|
121 | + |
|
122 | + // Send back post vars to paypal. |
|
123 | + $params = array( |
|
124 | + 'body' => $posted, |
|
125 | + 'timeout' => 60, |
|
126 | + 'httpversion' => '1.1', |
|
127 | + 'compress' => false, |
|
128 | + 'decompress' => false, |
|
129 | + 'user-agent' => 'GetPaid/' . WPINV_VERSION, |
|
130 | + ); |
|
131 | + |
|
132 | + // Post back to get a response. |
|
133 | + $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
134 | + |
|
135 | + // Check to see if the request was valid. |
|
136 | + if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | + wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
138 | + return true; |
|
139 | + } |
|
140 | + |
|
141 | + if ( is_wp_error( $response ) ) { |
|
142 | + wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
143 | + return false; |
|
144 | + } |
|
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | - return false; |
|
148 | - |
|
149 | - } |
|
146 | + wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
147 | + return false; |
|
148 | + |
|
149 | + } |
|
150 | 150 | |
151 | - /** |
|
152 | - * Check currency from IPN matches the invoice. |
|
153 | - * |
|
154 | - * @param WPInv_Invoice $invoice Invoice object. |
|
155 | - * @param string $currency currency to validate. |
|
156 | - */ |
|
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
151 | + /** |
|
152 | + * Check currency from IPN matches the invoice. |
|
153 | + * |
|
154 | + * @param WPInv_Invoice $invoice Invoice object. |
|
155 | + * @param string $currency currency to validate. |
|
156 | + */ |
|
157 | + protected function validate_ipn_currency( $invoice, $currency ) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
160 | 160 | |
161 | - /* translators: %s: currency code. */ |
|
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
161 | + /* translators: %s: currency code. */ |
|
162 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | - } |
|
164 | + wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
165 | + } |
|
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | - } |
|
167 | + wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * Check payment amount from IPN matches the invoice. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice Invoice object. |
|
174 | - * @param float $amount amount to validate. |
|
175 | - */ |
|
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
170 | + /** |
|
171 | + * Check payment amount from IPN matches the invoice. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice Invoice object. |
|
174 | + * @param float $amount amount to validate. |
|
175 | + */ |
|
176 | + protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | + if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
178 | 178 | |
179 | - /* translators: %s: Amount. */ |
|
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
179 | + /* translators: %s: Amount. */ |
|
180 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
181 | 181 | |
182 | - wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | - } |
|
182 | + wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
183 | + } |
|
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | - } |
|
185 | + wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
186 | + } |
|
187 | 187 | |
188 | - /** |
|
189 | - * Verify receiver email from PayPal. |
|
190 | - * |
|
191 | - * @param WPInv_Invoice $invoice Invoice object. |
|
192 | - * @param string $receiver_email Email to validate. |
|
193 | - */ |
|
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
188 | + /** |
|
189 | + * Verify receiver email from PayPal. |
|
190 | + * |
|
191 | + * @param WPInv_Invoice $invoice Invoice object. |
|
192 | + * @param string $receiver_email Email to validate. |
|
193 | + */ |
|
194 | + protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | + $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | + wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
199 | 199 | |
200 | - /* translators: %s: email address . */ |
|
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
200 | + /* translators: %s: email address . */ |
|
201 | + $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
202 | 202 | |
203 | - wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | - } |
|
203 | + wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
204 | + } |
|
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | - } |
|
206 | + wpinv_error_log( 'Validated PayPal Email' ); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * Handles one time payments. |
|
211 | - * |
|
212 | - * @param WPInv_Invoice $invoice Invoice object. |
|
213 | - * @param array $posted Posted data. |
|
214 | - */ |
|
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | - |
|
217 | - // Collect payment details |
|
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | - |
|
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | - |
|
224 | - // Update the transaction id. |
|
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | - $invoice->save(); |
|
228 | - } |
|
209 | + /** |
|
210 | + * Handles one time payments. |
|
211 | + * |
|
212 | + * @param WPInv_Invoice $invoice Invoice object. |
|
213 | + * @param array $posted Posted data. |
|
214 | + */ |
|
215 | + protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
216 | + |
|
217 | + // Collect payment details |
|
218 | + $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
220 | + |
|
221 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
223 | + |
|
224 | + // Update the transaction id. |
|
225 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | + $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
227 | + $invoice->save(); |
|
228 | + } |
|
229 | 229 | |
230 | - // Process a refund. |
|
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
230 | + // Process a refund. |
|
231 | + if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | - } |
|
235 | + if ( ! $invoice->is_refunded() ) { |
|
236 | + $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + } |
|
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
240 | - } |
|
239 | + return wpinv_error_log( $posted['reason_code'] ); |
|
240 | + } |
|
241 | 241 | |
242 | - // Process payments. |
|
243 | - if ( $payment_status == 'completed' ) { |
|
242 | + // Process payments. |
|
243 | + if ( $payment_status == 'completed' ) { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | - } |
|
245 | + if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | + return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
247 | + } |
|
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
250 | 250 | |
251 | - $note = ''; |
|
252 | - |
|
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | - } |
|
251 | + $note = ''; |
|
252 | + |
|
253 | + if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | + $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + } |
|
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | - } |
|
257 | + if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | + $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + } |
|
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | + return wpinv_error_log( 'Invoice marked as paid.' ); |
|
263 | 263 | |
264 | - } |
|
265 | - |
|
266 | - // Pending payments. |
|
267 | - if ( $payment_status == 'pending' ) { |
|
264 | + } |
|
265 | + |
|
266 | + // Pending payments. |
|
267 | + if ( $payment_status == 'pending' ) { |
|
268 | 268 | |
269 | - /* translators: %s: pending reason. */ |
|
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | - |
|
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | - } |
|
269 | + /* translators: %s: pending reason. */ |
|
270 | + $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
271 | + |
|
272 | + return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
273 | + } |
|
274 | 274 | |
275 | - /* translators: %s: payment status. */ |
|
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
275 | + /* translators: %s: payment status. */ |
|
276 | + $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Handles one time payments. |
|
282 | - * |
|
283 | - * @param WPInv_Invoice $invoice Invoice object. |
|
284 | - * @param array $posted Posted data. |
|
285 | - */ |
|
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | - } |
|
280 | + /** |
|
281 | + * Handles one time payments. |
|
282 | + * |
|
283 | + * @param WPInv_Invoice $invoice Invoice object. |
|
284 | + * @param array $posted Posted data. |
|
285 | + */ |
|
286 | + protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | + $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + } |
|
289 | 289 | |
290 | - /** |
|
291 | - * Handles subscription sign ups. |
|
292 | - * |
|
293 | - * @param WPInv_Invoice $invoice Invoice object. |
|
294 | - * @param array $posted Posted data. |
|
295 | - */ |
|
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
290 | + /** |
|
291 | + * Handles subscription sign ups. |
|
292 | + * |
|
293 | + * @param WPInv_Invoice $invoice Invoice object. |
|
294 | + * @param array $posted Posted data. |
|
295 | + */ |
|
296 | + protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
297 | 297 | |
298 | - wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
298 | + wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
299 | 299 | |
300 | - // Make sure the invoice has a subscription. |
|
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
300 | + // Make sure the invoice has a subscription. |
|
301 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | - } |
|
303 | + if ( empty( $subscription ) ) { |
|
304 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
305 | + } |
|
306 | 306 | |
307 | - // Validate the IPN. |
|
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
307 | + // Validate the IPN. |
|
308 | + $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | + $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | + $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | + $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
312 | 312 | |
313 | - // Activate the subscription. |
|
314 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
315 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
316 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
317 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
318 | - $subscription->activate(); |
|
313 | + // Activate the subscription. |
|
314 | + $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
315 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
316 | + $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
317 | + $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
318 | + $subscription->activate(); |
|
319 | 319 | |
320 | - // Set the transaction id. |
|
321 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
322 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | - } |
|
320 | + // Set the transaction id. |
|
321 | + if ( ! empty( $posted['txn_id'] ) ) { |
|
322 | + $invoice->set_transaction_id( $posted['txn_id'] ); |
|
323 | + } |
|
324 | 324 | |
325 | - // Update the payment status. |
|
326 | - $invoice->mark_paid(); |
|
325 | + // Update the payment status. |
|
326 | + $invoice->mark_paid(); |
|
327 | 327 | |
328 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
328 | + $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
329 | 329 | |
330 | - wpinv_error_log( 'Subscription started.' ); |
|
331 | - } |
|
330 | + wpinv_error_log( 'Subscription started.' ); |
|
331 | + } |
|
332 | 332 | |
333 | - /** |
|
334 | - * Handles subscription renewals. |
|
335 | - * |
|
336 | - * @param WPInv_Invoice $invoice Invoice object. |
|
337 | - * @param array $posted Posted data. |
|
338 | - */ |
|
339 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
333 | + /** |
|
334 | + * Handles subscription renewals. |
|
335 | + * |
|
336 | + * @param WPInv_Invoice $invoice Invoice object. |
|
337 | + * @param array $posted Posted data. |
|
338 | + */ |
|
339 | + protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
340 | 340 | |
341 | - // Make sure the invoice has a subscription. |
|
342 | - $subscription = wpinv_get_subscription( $invoice ); |
|
341 | + // Make sure the invoice has a subscription. |
|
342 | + $subscription = wpinv_get_subscription( $invoice ); |
|
343 | 343 | |
344 | - if ( empty( $subscription ) ) { |
|
345 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
346 | - } |
|
344 | + if ( empty( $subscription ) ) { |
|
345 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
346 | + } |
|
347 | 347 | |
348 | - // Abort if this is the first payment. |
|
349 | - if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
350 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
351 | - $invoice->save(); |
|
352 | - return; |
|
353 | - } |
|
354 | - |
|
355 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
348 | + // Abort if this is the first payment. |
|
349 | + if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
350 | + $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
351 | + $invoice->save(); |
|
352 | + return; |
|
353 | + } |
|
354 | + |
|
355 | + wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
356 | 356 | |
357 | - // Abort if the payment is already recorded. |
|
358 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
359 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
360 | - } |
|
361 | - |
|
362 | - $args = array( |
|
363 | - 'transaction_id' => $posted['txn_id'], |
|
364 | - 'gateway' => $this->id, |
|
365 | - ); |
|
366 | - |
|
367 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
368 | - |
|
369 | - if ( empty( $invoice ) ) { |
|
370 | - return; |
|
371 | - } |
|
372 | - |
|
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
374 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
375 | - |
|
376 | - $subscription->renew(); |
|
377 | - wpinv_error_log( 'Subscription renewed.' ); |
|
378 | - |
|
379 | - } |
|
380 | - |
|
381 | - /** |
|
382 | - * Handles subscription cancelations. |
|
383 | - * |
|
384 | - * @param WPInv_Invoice $invoice Invoice object. |
|
385 | - */ |
|
386 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
387 | - |
|
388 | - // Make sure the invoice has a subscription. |
|
389 | - $subscription = wpinv_get_subscription( $invoice ); |
|
390 | - |
|
391 | - if ( empty( $subscription ) ) { |
|
392 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
393 | - } |
|
394 | - |
|
395 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
396 | - $subscription->cancel(); |
|
397 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
398 | - |
|
399 | - } |
|
400 | - |
|
401 | - /** |
|
402 | - * Handles subscription completions. |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice Invoice object. |
|
405 | - * @param array $posted Posted data. |
|
406 | - */ |
|
407 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
408 | - |
|
409 | - // Make sure the invoice has a subscription. |
|
410 | - $subscription = wpinv_get_subscription( $invoice ); |
|
357 | + // Abort if the payment is already recorded. |
|
358 | + if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
359 | + return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
360 | + } |
|
361 | + |
|
362 | + $args = array( |
|
363 | + 'transaction_id' => $posted['txn_id'], |
|
364 | + 'gateway' => $this->id, |
|
365 | + ); |
|
366 | + |
|
367 | + $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
368 | + |
|
369 | + if ( empty( $invoice ) ) { |
|
370 | + return; |
|
371 | + } |
|
372 | + |
|
373 | + $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
374 | + $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
375 | + |
|
376 | + $subscription->renew(); |
|
377 | + wpinv_error_log( 'Subscription renewed.' ); |
|
378 | + |
|
379 | + } |
|
380 | + |
|
381 | + /** |
|
382 | + * Handles subscription cancelations. |
|
383 | + * |
|
384 | + * @param WPInv_Invoice $invoice Invoice object. |
|
385 | + */ |
|
386 | + protected function ipn_txn_subscr_cancel( $invoice ) { |
|
387 | + |
|
388 | + // Make sure the invoice has a subscription. |
|
389 | + $subscription = wpinv_get_subscription( $invoice ); |
|
390 | + |
|
391 | + if ( empty( $subscription ) ) { |
|
392 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
393 | + } |
|
394 | + |
|
395 | + wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
396 | + $subscription->cancel(); |
|
397 | + wpinv_error_log( 'Subscription cancelled.' ); |
|
398 | + |
|
399 | + } |
|
400 | + |
|
401 | + /** |
|
402 | + * Handles subscription completions. |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice Invoice object. |
|
405 | + * @param array $posted Posted data. |
|
406 | + */ |
|
407 | + protected function ipn_txn_subscr_eot( $invoice ) { |
|
408 | + |
|
409 | + // Make sure the invoice has a subscription. |
|
410 | + $subscription = wpinv_get_subscription( $invoice ); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
414 | - } |
|
412 | + if ( empty( $subscription ) ) { |
|
413 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
414 | + } |
|
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
417 | - $subscription->complete(); |
|
418 | - wpinv_error_log( 'Subscription completed.' ); |
|
416 | + wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
417 | + $subscription->complete(); |
|
418 | + wpinv_error_log( 'Subscription completed.' ); |
|
419 | 419 | |
420 | - } |
|
420 | + } |
|
421 | 421 | |
422 | - /** |
|
423 | - * Handles subscription fails. |
|
424 | - * |
|
425 | - * @param WPInv_Invoice $invoice Invoice object. |
|
426 | - * @param array $posted Posted data. |
|
427 | - */ |
|
428 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
422 | + /** |
|
423 | + * Handles subscription fails. |
|
424 | + * |
|
425 | + * @param WPInv_Invoice $invoice Invoice object. |
|
426 | + * @param array $posted Posted data. |
|
427 | + */ |
|
428 | + protected function ipn_txn_subscr_failed( $invoice ) { |
|
429 | 429 | |
430 | - // Make sure the invoice has a subscription. |
|
431 | - $subscription = wpinv_get_subscription( $invoice ); |
|
430 | + // Make sure the invoice has a subscription. |
|
431 | + $subscription = wpinv_get_subscription( $invoice ); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
435 | - } |
|
433 | + if ( empty( $subscription ) ) { |
|
434 | + return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
435 | + } |
|
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
438 | - $subscription->failing(); |
|
439 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
437 | + wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
438 | + $subscription->failing(); |
|
439 | + wpinv_error_log( 'Subscription marked as failing.' ); |
|
440 | 440 | |
441 | - } |
|
441 | + } |
|
442 | 442 | |
443 | 443 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,41 +43,41 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler' ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler'); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_unslash( $_POST ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_unslash($_POST); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal' ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 500 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal'); |
|
60 | + wp_die('Invoice not paid via PayPal', 500); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = sanitize_key( strtolower( $posted['payment_status'] ) ); |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = sanitize_key(strtolower($posted['payment_status'])); |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'] ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'] ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status']); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type']); |
|
68 | 68 | |
69 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
70 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data' ); |
|
69 | + if ($this->gateway->is_sandbox($invoice)) { |
|
70 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data'); |
|
71 | 71 | } |
72 | 72 | |
73 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
74 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
75 | - wpinv_error_log( 'Done processing IPN' ); |
|
76 | - wp_die( 'Processed', 200 ); |
|
73 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
74 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
75 | + wpinv_error_log('Done processing IPN'); |
|
76 | + wp_die('Processed', 200); |
|
77 | 77 | } |
78 | 78 | |
79 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'] ); |
|
80 | - wp_die( 'Unsupported IPN type', 200 ); |
|
79 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type']); |
|
80 | + wp_die('Unsupported IPN type', 200); |
|
81 | 81 | |
82 | 82 | } |
83 | 83 | |
@@ -87,22 +87,22 @@ discard block |
||
87 | 87 | * @param array $posted |
88 | 88 | * @return WPInv_Invoice |
89 | 89 | */ |
90 | - protected function get_ipn_invoice( $posted ) { |
|
90 | + protected function get_ipn_invoice($posted) { |
|
91 | 91 | |
92 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice' ); |
|
92 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice'); |
|
93 | 93 | |
94 | - if ( ! empty( $posted['custom'] ) ) { |
|
95 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
94 | + if (!empty($posted['custom'])) { |
|
95 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
96 | 96 | |
97 | - if ( $invoice->exists() ) { |
|
98 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number() ); |
|
97 | + if ($invoice->exists()) { |
|
98 | + wpinv_error_log('Found invoice #' . $invoice->get_number()); |
|
99 | 99 | return $invoice; |
100 | 100 | } |
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | - wpinv_error_log( 'Could not retrieve the associated invoice.' ); |
|
105 | - wp_die( 'Could not retrieve the associated invoice.', 500 ); |
|
104 | + wpinv_error_log('Could not retrieve the associated invoice.'); |
|
105 | + wp_die('Could not retrieve the associated invoice.', 500); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | */ |
111 | 111 | protected function validate_ipn() { |
112 | 112 | |
113 | - wpinv_error_log( 'Validating PayPal IPN response' ); |
|
113 | + wpinv_error_log('Validating PayPal IPN response'); |
|
114 | 114 | |
115 | 115 | // Retrieve the associated invoice. |
116 | - $posted = wp_unslash( $_POST ); |
|
117 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
116 | + $posted = wp_unslash($_POST); |
|
117 | + $invoice = $this->get_ipn_invoice($posted); |
|
118 | 118 | |
119 | 119 | // Validate the IPN. |
120 | 120 | $posted['cmd'] = '_notify-validate'; |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log($response['body'], 'Received valid response from PayPal IPN'); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency' ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency'); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Currencies do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount' ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount'); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email' ); |
|
206 | + wpinv_error_log('Validated PayPal Email'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,68 +212,68 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | 230 | // Process a refund. |
231 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
231 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
232 | 232 | |
233 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
233 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
234 | 234 | |
235 | - if ( ! $invoice->is_refunded() ) { |
|
236 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
235 | + if (!$invoice->is_refunded()) { |
|
236 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
237 | 237 | } |
238 | 238 | |
239 | - return wpinv_error_log( $posted['reason_code'] ); |
|
239 | + return wpinv_error_log($posted['reason_code']); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | // Process payments. |
243 | - if ( $payment_status == 'completed' ) { |
|
243 | + if ($payment_status == 'completed') { |
|
244 | 244 | |
245 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
246 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.' ); |
|
245 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
246 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.'); |
|
247 | 247 | } |
248 | 248 | |
249 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
249 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
250 | 250 | |
251 | 251 | $note = ''; |
252 | 252 | |
253 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
254 | - $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
253 | + if (!empty($posted['mc_fee'])) { |
|
254 | + $note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
255 | 255 | } |
256 | 256 | |
257 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
258 | - $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
257 | + if (!empty($posted['payer_status'])) { |
|
258 | + $note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
259 | 259 | } |
260 | 260 | |
261 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
262 | - return wpinv_error_log( 'Invoice marked as paid.' ); |
|
261 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
262 | + return wpinv_error_log('Invoice marked as paid.'); |
|
263 | 263 | |
264 | 264 | } |
265 | 265 | |
266 | 266 | // Pending payments. |
267 | - if ( $payment_status == 'pending' ) { |
|
267 | + if ($payment_status == 'pending') { |
|
268 | 268 | |
269 | 269 | /* translators: %s: pending reason. */ |
270 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
270 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
271 | 271 | |
272 | - return wpinv_error_log( 'Invoice marked as "payment held".' ); |
|
272 | + return wpinv_error_log('Invoice marked as "payment held".'); |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /* translators: %s: payment status. */ |
276 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
276 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
277 | 277 | |
278 | 278 | } |
279 | 279 | |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | * @param WPInv_Invoice $invoice Invoice object. |
284 | 284 | * @param array $posted Posted data. |
285 | 285 | */ |
286 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
287 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
286 | + protected function ipn_txn_cart($invoice, $posted) { |
|
287 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | /** |
@@ -293,41 +293,41 @@ discard block |
||
293 | 293 | * @param WPInv_Invoice $invoice Invoice object. |
294 | 294 | * @param array $posted Posted data. |
295 | 295 | */ |
296 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
296 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
297 | 297 | |
298 | - wpinv_error_log( $posted, 'Processing subscription signup' ); |
|
298 | + wpinv_error_log($posted, 'Processing subscription signup'); |
|
299 | 299 | |
300 | 300 | // Make sure the invoice has a subscription. |
301 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
301 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
302 | 302 | |
303 | - if ( empty( $subscription ) ) { |
|
304 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
303 | + if (empty($subscription)) { |
|
304 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | // Validate the IPN. |
308 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
309 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
310 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
311 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
308 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
309 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
310 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
311 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
312 | 312 | |
313 | 313 | // Activate the subscription. |
314 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
315 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
316 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
317 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
314 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
315 | + $subscription->set_date_created(current_time('mysql')); |
|
316 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
317 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
318 | 318 | $subscription->activate(); |
319 | 319 | |
320 | 320 | // Set the transaction id. |
321 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
322 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
321 | + if (!empty($posted['txn_id'])) { |
|
322 | + $invoice->set_transaction_id($posted['txn_id']); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | // Update the payment status. |
326 | 326 | $invoice->mark_paid(); |
327 | 327 | |
328 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
328 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
329 | 329 | |
330 | - wpinv_error_log( 'Subscription started.' ); |
|
330 | + wpinv_error_log('Subscription started.'); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | /** |
@@ -336,27 +336,27 @@ discard block |
||
336 | 336 | * @param WPInv_Invoice $invoice Invoice object. |
337 | 337 | * @param array $posted Posted data. |
338 | 338 | */ |
339 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
339 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
340 | 340 | |
341 | 341 | // Make sure the invoice has a subscription. |
342 | - $subscription = wpinv_get_subscription( $invoice ); |
|
342 | + $subscription = wpinv_get_subscription($invoice); |
|
343 | 343 | |
344 | - if ( empty( $subscription ) ) { |
|
345 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
344 | + if (empty($subscription)) { |
|
345 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Abort if this is the first payment. |
349 | - if ( date( 'Ynd', $subscription->get_date_created() ) == date( 'Ynd', strtotime( $posted['payment_date'] ) ) ) { |
|
350 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
349 | + if (date('Ynd', $subscription->get_date_created()) == date('Ynd', strtotime($posted['payment_date']))) { |
|
350 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
351 | 351 | $invoice->save(); |
352 | 352 | return; |
353 | 353 | } |
354 | 354 | |
355 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id() ); |
|
355 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id()); |
|
356 | 356 | |
357 | 357 | // Abort if the payment is already recorded. |
358 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
359 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed' ); |
|
358 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
359 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed'); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | $args = array( |
@@ -364,17 +364,17 @@ discard block |
||
364 | 364 | 'gateway' => $this->id, |
365 | 365 | ); |
366 | 366 | |
367 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
367 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
368 | 368 | |
369 | - if ( empty( $invoice ) ) { |
|
369 | + if (empty($invoice)) { |
|
370 | 370 | return; |
371 | 371 | } |
372 | 372 | |
373 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
374 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
373 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
374 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
375 | 375 | |
376 | 376 | $subscription->renew(); |
377 | - wpinv_error_log( 'Subscription renewed.' ); |
|
377 | + wpinv_error_log('Subscription renewed.'); |
|
378 | 378 | |
379 | 379 | } |
380 | 380 | |
@@ -383,18 +383,18 @@ discard block |
||
383 | 383 | * |
384 | 384 | * @param WPInv_Invoice $invoice Invoice object. |
385 | 385 | */ |
386 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
386 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
387 | 387 | |
388 | 388 | // Make sure the invoice has a subscription. |
389 | - $subscription = wpinv_get_subscription( $invoice ); |
|
389 | + $subscription = wpinv_get_subscription($invoice); |
|
390 | 390 | |
391 | - if ( empty( $subscription ) ) { |
|
392 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
391 | + if (empty($subscription)) { |
|
392 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
393 | 393 | } |
394 | 394 | |
395 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id() ); |
|
395 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id()); |
|
396 | 396 | $subscription->cancel(); |
397 | - wpinv_error_log( 'Subscription cancelled.' ); |
|
397 | + wpinv_error_log('Subscription cancelled.'); |
|
398 | 398 | |
399 | 399 | } |
400 | 400 | |
@@ -404,18 +404,18 @@ discard block |
||
404 | 404 | * @param WPInv_Invoice $invoice Invoice object. |
405 | 405 | * @param array $posted Posted data. |
406 | 406 | */ |
407 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
407 | + protected function ipn_txn_subscr_eot($invoice) { |
|
408 | 408 | |
409 | 409 | // Make sure the invoice has a subscription. |
410 | - $subscription = wpinv_get_subscription( $invoice ); |
|
410 | + $subscription = wpinv_get_subscription($invoice); |
|
411 | 411 | |
412 | - if ( empty( $subscription ) ) { |
|
413 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
412 | + if (empty($subscription)) { |
|
413 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
414 | 414 | } |
415 | 415 | |
416 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id() ); |
|
416 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id()); |
|
417 | 417 | $subscription->complete(); |
418 | - wpinv_error_log( 'Subscription completed.' ); |
|
418 | + wpinv_error_log('Subscription completed.'); |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | |
@@ -425,18 +425,18 @@ discard block |
||
425 | 425 | * @param WPInv_Invoice $invoice Invoice object. |
426 | 426 | * @param array $posted Posted data. |
427 | 427 | */ |
428 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
428 | + protected function ipn_txn_subscr_failed($invoice) { |
|
429 | 429 | |
430 | 430 | // Make sure the invoice has a subscription. |
431 | - $subscription = wpinv_get_subscription( $invoice ); |
|
431 | + $subscription = wpinv_get_subscription($invoice); |
|
432 | 432 | |
433 | - if ( empty( $subscription ) ) { |
|
434 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found' ); |
|
433 | + if (empty($subscription)) { |
|
434 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found'); |
|
435 | 435 | } |
436 | 436 | |
437 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id() ); |
|
437 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id()); |
|
438 | 438 | $subscription->failing(); |
439 | - wpinv_error_log( 'Subscription marked as failing.' ); |
|
439 | + wpinv_error_log('Subscription marked as failing.'); |
|
440 | 440 | |
441 | 441 | } |
442 | 442 |
@@ -13,72 +13,72 @@ discard block |
||
13 | 13 | class GetPaid_Paypal_Gateway extends GetPaid_Payment_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'paypal'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 1; |
35 | 35 | |
36 | 36 | /** |
37 | - * Stores line items to send to PayPal. |
|
38 | - * |
|
39 | - * @var array |
|
40 | - */ |
|
37 | + * Stores line items to send to PayPal. |
|
38 | + * |
|
39 | + * @var array |
|
40 | + */ |
|
41 | 41 | protected $line_items = array(); |
42 | 42 | |
43 | 43 | /** |
44 | - * Endpoint for requests from PayPal. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
48 | - protected $notify_url; |
|
49 | - |
|
50 | - /** |
|
51 | - * Endpoint for requests to PayPal. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
44 | + * Endpoint for requests from PayPal. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | + protected $notify_url; |
|
49 | + |
|
50 | + /** |
|
51 | + * Endpoint for requests to PayPal. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | 55 | protected $endpoint; |
56 | 56 | |
57 | 57 | /** |
58 | - * Currencies this gateway is allowed for. |
|
59 | - * |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
58 | + * Currencies this gateway is allowed for. |
|
59 | + * |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
63 | 63 | |
64 | 64 | /** |
65 | - * URL to view a transaction. |
|
66 | - * |
|
67 | - * @var string |
|
68 | - */ |
|
65 | + * URL to view a transaction. |
|
66 | + * |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s'; |
70 | 70 | |
71 | 71 | /** |
72 | - * URL to view a subscription. |
|
73 | - * |
|
74 | - * @var string |
|
75 | - */ |
|
76 | - public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
72 | + * URL to view a subscription. |
|
73 | + * |
|
74 | + * @var string |
|
75 | + */ |
|
76 | + public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s'; |
|
77 | 77 | |
78 | 78 | /** |
79 | - * Class constructor. |
|
80 | - */ |
|
81 | - public function __construct() { |
|
79 | + * Class constructor. |
|
80 | + */ |
|
81 | + public function __construct() { |
|
82 | 82 | |
83 | 83 | $this->title = __( 'PayPal Standard', 'invoicing' ); |
84 | 84 | $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
@@ -92,15 +92,15 @@ discard block |
||
92 | 92 | } |
93 | 93 | |
94 | 94 | /** |
95 | - * Process Payment. |
|
96 | - * |
|
97 | - * |
|
98 | - * @param WPInv_Invoice $invoice Invoice. |
|
99 | - * @param array $submission_data Posted checkout fields. |
|
100 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
95 | + * Process Payment. |
|
96 | + * |
|
97 | + * |
|
98 | + * @param WPInv_Invoice $invoice Invoice. |
|
99 | + * @param array $submission_data Posted checkout fields. |
|
100 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | 106 | $paypal_redirect = $this->get_request_url( $invoice ); |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
126 | - * Get the PayPal request URL for an invoice. |
|
127 | - * |
|
128 | - * @param WPInv_Invoice $invoice Invoice object. |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public function get_request_url( $invoice ) { |
|
126 | + * Get the PayPal request URL for an invoice. |
|
127 | + * |
|
128 | + * @param WPInv_Invoice $invoice Invoice object. |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public function get_request_url( $invoice ) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | 137 | $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
@@ -144,44 +144,44 @@ discard block |
||
144 | 144 | |
145 | 145 | return add_query_arg( $paypal_args, $this->endpoint ); |
146 | 146 | |
147 | - } |
|
147 | + } |
|
148 | 148 | |
149 | 149 | /** |
150 | - * Get PayPal Args for passing to PP. |
|
151 | - * |
|
152 | - * @param WPInv_Invoice $invoice Invoice object. |
|
153 | - * @return array |
|
154 | - */ |
|
155 | - protected function get_paypal_args( $invoice ) { |
|
150 | + * Get PayPal Args for passing to PP. |
|
151 | + * |
|
152 | + * @param WPInv_Invoice $invoice Invoice object. |
|
153 | + * @return array |
|
154 | + */ |
|
155 | + protected function get_paypal_args( $invoice ) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | - |
|
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | - $force_one_line_item = true; |
|
162 | - } |
|
163 | - |
|
164 | - $paypal_args = apply_filters( |
|
165 | - 'getpaid_paypal_args', |
|
166 | - array_merge( |
|
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | - ), |
|
170 | - $invoice |
|
171 | - ); |
|
172 | - |
|
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
158 | + $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
159 | + |
|
160 | + if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
161 | + $force_one_line_item = true; |
|
162 | + } |
|
163 | + |
|
164 | + $paypal_args = apply_filters( |
|
165 | + 'getpaid_paypal_args', |
|
166 | + array_merge( |
|
167 | + $this->get_transaction_args( $invoice ), |
|
168 | + $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
169 | + ), |
|
170 | + $invoice |
|
171 | + ); |
|
172 | + |
|
173 | + return $this->fix_request_length( $invoice, $paypal_args ); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Get transaction args for paypal request. |
|
178 | - * |
|
179 | - * @param WPInv_Invoice $invoice Invoice object. |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - protected function get_transaction_args( $invoice ) { |
|
183 | - |
|
184 | - return array( |
|
177 | + * Get transaction args for paypal request. |
|
178 | + * |
|
179 | + * @param WPInv_Invoice $invoice Invoice object. |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + protected function get_transaction_args( $invoice ) { |
|
183 | + |
|
184 | + return array( |
|
185 | 185 | 'cmd' => '_cart', |
186 | 186 | 'business' => wpinv_get_option( 'paypal_email', false ), |
187 | 187 | 'no_shipping' => '1', |
@@ -206,16 +206,16 @@ discard block |
||
206 | 206 | } |
207 | 207 | |
208 | 208 | /** |
209 | - * Get line item args for paypal request. |
|
210 | - * |
|
211 | - * @param WPInv_Invoice $invoice Invoice object. |
|
212 | - * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
209 | + * Get line item args for paypal request. |
|
210 | + * |
|
211 | + * @param WPInv_Invoice $invoice Invoice object. |
|
212 | + * @param bool $force_one_line_item Create only one item for this invoice. |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
218 | + if ( $force_one_line_item ) { |
|
219 | 219 | return $this->get_line_item_args_single_item( $invoice ); |
220 | 220 | } |
221 | 221 | |
@@ -235,129 +235,129 @@ discard block |
||
235 | 235 | $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge( $line_item_args, $this->get_line_items() ); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get line item args for paypal request as a single line item. |
|
244 | - * |
|
245 | - * @param WPInv_Invoice $invoice Invoice object. |
|
246 | - * @return array |
|
247 | - */ |
|
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
249 | - $this->delete_line_items(); |
|
243 | + * Get line item args for paypal request as a single line item. |
|
244 | + * |
|
245 | + * @param WPInv_Invoice $invoice Invoice object. |
|
246 | + * @return array |
|
247 | + */ |
|
248 | + protected function get_line_item_args_single_item( $invoice ) { |
|
249 | + $this->delete_line_items(); |
|
250 | 250 | |
251 | 251 | $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
252 | + $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
253 | 253 | |
254 | - return $this->get_line_items(); |
|
254 | + return $this->get_line_items(); |
|
255 | 255 | } |
256 | 256 | |
257 | 257 | /** |
258 | - * Return all line items. |
|
259 | - */ |
|
260 | - protected function get_line_items() { |
|
261 | - return $this->line_items; |
|
262 | - } |
|
258 | + * Return all line items. |
|
259 | + */ |
|
260 | + protected function get_line_items() { |
|
261 | + return $this->line_items; |
|
262 | + } |
|
263 | 263 | |
264 | 264 | /** |
265 | - * Remove all line items. |
|
266 | - */ |
|
267 | - protected function delete_line_items() { |
|
268 | - $this->line_items = array(); |
|
265 | + * Remove all line items. |
|
266 | + */ |
|
267 | + protected function delete_line_items() { |
|
268 | + $this->line_items = array(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
272 | - * Prepare line items to send to paypal. |
|
273 | - * |
|
274 | - * @param WPInv_Invoice $invoice Invoice object. |
|
275 | - */ |
|
276 | - protected function prepare_line_items( $invoice ) { |
|
277 | - $this->delete_line_items(); |
|
278 | - |
|
279 | - // Items. |
|
280 | - foreach ( $invoice->get_items() as $item ) { |
|
281 | - $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | - $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
272 | + * Prepare line items to send to paypal. |
|
273 | + * |
|
274 | + * @param WPInv_Invoice $invoice Invoice object. |
|
275 | + */ |
|
276 | + protected function prepare_line_items( $invoice ) { |
|
277 | + $this->delete_line_items(); |
|
278 | + |
|
279 | + // Items. |
|
280 | + foreach ( $invoice->get_items() as $item ) { |
|
281 | + $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
|
282 | + $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
|
283 | + $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
287 | + foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | 288 | $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | 293 | /** |
294 | - * Add PayPal Line Item. |
|
295 | - * |
|
296 | - * @param string $item_name Item name. |
|
297 | - * @param int $quantity Item quantity. |
|
298 | - * @param float $amount Amount. |
|
299 | - * @param string $item_number Item number. |
|
300 | - */ |
|
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | - |
|
304 | - $item = apply_filters( |
|
305 | - 'getpaid_paypal_line_item', |
|
306 | - array( |
|
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | - 'quantity' => (int) $quantity, |
|
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | - 'item_number' => $item_number, |
|
311 | - ), |
|
312 | - $item_name, |
|
313 | - $quantity, |
|
314 | - $amount, |
|
315 | - $item_number |
|
316 | - ); |
|
317 | - |
|
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
294 | + * Add PayPal Line Item. |
|
295 | + * |
|
296 | + * @param string $item_name Item name. |
|
297 | + * @param int $quantity Item quantity. |
|
298 | + * @param float $amount Amount. |
|
299 | + * @param string $item_number Item number. |
|
300 | + */ |
|
301 | + protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | + $index = ( count( $this->line_items ) / 4 ) + 1; |
|
303 | + |
|
304 | + $item = apply_filters( |
|
305 | + 'getpaid_paypal_line_item', |
|
306 | + array( |
|
307 | + 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
308 | + 'quantity' => (int) $quantity, |
|
309 | + 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
310 | + 'item_number' => $item_number, |
|
311 | + ), |
|
312 | + $item_name, |
|
313 | + $quantity, |
|
314 | + $amount, |
|
315 | + $item_number |
|
316 | + ); |
|
317 | + |
|
318 | + $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | 319 | $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | + $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
327 | - * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | - * |
|
329 | - * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | - * |
|
331 | - * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | - * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | - * @return array |
|
334 | - */ |
|
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | - $max_paypal_length = 2083; |
|
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | - |
|
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | - return $paypal_args; |
|
341 | - } |
|
342 | - |
|
343 | - return apply_filters( |
|
344 | - 'getpaid_paypal_args', |
|
345 | - array_merge( |
|
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
348 | - ), |
|
349 | - $invoice |
|
350 | - ); |
|
327 | + * If the default request with line items is too long, generate a new one with only one line item. |
|
328 | + * |
|
329 | + * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer. |
|
330 | + * |
|
331 | + * @param WPInv_Invoice $invoice Invoice to be sent to Paypal. |
|
332 | + * @param array $paypal_args Arguments sent to Paypal in the request. |
|
333 | + * @return array |
|
334 | + */ |
|
335 | + protected function fix_request_length( $invoice, $paypal_args ) { |
|
336 | + $max_paypal_length = 2083; |
|
337 | + $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
338 | + |
|
339 | + if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
340 | + return $paypal_args; |
|
341 | + } |
|
342 | + |
|
343 | + return apply_filters( |
|
344 | + 'getpaid_paypal_args', |
|
345 | + array_merge( |
|
346 | + $this->get_transaction_args( $invoice ), |
|
347 | + $this->get_line_item_args( $invoice, true ) |
|
348 | + ), |
|
349 | + $invoice |
|
350 | + ); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
355 | - * Processes recurring invoices. |
|
356 | - * |
|
357 | - * @param array $paypal_args PayPal args. |
|
358 | - * @param WPInv_Invoice $invoice Invoice object. |
|
359 | - */ |
|
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
355 | + * Processes recurring invoices. |
|
356 | + * |
|
357 | + * @param array $paypal_args PayPal args. |
|
358 | + * @param WPInv_Invoice $invoice Invoice object. |
|
359 | + */ |
|
360 | + public function process_subscription( $paypal_args, $invoice ) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | 363 | if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
@@ -382,11 +382,11 @@ discard block |
||
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
385 | - // Trial period length. |
|
386 | - $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
385 | + // Trial period length. |
|
386 | + $paypal_args['p1'] = $subscription_item->get_trial_interval(); |
|
387 | 387 | |
388 | - // Trial period. |
|
389 | - $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
388 | + // Trial period. |
|
389 | + $paypal_args['t1'] = $subscription_item->get_trial_period(); |
|
390 | 390 | |
391 | 391 | } else if ( $initial_amount != $recurring_amount ) { |
392 | 392 | |
@@ -409,40 +409,40 @@ discard block |
||
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
413 | 413 | |
414 | - // Subscription price |
|
415 | - $paypal_args['a3'] = $recurring_amount; |
|
414 | + // Subscription price |
|
415 | + $paypal_args['a3'] = $recurring_amount; |
|
416 | 416 | |
417 | - // Subscription duration |
|
418 | - $paypal_args['p3'] = $interval; |
|
417 | + // Subscription duration |
|
418 | + $paypal_args['p3'] = $interval; |
|
419 | 419 | |
420 | - // Subscription period |
|
421 | - $paypal_args['t3'] = $period; |
|
420 | + // Subscription period |
|
421 | + $paypal_args['t3'] = $period; |
|
422 | 422 | |
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
427 | 427 | |
428 | - // Non-recurring payments |
|
429 | - $paypal_args['src'] = 0; |
|
428 | + // Non-recurring payments |
|
429 | + $paypal_args['src'] = 0; |
|
430 | 430 | |
431 | - } else { |
|
431 | + } else { |
|
432 | 432 | |
433 | - $paypal_args['src'] = 1; |
|
433 | + $paypal_args['src'] = 1; |
|
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ( $bill_times > 0 ) { |
|
436 | 436 | |
437 | - // An initial period is being used to charge a sign-up fee |
|
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | - $bill_times--; |
|
440 | - } |
|
437 | + // An initial period is being used to charge a sign-up fee |
|
438 | + if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
439 | + $bill_times--; |
|
440 | + } |
|
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | 443 | $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
444 | 444 | |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | // Force return URL so that order description & instructions display |
@@ -458,19 +458,19 @@ discard block |
||
458 | 458 | } |
459 | 459 | |
460 | 460 | return apply_filters( |
461 | - 'getpaid_paypal_subscription_args', |
|
462 | - $paypal_args, |
|
463 | - $invoice |
|
461 | + 'getpaid_paypal_subscription_args', |
|
462 | + $paypal_args, |
|
463 | + $invoice |
|
464 | 464 | ); |
465 | 465 | |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | - * Processes ipns and marks payments as complete. |
|
470 | - * |
|
471 | - * @return void |
|
472 | - */ |
|
473 | - public function verify_ipn() { |
|
469 | + * Processes ipns and marks payments as complete. |
|
470 | + * |
|
471 | + * @return void |
|
472 | + */ |
|
473 | + public function verify_ipn() { |
|
474 | 474 | new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
475 | 475 | } |
476 | 476 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Paypal Payment Gateway class. |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @var array |
26 | 26 | */ |
27 | - protected $supports = array( 'subscription', 'sandbox' ); |
|
27 | + protected $supports = array('subscription', 'sandbox'); |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Payment method order. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @var array |
61 | 61 | */ |
62 | - public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ); |
|
62 | + public $currencies = array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR'); |
|
63 | 63 | |
64 | 64 | /** |
65 | 65 | * URL to view a transaction. |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function __construct() { |
82 | 82 | |
83 | - $this->title = __( 'PayPal Standard', 'invoicing' ); |
|
84 | - $this->method_title = __( 'PayPal Standard', 'invoicing' ); |
|
85 | - $this->checkout_button_text = __( 'Proceed to PayPal', 'invoicing' ); |
|
86 | - $this->notify_url = wpinv_get_ipn_url( $this->id ); |
|
83 | + $this->title = __('PayPal Standard', 'invoicing'); |
|
84 | + $this->method_title = __('PayPal Standard', 'invoicing'); |
|
85 | + $this->checkout_button_text = __('Proceed to PayPal', 'invoicing'); |
|
86 | + $this->notify_url = wpinv_get_ipn_url($this->id); |
|
87 | 87 | |
88 | - add_filter( 'getpaid_paypal_args', array( $this, 'process_subscription' ), 10, 2 ); |
|
89 | - add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 ); |
|
88 | + add_filter('getpaid_paypal_args', array($this, 'process_subscription'), 10, 2); |
|
89 | + add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2); |
|
90 | 90 | |
91 | 91 | parent::__construct(); |
92 | 92 | } |
@@ -100,16 +100,16 @@ discard block |
||
100 | 100 | * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
101 | 101 | * @return array |
102 | 102 | */ |
103 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
103 | + public function process_payment($invoice, $submission_data, $submission) { |
|
104 | 104 | |
105 | 105 | // Get redirect url. |
106 | - $paypal_redirect = $this->get_request_url( $invoice ); |
|
106 | + $paypal_redirect = $this->get_request_url($invoice); |
|
107 | 107 | |
108 | 108 | // Add a note about the request url. |
109 | 109 | $invoice->add_note( |
110 | 110 | sprintf( |
111 | - __( 'Redirecting to PayPal: %s', 'invoicing' ), |
|
112 | - esc_url( $paypal_redirect ) |
|
111 | + __('Redirecting to PayPal: %s', 'invoicing'), |
|
112 | + esc_url($paypal_redirect) |
|
113 | 113 | ), |
114 | 114 | false, |
115 | 115 | false, |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | |
119 | 119 | // Redirect to PayPal |
120 | - wp_redirect( $paypal_redirect ); |
|
120 | + wp_redirect($paypal_redirect); |
|
121 | 121 | exit; |
122 | 122 | |
123 | 123 | } |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param WPInv_Invoice $invoice Invoice object. |
129 | 129 | * @return string |
130 | 130 | */ |
131 | - public function get_request_url( $invoice ) { |
|
131 | + public function get_request_url($invoice) { |
|
132 | 132 | |
133 | 133 | // Endpoint for this request |
134 | - $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
134 | + $this->endpoint = $this->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?'; |
|
135 | 135 | |
136 | 136 | // Retrieve paypal args. |
137 | - $paypal_args = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' ); |
|
137 | + $paypal_args = map_deep($this->get_paypal_args($invoice), 'urlencode'); |
|
138 | 138 | |
139 | - if ( $invoice->is_recurring() ) { |
|
139 | + if ($invoice->is_recurring()) { |
|
140 | 140 | $paypal_args['bn'] = 'GetPaid_Subscribe_WPS_US'; |
141 | 141 | } else { |
142 | 142 | $paypal_args['bn'] = 'GetPaid_ShoppingCart_WPS_US'; |
143 | 143 | } |
144 | 144 | |
145 | - return add_query_arg( $paypal_args, $this->endpoint ); |
|
145 | + return add_query_arg($paypal_args, $this->endpoint); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,25 +152,25 @@ discard block |
||
152 | 152 | * @param WPInv_Invoice $invoice Invoice object. |
153 | 153 | * @return array |
154 | 154 | */ |
155 | - protected function get_paypal_args( $invoice ) { |
|
155 | + protected function get_paypal_args($invoice) { |
|
156 | 156 | |
157 | 157 | // Whether or not to send the line items as one item. |
158 | - $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice ); |
|
158 | + $force_one_line_item = apply_filters('getpaid_paypal_force_one_line_item', false, $invoice); |
|
159 | 159 | |
160 | - if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) { |
|
160 | + if ($invoice->is_recurring() || (wpinv_use_taxes() && wpinv_prices_include_tax())) { |
|
161 | 161 | $force_one_line_item = true; |
162 | 162 | } |
163 | 163 | |
164 | 164 | $paypal_args = apply_filters( |
165 | 165 | 'getpaid_paypal_args', |
166 | 166 | array_merge( |
167 | - $this->get_transaction_args( $invoice ), |
|
168 | - $this->get_line_item_args( $invoice, $force_one_line_item ) |
|
167 | + $this->get_transaction_args($invoice), |
|
168 | + $this->get_line_item_args($invoice, $force_one_line_item) |
|
169 | 169 | ), |
170 | 170 | $invoice |
171 | 171 | ); |
172 | 172 | |
173 | - return $this->fix_request_length( $invoice, $paypal_args ); |
|
173 | + return $this->fix_request_length($invoice, $paypal_args); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
@@ -179,11 +179,11 @@ discard block |
||
179 | 179 | * @param WPInv_Invoice $invoice Invoice object. |
180 | 180 | * @return array |
181 | 181 | */ |
182 | - protected function get_transaction_args( $invoice ) { |
|
182 | + protected function get_transaction_args($invoice) { |
|
183 | 183 | |
184 | 184 | return array( |
185 | 185 | 'cmd' => '_cart', |
186 | - 'business' => wpinv_get_option( 'paypal_email', false ), |
|
186 | + 'business' => wpinv_get_option('paypal_email', false), |
|
187 | 187 | 'no_shipping' => '1', |
188 | 188 | 'shipping' => '0', |
189 | 189 | 'no_note' => '1', |
@@ -191,16 +191,16 @@ discard block |
||
191 | 191 | 'rm' => is_ssl() ? 2 : 1, |
192 | 192 | 'upload' => 1, |
193 | 193 | 'currency_code' => $invoice->get_currency(), // https://developer.paypal.com/docs/nvp-soap-api/currency-codes/#paypal |
194 | - 'return' => esc_url_raw( $this->get_return_url( $invoice ) ), |
|
195 | - 'cancel_return' => esc_url_raw( $invoice->get_checkout_payment_url() ), |
|
196 | - 'notify_url' => getpaid_limit_length( $this->notify_url, 255 ), |
|
197 | - 'invoice' => getpaid_limit_length( $invoice->get_number(), 127 ), |
|
194 | + 'return' => esc_url_raw($this->get_return_url($invoice)), |
|
195 | + 'cancel_return' => esc_url_raw($invoice->get_checkout_payment_url()), |
|
196 | + 'notify_url' => getpaid_limit_length($this->notify_url, 255), |
|
197 | + 'invoice' => getpaid_limit_length($invoice->get_number(), 127), |
|
198 | 198 | 'custom' => $invoice->get_id(), |
199 | - 'first_name' => getpaid_limit_length( $invoice->get_first_name(), 32 ), |
|
200 | - 'last_name' => getpaid_limit_length( $invoice->get_last_name(), 64 ), |
|
201 | - 'country' => getpaid_limit_length( $invoice->get_country(), 2 ), |
|
202 | - 'email' => getpaid_limit_length( $invoice->get_email(), 127 ), |
|
203 | - 'cbt' => get_bloginfo( 'name' ) |
|
199 | + 'first_name' => getpaid_limit_length($invoice->get_first_name(), 32), |
|
200 | + 'last_name' => getpaid_limit_length($invoice->get_last_name(), 64), |
|
201 | + 'country' => getpaid_limit_length($invoice->get_country(), 2), |
|
202 | + 'email' => getpaid_limit_length($invoice->get_email(), 127), |
|
203 | + 'cbt' => get_bloginfo('name') |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
@@ -212,30 +212,30 @@ discard block |
||
212 | 212 | * @param bool $force_one_line_item Create only one item for this invoice. |
213 | 213 | * @return array |
214 | 214 | */ |
215 | - protected function get_line_item_args( $invoice, $force_one_line_item = false ) { |
|
215 | + protected function get_line_item_args($invoice, $force_one_line_item = false) { |
|
216 | 216 | |
217 | 217 | // Maybe send invoice as a single item. |
218 | - if ( $force_one_line_item ) { |
|
219 | - return $this->get_line_item_args_single_item( $invoice ); |
|
218 | + if ($force_one_line_item) { |
|
219 | + return $this->get_line_item_args_single_item($invoice); |
|
220 | 220 | } |
221 | 221 | |
222 | 222 | // Send each line item individually. |
223 | 223 | $line_item_args = array(); |
224 | 224 | |
225 | 225 | // Prepare line items. |
226 | - $this->prepare_line_items( $invoice ); |
|
226 | + $this->prepare_line_items($invoice); |
|
227 | 227 | |
228 | 228 | // Add taxes to the cart |
229 | - if ( wpinv_use_taxes() && $invoice->is_taxable() ) { |
|
230 | - $line_item_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_tax(), 2 ); |
|
229 | + if (wpinv_use_taxes() && $invoice->is_taxable()) { |
|
230 | + $line_item_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_tax(), 2); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Add discount. |
234 | - if ( $invoice->get_total_discount() > 0 ) { |
|
235 | - $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 ); |
|
234 | + if ($invoice->get_total_discount() > 0) { |
|
235 | + $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount((float) $invoice->get_total_discount(), 2); |
|
236 | 236 | } |
237 | 237 | |
238 | - return array_merge( $line_item_args, $this->get_line_items() ); |
|
238 | + return array_merge($line_item_args, $this->get_line_items()); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -245,11 +245,11 @@ discard block |
||
245 | 245 | * @param WPInv_Invoice $invoice Invoice object. |
246 | 246 | * @return array |
247 | 247 | */ |
248 | - protected function get_line_item_args_single_item( $invoice ) { |
|
248 | + protected function get_line_item_args_single_item($invoice) { |
|
249 | 249 | $this->delete_line_items(); |
250 | 250 | |
251 | - $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
252 | - $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() ); |
|
251 | + $item_name = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
252 | + $this->add_line_item($item_name, 1, wpinv_sanitize_amount((float) $invoice->get_total(), 2), $invoice->get_id()); |
|
253 | 253 | |
254 | 254 | return $this->get_line_items(); |
255 | 255 | } |
@@ -273,19 +273,19 @@ discard block |
||
273 | 273 | * |
274 | 274 | * @param WPInv_Invoice $invoice Invoice object. |
275 | 275 | */ |
276 | - protected function prepare_line_items( $invoice ) { |
|
276 | + protected function prepare_line_items($invoice) { |
|
277 | 277 | $this->delete_line_items(); |
278 | 278 | |
279 | 279 | // Items. |
280 | - foreach ( $invoice->get_items() as $item ) { |
|
280 | + foreach ($invoice->get_items() as $item) { |
|
281 | 281 | $amount = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total(); |
282 | 282 | $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity(); |
283 | - $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() ); |
|
283 | + $this->add_line_item($item->get_raw_name(), $quantity, $amount, $item->get_id()); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | // Fees. |
287 | - foreach ( $invoice->get_fees() as $fee => $data ) { |
|
288 | - $this->add_line_item( $fee, 1, wpinv_sanitize_amount( $data['initial_fee'] ) ); |
|
287 | + foreach ($invoice->get_fees() as $fee => $data) { |
|
288 | + $this->add_line_item($fee, 1, wpinv_sanitize_amount($data['initial_fee'])); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
@@ -298,15 +298,15 @@ discard block |
||
298 | 298 | * @param float $amount Amount. |
299 | 299 | * @param string $item_number Item number. |
300 | 300 | */ |
301 | - protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) { |
|
302 | - $index = ( count( $this->line_items ) / 4 ) + 1; |
|
301 | + protected function add_line_item($item_name, $quantity = 1, $amount = 0.0, $item_number = '') { |
|
302 | + $index = (count($this->line_items) / 4) + 1; |
|
303 | 303 | |
304 | 304 | $item = apply_filters( |
305 | 305 | 'getpaid_paypal_line_item', |
306 | 306 | array( |
307 | - 'item_name' => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ), |
|
307 | + 'item_name' => html_entity_decode(getpaid_limit_length($item_name ? wp_strip_all_tags($item_name) : __('Item', 'invoicing'), 127), ENT_NOQUOTES, 'UTF-8'), |
|
308 | 308 | 'quantity' => (int) $quantity, |
309 | - 'amount' => wpinv_sanitize_amount( (float) $amount, 2 ), |
|
309 | + 'amount' => wpinv_sanitize_amount((float) $amount, 2), |
|
310 | 310 | 'item_number' => $item_number, |
311 | 311 | ), |
312 | 312 | $item_name, |
@@ -315,12 +315,12 @@ discard block |
||
315 | 315 | $item_number |
316 | 316 | ); |
317 | 317 | |
318 | - $this->line_items[ 'item_name_' . $index ] = getpaid_limit_length( $item['item_name'], 127 ); |
|
319 | - $this->line_items[ 'quantity_' . $index ] = $item['quantity']; |
|
318 | + $this->line_items['item_name_' . $index] = getpaid_limit_length($item['item_name'], 127); |
|
319 | + $this->line_items['quantity_' . $index] = $item['quantity']; |
|
320 | 320 | |
321 | 321 | // The price or amount of the product, service, or contribution, not including shipping, handling, or tax. |
322 | - $this->line_items[ 'amount_' . $index ] = $item['amount']; |
|
323 | - $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 ); |
|
322 | + $this->line_items['amount_' . $index] = $item['amount']; |
|
323 | + $this->line_items['item_number_' . $index] = getpaid_limit_length($item['item_number'], 127); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | /** |
@@ -332,19 +332,19 @@ discard block |
||
332 | 332 | * @param array $paypal_args Arguments sent to Paypal in the request. |
333 | 333 | * @return array |
334 | 334 | */ |
335 | - protected function fix_request_length( $invoice, $paypal_args ) { |
|
335 | + protected function fix_request_length($invoice, $paypal_args) { |
|
336 | 336 | $max_paypal_length = 2083; |
337 | - $query_candidate = http_build_query( $paypal_args, '', '&' ); |
|
337 | + $query_candidate = http_build_query($paypal_args, '', '&'); |
|
338 | 338 | |
339 | - if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) { |
|
339 | + if (strlen($this->endpoint . $query_candidate) <= $max_paypal_length) { |
|
340 | 340 | return $paypal_args; |
341 | 341 | } |
342 | 342 | |
343 | 343 | return apply_filters( |
344 | 344 | 'getpaid_paypal_args', |
345 | 345 | array_merge( |
346 | - $this->get_transaction_args( $invoice ), |
|
347 | - $this->get_line_item_args( $invoice, true ) |
|
346 | + $this->get_transaction_args($invoice), |
|
347 | + $this->get_line_item_args($invoice, true) |
|
348 | 348 | ), |
349 | 349 | $invoice |
350 | 350 | ); |
@@ -357,10 +357,10 @@ discard block |
||
357 | 357 | * @param array $paypal_args PayPal args. |
358 | 358 | * @param WPInv_Invoice $invoice Invoice object. |
359 | 359 | */ |
360 | - public function process_subscription( $paypal_args, $invoice ) { |
|
360 | + public function process_subscription($paypal_args, $invoice) { |
|
361 | 361 | |
362 | 362 | // Make sure this is a subscription. |
363 | - if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) { |
|
363 | + if (!$invoice->is_recurring() || !$subscription = wpinv_get_subscription($invoice)) { |
|
364 | 364 | return $paypal_args; |
365 | 365 | } |
366 | 366 | |
@@ -368,17 +368,17 @@ discard block |
||
368 | 368 | $paypal_args['cmd'] = '_xclick-subscriptions'; |
369 | 369 | |
370 | 370 | // Subscription name. |
371 | - $paypal_args['item_name'] = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() ); |
|
371 | + $paypal_args['item_name'] = sprintf(__('Invoice #%s', 'invoicing'), $invoice->get_number()); |
|
372 | 372 | |
373 | 373 | // Get subscription args. |
374 | - $period = strtoupper( substr( $subscription->get_period(), 0, 1) ); |
|
374 | + $period = strtoupper(substr($subscription->get_period(), 0, 1)); |
|
375 | 375 | $interval = (int) $subscription->get_frequency(); |
376 | 376 | $bill_times = (int) $subscription->get_bill_times(); |
377 | - $initial_amount = (float) wpinv_sanitize_amount( $invoice->get_initial_total(), 2 ); |
|
378 | - $recurring_amount = (float) wpinv_sanitize_amount( $invoice->get_recurring_total(), 2 ); |
|
379 | - $subscription_item = $invoice->get_recurring( true ); |
|
377 | + $initial_amount = (float) wpinv_sanitize_amount($invoice->get_initial_total(), 2); |
|
378 | + $recurring_amount = (float) wpinv_sanitize_amount($invoice->get_recurring_total(), 2); |
|
379 | + $subscription_item = $invoice->get_recurring(true); |
|
380 | 380 | |
381 | - if ( $subscription_item->has_free_trial() ) { |
|
381 | + if ($subscription_item->has_free_trial()) { |
|
382 | 382 | |
383 | 383 | $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount; |
384 | 384 | |
@@ -388,28 +388,28 @@ discard block |
||
388 | 388 | // Trial period. |
389 | 389 | $paypal_args['t1'] = $subscription_item->get_trial_period(); |
390 | 390 | |
391 | - } else if ( $initial_amount != $recurring_amount ) { |
|
391 | + } else if ($initial_amount != $recurring_amount) { |
|
392 | 392 | |
393 | 393 | // No trial period, but initial amount includes a sign-up fee and/or other items, so charge it as a separate period. |
394 | 394 | |
395 | - if ( 1 == $bill_times ) { |
|
395 | + if (1 == $bill_times) { |
|
396 | 396 | $param_number = 3; |
397 | 397 | } else { |
398 | 398 | $param_number = 1; |
399 | 399 | } |
400 | 400 | |
401 | - $paypal_args[ 'a' . $param_number ] = $initial_amount ? 0 : $initial_amount; |
|
401 | + $paypal_args['a' . $param_number] = $initial_amount ? 0 : $initial_amount; |
|
402 | 402 | |
403 | 403 | // Sign Up interval |
404 | - $paypal_args[ 'p' . $param_number ] = $interval; |
|
404 | + $paypal_args['p' . $param_number] = $interval; |
|
405 | 405 | |
406 | 406 | // Sign Up unit of duration |
407 | - $paypal_args[ 't' . $param_number ] = $period; |
|
407 | + $paypal_args['t' . $param_number] = $period; |
|
408 | 408 | |
409 | 409 | } |
410 | 410 | |
411 | 411 | // We have a recurring payment |
412 | - if ( ! isset( $param_number ) || 1 == $param_number ) { |
|
412 | + if (!isset($param_number) || 1 == $param_number) { |
|
413 | 413 | |
414 | 414 | // Subscription price |
415 | 415 | $paypal_args['a3'] = $recurring_amount; |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // Recurring payments |
426 | - if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) { |
|
426 | + if (1 == $bill_times || ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial() && 2 == $bill_times)) { |
|
427 | 427 | |
428 | 428 | // Non-recurring payments |
429 | 429 | $paypal_args['src'] = 0; |
@@ -432,15 +432,15 @@ discard block |
||
432 | 432 | |
433 | 433 | $paypal_args['src'] = 1; |
434 | 434 | |
435 | - if ( $bill_times > 0 ) { |
|
435 | + if ($bill_times > 0) { |
|
436 | 436 | |
437 | 437 | // An initial period is being used to charge a sign-up fee |
438 | - if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) { |
|
438 | + if ($initial_amount != $recurring_amount && !$subscription_item->has_free_trial()) { |
|
439 | 439 | $bill_times--; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Make sure it's not over the max of 52 |
443 | - $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 ); |
|
443 | + $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52); |
|
444 | 444 | |
445 | 445 | } |
446 | 446 | } |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | $paypal_args['rm'] = 2; |
450 | 450 | |
451 | 451 | // Get rid of redudant items. |
452 | - foreach ( array( 'item_name_1', 'quantity_1', 'amount_1', 'item_number_1' ) as $arg ) { |
|
452 | + foreach (array('item_name_1', 'quantity_1', 'amount_1', 'item_number_1') as $arg) { |
|
453 | 453 | |
454 | - if ( isset( $paypal_args[ $arg ] ) ) { |
|
455 | - unset( $paypal_args[ $arg ] ); |
|
454 | + if (isset($paypal_args[$arg])) { |
|
455 | + unset($paypal_args[$arg]); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | } |
@@ -471,16 +471,16 @@ discard block |
||
471 | 471 | * @return void |
472 | 472 | */ |
473 | 473 | public function verify_ipn() { |
474 | - new GetPaid_Paypal_Gateway_IPN_Handler( $this ); |
|
474 | + new GetPaid_Paypal_Gateway_IPN_Handler($this); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | 478 | * Displays a notice on the checkout page if sandbox is enabled. |
479 | 479 | */ |
480 | - public function sandbox_notice( $description, $gateway ) { |
|
481 | - if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) { |
|
480 | + public function sandbox_notice($description, $gateway) { |
|
481 | + if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) { |
|
482 | 482 | $description .= '<br> <br>' . sprintf( |
483 | - __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ), |
|
483 | + __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'), |
|
484 | 484 | '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">', |
485 | 485 | '</a>' |
486 | 486 | ); |
@@ -232,26 +232,26 @@ discard block |
||
232 | 232 | } |
233 | 233 | |
234 | 234 | function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
235 | + $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | 238 | if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | - } |
|
244 | + if ( false !== $chosen ) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
246 | + } |
|
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | - $enabled_gateway = 'manual'; |
|
252 | - } else { |
|
253 | - $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | - } |
|
248 | + if ( ! empty ( $chosen ) ) { |
|
249 | + $enabled_gateway = urldecode( $chosen ); |
|
250 | + } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
251 | + $enabled_gateway = 'manual'; |
|
252 | + } else { |
|
253 | + $enabled_gateway = wpinv_get_default_gateway(); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
257 | 257 | if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | function wpinv_record_gateway_error( $title = '', $message = '' ) { |
@@ -270,21 +270,21 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
273 | - $ret = 0; |
|
274 | - $args = array( |
|
275 | - 'meta_key' => '_wpinv_gateway', |
|
276 | - 'meta_value' => $gateway_id, |
|
277 | - 'nopaging' => true, |
|
278 | - 'post_type' => 'wpi_invoice', |
|
279 | - 'post_status' => $status, |
|
280 | - 'fields' => 'ids' |
|
281 | - ); |
|
282 | - |
|
283 | - $payments = new WP_Query( $args ); |
|
284 | - |
|
285 | - if( $payments ) |
|
286 | - $ret = $payments->post_count; |
|
287 | - return $ret; |
|
273 | + $ret = 0; |
|
274 | + $args = array( |
|
275 | + 'meta_key' => '_wpinv_gateway', |
|
276 | + 'meta_value' => $gateway_id, |
|
277 | + 'nopaging' => true, |
|
278 | + 'post_type' => 'wpi_invoice', |
|
279 | + 'post_status' => $status, |
|
280 | + 'fields' => 'ids' |
|
281 | + ); |
|
282 | + |
|
283 | + $payments = new WP_Query( $args ); |
|
284 | + |
|
285 | + if( $payments ) |
|
286 | + $ret = $payments->post_count; |
|
287 | + return $ret; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | function wpinv_settings_update_gateways( $input ) { |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains gateway functions. |
4 | 4 | * |
5 | 5 | */ |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Returns an array of payment gateways. |
@@ -11,141 +11,141 @@ discard block |
||
11 | 11 | * @return array |
12 | 12 | */ |
13 | 13 | function wpinv_get_payment_gateways() { |
14 | - return apply_filters( 'wpinv_payment_gateways', array() ); |
|
14 | + return apply_filters('wpinv_payment_gateways', array()); |
|
15 | 15 | } |
16 | 16 | |
17 | -function wpinv_payment_gateway_titles( $all_gateways ) { |
|
17 | +function wpinv_payment_gateway_titles($all_gateways) { |
|
18 | 18 | global $wpinv_options; |
19 | 19 | |
20 | 20 | $gateways = array(); |
21 | - foreach ( $all_gateways as $key => $gateway ) { |
|
22 | - if ( !empty( $wpinv_options[$key . '_title'] ) ) { |
|
23 | - $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' ); |
|
21 | + foreach ($all_gateways as $key => $gateway) { |
|
22 | + if (!empty($wpinv_options[$key . '_title'])) { |
|
23 | + $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing'); |
|
24 | 24 | } |
25 | 25 | |
26 | - $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' ); |
|
26 | + $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : ''); |
|
27 | 27 | } |
28 | 28 | |
29 | - asort( $gateways ); |
|
29 | + asort($gateways); |
|
30 | 30 | |
31 | - foreach ( $gateways as $gateway => $key ) { |
|
31 | + foreach ($gateways as $gateway => $key) { |
|
32 | 32 | $gateways[$gateway] = $all_gateways[$gateway]; |
33 | 33 | } |
34 | 34 | |
35 | 35 | return $gateways; |
36 | 36 | } |
37 | -add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 ); |
|
37 | +add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1); |
|
38 | 38 | |
39 | -function wpinv_get_enabled_payment_gateways( $sort = false ) { |
|
39 | +function wpinv_get_enabled_payment_gateways($sort = false) { |
|
40 | 40 | $gateways = wpinv_get_payment_gateways(); |
41 | - $enabled = wpinv_get_option( 'gateways', false ); |
|
41 | + $enabled = wpinv_get_option('gateways', false); |
|
42 | 42 | |
43 | 43 | $gateway_list = array(); |
44 | 44 | |
45 | - foreach ( $gateways as $key => $gateway ) { |
|
46 | - if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) { |
|
47 | - $gateway_list[ $key ] = $gateway; |
|
45 | + foreach ($gateways as $key => $gateway) { |
|
46 | + if (isset($enabled[$key]) && $enabled[$key] == 1) { |
|
47 | + $gateway_list[$key] = $gateway; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | |
51 | - if ( true === $sort ) { |
|
52 | - uasort( $gateway_list, 'wpinv_sort_gateway_order' ); |
|
51 | + if (true === $sort) { |
|
52 | + uasort($gateway_list, 'wpinv_sort_gateway_order'); |
|
53 | 53 | |
54 | 54 | // Reorder our gateways so the default is first |
55 | 55 | $default_gateway_id = wpinv_get_default_gateway(); |
56 | 56 | |
57 | - if ( wpinv_is_gateway_active( $default_gateway_id ) ) { |
|
58 | - $default_gateway = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] ); |
|
59 | - unset( $gateway_list[ $default_gateway_id ] ); |
|
57 | + if (wpinv_is_gateway_active($default_gateway_id)) { |
|
58 | + $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]); |
|
59 | + unset($gateway_list[$default_gateway_id]); |
|
60 | 60 | |
61 | - $gateway_list = array_merge( $default_gateway, $gateway_list ); |
|
61 | + $gateway_list = array_merge($default_gateway, $gateway_list); |
|
62 | 62 | } |
63 | 63 | } |
64 | 64 | |
65 | - return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list ); |
|
65 | + return apply_filters('wpinv_enabled_payment_gateways', $gateway_list); |
|
66 | 66 | } |
67 | 67 | |
68 | -function wpinv_sort_gateway_order( $a, $b ) { |
|
68 | +function wpinv_sort_gateway_order($a, $b) { |
|
69 | 69 | return $a['ordering'] - $b['ordering']; |
70 | 70 | } |
71 | 71 | |
72 | -function wpinv_is_gateway_active( $gateway ) { |
|
72 | +function wpinv_is_gateway_active($gateway) { |
|
73 | 73 | $gateways = wpinv_get_enabled_payment_gateways(); |
74 | 74 | |
75 | - $ret = is_array($gateways) && $gateway ? array_key_exists( $gateway, $gateways ) : false; |
|
75 | + $ret = is_array($gateways) && $gateway ? array_key_exists($gateway, $gateways) : false; |
|
76 | 76 | |
77 | - return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways ); |
|
77 | + return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | function wpinv_get_default_gateway() { |
81 | - $default = wpinv_get_option( 'default_gateway', 'paypal' ); |
|
81 | + $default = wpinv_get_option('default_gateway', 'paypal'); |
|
82 | 82 | |
83 | - if ( !wpinv_is_gateway_active( $default ) ) { |
|
83 | + if (!wpinv_is_gateway_active($default)) { |
|
84 | 84 | $gateways = wpinv_get_enabled_payment_gateways(); |
85 | - $gateways = array_keys( $gateways ); |
|
86 | - $default = reset( $gateways ); |
|
85 | + $gateways = array_keys($gateways); |
|
86 | + $default = reset($gateways); |
|
87 | 87 | } |
88 | 88 | |
89 | - return apply_filters( 'wpinv_default_gateway', $default ); |
|
89 | + return apply_filters('wpinv_default_gateway', $default); |
|
90 | 90 | } |
91 | 91 | |
92 | -function wpinv_get_gateway_admin_label( $gateway ) { |
|
92 | +function wpinv_get_gateway_admin_label($gateway) { |
|
93 | 93 | $gateways = wpinv_get_payment_gateways(); |
94 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway; |
|
95 | - $payment = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false; |
|
94 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway; |
|
95 | + $payment = isset($_GET['id']) ? absint($_GET['id']) : false; |
|
96 | 96 | |
97 | - if( $gateway == 'manual' && $payment ) { |
|
98 | - if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) { |
|
99 | - $label = __( 'Free Purchase', 'invoicing' ); |
|
97 | + if ($gateway == 'manual' && $payment) { |
|
98 | + if (!((float) wpinv_payment_total($payment) > 0)) { |
|
99 | + $label = __('Free Purchase', 'invoicing'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway ); |
|
103 | + return apply_filters('wpinv_gateway_admin_label', $label, $gateway); |
|
104 | 104 | } |
105 | 105 | |
106 | -function wpinv_get_gateway_description( $gateway ) { |
|
106 | +function wpinv_get_gateway_description($gateway) { |
|
107 | 107 | global $wpinv_options; |
108 | 108 | |
109 | - $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
109 | + $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : ''; |
|
110 | 110 | |
111 | - return apply_filters( 'wpinv_gateway_description', $description, $gateway ); |
|
111 | + return apply_filters('wpinv_gateway_description', $description, $gateway); |
|
112 | 112 | } |
113 | 113 | |
114 | -function wpinv_get_gateway_button_label( $gateway ) { |
|
115 | - return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' ); |
|
114 | +function wpinv_get_gateway_button_label($gateway) { |
|
115 | + return apply_filters('wpinv_gateway_' . $gateway . '_button_label', ''); |
|
116 | 116 | } |
117 | 117 | |
118 | -function wpinv_get_gateway_checkout_label( $gateway ) { |
|
118 | +function wpinv_get_gateway_checkout_label($gateway) { |
|
119 | 119 | $gateways = wpinv_get_payment_gateways(); |
120 | - $label = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway; |
|
120 | + $label = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway; |
|
121 | 121 | |
122 | - if ( $gateway == 'none' ) { |
|
123 | - $label = __( 'None', 'invoicing' ); |
|
122 | + if ($gateway == 'none') { |
|
123 | + $label = __('None', 'invoicing'); |
|
124 | 124 | } |
125 | 125 | |
126 | - return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway ); |
|
126 | + return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway); |
|
127 | 127 | } |
128 | 128 | |
129 | -function wpinv_settings_sections_gateways( $settings ) { |
|
129 | +function wpinv_settings_sections_gateways($settings) { |
|
130 | 130 | $gateways = wpinv_get_payment_gateways(); |
131 | 131 | |
132 | 132 | if (!empty($gateways)) { |
133 | - foreach ($gateways as $key => $gateway) { |
|
133 | + foreach ($gateways as $key => $gateway) { |
|
134 | 134 | $settings[$key] = $gateway['admin_label']; |
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
138 | 138 | return $settings; |
139 | 139 | } |
140 | -add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 ); |
|
140 | +add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1); |
|
141 | 141 | |
142 | 142 | /** |
143 | 143 | * Adds GateWay settings. |
144 | 144 | */ |
145 | -function wpinv_settings_gateways( $settings ) { |
|
145 | +function wpinv_settings_gateways($settings) { |
|
146 | 146 | |
147 | 147 | // Loop through each gateway. |
148 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
148 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
149 | 149 | |
150 | 150 | $gateway_settings = array( |
151 | 151 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | "{$key}_header" => array( |
154 | 154 | |
155 | 155 | 'id' => "{$key}_gateway_header", |
156 | - 'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>', |
|
156 | + 'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>', |
|
157 | 157 | 'custom' => $key, |
158 | 158 | 'type' => 'gateway_header', |
159 | 159 | |
@@ -162,56 +162,56 @@ discard block |
||
162 | 162 | // Activate/Deactivate a gateway. |
163 | 163 | "{$key}_active" => array( |
164 | 164 | 'id' => $key . '_active', |
165 | - 'name' => __( 'Activate', 'invoicing' ), |
|
166 | - 'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ), |
|
165 | + 'name' => __('Activate', 'invoicing'), |
|
166 | + 'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']), |
|
167 | 167 | 'type' => 'checkbox', |
168 | 168 | ), |
169 | 169 | |
170 | 170 | // Activate/Deactivate sandbox. |
171 | 171 | "{$key}_sandbox" => array( |
172 | 172 | 'id' => $key . '_sandbox', |
173 | - 'name' => __( 'Sandbox', 'invoicing' ), |
|
174 | - 'desc' => __( 'Enable sandbox to test payments', 'invoicing' ), |
|
173 | + 'name' => __('Sandbox', 'invoicing'), |
|
174 | + 'desc' => __('Enable sandbox to test payments', 'invoicing'), |
|
175 | 175 | 'type' => 'checkbox', |
176 | 176 | ), |
177 | 177 | |
178 | 178 | // Checkout title. |
179 | 179 | "{$key}_title" => array( |
180 | 180 | 'id' => $key . '_title', |
181 | - 'name' => __( 'Checkout Title', 'invoicing' ), |
|
182 | - 'std' => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '', |
|
181 | + 'name' => __('Checkout Title', 'invoicing'), |
|
182 | + 'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '', |
|
183 | 183 | 'type' => 'text', |
184 | 184 | ), |
185 | 185 | |
186 | 186 | // Checkout description. |
187 | 187 | "{$key}_desc" => array( |
188 | 188 | 'id' => $key . '_desc', |
189 | - 'name' => __( 'Checkout Description', 'invoicing' ), |
|
190 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
189 | + 'name' => __('Checkout Description', 'invoicing'), |
|
190 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
191 | 191 | 'type' => 'text', |
192 | 192 | ), |
193 | 193 | |
194 | 194 | // Checkout order. |
195 | 195 | "{$key}_ordering" => array( |
196 | 196 | 'id' => $key . '_ordering', |
197 | - 'name' => __( 'Priority', 'invoicing' ), |
|
198 | - 'std' => apply_filters( "getpaid_default_{$key}_checkout_description", '' ), |
|
197 | + 'name' => __('Priority', 'invoicing'), |
|
198 | + 'std' => apply_filters("getpaid_default_{$key}_checkout_description", ''), |
|
199 | 199 | 'type' => 'number', |
200 | 200 | 'step' => '1', |
201 | 201 | 'min' => '-100000', |
202 | 202 | 'max' => '100000', |
203 | - 'std' => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10', |
|
203 | + 'std' => isset($gateway['ordering']) ? $gateway['ordering'] : '10', |
|
204 | 204 | ), |
205 | 205 | |
206 | 206 | ); |
207 | 207 | |
208 | 208 | // Maybe remove the sandbox. |
209 | - if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) { |
|
210 | - unset( $gateway_settings["{$key}_sandbox"] ); |
|
209 | + if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) { |
|
210 | + unset($gateway_settings["{$key}_sandbox"]); |
|
211 | 211 | } |
212 | 212 | |
213 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway ); |
|
214 | - $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway ); |
|
213 | + $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway); |
|
214 | + $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway); |
|
215 | 215 | |
216 | 216 | $settings[$key] = $gateway_settings; |
217 | 217 | } |
@@ -219,57 +219,57 @@ discard block |
||
219 | 219 | return $settings; |
220 | 220 | |
221 | 221 | } |
222 | -add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 ); |
|
222 | +add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1); |
|
223 | 223 | |
224 | -function wpinv_gateway_header_callback( $args ) { |
|
225 | - echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />'; |
|
224 | +function wpinv_gateway_header_callback($args) { |
|
225 | + echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />'; |
|
226 | 226 | } |
227 | 227 | |
228 | -function wpinv_get_gateway_supports( $gateway ) { |
|
228 | +function wpinv_get_gateway_supports($gateway) { |
|
229 | 229 | $gateways = wpinv_get_enabled_payment_gateways(); |
230 | - $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array(); |
|
231 | - return apply_filters( 'wpinv_gateway_supports', $supports, $gateway ); |
|
230 | + $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array(); |
|
231 | + return apply_filters('wpinv_gateway_supports', $supports, $gateway); |
|
232 | 232 | } |
233 | 233 | |
234 | -function wpinv_get_chosen_gateway( $invoice_id = 0 ) { |
|
235 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
234 | +function wpinv_get_chosen_gateway($invoice_id = 0) { |
|
235 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
236 | 236 | |
237 | 237 | $chosen = false; |
238 | - if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
238 | + if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) { |
|
239 | 239 | $chosen = $invoice->get_gateway(); |
240 | 240 | } |
241 | 241 | |
242 | - $chosen = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen; |
|
242 | + $chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen; |
|
243 | 243 | |
244 | - if ( false !== $chosen ) { |
|
245 | - $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen ); |
|
244 | + if (false !== $chosen) { |
|
245 | + $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( ! empty ( $chosen ) ) { |
|
249 | - $enabled_gateway = urldecode( $chosen ); |
|
250 | - } else if ( !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) { |
|
248 | + if (!empty ($chosen)) { |
|
249 | + $enabled_gateway = urldecode($chosen); |
|
250 | + } else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) { |
|
251 | 251 | $enabled_gateway = 'manual'; |
252 | 252 | } else { |
253 | 253 | $enabled_gateway = wpinv_get_default_gateway(); |
254 | 254 | } |
255 | 255 | |
256 | - if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) { |
|
257 | - if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){ |
|
256 | + if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) { |
|
257 | + if (wpinv_is_gateway_active(wpinv_get_default_gateway())) { |
|
258 | 258 | $enabled_gateway = wpinv_get_default_gateway(); |
259 | - }else{ |
|
259 | + } else { |
|
260 | 260 | $enabled_gateway = $gateways[0]; |
261 | 261 | } |
262 | 262 | |
263 | 263 | } |
264 | 264 | |
265 | - return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway ); |
|
265 | + return apply_filters('wpinv_chosen_gateway', $enabled_gateway); |
|
266 | 266 | } |
267 | 267 | |
268 | -function wpinv_record_gateway_error( $title = '', $message = '' ) { |
|
269 | - return wpinv_error_log( $message, $title ); |
|
268 | +function wpinv_record_gateway_error($title = '', $message = '') { |
|
269 | + return wpinv_error_log($message, $title); |
|
270 | 270 | } |
271 | 271 | |
272 | -function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) { |
|
272 | +function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') { |
|
273 | 273 | $ret = 0; |
274 | 274 | $args = array( |
275 | 275 | 'meta_key' => '_wpinv_gateway', |
@@ -280,48 +280,48 @@ discard block |
||
280 | 280 | 'fields' => 'ids' |
281 | 281 | ); |
282 | 282 | |
283 | - $payments = new WP_Query( $args ); |
|
283 | + $payments = new WP_Query($args); |
|
284 | 284 | |
285 | - if( $payments ) |
|
285 | + if ($payments) |
|
286 | 286 | $ret = $payments->post_count; |
287 | 287 | return $ret; |
288 | 288 | } |
289 | 289 | |
290 | -function wpinv_settings_update_gateways( $input ) { |
|
290 | +function wpinv_settings_update_gateways($input) { |
|
291 | 291 | global $wpinv_options; |
292 | 292 | |
293 | - if ( !empty( $input['save_gateway'] ) ) { |
|
294 | - $gateways = wpinv_get_option( 'gateways', false ); |
|
293 | + if (!empty($input['save_gateway'])) { |
|
294 | + $gateways = wpinv_get_option('gateways', false); |
|
295 | 295 | $gateways = !empty($gateways) ? $gateways : array(); |
296 | 296 | $gateway = $input['save_gateway']; |
297 | 297 | |
298 | - if ( !empty( $input[$gateway . '_active'] ) ) { |
|
298 | + if (!empty($input[$gateway . '_active'])) { |
|
299 | 299 | $gateways[$gateway] = 1; |
300 | 300 | } else { |
301 | - if ( isset( $gateways[$gateway] ) ) { |
|
302 | - unset( $gateways[$gateway] ); |
|
301 | + if (isset($gateways[$gateway])) { |
|
302 | + unset($gateways[$gateway]); |
|
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | 306 | $input['gateways'] = $gateways; |
307 | 307 | } |
308 | 308 | |
309 | - if ( !empty( $input['default_gateway'] ) ) { |
|
309 | + if (!empty($input['default_gateway'])) { |
|
310 | 310 | $gateways = wpinv_get_payment_gateways(); |
311 | 311 | |
312 | - foreach ( $gateways as $key => $gateway ) { |
|
313 | - $active = 0; |
|
314 | - if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) { |
|
312 | + foreach ($gateways as $key => $gateway) { |
|
313 | + $active = 0; |
|
314 | + if (!empty($input['gateways']) && !empty($input['gateways'][$key])) { |
|
315 | 315 | $active = 1; |
316 | 316 | } |
317 | 317 | |
318 | 318 | $input[$key . '_active'] = $active; |
319 | 319 | |
320 | - if ( empty( $wpinv_options[$key . '_title'] ) ) { |
|
320 | + if (empty($wpinv_options[$key . '_title'])) { |
|
321 | 321 | $input[$key . '_title'] = $gateway['checkout_label']; |
322 | 322 | } |
323 | 323 | |
324 | - if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) { |
|
324 | + if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) { |
|
325 | 325 | $input[$key . '_ordering'] = $gateway['ordering']; |
326 | 326 | } |
327 | 327 | } |
@@ -329,27 +329,27 @@ discard block |
||
329 | 329 | |
330 | 330 | return $input; |
331 | 331 | } |
332 | -add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 ); |
|
332 | +add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1); |
|
333 | 333 | |
334 | 334 | // PayPal Standard settings |
335 | -function wpinv_gateway_settings_paypal( $setting ) { |
|
336 | - $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' ); |
|
337 | - $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' ); |
|
335 | +function wpinv_gateway_settings_paypal($setting) { |
|
336 | + $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing'); |
|
337 | + $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing'); |
|
338 | 338 | |
339 | 339 | $setting['paypal_sandbox'] = array( |
340 | 340 | 'type' => 'checkbox', |
341 | 341 | 'id' => 'paypal_sandbox', |
342 | - 'name' => __( 'PayPal Sandbox', 'invoicing' ), |
|
343 | - 'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ), |
|
342 | + 'name' => __('PayPal Sandbox', 'invoicing'), |
|
343 | + 'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'), |
|
344 | 344 | 'std' => 1 |
345 | 345 | ); |
346 | 346 | |
347 | 347 | $setting['paypal_email'] = array( |
348 | 348 | 'type' => 'text', |
349 | 349 | 'id' => 'paypal_email', |
350 | - 'name' => __( 'PayPal Email', 'invoicing' ), |
|
351 | - 'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ), |
|
352 | - 'std' => __( '[email protected]', 'invoicing' ), |
|
350 | + 'name' => __('PayPal Email', 'invoicing'), |
|
351 | + 'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'), |
|
352 | + 'std' => __('[email protected]', 'invoicing'), |
|
353 | 353 | ); |
354 | 354 | /* |
355 | 355 | $setting['paypal_ipn_url'] = array( |
@@ -363,18 +363,18 @@ discard block |
||
363 | 363 | |
364 | 364 | return $setting; |
365 | 365 | } |
366 | -add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 ); |
|
366 | +add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1); |
|
367 | 367 | |
368 | 368 | /** |
369 | 369 | * Displays the ipn url field. |
370 | 370 | */ |
371 | -function wpinv_ipn_url_callback( $args ) { |
|
372 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
371 | +function wpinv_ipn_url_callback($args) { |
|
372 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
373 | 373 | |
374 | 374 | $attrs = $args['readonly'] ? ' readonly' : ''; |
375 | 375 | |
376 | - $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
377 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
376 | + $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">'; |
|
377 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>'; |
|
378 | 378 | |
379 | 379 | echo $html; |
380 | 380 | } |
@@ -386,9 +386,9 @@ discard block |
||
386 | 386 | * |
387 | 387 | * @return bool |
388 | 388 | */ |
389 | -function wpinv_is_test_mode( $gateway = '' ) { |
|
390 | - $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", false ); |
|
391 | - return apply_filters( 'wpinv_is_test_mode', $sandbox, $gateway ); |
|
389 | +function wpinv_is_test_mode($gateway = '') { |
|
390 | + $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", false); |
|
391 | + return apply_filters('wpinv_is_test_mode', $sandbox, $gateway); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | /** |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * |
400 | 400 | * @return string |
401 | 401 | */ |
402 | -function wpinv_get_ipn_url( $gateway = false, $args = array() ) { |
|
402 | +function wpinv_get_ipn_url($gateway = false, $args = array()) { |
|
403 | 403 | $args = wp_parse_args( |
404 | 404 | array( |
405 | 405 | 'wpi-listener' => 'IPN', |
@@ -408,37 +408,37 @@ discard block |
||
408 | 408 | $args |
409 | 409 | ); |
410 | 410 | |
411 | - return apply_filters( 'wpinv_ipn_url', add_query_arg( $args, home_url( 'index.php' ) ), $gateway, $args ); |
|
411 | + return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args); |
|
412 | 412 | |
413 | 413 | } |
414 | 414 | |
415 | 415 | /** |
416 | 416 | * Retrieves request data with slashes removed slashes. |
417 | 417 | */ |
418 | -function wpinv_get_post_data( $method = 'request' ) { |
|
418 | +function wpinv_get_post_data($method = 'request') { |
|
419 | 419 | |
420 | - if ( $method == 'post' ) { |
|
421 | - return wp_unslash( $_POST ); |
|
420 | + if ($method == 'post') { |
|
421 | + return wp_unslash($_POST); |
|
422 | 422 | } |
423 | 423 | |
424 | - if ( $method == 'get' ) { |
|
425 | - return wp_unslash( $_GET ); |
|
424 | + if ($method == 'get') { |
|
425 | + return wp_unslash($_GET); |
|
426 | 426 | } |
427 | 427 | |
428 | - return wp_unslash( $_REQUEST ); |
|
428 | + return wp_unslash($_REQUEST); |
|
429 | 429 | |
430 | 430 | } |
431 | 431 | |
432 | 432 | /** |
433 | 433 | * Checks if a given gateway supports subscription payments. |
434 | 434 | */ |
435 | -function wpinv_gateway_support_subscription( $gateway ) { |
|
435 | +function wpinv_gateway_support_subscription($gateway) { |
|
436 | 436 | $supports = false; |
437 | 437 | |
438 | - if ( wpinv_is_gateway_active( $gateway ) ) { |
|
439 | - $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports ); |
|
438 | + if (wpinv_is_gateway_active($gateway)) { |
|
439 | + $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports); |
|
440 | 440 | |
441 | - $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway ); |
|
441 | + $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway); |
|
442 | 442 | } |
443 | 443 | |
444 | 444 | return $supports; |
@@ -450,14 +450,14 @@ discard block |
||
450 | 450 | * @param array $gateways an array of gateways. |
451 | 451 | * @param GetPaid_Payment_Form $form payment form. |
452 | 452 | */ |
453 | -function wpinv_payment_gateways_on_cart( $gateways, $form ) { |
|
453 | +function wpinv_payment_gateways_on_cart($gateways, $form) { |
|
454 | 454 | |
455 | - if ( $form->is_recurring() ) { |
|
455 | + if ($form->is_recurring()) { |
|
456 | 456 | |
457 | - foreach ( array_keys( $gateways ) as $gateway ) { |
|
457 | + foreach (array_keys($gateways) as $gateway) { |
|
458 | 458 | |
459 | - if ( ! wpinv_gateway_support_subscription( $gateway ) ) { |
|
460 | - unset( $gateways[$gateway] ); |
|
459 | + if (!wpinv_gateway_support_subscription($gateway)) { |
|
460 | + unset($gateways[$gateway]); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | } |
@@ -466,4 +466,4 @@ discard block |
||
466 | 466 | |
467 | 467 | return $gateways; |
468 | 468 | } |
469 | -add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 ); |
|
469 | +add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2); |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * Please use GetPaid_Notification_Email_Sender |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /* |
12 | 12 | |-------------------------------------------------------------------------- |
@@ -17,19 +17,19 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * Generates the email header. |
19 | 19 | */ |
20 | -function wpinv_email_header( $email_heading ) { |
|
21 | - wpinv_get_template( 'emails/wpinv-email-header.php', compact( 'email_heading' ) ); |
|
20 | +function wpinv_email_header($email_heading) { |
|
21 | + wpinv_get_template('emails/wpinv-email-header.php', compact('email_heading')); |
|
22 | 22 | } |
23 | -add_action( 'wpinv_email_header', 'wpinv_email_header' ); |
|
23 | +add_action('wpinv_email_header', 'wpinv_email_header'); |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Generates the email footer. |
28 | 28 | */ |
29 | 29 | function wpinv_email_footer() { |
30 | - wpinv_get_template( 'emails/wpinv-email-footer.php' ); |
|
30 | + wpinv_get_template('emails/wpinv-email-footer.php'); |
|
31 | 31 | } |
32 | -add_action( 'wpinv_email_footer', 'wpinv_email_footer' ); |
|
32 | +add_action('wpinv_email_footer', 'wpinv_email_footer'); |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -39,13 +39,13 @@ discard block |
||
39 | 39 | * @param string $email_type |
40 | 40 | * @param bool $sent_to_admin |
41 | 41 | */ |
42 | -function wpinv_email_invoice_details( $invoice, $email_type, $sent_to_admin ) { |
|
42 | +function wpinv_email_invoice_details($invoice, $email_type, $sent_to_admin) { |
|
43 | 43 | |
44 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
45 | - wpinv_get_template( 'emails/invoice-details.php', $args ); |
|
44 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
45 | + wpinv_get_template('emails/invoice-details.php', $args); |
|
46 | 46 | |
47 | 47 | } |
48 | -add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 ); |
|
48 | +add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3); |
|
49 | 49 | |
50 | 50 | |
51 | 51 | /** |
@@ -55,17 +55,17 @@ discard block |
||
55 | 55 | * @param string $email_type |
56 | 56 | * @param bool $sent_to_admin |
57 | 57 | */ |
58 | -function wpinv_email_invoice_items( $invoice, $email_type, $sent_to_admin ) { |
|
58 | +function wpinv_email_invoice_items($invoice, $email_type, $sent_to_admin) { |
|
59 | 59 | |
60 | 60 | // Prepare line items. |
61 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
62 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
61 | + $columns = getpaid_invoice_item_columns($invoice); |
|
62 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
63 | 63 | |
64 | 64 | // Load the template. |
65 | - wpinv_get_template( 'emails/invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) ); |
|
65 | + wpinv_get_template('emails/invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin')); |
|
66 | 66 | |
67 | 67 | } |
68 | -add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 ); |
|
68 | +add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3); |
|
69 | 69 | |
70 | 70 | |
71 | 71 | /** |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | * @param string $email_type |
76 | 76 | * @param bool $sent_to_admin |
77 | 77 | */ |
78 | -function wpinv_email_billing_details( $invoice, $email_type, $sent_to_admin ) { |
|
78 | +function wpinv_email_billing_details($invoice, $email_type, $sent_to_admin) { |
|
79 | 79 | |
80 | - $args = compact( 'invoice', 'email_type', 'sent_to_admin' ); |
|
81 | - wpinv_get_template( 'emails/wpinv-email-billing-details.php', $args ); |
|
80 | + $args = compact('invoice', 'email_type', 'sent_to_admin'); |
|
81 | + wpinv_get_template('emails/wpinv-email-billing-details.php', $args); |
|
82 | 82 | |
83 | 83 | } |
84 | -add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 ); |
|
84 | +add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3); |
|
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Returns email css. |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | */ |
90 | 90 | function getpaid_get_email_css() { |
91 | 91 | |
92 | - $css = wpinv_get_template_html( 'emails/wpinv-email-styles.php' ); |
|
93 | - return apply_filters( 'wpinv_email_styles', $css ); |
|
92 | + $css = wpinv_get_template_html('emails/wpinv-email-styles.php'); |
|
93 | + return apply_filters('wpinv_email_styles', $css); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -101,26 +101,26 @@ discard block |
||
101 | 101 | * @return string |
102 | 102 | * |
103 | 103 | */ |
104 | -function wpinv_email_style_body( $content ) { |
|
104 | +function wpinv_email_style_body($content) { |
|
105 | 105 | |
106 | - if ( ! class_exists( 'DOMDocument' ) ) { |
|
106 | + if (!class_exists('DOMDocument')) { |
|
107 | 107 | return $content; |
108 | 108 | } |
109 | 109 | |
110 | 110 | $css = getpaid_get_email_css(); |
111 | 111 | |
112 | 112 | // include css inliner |
113 | - if ( ! class_exists( 'Emogrifier' ) ) { |
|
114 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
113 | + if (!class_exists('Emogrifier')) { |
|
114 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | // Inline the css. |
118 | 118 | try { |
119 | - $emogrifier = new Emogrifier( $content, $css ); |
|
119 | + $emogrifier = new Emogrifier($content, $css); |
|
120 | 120 | $_content = $emogrifier->emogrify(); |
121 | 121 | $content = $_content; |
122 | - } catch ( Exception $e ) { |
|
123 | - wpinv_error_log( $e->getMessage(), 'emogrifier' ); |
|
122 | + } catch (Exception $e) { |
|
123 | + wpinv_error_log($e->getMessage(), 'emogrifier'); |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | return $content; |
@@ -129,37 +129,37 @@ discard block |
||
129 | 129 | |
130 | 130 | // Backwards compatibility. |
131 | 131 | function wpinv_init_transactional_emails() { |
132 | - foreach ( apply_filters( 'wpinv_email_actions', array() ) as $action ) { |
|
133 | - add_action( $action, 'wpinv_send_transactional_email', 10, 10 ); |
|
132 | + foreach (apply_filters('wpinv_email_actions', array()) as $action) { |
|
133 | + add_action($action, 'wpinv_send_transactional_email', 10, 10); |
|
134 | 134 | } |
135 | 135 | } |
136 | -add_action( 'init', 'wpinv_init_transactional_emails' ); |
|
136 | +add_action('init', 'wpinv_init_transactional_emails'); |
|
137 | 137 | |
138 | 138 | function wpinv_send_transactional_email() { |
139 | 139 | $args = func_get_args(); |
140 | 140 | $function = current_filter() . '_notification'; |
141 | - do_action_ref_array( $function, $args ); |
|
141 | + do_action_ref_array($function, $args); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | function wpinv_mail_get_from_address() { |
145 | - $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) ); |
|
146 | - return sanitize_email( $from_address ); |
|
145 | + $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from')); |
|
146 | + return sanitize_email($from_address); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | function wpinv_mail_get_from_name() { |
150 | - $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) ); |
|
151 | - return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES ); |
|
150 | + $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name')); |
|
151 | + return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES); |
|
152 | 152 | } |
153 | 153 | |
154 | -function wpinv_mail_admin_bcc_active( $mail_type = '' ) { |
|
155 | - $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) ); |
|
156 | - return ( $active ? true : false ); |
|
154 | +function wpinv_mail_admin_bcc_active($mail_type = '') { |
|
155 | + $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc')); |
|
156 | + return ($active ? true : false); |
|
157 | 157 | } |
158 | 158 | |
159 | -function wpinv_mail_get_content_type( $content_type = 'text/html', $email_type = 'html' ) { |
|
160 | - $email_type = apply_filters( 'wpinv_mail_content_type', $email_type ); |
|
159 | +function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') { |
|
160 | + $email_type = apply_filters('wpinv_mail_content_type', $email_type); |
|
161 | 161 | |
162 | - switch ( $email_type ) { |
|
162 | + switch ($email_type) { |
|
163 | 163 | case 'html' : |
164 | 164 | $content_type = 'text/html'; |
165 | 165 | break; |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @param array $attachments Any files to attach to the email. |
185 | 185 | * @param string|array $cc An email or array of extra emails to send a copy of the email to. |
186 | 186 | */ |
187 | -function wpinv_mail_send( $to, $subject, $message, $deprecated, $attachments = array(), $cc = array() ) { |
|
187 | +function wpinv_mail_send($to, $subject, $message, $deprecated, $attachments = array(), $cc = array()) { |
|
188 | 188 | |
189 | 189 | $mailer = new GetPaid_Notification_Email_Sender(); |
190 | - $message = wpinv_email_style_body( $message ); |
|
191 | - $to = array_merge( wpinv_parse_list( $to ), wpinv_parse_list( $cc ) ); |
|
190 | + $message = wpinv_email_style_body($message); |
|
191 | + $to = array_merge(wpinv_parse_list($to), wpinv_parse_list($cc)); |
|
192 | 192 | |
193 | 193 | return $mailer->send( |
194 | 194 | $to, |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @return array |
206 | 206 | */ |
207 | 207 | function wpinv_get_emails() { |
208 | - return apply_filters( 'wpinv_get_emails', wpinv_get_data( 'email-settings' ) ); |
|
208 | + return apply_filters('wpinv_get_emails', wpinv_get_data('email-settings')); |
|
209 | 209 | } |
210 | 210 | |
211 | 211 | /** |
@@ -214,172 +214,172 @@ discard block |
||
214 | 214 | * @param array $settings |
215 | 215 | * @return array |
216 | 216 | */ |
217 | -function wpinv_settings_emails( $settings = array() ) { |
|
218 | - $settings = array_merge( $settings, wpinv_get_emails() ); |
|
219 | - return apply_filters( 'wpinv_settings_get_emails', $settings ); |
|
217 | +function wpinv_settings_emails($settings = array()) { |
|
218 | + $settings = array_merge($settings, wpinv_get_emails()); |
|
219 | + return apply_filters('wpinv_settings_get_emails', $settings); |
|
220 | 220 | } |
221 | -add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 ); |
|
221 | +add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1); |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Filter email section names. |
225 | 225 | * |
226 | 226 | */ |
227 | -function wpinv_settings_sections_emails( $settings ) { |
|
228 | - foreach ( wpinv_get_emails() as $key => $email) { |
|
229 | - $settings[$key] = ! empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : strip_tags( $key ); |
|
227 | +function wpinv_settings_sections_emails($settings) { |
|
228 | + foreach (wpinv_get_emails() as $key => $email) { |
|
229 | + $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : strip_tags($key); |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | return $settings; |
233 | 233 | } |
234 | -add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 ); |
|
234 | +add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1); |
|
235 | 235 | |
236 | -function wpinv_email_is_enabled( $email_type ) { |
|
236 | +function wpinv_email_is_enabled($email_type) { |
|
237 | 237 | $emails = wpinv_get_emails(); |
238 | - $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false; |
|
238 | + $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false; |
|
239 | 239 | |
240 | - return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type ); |
|
240 | + return apply_filters('wpinv_email_is_enabled', $enabled, $email_type); |
|
241 | 241 | } |
242 | 242 | |
243 | -function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
244 | - switch ( $email_type ) { |
|
243 | +function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
244 | + switch ($email_type) { |
|
245 | 245 | case 'new_invoice': |
246 | 246 | case 'cancelled_invoice': |
247 | 247 | case 'failed_invoice': |
248 | 248 | $recipient = wpinv_get_admin_email(); |
249 | 249 | break; |
250 | 250 | default: |
251 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
252 | - $recipient = !empty( $invoice ) ? $invoice->get_email() : ''; |
|
251 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
252 | + $recipient = !empty($invoice) ? $invoice->get_email() : ''; |
|
253 | 253 | break; |
254 | 254 | } |
255 | 255 | |
256 | - return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice ); |
|
256 | + return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice); |
|
257 | 257 | } |
258 | 258 | |
259 | 259 | /** |
260 | 260 | * Returns invoice CC recipients |
261 | 261 | */ |
262 | -function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
263 | - switch ( $email_type ) { |
|
262 | +function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
263 | + switch ($email_type) { |
|
264 | 264 | case 'new_invoice': |
265 | 265 | case 'cancelled_invoice': |
266 | 266 | case 'failed_invoice': |
267 | 267 | return array(); |
268 | 268 | break; |
269 | 269 | default: |
270 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
271 | - $recipient = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true ); |
|
272 | - if ( empty( $recipient ) ) { |
|
270 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
271 | + $recipient = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true); |
|
272 | + if (empty($recipient)) { |
|
273 | 273 | return array(); |
274 | 274 | } |
275 | - return array_filter( array_map( 'trim', explode( ',', $recipient ) ) ); |
|
275 | + return array_filter(array_map('trim', explode(',', $recipient))); |
|
276 | 276 | break; |
277 | 277 | } |
278 | 278 | |
279 | 279 | } |
280 | 280 | |
281 | -function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
282 | - $subject = wpinv_get_option( 'email_' . $email_type . '_subject' ); |
|
283 | - $subject = __( $subject, 'invoicing' ); |
|
281 | +function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
282 | + $subject = wpinv_get_option('email_' . $email_type . '_subject'); |
|
283 | + $subject = __($subject, 'invoicing'); |
|
284 | 284 | |
285 | - $subject = wpinv_email_format_text( $subject, $invoice ); |
|
285 | + $subject = wpinv_email_format_text($subject, $invoice); |
|
286 | 286 | |
287 | - return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice ); |
|
287 | + return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice); |
|
288 | 288 | } |
289 | 289 | |
290 | -function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
291 | - $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' ); |
|
292 | - $email_heading = __( $email_heading, 'invoicing' ); |
|
290 | +function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
291 | + $email_heading = wpinv_get_option('email_' . $email_type . '_heading'); |
|
292 | + $email_heading = __($email_heading, 'invoicing'); |
|
293 | 293 | |
294 | - $email_heading = wpinv_email_format_text( $email_heading, $invoice ); |
|
294 | + $email_heading = wpinv_email_format_text($email_heading, $invoice); |
|
295 | 295 | |
296 | - return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice ); |
|
296 | + return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice); |
|
297 | 297 | } |
298 | 298 | |
299 | -function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
300 | - $content = wpinv_get_option( 'email_' . $email_type . '_body' ); |
|
301 | - $content = __( $content, 'invoicing' ); |
|
299 | +function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
300 | + $content = wpinv_get_option('email_' . $email_type . '_body'); |
|
301 | + $content = __($content, 'invoicing'); |
|
302 | 302 | |
303 | - $content = wpinv_email_format_text( $content, $invoice ); |
|
303 | + $content = wpinv_email_format_text($content, $invoice); |
|
304 | 304 | |
305 | - return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice ); |
|
305 | + return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice); |
|
306 | 306 | } |
307 | 307 | |
308 | -function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
308 | +function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
309 | 309 | $from_name = wpinv_mail_get_from_address(); |
310 | 310 | $from_email = wpinv_mail_get_from_address(); |
311 | 311 | |
312 | - $invoice = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL ); |
|
312 | + $invoice = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL); |
|
313 | 313 | |
314 | - $headers = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n"; |
|
315 | - $headers .= "Reply-To: ". $from_email . "\r\n"; |
|
314 | + $headers = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n"; |
|
315 | + $headers .= "Reply-To: " . $from_email . "\r\n"; |
|
316 | 316 | $headers .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n"; |
317 | 317 | |
318 | - return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice ); |
|
318 | + return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice); |
|
319 | 319 | } |
320 | 320 | |
321 | -function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) { |
|
321 | +function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) { |
|
322 | 322 | $attachments = array(); |
323 | 323 | |
324 | - return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice ); |
|
324 | + return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice); |
|
325 | 325 | } |
326 | 326 | |
327 | 327 | /** |
328 | 328 | * Searches for and replaces certain placeholders in an email. |
329 | 329 | */ |
330 | -function wpinv_email_format_text( $content, $invoice ) { |
|
330 | +function wpinv_email_format_text($content, $invoice) { |
|
331 | 331 | |
332 | 332 | $replace_array = array( |
333 | 333 | '{site_title}' => wpinv_get_blogname(), |
334 | - '{date}' => getpaid_format_date( current_time( 'mysql' ) ), |
|
334 | + '{date}' => getpaid_format_date(current_time('mysql')), |
|
335 | 335 | ); |
336 | 336 | |
337 | - $invoice = new WPInv_Invoice( $invoice ); |
|
337 | + $invoice = new WPInv_Invoice($invoice); |
|
338 | 338 | |
339 | - if ( $invoice->get_id() ) { |
|
339 | + if ($invoice->get_id()) { |
|
340 | 340 | |
341 | 341 | $replace_array = array_merge( |
342 | 342 | $replace_array, |
343 | 343 | array( |
344 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
345 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
346 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
347 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
348 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
349 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
350 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total( true ) ) ), |
|
351 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
352 | - '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ), |
|
353 | - '{invoice_date}' => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ), |
|
354 | - '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ), |
|
355 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
356 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
357 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
344 | + '{name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
345 | + '{full_name}' => sanitize_text_field($invoice->get_user_full_name()), |
|
346 | + '{first_name}' => sanitize_text_field($invoice->get_first_name()), |
|
347 | + '{last_name}' => sanitize_text_field($invoice->get_last_name()), |
|
348 | + '{email}' => sanitize_email($invoice->get_email()), |
|
349 | + '{invoice_number}' => sanitize_text_field($invoice->get_number()), |
|
350 | + '{invoice_total}' => wpinv_price(wpinv_format_amount($invoice->get_total(true))), |
|
351 | + '{invoice_link}' => esc_url($invoice->get_view_url()), |
|
352 | + '{invoice_pay_link}'=> esc_url($invoice->get_checkout_payment_url()), |
|
353 | + '{invoice_date}' => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))), |
|
354 | + '{invoice_due_date}'=> date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))), |
|
355 | + '{invoice_quote}' => sanitize_text_field($invoice->get_type()), |
|
356 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_type())), |
|
357 | + '{is_was}' => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'), |
|
358 | 358 | ) |
359 | 359 | ); |
360 | 360 | |
361 | 361 | } |
362 | 362 | |
363 | 363 | // Let third party plugins filter the arra. |
364 | - $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice ); |
|
364 | + $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice); |
|
365 | 365 | |
366 | - foreach ( $replace_array as $key => $value ) { |
|
367 | - $content = str_replace( $key, $value, $content ); |
|
366 | + foreach ($replace_array as $key => $value) { |
|
367 | + $content = str_replace($key, $value, $content); |
|
368 | 368 | } |
369 | 369 | |
370 | - return apply_filters( 'wpinv_email_content_replace', $content ); |
|
370 | + return apply_filters('wpinv_email_content_replace', $content); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | |
374 | -function wpinv_email_wrap_message( $message ) { |
|
374 | +function wpinv_email_wrap_message($message) { |
|
375 | 375 | // Buffer |
376 | 376 | ob_start(); |
377 | 377 | |
378 | - do_action( 'wpinv_email_header' ); |
|
378 | + do_action('wpinv_email_header'); |
|
379 | 379 | |
380 | - echo wpautop( wptexturize( $message ) ); |
|
380 | + echo wpautop(wptexturize($message)); |
|
381 | 381 | |
382 | - do_action( 'wpinv_email_footer' ); |
|
382 | + do_action('wpinv_email_footer'); |
|
383 | 383 | |
384 | 384 | // Get contents |
385 | 385 | $message = ob_get_clean(); |
@@ -387,21 +387,21 @@ discard block |
||
387 | 387 | return $message; |
388 | 388 | } |
389 | 389 | |
390 | -function wpinv_add_notes_to_invoice_email( $invoice, $email_type ) { |
|
391 | - if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) { |
|
392 | - $date_format = get_option( 'date_format' ); |
|
393 | - $time_format = get_option( 'time_format' ); |
|
390 | +function wpinv_add_notes_to_invoice_email($invoice, $email_type) { |
|
391 | + if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) { |
|
392 | + $date_format = get_option('date_format'); |
|
393 | + $time_format = get_option('time_format'); |
|
394 | 394 | ?> |
395 | 395 | <div id="wpinv-email-notes"> |
396 | - <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3> |
|
396 | + <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3> |
|
397 | 397 | <ol class="wpinv-notes-lists"> |
398 | 398 | <?php |
399 | - foreach ( $invoice_notes as $note ) { |
|
400 | - $note_time = strtotime( $note->comment_date ); |
|
399 | + foreach ($invoice_notes as $note) { |
|
400 | + $note_time = strtotime($note->comment_date); |
|
401 | 401 | ?> |
402 | 402 | <li class="comment wpinv-note"> |
403 | - <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p> |
|
404 | - <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div> |
|
403 | + <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p> |
|
404 | + <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div> |
|
405 | 405 | </li> |
406 | 406 | <?php |
407 | 407 | } |
@@ -410,4 +410,4 @@ discard block |
||
410 | 410 | <?php |
411 | 411 | } |
412 | 412 | } |
413 | -add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 ); |
|
413 | +add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3); |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Personal data exporters. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * WPInv_Privacy_Exporters Class. |
@@ -17,38 +17,38 @@ discard block |
||
17 | 17 | * @param int $page Page. |
18 | 18 | * @return array An array of invoice data in name value pairs |
19 | 19 | */ |
20 | - public static function customer_invoice_data_exporter( $email_address, $page ) { |
|
20 | + public static function customer_invoice_data_exporter($email_address, $page) { |
|
21 | 21 | $done = false; |
22 | 22 | $page = (int) $page; |
23 | 23 | $data_to_export = array(); |
24 | 24 | |
25 | - $user = get_user_by( 'email', $email_address ); |
|
26 | - if ( ! $user instanceof WP_User ) { |
|
25 | + $user = get_user_by('email', $email_address); |
|
26 | + if (!$user instanceof WP_User) { |
|
27 | 27 | return array( |
28 | 28 | 'data' => $data_to_export, |
29 | 29 | 'done' => true, |
30 | 30 | ); |
31 | 31 | } |
32 | 32 | |
33 | - $args = array( |
|
33 | + $args = array( |
|
34 | 34 | 'limit' => 30, |
35 | 35 | 'page' => $page, |
36 | 36 | 'user' => $user->ID, |
37 | 37 | ); |
38 | 38 | |
39 | - $invoices = wpinv_get_invoices( $args ); |
|
39 | + $invoices = wpinv_get_invoices($args); |
|
40 | 40 | |
41 | - if ( 0 < count( $invoices ) ) { |
|
42 | - foreach ( $invoices as $invoice ) { |
|
41 | + if (0 < count($invoices)) { |
|
42 | + foreach ($invoices as $invoice) { |
|
43 | 43 | $data_to_export[] = array( |
44 | 44 | 'group_id' => 'customer_invoices', |
45 | - 'group_label' => __( 'Invoicing Data', 'invoicing' ), |
|
46 | - 'group_description' => __( 'Customer invoicing data.', 'invoicing' ), |
|
45 | + 'group_label' => __('Invoicing Data', 'invoicing'), |
|
46 | + 'group_description' => __('Customer invoicing data.', 'invoicing'), |
|
47 | 47 | 'item_id' => "wpinv-{$invoice->ID}", |
48 | - 'data' => self::get_customer_invoice_data( $invoice ), |
|
48 | + 'data' => self::get_customer_invoice_data($invoice), |
|
49 | 49 | ); |
50 | 50 | } |
51 | - $done = 30 > count( $invoices ); |
|
51 | + $done = 30 > count($invoices); |
|
52 | 52 | } else { |
53 | 53 | $done = true; |
54 | 54 | } |
@@ -66,59 +66,59 @@ discard block |
||
66 | 66 | * @param WPInv_Invoice $invoice invoice object. |
67 | 67 | * @return array |
68 | 68 | */ |
69 | - public static function get_customer_invoice_data( $invoice ) { |
|
69 | + public static function get_customer_invoice_data($invoice) { |
|
70 | 70 | $personal_data = array(); |
71 | 71 | |
72 | 72 | $props_to_export = array( |
73 | - 'number' => __( 'Invoice Number', 'invoicing' ), |
|
74 | - 'created_date' => __( 'Invoice Date', 'invoicing' ), |
|
75 | - 'status' => __( 'Invoice Status', 'invoicing' ), |
|
76 | - 'total' => __( 'Invoice Total', 'invoicing' ), |
|
77 | - 'items' => __( 'Invoice Items', 'invoicing' ), |
|
78 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
79 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
80 | - 'email' => __( 'Email Address', 'invoicing' ), |
|
81 | - '_wpinv_company' => __( 'Company', 'invoicing' ), |
|
82 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
83 | - 'address' => __( 'Address', 'invoicing' ), |
|
84 | - '_wpinv_city' => __( 'City', 'invoicing' ), |
|
85 | - '_wpinv_country' => __( 'Country', 'invoicing' ), |
|
86 | - '_wpinv_state' => __( 'State', 'invoicing' ), |
|
87 | - '_wpinv_zip' => __( 'Zip Code', 'invoicing' ), |
|
73 | + 'number' => __('Invoice Number', 'invoicing'), |
|
74 | + 'created_date' => __('Invoice Date', 'invoicing'), |
|
75 | + 'status' => __('Invoice Status', 'invoicing'), |
|
76 | + 'total' => __('Invoice Total', 'invoicing'), |
|
77 | + 'items' => __('Invoice Items', 'invoicing'), |
|
78 | + 'first_name' => __('First Name', 'invoicing'), |
|
79 | + 'last_name' => __('Last Name', 'invoicing'), |
|
80 | + 'email' => __('Email Address', 'invoicing'), |
|
81 | + '_wpinv_company' => __('Company', 'invoicing'), |
|
82 | + 'phone' => __('Phone Number', 'invoicing'), |
|
83 | + 'address' => __('Address', 'invoicing'), |
|
84 | + '_wpinv_city' => __('City', 'invoicing'), |
|
85 | + '_wpinv_country' => __('Country', 'invoicing'), |
|
86 | + '_wpinv_state' => __('State', 'invoicing'), |
|
87 | + '_wpinv_zip' => __('Zip Code', 'invoicing'), |
|
88 | 88 | ); |
89 | 89 | |
90 | - $subscription = wpinv_get_subscription( $invoice ); |
|
90 | + $subscription = wpinv_get_subscription($invoice); |
|
91 | 91 | $period = $initial_amt = $bill_times = $billed = $renewal_date = ''; |
92 | 92 | |
93 | - if ( $invoice->is_recurring() && !empty( $subscription ) ) { |
|
94 | - $frequency = getpaid_get_subscription_period_label( $subscription->get_period(),$subscription->get_frequency() ); |
|
95 | - $period = wpinv_price( wpinv_format_amount( $subscription->get_recurring_amount() ), $subscription->get_parent_payment()->get_currency() ) . ' / ' . $frequency; |
|
96 | - $initial_amt = wpinv_price( wpinv_format_amount( $subscription->get_initial_amount() ), $subscription->get_parent_payment()->get_currency() ); |
|
97 | - $bill_times = $subscription->get_times_billed() . ' / ' . ( ( $subscription->get_bill_times() == 0 ) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->get_bill_times() ); |
|
98 | - $renewal_date = ! empty( $subscription->get_expiration() ) ? getpaid_format_date( $subscription->get_expiration() ) : __( 'N/A', 'invoicing' ); |
|
99 | - |
|
100 | - $props_to_export['period'] = __( 'Billing Cycle', 'invoicing' ); |
|
101 | - $props_to_export['initial_amount'] = __( 'Initial Amount', 'invoicing' ); |
|
102 | - $props_to_export['bill_times'] = __( 'Times Billed', 'invoicing' ); |
|
103 | - $props_to_export['renewal_date'] = __( 'Renewal Date', 'invoicing' ); |
|
93 | + if ($invoice->is_recurring() && !empty($subscription)) { |
|
94 | + $frequency = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency()); |
|
95 | + $period = wpinv_price(wpinv_format_amount($subscription->get_recurring_amount()), $subscription->get_parent_payment()->get_currency()) . ' / ' . $frequency; |
|
96 | + $initial_amt = wpinv_price(wpinv_format_amount($subscription->get_initial_amount()), $subscription->get_parent_payment()->get_currency()); |
|
97 | + $bill_times = $subscription->get_times_billed() . ' / ' . (($subscription->get_bill_times() == 0) ? __('Until Cancelled', 'invoicing') : $subscription->get_bill_times()); |
|
98 | + $renewal_date = !empty($subscription->get_expiration()) ? getpaid_format_date($subscription->get_expiration()) : __('N/A', 'invoicing'); |
|
99 | + |
|
100 | + $props_to_export['period'] = __('Billing Cycle', 'invoicing'); |
|
101 | + $props_to_export['initial_amount'] = __('Initial Amount', 'invoicing'); |
|
102 | + $props_to_export['bill_times'] = __('Times Billed', 'invoicing'); |
|
103 | + $props_to_export['renewal_date'] = __('Renewal Date', 'invoicing'); |
|
104 | 104 | } |
105 | 105 | |
106 | - $props_to_export['ip'] = __( 'IP Address', 'invoicing' ); |
|
107 | - $props_to_export['view_url'] = __( 'Invoice Link', 'invoicing' ); |
|
106 | + $props_to_export['ip'] = __('IP Address', 'invoicing'); |
|
107 | + $props_to_export['view_url'] = __('Invoice Link', 'invoicing'); |
|
108 | 108 | |
109 | - $props_to_export = apply_filters( 'wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
109 | + $props_to_export = apply_filters('wpinv_privacy_export_invoice_personal_data_props', $props_to_export, $invoice, $subscription); |
|
110 | 110 | |
111 | - foreach ( $props_to_export as $prop => $name ) { |
|
111 | + foreach ($props_to_export as $prop => $name) { |
|
112 | 112 | $value = ''; |
113 | 113 | |
114 | - switch ( $prop ) { |
|
114 | + switch ($prop) { |
|
115 | 115 | case 'items': |
116 | 116 | $item_names = array(); |
117 | - foreach ( $invoice->get_cart_details() as $key => $cart_item ) { |
|
118 | - $item_quantity = $cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1; |
|
117 | + foreach ($invoice->get_cart_details() as $key => $cart_item) { |
|
118 | + $item_quantity = $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1; |
|
119 | 119 | $item_names[] = $cart_item['name'] . ' x ' . $item_quantity; |
120 | 120 | } |
121 | - $value = implode( ', ', $item_names ); |
|
121 | + $value = implode(', ', $item_names); |
|
122 | 122 | break; |
123 | 123 | case 'status': |
124 | 124 | $value = $invoice->get_status(true); |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | $value = $renewal_date; |
140 | 140 | break; |
141 | 141 | default: |
142 | - if ( is_callable( array( $invoice, 'get_' . $prop ) ) ) { |
|
142 | + if (is_callable(array($invoice, 'get_' . $prop))) { |
|
143 | 143 | $value = $invoice->{"get_$prop"}(); |
144 | 144 | } else { |
145 | 145 | $value = $invoice->get_meta($prop); |
@@ -147,9 +147,9 @@ discard block |
||
147 | 147 | break; |
148 | 148 | } |
149 | 149 | |
150 | - $value = apply_filters( 'wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice ); |
|
150 | + $value = apply_filters('wpi_privacy_export_invoice_personal_data_prop', $value, $prop, $invoice); |
|
151 | 151 | |
152 | - if ( $value ) { |
|
152 | + if ($value) { |
|
153 | 153 | $personal_data[] = array( |
154 | 154 | 'name' => $name, |
155 | 155 | 'value' => $value, |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | } |
160 | 160 | |
161 | - $personal_data = apply_filters( 'wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice ); |
|
161 | + $personal_data = apply_filters('wpinv_privacy_export_invoice_personal_data', $personal_data, $invoice); |
|
162 | 162 | |
163 | 163 | return $personal_data; |
164 | 164 |
@@ -14,420 +14,420 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Plugin { |
16 | 16 | |
17 | - /** |
|
18 | - * GetPaid version. |
|
19 | - * |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - public $version; |
|
23 | - |
|
24 | - /** |
|
25 | - * Data container. |
|
26 | - * |
|
27 | - * @var array |
|
28 | - */ |
|
29 | - protected $data = array(); |
|
30 | - |
|
31 | - /** |
|
32 | - * Form elements instance. |
|
33 | - * |
|
34 | - * @var WPInv_Payment_Form_Elements |
|
35 | - */ |
|
36 | - public $form_elements; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax instance. |
|
40 | - * |
|
41 | - * @var WPInv_EUVat |
|
42 | - */ |
|
43 | - public $tax; |
|
44 | - |
|
45 | - /** |
|
46 | - * @param array An array of payment gateways. |
|
47 | - */ |
|
48 | - public $gateways; |
|
49 | - |
|
50 | - /** |
|
51 | - * Class constructor. |
|
52 | - */ |
|
53 | - public function __construct() { |
|
54 | - $this->define_constants(); |
|
55 | - $this->includes(); |
|
56 | - $this->init_hooks(); |
|
57 | - $this->set_properties(); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Sets a custom data property. |
|
62 | - * |
|
63 | - * @param string $prop The prop to set. |
|
64 | - * @param mixed $value The value to retrieve. |
|
65 | - */ |
|
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Gets a custom data property. |
|
72 | - * |
|
73 | - * @param string $prop The prop to set. |
|
74 | - * @return mixed The value. |
|
75 | - */ |
|
76 | - public function get( $prop ) { |
|
77 | - |
|
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
80 | - } |
|
81 | - |
|
82 | - return null; |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Define class properties. |
|
87 | - */ |
|
88 | - public function set_properties() { |
|
89 | - |
|
90 | - // Sessions. |
|
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | - $this->tax = new WPInv_EUVat(); |
|
94 | - $this->tax->init(); |
|
95 | - $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | - |
|
97 | - // Init other objects. |
|
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Define plugin constants. |
|
115 | - */ |
|
116 | - public function define_constants() { |
|
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | - $this->version = WPINV_VERSION; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Hook into actions and filters. |
|
124 | - * |
|
125 | - * @since 1.0.19 |
|
126 | - */ |
|
127 | - protected function init_hooks() { |
|
128 | - /* Internationalize the text strings used. */ |
|
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | - |
|
131 | - // Init the plugin after WordPress inits. |
|
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | - |
|
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | - } |
|
140 | - |
|
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | - |
|
147 | - // Fires after registering actions. |
|
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - public function plugins_loaded() { |
|
154 | - /* Internationalize the text strings used. */ |
|
155 | - $this->load_textdomain(); |
|
156 | - |
|
157 | - do_action( 'wpinv_loaded' ); |
|
158 | - |
|
159 | - // Fix oxygen page builder conflict |
|
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
161 | - wpinv_oxygen_fix_conflict(); |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * Load the translation of the plugin. |
|
167 | - * |
|
168 | - * @since 1.0 |
|
169 | - */ |
|
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | - } |
|
174 | - |
|
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | - |
|
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | - |
|
181 | - /** |
|
182 | - * Define language constants. |
|
183 | - */ |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Include required core files used in admin and on the frontend. |
|
189 | - */ |
|
190 | - public function includes() { |
|
191 | - |
|
192 | - // Start with the settings. |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | - |
|
195 | - // Packages/libraries. |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | - |
|
199 | - // Load functions. |
|
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | - |
|
216 | - // Register autoloader. |
|
217 | - try { |
|
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | - } |
|
222 | - |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | - |
|
245 | - /** |
|
246 | - * Load the tax class. |
|
247 | - */ |
|
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | - } |
|
251 | - |
|
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | - GetPaid_Post_Types_Admin::init(); |
|
254 | - |
|
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | - // load the user class only on the users.php page |
|
264 | - global $pagenow; |
|
265 | - if($pagenow=='users.php'){ |
|
266 | - new WPInv_Admin_Users(); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - // Register cli commands |
|
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | - } |
|
275 | - |
|
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Class autoloader |
|
281 | - * |
|
282 | - * @param string $class_name The name of the class to load. |
|
283 | - * @access public |
|
284 | - * @since 1.0.19 |
|
285 | - * @return void |
|
286 | - */ |
|
287 | - public function autoload( $class_name ) { |
|
288 | - |
|
289 | - // Normalize the class name... |
|
290 | - $class_name = strtolower( $class_name ); |
|
291 | - |
|
292 | - // ... and make sure it is our class. |
|
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | - return; |
|
295 | - } |
|
296 | - |
|
297 | - // Next, prepare the file name from the class. |
|
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | - |
|
300 | - // Base path of the classes. |
|
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | - |
|
303 | - // And an array of possible locations in order of importance. |
|
304 | - $locations = array( |
|
305 | - "$plugin_path/includes", |
|
306 | - "$plugin_path/includes/data-stores", |
|
307 | - "$plugin_path/includes/gateways", |
|
308 | - "$plugin_path/includes/payments", |
|
309 | - "$plugin_path/includes/api", |
|
310 | - "$plugin_path/includes/admin", |
|
311 | - "$plugin_path/includes/admin/meta-boxes", |
|
312 | - ); |
|
313 | - |
|
314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | - |
|
316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | - include trailingslashit( $location ) . $file_name; |
|
318 | - break; |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - } |
|
324 | - |
|
325 | - /** |
|
326 | - * Inits hooks etc. |
|
327 | - */ |
|
328 | - public function init() { |
|
329 | - |
|
330 | - // Fires before getpaid inits. |
|
331 | - do_action( 'before_getpaid_init', $this ); |
|
332 | - |
|
333 | - // Load default gateways. |
|
334 | - $gateways = apply_filters( |
|
335 | - 'getpaid_default_gateways', |
|
336 | - array( |
|
337 | - 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | - 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | - 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | - 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | - 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | - ) |
|
343 | - ); |
|
344 | - |
|
345 | - foreach ( $gateways as $id => $class ) { |
|
346 | - $this->gateways[ $id ] = new $class(); |
|
347 | - } |
|
348 | - |
|
349 | - // Fires after getpaid inits. |
|
350 | - do_action( 'getpaid_init', $this ); |
|
351 | - |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Checks if this is an IPN request and processes it. |
|
356 | - */ |
|
357 | - public function maybe_process_ipn() { |
|
358 | - |
|
359 | - // Ensure that this is an IPN request. |
|
360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | - return; |
|
362 | - } |
|
363 | - |
|
364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | - |
|
366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | - exit; |
|
369 | - |
|
370 | - } |
|
371 | - |
|
372 | - public function enqueue_scripts() { |
|
373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | - |
|
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | - |
|
379 | - // Register scripts |
|
380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | - |
|
383 | - $localize = array(); |
|
384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | - $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
387 | - $localize['currency_pos'] = wpinv_currency_position(); |
|
388 | - $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
389 | - $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
390 | - $localize['decimals'] = wpinv_decimals(); |
|
391 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
392 | - $localize['UseTaxes'] = wpinv_use_taxes(); |
|
393 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
394 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
395 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
396 | - |
|
397 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
398 | - |
|
399 | - wp_enqueue_script( 'jquery-blockui' ); |
|
400 | - $autofill_api = wpinv_get_option('address_autofill_api'); |
|
401 | - $autofill_active = wpinv_get_option('address_autofill_active'); |
|
402 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
403 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
404 | - wp_dequeue_script( 'google-maps-api' ); |
|
405 | - } |
|
406 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
407 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
408 | - } |
|
409 | - |
|
410 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
411 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
412 | - |
|
413 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
414 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
415 | - |
|
416 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
417 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
418 | - } |
|
419 | - |
|
420 | - public function wpinv_actions() { |
|
421 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
422 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - /** |
|
17 | + /** |
|
18 | + * GetPaid version. |
|
19 | + * |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + public $version; |
|
23 | + |
|
24 | + /** |
|
25 | + * Data container. |
|
26 | + * |
|
27 | + * @var array |
|
28 | + */ |
|
29 | + protected $data = array(); |
|
30 | + |
|
31 | + /** |
|
32 | + * Form elements instance. |
|
33 | + * |
|
34 | + * @var WPInv_Payment_Form_Elements |
|
35 | + */ |
|
36 | + public $form_elements; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax instance. |
|
40 | + * |
|
41 | + * @var WPInv_EUVat |
|
42 | + */ |
|
43 | + public $tax; |
|
44 | + |
|
45 | + /** |
|
46 | + * @param array An array of payment gateways. |
|
47 | + */ |
|
48 | + public $gateways; |
|
49 | + |
|
50 | + /** |
|
51 | + * Class constructor. |
|
52 | + */ |
|
53 | + public function __construct() { |
|
54 | + $this->define_constants(); |
|
55 | + $this->includes(); |
|
56 | + $this->init_hooks(); |
|
57 | + $this->set_properties(); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Sets a custom data property. |
|
62 | + * |
|
63 | + * @param string $prop The prop to set. |
|
64 | + * @param mixed $value The value to retrieve. |
|
65 | + */ |
|
66 | + public function set( $prop, $value ) { |
|
67 | + $this->data[ $prop ] = $value; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Gets a custom data property. |
|
72 | + * |
|
73 | + * @param string $prop The prop to set. |
|
74 | + * @return mixed The value. |
|
75 | + */ |
|
76 | + public function get( $prop ) { |
|
77 | + |
|
78 | + if ( isset( $this->data[ $prop ] ) ) { |
|
79 | + return $this->data[ $prop ]; |
|
80 | + } |
|
81 | + |
|
82 | + return null; |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Define class properties. |
|
87 | + */ |
|
88 | + public function set_properties() { |
|
89 | + |
|
90 | + // Sessions. |
|
91 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | + $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
93 | + $this->tax = new WPInv_EUVat(); |
|
94 | + $this->tax->init(); |
|
95 | + $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
|
96 | + |
|
97 | + // Init other objects. |
|
98 | + $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | + $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | + $this->set( 'notes', new WPInv_Notes() ); |
|
101 | + $this->set( 'api', new WPInv_API() ); |
|
102 | + $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | + $this->set( 'template', new GetPaid_Template() ); |
|
104 | + $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | + $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | + $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | + $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | + $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | + $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Define plugin constants. |
|
115 | + */ |
|
116 | + public function define_constants() { |
|
117 | + define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | + define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
119 | + $this->version = WPINV_VERSION; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Hook into actions and filters. |
|
124 | + * |
|
125 | + * @since 1.0.19 |
|
126 | + */ |
|
127 | + protected function init_hooks() { |
|
128 | + /* Internationalize the text strings used. */ |
|
129 | + add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
130 | + |
|
131 | + // Init the plugin after WordPress inits. |
|
132 | + add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | + add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | + add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | + add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
136 | + |
|
137 | + if ( class_exists( 'BuddyPress' ) ) { |
|
138 | + add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
139 | + } |
|
140 | + |
|
141 | + add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | + add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | + add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | + add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | + add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
146 | + |
|
147 | + // Fires after registering actions. |
|
148 | + do_action( 'wpinv_actions', $this ); |
|
149 | + do_action( 'getpaid_actions', $this ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + public function plugins_loaded() { |
|
154 | + /* Internationalize the text strings used. */ |
|
155 | + $this->load_textdomain(); |
|
156 | + |
|
157 | + do_action( 'wpinv_loaded' ); |
|
158 | + |
|
159 | + // Fix oxygen page builder conflict |
|
160 | + if ( function_exists( 'ct_css_output' ) ) { |
|
161 | + wpinv_oxygen_fix_conflict(); |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * Load the translation of the plugin. |
|
167 | + * |
|
168 | + * @since 1.0 |
|
169 | + */ |
|
170 | + public function load_textdomain( $locale = NULL ) { |
|
171 | + if ( empty( $locale ) ) { |
|
172 | + $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
173 | + } |
|
174 | + |
|
175 | + $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
176 | + |
|
177 | + unload_textdomain( 'invoicing' ); |
|
178 | + load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | + load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
180 | + |
|
181 | + /** |
|
182 | + * Define language constants. |
|
183 | + */ |
|
184 | + require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Include required core files used in admin and on the frontend. |
|
189 | + */ |
|
190 | + public function includes() { |
|
191 | + |
|
192 | + // Start with the settings. |
|
193 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
194 | + |
|
195 | + // Packages/libraries. |
|
196 | + require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | + require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
198 | + |
|
199 | + // Load functions. |
|
200 | + require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | + require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | + require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | + require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
215 | + |
|
216 | + // Register autoloader. |
|
217 | + try { |
|
218 | + spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | + } catch ( Exception $e ) { |
|
220 | + wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
221 | + } |
|
222 | + |
|
223 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | + require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | + require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | + require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | + require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | + require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | + require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | + require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
244 | + |
|
245 | + /** |
|
246 | + * Load the tax class. |
|
247 | + */ |
|
248 | + if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | + require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
250 | + } |
|
251 | + |
|
252 | + if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
253 | + GetPaid_Post_Types_Admin::init(); |
|
254 | + |
|
255 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
263 | + // load the user class only on the users.php page |
|
264 | + global $pagenow; |
|
265 | + if($pagenow=='users.php'){ |
|
266 | + new WPInv_Admin_Users(); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + // Register cli commands |
|
271 | + if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | + WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
274 | + } |
|
275 | + |
|
276 | + require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Class autoloader |
|
281 | + * |
|
282 | + * @param string $class_name The name of the class to load. |
|
283 | + * @access public |
|
284 | + * @since 1.0.19 |
|
285 | + * @return void |
|
286 | + */ |
|
287 | + public function autoload( $class_name ) { |
|
288 | + |
|
289 | + // Normalize the class name... |
|
290 | + $class_name = strtolower( $class_name ); |
|
291 | + |
|
292 | + // ... and make sure it is our class. |
|
293 | + if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
294 | + return; |
|
295 | + } |
|
296 | + |
|
297 | + // Next, prepare the file name from the class. |
|
298 | + $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
299 | + |
|
300 | + // Base path of the classes. |
|
301 | + $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
302 | + |
|
303 | + // And an array of possible locations in order of importance. |
|
304 | + $locations = array( |
|
305 | + "$plugin_path/includes", |
|
306 | + "$plugin_path/includes/data-stores", |
|
307 | + "$plugin_path/includes/gateways", |
|
308 | + "$plugin_path/includes/payments", |
|
309 | + "$plugin_path/includes/api", |
|
310 | + "$plugin_path/includes/admin", |
|
311 | + "$plugin_path/includes/admin/meta-boxes", |
|
312 | + ); |
|
313 | + |
|
314 | + foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
315 | + |
|
316 | + if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | + include trailingslashit( $location ) . $file_name; |
|
318 | + break; |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + } |
|
324 | + |
|
325 | + /** |
|
326 | + * Inits hooks etc. |
|
327 | + */ |
|
328 | + public function init() { |
|
329 | + |
|
330 | + // Fires before getpaid inits. |
|
331 | + do_action( 'before_getpaid_init', $this ); |
|
332 | + |
|
333 | + // Load default gateways. |
|
334 | + $gateways = apply_filters( |
|
335 | + 'getpaid_default_gateways', |
|
336 | + array( |
|
337 | + 'manual' => 'GetPaid_Manual_Gateway', |
|
338 | + 'paypal' => 'GetPaid_Paypal_Gateway', |
|
339 | + 'worldpay' => 'GetPaid_Worldpay_Gateway', |
|
340 | + 'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway', |
|
341 | + 'authorizenet' => 'GetPaid_Authorize_Net_Gateway', |
|
342 | + ) |
|
343 | + ); |
|
344 | + |
|
345 | + foreach ( $gateways as $id => $class ) { |
|
346 | + $this->gateways[ $id ] = new $class(); |
|
347 | + } |
|
348 | + |
|
349 | + // Fires after getpaid inits. |
|
350 | + do_action( 'getpaid_init', $this ); |
|
351 | + |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Checks if this is an IPN request and processes it. |
|
356 | + */ |
|
357 | + public function maybe_process_ipn() { |
|
358 | + |
|
359 | + // Ensure that this is an IPN request. |
|
360 | + if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
361 | + return; |
|
362 | + } |
|
363 | + |
|
364 | + $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
365 | + |
|
366 | + do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | + do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
368 | + exit; |
|
369 | + |
|
370 | + } |
|
371 | + |
|
372 | + public function enqueue_scripts() { |
|
373 | + $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | + |
|
375 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | + wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | + wp_enqueue_style( 'wpinv_front_style' ); |
|
378 | + |
|
379 | + // Register scripts |
|
380 | + wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | + wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
382 | + |
|
383 | + $localize = array(); |
|
384 | + $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | + $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
386 | + $localize['currency_symbol'] = wpinv_currency_symbol(); |
|
387 | + $localize['currency_pos'] = wpinv_currency_position(); |
|
388 | + $localize['thousand_sep'] = wpinv_thousands_separator(); |
|
389 | + $localize['decimal_sep'] = wpinv_decimal_separator(); |
|
390 | + $localize['decimals'] = wpinv_decimals(); |
|
391 | + $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
392 | + $localize['UseTaxes'] = wpinv_use_taxes(); |
|
393 | + $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
394 | + $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
395 | + $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
396 | + |
|
397 | + $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
398 | + |
|
399 | + wp_enqueue_script( 'jquery-blockui' ); |
|
400 | + $autofill_api = wpinv_get_option('address_autofill_api'); |
|
401 | + $autofill_active = wpinv_get_option('address_autofill_active'); |
|
402 | + if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
403 | + if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
404 | + wp_dequeue_script( 'google-maps-api' ); |
|
405 | + } |
|
406 | + wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
407 | + wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
408 | + } |
|
409 | + |
|
410 | + wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
411 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
412 | + |
|
413 | + wp_enqueue_script( 'wpinv-front-script' ); |
|
414 | + wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
415 | + |
|
416 | + $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
417 | + wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
418 | + } |
|
419 | + |
|
420 | + public function wpinv_actions() { |
|
421 | + if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
422 | + do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + /** |
|
427 | 427 | * Fires an action after verifying that a user can fire them. |
428 | - * |
|
429 | - * Note: If the action is on an invoice, subscription etc, esure that the |
|
430 | - * current user owns the invoice/subscription. |
|
428 | + * |
|
429 | + * Note: If the action is on an invoice, subscription etc, esure that the |
|
430 | + * current user owns the invoice/subscription. |
|
431 | 431 | */ |
432 | 432 | public function maybe_do_authenticated_action() { |
433 | 433 | |
@@ -438,82 +438,82 @@ discard block |
||
438 | 438 | |
439 | 439 | } |
440 | 440 | |
441 | - public function pre_get_posts( $wp_query ) { |
|
442 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
443 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
444 | - } |
|
445 | - |
|
446 | - return $wp_query; |
|
447 | - } |
|
448 | - |
|
449 | - public function bp_invoicing_init() { |
|
450 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
451 | - } |
|
452 | - |
|
453 | - /** |
|
454 | - * Register widgets |
|
455 | - * |
|
456 | - */ |
|
457 | - public function register_widgets() { |
|
458 | - $widgets = apply_filters( |
|
459 | - 'getpaid_widget_classes', |
|
460 | - array( |
|
461 | - 'WPInv_Checkout_Widget', |
|
462 | - 'WPInv_History_Widget', |
|
463 | - 'WPInv_Receipt_Widget', |
|
464 | - 'WPInv_Subscriptions_Widget', |
|
465 | - 'WPInv_Buy_Item_Widget', |
|
466 | - 'WPInv_Messages_Widget', |
|
467 | - 'WPInv_GetPaid_Widget' |
|
468 | - ) |
|
469 | - ); |
|
470 | - |
|
471 | - foreach ( $widgets as $widget ) { |
|
472 | - register_widget( $widget ); |
|
473 | - } |
|
441 | + public function pre_get_posts( $wp_query ) { |
|
442 | + if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
443 | + $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
444 | + } |
|
445 | + |
|
446 | + return $wp_query; |
|
447 | + } |
|
448 | + |
|
449 | + public function bp_invoicing_init() { |
|
450 | + require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
451 | + } |
|
452 | + |
|
453 | + /** |
|
454 | + * Register widgets |
|
455 | + * |
|
456 | + */ |
|
457 | + public function register_widgets() { |
|
458 | + $widgets = apply_filters( |
|
459 | + 'getpaid_widget_classes', |
|
460 | + array( |
|
461 | + 'WPInv_Checkout_Widget', |
|
462 | + 'WPInv_History_Widget', |
|
463 | + 'WPInv_Receipt_Widget', |
|
464 | + 'WPInv_Subscriptions_Widget', |
|
465 | + 'WPInv_Buy_Item_Widget', |
|
466 | + 'WPInv_Messages_Widget', |
|
467 | + 'WPInv_GetPaid_Widget' |
|
468 | + ) |
|
469 | + ); |
|
470 | + |
|
471 | + foreach ( $widgets as $widget ) { |
|
472 | + register_widget( $widget ); |
|
473 | + } |
|
474 | 474 | |
475 | - } |
|
475 | + } |
|
476 | 476 | |
477 | - /** |
|
478 | - * Remove our pages from yoast sitemaps. |
|
479 | - * |
|
480 | - * @since 1.0.19 |
|
481 | - * @param int[] $excluded_posts_ids |
|
482 | - */ |
|
483 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
477 | + /** |
|
478 | + * Remove our pages from yoast sitemaps. |
|
479 | + * |
|
480 | + * @since 1.0.19 |
|
481 | + * @param int[] $excluded_posts_ids |
|
482 | + */ |
|
483 | + public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
484 | 484 | |
485 | - // Ensure that we have an array. |
|
486 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
487 | - $excluded_posts_ids = array(); |
|
488 | - } |
|
485 | + // Ensure that we have an array. |
|
486 | + if ( ! is_array( $excluded_posts_ids ) ) { |
|
487 | + $excluded_posts_ids = array(); |
|
488 | + } |
|
489 | 489 | |
490 | - // Prepare our pages. |
|
491 | - $our_pages = array(); |
|
490 | + // Prepare our pages. |
|
491 | + $our_pages = array(); |
|
492 | 492 | |
493 | - // Checkout page. |
|
494 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
493 | + // Checkout page. |
|
494 | + $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
495 | 495 | |
496 | - // Success page. |
|
497 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
496 | + // Success page. |
|
497 | + $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
498 | 498 | |
499 | - // Failure page. |
|
500 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
499 | + // Failure page. |
|
500 | + $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
501 | 501 | |
502 | - // History page. |
|
503 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
502 | + // History page. |
|
503 | + $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
504 | 504 | |
505 | - // Subscriptions page. |
|
506 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
505 | + // Subscriptions page. |
|
506 | + $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
507 | 507 | |
508 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
508 | + $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
509 | 509 | |
510 | - $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
511 | - return array_unique( $excluded_posts_ids ); |
|
510 | + $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
|
511 | + return array_unique( $excluded_posts_ids ); |
|
512 | 512 | |
513 | - } |
|
513 | + } |
|
514 | 514 | |
515 | - public function wp_footer() { |
|
516 | - echo ' |
|
515 | + public function wp_footer() { |
|
516 | + echo ' |
|
517 | 517 | <div class="bsui"> |
518 | 518 | <div id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog"> |
519 | 519 | <div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;"> |
@@ -524,6 +524,6 @@ discard block |
||
524 | 524 | </div> |
525 | 525 | </div> |
526 | 526 | '; |
527 | - } |
|
527 | + } |
|
528 | 528 | |
529 | 529 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Main Invoicing class. |
@@ -63,8 +63,8 @@ discard block |
||
63 | 63 | * @param string $prop The prop to set. |
64 | 64 | * @param mixed $value The value to retrieve. |
65 | 65 | */ |
66 | - public function set( $prop, $value ) { |
|
67 | - $this->data[ $prop ] = $value; |
|
66 | + public function set($prop, $value) { |
|
67 | + $this->data[$prop] = $value; |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | /** |
@@ -73,10 +73,10 @@ discard block |
||
73 | 73 | * @param string $prop The prop to set. |
74 | 74 | * @return mixed The value. |
75 | 75 | */ |
76 | - public function get( $prop ) { |
|
76 | + public function get($prop) { |
|
77 | 77 | |
78 | - if ( isset( $this->data[ $prop ] ) ) { |
|
79 | - return $this->data[ $prop ]; |
|
78 | + if (isset($this->data[$prop])) { |
|
79 | + return $this->data[$prop]; |
|
80 | 80 | } |
81 | 81 | |
82 | 82 | return null; |
@@ -88,25 +88,25 @@ discard block |
||
88 | 88 | public function set_properties() { |
89 | 89 | |
90 | 90 | // Sessions. |
91 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
92 | - $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility. |
|
91 | + $this->set('session', new WPInv_Session_Handler()); |
|
92 | + $GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility. |
|
93 | 93 | $this->tax = new WPInv_EUVat(); |
94 | 94 | $this->tax->init(); |
95 | 95 | $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility. |
96 | 96 | |
97 | 97 | // Init other objects. |
98 | - $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor. |
|
99 | - $this->set( 'session', new WPInv_Session_Handler() ); |
|
100 | - $this->set( 'notes', new WPInv_Notes() ); |
|
101 | - $this->set( 'api', new WPInv_API() ); |
|
102 | - $this->set( 'post_types', new GetPaid_Post_Types() ); |
|
103 | - $this->set( 'template', new GetPaid_Template() ); |
|
104 | - $this->set( 'admin', new GetPaid_Admin() ); |
|
105 | - $this->set( 'subscriptions', new WPInv_Subscriptions() ); |
|
106 | - $this->set( 'invoice_emails', new GetPaid_Invoice_Notification_Emails() ); |
|
107 | - $this->set( 'subscription_emails', new GetPaid_Subscription_Notification_Emails() ); |
|
108 | - $this->set( 'daily_maintenace', new GetPaid_Daily_Maintenance() ); |
|
109 | - $this->set( 'payment_forms', new GetPaid_Payment_Forms() ); |
|
98 | + $this->set('reports', new WPInv_Reports()); // TODO: Refactor. |
|
99 | + $this->set('session', new WPInv_Session_Handler()); |
|
100 | + $this->set('notes', new WPInv_Notes()); |
|
101 | + $this->set('api', new WPInv_API()); |
|
102 | + $this->set('post_types', new GetPaid_Post_Types()); |
|
103 | + $this->set('template', new GetPaid_Template()); |
|
104 | + $this->set('admin', new GetPaid_Admin()); |
|
105 | + $this->set('subscriptions', new WPInv_Subscriptions()); |
|
106 | + $this->set('invoice_emails', new GetPaid_Invoice_Notification_Emails()); |
|
107 | + $this->set('subscription_emails', new GetPaid_Subscription_Notification_Emails()); |
|
108 | + $this->set('daily_maintenace', new GetPaid_Daily_Maintenance()); |
|
109 | + $this->set('payment_forms', new GetPaid_Payment_Forms()); |
|
110 | 110 | |
111 | 111 | } |
112 | 112 | |
@@ -114,8 +114,8 @@ discard block |
||
114 | 114 | * Define plugin constants. |
115 | 115 | */ |
116 | 116 | public function define_constants() { |
117 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
118 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
117 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
118 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
119 | 119 | $this->version = WPINV_VERSION; |
120 | 120 | } |
121 | 121 | |
@@ -126,27 +126,27 @@ discard block |
||
126 | 126 | */ |
127 | 127 | protected function init_hooks() { |
128 | 128 | /* Internationalize the text strings used. */ |
129 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
129 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
130 | 130 | |
131 | 131 | // Init the plugin after WordPress inits. |
132 | - add_action( 'init', array( $this, 'init' ), 1 ); |
|
133 | - add_action( 'init', array( $this, 'maybe_process_ipn' ), 10 ); |
|
134 | - add_action( 'init', array( $this, 'wpinv_actions' ) ); |
|
135 | - add_action( 'init', array( $this, 'maybe_do_authenticated_action' ), 100 ); |
|
132 | + add_action('init', array($this, 'init'), 1); |
|
133 | + add_action('init', array($this, 'maybe_process_ipn'), 10); |
|
134 | + add_action('init', array($this, 'wpinv_actions')); |
|
135 | + add_action('init', array($this, 'maybe_do_authenticated_action'), 100); |
|
136 | 136 | |
137 | - if ( class_exists( 'BuddyPress' ) ) { |
|
138 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
137 | + if (class_exists('BuddyPress')) { |
|
138 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
139 | 139 | } |
140 | 140 | |
141 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
142 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
143 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
144 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
145 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
141 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
142 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
143 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
144 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
145 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
146 | 146 | |
147 | 147 | // Fires after registering actions. |
148 | - do_action( 'wpinv_actions', $this ); |
|
149 | - do_action( 'getpaid_actions', $this ); |
|
148 | + do_action('wpinv_actions', $this); |
|
149 | + do_action('getpaid_actions', $this); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | /* Internationalize the text strings used. */ |
155 | 155 | $this->load_textdomain(); |
156 | 156 | |
157 | - do_action( 'wpinv_loaded' ); |
|
157 | + do_action('wpinv_loaded'); |
|
158 | 158 | |
159 | 159 | // Fix oxygen page builder conflict |
160 | - if ( function_exists( 'ct_css_output' ) ) { |
|
160 | + if (function_exists('ct_css_output')) { |
|
161 | 161 | wpinv_oxygen_fix_conflict(); |
162 | 162 | } |
163 | 163 | } |
@@ -167,21 +167,21 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @since 1.0 |
169 | 169 | */ |
170 | - public function load_textdomain( $locale = NULL ) { |
|
171 | - if ( empty( $locale ) ) { |
|
172 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
170 | + public function load_textdomain($locale = NULL) { |
|
171 | + if (empty($locale)) { |
|
172 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
173 | 173 | } |
174 | 174 | |
175 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
175 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
176 | 176 | |
177 | - unload_textdomain( 'invoicing' ); |
|
178 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
179 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
177 | + unload_textdomain('invoicing'); |
|
178 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
179 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
180 | 180 | |
181 | 181 | /** |
182 | 182 | * Define language constants. |
183 | 183 | */ |
184 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |
@@ -190,90 +190,90 @@ discard block |
||
190 | 190 | public function includes() { |
191 | 191 | |
192 | 192 | // Start with the settings. |
193 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
194 | 194 | |
195 | 195 | // Packages/libraries. |
196 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
198 | 198 | |
199 | 199 | // Load functions. |
200 | - require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' ); |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
202 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
203 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
204 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
205 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
206 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
207 | - require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' ); |
|
208 | - require_once( WPINV_PLUGIN_DIR . 'includes/subscription-functions.php' ); |
|
209 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
210 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
211 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
212 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
213 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
214 | - require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' ); |
|
200 | + require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php'); |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
202 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
203 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
204 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
205 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
206 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
207 | + require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php'); |
|
208 | + require_once(WPINV_PLUGIN_DIR . 'includes/subscription-functions.php'); |
|
209 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
210 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
211 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
212 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
213 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
214 | + require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php'); |
|
215 | 215 | |
216 | 216 | // Register autoloader. |
217 | 217 | try { |
218 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
219 | - } catch ( Exception $e ) { |
|
220 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
218 | + spl_autoload_register(array($this, 'autoload'), true); |
|
219 | + } catch (Exception $e) { |
|
220 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
221 | 221 | } |
222 | 222 | |
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
224 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
234 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
235 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
236 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
237 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
238 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
239 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
240 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
241 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
242 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
243 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
224 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
234 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
235 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
236 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
237 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
238 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
239 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
240 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
241 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
242 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
243 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * Load the tax class. |
247 | 247 | */ |
248 | - if ( ! class_exists( 'WPInv_EUVat' ) ) { |
|
249 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
248 | + if (!class_exists('WPInv_EUVat')) { |
|
249 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
250 | 250 | } |
251 | 251 | |
252 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
252 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
253 | 253 | GetPaid_Post_Types_Admin::init(); |
254 | 254 | |
255 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
256 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
257 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
258 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
259 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
260 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
261 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
262 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
255 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
256 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
257 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
258 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
259 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
260 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
261 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
262 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
263 | 263 | // load the user class only on the users.php page |
264 | 264 | global $pagenow; |
265 | - if($pagenow=='users.php'){ |
|
265 | + if ($pagenow == 'users.php') { |
|
266 | 266 | new WPInv_Admin_Users(); |
267 | 267 | } |
268 | 268 | } |
269 | 269 | |
270 | 270 | // Register cli commands |
271 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
272 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
273 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
271 | + if (defined('WP_CLI') && WP_CLI) { |
|
272 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
273 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
274 | 274 | } |
275 | 275 | |
276 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
276 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
277 | 277 | } |
278 | 278 | |
279 | 279 | /** |
@@ -284,21 +284,21 @@ discard block |
||
284 | 284 | * @since 1.0.19 |
285 | 285 | * @return void |
286 | 286 | */ |
287 | - public function autoload( $class_name ) { |
|
287 | + public function autoload($class_name) { |
|
288 | 288 | |
289 | 289 | // Normalize the class name... |
290 | - $class_name = strtolower( $class_name ); |
|
290 | + $class_name = strtolower($class_name); |
|
291 | 291 | |
292 | 292 | // ... and make sure it is our class. |
293 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
293 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
294 | 294 | return; |
295 | 295 | } |
296 | 296 | |
297 | 297 | // Next, prepare the file name from the class. |
298 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
298 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
299 | 299 | |
300 | 300 | // Base path of the classes. |
301 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
301 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
302 | 302 | |
303 | 303 | // And an array of possible locations in order of importance. |
304 | 304 | $locations = array( |
@@ -311,10 +311,10 @@ discard block |
||
311 | 311 | "$plugin_path/includes/admin/meta-boxes", |
312 | 312 | ); |
313 | 313 | |
314 | - foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) { |
|
314 | + foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) { |
|
315 | 315 | |
316 | - if ( file_exists( trailingslashit( $location ) . $file_name ) ) { |
|
317 | - include trailingslashit( $location ) . $file_name; |
|
316 | + if (file_exists(trailingslashit($location) . $file_name)) { |
|
317 | + include trailingslashit($location) . $file_name; |
|
318 | 318 | break; |
319 | 319 | } |
320 | 320 | |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | public function init() { |
329 | 329 | |
330 | 330 | // Fires before getpaid inits. |
331 | - do_action( 'before_getpaid_init', $this ); |
|
331 | + do_action('before_getpaid_init', $this); |
|
332 | 332 | |
333 | 333 | // Load default gateways. |
334 | 334 | $gateways = apply_filters( |
@@ -342,12 +342,12 @@ discard block |
||
342 | 342 | ) |
343 | 343 | ); |
344 | 344 | |
345 | - foreach ( $gateways as $id => $class ) { |
|
346 | - $this->gateways[ $id ] = new $class(); |
|
345 | + foreach ($gateways as $id => $class) { |
|
346 | + $this->gateways[$id] = new $class(); |
|
347 | 347 | } |
348 | 348 | |
349 | 349 | // Fires after getpaid inits. |
350 | - do_action( 'getpaid_init', $this ); |
|
350 | + do_action('getpaid_init', $this); |
|
351 | 351 | |
352 | 352 | } |
353 | 353 | |
@@ -357,69 +357,69 @@ discard block |
||
357 | 357 | public function maybe_process_ipn() { |
358 | 358 | |
359 | 359 | // Ensure that this is an IPN request. |
360 | - if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) { |
|
360 | + if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) { |
|
361 | 361 | return; |
362 | 362 | } |
363 | 363 | |
364 | - $gateway = wpinv_clean( $_GET['wpi-gateway'] ); |
|
364 | + $gateway = wpinv_clean($_GET['wpi-gateway']); |
|
365 | 365 | |
366 | - do_action( 'wpinv_verify_payment_ipn', $gateway ); |
|
367 | - do_action( "wpinv_verify_{$gateway}_ipn" ); |
|
366 | + do_action('wpinv_verify_payment_ipn', $gateway); |
|
367 | + do_action("wpinv_verify_{$gateway}_ipn"); |
|
368 | 368 | exit; |
369 | 369 | |
370 | 370 | } |
371 | 371 | |
372 | 372 | public function enqueue_scripts() { |
373 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
373 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
374 | 374 | |
375 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
376 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
377 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
375 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
376 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
377 | + wp_enqueue_style('wpinv_front_style'); |
|
378 | 378 | |
379 | 379 | // Register scripts |
380 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
381 | - wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ), filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) ); |
|
380 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
381 | + wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js')); |
|
382 | 382 | |
383 | 383 | $localize = array(); |
384 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
385 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
384 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
385 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
386 | 386 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
387 | 387 | $localize['currency_pos'] = wpinv_currency_position(); |
388 | 388 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
389 | 389 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
390 | 390 | $localize['decimals'] = wpinv_decimals(); |
391 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
391 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
392 | 392 | $localize['UseTaxes'] = wpinv_use_taxes(); |
393 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
394 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
395 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
393 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
394 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
395 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
396 | 396 | |
397 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
397 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
398 | 398 | |
399 | - wp_enqueue_script( 'jquery-blockui' ); |
|
399 | + wp_enqueue_script('jquery-blockui'); |
|
400 | 400 | $autofill_api = wpinv_get_option('address_autofill_api'); |
401 | 401 | $autofill_active = wpinv_get_option('address_autofill_active'); |
402 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
403 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
404 | - wp_dequeue_script( 'google-maps-api' ); |
|
402 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
403 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
404 | + wp_dequeue_script('google-maps-api'); |
|
405 | 405 | } |
406 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
407 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
406 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
407 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
408 | 408 | } |
409 | 409 | |
410 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all' ); |
|
411 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
410 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.min.css', array(), WPINV_VERSION, 'all'); |
|
411 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
412 | 412 | |
413 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
414 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
413 | + wp_enqueue_script('wpinv-front-script'); |
|
414 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
415 | 415 | |
416 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
417 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
416 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
417 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | public function wpinv_actions() { |
421 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
422 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
421 | + if (isset($_REQUEST['wpi_action'])) { |
|
422 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
423 | 423 | } |
424 | 424 | } |
425 | 425 | |
@@ -431,23 +431,23 @@ discard block |
||
431 | 431 | */ |
432 | 432 | public function maybe_do_authenticated_action() { |
433 | 433 | |
434 | - if ( is_user_logged_in() && isset( $_REQUEST['getpaid-action'] ) && isset( $_REQUEST['getpaid-nonce'] ) && wp_verify_nonce( $_REQUEST['getpaid-nonce'], 'getpaid-nonce' ) ) { |
|
435 | - $key = sanitize_key( $_REQUEST['getpaid-action'] ); |
|
436 | - do_action( "getpaid_authenticated_action_$key", $_REQUEST ); |
|
434 | + if (is_user_logged_in() && isset($_REQUEST['getpaid-action']) && isset($_REQUEST['getpaid-nonce']) && wp_verify_nonce($_REQUEST['getpaid-nonce'], 'getpaid-nonce')) { |
|
435 | + $key = sanitize_key($_REQUEST['getpaid-action']); |
|
436 | + do_action("getpaid_authenticated_action_$key", $_REQUEST); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | } |
440 | 440 | |
441 | - public function pre_get_posts( $wp_query ) { |
|
442 | - if ( ! is_admin() && !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) { |
|
443 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
441 | + public function pre_get_posts($wp_query) { |
|
442 | + if (!is_admin() && !empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) { |
|
443 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | return $wp_query; |
447 | 447 | } |
448 | 448 | |
449 | 449 | public function bp_invoicing_init() { |
450 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
450 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | /** |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | ) |
469 | 469 | ); |
470 | 470 | |
471 | - foreach ( $widgets as $widget ) { |
|
472 | - register_widget( $widget ); |
|
471 | + foreach ($widgets as $widget) { |
|
472 | + register_widget($widget); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -480,10 +480,10 @@ discard block |
||
480 | 480 | * @since 1.0.19 |
481 | 481 | * @param int[] $excluded_posts_ids |
482 | 482 | */ |
483 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
483 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
484 | 484 | |
485 | 485 | // Ensure that we have an array. |
486 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
486 | + if (!is_array($excluded_posts_ids)) { |
|
487 | 487 | $excluded_posts_ids = array(); |
488 | 488 | } |
489 | 489 | |
@@ -491,24 +491,24 @@ discard block |
||
491 | 491 | $our_pages = array(); |
492 | 492 | |
493 | 493 | // Checkout page. |
494 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
494 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
495 | 495 | |
496 | 496 | // Success page. |
497 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
497 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
498 | 498 | |
499 | 499 | // Failure page. |
500 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
500 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
501 | 501 | |
502 | 502 | // History page. |
503 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
503 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
504 | 504 | |
505 | 505 | // Subscriptions page. |
506 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
506 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
507 | 507 | |
508 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
508 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
509 | 509 | |
510 | 510 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
511 | - return array_unique( $excluded_posts_ids ); |
|
511 | + return array_unique($excluded_posts_ids); |
|
512 | 512 | |
513 | 513 | } |
514 | 514 |
@@ -4,99 +4,99 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Displays an invoice. |
11 | 11 | * |
12 | 12 | * @param WPInv_Invoice $invoice. |
13 | 13 | */ |
14 | -function getpaid_invoice( $invoice ) { |
|
15 | - if ( ! empty( $invoice ) ) { |
|
16 | - wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) ); |
|
14 | +function getpaid_invoice($invoice) { |
|
15 | + if (!empty($invoice)) { |
|
16 | + wpinv_get_template('invoice/invoice.php', compact('invoice')); |
|
17 | 17 | } |
18 | 18 | } |
19 | -add_action( 'getpaid_invoice', 'getpaid_invoice', 10 ); |
|
19 | +add_action('getpaid_invoice', 'getpaid_invoice', 10); |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * Displays the invoice footer. |
23 | 23 | */ |
24 | -function getpaid_invoice_footer( $invoice ) { |
|
25 | - if ( ! empty( $invoice ) ) { |
|
26 | - wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) ); |
|
24 | +function getpaid_invoice_footer($invoice) { |
|
25 | + if (!empty($invoice)) { |
|
26 | + wpinv_get_template('invoice/footer.php', compact('invoice')); |
|
27 | 27 | } |
28 | 28 | } |
29 | -add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 ); |
|
29 | +add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10); |
|
30 | 30 | |
31 | 31 | /** |
32 | 32 | * Displays the invoice top bar. |
33 | 33 | */ |
34 | -function getpaid_invoice_header( $invoice ) { |
|
35 | - if ( ! empty( $invoice ) ) { |
|
36 | - wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) ); |
|
34 | +function getpaid_invoice_header($invoice) { |
|
35 | + if (!empty($invoice)) { |
|
36 | + wpinv_get_template('invoice/header.php', compact('invoice')); |
|
37 | 37 | } |
38 | 38 | } |
39 | -add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 ); |
|
39 | +add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10); |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Displays actions on the left side of the header. |
43 | 43 | */ |
44 | -function getpaid_invoice_header_left_actions( $invoice ) { |
|
45 | - if ( ! empty( $invoice ) ) { |
|
46 | - wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) ); |
|
44 | +function getpaid_invoice_header_left_actions($invoice) { |
|
45 | + if (!empty($invoice)) { |
|
46 | + wpinv_get_template('invoice/header-left-actions.php', compact('invoice')); |
|
47 | 47 | } |
48 | 48 | } |
49 | -add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 ); |
|
49 | +add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10); |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * Displays actions on the right side of the invoice top bar. |
53 | 53 | */ |
54 | -function getpaid_invoice_header_right_actions( $invoice ) { |
|
55 | - if ( ! empty( $invoice ) ) { |
|
56 | - wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) ); |
|
54 | +function getpaid_invoice_header_right_actions($invoice) { |
|
55 | + if (!empty($invoice)) { |
|
56 | + wpinv_get_template('invoice/header-right-actions.php', compact('invoice')); |
|
57 | 57 | } |
58 | 58 | } |
59 | -add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 ); |
|
59 | +add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10); |
|
60 | 60 | |
61 | 61 | /** |
62 | 62 | * Displays the invoice title, watermark, logo etc. |
63 | 63 | */ |
64 | -function getpaid_invoice_details_top( $invoice ) { |
|
65 | - if ( ! empty( $invoice ) ) { |
|
66 | - wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) ); |
|
64 | +function getpaid_invoice_details_top($invoice) { |
|
65 | + if (!empty($invoice)) { |
|
66 | + wpinv_get_template('invoice/details-top.php', compact('invoice')); |
|
67 | 67 | } |
68 | 68 | } |
69 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 ); |
|
69 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Displays the company logo. |
73 | 73 | */ |
74 | -function getpaid_invoice_logo( $invoice ) { |
|
75 | - if ( ! empty( $invoice ) ) { |
|
76 | - wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) ); |
|
74 | +function getpaid_invoice_logo($invoice) { |
|
75 | + if (!empty($invoice)) { |
|
76 | + wpinv_get_template('invoice/invoice-logo.php', compact('invoice')); |
|
77 | 77 | } |
78 | 78 | } |
79 | -add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' ); |
|
79 | +add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo'); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Displays the type of invoice. |
83 | 83 | */ |
84 | -function getpaid_invoice_type( $invoice ) { |
|
85 | - if ( ! empty( $invoice ) ) { |
|
86 | - wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) ); |
|
84 | +function getpaid_invoice_type($invoice) { |
|
85 | + if (!empty($invoice)) { |
|
86 | + wpinv_get_template('invoice/invoice-type.php', compact('invoice')); |
|
87 | 87 | } |
88 | 88 | } |
89 | -add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' ); |
|
89 | +add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type'); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Displays the invoice details. |
93 | 93 | */ |
94 | -function getpaid_invoice_details_main( $invoice ) { |
|
95 | - if ( ! empty( $invoice ) ) { |
|
96 | - wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) ); |
|
94 | +function getpaid_invoice_details_main($invoice) { |
|
95 | + if (!empty($invoice)) { |
|
96 | + wpinv_get_template('invoice/details.php', compact('invoice')); |
|
97 | 97 | } |
98 | 98 | } |
99 | -add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 ); |
|
99 | +add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50); |
|
100 | 100 | |
101 | 101 | /** |
102 | 102 | * Returns a path to the templates directory. |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
126 | 126 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
127 | 127 | */ |
128 | -function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
129 | - return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path ); |
|
128 | +function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
129 | + return getpaid_template()->display_template($template_name, $args, $template_path, $default_path); |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -139,8 +139,8 @@ discard block |
||
139 | 139 | * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'. |
140 | 140 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
141 | 141 | */ |
142 | -function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) { |
|
143 | - return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path ); |
|
142 | +function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') { |
|
143 | + return getpaid_template()->get_template($template_name, $args, $template_path, $default_path); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @return string |
150 | 150 | */ |
151 | 151 | function wpinv_template_path() { |
152 | - return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() ); |
|
152 | + return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name()); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @return string |
159 | 159 | */ |
160 | 160 | function wpinv_get_theme_template_dir_name() { |
161 | - return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) ); |
|
161 | + return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing')); |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | /** |
@@ -170,56 +170,56 @@ discard block |
||
170 | 170 | * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'. |
171 | 171 | * @param string $default_path The root path to the default template. Defaults to invoicing/templates |
172 | 172 | */ |
173 | -function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) { |
|
174 | - return getpaid_template()->locate_template( $template_name, $template_path, $default_path ); |
|
173 | +function wpinv_locate_template($template_name, $template_path = '', $default_path = '') { |
|
174 | + return getpaid_template()->locate_template($template_name, $template_path, $default_path); |
|
175 | 175 | } |
176 | 176 | |
177 | -function wpinv_get_template_part( $slug, $name = null, $load = true ) { |
|
178 | - do_action( 'get_template_part_' . $slug, $slug, $name ); |
|
177 | +function wpinv_get_template_part($slug, $name = null, $load = true) { |
|
178 | + do_action('get_template_part_' . $slug, $slug, $name); |
|
179 | 179 | |
180 | 180 | // Setup possible parts |
181 | 181 | $templates = array(); |
182 | - if ( isset( $name ) ) |
|
182 | + if (isset($name)) |
|
183 | 183 | $templates[] = $slug . '-' . $name . '.php'; |
184 | 184 | $templates[] = $slug . '.php'; |
185 | 185 | |
186 | 186 | // Allow template parts to be filtered |
187 | - $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name ); |
|
187 | + $templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name); |
|
188 | 188 | |
189 | 189 | // Return the part that is found |
190 | - return wpinv_locate_tmpl( $templates, $load, false ); |
|
190 | + return wpinv_locate_tmpl($templates, $load, false); |
|
191 | 191 | } |
192 | 192 | |
193 | -function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) { |
|
193 | +function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) { |
|
194 | 194 | // No file found yet |
195 | 195 | $located = false; |
196 | 196 | |
197 | 197 | // Try to find a template file |
198 | - foreach ( (array)$template_names as $template_name ) { |
|
198 | + foreach ((array) $template_names as $template_name) { |
|
199 | 199 | |
200 | 200 | // Continue if template is empty |
201 | - if ( empty( $template_name ) ) |
|
201 | + if (empty($template_name)) |
|
202 | 202 | continue; |
203 | 203 | |
204 | 204 | // Trim off any slashes from the template name |
205 | - $template_name = ltrim( $template_name, '/' ); |
|
205 | + $template_name = ltrim($template_name, '/'); |
|
206 | 206 | |
207 | 207 | // try locating this template file by looping through the template paths |
208 | - foreach( wpinv_get_theme_template_paths() as $template_path ) { |
|
208 | + foreach (wpinv_get_theme_template_paths() as $template_path) { |
|
209 | 209 | |
210 | - if( file_exists( $template_path . $template_name ) ) { |
|
210 | + if (file_exists($template_path . $template_name)) { |
|
211 | 211 | $located = $template_path . $template_name; |
212 | 212 | break; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | - if( !empty( $located ) ) { |
|
216 | + if (!empty($located)) { |
|
217 | 217 | break; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | |
221 | - if ( ( true == $load ) && ! empty( $located ) ) |
|
222 | - load_template( $located, $require_once ); |
|
221 | + if ((true == $load) && !empty($located)) |
|
222 | + load_template($located, $require_once); |
|
223 | 223 | |
224 | 224 | return $located; |
225 | 225 | } |
@@ -228,155 +228,155 @@ discard block |
||
228 | 228 | $template_dir = wpinv_get_theme_template_dir_name(); |
229 | 229 | |
230 | 230 | $file_paths = array( |
231 | - 1 => trailingslashit( get_stylesheet_directory() ) . $template_dir, |
|
232 | - 10 => trailingslashit( get_template_directory() ) . $template_dir, |
|
231 | + 1 => trailingslashit(get_stylesheet_directory()) . $template_dir, |
|
232 | + 10 => trailingslashit(get_template_directory()) . $template_dir, |
|
233 | 233 | 100 => wpinv_get_templates_dir() |
234 | 234 | ); |
235 | 235 | |
236 | - $file_paths = apply_filters( 'wpinv_template_paths', $file_paths ); |
|
236 | + $file_paths = apply_filters('wpinv_template_paths', $file_paths); |
|
237 | 237 | |
238 | 238 | // sort the file paths based on priority |
239 | - ksort( $file_paths, SORT_NUMERIC ); |
|
239 | + ksort($file_paths, SORT_NUMERIC); |
|
240 | 240 | |
241 | - return array_map( 'trailingslashit', $file_paths ); |
|
241 | + return array_map('trailingslashit', $file_paths); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | function wpinv_checkout_meta_tags() { |
245 | 245 | |
246 | 246 | $pages = array(); |
247 | - $pages[] = wpinv_get_option( 'success_page' ); |
|
248 | - $pages[] = wpinv_get_option( 'failure_page' ); |
|
249 | - $pages[] = wpinv_get_option( 'invoice_history_page' ); |
|
250 | - $pages[] = wpinv_get_option( 'invoice_subscription_page' ); |
|
247 | + $pages[] = wpinv_get_option('success_page'); |
|
248 | + $pages[] = wpinv_get_option('failure_page'); |
|
249 | + $pages[] = wpinv_get_option('invoice_history_page'); |
|
250 | + $pages[] = wpinv_get_option('invoice_subscription_page'); |
|
251 | 251 | |
252 | - if( !wpinv_is_checkout() && !is_page( $pages ) ) { |
|
252 | + if (!wpinv_is_checkout() && !is_page($pages)) { |
|
253 | 253 | return; |
254 | 254 | } |
255 | 255 | |
256 | 256 | echo '<meta name="robots" content="noindex,nofollow" />' . "\n"; |
257 | 257 | } |
258 | -add_action( 'wp_head', 'wpinv_checkout_meta_tags' ); |
|
258 | +add_action('wp_head', 'wpinv_checkout_meta_tags'); |
|
259 | 259 | |
260 | -function wpinv_add_body_classes( $class ) { |
|
261 | - $classes = (array)$class; |
|
260 | +function wpinv_add_body_classes($class) { |
|
261 | + $classes = (array) $class; |
|
262 | 262 | |
263 | - if( wpinv_is_checkout() ) { |
|
263 | + if (wpinv_is_checkout()) { |
|
264 | 264 | $classes[] = 'wpinv-checkout'; |
265 | 265 | $classes[] = 'wpinv-page'; |
266 | 266 | } |
267 | 267 | |
268 | - if( wpinv_is_success_page() ) { |
|
268 | + if (wpinv_is_success_page()) { |
|
269 | 269 | $classes[] = 'wpinv-success'; |
270 | 270 | $classes[] = 'wpinv-page'; |
271 | 271 | } |
272 | 272 | |
273 | - if( wpinv_is_failed_transaction_page() ) { |
|
273 | + if (wpinv_is_failed_transaction_page()) { |
|
274 | 274 | $classes[] = 'wpinv-failed-transaction'; |
275 | 275 | $classes[] = 'wpinv-page'; |
276 | 276 | } |
277 | 277 | |
278 | - if( wpinv_is_invoice_history_page() ) { |
|
278 | + if (wpinv_is_invoice_history_page()) { |
|
279 | 279 | $classes[] = 'wpinv-history'; |
280 | 280 | $classes[] = 'wpinv-page'; |
281 | 281 | } |
282 | 282 | |
283 | - if( wpinv_is_subscriptions_history_page() ) { |
|
283 | + if (wpinv_is_subscriptions_history_page()) { |
|
284 | 284 | $classes[] = 'wpinv-subscription'; |
285 | 285 | $classes[] = 'wpinv-page'; |
286 | 286 | } |
287 | 287 | |
288 | - if( wpinv_is_test_mode() ) { |
|
288 | + if (wpinv_is_test_mode()) { |
|
289 | 289 | $classes[] = 'wpinv-test-mode'; |
290 | 290 | $classes[] = 'wpinv-page'; |
291 | 291 | } |
292 | 292 | |
293 | - return array_unique( $classes ); |
|
293 | + return array_unique($classes); |
|
294 | 294 | } |
295 | -add_filter( 'body_class', 'wpinv_add_body_classes' ); |
|
295 | +add_filter('body_class', 'wpinv_add_body_classes'); |
|
296 | 296 | |
297 | -function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) { |
|
298 | - $args = array( 'nopaging' => true ); |
|
297 | +function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') { |
|
298 | + $args = array('nopaging' => true); |
|
299 | 299 | |
300 | - if ( ! empty( $status ) ) |
|
300 | + if (!empty($status)) |
|
301 | 301 | $args['post_status'] = $status; |
302 | 302 | |
303 | - $discounts = wpinv_get_discounts( $args ); |
|
303 | + $discounts = wpinv_get_discounts($args); |
|
304 | 304 | $options = array(); |
305 | 305 | |
306 | - if ( $discounts ) { |
|
307 | - foreach ( $discounts as $discount ) { |
|
308 | - $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) ); |
|
306 | + if ($discounts) { |
|
307 | + foreach ($discounts as $discount) { |
|
308 | + $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID)); |
|
309 | 309 | } |
310 | 310 | } else { |
311 | - $options[0] = __( 'No discounts found', 'invoicing' ); |
|
311 | + $options[0] = __('No discounts found', 'invoicing'); |
|
312 | 312 | } |
313 | 313 | |
314 | - $output = wpinv_html_select( array( |
|
314 | + $output = wpinv_html_select(array( |
|
315 | 315 | 'name' => $name, |
316 | 316 | 'selected' => $selected, |
317 | 317 | 'options' => $options, |
318 | 318 | 'show_option_all' => false, |
319 | 319 | 'show_option_none' => false, |
320 | - ) ); |
|
320 | + )); |
|
321 | 321 | |
322 | 322 | return $output; |
323 | 323 | } |
324 | 324 | |
325 | -function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) { |
|
326 | - $current = date( 'Y' ); |
|
327 | - $start_year = $current - absint( $years_before ); |
|
328 | - $end_year = $current + absint( $years_after ); |
|
329 | - $selected = empty( $selected ) ? date( 'Y' ) : $selected; |
|
325 | +function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) { |
|
326 | + $current = date('Y'); |
|
327 | + $start_year = $current - absint($years_before); |
|
328 | + $end_year = $current + absint($years_after); |
|
329 | + $selected = empty($selected) ? date('Y') : $selected; |
|
330 | 330 | $options = array(); |
331 | 331 | |
332 | - while ( $start_year <= $end_year ) { |
|
333 | - $options[ absint( $start_year ) ] = $start_year; |
|
332 | + while ($start_year <= $end_year) { |
|
333 | + $options[absint($start_year)] = $start_year; |
|
334 | 334 | $start_year++; |
335 | 335 | } |
336 | 336 | |
337 | - $output = wpinv_html_select( array( |
|
337 | + $output = wpinv_html_select(array( |
|
338 | 338 | 'name' => $name, |
339 | 339 | 'selected' => $selected, |
340 | 340 | 'options' => $options, |
341 | 341 | 'show_option_all' => false, |
342 | 342 | 'show_option_none' => false |
343 | - ) ); |
|
343 | + )); |
|
344 | 344 | |
345 | 345 | return $output; |
346 | 346 | } |
347 | 347 | |
348 | -function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) { |
|
348 | +function wpinv_html_month_dropdown($name = 'month', $selected = 0) { |
|
349 | 349 | |
350 | 350 | $options = array( |
351 | - '1' => __( 'January', 'invoicing' ), |
|
352 | - '2' => __( 'February', 'invoicing' ), |
|
353 | - '3' => __( 'March', 'invoicing' ), |
|
354 | - '4' => __( 'April', 'invoicing' ), |
|
355 | - '5' => __( 'May', 'invoicing' ), |
|
356 | - '6' => __( 'June', 'invoicing' ), |
|
357 | - '7' => __( 'July', 'invoicing' ), |
|
358 | - '8' => __( 'August', 'invoicing' ), |
|
359 | - '9' => __( 'September', 'invoicing' ), |
|
360 | - '10' => __( 'October', 'invoicing' ), |
|
361 | - '11' => __( 'November', 'invoicing' ), |
|
362 | - '12' => __( 'December', 'invoicing' ), |
|
351 | + '1' => __('January', 'invoicing'), |
|
352 | + '2' => __('February', 'invoicing'), |
|
353 | + '3' => __('March', 'invoicing'), |
|
354 | + '4' => __('April', 'invoicing'), |
|
355 | + '5' => __('May', 'invoicing'), |
|
356 | + '6' => __('June', 'invoicing'), |
|
357 | + '7' => __('July', 'invoicing'), |
|
358 | + '8' => __('August', 'invoicing'), |
|
359 | + '9' => __('September', 'invoicing'), |
|
360 | + '10' => __('October', 'invoicing'), |
|
361 | + '11' => __('November', 'invoicing'), |
|
362 | + '12' => __('December', 'invoicing'), |
|
363 | 363 | ); |
364 | 364 | |
365 | 365 | // If no month is selected, default to the current month |
366 | - $selected = empty( $selected ) ? date( 'n' ) : $selected; |
|
366 | + $selected = empty($selected) ? date('n') : $selected; |
|
367 | 367 | |
368 | - $output = wpinv_html_select( array( |
|
368 | + $output = wpinv_html_select(array( |
|
369 | 369 | 'name' => $name, |
370 | 370 | 'selected' => $selected, |
371 | 371 | 'options' => $options, |
372 | 372 | 'show_option_all' => false, |
373 | 373 | 'show_option_none' => false |
374 | - ) ); |
|
374 | + )); |
|
375 | 375 | |
376 | 376 | return $output; |
377 | 377 | } |
378 | 378 | |
379 | -function wpinv_html_select( $args = array() ) { |
|
379 | +function wpinv_html_select($args = array()) { |
|
380 | 380 | $defaults = array( |
381 | 381 | 'options' => array(), |
382 | 382 | 'name' => null, |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | 'selected' => 0, |
386 | 386 | 'placeholder' => null, |
387 | 387 | 'multiple' => false, |
388 | - 'show_option_all' => _x( 'All', 'all dropdown items', 'invoicing' ), |
|
389 | - 'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ), |
|
388 | + 'show_option_all' => _x('All', 'all dropdown items', 'invoicing'), |
|
389 | + 'show_option_none' => _x('None', 'no dropdown items', 'invoicing'), |
|
390 | 390 | 'data' => array(), |
391 | 391 | 'onchange' => null, |
392 | 392 | 'required' => false, |
@@ -394,74 +394,74 @@ discard block |
||
394 | 394 | 'readonly' => false, |
395 | 395 | ); |
396 | 396 | |
397 | - $args = wp_parse_args( $args, $defaults ); |
|
397 | + $args = wp_parse_args($args, $defaults); |
|
398 | 398 | |
399 | 399 | $data_elements = ''; |
400 | - foreach ( $args['data'] as $key => $value ) { |
|
401 | - $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"'; |
|
400 | + foreach ($args['data'] as $key => $value) { |
|
401 | + $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"'; |
|
402 | 402 | } |
403 | 403 | |
404 | - if( $args['multiple'] ) { |
|
404 | + if ($args['multiple']) { |
|
405 | 405 | $multiple = ' MULTIPLE'; |
406 | 406 | } else { |
407 | 407 | $multiple = ''; |
408 | 408 | } |
409 | 409 | |
410 | - if( $args['placeholder'] ) { |
|
410 | + if ($args['placeholder']) { |
|
411 | 411 | $placeholder = $args['placeholder']; |
412 | 412 | } else { |
413 | 413 | $placeholder = ''; |
414 | 414 | } |
415 | 415 | |
416 | 416 | $options = ''; |
417 | - if( !empty( $args['onchange'] ) ) { |
|
418 | - $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
417 | + if (!empty($args['onchange'])) { |
|
418 | + $options .= ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
419 | 419 | } |
420 | 420 | |
421 | - if( !empty( $args['required'] ) ) { |
|
421 | + if (!empty($args['required'])) { |
|
422 | 422 | $options .= ' required="required"'; |
423 | 423 | } |
424 | 424 | |
425 | - if( !empty( $args['disabled'] ) ) { |
|
425 | + if (!empty($args['disabled'])) { |
|
426 | 426 | $options .= ' disabled'; |
427 | 427 | } |
428 | 428 | |
429 | - if( !empty( $args['readonly'] ) ) { |
|
429 | + if (!empty($args['readonly'])) { |
|
430 | 430 | $options .= ' readonly'; |
431 | 431 | } |
432 | 432 | |
433 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
434 | - $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>'; |
|
433 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
434 | + $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>'; |
|
435 | 435 | |
436 | - if ( $args['show_option_all'] ) { |
|
437 | - if( $args['multiple'] ) { |
|
438 | - $selected = selected( true, in_array( 0, $args['selected'] ), false ); |
|
436 | + if ($args['show_option_all']) { |
|
437 | + if ($args['multiple']) { |
|
438 | + $selected = selected(true, in_array(0, $args['selected']), false); |
|
439 | 439 | } else { |
440 | - $selected = selected( $args['selected'], 0, false ); |
|
440 | + $selected = selected($args['selected'], 0, false); |
|
441 | 441 | } |
442 | - $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>'; |
|
442 | + $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>'; |
|
443 | 443 | } |
444 | 444 | |
445 | - if ( !empty( $args['options'] ) ) { |
|
445 | + if (!empty($args['options'])) { |
|
446 | 446 | |
447 | - if ( $args['show_option_none'] ) { |
|
448 | - if( $args['multiple'] ) { |
|
449 | - $selected = selected( true, in_array( "", $args['selected'] ), false ); |
|
447 | + if ($args['show_option_none']) { |
|
448 | + if ($args['multiple']) { |
|
449 | + $selected = selected(true, in_array("", $args['selected']), false); |
|
450 | 450 | } else { |
451 | - $selected = selected( $args['selected'] === "", true, false ); |
|
451 | + $selected = selected($args['selected'] === "", true, false); |
|
452 | 452 | } |
453 | - $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>'; |
|
453 | + $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>'; |
|
454 | 454 | } |
455 | 455 | |
456 | - foreach( $args['options'] as $key => $option ) { |
|
456 | + foreach ($args['options'] as $key => $option) { |
|
457 | 457 | |
458 | - if( $args['multiple'] && is_array( $args['selected'] ) ) { |
|
459 | - $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false ); |
|
458 | + if ($args['multiple'] && is_array($args['selected'])) { |
|
459 | + $selected = selected(true, (bool) in_array($key, $args['selected']), false); |
|
460 | 460 | } else { |
461 | - $selected = selected( $args['selected'], $key, false ); |
|
461 | + $selected = selected($args['selected'], $key, false); |
|
462 | 462 | } |
463 | 463 | |
464 | - $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>'; |
|
464 | + $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>'; |
|
465 | 465 | } |
466 | 466 | } |
467 | 467 | |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | return $output; |
471 | 471 | } |
472 | 472 | |
473 | -function wpinv_item_dropdown( $args = array() ) { |
|
473 | +function wpinv_item_dropdown($args = array()) { |
|
474 | 474 | $defaults = array( |
475 | 475 | 'name' => 'wpi_item', |
476 | 476 | 'id' => 'wpi_item', |
@@ -478,14 +478,14 @@ discard block |
||
478 | 478 | 'multiple' => false, |
479 | 479 | 'selected' => 0, |
480 | 480 | 'number' => 100, |
481 | - 'placeholder' => __( 'Choose a item', 'invoicing' ), |
|
482 | - 'data' => array( 'search-type' => 'item' ), |
|
481 | + 'placeholder' => __('Choose a item', 'invoicing'), |
|
482 | + 'data' => array('search-type' => 'item'), |
|
483 | 483 | 'show_option_all' => false, |
484 | 484 | 'show_option_none' => false, |
485 | 485 | 'show_recurring' => false, |
486 | 486 | ); |
487 | 487 | |
488 | - $args = wp_parse_args( $args, $defaults ); |
|
488 | + $args = wp_parse_args($args, $defaults); |
|
489 | 489 | |
490 | 490 | $item_args = array( |
491 | 491 | 'post_type' => 'wpi_item', |
@@ -494,44 +494,44 @@ discard block |
||
494 | 494 | 'posts_per_page' => $args['number'] |
495 | 495 | ); |
496 | 496 | |
497 | - $item_args = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults ); |
|
497 | + $item_args = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults); |
|
498 | 498 | |
499 | - $items = get_posts( $item_args ); |
|
499 | + $items = get_posts($item_args); |
|
500 | 500 | $options = array(); |
501 | - if ( $items ) { |
|
502 | - foreach ( $items as $item ) { |
|
503 | - $title = esc_html( $item->post_title ); |
|
501 | + if ($items) { |
|
502 | + foreach ($items as $item) { |
|
503 | + $title = esc_html($item->post_title); |
|
504 | 504 | |
505 | - if ( !empty( $args['show_recurring'] ) ) { |
|
506 | - $title .= wpinv_get_item_suffix( $item->ID, false ); |
|
505 | + if (!empty($args['show_recurring'])) { |
|
506 | + $title .= wpinv_get_item_suffix($item->ID, false); |
|
507 | 507 | } |
508 | 508 | |
509 | - $options[ absint( $item->ID ) ] = $title; |
|
509 | + $options[absint($item->ID)] = $title; |
|
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | // This ensures that any selected items are included in the drop down |
514 | - if( is_array( $args['selected'] ) ) { |
|
515 | - foreach( $args['selected'] as $item ) { |
|
516 | - if( ! in_array( $item, $options ) ) { |
|
517 | - $title = get_the_title( $item ); |
|
518 | - if ( !empty( $args['show_recurring'] ) ) { |
|
519 | - $title .= wpinv_get_item_suffix( $item, false ); |
|
514 | + if (is_array($args['selected'])) { |
|
515 | + foreach ($args['selected'] as $item) { |
|
516 | + if (!in_array($item, $options)) { |
|
517 | + $title = get_the_title($item); |
|
518 | + if (!empty($args['show_recurring'])) { |
|
519 | + $title .= wpinv_get_item_suffix($item, false); |
|
520 | 520 | } |
521 | 521 | $options[$item] = $title; |
522 | 522 | } |
523 | 523 | } |
524 | - } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) { |
|
525 | - if ( ! in_array( $args['selected'], $options ) ) { |
|
526 | - $title = get_the_title( $args['selected'] ); |
|
527 | - if ( !empty( $args['show_recurring'] ) ) { |
|
528 | - $title .= wpinv_get_item_suffix( $args['selected'], false ); |
|
524 | + } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) { |
|
525 | + if (!in_array($args['selected'], $options)) { |
|
526 | + $title = get_the_title($args['selected']); |
|
527 | + if (!empty($args['show_recurring'])) { |
|
528 | + $title .= wpinv_get_item_suffix($args['selected'], false); |
|
529 | 529 | } |
530 | - $options[$args['selected']] = get_the_title( $args['selected'] ); |
|
530 | + $options[$args['selected']] = get_the_title($args['selected']); |
|
531 | 531 | } |
532 | 532 | } |
533 | 533 | |
534 | - $output = wpinv_html_select( array( |
|
534 | + $output = wpinv_html_select(array( |
|
535 | 535 | 'name' => $args['name'], |
536 | 536 | 'selected' => $args['selected'], |
537 | 537 | 'id' => $args['id'], |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | 'show_option_all' => $args['show_option_all'], |
543 | 543 | 'show_option_none' => $args['show_option_none'], |
544 | 544 | 'data' => $args['data'], |
545 | - ) ); |
|
545 | + )); |
|
546 | 546 | |
547 | 547 | return $output; |
548 | 548 | } |
@@ -562,16 +562,16 @@ discard block |
||
562 | 562 | ); |
563 | 563 | |
564 | 564 | $options = array(); |
565 | - if ( $items ) { |
|
566 | - foreach ( $items as $item ) { |
|
567 | - $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false ); |
|
565 | + if ($items) { |
|
566 | + foreach ($items as $item) { |
|
567 | + $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false); |
|
568 | 568 | } |
569 | 569 | } |
570 | 570 | |
571 | 571 | return $options; |
572 | 572 | } |
573 | 573 | |
574 | -function wpinv_html_checkbox( $args = array() ) { |
|
574 | +function wpinv_html_checkbox($args = array()) { |
|
575 | 575 | $defaults = array( |
576 | 576 | 'name' => null, |
577 | 577 | 'current' => null, |
@@ -582,17 +582,17 @@ discard block |
||
582 | 582 | ) |
583 | 583 | ); |
584 | 584 | |
585 | - $args = wp_parse_args( $args, $defaults ); |
|
585 | + $args = wp_parse_args($args, $defaults); |
|
586 | 586 | |
587 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
587 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
588 | 588 | $options = ''; |
589 | - if ( ! empty( $args['options']['disabled'] ) ) { |
|
589 | + if (!empty($args['options']['disabled'])) { |
|
590 | 590 | $options .= ' disabled="disabled"'; |
591 | - } elseif ( ! empty( $args['options']['readonly'] ) ) { |
|
591 | + } elseif (!empty($args['options']['readonly'])) { |
|
592 | 592 | $options .= ' readonly'; |
593 | 593 | } |
594 | 594 | |
595 | - $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />'; |
|
595 | + $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />'; |
|
596 | 596 | |
597 | 597 | return $output; |
598 | 598 | } |
@@ -600,30 +600,30 @@ discard block |
||
600 | 600 | /** |
601 | 601 | * Displays a hidden field. |
602 | 602 | */ |
603 | -function getpaid_hidden_field( $name, $value ) { |
|
604 | - $name = sanitize_text_field( $name ); |
|
605 | - $value = esc_attr( $value ); |
|
603 | +function getpaid_hidden_field($name, $value) { |
|
604 | + $name = sanitize_text_field($name); |
|
605 | + $value = esc_attr($value); |
|
606 | 606 | |
607 | 607 | echo "<input type='hidden' name='$name' value='$value' />"; |
608 | 608 | } |
609 | 609 | |
610 | -function wpinv_html_text( $args = array() ) { |
|
610 | +function wpinv_html_text($args = array()) { |
|
611 | 611 | // Backwards compatibility |
612 | - if ( func_num_args() > 1 ) { |
|
612 | + if (func_num_args() > 1) { |
|
613 | 613 | $args = func_get_args(); |
614 | 614 | |
615 | 615 | $name = $args[0]; |
616 | - $value = isset( $args[1] ) ? $args[1] : ''; |
|
617 | - $label = isset( $args[2] ) ? $args[2] : ''; |
|
618 | - $desc = isset( $args[3] ) ? $args[3] : ''; |
|
616 | + $value = isset($args[1]) ? $args[1] : ''; |
|
617 | + $label = isset($args[2]) ? $args[2] : ''; |
|
618 | + $desc = isset($args[3]) ? $args[3] : ''; |
|
619 | 619 | } |
620 | 620 | |
621 | 621 | $defaults = array( |
622 | 622 | 'id' => '', |
623 | - 'name' => isset( $name ) ? $name : 'text', |
|
624 | - 'value' => isset( $value ) ? $value : null, |
|
625 | - 'label' => isset( $label ) ? $label : null, |
|
626 | - 'desc' => isset( $desc ) ? $desc : null, |
|
623 | + 'name' => isset($name) ? $name : 'text', |
|
624 | + 'value' => isset($value) ? $value : null, |
|
625 | + 'label' => isset($label) ? $label : null, |
|
626 | + 'desc' => isset($desc) ? $desc : null, |
|
627 | 627 | 'placeholder' => '', |
628 | 628 | 'class' => 'regular-text', |
629 | 629 | 'disabled' => false, |
@@ -633,51 +633,51 @@ discard block |
||
633 | 633 | 'data' => false |
634 | 634 | ); |
635 | 635 | |
636 | - $args = wp_parse_args( $args, $defaults ); |
|
636 | + $args = wp_parse_args($args, $defaults); |
|
637 | 637 | |
638 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
638 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
639 | 639 | $options = ''; |
640 | - if( $args['required'] ) { |
|
640 | + if ($args['required']) { |
|
641 | 641 | $options .= ' required="required"'; |
642 | 642 | } |
643 | - if( $args['readonly'] ) { |
|
643 | + if ($args['readonly']) { |
|
644 | 644 | $options .= ' readonly'; |
645 | 645 | } |
646 | - if( $args['readonly'] ) { |
|
646 | + if ($args['readonly']) { |
|
647 | 647 | $options .= ' readonly'; |
648 | 648 | } |
649 | 649 | |
650 | 650 | $data = ''; |
651 | - if ( !empty( $args['data'] ) ) { |
|
652 | - foreach ( $args['data'] as $key => $value ) { |
|
653 | - $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" '; |
|
651 | + if (!empty($args['data'])) { |
|
652 | + foreach ($args['data'] as $key => $value) { |
|
653 | + $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" '; |
|
654 | 654 | } |
655 | 655 | } |
656 | 656 | |
657 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
658 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
659 | - if ( ! empty( $args['desc'] ) ) { |
|
660 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
657 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
658 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>'; |
|
659 | + if (!empty($args['desc'])) { |
|
660 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
661 | 661 | } |
662 | 662 | |
663 | - $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>'; |
|
663 | + $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>'; |
|
664 | 664 | |
665 | 665 | $output .= '</span>'; |
666 | 666 | |
667 | 667 | return $output; |
668 | 668 | } |
669 | 669 | |
670 | -function wpinv_html_date_field( $args = array() ) { |
|
671 | - if( empty( $args['class'] ) ) { |
|
670 | +function wpinv_html_date_field($args = array()) { |
|
671 | + if (empty($args['class'])) { |
|
672 | 672 | $args['class'] = 'wpiDatepicker'; |
673 | - } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) { |
|
673 | + } elseif (!strpos($args['class'], 'wpiDatepicker')) { |
|
674 | 674 | $args['class'] .= ' wpiDatepicker'; |
675 | 675 | } |
676 | 676 | |
677 | - return wpinv_html_text( $args ); |
|
677 | + return wpinv_html_text($args); |
|
678 | 678 | } |
679 | 679 | |
680 | -function wpinv_html_textarea( $args = array() ) { |
|
680 | +function wpinv_html_textarea($args = array()) { |
|
681 | 681 | $defaults = array( |
682 | 682 | 'name' => 'textarea', |
683 | 683 | 'value' => null, |
@@ -688,31 +688,31 @@ discard block |
||
688 | 688 | 'placeholder' => '', |
689 | 689 | ); |
690 | 690 | |
691 | - $args = wp_parse_args( $args, $defaults ); |
|
691 | + $args = wp_parse_args($args, $defaults); |
|
692 | 692 | |
693 | - $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) ); |
|
693 | + $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class']))); |
|
694 | 694 | $disabled = ''; |
695 | - if( $args['disabled'] ) { |
|
695 | + if ($args['disabled']) { |
|
696 | 696 | $disabled = ' disabled="disabled"'; |
697 | 697 | } |
698 | 698 | |
699 | - $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">'; |
|
700 | - $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>'; |
|
701 | - $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>'; |
|
699 | + $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">'; |
|
700 | + $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>'; |
|
701 | + $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>'; |
|
702 | 702 | |
703 | - if ( ! empty( $args['desc'] ) ) { |
|
704 | - $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>'; |
|
703 | + if (!empty($args['desc'])) { |
|
704 | + $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>'; |
|
705 | 705 | } |
706 | 706 | $output .= '</span>'; |
707 | 707 | |
708 | 708 | return $output; |
709 | 709 | } |
710 | 710 | |
711 | -function wpinv_html_ajax_user_search( $args = array() ) { |
|
711 | +function wpinv_html_ajax_user_search($args = array()) { |
|
712 | 712 | $defaults = array( |
713 | 713 | 'name' => 'user_id', |
714 | 714 | 'value' => null, |
715 | - 'placeholder' => __( 'Enter username', 'invoicing' ), |
|
715 | + 'placeholder' => __('Enter username', 'invoicing'), |
|
716 | 716 | 'label' => null, |
717 | 717 | 'desc' => null, |
718 | 718 | 'class' => '', |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | 'data' => false |
722 | 722 | ); |
723 | 723 | |
724 | - $args = wp_parse_args( $args, $defaults ); |
|
724 | + $args = wp_parse_args($args, $defaults); |
|
725 | 725 | |
726 | 726 | $args['class'] = 'wpinv-ajax-user-search ' . $args['class']; |
727 | 727 | |
728 | 728 | $output = '<span class="wpinv_user_search_wrap">'; |
729 | - $output .= wpinv_html_text( $args ); |
|
730 | - $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>'; |
|
729 | + $output .= wpinv_html_text($args); |
|
730 | + $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>'; |
|
731 | 731 | $output .= '</span>'; |
732 | 732 | |
733 | 733 | return $output; |
@@ -743,20 +743,20 @@ discard block |
||
743 | 743 | * |
744 | 744 | * @param string $template the template that is currently being used. |
745 | 745 | */ |
746 | -function wpinv_template( $template ) { |
|
746 | +function wpinv_template($template) { |
|
747 | 747 | global $post; |
748 | 748 | |
749 | - if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) { |
|
749 | + if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) { |
|
750 | 750 | |
751 | 751 | // If the user can view this invoice, display it. |
752 | - if ( wpinv_user_can_view_invoice( $post->ID ) ) { |
|
752 | + if (wpinv_user_can_view_invoice($post->ID)) { |
|
753 | 753 | |
754 | - return wpinv_get_template_part( 'wpinv-invoice-print', false, false ); |
|
754 | + return wpinv_get_template_part('wpinv-invoice-print', false, false); |
|
755 | 755 | |
756 | 756 | // Else display an error message. |
757 | 757 | } else { |
758 | 758 | |
759 | - return wpinv_get_template_part( 'wpinv-invalid-access', false, false ); |
|
759 | + return wpinv_get_template_part('wpinv-invalid-access', false, false); |
|
760 | 760 | |
761 | 761 | } |
762 | 762 | |
@@ -764,46 +764,46 @@ discard block |
||
764 | 764 | |
765 | 765 | return $template; |
766 | 766 | } |
767 | -add_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
767 | +add_filter('template_include', 'wpinv_template', 10, 1); |
|
768 | 768 | |
769 | 769 | function wpinv_get_business_address() { |
770 | 770 | $business_address = wpinv_store_address(); |
771 | - $business_address = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : ''; |
|
771 | + $business_address = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : ''; |
|
772 | 772 | |
773 | 773 | $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : ''; |
774 | 774 | |
775 | - return apply_filters( 'wpinv_get_business_address', $business_address ); |
|
775 | + return apply_filters('wpinv_get_business_address', $business_address); |
|
776 | 776 | } |
777 | 777 | |
778 | 778 | /** |
779 | 779 | * Displays the company address. |
780 | 780 | */ |
781 | 781 | function wpinv_display_from_address() { |
782 | - wpinv_get_template( 'invoice/company-address.php' ); |
|
782 | + wpinv_get_template('invoice/company-address.php'); |
|
783 | 783 | } |
784 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 ); |
|
784 | +add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10); |
|
785 | 785 | |
786 | -function wpinv_watermark( $id = 0 ) { |
|
787 | - $output = wpinv_get_watermark( $id ); |
|
788 | - return apply_filters( 'wpinv_get_watermark', $output, $id ); |
|
786 | +function wpinv_watermark($id = 0) { |
|
787 | + $output = wpinv_get_watermark($id); |
|
788 | + return apply_filters('wpinv_get_watermark', $output, $id); |
|
789 | 789 | } |
790 | 790 | |
791 | -function wpinv_get_watermark( $id ) { |
|
792 | - if ( !$id > 0 ) { |
|
791 | +function wpinv_get_watermark($id) { |
|
792 | + if (!$id > 0) { |
|
793 | 793 | return NULL; |
794 | 794 | } |
795 | 795 | |
796 | - $invoice = wpinv_get_invoice( $id ); |
|
796 | + $invoice = wpinv_get_invoice($id); |
|
797 | 797 | |
798 | - if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) { |
|
799 | - if ( $invoice->is_paid() ) { |
|
800 | - return __( 'Paid', 'invoicing' ); |
|
798 | + if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) { |
|
799 | + if ($invoice->is_paid()) { |
|
800 | + return __('Paid', 'invoicing'); |
|
801 | 801 | } |
802 | - if ( $invoice->is_refunded() ) { |
|
803 | - return __( 'Refunded', 'invoicing' ); |
|
802 | + if ($invoice->is_refunded()) { |
|
803 | + return __('Refunded', 'invoicing'); |
|
804 | 804 | } |
805 | - if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) { |
|
806 | - return __( 'Cancelled', 'invoicing' ); |
|
805 | + if ($invoice->has_status(array('wpi-cancelled'))) { |
|
806 | + return __('Cancelled', 'invoicing'); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | |
@@ -813,30 +813,30 @@ discard block |
||
813 | 813 | /** |
814 | 814 | * @deprecated |
815 | 815 | */ |
816 | -function wpinv_display_invoice_details( $invoice ) { |
|
817 | - return getpaid_invoice_meta( $invoice ); |
|
816 | +function wpinv_display_invoice_details($invoice) { |
|
817 | + return getpaid_invoice_meta($invoice); |
|
818 | 818 | } |
819 | 819 | |
820 | 820 | /** |
821 | 821 | * Displays invoice meta. |
822 | 822 | */ |
823 | -function getpaid_invoice_meta( $invoice ) { |
|
823 | +function getpaid_invoice_meta($invoice) { |
|
824 | 824 | |
825 | - $invoice = new WPInv_Invoice( $invoice ); |
|
825 | + $invoice = new WPInv_Invoice($invoice); |
|
826 | 826 | |
827 | 827 | // Ensure that we have an invoice. |
828 | - if ( 0 == $invoice->get_id() ) { |
|
828 | + if (0 == $invoice->get_id()) { |
|
829 | 829 | return; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // Get the invoice meta. |
833 | - $meta = getpaid_get_invoice_meta( $invoice ); |
|
833 | + $meta = getpaid_get_invoice_meta($invoice); |
|
834 | 834 | |
835 | 835 | // Display the meta. |
836 | - wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) ); |
|
836 | + wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta')); |
|
837 | 837 | |
838 | 838 | } |
839 | -add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 ); |
|
839 | +add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10); |
|
840 | 840 | |
841 | 841 | /** |
842 | 842 | * Retrieves the address markup to use on Invoices. |
@@ -848,29 +848,29 @@ discard block |
||
848 | 848 | * @param string $separator How to separate address lines. |
849 | 849 | * @return string |
850 | 850 | */ |
851 | -function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) { |
|
851 | +function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') { |
|
852 | 852 | |
853 | 853 | // Retrieve the address markup... |
854 | - $country= empty( $billing_details['country'] ) ? '' : $billing_details['country']; |
|
855 | - $format = wpinv_get_full_address_format( $country ); |
|
854 | + $country = empty($billing_details['country']) ? '' : $billing_details['country']; |
|
855 | + $format = wpinv_get_full_address_format($country); |
|
856 | 856 | |
857 | 857 | // ... and the replacements. |
858 | - $replacements = wpinv_get_invoice_address_replacements( $billing_details ); |
|
858 | + $replacements = wpinv_get_invoice_address_replacements($billing_details); |
|
859 | 859 | |
860 | - $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format ); |
|
860 | + $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format); |
|
861 | 861 | |
862 | 862 | // Remove unavailable tags. |
863 | - $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address ); |
|
863 | + $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address); |
|
864 | 864 | |
865 | 865 | // Clean up white space. |
866 | - $formatted_address = preg_replace( '/ +/', ' ', trim( $formatted_address ) ); |
|
867 | - $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address ); |
|
866 | + $formatted_address = preg_replace('/ +/', ' ', trim($formatted_address)); |
|
867 | + $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address); |
|
868 | 868 | |
869 | 869 | // Break newlines apart and remove empty lines/trim commas and white space. |
870 | - $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) ); |
|
870 | + $formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address))); |
|
871 | 871 | |
872 | 872 | // Add html breaks. |
873 | - $formatted_address = implode( $separator, $formatted_address ); |
|
873 | + $formatted_address = implode($separator, $formatted_address); |
|
874 | 874 | |
875 | 875 | // We're done! |
876 | 876 | return $formatted_address; |
@@ -882,88 +882,88 @@ discard block |
||
882 | 882 | * |
883 | 883 | * @param WPInv_Invoice $invoice |
884 | 884 | */ |
885 | -function wpinv_display_to_address( $invoice = 0 ) { |
|
886 | - if ( ! empty( $invoice ) ) { |
|
887 | - wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) ); |
|
885 | +function wpinv_display_to_address($invoice = 0) { |
|
886 | + if (!empty($invoice)) { |
|
887 | + wpinv_get_template('invoice/billing-address.php', compact('invoice')); |
|
888 | 888 | } |
889 | 889 | } |
890 | -add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 ); |
|
890 | +add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40); |
|
891 | 891 | |
892 | 892 | |
893 | 893 | /** |
894 | 894 | * Displays invoice line items. |
895 | 895 | */ |
896 | -function wpinv_display_line_items( $invoice_id = 0 ) { |
|
896 | +function wpinv_display_line_items($invoice_id = 0) { |
|
897 | 897 | |
898 | 898 | // Prepare the invoice. |
899 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
899 | + $invoice = new WPInv_Invoice($invoice_id); |
|
900 | 900 | |
901 | 901 | // Abort if there is no invoice. |
902 | - if ( 0 == $invoice->get_id() ) { |
|
902 | + if (0 == $invoice->get_id()) { |
|
903 | 903 | return; |
904 | 904 | } |
905 | 905 | |
906 | 906 | // Line item columns. |
907 | - $columns = getpaid_invoice_item_columns( $invoice ); |
|
908 | - $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice ); |
|
907 | + $columns = getpaid_invoice_item_columns($invoice); |
|
908 | + $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice); |
|
909 | 909 | |
910 | - wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) ); |
|
910 | + wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns')); |
|
911 | 911 | } |
912 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 ); |
|
912 | +add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10); |
|
913 | 913 | |
914 | 914 | /** |
915 | 915 | * Displays invoice notices on invoices. |
916 | 916 | */ |
917 | 917 | function wpinv_display_invoice_notice() { |
918 | 918 | |
919 | - $label = wpinv_get_option( 'vat_invoice_notice_label' ); |
|
920 | - $notice = wpinv_get_option( 'vat_invoice_notice' ); |
|
919 | + $label = wpinv_get_option('vat_invoice_notice_label'); |
|
920 | + $notice = wpinv_get_option('vat_invoice_notice'); |
|
921 | 921 | |
922 | - if ( empty( $label ) && empty( $notice ) ) { |
|
922 | + if (empty($label) && empty($notice)) { |
|
923 | 923 | return; |
924 | 924 | } |
925 | 925 | |
926 | 926 | echo '<div class="mt-4 mb-4 wpinv-vat-notice">'; |
927 | 927 | |
928 | - if ( ! empty( $label ) ) { |
|
929 | - $label = sanitize_text_field( $label ); |
|
928 | + if (!empty($label)) { |
|
929 | + $label = sanitize_text_field($label); |
|
930 | 930 | echo "<h5>$label</h5>"; |
931 | 931 | } |
932 | 932 | |
933 | - if ( ! empty( $notice ) ) { |
|
934 | - echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>'; |
|
933 | + if (!empty($notice)) { |
|
934 | + echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>'; |
|
935 | 935 | } |
936 | 936 | |
937 | 937 | echo '</div>'; |
938 | 938 | } |
939 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 ); |
|
939 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100); |
|
940 | 940 | |
941 | 941 | /** |
942 | 942 | * @param WPInv_Invoice $invoice |
943 | 943 | */ |
944 | -function wpinv_display_invoice_notes( $invoice ) { |
|
944 | +function wpinv_display_invoice_notes($invoice) { |
|
945 | 945 | |
946 | 946 | // Retrieve the notes. |
947 | - $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' ); |
|
947 | + $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer'); |
|
948 | 948 | |
949 | 949 | // Abort if we have non. |
950 | - if ( empty( $notes ) ) { |
|
950 | + if (empty($notes)) { |
|
951 | 951 | return; |
952 | 952 | } |
953 | 953 | |
954 | 954 | // Echo the note. |
955 | 955 | echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">'; |
956 | - echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>'; |
|
956 | + echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>'; |
|
957 | 957 | echo '<ul class="getpaid-invoice-notes mt-4 p-0">'; |
958 | 958 | |
959 | - foreach( $notes as $note ) { |
|
960 | - wpinv_get_invoice_note_line_item( $note ); |
|
959 | + foreach ($notes as $note) { |
|
960 | + wpinv_get_invoice_note_line_item($note); |
|
961 | 961 | } |
962 | 962 | |
963 | 963 | echo '</ul>'; |
964 | 964 | echo '</div>'; |
965 | 965 | } |
966 | -add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 ); |
|
966 | +add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60); |
|
967 | 967 | |
968 | 968 | /** |
969 | 969 | * Loads scripts on our invoice templates. |
@@ -971,32 +971,32 @@ discard block |
||
971 | 971 | function wpinv_display_style() { |
972 | 972 | |
973 | 973 | // Make sure that all scripts have been loaded. |
974 | - if ( ! did_action( 'wp_enqueue_scripts' ) ) { |
|
975 | - do_action( 'wp_enqueue_scripts' ); |
|
974 | + if (!did_action('wp_enqueue_scripts')) { |
|
975 | + do_action('wp_enqueue_scripts'); |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | // Register the invoices style. |
979 | - wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) ); |
|
979 | + wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css')); |
|
980 | 980 | |
981 | 981 | // Load required styles |
982 | - wp_print_styles( 'open-sans' ); |
|
983 | - wp_print_styles( 'wpinv-single-style' ); |
|
984 | - wp_print_styles( 'ayecode-ui' ); |
|
982 | + wp_print_styles('open-sans'); |
|
983 | + wp_print_styles('wpinv-single-style'); |
|
984 | + wp_print_styles('ayecode-ui'); |
|
985 | 985 | |
986 | 986 | // Maybe load custom css. |
987 | - $custom_css = wpinv_get_option( 'template_custom_css' ); |
|
987 | + $custom_css = wpinv_get_option('template_custom_css'); |
|
988 | 988 | |
989 | - if ( isset( $custom_css ) && ! empty( $custom_css ) ) { |
|
990 | - $custom_css = wp_kses( $custom_css, array( '\'', '\"' ) ); |
|
991 | - $custom_css = str_replace( '>', '>', $custom_css ); |
|
989 | + if (isset($custom_css) && !empty($custom_css)) { |
|
990 | + $custom_css = wp_kses($custom_css, array('\'', '\"')); |
|
991 | + $custom_css = str_replace('>', '>', $custom_css); |
|
992 | 992 | echo '<style type="text/css">'; |
993 | 993 | echo $custom_css; |
994 | 994 | echo '</style>'; |
995 | 995 | } |
996 | 996 | |
997 | 997 | } |
998 | -add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' ); |
|
999 | -add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' ); |
|
998 | +add_action('wpinv_invoice_print_head', 'wpinv_display_style'); |
|
999 | +add_action('wpinv_invalid_invoice_head', 'wpinv_display_style'); |
|
1000 | 1000 | |
1001 | 1001 | |
1002 | 1002 | /** |
@@ -1008,41 +1008,41 @@ discard block |
||
1008 | 1008 | // Retrieve the current invoice. |
1009 | 1009 | $invoice_id = getpaid_get_current_invoice_id(); |
1010 | 1010 | |
1011 | - if ( empty( $invoice_id ) ) { |
|
1011 | + if (empty($invoice_id)) { |
|
1012 | 1012 | |
1013 | 1013 | return aui()->alert( |
1014 | 1014 | array( |
1015 | 1015 | 'type' => 'warning', |
1016 | - 'content' => __( 'Invalid invoice', 'invoicing' ), |
|
1016 | + 'content' => __('Invalid invoice', 'invoicing'), |
|
1017 | 1017 | ) |
1018 | 1018 | ); |
1019 | 1019 | |
1020 | 1020 | } |
1021 | 1021 | |
1022 | 1022 | // Can the user view this invoice? |
1023 | - if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) { |
|
1023 | + if (!wpinv_user_can_view_invoice($invoice_id)) { |
|
1024 | 1024 | |
1025 | 1025 | return aui()->alert( |
1026 | 1026 | array( |
1027 | 1027 | 'type' => 'warning', |
1028 | - 'content' => __( 'You are not allowed to view this invoice', 'invoicing' ), |
|
1028 | + 'content' => __('You are not allowed to view this invoice', 'invoicing'), |
|
1029 | 1029 | ) |
1030 | 1030 | ); |
1031 | 1031 | |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | // Ensure that it is not yet paid for. |
1035 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1035 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1036 | 1036 | |
1037 | 1037 | // Maybe mark it as viewed. |
1038 | - getpaid_maybe_mark_invoice_as_viewed( $invoice ); |
|
1038 | + getpaid_maybe_mark_invoice_as_viewed($invoice); |
|
1039 | 1039 | |
1040 | - if ( $invoice->is_paid() ) { |
|
1040 | + if ($invoice->is_paid()) { |
|
1041 | 1041 | |
1042 | 1042 | return aui()->alert( |
1043 | 1043 | array( |
1044 | 1044 | 'type' => 'success', |
1045 | - 'content' => __( 'This invoice has already been paid.', 'invoicing' ), |
|
1045 | + 'content' => __('This invoice has already been paid.', 'invoicing'), |
|
1046 | 1046 | ) |
1047 | 1047 | ); |
1048 | 1048 | |
@@ -1052,14 +1052,14 @@ discard block |
||
1052 | 1052 | $wpi_checkout_id = $invoice_id; |
1053 | 1053 | |
1054 | 1054 | // We'll display this invoice via the default form. |
1055 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1055 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1056 | 1056 | |
1057 | - if ( 0 == $form->get_id() ) { |
|
1057 | + if (0 == $form->get_id()) { |
|
1058 | 1058 | |
1059 | 1059 | return aui()->alert( |
1060 | 1060 | array( |
1061 | 1061 | 'type' => 'warning', |
1062 | - 'content' => __( 'Error loading the payment form', 'invoicing' ), |
|
1062 | + 'content' => __('Error loading the payment form', 'invoicing'), |
|
1063 | 1063 | ) |
1064 | 1064 | ); |
1065 | 1065 | |
@@ -1067,7 +1067,7 @@ discard block |
||
1067 | 1067 | |
1068 | 1068 | // Set the invoice. |
1069 | 1069 | $form->invoice = $invoice; |
1070 | - $form->set_items( $invoice->get_items() ); |
|
1070 | + $form->set_items($invoice->get_items()); |
|
1071 | 1071 | |
1072 | 1072 | // Generate the html. |
1073 | 1073 | return $form->get_html(); |
@@ -1075,7 +1075,7 @@ discard block |
||
1075 | 1075 | } |
1076 | 1076 | |
1077 | 1077 | function wpinv_empty_cart_message() { |
1078 | - return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' ); |
|
1078 | + return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>'); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1092,38 +1092,38 @@ discard block |
||
1092 | 1092 | ) |
1093 | 1093 | ); |
1094 | 1094 | } |
1095 | -add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' ); |
|
1095 | +add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart'); |
|
1096 | 1096 | |
1097 | -function wpinv_receipt_billing_address( $invoice_id = 0 ) { |
|
1098 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1097 | +function wpinv_receipt_billing_address($invoice_id = 0) { |
|
1098 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1099 | 1099 | |
1100 | - if ( empty( $invoice ) ) { |
|
1100 | + if (empty($invoice)) { |
|
1101 | 1101 | return NULL; |
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | $billing_details = $invoice->get_user_info(); |
1105 | - $address_row = wpinv_get_invoice_address_markup( $billing_details ); |
|
1105 | + $address_row = wpinv_get_invoice_address_markup($billing_details); |
|
1106 | 1106 | |
1107 | 1107 | ob_start(); |
1108 | 1108 | ?> |
1109 | 1109 | <table class="table table-bordered table-sm wpi-billing-details"> |
1110 | 1110 | <tbody> |
1111 | 1111 | <tr class="wpi-receipt-name"> |
1112 | - <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th> |
|
1113 | - <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td> |
|
1112 | + <th class="text-left"><?php _e('Name', 'invoicing'); ?></th> |
|
1113 | + <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td> |
|
1114 | 1114 | </tr> |
1115 | 1115 | <tr class="wpi-receipt-email"> |
1116 | - <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th> |
|
1117 | - <td><?php echo $billing_details['email'] ;?></td> |
|
1116 | + <th class="text-left"><?php _e('Email', 'invoicing'); ?></th> |
|
1117 | + <td><?php echo $billing_details['email']; ?></td> |
|
1118 | 1118 | </tr> |
1119 | 1119 | <tr class="wpi-receipt-address"> |
1120 | - <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th> |
|
1121 | - <td><?php echo $address_row ;?></td> |
|
1120 | + <th class="text-left"><?php _e('Address', 'invoicing'); ?></th> |
|
1121 | + <td><?php echo $address_row; ?></td> |
|
1122 | 1122 | </tr> |
1123 | - <?php if ( $billing_details['phone'] ) { ?> |
|
1123 | + <?php if ($billing_details['phone']) { ?> |
|
1124 | 1124 | <tr class="wpi-receipt-phone"> |
1125 | - <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th> |
|
1126 | - <td><?php echo esc_html( $billing_details['phone'] ) ;?></td> |
|
1125 | + <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th> |
|
1126 | + <td><?php echo esc_html($billing_details['phone']); ?></td> |
|
1127 | 1127 | </tr> |
1128 | 1128 | <?php } ?> |
1129 | 1129 | </tbody> |
@@ -1131,7 +1131,7 @@ discard block |
||
1131 | 1131 | <?php |
1132 | 1132 | $output = ob_get_clean(); |
1133 | 1133 | |
1134 | - $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id ); |
|
1134 | + $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id); |
|
1135 | 1135 | |
1136 | 1136 | echo $output; |
1137 | 1137 | } |
@@ -1139,88 +1139,88 @@ discard block |
||
1139 | 1139 | /** |
1140 | 1140 | * Filters the receipt page. |
1141 | 1141 | */ |
1142 | -function wpinv_filter_success_page_content( $content ) { |
|
1142 | +function wpinv_filter_success_page_content($content) { |
|
1143 | 1143 | |
1144 | 1144 | // Ensure this is our page. |
1145 | - if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) { |
|
1145 | + if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) { |
|
1146 | 1146 | |
1147 | - $gateway = sanitize_text_field( $_GET['payment-confirm'] ); |
|
1148 | - return apply_filters( "wpinv_payment_confirm_$gateway", $content ); |
|
1147 | + $gateway = sanitize_text_field($_GET['payment-confirm']); |
|
1148 | + return apply_filters("wpinv_payment_confirm_$gateway", $content); |
|
1149 | 1149 | |
1150 | 1150 | } |
1151 | 1151 | |
1152 | 1152 | return $content; |
1153 | 1153 | } |
1154 | -add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 ); |
|
1154 | +add_filter('the_content', 'wpinv_filter_success_page_content', 99999); |
|
1155 | 1155 | |
1156 | -function wpinv_invoice_link( $invoice_id ) { |
|
1157 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1156 | +function wpinv_invoice_link($invoice_id) { |
|
1157 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1158 | 1158 | |
1159 | - if ( empty( $invoice ) ) { |
|
1159 | + if (empty($invoice)) { |
|
1160 | 1160 | return NULL; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | - $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>'; |
|
1163 | + $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>'; |
|
1164 | 1164 | |
1165 | - return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice ); |
|
1165 | + return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice); |
|
1166 | 1166 | } |
1167 | 1167 | |
1168 | -function wpinv_cart_total_label( $label, $invoice ) { |
|
1169 | - if ( empty( $invoice ) ) { |
|
1168 | +function wpinv_cart_total_label($label, $invoice) { |
|
1169 | + if (empty($invoice)) { |
|
1170 | 1170 | return $label; |
1171 | 1171 | } |
1172 | 1172 | |
1173 | 1173 | $prefix_label = ''; |
1174 | - if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) { |
|
1175 | - $prefix_label = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice ); |
|
1176 | - } else if ( $invoice->is_renewal() ) { |
|
1177 | - $prefix_label = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> '; |
|
1174 | + if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) { |
|
1175 | + $prefix_label = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice); |
|
1176 | + } else if ($invoice->is_renewal()) { |
|
1177 | + $prefix_label = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> '; |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | - if ( $prefix_label != '' ) { |
|
1181 | - $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1180 | + if ($prefix_label != '') { |
|
1181 | + $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label; |
|
1182 | 1182 | } |
1183 | 1183 | |
1184 | 1184 | return $label; |
1185 | 1185 | } |
1186 | -add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1187 | -add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1188 | -add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 ); |
|
1186 | +add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1187 | +add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1188 | +add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2); |
|
1189 | 1189 | |
1190 | -function wpinv_get_invoice_note_line_item( $note, $echo = true ) { |
|
1191 | - if ( empty( $note ) ) { |
|
1190 | +function wpinv_get_invoice_note_line_item($note, $echo = true) { |
|
1191 | + if (empty($note)) { |
|
1192 | 1192 | return NULL; |
1193 | 1193 | } |
1194 | 1194 | |
1195 | - if ( is_int( $note ) ) { |
|
1196 | - $note = get_comment( $note ); |
|
1195 | + if (is_int($note)) { |
|
1196 | + $note = get_comment($note); |
|
1197 | 1197 | } |
1198 | 1198 | |
1199 | - if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) { |
|
1199 | + if (!(is_object($note) && is_a($note, 'WP_Comment'))) { |
|
1200 | 1200 | return NULL; |
1201 | 1201 | } |
1202 | 1202 | |
1203 | - $note_classes = array( 'note' ); |
|
1204 | - $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : ''; |
|
1203 | + $note_classes = array('note'); |
|
1204 | + $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : ''; |
|
1205 | 1205 | $note_classes[] = $note->comment_author === 'System' ? 'system-note' : ''; |
1206 | - $note_classes = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note ); |
|
1207 | - $note_classes = !empty( $note_classes ) ? implode( ' ', $note_classes ) : ''; |
|
1206 | + $note_classes = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note); |
|
1207 | + $note_classes = !empty($note_classes) ? implode(' ', $note_classes) : ''; |
|
1208 | 1208 | |
1209 | 1209 | ob_start(); |
1210 | 1210 | ?> |
1211 | - <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3"> |
|
1211 | + <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3"> |
|
1212 | 1212 | <div class="note_content bg-light border position-relative p-4"> |
1213 | 1213 | |
1214 | - <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?> |
|
1214 | + <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?> |
|
1215 | 1215 | |
1216 | - <?php if ( ! is_admin() ) : ?> |
|
1216 | + <?php if (!is_admin()) : ?> |
|
1217 | 1217 | <em class="meta position-absolute form-text"> |
1218 | 1218 | <?php |
1219 | 1219 | printf( |
1220 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1220 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1221 | 1221 | $note->comment_author, |
1222 | - getpaid_format_date_value( $note->comment_date ), |
|
1223 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1222 | + getpaid_format_date_value($note->comment_date), |
|
1223 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1224 | 1224 | ); |
1225 | 1225 | ?> |
1226 | 1226 | </em> |
@@ -1228,21 +1228,21 @@ discard block |
||
1228 | 1228 | |
1229 | 1229 | </div> |
1230 | 1230 | |
1231 | - <?php if ( is_admin() ) : ?> |
|
1231 | + <?php if (is_admin()) : ?> |
|
1232 | 1232 | |
1233 | 1233 | <p class="meta px-4 py-2"> |
1234 | - <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"> |
|
1234 | + <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"> |
|
1235 | 1235 | <?php |
1236 | 1236 | printf( |
1237 | - __( '%1$s - %2$s at %3$s', 'invoicing' ), |
|
1237 | + __('%1$s - %2$s at %3$s', 'invoicing'), |
|
1238 | 1238 | $note->comment_author, |
1239 | - getpaid_format_date_value( $note->comment_date ), |
|
1240 | - date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) |
|
1239 | + getpaid_format_date_value($note->comment_date), |
|
1240 | + date_i18n(get_option('time_format'), strtotime($note->comment_date)) |
|
1241 | 1241 | ); |
1242 | 1242 | ?> |
1243 | 1243 | </abbr> |
1244 | - <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?> |
|
1245 | - <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a> |
|
1244 | + <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?> |
|
1245 | + <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a> |
|
1246 | 1246 | <?php } ?> |
1247 | 1247 | </p> |
1248 | 1248 | |
@@ -1251,9 +1251,9 @@ discard block |
||
1251 | 1251 | </li> |
1252 | 1252 | <?php |
1253 | 1253 | $note_content = ob_get_clean(); |
1254 | - $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo ); |
|
1254 | + $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo); |
|
1255 | 1255 | |
1256 | - if ( $echo ) { |
|
1256 | + if ($echo) { |
|
1257 | 1257 | echo $note_content; |
1258 | 1258 | } else { |
1259 | 1259 | return $note_content; |
@@ -1263,36 +1263,36 @@ discard block |
||
1263 | 1263 | function wpinv_invalid_invoice_content() { |
1264 | 1264 | global $post; |
1265 | 1265 | |
1266 | - $invoice = wpinv_get_invoice( $post->ID ); |
|
1266 | + $invoice = wpinv_get_invoice($post->ID); |
|
1267 | 1267 | |
1268 | - $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' ); |
|
1269 | - if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) { |
|
1270 | - if ( is_user_logged_in() ) { |
|
1271 | - if ( wpinv_require_login_to_checkout() ) { |
|
1272 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1273 | - $error = __( 'You are not allowed to view this invoice.', 'invoicing' ); |
|
1268 | + $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing'); |
|
1269 | + if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) { |
|
1270 | + if (is_user_logged_in()) { |
|
1271 | + if (wpinv_require_login_to_checkout()) { |
|
1272 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1273 | + $error = __('You are not allowed to view this invoice.', 'invoicing'); |
|
1274 | 1274 | } |
1275 | 1275 | } |
1276 | 1276 | } else { |
1277 | - if ( wpinv_require_login_to_checkout() ) { |
|
1278 | - if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
1279 | - $error = __( 'You must be logged in to view this invoice.', 'invoicing' ); |
|
1277 | + if (wpinv_require_login_to_checkout()) { |
|
1278 | + if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
1279 | + $error = __('You must be logged in to view this invoice.', 'invoicing'); |
|
1280 | 1280 | } |
1281 | 1281 | } |
1282 | 1282 | } |
1283 | 1283 | } else { |
1284 | - $error = __( 'This invoice is deleted or does not exist.', 'invoicing' ); |
|
1284 | + $error = __('This invoice is deleted or does not exist.', 'invoicing'); |
|
1285 | 1285 | } |
1286 | 1286 | ?> |
1287 | 1287 | <div class="row wpinv-row-invalid"> |
1288 | 1288 | <div class="col-md-6 col-md-offset-3 wpinv-message error"> |
1289 | - <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3> |
|
1289 | + <h3><?php _e('Access Denied', 'invoicing'); ?></h3> |
|
1290 | 1290 | <p class="wpinv-msg-text"><?php echo $error; ?></p> |
1291 | 1291 | </div> |
1292 | 1292 | </div> |
1293 | 1293 | <?php |
1294 | 1294 | } |
1295 | -add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' ); |
|
1295 | +add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content'); |
|
1296 | 1296 | |
1297 | 1297 | /** |
1298 | 1298 | * Function to get privacy policy text. |
@@ -1301,21 +1301,21 @@ discard block |
||
1301 | 1301 | * @return string |
1302 | 1302 | */ |
1303 | 1303 | function wpinv_get_policy_text() { |
1304 | - $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 ); |
|
1304 | + $privacy_page_id = get_option('wp_page_for_privacy_policy', 0); |
|
1305 | 1305 | |
1306 | - $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' )); |
|
1306 | + $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]')); |
|
1307 | 1307 | |
1308 | - if(!$privacy_page_id){ |
|
1309 | - $privacy_page_id = wpinv_get_option( 'privacy_page', 0 ); |
|
1308 | + if (!$privacy_page_id) { |
|
1309 | + $privacy_page_id = wpinv_get_option('privacy_page', 0); |
|
1310 | 1310 | } |
1311 | 1311 | |
1312 | - $privacy_link = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' ); |
|
1312 | + $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing'); |
|
1313 | 1313 | |
1314 | 1314 | $find_replace = array( |
1315 | 1315 | '[wpinv_privacy_policy]' => $privacy_link, |
1316 | 1316 | ); |
1317 | 1317 | |
1318 | - $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text ); |
|
1318 | + $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text); |
|
1319 | 1319 | |
1320 | 1320 | return wp_kses_post(wpautop($privacy_text)); |
1321 | 1321 | } |
@@ -1323,21 +1323,21 @@ discard block |
||
1323 | 1323 | function wpinv_oxygen_fix_conflict() { |
1324 | 1324 | global $ct_ignore_post_types; |
1325 | 1325 | |
1326 | - if ( ! is_array( $ct_ignore_post_types ) ) { |
|
1326 | + if (!is_array($ct_ignore_post_types)) { |
|
1327 | 1327 | $ct_ignore_post_types = array(); |
1328 | 1328 | } |
1329 | 1329 | |
1330 | - $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' ); |
|
1330 | + $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item'); |
|
1331 | 1331 | |
1332 | - foreach ( $post_types as $post_type ) { |
|
1332 | + foreach ($post_types as $post_type) { |
|
1333 | 1333 | $ct_ignore_post_types[] = $post_type; |
1334 | 1334 | |
1335 | 1335 | // Ignore post type |
1336 | - add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 ); |
|
1336 | + add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999); |
|
1337 | 1337 | } |
1338 | 1338 | |
1339 | - remove_filter( 'template_include', 'wpinv_template', 10, 1 ); |
|
1340 | - add_filter( 'template_include', 'wpinv_template', 999, 1 ); |
|
1339 | + remove_filter('template_include', 'wpinv_template', 10, 1); |
|
1340 | + add_filter('template_include', 'wpinv_template', 999, 1); |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | /** |
@@ -1345,10 +1345,10 @@ discard block |
||
1345 | 1345 | * |
1346 | 1346 | * @param GetPaid_Payment_Form $form |
1347 | 1347 | */ |
1348 | -function getpaid_display_payment_form( $form ) { |
|
1348 | +function getpaid_display_payment_form($form) { |
|
1349 | 1349 | |
1350 | - if ( is_numeric( $form ) ) { |
|
1351 | - $form = new GetPaid_Payment_Form( $form ); |
|
1350 | + if (is_numeric($form)) { |
|
1351 | + $form = new GetPaid_Payment_Form($form); |
|
1352 | 1352 | } |
1353 | 1353 | |
1354 | 1354 | $form->display(); |
@@ -1358,16 +1358,16 @@ discard block |
||
1358 | 1358 | /** |
1359 | 1359 | * Helper function to display a item payment form on the frontend. |
1360 | 1360 | */ |
1361 | -function getpaid_display_item_payment_form( $items ) { |
|
1361 | +function getpaid_display_item_payment_form($items) { |
|
1362 | 1362 | |
1363 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1364 | - $form->set_items( $items ); |
|
1363 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1364 | + $form->set_items($items); |
|
1365 | 1365 | |
1366 | - if ( 0 == count( $form->get_items() ) ) { |
|
1366 | + if (0 == count($form->get_items())) { |
|
1367 | 1367 | echo aui()->alert( |
1368 | 1368 | array( |
1369 | 1369 | 'type' => 'warning', |
1370 | - 'content' => __( 'No published items found', 'invoicing' ), |
|
1370 | + 'content' => __('No published items found', 'invoicing'), |
|
1371 | 1371 | ) |
1372 | 1372 | ); |
1373 | 1373 | return; |
@@ -1379,32 +1379,32 @@ discard block |
||
1379 | 1379 | /** |
1380 | 1380 | * Helper function to display an invoice payment form on the frontend. |
1381 | 1381 | */ |
1382 | -function getpaid_display_invoice_payment_form( $invoice_id ) { |
|
1382 | +function getpaid_display_invoice_payment_form($invoice_id) { |
|
1383 | 1383 | |
1384 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1384 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1385 | 1385 | |
1386 | - if ( empty( $invoice ) ) { |
|
1386 | + if (empty($invoice)) { |
|
1387 | 1387 | echo aui()->alert( |
1388 | 1388 | array( |
1389 | 1389 | 'type' => 'warning', |
1390 | - 'content' => __( 'Invoice not found', 'invoicing' ), |
|
1390 | + 'content' => __('Invoice not found', 'invoicing'), |
|
1391 | 1391 | ) |
1392 | 1392 | ); |
1393 | 1393 | return; |
1394 | 1394 | } |
1395 | 1395 | |
1396 | - if ( $invoice->is_paid() ) { |
|
1396 | + if ($invoice->is_paid()) { |
|
1397 | 1397 | echo aui()->alert( |
1398 | 1398 | array( |
1399 | 1399 | 'type' => 'warning', |
1400 | - 'content' => __( 'Invoice has already been paid', 'invoicing' ), |
|
1400 | + 'content' => __('Invoice has already been paid', 'invoicing'), |
|
1401 | 1401 | ) |
1402 | 1402 | ); |
1403 | 1403 | return; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | - $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() ); |
|
1407 | - $form->set_items( $invoice->get_items() ); |
|
1406 | + $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form()); |
|
1407 | + $form->set_items($invoice->get_items()); |
|
1408 | 1408 | |
1409 | 1409 | $form->display(); |
1410 | 1410 | } |
@@ -1412,23 +1412,23 @@ discard block |
||
1412 | 1412 | /** |
1413 | 1413 | * Helper function to convert item string to array. |
1414 | 1414 | */ |
1415 | -function getpaid_convert_items_to_array( $items ) { |
|
1416 | - $items = array_filter( array_map( 'trim', explode( ',', $items ) ) ); |
|
1415 | +function getpaid_convert_items_to_array($items) { |
|
1416 | + $items = array_filter(array_map('trim', explode(',', $items))); |
|
1417 | 1417 | $prepared = array(); |
1418 | 1418 | |
1419 | - foreach ( $items as $item ) { |
|
1420 | - $data = array_map( 'trim', explode( '|', $item ) ); |
|
1419 | + foreach ($items as $item) { |
|
1420 | + $data = array_map('trim', explode('|', $item)); |
|
1421 | 1421 | |
1422 | - if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) { |
|
1422 | + if (empty($data[0]) || !is_numeric($data[0])) { |
|
1423 | 1423 | continue; |
1424 | 1424 | } |
1425 | 1425 | |
1426 | 1426 | $quantity = 1; |
1427 | - if ( isset( $data[1] ) && is_numeric( $data[1] ) ) { |
|
1427 | + if (isset($data[1]) && is_numeric($data[1])) { |
|
1428 | 1428 | $quantity = (int) $data[1]; |
1429 | 1429 | } |
1430 | 1430 | |
1431 | - $prepared[ $data[0] ] = $quantity; |
|
1431 | + $prepared[$data[0]] = $quantity; |
|
1432 | 1432 | |
1433 | 1433 | } |
1434 | 1434 | |
@@ -1438,13 +1438,13 @@ discard block |
||
1438 | 1438 | /** |
1439 | 1439 | * Helper function to convert item array to string. |
1440 | 1440 | */ |
1441 | -function getpaid_convert_items_to_string( $items ) { |
|
1441 | +function getpaid_convert_items_to_string($items) { |
|
1442 | 1442 | $prepared = array(); |
1443 | 1443 | |
1444 | - foreach ( $items as $item => $quantity ) { |
|
1444 | + foreach ($items as $item => $quantity) { |
|
1445 | 1445 | $prepared[] = "$item|$quantity"; |
1446 | 1446 | } |
1447 | - return implode( ',', $prepared ); |
|
1447 | + return implode(',', $prepared); |
|
1448 | 1448 | } |
1449 | 1449 | |
1450 | 1450 | /** |
@@ -1452,22 +1452,22 @@ discard block |
||
1452 | 1452 | * |
1453 | 1453 | * Provide a label and one of $form, $items or $invoice. |
1454 | 1454 | */ |
1455 | -function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) { |
|
1456 | - $label = sanitize_text_field( $label ); |
|
1455 | +function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) { |
|
1456 | + $label = sanitize_text_field($label); |
|
1457 | 1457 | $nonce = wp_create_nonce('getpaid_ajax_form'); |
1458 | 1458 | |
1459 | - if ( ! empty( $form ) ) { |
|
1460 | - $form = esc_attr( $form ); |
|
1459 | + if (!empty($form)) { |
|
1460 | + $form = esc_attr($form); |
|
1461 | 1461 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; |
1462 | 1462 | } |
1463 | 1463 | |
1464 | - if ( ! empty( $items ) ) { |
|
1465 | - $items = esc_attr( $items ); |
|
1464 | + if (!empty($items)) { |
|
1465 | + $items = esc_attr($items); |
|
1466 | 1466 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; |
1467 | 1467 | } |
1468 | 1468 | |
1469 | - if ( ! empty( $invoice ) ) { |
|
1470 | - $invoice = esc_attr( $invoice ); |
|
1469 | + if (!empty($invoice)) { |
|
1470 | + $invoice = esc_attr($invoice); |
|
1471 | 1471 | return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; |
1472 | 1472 | } |
1473 | 1473 | |
@@ -1478,17 +1478,17 @@ discard block |
||
1478 | 1478 | * |
1479 | 1479 | * @param WPInv_Invoice $invoice |
1480 | 1480 | */ |
1481 | -function getpaid_the_invoice_description( $invoice ) { |
|
1481 | +function getpaid_the_invoice_description($invoice) { |
|
1482 | 1482 | $description = $invoice->get_description(); |
1483 | 1483 | |
1484 | - if ( empty( $description ) ) { |
|
1484 | + if (empty($description)) { |
|
1485 | 1485 | return; |
1486 | 1486 | } |
1487 | 1487 | |
1488 | - $description = wp_kses_post( $description ); |
|
1488 | + $description = wp_kses_post($description); |
|
1489 | 1489 | echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>"; |
1490 | 1490 | } |
1491 | -add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 ); |
|
1491 | +add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100); |
|
1492 | 1492 | |
1493 | 1493 | /** |
1494 | 1494 | * Render element on a form. |
@@ -1496,60 +1496,60 @@ discard block |
||
1496 | 1496 | * @param array $element |
1497 | 1497 | * @param GetPaid_Payment_Form $form |
1498 | 1498 | */ |
1499 | -function getpaid_payment_form_element( $element, $form ) { |
|
1499 | +function getpaid_payment_form_element($element, $form) { |
|
1500 | 1500 | |
1501 | 1501 | // Set up the args. |
1502 | - $element_type = trim( $element['type'] ); |
|
1502 | + $element_type = trim($element['type']); |
|
1503 | 1503 | $element['form'] = $form; |
1504 | - extract( $element ); |
|
1504 | + extract($element); |
|
1505 | 1505 | |
1506 | 1506 | // Try to locate the appropriate template. |
1507 | - $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" ); |
|
1507 | + $located = wpinv_locate_template("payment-forms/elements/$element_type.php"); |
|
1508 | 1508 | |
1509 | 1509 | // Abort if this is not our element. |
1510 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1510 | + if (empty($located) || !file_exists($located)) { |
|
1511 | 1511 | return; |
1512 | 1512 | } |
1513 | 1513 | |
1514 | 1514 | // Generate the class and id of the element. |
1515 | - $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) ); |
|
1516 | - $id = isset( $id ) ? $id : uniqid( 'gp' ); |
|
1515 | + $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type)); |
|
1516 | + $id = isset($id) ? $id : uniqid('gp'); |
|
1517 | 1517 | |
1518 | 1518 | // Echo the opening wrapper. |
1519 | 1519 | echo "<div class='getpaid-payment-form-element $wrapper_class'>"; |
1520 | 1520 | |
1521 | 1521 | // Fires before displaying a given element type's content. |
1522 | - do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form ); |
|
1522 | + do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form); |
|
1523 | 1523 | |
1524 | 1524 | // Include the template for the element. |
1525 | 1525 | include $located; |
1526 | 1526 | |
1527 | 1527 | // Fires after displaying a given element type's content. |
1528 | - do_action( "getpaid_payment_form_{$element_type}_element", $element, $form ); |
|
1528 | + do_action("getpaid_payment_form_{$element_type}_element", $element, $form); |
|
1529 | 1529 | |
1530 | 1530 | // Echo the closing wrapper. |
1531 | 1531 | echo '</div>'; |
1532 | 1532 | } |
1533 | -add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 ); |
|
1533 | +add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2); |
|
1534 | 1534 | |
1535 | 1535 | /** |
1536 | 1536 | * Render an element's edit page. |
1537 | 1537 | * |
1538 | 1538 | * @param WP_Post $post |
1539 | 1539 | */ |
1540 | -function getpaid_payment_form_edit_element_template( $post ) { |
|
1540 | +function getpaid_payment_form_edit_element_template($post) { |
|
1541 | 1541 | |
1542 | 1542 | // Retrieve all elements. |
1543 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1543 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1544 | 1544 | |
1545 | - foreach ( $all_elements as $element ) { |
|
1545 | + foreach ($all_elements as $element) { |
|
1546 | 1546 | |
1547 | 1547 | // Try to locate the appropriate template. |
1548 | - $element = sanitize_key( $element ); |
|
1549 | - $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" ); |
|
1548 | + $element = sanitize_key($element); |
|
1549 | + $located = wpinv_locate_template("payment-forms-admin/edit/$element.php"); |
|
1550 | 1550 | |
1551 | 1551 | // Continue if this is not our element. |
1552 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1552 | + if (empty($located) || !file_exists($located)) { |
|
1553 | 1553 | continue; |
1554 | 1554 | } |
1555 | 1555 | |
@@ -1560,7 +1560,7 @@ discard block |
||
1560 | 1560 | } |
1561 | 1561 | |
1562 | 1562 | } |
1563 | -add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' ); |
|
1563 | +add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template'); |
|
1564 | 1564 | |
1565 | 1565 | /** |
1566 | 1566 | * Render an element's preview. |
@@ -1569,16 +1569,16 @@ discard block |
||
1569 | 1569 | function getpaid_payment_form_render_element_preview_template() { |
1570 | 1570 | |
1571 | 1571 | // Retrieve all elements. |
1572 | - $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' ); |
|
1572 | + $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type'); |
|
1573 | 1573 | |
1574 | - foreach ( $all_elements as $element ) { |
|
1574 | + foreach ($all_elements as $element) { |
|
1575 | 1575 | |
1576 | 1576 | // Try to locate the appropriate template. |
1577 | - $element = sanitize_key( $element ); |
|
1578 | - $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" ); |
|
1577 | + $element = sanitize_key($element); |
|
1578 | + $located = wpinv_locate_template("payment-forms-admin/previews/$element.php"); |
|
1579 | 1579 | |
1580 | 1580 | // Continue if this is not our element. |
1581 | - if ( empty( $located ) || ! file_exists( $located ) ) { |
|
1581 | + if (empty($located) || !file_exists($located)) { |
|
1582 | 1582 | continue; |
1583 | 1583 | } |
1584 | 1584 | |
@@ -1589,7 +1589,7 @@ discard block |
||
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | } |
1592 | -add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' ); |
|
1592 | +add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template'); |
|
1593 | 1593 | |
1594 | 1594 | /** |
1595 | 1595 | * Shows a list of gateways that support recurring payments. |
@@ -1597,17 +1597,17 @@ discard block |
||
1597 | 1597 | function wpinv_get_recurring_gateways_text() { |
1598 | 1598 | $gateways = array(); |
1599 | 1599 | |
1600 | - foreach ( wpinv_get_payment_gateways() as $key => $gateway ) { |
|
1601 | - if ( wpinv_gateway_support_subscription( $key ) ) { |
|
1602 | - $gateways[] = sanitize_text_field( $gateway['admin_label'] ); |
|
1600 | + foreach (wpinv_get_payment_gateways() as $key => $gateway) { |
|
1601 | + if (wpinv_gateway_support_subscription($key)) { |
|
1602 | + $gateways[] = sanitize_text_field($gateway['admin_label']); |
|
1603 | 1603 | } |
1604 | 1604 | } |
1605 | 1605 | |
1606 | - if ( empty( $gateways ) ) { |
|
1607 | - return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>"; |
|
1606 | + if (empty($gateways)) { |
|
1607 | + return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>"; |
|
1608 | 1608 | } |
1609 | 1609 | |
1610 | - return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>"; |
|
1610 | + return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>"; |
|
1611 | 1611 | |
1612 | 1612 | } |
1613 | 1613 | |
@@ -1617,7 +1617,7 @@ discard block |
||
1617 | 1617 | * @return GetPaid_Template |
1618 | 1618 | */ |
1619 | 1619 | function getpaid_template() { |
1620 | - return getpaid()->get( 'template' ); |
|
1620 | + return getpaid()->get('template'); |
|
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | /** |
@@ -1626,23 +1626,23 @@ discard block |
||
1626 | 1626 | * @param array args |
1627 | 1627 | * @return string |
1628 | 1628 | */ |
1629 | -function getpaid_paginate_links( $args ) { |
|
1629 | +function getpaid_paginate_links($args) { |
|
1630 | 1630 | |
1631 | 1631 | $args['type'] = 'array'; |
1632 | 1632 | $args['mid_size'] = 1; |
1633 | - $pages = paginate_links( $args ); |
|
1633 | + $pages = paginate_links($args); |
|
1634 | 1634 | |
1635 | - if ( ! is_array( $pages ) ) { |
|
1635 | + if (!is_array($pages)) { |
|
1636 | 1636 | return ''; |
1637 | 1637 | } |
1638 | 1638 | |
1639 | 1639 | $_pages = array(); |
1640 | - foreach ( $pages as $page ) { |
|
1641 | - $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page ); |
|
1640 | + foreach ($pages as $page) { |
|
1641 | + $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page); |
|
1642 | 1642 | } |
1643 | 1643 | |
1644 | 1644 | $links = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>"; |
1645 | - $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages ); |
|
1645 | + $links .= join("</li>\n\t\t<li class='page-item'>", $_pages); |
|
1646 | 1646 | $links .= "</li>\n\t</ul>\n</nav>\n"; |
1647 | 1647 | |
1648 | 1648 | return $links; |
@@ -10,52 +10,52 @@ discard block |
||
10 | 10 | * @var array $columns |
11 | 11 | */ |
12 | 12 | |
13 | -defined( 'ABSPATH' ) || exit; |
|
13 | +defined('ABSPATH') || exit; |
|
14 | 14 | |
15 | -do_action( 'getpaid_before_invoice_line_item', $invoice, $item ); |
|
15 | +do_action('getpaid_before_invoice_line_item', $invoice, $item); |
|
16 | 16 | |
17 | 17 | ?> |
18 | 18 | |
19 | -<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class( $item->get_type() ); ?> border-bottom'> |
|
19 | +<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class($item->get_type()); ?> border-bottom'> |
|
20 | 20 | |
21 | 21 | <div class="form-row"> |
22 | 22 | |
23 | - <?php foreach ( array_keys( $columns ) as $column ): ?> |
|
23 | + <?php foreach (array_keys($columns) as $column): ?> |
|
24 | 24 | |
25 | - <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class( $column ); ?>"> |
|
25 | + <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class($column); ?>"> |
|
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | 29 | // Fires before printing a line item column. |
30 | - do_action( "getpaid_invoice_line_item_before_$column", $item, $invoice ); |
|
30 | + do_action("getpaid_invoice_line_item_before_$column", $item, $invoice); |
|
31 | 31 | |
32 | 32 | // Item name. |
33 | - if ( 'name' == $column ) { |
|
33 | + if ('name' == $column) { |
|
34 | 34 | |
35 | 35 | // Display the name. |
36 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
36 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
37 | 37 | |
38 | 38 | // And an optional description. |
39 | 39 | $description = $item->get_description(); |
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - $description = wp_kses_post( $description ); |
|
41 | + if (!empty($description)) { |
|
42 | + $description = wp_kses_post($description); |
|
43 | 43 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
44 | 44 | } |
45 | 45 | |
46 | - $actions = apply_filters( 'getpaid-invoice-page-line-item-actions', array(), $item, $invoice ); |
|
46 | + $actions = apply_filters('getpaid-invoice-page-line-item-actions', array(), $item, $invoice); |
|
47 | 47 | |
48 | - if ( ! empty( $actions ) ) { |
|
48 | + if (!empty($actions)) { |
|
49 | 49 | |
50 | - $sanitized = array(); |
|
51 | - foreach ( $actions as $key => $action ) { |
|
52 | - $key = sanitize_html_class( $key ); |
|
53 | - $action = wp_kses_post( $action ); |
|
50 | + $sanitized = array(); |
|
51 | + foreach ($actions as $key => $action) { |
|
52 | + $key = sanitize_html_class($key); |
|
53 | + $action = wp_kses_post($action); |
|
54 | 54 | $sanitized[] = "<span class='$key'>$action</span>"; |
55 | 55 | } |
56 | 56 | |
57 | 57 | echo "<small class='form-text getpaid-line-item-actions'>"; |
58 | - echo implode( ' | ', $sanitized ); |
|
58 | + echo implode(' | ', $sanitized); |
|
59 | 59 | echo '</small>'; |
60 | 60 | |
61 | 61 | } |
@@ -63,30 +63,30 @@ discard block |
||
63 | 63 | } |
64 | 64 | |
65 | 65 | // Item price. |
66 | - if ( 'price' == $column ) { |
|
66 | + if ('price' == $column) { |
|
67 | 67 | |
68 | 68 | // Display the item price (or recurring price if this is a renewal invoice) |
69 | 69 | $price = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price(); |
70 | - echo wpinv_price( $price ); |
|
70 | + echo wpinv_price($price); |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | |
74 | 74 | // Item quantity. |
75 | - if ( 'quantity' == $column ) { |
|
75 | + if ('quantity' == $column) { |
|
76 | 76 | echo (int) $item->get_quantity(); |
77 | 77 | } |
78 | 78 | |
79 | 79 | // Item sub total. |
80 | - if ( 'subtotal' == $column ) { |
|
80 | + if ('subtotal' == $column) { |
|
81 | 81 | $subtotal = $invoice->is_renewal() ? $item->get_recurring_sub_total() : $item->get_sub_total(); |
82 | - echo wpinv_price( $subtotal ); |
|
82 | + echo wpinv_price($subtotal); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | // Fires when printing a line item column. |
86 | - do_action( "getpaid_invoice_line_item_$column", $item, $invoice ); |
|
86 | + do_action("getpaid_invoice_line_item_$column", $item, $invoice); |
|
87 | 87 | |
88 | 88 | // Fires after printing a line item column. |
89 | - do_action( "getpaid_invoice_line_item_after_$column", $item, $invoice ); |
|
89 | + do_action("getpaid_invoice_line_item_after_$column", $item, $invoice); |
|
90 | 90 | |
91 | 91 | ?> |
92 | 92 |