@@ -11,30 +11,30 @@ discard block |
||
11 | 11 | class WPInv_Invoice extends GetPaid_Data { |
12 | 12 | |
13 | 13 | /** |
14 | - * Which data store to load. |
|
15 | - * |
|
16 | - * @var string |
|
17 | - */ |
|
14 | + * Which data store to load. |
|
15 | + * |
|
16 | + * @var string |
|
17 | + */ |
|
18 | 18 | protected $data_store_name = 'invoice'; |
19 | 19 | |
20 | 20 | /** |
21 | - * This is the name of this object type. |
|
22 | - * |
|
23 | - * @var string |
|
24 | - */ |
|
21 | + * This is the name of this object type. |
|
22 | + * |
|
23 | + * @var string |
|
24 | + */ |
|
25 | 25 | protected $object_type = 'invoice'; |
26 | 26 | |
27 | 27 | /** |
28 | - * Item Data array. This is the core item data exposed in APIs. |
|
29 | - * |
|
30 | - * @since 1.0.19 |
|
31 | - * @var array |
|
32 | - */ |
|
33 | - protected $data = array( |
|
34 | - 'parent_id' => 0, |
|
35 | - 'status' => 'wpi-pending', |
|
36 | - 'version' => '', |
|
37 | - 'date_created' => null, |
|
28 | + * Item Data array. This is the core item data exposed in APIs. |
|
29 | + * |
|
30 | + * @since 1.0.19 |
|
31 | + * @var array |
|
32 | + */ |
|
33 | + protected $data = array( |
|
34 | + 'parent_id' => 0, |
|
35 | + 'status' => 'wpi-pending', |
|
36 | + 'version' => '', |
|
37 | + 'date_created' => null, |
|
38 | 38 | 'date_modified' => null, |
39 | 39 | 'due_date' => null, |
40 | 40 | 'completed_date' => null, |
@@ -79,13 +79,13 @@ discard block |
||
79 | 79 | // user_info, payment_meta, cart_details, full_name |
80 | 80 | |
81 | 81 | /** |
82 | - * Stores meta in cache for future reads. |
|
83 | - * |
|
84 | - * A group must be set to to enable caching. |
|
85 | - * |
|
86 | - * @var string |
|
87 | - */ |
|
88 | - protected $cache_group = 'getpaid_invoices'; |
|
82 | + * Stores meta in cache for future reads. |
|
83 | + * |
|
84 | + * A group must be set to to enable caching. |
|
85 | + * |
|
86 | + * @var string |
|
87 | + */ |
|
88 | + protected $cache_group = 'getpaid_invoices'; |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * Stores a reference to the original WP_Post object |
@@ -95,74 +95,74 @@ discard block |
||
95 | 95 | protected $post = null; |
96 | 96 | |
97 | 97 | /** |
98 | - * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
99 | - * |
|
100 | - * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
|
101 | - */ |
|
98 | + * Get the invoice if ID is passed, otherwise the invoice is new and empty. |
|
99 | + * |
|
100 | + * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
|
101 | + */ |
|
102 | 102 | public function __construct( $invoice = false ) { |
103 | 103 | |
104 | 104 | parent::__construct( $invoice ); |
105 | 105 | |
106 | - if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
107 | - $this->set_id( $invoice ); |
|
108 | - } elseif ( $invoice instanceof self ) { |
|
109 | - $this->set_id( $invoice->get_id() ); |
|
110 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
111 | - $this->set_id( $invoice->ID ); |
|
112 | - } elseif ( is_array( $invoice ) ) { |
|
113 | - $this->set_props( $invoice ); |
|
114 | - |
|
115 | - if ( isset( $invoice['ID'] ) ) { |
|
116 | - $this->set_id( $invoice['ID'] ); |
|
117 | - } |
|
118 | - |
|
119 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
120 | - $this->set_id( $invoice_id ); |
|
121 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
122 | - $this->set_id( $invoice_id ); |
|
123 | - } else { |
|
124 | - $this->set_object_read( true ); |
|
125 | - } |
|
106 | + if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
107 | + $this->set_id( $invoice ); |
|
108 | + } elseif ( $invoice instanceof self ) { |
|
109 | + $this->set_id( $invoice->get_id() ); |
|
110 | + } elseif ( ! empty( $invoice->ID ) ) { |
|
111 | + $this->set_id( $invoice->ID ); |
|
112 | + } elseif ( is_array( $invoice ) ) { |
|
113 | + $this->set_props( $invoice ); |
|
114 | + |
|
115 | + if ( isset( $invoice['ID'] ) ) { |
|
116 | + $this->set_id( $invoice['ID'] ); |
|
117 | + } |
|
118 | + |
|
119 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
120 | + $this->set_id( $invoice_id ); |
|
121 | + } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
122 | + $this->set_id( $invoice_id ); |
|
123 | + } else { |
|
124 | + $this->set_object_read( true ); |
|
125 | + } |
|
126 | 126 | |
127 | 127 | // Load the datastore. |
128 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
128 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
129 | 129 | |
130 | - if ( $this->get_id() > 0 ) { |
|
130 | + if ( $this->get_id() > 0 ) { |
|
131 | 131 | $this->post = get_post( $this->get_id() ); |
132 | 132 | $this->ID = $this->get_id(); |
133 | - $this->data_store->read( $this ); |
|
133 | + $this->data_store->read( $this ); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
139 | - * Given a discount code, it returns a discount id. |
|
140 | - * |
|
141 | - * |
|
142 | - * @static |
|
143 | - * @param string $discount_code |
|
144 | - * @since 1.0.15 |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
139 | + * Given a discount code, it returns a discount id. |
|
140 | + * |
|
141 | + * |
|
142 | + * @static |
|
143 | + * @param string $discount_code |
|
144 | + * @since 1.0.15 |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
148 | 148 | global $wpdb; |
149 | 149 | |
150 | - // Trim the code. |
|
150 | + // Trim the code. |
|
151 | 151 | $key = trim( $invoice_key_or_number ); |
152 | 152 | |
153 | 153 | // Valid fields. |
154 | 154 | $fields = array( 'key', 'number' ); |
155 | 155 | |
156 | - // Ensure a value has been passed. |
|
157 | - if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
158 | - return 0; |
|
159 | - } |
|
156 | + // Ensure a value has been passed. |
|
157 | + if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
158 | + return 0; |
|
159 | + } |
|
160 | 160 | |
161 | - // Maybe retrieve from the cache. |
|
162 | - $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
163 | - if ( ! empty( $invoice_id ) ) { |
|
164 | - return $invoice_id; |
|
165 | - } |
|
161 | + // Maybe retrieve from the cache. |
|
162 | + $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
163 | + if ( ! empty( $invoice_id ) ) { |
|
164 | + return $invoice_id; |
|
165 | + } |
|
166 | 166 | |
167 | 167 | // Fetch from the db. |
168 | 168 | $table = $wpdb->prefix . 'getpaid_invoices'; |
@@ -170,14 +170,14 @@ discard block |
||
170 | 170 | $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key ) |
171 | 171 | ); |
172 | 172 | |
173 | - if ( empty( $invoice_id ) ) { |
|
174 | - return 0; |
|
175 | - } |
|
173 | + if ( empty( $invoice_id ) ) { |
|
174 | + return 0; |
|
175 | + } |
|
176 | 176 | |
177 | - // Update the cache with our data |
|
178 | - wp_cache_add( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
177 | + // Update the cache with our data |
|
178 | + wp_cache_add( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
179 | 179 | |
180 | - return $invoice_id; |
|
180 | + return $invoice_id; |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /* |
@@ -196,198 +196,198 @@ discard block |
||
196 | 196 | */ |
197 | 197 | |
198 | 198 | /** |
199 | - * Get parent invoice ID. |
|
200 | - * |
|
201 | - * @since 1.0.19 |
|
202 | - * @param string $context View or edit context. |
|
203 | - * @return int |
|
204 | - */ |
|
205 | - public function get_parent_id( $context = 'view' ) { |
|
206 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
199 | + * Get parent invoice ID. |
|
200 | + * |
|
201 | + * @since 1.0.19 |
|
202 | + * @param string $context View or edit context. |
|
203 | + * @return int |
|
204 | + */ |
|
205 | + public function get_parent_id( $context = 'view' ) { |
|
206 | + return (int) $this->get_prop( 'parent_id', $context ); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * Get invoice status. |
|
211 | - * |
|
212 | - * @since 1.0.19 |
|
213 | - * @param string $context View or edit context. |
|
214 | - * @return string |
|
215 | - */ |
|
216 | - public function get_status( $context = 'view' ) { |
|
217 | - return $this->get_prop( 'status', $context ); |
|
210 | + * Get invoice status. |
|
211 | + * |
|
212 | + * @since 1.0.19 |
|
213 | + * @param string $context View or edit context. |
|
214 | + * @return string |
|
215 | + */ |
|
216 | + public function get_status( $context = 'view' ) { |
|
217 | + return $this->get_prop( 'status', $context ); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
221 | - * Get plugin version when the invoice was created. |
|
222 | - * |
|
223 | - * @since 1.0.19 |
|
224 | - * @param string $context View or edit context. |
|
225 | - * @return string |
|
226 | - */ |
|
227 | - public function get_version( $context = 'view' ) { |
|
228 | - return $this->get_prop( 'version', $context ); |
|
221 | + * Get plugin version when the invoice was created. |
|
222 | + * |
|
223 | + * @since 1.0.19 |
|
224 | + * @param string $context View or edit context. |
|
225 | + * @return string |
|
226 | + */ |
|
227 | + public function get_version( $context = 'view' ) { |
|
228 | + return $this->get_prop( 'version', $context ); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
232 | - * Get date when the invoice was created. |
|
233 | - * |
|
234 | - * @since 1.0.19 |
|
235 | - * @param string $context View or edit context. |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - public function get_date_created( $context = 'view' ) { |
|
239 | - return $this->get_prop( 'date_created', $context ); |
|
232 | + * Get date when the invoice was created. |
|
233 | + * |
|
234 | + * @since 1.0.19 |
|
235 | + * @param string $context View or edit context. |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + public function get_date_created( $context = 'view' ) { |
|
239 | + return $this->get_prop( 'date_created', $context ); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
243 | - * Get GMT date when the invoice was created. |
|
244 | - * |
|
245 | - * @since 1.0.19 |
|
246 | - * @param string $context View or edit context. |
|
247 | - * @return string |
|
248 | - */ |
|
249 | - public function get_date_created_gmt( $context = 'view' ) { |
|
243 | + * Get GMT date when the invoice was created. |
|
244 | + * |
|
245 | + * @since 1.0.19 |
|
246 | + * @param string $context View or edit context. |
|
247 | + * @return string |
|
248 | + */ |
|
249 | + public function get_date_created_gmt( $context = 'view' ) { |
|
250 | 250 | $date = $this->get_date_created( $context ); |
251 | 251 | |
252 | 252 | if ( $date ) { |
253 | 253 | $date = get_gmt_from_date( $date ); |
254 | 254 | } |
255 | - return $date; |
|
255 | + return $date; |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | /** |
259 | - * Get date when the invoice was last modified. |
|
260 | - * |
|
261 | - * @since 1.0.19 |
|
262 | - * @param string $context View or edit context. |
|
263 | - * @return string |
|
264 | - */ |
|
265 | - public function get_date_modified( $context = 'view' ) { |
|
266 | - return $this->get_prop( 'date_modified', $context ); |
|
259 | + * Get date when the invoice was last modified. |
|
260 | + * |
|
261 | + * @since 1.0.19 |
|
262 | + * @param string $context View or edit context. |
|
263 | + * @return string |
|
264 | + */ |
|
265 | + public function get_date_modified( $context = 'view' ) { |
|
266 | + return $this->get_prop( 'date_modified', $context ); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
270 | - * Get GMT date when the invoice was last modified. |
|
271 | - * |
|
272 | - * @since 1.0.19 |
|
273 | - * @param string $context View or edit context. |
|
274 | - * @return string |
|
275 | - */ |
|
276 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
270 | + * Get GMT date when the invoice was last modified. |
|
271 | + * |
|
272 | + * @since 1.0.19 |
|
273 | + * @param string $context View or edit context. |
|
274 | + * @return string |
|
275 | + */ |
|
276 | + public function get_date_modified_gmt( $context = 'view' ) { |
|
277 | 277 | $date = $this->get_date_modified( $context ); |
278 | 278 | |
279 | 279 | if ( $date ) { |
280 | 280 | $date = get_gmt_from_date( $date ); |
281 | 281 | } |
282 | - return $date; |
|
282 | + return $date; |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Get the invoice due date. |
|
287 | - * |
|
288 | - * @since 1.0.19 |
|
289 | - * @param string $context View or edit context. |
|
290 | - * @return string |
|
291 | - */ |
|
292 | - public function get_due_date( $context = 'view' ) { |
|
293 | - return $this->get_prop( 'due_date', $context ); |
|
286 | + * Get the invoice due date. |
|
287 | + * |
|
288 | + * @since 1.0.19 |
|
289 | + * @param string $context View or edit context. |
|
290 | + * @return string |
|
291 | + */ |
|
292 | + public function get_due_date( $context = 'view' ) { |
|
293 | + return $this->get_prop( 'due_date', $context ); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
297 | - * Alias for self::get_due_date(). |
|
298 | - * |
|
299 | - * @since 1.0.19 |
|
300 | - * @param string $context View or edit context. |
|
301 | - * @return string |
|
302 | - */ |
|
303 | - public function get_date_due( $context = 'view' ) { |
|
304 | - return $this->get_due_date( $context ); |
|
297 | + * Alias for self::get_due_date(). |
|
298 | + * |
|
299 | + * @since 1.0.19 |
|
300 | + * @param string $context View or edit context. |
|
301 | + * @return string |
|
302 | + */ |
|
303 | + public function get_date_due( $context = 'view' ) { |
|
304 | + return $this->get_due_date( $context ); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
308 | - * Get the invoice GMT due date. |
|
309 | - * |
|
310 | - * @since 1.0.19 |
|
311 | - * @param string $context View or edit context. |
|
312 | - * @return string |
|
313 | - */ |
|
314 | - public function get_due_date_gmt( $context = 'view' ) { |
|
308 | + * Get the invoice GMT due date. |
|
309 | + * |
|
310 | + * @since 1.0.19 |
|
311 | + * @param string $context View or edit context. |
|
312 | + * @return string |
|
313 | + */ |
|
314 | + public function get_due_date_gmt( $context = 'view' ) { |
|
315 | 315 | $date = $this->get_due_date( $context ); |
316 | 316 | |
317 | 317 | if ( $date ) { |
318 | 318 | $date = get_gmt_from_date( $date ); |
319 | 319 | } |
320 | - return $date; |
|
320 | + return $date; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
324 | - * Alias for self::get_due_date_gmt(). |
|
325 | - * |
|
326 | - * @since 1.0.19 |
|
327 | - * @param string $context View or edit context. |
|
328 | - * @return string |
|
329 | - */ |
|
330 | - public function get_gmt_date_due( $context = 'view' ) { |
|
331 | - return $this->get_due_date_gmt( $context ); |
|
324 | + * Alias for self::get_due_date_gmt(). |
|
325 | + * |
|
326 | + * @since 1.0.19 |
|
327 | + * @param string $context View or edit context. |
|
328 | + * @return string |
|
329 | + */ |
|
330 | + public function get_gmt_date_due( $context = 'view' ) { |
|
331 | + return $this->get_due_date_gmt( $context ); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | - * Get date when the invoice was completed. |
|
336 | - * |
|
337 | - * @since 1.0.19 |
|
338 | - * @param string $context View or edit context. |
|
339 | - * @return string |
|
340 | - */ |
|
341 | - public function get_completed_date( $context = 'view' ) { |
|
342 | - return $this->get_prop( 'completed_date', $context ); |
|
335 | + * Get date when the invoice was completed. |
|
336 | + * |
|
337 | + * @since 1.0.19 |
|
338 | + * @param string $context View or edit context. |
|
339 | + * @return string |
|
340 | + */ |
|
341 | + public function get_completed_date( $context = 'view' ) { |
|
342 | + return $this->get_prop( 'completed_date', $context ); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
346 | - * Alias for self::get_completed_date(). |
|
347 | - * |
|
348 | - * @since 1.0.19 |
|
349 | - * @param string $context View or edit context. |
|
350 | - * @return string |
|
351 | - */ |
|
352 | - public function get_date_completed( $context = 'view' ) { |
|
353 | - return $this->get_completed_date( $context ); |
|
346 | + * Alias for self::get_completed_date(). |
|
347 | + * |
|
348 | + * @since 1.0.19 |
|
349 | + * @param string $context View or edit context. |
|
350 | + * @return string |
|
351 | + */ |
|
352 | + public function get_date_completed( $context = 'view' ) { |
|
353 | + return $this->get_completed_date( $context ); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
357 | - * Get GMT date when the invoice was was completed. |
|
358 | - * |
|
359 | - * @since 1.0.19 |
|
360 | - * @param string $context View or edit context. |
|
361 | - * @return string |
|
362 | - */ |
|
363 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
357 | + * Get GMT date when the invoice was was completed. |
|
358 | + * |
|
359 | + * @since 1.0.19 |
|
360 | + * @param string $context View or edit context. |
|
361 | + * @return string |
|
362 | + */ |
|
363 | + public function get_completed_date_gmt( $context = 'view' ) { |
|
364 | 364 | $date = $this->get_completed_date( $context ); |
365 | 365 | |
366 | 366 | if ( $date ) { |
367 | 367 | $date = get_gmt_from_date( $date ); |
368 | 368 | } |
369 | - return $date; |
|
369 | + return $date; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | /** |
373 | - * Alias for self::get_completed_date_gmt(). |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $context View or edit context. |
|
377 | - * @return string |
|
378 | - */ |
|
379 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
380 | - return $this->get_completed_date_gmt( $context ); |
|
373 | + * Alias for self::get_completed_date_gmt(). |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $context View or edit context. |
|
377 | + * @return string |
|
378 | + */ |
|
379 | + public function get_gmt_completed_date( $context = 'view' ) { |
|
380 | + return $this->get_completed_date_gmt( $context ); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
384 | - * Get the invoice number. |
|
385 | - * |
|
386 | - * @since 1.0.19 |
|
387 | - * @param string $context View or edit context. |
|
388 | - * @return string |
|
389 | - */ |
|
390 | - public function get_number( $context = 'view' ) { |
|
384 | + * Get the invoice number. |
|
385 | + * |
|
386 | + * @since 1.0.19 |
|
387 | + * @param string $context View or edit context. |
|
388 | + * @return string |
|
389 | + */ |
|
390 | + public function get_number( $context = 'view' ) { |
|
391 | 391 | $number = $this->get_prop( 'number', $context ); |
392 | 392 | |
393 | 393 | if ( empty( $number ) ) { |
@@ -395,17 +395,17 @@ discard block |
||
395 | 395 | $this->set_number( $number ); |
396 | 396 | } |
397 | 397 | |
398 | - return $number; |
|
398 | + return $number; |
|
399 | 399 | } |
400 | 400 | |
401 | 401 | /** |
402 | - * Get the invoice key. |
|
403 | - * |
|
404 | - * @since 1.0.19 |
|
405 | - * @param string $context View or edit context. |
|
406 | - * @return string |
|
407 | - */ |
|
408 | - public function get_key( $context = 'view' ) { |
|
402 | + * Get the invoice key. |
|
403 | + * |
|
404 | + * @since 1.0.19 |
|
405 | + * @param string $context View or edit context. |
|
406 | + * @return string |
|
407 | + */ |
|
408 | + public function get_key( $context = 'view' ) { |
|
409 | 409 | $key = $this->get_prop( 'key', $context ); |
410 | 410 | |
411 | 411 | if ( empty( $key ) ) { |
@@ -413,814 +413,814 @@ discard block |
||
413 | 413 | $this->set_key( $key ); |
414 | 414 | } |
415 | 415 | |
416 | - return $key; |
|
416 | + return $key; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
420 | - * Get the invoice type. |
|
421 | - * |
|
422 | - * @since 1.0.19 |
|
423 | - * @param string $context View or edit context. |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public function get_type( $context = 'view' ) { |
|
420 | + * Get the invoice type. |
|
421 | + * |
|
422 | + * @since 1.0.19 |
|
423 | + * @param string $context View or edit context. |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public function get_type( $context = 'view' ) { |
|
427 | 427 | return $this->get_prop( 'type', $context ); |
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
431 | - * Get the invoice mode. |
|
432 | - * |
|
433 | - * @since 1.0.19 |
|
434 | - * @param string $context View or edit context. |
|
435 | - * @return string |
|
436 | - */ |
|
437 | - public function get_mode( $context = 'view' ) { |
|
431 | + * Get the invoice mode. |
|
432 | + * |
|
433 | + * @since 1.0.19 |
|
434 | + * @param string $context View or edit context. |
|
435 | + * @return string |
|
436 | + */ |
|
437 | + public function get_mode( $context = 'view' ) { |
|
438 | 438 | return $this->get_prop( 'mode', $context ); |
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
442 | - * Get the invoice name/title. |
|
443 | - * |
|
444 | - * @since 1.0.19 |
|
445 | - * @param string $context View or edit context. |
|
446 | - * @return string |
|
447 | - */ |
|
448 | - public function get_name( $context = 'view' ) { |
|
442 | + * Get the invoice name/title. |
|
443 | + * |
|
444 | + * @since 1.0.19 |
|
445 | + * @param string $context View or edit context. |
|
446 | + * @return string |
|
447 | + */ |
|
448 | + public function get_name( $context = 'view' ) { |
|
449 | 449 | $name = $this->get_prop( 'title', $context ); |
450 | 450 | |
451 | - return empty( $name ) ? $this->get_number( $context ) : $name; |
|
451 | + return empty( $name ) ? $this->get_number( $context ) : $name; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
455 | - * Alias of self::get_name(). |
|
456 | - * |
|
457 | - * @since 1.0.19 |
|
458 | - * @param string $context View or edit context. |
|
459 | - * @return string |
|
460 | - */ |
|
461 | - public function get_title( $context = 'view' ) { |
|
462 | - return $this->get_name( $context ); |
|
455 | + * Alias of self::get_name(). |
|
456 | + * |
|
457 | + * @since 1.0.19 |
|
458 | + * @param string $context View or edit context. |
|
459 | + * @return string |
|
460 | + */ |
|
461 | + public function get_title( $context = 'view' ) { |
|
462 | + return $this->get_name( $context ); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
466 | - * Get the invoice description. |
|
467 | - * |
|
468 | - * @since 1.0.19 |
|
469 | - * @param string $context View or edit context. |
|
470 | - * @return string |
|
471 | - */ |
|
472 | - public function get_description( $context = 'view' ) { |
|
473 | - return $this->get_prop( 'description', $context ); |
|
466 | + * Get the invoice description. |
|
467 | + * |
|
468 | + * @since 1.0.19 |
|
469 | + * @param string $context View or edit context. |
|
470 | + * @return string |
|
471 | + */ |
|
472 | + public function get_description( $context = 'view' ) { |
|
473 | + return $this->get_prop( 'description', $context ); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Alias of self::get_description(). |
|
478 | - * |
|
479 | - * @since 1.0.19 |
|
480 | - * @param string $context View or edit context. |
|
481 | - * @return string |
|
482 | - */ |
|
483 | - public function get_excerpt( $context = 'view' ) { |
|
484 | - return $this->get_description( $context ); |
|
477 | + * Alias of self::get_description(). |
|
478 | + * |
|
479 | + * @since 1.0.19 |
|
480 | + * @param string $context View or edit context. |
|
481 | + * @return string |
|
482 | + */ |
|
483 | + public function get_excerpt( $context = 'view' ) { |
|
484 | + return $this->get_description( $context ); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
488 | - * Alias of self::get_description(). |
|
489 | - * |
|
490 | - * @since 1.0.19 |
|
491 | - * @param string $context View or edit context. |
|
492 | - * @return string |
|
493 | - */ |
|
494 | - public function get_summary( $context = 'view' ) { |
|
495 | - return $this->get_description( $context ); |
|
488 | + * Alias of self::get_description(). |
|
489 | + * |
|
490 | + * @since 1.0.19 |
|
491 | + * @param string $context View or edit context. |
|
492 | + * @return string |
|
493 | + */ |
|
494 | + public function get_summary( $context = 'view' ) { |
|
495 | + return $this->get_description( $context ); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
499 | - * Get the customer id. |
|
500 | - * |
|
501 | - * @since 1.0.19 |
|
502 | - * @param string $context View or edit context. |
|
503 | - * @return int |
|
504 | - */ |
|
505 | - public function get_author( $context = 'view' ) { |
|
506 | - return (int) $this->get_prop( 'author', $context ); |
|
499 | + * Get the customer id. |
|
500 | + * |
|
501 | + * @since 1.0.19 |
|
502 | + * @param string $context View or edit context. |
|
503 | + * @return int |
|
504 | + */ |
|
505 | + public function get_author( $context = 'view' ) { |
|
506 | + return (int) $this->get_prop( 'author', $context ); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
510 | - * Alias of self::get_author(). |
|
511 | - * |
|
512 | - * @since 1.0.19 |
|
513 | - * @param string $context View or edit context. |
|
514 | - * @return int |
|
515 | - */ |
|
516 | - public function get_user_id( $context = 'view' ) { |
|
517 | - return $this->get_author( $context ); |
|
510 | + * Alias of self::get_author(). |
|
511 | + * |
|
512 | + * @since 1.0.19 |
|
513 | + * @param string $context View or edit context. |
|
514 | + * @return int |
|
515 | + */ |
|
516 | + public function get_user_id( $context = 'view' ) { |
|
517 | + return $this->get_author( $context ); |
|
518 | 518 | } |
519 | 519 | |
520 | - /** |
|
521 | - * Alias of self::get_author(). |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - * @param string $context View or edit context. |
|
525 | - * @return int |
|
526 | - */ |
|
527 | - public function get_customer_id( $context = 'view' ) { |
|
528 | - return $this->get_author( $context ); |
|
520 | + /** |
|
521 | + * Alias of self::get_author(). |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + * @param string $context View or edit context. |
|
525 | + * @return int |
|
526 | + */ |
|
527 | + public function get_customer_id( $context = 'view' ) { |
|
528 | + return $this->get_author( $context ); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
532 | - * Get the customer's ip. |
|
533 | - * |
|
534 | - * @since 1.0.19 |
|
535 | - * @param string $context View or edit context. |
|
536 | - * @return string |
|
537 | - */ |
|
538 | - public function get_ip( $context = 'view' ) { |
|
539 | - return $this->get_prop( 'user_ip', $context ); |
|
532 | + * Get the customer's ip. |
|
533 | + * |
|
534 | + * @since 1.0.19 |
|
535 | + * @param string $context View or edit context. |
|
536 | + * @return string |
|
537 | + */ |
|
538 | + public function get_ip( $context = 'view' ) { |
|
539 | + return $this->get_prop( 'user_ip', $context ); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
543 | - * Alias of self::get_ip(). |
|
544 | - * |
|
545 | - * @since 1.0.19 |
|
546 | - * @param string $context View or edit context. |
|
547 | - * @return int |
|
548 | - */ |
|
549 | - public function get_user_ip( $context = 'view' ) { |
|
550 | - return $this->get_ip( $context ); |
|
543 | + * Alias of self::get_ip(). |
|
544 | + * |
|
545 | + * @since 1.0.19 |
|
546 | + * @param string $context View or edit context. |
|
547 | + * @return int |
|
548 | + */ |
|
549 | + public function get_user_ip( $context = 'view' ) { |
|
550 | + return $this->get_ip( $context ); |
|
551 | 551 | } |
552 | 552 | |
553 | - /** |
|
554 | - * Alias of self::get_ip(). |
|
555 | - * |
|
556 | - * @since 1.0.19 |
|
557 | - * @param string $context View or edit context. |
|
558 | - * @return int |
|
559 | - */ |
|
560 | - public function get_customer_ip( $context = 'view' ) { |
|
561 | - return $this->get_ip( $context ); |
|
553 | + /** |
|
554 | + * Alias of self::get_ip(). |
|
555 | + * |
|
556 | + * @since 1.0.19 |
|
557 | + * @param string $context View or edit context. |
|
558 | + * @return int |
|
559 | + */ |
|
560 | + public function get_customer_ip( $context = 'view' ) { |
|
561 | + return $this->get_ip( $context ); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /** |
565 | - * Get the customer's first name. |
|
566 | - * |
|
567 | - * @since 1.0.19 |
|
568 | - * @param string $context View or edit context. |
|
569 | - * @return string |
|
570 | - */ |
|
571 | - public function get_first_name( $context = 'view' ) { |
|
572 | - return $this->get_prop( 'first_name', $context ); |
|
565 | + * Get the customer's first name. |
|
566 | + * |
|
567 | + * @since 1.0.19 |
|
568 | + * @param string $context View or edit context. |
|
569 | + * @return string |
|
570 | + */ |
|
571 | + public function get_first_name( $context = 'view' ) { |
|
572 | + return $this->get_prop( 'first_name', $context ); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
576 | - * Alias of self::get_first_name(). |
|
577 | - * |
|
578 | - * @since 1.0.19 |
|
579 | - * @param string $context View or edit context. |
|
580 | - * @return int |
|
581 | - */ |
|
582 | - public function get_user_first_name( $context = 'view' ) { |
|
583 | - return $this->get_first_name( $context ); |
|
576 | + * Alias of self::get_first_name(). |
|
577 | + * |
|
578 | + * @since 1.0.19 |
|
579 | + * @param string $context View or edit context. |
|
580 | + * @return int |
|
581 | + */ |
|
582 | + public function get_user_first_name( $context = 'view' ) { |
|
583 | + return $this->get_first_name( $context ); |
|
584 | 584 | } |
585 | 585 | |
586 | - /** |
|
587 | - * Alias of self::get_first_name(). |
|
588 | - * |
|
589 | - * @since 1.0.19 |
|
590 | - * @param string $context View or edit context. |
|
591 | - * @return int |
|
592 | - */ |
|
593 | - public function get_customer_first_name( $context = 'view' ) { |
|
594 | - return $this->get_first_name( $context ); |
|
586 | + /** |
|
587 | + * Alias of self::get_first_name(). |
|
588 | + * |
|
589 | + * @since 1.0.19 |
|
590 | + * @param string $context View or edit context. |
|
591 | + * @return int |
|
592 | + */ |
|
593 | + public function get_customer_first_name( $context = 'view' ) { |
|
594 | + return $this->get_first_name( $context ); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
598 | - * Get the customer's last name. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - * @param string $context View or edit context. |
|
602 | - * @return string |
|
603 | - */ |
|
604 | - public function get_last_name( $context = 'view' ) { |
|
605 | - return $this->get_prop( 'last_name', $context ); |
|
598 | + * Get the customer's last name. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + * @param string $context View or edit context. |
|
602 | + * @return string |
|
603 | + */ |
|
604 | + public function get_last_name( $context = 'view' ) { |
|
605 | + return $this->get_prop( 'last_name', $context ); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
609 | - * Alias of self::get_last_name(). |
|
610 | - * |
|
611 | - * @since 1.0.19 |
|
612 | - * @param string $context View or edit context. |
|
613 | - * @return int |
|
614 | - */ |
|
615 | - public function get_user_last_name( $context = 'view' ) { |
|
616 | - return $this->get_last_name( $context ); |
|
609 | + * Alias of self::get_last_name(). |
|
610 | + * |
|
611 | + * @since 1.0.19 |
|
612 | + * @param string $context View or edit context. |
|
613 | + * @return int |
|
614 | + */ |
|
615 | + public function get_user_last_name( $context = 'view' ) { |
|
616 | + return $this->get_last_name( $context ); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
620 | - * Alias of self::get_last_name(). |
|
621 | - * |
|
622 | - * @since 1.0.19 |
|
623 | - * @param string $context View or edit context. |
|
624 | - * @return int |
|
625 | - */ |
|
626 | - public function get_customer_last_name( $context = 'view' ) { |
|
627 | - return $this->get_last_name( $context ); |
|
620 | + * Alias of self::get_last_name(). |
|
621 | + * |
|
622 | + * @since 1.0.19 |
|
623 | + * @param string $context View or edit context. |
|
624 | + * @return int |
|
625 | + */ |
|
626 | + public function get_customer_last_name( $context = 'view' ) { |
|
627 | + return $this->get_last_name( $context ); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
631 | - * Get the customer's full name. |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - * @param string $context View or edit context. |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function get_full_name( $context = 'view' ) { |
|
638 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
631 | + * Get the customer's full name. |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + * @param string $context View or edit context. |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function get_full_name( $context = 'view' ) { |
|
638 | + return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
642 | - * Alias of self::get_full_name(). |
|
643 | - * |
|
644 | - * @since 1.0.19 |
|
645 | - * @param string $context View or edit context. |
|
646 | - * @return int |
|
647 | - */ |
|
648 | - public function get_user_full_name( $context = 'view' ) { |
|
649 | - return $this->get_full_name( $context ); |
|
642 | + * Alias of self::get_full_name(). |
|
643 | + * |
|
644 | + * @since 1.0.19 |
|
645 | + * @param string $context View or edit context. |
|
646 | + * @return int |
|
647 | + */ |
|
648 | + public function get_user_full_name( $context = 'view' ) { |
|
649 | + return $this->get_full_name( $context ); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
653 | - * Alias of self::get_full_name(). |
|
654 | - * |
|
655 | - * @since 1.0.19 |
|
656 | - * @param string $context View or edit context. |
|
657 | - * @return int |
|
658 | - */ |
|
659 | - public function get_customer_full_name( $context = 'view' ) { |
|
660 | - return $this->get_full_name( $context ); |
|
653 | + * Alias of self::get_full_name(). |
|
654 | + * |
|
655 | + * @since 1.0.19 |
|
656 | + * @param string $context View or edit context. |
|
657 | + * @return int |
|
658 | + */ |
|
659 | + public function get_customer_full_name( $context = 'view' ) { |
|
660 | + return $this->get_full_name( $context ); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
664 | - * Get the customer's phone number. |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
667 | - * @param string $context View or edit context. |
|
668 | - * @return string |
|
669 | - */ |
|
670 | - public function get_phone( $context = 'view' ) { |
|
671 | - return $this->get_prop( 'phone', $context ); |
|
664 | + * Get the customer's phone number. |
|
665 | + * |
|
666 | + * @since 1.0.19 |
|
667 | + * @param string $context View or edit context. |
|
668 | + * @return string |
|
669 | + */ |
|
670 | + public function get_phone( $context = 'view' ) { |
|
671 | + return $this->get_prop( 'phone', $context ); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
675 | - * Alias of self::get_phone(). |
|
676 | - * |
|
677 | - * @since 1.0.19 |
|
678 | - * @param string $context View or edit context. |
|
679 | - * @return int |
|
680 | - */ |
|
681 | - public function get_phone_number( $context = 'view' ) { |
|
682 | - return $this->get_phone( $context ); |
|
675 | + * Alias of self::get_phone(). |
|
676 | + * |
|
677 | + * @since 1.0.19 |
|
678 | + * @param string $context View or edit context. |
|
679 | + * @return int |
|
680 | + */ |
|
681 | + public function get_phone_number( $context = 'view' ) { |
|
682 | + return $this->get_phone( $context ); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | /** |
686 | - * Alias of self::get_phone(). |
|
687 | - * |
|
688 | - * @since 1.0.19 |
|
689 | - * @param string $context View or edit context. |
|
690 | - * @return int |
|
691 | - */ |
|
692 | - public function get_user_phone( $context = 'view' ) { |
|
693 | - return $this->get_phone( $context ); |
|
686 | + * Alias of self::get_phone(). |
|
687 | + * |
|
688 | + * @since 1.0.19 |
|
689 | + * @param string $context View or edit context. |
|
690 | + * @return int |
|
691 | + */ |
|
692 | + public function get_user_phone( $context = 'view' ) { |
|
693 | + return $this->get_phone( $context ); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
697 | - * Alias of self::get_phone(). |
|
698 | - * |
|
699 | - * @since 1.0.19 |
|
700 | - * @param string $context View or edit context. |
|
701 | - * @return int |
|
702 | - */ |
|
703 | - public function get_customer_phone( $context = 'view' ) { |
|
704 | - return $this->get_phone( $context ); |
|
697 | + * Alias of self::get_phone(). |
|
698 | + * |
|
699 | + * @since 1.0.19 |
|
700 | + * @param string $context View or edit context. |
|
701 | + * @return int |
|
702 | + */ |
|
703 | + public function get_customer_phone( $context = 'view' ) { |
|
704 | + return $this->get_phone( $context ); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /** |
708 | - * Get the customer's email address. |
|
709 | - * |
|
710 | - * @since 1.0.19 |
|
711 | - * @param string $context View or edit context. |
|
712 | - * @return string |
|
713 | - */ |
|
714 | - public function get_email( $context = 'view' ) { |
|
715 | - return $this->get_prop( 'email', $context ); |
|
708 | + * Get the customer's email address. |
|
709 | + * |
|
710 | + * @since 1.0.19 |
|
711 | + * @param string $context View or edit context. |
|
712 | + * @return string |
|
713 | + */ |
|
714 | + public function get_email( $context = 'view' ) { |
|
715 | + return $this->get_prop( 'email', $context ); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
719 | - * Alias of self::get_email(). |
|
720 | - * |
|
721 | - * @since 1.0.19 |
|
722 | - * @param string $context View or edit context. |
|
723 | - * @return string |
|
724 | - */ |
|
725 | - public function get_email_address( $context = 'view' ) { |
|
726 | - return $this->get_email( $context ); |
|
719 | + * Alias of self::get_email(). |
|
720 | + * |
|
721 | + * @since 1.0.19 |
|
722 | + * @param string $context View or edit context. |
|
723 | + * @return string |
|
724 | + */ |
|
725 | + public function get_email_address( $context = 'view' ) { |
|
726 | + return $this->get_email( $context ); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
730 | - * Alias of self::get_email(). |
|
731 | - * |
|
732 | - * @since 1.0.19 |
|
733 | - * @param string $context View or edit context. |
|
734 | - * @return int |
|
735 | - */ |
|
736 | - public function get_user_email( $context = 'view' ) { |
|
737 | - return $this->get_email( $context ); |
|
730 | + * Alias of self::get_email(). |
|
731 | + * |
|
732 | + * @since 1.0.19 |
|
733 | + * @param string $context View or edit context. |
|
734 | + * @return int |
|
735 | + */ |
|
736 | + public function get_user_email( $context = 'view' ) { |
|
737 | + return $this->get_email( $context ); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
741 | - * Alias of self::get_email(). |
|
742 | - * |
|
743 | - * @since 1.0.19 |
|
744 | - * @param string $context View or edit context. |
|
745 | - * @return int |
|
746 | - */ |
|
747 | - public function get_customer_email( $context = 'view' ) { |
|
748 | - return $this->get_email( $context ); |
|
741 | + * Alias of self::get_email(). |
|
742 | + * |
|
743 | + * @since 1.0.19 |
|
744 | + * @param string $context View or edit context. |
|
745 | + * @return int |
|
746 | + */ |
|
747 | + public function get_customer_email( $context = 'view' ) { |
|
748 | + return $this->get_email( $context ); |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
752 | - * Get the customer's country. |
|
753 | - * |
|
754 | - * @since 1.0.19 |
|
755 | - * @param string $context View or edit context. |
|
756 | - * @return string |
|
757 | - */ |
|
758 | - public function get_country( $context = 'view' ) { |
|
759 | - return $this->get_prop( 'country', $context ); |
|
752 | + * Get the customer's country. |
|
753 | + * |
|
754 | + * @since 1.0.19 |
|
755 | + * @param string $context View or edit context. |
|
756 | + * @return string |
|
757 | + */ |
|
758 | + public function get_country( $context = 'view' ) { |
|
759 | + return $this->get_prop( 'country', $context ); |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | /** |
763 | - * Alias of self::get_country(). |
|
764 | - * |
|
765 | - * @since 1.0.19 |
|
766 | - * @param string $context View or edit context. |
|
767 | - * @return int |
|
768 | - */ |
|
769 | - public function get_user_country( $context = 'view' ) { |
|
770 | - return $this->get_country( $context ); |
|
763 | + * Alias of self::get_country(). |
|
764 | + * |
|
765 | + * @since 1.0.19 |
|
766 | + * @param string $context View or edit context. |
|
767 | + * @return int |
|
768 | + */ |
|
769 | + public function get_user_country( $context = 'view' ) { |
|
770 | + return $this->get_country( $context ); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
774 | - * Alias of self::get_country(). |
|
775 | - * |
|
776 | - * @since 1.0.19 |
|
777 | - * @param string $context View or edit context. |
|
778 | - * @return int |
|
779 | - */ |
|
780 | - public function get_customer_country( $context = 'view' ) { |
|
781 | - return $this->get_country( $context ); |
|
774 | + * Alias of self::get_country(). |
|
775 | + * |
|
776 | + * @since 1.0.19 |
|
777 | + * @param string $context View or edit context. |
|
778 | + * @return int |
|
779 | + */ |
|
780 | + public function get_customer_country( $context = 'view' ) { |
|
781 | + return $this->get_country( $context ); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
785 | - * Get the customer's state. |
|
786 | - * |
|
787 | - * @since 1.0.19 |
|
788 | - * @param string $context View or edit context. |
|
789 | - * @return string |
|
790 | - */ |
|
791 | - public function get_state( $context = 'view' ) { |
|
792 | - return $this->get_prop( 'state', $context ); |
|
785 | + * Get the customer's state. |
|
786 | + * |
|
787 | + * @since 1.0.19 |
|
788 | + * @param string $context View or edit context. |
|
789 | + * @return string |
|
790 | + */ |
|
791 | + public function get_state( $context = 'view' ) { |
|
792 | + return $this->get_prop( 'state', $context ); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
796 | - * Alias of self::get_state(). |
|
797 | - * |
|
798 | - * @since 1.0.19 |
|
799 | - * @param string $context View or edit context. |
|
800 | - * @return int |
|
801 | - */ |
|
802 | - public function get_user_state( $context = 'view' ) { |
|
803 | - return $this->get_state( $context ); |
|
796 | + * Alias of self::get_state(). |
|
797 | + * |
|
798 | + * @since 1.0.19 |
|
799 | + * @param string $context View or edit context. |
|
800 | + * @return int |
|
801 | + */ |
|
802 | + public function get_user_state( $context = 'view' ) { |
|
803 | + return $this->get_state( $context ); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
807 | - * Alias of self::get_state(). |
|
808 | - * |
|
809 | - * @since 1.0.19 |
|
810 | - * @param string $context View or edit context. |
|
811 | - * @return int |
|
812 | - */ |
|
813 | - public function get_customer_state( $context = 'view' ) { |
|
814 | - return $this->get_state( $context ); |
|
807 | + * Alias of self::get_state(). |
|
808 | + * |
|
809 | + * @since 1.0.19 |
|
810 | + * @param string $context View or edit context. |
|
811 | + * @return int |
|
812 | + */ |
|
813 | + public function get_customer_state( $context = 'view' ) { |
|
814 | + return $this->get_state( $context ); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | /** |
818 | - * Get the customer's city. |
|
819 | - * |
|
820 | - * @since 1.0.19 |
|
821 | - * @param string $context View or edit context. |
|
822 | - * @return string |
|
823 | - */ |
|
824 | - public function get_city( $context = 'view' ) { |
|
825 | - return $this->get_prop( 'city', $context ); |
|
818 | + * Get the customer's city. |
|
819 | + * |
|
820 | + * @since 1.0.19 |
|
821 | + * @param string $context View or edit context. |
|
822 | + * @return string |
|
823 | + */ |
|
824 | + public function get_city( $context = 'view' ) { |
|
825 | + return $this->get_prop( 'city', $context ); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
829 | - * Alias of self::get_city(). |
|
830 | - * |
|
831 | - * @since 1.0.19 |
|
832 | - * @param string $context View or edit context. |
|
833 | - * @return string |
|
834 | - */ |
|
835 | - public function get_user_city( $context = 'view' ) { |
|
836 | - return $this->get_city( $context ); |
|
829 | + * Alias of self::get_city(). |
|
830 | + * |
|
831 | + * @since 1.0.19 |
|
832 | + * @param string $context View or edit context. |
|
833 | + * @return string |
|
834 | + */ |
|
835 | + public function get_user_city( $context = 'view' ) { |
|
836 | + return $this->get_city( $context ); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
840 | - * Alias of self::get_city(). |
|
841 | - * |
|
842 | - * @since 1.0.19 |
|
843 | - * @param string $context View or edit context. |
|
844 | - * @return string |
|
845 | - */ |
|
846 | - public function get_customer_city( $context = 'view' ) { |
|
847 | - return $this->get_city( $context ); |
|
840 | + * Alias of self::get_city(). |
|
841 | + * |
|
842 | + * @since 1.0.19 |
|
843 | + * @param string $context View or edit context. |
|
844 | + * @return string |
|
845 | + */ |
|
846 | + public function get_customer_city( $context = 'view' ) { |
|
847 | + return $this->get_city( $context ); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
851 | - * Get the customer's zip. |
|
852 | - * |
|
853 | - * @since 1.0.19 |
|
854 | - * @param string $context View or edit context. |
|
855 | - * @return string |
|
856 | - */ |
|
857 | - public function get_zip( $context = 'view' ) { |
|
858 | - return $this->get_prop( 'zip', $context ); |
|
851 | + * Get the customer's zip. |
|
852 | + * |
|
853 | + * @since 1.0.19 |
|
854 | + * @param string $context View or edit context. |
|
855 | + * @return string |
|
856 | + */ |
|
857 | + public function get_zip( $context = 'view' ) { |
|
858 | + return $this->get_prop( 'zip', $context ); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | /** |
862 | - * Alias of self::get_zip(). |
|
863 | - * |
|
864 | - * @since 1.0.19 |
|
865 | - * @param string $context View or edit context. |
|
866 | - * @return string |
|
867 | - */ |
|
868 | - public function get_user_zip( $context = 'view' ) { |
|
869 | - return $this->get_zip( $context ); |
|
862 | + * Alias of self::get_zip(). |
|
863 | + * |
|
864 | + * @since 1.0.19 |
|
865 | + * @param string $context View or edit context. |
|
866 | + * @return string |
|
867 | + */ |
|
868 | + public function get_user_zip( $context = 'view' ) { |
|
869 | + return $this->get_zip( $context ); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
873 | - * Alias of self::get_zip(). |
|
874 | - * |
|
875 | - * @since 1.0.19 |
|
876 | - * @param string $context View or edit context. |
|
877 | - * @return string |
|
878 | - */ |
|
879 | - public function get_customer_zip( $context = 'view' ) { |
|
880 | - return $this->get_zip( $context ); |
|
873 | + * Alias of self::get_zip(). |
|
874 | + * |
|
875 | + * @since 1.0.19 |
|
876 | + * @param string $context View or edit context. |
|
877 | + * @return string |
|
878 | + */ |
|
879 | + public function get_customer_zip( $context = 'view' ) { |
|
880 | + return $this->get_zip( $context ); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | /** |
884 | - * Get the customer's company. |
|
885 | - * |
|
886 | - * @since 1.0.19 |
|
887 | - * @param string $context View or edit context. |
|
888 | - * @return string |
|
889 | - */ |
|
890 | - public function get_company( $context = 'view' ) { |
|
891 | - return $this->get_prop( 'company', $context ); |
|
884 | + * Get the customer's company. |
|
885 | + * |
|
886 | + * @since 1.0.19 |
|
887 | + * @param string $context View or edit context. |
|
888 | + * @return string |
|
889 | + */ |
|
890 | + public function get_company( $context = 'view' ) { |
|
891 | + return $this->get_prop( 'company', $context ); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
895 | - * Alias of self::get_company(). |
|
896 | - * |
|
897 | - * @since 1.0.19 |
|
898 | - * @param string $context View or edit context. |
|
899 | - * @return string |
|
900 | - */ |
|
901 | - public function get_user_company( $context = 'view' ) { |
|
902 | - return $this->get_company( $context ); |
|
895 | + * Alias of self::get_company(). |
|
896 | + * |
|
897 | + * @since 1.0.19 |
|
898 | + * @param string $context View or edit context. |
|
899 | + * @return string |
|
900 | + */ |
|
901 | + public function get_user_company( $context = 'view' ) { |
|
902 | + return $this->get_company( $context ); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
906 | - * Alias of self::get_company(). |
|
907 | - * |
|
908 | - * @since 1.0.19 |
|
909 | - * @param string $context View or edit context. |
|
910 | - * @return string |
|
911 | - */ |
|
912 | - public function get_customer_company( $context = 'view' ) { |
|
913 | - return $this->get_company( $context ); |
|
906 | + * Alias of self::get_company(). |
|
907 | + * |
|
908 | + * @since 1.0.19 |
|
909 | + * @param string $context View or edit context. |
|
910 | + * @return string |
|
911 | + */ |
|
912 | + public function get_customer_company( $context = 'view' ) { |
|
913 | + return $this->get_company( $context ); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
917 | - * Get the customer's vat number. |
|
918 | - * |
|
919 | - * @since 1.0.19 |
|
920 | - * @param string $context View or edit context. |
|
921 | - * @return string |
|
922 | - */ |
|
923 | - public function get_vat_number( $context = 'view' ) { |
|
924 | - return $this->get_prop( 'vat_number', $context ); |
|
917 | + * Get the customer's vat number. |
|
918 | + * |
|
919 | + * @since 1.0.19 |
|
920 | + * @param string $context View or edit context. |
|
921 | + * @return string |
|
922 | + */ |
|
923 | + public function get_vat_number( $context = 'view' ) { |
|
924 | + return $this->get_prop( 'vat_number', $context ); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
928 | - * Alias of self::get_vat_number(). |
|
929 | - * |
|
930 | - * @since 1.0.19 |
|
931 | - * @param string $context View or edit context. |
|
932 | - * @return string |
|
933 | - */ |
|
934 | - public function get_user_vat_number( $context = 'view' ) { |
|
935 | - return $this->get_vat_number( $context ); |
|
928 | + * Alias of self::get_vat_number(). |
|
929 | + * |
|
930 | + * @since 1.0.19 |
|
931 | + * @param string $context View or edit context. |
|
932 | + * @return string |
|
933 | + */ |
|
934 | + public function get_user_vat_number( $context = 'view' ) { |
|
935 | + return $this->get_vat_number( $context ); |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
939 | - * Alias of self::get_vat_number(). |
|
940 | - * |
|
941 | - * @since 1.0.19 |
|
942 | - * @param string $context View or edit context. |
|
943 | - * @return string |
|
944 | - */ |
|
945 | - public function get_customer_vat_number( $context = 'view' ) { |
|
946 | - return $this->get_vat_number( $context ); |
|
939 | + * Alias of self::get_vat_number(). |
|
940 | + * |
|
941 | + * @since 1.0.19 |
|
942 | + * @param string $context View or edit context. |
|
943 | + * @return string |
|
944 | + */ |
|
945 | + public function get_customer_vat_number( $context = 'view' ) { |
|
946 | + return $this->get_vat_number( $context ); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | /** |
950 | - * Get the customer's vat rate. |
|
951 | - * |
|
952 | - * @since 1.0.19 |
|
953 | - * @param string $context View or edit context. |
|
954 | - * @return string |
|
955 | - */ |
|
956 | - public function get_vat_rate( $context = 'view' ) { |
|
957 | - return $this->get_prop( 'vat_rate', $context ); |
|
950 | + * Get the customer's vat rate. |
|
951 | + * |
|
952 | + * @since 1.0.19 |
|
953 | + * @param string $context View or edit context. |
|
954 | + * @return string |
|
955 | + */ |
|
956 | + public function get_vat_rate( $context = 'view' ) { |
|
957 | + return $this->get_prop( 'vat_rate', $context ); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
961 | - * Alias of self::get_vat_rate(). |
|
962 | - * |
|
963 | - * @since 1.0.19 |
|
964 | - * @param string $context View or edit context. |
|
965 | - * @return string |
|
966 | - */ |
|
967 | - public function get_user_vat_rate( $context = 'view' ) { |
|
968 | - return $this->get_vat_rate( $context ); |
|
961 | + * Alias of self::get_vat_rate(). |
|
962 | + * |
|
963 | + * @since 1.0.19 |
|
964 | + * @param string $context View or edit context. |
|
965 | + * @return string |
|
966 | + */ |
|
967 | + public function get_user_vat_rate( $context = 'view' ) { |
|
968 | + return $this->get_vat_rate( $context ); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
972 | - * Alias of self::get_vat_rate(). |
|
973 | - * |
|
974 | - * @since 1.0.19 |
|
975 | - * @param string $context View or edit context. |
|
976 | - * @return string |
|
977 | - */ |
|
978 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
979 | - return $this->get_vat_rate( $context ); |
|
972 | + * Alias of self::get_vat_rate(). |
|
973 | + * |
|
974 | + * @since 1.0.19 |
|
975 | + * @param string $context View or edit context. |
|
976 | + * @return string |
|
977 | + */ |
|
978 | + public function get_customer_vat_rate( $context = 'view' ) { |
|
979 | + return $this->get_vat_rate( $context ); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
983 | - * Get the customer's address. |
|
984 | - * |
|
985 | - * @since 1.0.19 |
|
986 | - * @param string $context View or edit context. |
|
987 | - * @return string |
|
988 | - */ |
|
989 | - public function get_address( $context = 'view' ) { |
|
990 | - return $this->get_prop( 'address', $context ); |
|
983 | + * Get the customer's address. |
|
984 | + * |
|
985 | + * @since 1.0.19 |
|
986 | + * @param string $context View or edit context. |
|
987 | + * @return string |
|
988 | + */ |
|
989 | + public function get_address( $context = 'view' ) { |
|
990 | + return $this->get_prop( 'address', $context ); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
994 | - * Alias of self::get_address(). |
|
995 | - * |
|
996 | - * @since 1.0.19 |
|
997 | - * @param string $context View or edit context. |
|
998 | - * @return string |
|
999 | - */ |
|
1000 | - public function get_user_address( $context = 'view' ) { |
|
1001 | - return $this->get_address( $context ); |
|
994 | + * Alias of self::get_address(). |
|
995 | + * |
|
996 | + * @since 1.0.19 |
|
997 | + * @param string $context View or edit context. |
|
998 | + * @return string |
|
999 | + */ |
|
1000 | + public function get_user_address( $context = 'view' ) { |
|
1001 | + return $this->get_address( $context ); |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
1005 | - * Alias of self::get_address(). |
|
1006 | - * |
|
1007 | - * @since 1.0.19 |
|
1008 | - * @param string $context View or edit context. |
|
1009 | - * @return string |
|
1010 | - */ |
|
1011 | - public function get_customer_address( $context = 'view' ) { |
|
1012 | - return $this->get_address( $context ); |
|
1005 | + * Alias of self::get_address(). |
|
1006 | + * |
|
1007 | + * @since 1.0.19 |
|
1008 | + * @param string $context View or edit context. |
|
1009 | + * @return string |
|
1010 | + */ |
|
1011 | + public function get_customer_address( $context = 'view' ) { |
|
1012 | + return $this->get_address( $context ); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | /** |
1016 | - * Get whether the customer has confirmed their address. |
|
1017 | - * |
|
1018 | - * @since 1.0.19 |
|
1019 | - * @param string $context View or edit context. |
|
1020 | - * @return bool |
|
1021 | - */ |
|
1022 | - public function get_address_confirmed( $context = 'view' ) { |
|
1023 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1016 | + * Get whether the customer has confirmed their address. |
|
1017 | + * |
|
1018 | + * @since 1.0.19 |
|
1019 | + * @param string $context View or edit context. |
|
1020 | + * @return bool |
|
1021 | + */ |
|
1022 | + public function get_address_confirmed( $context = 'view' ) { |
|
1023 | + return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
1027 | - * Alias of self::get_address_confirmed(). |
|
1028 | - * |
|
1029 | - * @since 1.0.19 |
|
1030 | - * @param string $context View or edit context. |
|
1031 | - * @return bool |
|
1032 | - */ |
|
1033 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1034 | - return $this->get_address_confirmed( $context ); |
|
1027 | + * Alias of self::get_address_confirmed(). |
|
1028 | + * |
|
1029 | + * @since 1.0.19 |
|
1030 | + * @param string $context View or edit context. |
|
1031 | + * @return bool |
|
1032 | + */ |
|
1033 | + public function get_user_address_confirmed( $context = 'view' ) { |
|
1034 | + return $this->get_address_confirmed( $context ); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | /** |
1038 | - * Alias of self::get_address(). |
|
1039 | - * |
|
1040 | - * @since 1.0.19 |
|
1041 | - * @param string $context View or edit context. |
|
1042 | - * @return bool |
|
1043 | - */ |
|
1044 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1045 | - return $this->get_address_confirmed( $context ); |
|
1038 | + * Alias of self::get_address(). |
|
1039 | + * |
|
1040 | + * @since 1.0.19 |
|
1041 | + * @param string $context View or edit context. |
|
1042 | + * @return bool |
|
1043 | + */ |
|
1044 | + public function get_customer_address_confirmed( $context = 'view' ) { |
|
1045 | + return $this->get_address_confirmed( $context ); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
1049 | - * Get the invoice subtotal. |
|
1050 | - * |
|
1051 | - * @since 1.0.19 |
|
1052 | - * @param string $context View or edit context. |
|
1053 | - * @return float |
|
1054 | - */ |
|
1055 | - public function get_subtotal( $context = 'view' ) { |
|
1056 | - return (float) $this->get_prop( 'subtotal', $context ); |
|
1049 | + * Get the invoice subtotal. |
|
1050 | + * |
|
1051 | + * @since 1.0.19 |
|
1052 | + * @param string $context View or edit context. |
|
1053 | + * @return float |
|
1054 | + */ |
|
1055 | + public function get_subtotal( $context = 'view' ) { |
|
1056 | + return (float) $this->get_prop( 'subtotal', $context ); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
1060 | - * Get the invoice discount total. |
|
1061 | - * |
|
1062 | - * @since 1.0.19 |
|
1063 | - * @param string $context View or edit context. |
|
1064 | - * @return float |
|
1065 | - */ |
|
1066 | - public function get_total_discount( $context = 'view' ) { |
|
1067 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1060 | + * Get the invoice discount total. |
|
1061 | + * |
|
1062 | + * @since 1.0.19 |
|
1063 | + * @param string $context View or edit context. |
|
1064 | + * @return float |
|
1065 | + */ |
|
1066 | + public function get_total_discount( $context = 'view' ) { |
|
1067 | + return (float) $this->get_prop( 'total_discount', $context ); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
1071 | - * Get the invoice tax total. |
|
1072 | - * |
|
1073 | - * @since 1.0.19 |
|
1074 | - * @param string $context View or edit context. |
|
1075 | - * @return float |
|
1076 | - */ |
|
1077 | - public function get_total_tax( $context = 'view' ) { |
|
1078 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1071 | + * Get the invoice tax total. |
|
1072 | + * |
|
1073 | + * @since 1.0.19 |
|
1074 | + * @param string $context View or edit context. |
|
1075 | + * @return float |
|
1076 | + */ |
|
1077 | + public function get_total_tax( $context = 'view' ) { |
|
1078 | + return (float) $this->get_prop( 'total_tax', $context ); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
1082 | - * Get the invoice fees total. |
|
1083 | - * |
|
1084 | - * @since 1.0.19 |
|
1085 | - * @param string $context View or edit context. |
|
1086 | - * @return float |
|
1087 | - */ |
|
1088 | - public function get_total_fees( $context = 'view' ) { |
|
1089 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1082 | + * Get the invoice fees total. |
|
1083 | + * |
|
1084 | + * @since 1.0.19 |
|
1085 | + * @param string $context View or edit context. |
|
1086 | + * @return float |
|
1087 | + */ |
|
1088 | + public function get_total_fees( $context = 'view' ) { |
|
1089 | + return (float) $this->get_prop( 'total_fees', $context ); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | /** |
1093 | - * Get the invoice total. |
|
1094 | - * |
|
1095 | - * @since 1.0.19 |
|
1093 | + * Get the invoice total. |
|
1094 | + * |
|
1095 | + * @since 1.0.19 |
|
1096 | 1096 | * @param string $context View or edit context. |
1097 | 1097 | * @return float |
1098 | - */ |
|
1099 | - public function get_total( $context = 'view' ) { |
|
1100 | - $total = $this->get_subtotal( $context ) + $this->get_total_fees( $context ) - $this->get_total_discount( $context ) + $this->get_total_tax( $context ); |
|
1101 | - $total = apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1102 | - return (float) wpinv_sanitize_amount( $total ); |
|
1098 | + */ |
|
1099 | + public function get_total( $context = 'view' ) { |
|
1100 | + $total = $this->get_subtotal( $context ) + $this->get_total_fees( $context ) - $this->get_total_discount( $context ) + $this->get_total_tax( $context ); |
|
1101 | + $total = apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1102 | + return (float) wpinv_sanitize_amount( $total ); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | /** |
1106 | - * Get the invoice fees. |
|
1107 | - * |
|
1108 | - * @since 1.0.19 |
|
1109 | - * @param string $context View or edit context. |
|
1110 | - * @return array |
|
1111 | - */ |
|
1112 | - public function get_fees( $context = 'view' ) { |
|
1113 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1106 | + * Get the invoice fees. |
|
1107 | + * |
|
1108 | + * @since 1.0.19 |
|
1109 | + * @param string $context View or edit context. |
|
1110 | + * @return array |
|
1111 | + */ |
|
1112 | + public function get_fees( $context = 'view' ) { |
|
1113 | + return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | /** |
1117 | - * Get the invoice discounts. |
|
1118 | - * |
|
1119 | - * @since 1.0.19 |
|
1120 | - * @param string $context View or edit context. |
|
1121 | - * @return array |
|
1122 | - */ |
|
1123 | - public function get_discounts( $context = 'view' ) { |
|
1124 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1117 | + * Get the invoice discounts. |
|
1118 | + * |
|
1119 | + * @since 1.0.19 |
|
1120 | + * @param string $context View or edit context. |
|
1121 | + * @return array |
|
1122 | + */ |
|
1123 | + public function get_discounts( $context = 'view' ) { |
|
1124 | + return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | /** |
1128 | - * Get the invoice taxes. |
|
1129 | - * |
|
1130 | - * @since 1.0.19 |
|
1131 | - * @param string $context View or edit context. |
|
1132 | - * @return array |
|
1133 | - */ |
|
1134 | - public function get_taxes( $context = 'view' ) { |
|
1135 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1128 | + * Get the invoice taxes. |
|
1129 | + * |
|
1130 | + * @since 1.0.19 |
|
1131 | + * @param string $context View or edit context. |
|
1132 | + * @return array |
|
1133 | + */ |
|
1134 | + public function get_taxes( $context = 'view' ) { |
|
1135 | + return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1136 | 1136 | } |
1137 | 1137 | |
1138 | 1138 | /** |
1139 | - * Get the invoice items. |
|
1140 | - * |
|
1141 | - * @since 1.0.19 |
|
1142 | - * @param string $context View or edit context. |
|
1143 | - * @return array |
|
1144 | - */ |
|
1145 | - public function get_items( $context = 'view' ) { |
|
1146 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
1139 | + * Get the invoice items. |
|
1140 | + * |
|
1141 | + * @since 1.0.19 |
|
1142 | + * @param string $context View or edit context. |
|
1143 | + * @return array |
|
1144 | + */ |
|
1145 | + public function get_items( $context = 'view' ) { |
|
1146 | + return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | /** |
1150 | - * Get the invoice's payment form. |
|
1151 | - * |
|
1152 | - * @since 1.0.19 |
|
1153 | - * @param string $context View or edit context. |
|
1154 | - * @return int |
|
1155 | - */ |
|
1156 | - public function get_payment_form( $context = 'view' ) { |
|
1157 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1150 | + * Get the invoice's payment form. |
|
1151 | + * |
|
1152 | + * @since 1.0.19 |
|
1153 | + * @param string $context View or edit context. |
|
1154 | + * @return int |
|
1155 | + */ |
|
1156 | + public function get_payment_form( $context = 'view' ) { |
|
1157 | + return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | /** |
1161 | - * Get the invoice's submission id. |
|
1162 | - * |
|
1163 | - * @since 1.0.19 |
|
1164 | - * @param string $context View or edit context. |
|
1165 | - * @return string |
|
1166 | - */ |
|
1167 | - public function get_submission_id( $context = 'view' ) { |
|
1168 | - return $this->get_prop( 'submission_id', $context ); |
|
1161 | + * Get the invoice's submission id. |
|
1162 | + * |
|
1163 | + * @since 1.0.19 |
|
1164 | + * @param string $context View or edit context. |
|
1165 | + * @return string |
|
1166 | + */ |
|
1167 | + public function get_submission_id( $context = 'view' ) { |
|
1168 | + return $this->get_prop( 'submission_id', $context ); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | /** |
1172 | - * Get the invoice's discount code. |
|
1173 | - * |
|
1174 | - * @since 1.0.19 |
|
1175 | - * @param string $context View or edit context. |
|
1176 | - * @return string |
|
1177 | - */ |
|
1178 | - public function get_discount_code( $context = 'view' ) { |
|
1179 | - return $this->get_prop( 'discount_code', $context ); |
|
1172 | + * Get the invoice's discount code. |
|
1173 | + * |
|
1174 | + * @since 1.0.19 |
|
1175 | + * @param string $context View or edit context. |
|
1176 | + * @return string |
|
1177 | + */ |
|
1178 | + public function get_discount_code( $context = 'view' ) { |
|
1179 | + return $this->get_prop( 'discount_code', $context ); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
1183 | - * Get the invoice's gateway. |
|
1184 | - * |
|
1185 | - * @since 1.0.19 |
|
1186 | - * @param string $context View or edit context. |
|
1187 | - * @return string |
|
1188 | - */ |
|
1189 | - public function get_gateway( $context = 'view' ) { |
|
1190 | - return $this->get_prop( 'gateway', $context ); |
|
1183 | + * Get the invoice's gateway. |
|
1184 | + * |
|
1185 | + * @since 1.0.19 |
|
1186 | + * @param string $context View or edit context. |
|
1187 | + * @return string |
|
1188 | + */ |
|
1189 | + public function get_gateway( $context = 'view' ) { |
|
1190 | + return $this->get_prop( 'gateway', $context ); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | /** |
1194 | - * Get the invoice's transaction id. |
|
1195 | - * |
|
1196 | - * @since 1.0.19 |
|
1197 | - * @param string $context View or edit context. |
|
1198 | - * @return string |
|
1199 | - */ |
|
1200 | - public function get_transaction_id( $context = 'view' ) { |
|
1201 | - return $this->get_prop( 'transaction_id', $context ); |
|
1194 | + * Get the invoice's transaction id. |
|
1195 | + * |
|
1196 | + * @since 1.0.19 |
|
1197 | + * @param string $context View or edit context. |
|
1198 | + * @return string |
|
1199 | + */ |
|
1200 | + public function get_transaction_id( $context = 'view' ) { |
|
1201 | + return $this->get_prop( 'transaction_id', $context ); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | /** |
1205 | - * Get the invoice's currency. |
|
1206 | - * |
|
1207 | - * @since 1.0.19 |
|
1208 | - * @param string $context View or edit context. |
|
1209 | - * @return string |
|
1210 | - */ |
|
1211 | - public function get_currency( $context = 'view' ) { |
|
1205 | + * Get the invoice's currency. |
|
1206 | + * |
|
1207 | + * @since 1.0.19 |
|
1208 | + * @param string $context View or edit context. |
|
1209 | + * @return string |
|
1210 | + */ |
|
1211 | + public function get_currency( $context = 'view' ) { |
|
1212 | 1212 | $currency = $this->get_prop( 'currency', $context ); |
1213 | 1213 | return empty( $currency ) ? wpinv_get_currency() : $currency; |
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | /** |
1217 | - * Checks if we are charging taxes for this invoice. |
|
1218 | - * |
|
1219 | - * @since 1.0.19 |
|
1220 | - * @param string $context View or edit context. |
|
1221 | - * @return bool |
|
1222 | - */ |
|
1223 | - public function get_disable_taxes( $context = 'view' ) { |
|
1217 | + * Checks if we are charging taxes for this invoice. |
|
1218 | + * |
|
1219 | + * @since 1.0.19 |
|
1220 | + * @param string $context View or edit context. |
|
1221 | + * @return bool |
|
1222 | + */ |
|
1223 | + public function get_disable_taxes( $context = 'view' ) { |
|
1224 | 1224 | return (bool) $this->get_prop( 'disable_taxes', $context ); |
1225 | 1225 | } |
1226 | 1226 | |
@@ -1237,9 +1237,9 @@ discard block |
||
1237 | 1237 | return $value; |
1238 | 1238 | } |
1239 | 1239 | |
1240 | - /** |
|
1241 | - * Sets an invoice key. |
|
1242 | - */ |
|
1240 | + /** |
|
1241 | + * Sets an invoice key. |
|
1242 | + */ |
|
1243 | 1243 | public function set( $key, $value ) { |
1244 | 1244 | $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
1245 | 1245 |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | // MUST have WordPress. |
4 | -if ( !defined( 'WPINC' ) ) { |
|
5 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
4 | +if (!defined('WPINC')) { |
|
5 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -99,38 +99,38 @@ discard block |
||
99 | 99 | * |
100 | 100 | * @param int/string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, number or object to read. |
101 | 101 | */ |
102 | - public function __construct( $invoice = false ) { |
|
102 | + public function __construct($invoice = false) { |
|
103 | 103 | |
104 | - parent::__construct( $invoice ); |
|
104 | + parent::__construct($invoice); |
|
105 | 105 | |
106 | - if ( is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) { |
|
107 | - $this->set_id( $invoice ); |
|
108 | - } elseif ( $invoice instanceof self ) { |
|
109 | - $this->set_id( $invoice->get_id() ); |
|
110 | - } elseif ( ! empty( $invoice->ID ) ) { |
|
111 | - $this->set_id( $invoice->ID ); |
|
112 | - } elseif ( is_array( $invoice ) ) { |
|
113 | - $this->set_props( $invoice ); |
|
106 | + if (is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) { |
|
107 | + $this->set_id($invoice); |
|
108 | + } elseif ($invoice instanceof self) { |
|
109 | + $this->set_id($invoice->get_id()); |
|
110 | + } elseif (!empty($invoice->ID)) { |
|
111 | + $this->set_id($invoice->ID); |
|
112 | + } elseif (is_array($invoice)) { |
|
113 | + $this->set_props($invoice); |
|
114 | 114 | |
115 | - if ( isset( $invoice['ID'] ) ) { |
|
116 | - $this->set_id( $invoice['ID'] ); |
|
115 | + if (isset($invoice['ID'])) { |
|
116 | + $this->set_id($invoice['ID']); |
|
117 | 117 | } |
118 | 118 | |
119 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'key' ) ) { |
|
120 | - $this->set_id( $invoice_id ); |
|
121 | - } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_discount_id_by_code( $invoice, 'number' ) ) { |
|
122 | - $this->set_id( $invoice_id ); |
|
119 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'key')) { |
|
120 | + $this->set_id($invoice_id); |
|
121 | + } elseif (is_scalar($invoice) && $invoice_id = self::get_discount_id_by_code($invoice, 'number')) { |
|
122 | + $this->set_id($invoice_id); |
|
123 | 123 | } else { |
124 | - $this->set_object_read( true ); |
|
124 | + $this->set_object_read(true); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | // Load the datastore. |
128 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
128 | + $this->data_store = GetPaid_Data_Store::load($this->data_store_name); |
|
129 | 129 | |
130 | - if ( $this->get_id() > 0 ) { |
|
131 | - $this->post = get_post( $this->get_id() ); |
|
130 | + if ($this->get_id() > 0) { |
|
131 | + $this->post = get_post($this->get_id()); |
|
132 | 132 | $this->ID = $this->get_id(); |
133 | - $this->data_store->read( $this ); |
|
133 | + $this->data_store->read($this); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | } |
@@ -144,38 +144,38 @@ discard block |
||
144 | 144 | * @since 1.0.15 |
145 | 145 | * @return int |
146 | 146 | */ |
147 | - public static function get_discount_id_by_code( $invoice_key_or_number, $field = 'key' ) { |
|
147 | + public static function get_discount_id_by_code($invoice_key_or_number, $field = 'key') { |
|
148 | 148 | global $wpdb; |
149 | 149 | |
150 | 150 | // Trim the code. |
151 | - $key = trim( $invoice_key_or_number ); |
|
151 | + $key = trim($invoice_key_or_number); |
|
152 | 152 | |
153 | 153 | // Valid fields. |
154 | - $fields = array( 'key', 'number' ); |
|
154 | + $fields = array('key', 'number'); |
|
155 | 155 | |
156 | 156 | // Ensure a value has been passed. |
157 | - if ( empty( $key ) || ! in_array( $field, $fields ) ) { |
|
157 | + if (empty($key) || !in_array($field, $fields)) { |
|
158 | 158 | return 0; |
159 | 159 | } |
160 | 160 | |
161 | 161 | // Maybe retrieve from the cache. |
162 | - $invoice_id = wp_cache_get( $key, 'getpaid_invoice_keys_' . $field ); |
|
163 | - if ( ! empty( $invoice_id ) ) { |
|
162 | + $invoice_id = wp_cache_get($key, 'getpaid_invoice_keys_' . $field); |
|
163 | + if (!empty($invoice_id)) { |
|
164 | 164 | return $invoice_id; |
165 | 165 | } |
166 | 166 | |
167 | 167 | // Fetch from the db. |
168 | 168 | $table = $wpdb->prefix . 'getpaid_invoices'; |
169 | 169 | $invoice_id = $wpdb->get_var( |
170 | - $wpdb->prepare( "SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key ) |
|
170 | + $wpdb->prepare("SELECT `post_id` FROM $table WHERE $field=%s LIMIT 1", $key) |
|
171 | 171 | ); |
172 | 172 | |
173 | - if ( empty( $invoice_id ) ) { |
|
173 | + if (empty($invoice_id)) { |
|
174 | 174 | return 0; |
175 | 175 | } |
176 | 176 | |
177 | 177 | // Update the cache with our data |
178 | - wp_cache_add( $key, $invoice_id, 'getpaid_invoice_keys_' . $field ); |
|
178 | + wp_cache_add($key, $invoice_id, 'getpaid_invoice_keys_' . $field); |
|
179 | 179 | |
180 | 180 | return $invoice_id; |
181 | 181 | } |
@@ -202,8 +202,8 @@ discard block |
||
202 | 202 | * @param string $context View or edit context. |
203 | 203 | * @return int |
204 | 204 | */ |
205 | - public function get_parent_id( $context = 'view' ) { |
|
206 | - return (int) $this->get_prop( 'parent_id', $context ); |
|
205 | + public function get_parent_id($context = 'view') { |
|
206 | + return (int) $this->get_prop('parent_id', $context); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -213,8 +213,8 @@ discard block |
||
213 | 213 | * @param string $context View or edit context. |
214 | 214 | * @return string |
215 | 215 | */ |
216 | - public function get_status( $context = 'view' ) { |
|
217 | - return $this->get_prop( 'status', $context ); |
|
216 | + public function get_status($context = 'view') { |
|
217 | + return $this->get_prop('status', $context); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -224,8 +224,8 @@ discard block |
||
224 | 224 | * @param string $context View or edit context. |
225 | 225 | * @return string |
226 | 226 | */ |
227 | - public function get_version( $context = 'view' ) { |
|
228 | - return $this->get_prop( 'version', $context ); |
|
227 | + public function get_version($context = 'view') { |
|
228 | + return $this->get_prop('version', $context); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | /** |
@@ -235,8 +235,8 @@ discard block |
||
235 | 235 | * @param string $context View or edit context. |
236 | 236 | * @return string |
237 | 237 | */ |
238 | - public function get_date_created( $context = 'view' ) { |
|
239 | - return $this->get_prop( 'date_created', $context ); |
|
238 | + public function get_date_created($context = 'view') { |
|
239 | + return $this->get_prop('date_created', $context); |
|
240 | 240 | } |
241 | 241 | |
242 | 242 | /** |
@@ -246,11 +246,11 @@ discard block |
||
246 | 246 | * @param string $context View or edit context. |
247 | 247 | * @return string |
248 | 248 | */ |
249 | - public function get_date_created_gmt( $context = 'view' ) { |
|
250 | - $date = $this->get_date_created( $context ); |
|
249 | + public function get_date_created_gmt($context = 'view') { |
|
250 | + $date = $this->get_date_created($context); |
|
251 | 251 | |
252 | - if ( $date ) { |
|
253 | - $date = get_gmt_from_date( $date ); |
|
252 | + if ($date) { |
|
253 | + $date = get_gmt_from_date($date); |
|
254 | 254 | } |
255 | 255 | return $date; |
256 | 256 | } |
@@ -262,8 +262,8 @@ discard block |
||
262 | 262 | * @param string $context View or edit context. |
263 | 263 | * @return string |
264 | 264 | */ |
265 | - public function get_date_modified( $context = 'view' ) { |
|
266 | - return $this->get_prop( 'date_modified', $context ); |
|
265 | + public function get_date_modified($context = 'view') { |
|
266 | + return $this->get_prop('date_modified', $context); |
|
267 | 267 | } |
268 | 268 | |
269 | 269 | /** |
@@ -273,11 +273,11 @@ discard block |
||
273 | 273 | * @param string $context View or edit context. |
274 | 274 | * @return string |
275 | 275 | */ |
276 | - public function get_date_modified_gmt( $context = 'view' ) { |
|
277 | - $date = $this->get_date_modified( $context ); |
|
276 | + public function get_date_modified_gmt($context = 'view') { |
|
277 | + $date = $this->get_date_modified($context); |
|
278 | 278 | |
279 | - if ( $date ) { |
|
280 | - $date = get_gmt_from_date( $date ); |
|
279 | + if ($date) { |
|
280 | + $date = get_gmt_from_date($date); |
|
281 | 281 | } |
282 | 282 | return $date; |
283 | 283 | } |
@@ -289,8 +289,8 @@ discard block |
||
289 | 289 | * @param string $context View or edit context. |
290 | 290 | * @return string |
291 | 291 | */ |
292 | - public function get_due_date( $context = 'view' ) { |
|
293 | - return $this->get_prop( 'due_date', $context ); |
|
292 | + public function get_due_date($context = 'view') { |
|
293 | + return $this->get_prop('due_date', $context); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -300,8 +300,8 @@ discard block |
||
300 | 300 | * @param string $context View or edit context. |
301 | 301 | * @return string |
302 | 302 | */ |
303 | - public function get_date_due( $context = 'view' ) { |
|
304 | - return $this->get_due_date( $context ); |
|
303 | + public function get_date_due($context = 'view') { |
|
304 | + return $this->get_due_date($context); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | /** |
@@ -311,11 +311,11 @@ discard block |
||
311 | 311 | * @param string $context View or edit context. |
312 | 312 | * @return string |
313 | 313 | */ |
314 | - public function get_due_date_gmt( $context = 'view' ) { |
|
315 | - $date = $this->get_due_date( $context ); |
|
314 | + public function get_due_date_gmt($context = 'view') { |
|
315 | + $date = $this->get_due_date($context); |
|
316 | 316 | |
317 | - if ( $date ) { |
|
318 | - $date = get_gmt_from_date( $date ); |
|
317 | + if ($date) { |
|
318 | + $date = get_gmt_from_date($date); |
|
319 | 319 | } |
320 | 320 | return $date; |
321 | 321 | } |
@@ -327,8 +327,8 @@ discard block |
||
327 | 327 | * @param string $context View or edit context. |
328 | 328 | * @return string |
329 | 329 | */ |
330 | - public function get_gmt_date_due( $context = 'view' ) { |
|
331 | - return $this->get_due_date_gmt( $context ); |
|
330 | + public function get_gmt_date_due($context = 'view') { |
|
331 | + return $this->get_due_date_gmt($context); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
@@ -338,8 +338,8 @@ discard block |
||
338 | 338 | * @param string $context View or edit context. |
339 | 339 | * @return string |
340 | 340 | */ |
341 | - public function get_completed_date( $context = 'view' ) { |
|
342 | - return $this->get_prop( 'completed_date', $context ); |
|
341 | + public function get_completed_date($context = 'view') { |
|
342 | + return $this->get_prop('completed_date', $context); |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
@@ -349,8 +349,8 @@ discard block |
||
349 | 349 | * @param string $context View or edit context. |
350 | 350 | * @return string |
351 | 351 | */ |
352 | - public function get_date_completed( $context = 'view' ) { |
|
353 | - return $this->get_completed_date( $context ); |
|
352 | + public function get_date_completed($context = 'view') { |
|
353 | + return $this->get_completed_date($context); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | * @param string $context View or edit context. |
361 | 361 | * @return string |
362 | 362 | */ |
363 | - public function get_completed_date_gmt( $context = 'view' ) { |
|
364 | - $date = $this->get_completed_date( $context ); |
|
363 | + public function get_completed_date_gmt($context = 'view') { |
|
364 | + $date = $this->get_completed_date($context); |
|
365 | 365 | |
366 | - if ( $date ) { |
|
367 | - $date = get_gmt_from_date( $date ); |
|
366 | + if ($date) { |
|
367 | + $date = get_gmt_from_date($date); |
|
368 | 368 | } |
369 | 369 | return $date; |
370 | 370 | } |
@@ -376,8 +376,8 @@ discard block |
||
376 | 376 | * @param string $context View or edit context. |
377 | 377 | * @return string |
378 | 378 | */ |
379 | - public function get_gmt_completed_date( $context = 'view' ) { |
|
380 | - return $this->get_completed_date_gmt( $context ); |
|
379 | + public function get_gmt_completed_date($context = 'view') { |
|
380 | + return $this->get_completed_date_gmt($context); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | /** |
@@ -387,12 +387,12 @@ discard block |
||
387 | 387 | * @param string $context View or edit context. |
388 | 388 | * @return string |
389 | 389 | */ |
390 | - public function get_number( $context = 'view' ) { |
|
391 | - $number = $this->get_prop( 'number', $context ); |
|
390 | + public function get_number($context = 'view') { |
|
391 | + $number = $this->get_prop('number', $context); |
|
392 | 392 | |
393 | - if ( empty( $number ) ) { |
|
393 | + if (empty($number)) { |
|
394 | 394 | $number = $this->generate_number(); |
395 | - $this->set_number( $number ); |
|
395 | + $this->set_number($number); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | return $number; |
@@ -405,12 +405,12 @@ discard block |
||
405 | 405 | * @param string $context View or edit context. |
406 | 406 | * @return string |
407 | 407 | */ |
408 | - public function get_key( $context = 'view' ) { |
|
409 | - $key = $this->get_prop( 'key', $context ); |
|
408 | + public function get_key($context = 'view') { |
|
409 | + $key = $this->get_prop('key', $context); |
|
410 | 410 | |
411 | - if ( empty( $key ) ) { |
|
412 | - $key = $this->generate_key( $this->post_type ); |
|
413 | - $this->set_key( $key ); |
|
411 | + if (empty($key)) { |
|
412 | + $key = $this->generate_key($this->post_type); |
|
413 | + $this->set_key($key); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | return $key; |
@@ -423,8 +423,8 @@ discard block |
||
423 | 423 | * @param string $context View or edit context. |
424 | 424 | * @return string |
425 | 425 | */ |
426 | - public function get_type( $context = 'view' ) { |
|
427 | - return $this->get_prop( 'type', $context ); |
|
426 | + public function get_type($context = 'view') { |
|
427 | + return $this->get_prop('type', $context); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | * @param string $context View or edit context. |
435 | 435 | * @return string |
436 | 436 | */ |
437 | - public function get_mode( $context = 'view' ) { |
|
438 | - return $this->get_prop( 'mode', $context ); |
|
437 | + public function get_mode($context = 'view') { |
|
438 | + return $this->get_prop('mode', $context); |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | /** |
@@ -445,10 +445,10 @@ discard block |
||
445 | 445 | * @param string $context View or edit context. |
446 | 446 | * @return string |
447 | 447 | */ |
448 | - public function get_name( $context = 'view' ) { |
|
449 | - $name = $this->get_prop( 'title', $context ); |
|
448 | + public function get_name($context = 'view') { |
|
449 | + $name = $this->get_prop('title', $context); |
|
450 | 450 | |
451 | - return empty( $name ) ? $this->get_number( $context ) : $name; |
|
451 | + return empty($name) ? $this->get_number($context) : $name; |
|
452 | 452 | } |
453 | 453 | |
454 | 454 | /** |
@@ -458,8 +458,8 @@ discard block |
||
458 | 458 | * @param string $context View or edit context. |
459 | 459 | * @return string |
460 | 460 | */ |
461 | - public function get_title( $context = 'view' ) { |
|
462 | - return $this->get_name( $context ); |
|
461 | + public function get_title($context = 'view') { |
|
462 | + return $this->get_name($context); |
|
463 | 463 | } |
464 | 464 | |
465 | 465 | /** |
@@ -469,8 +469,8 @@ discard block |
||
469 | 469 | * @param string $context View or edit context. |
470 | 470 | * @return string |
471 | 471 | */ |
472 | - public function get_description( $context = 'view' ) { |
|
473 | - return $this->get_prop( 'description', $context ); |
|
472 | + public function get_description($context = 'view') { |
|
473 | + return $this->get_prop('description', $context); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -480,8 +480,8 @@ discard block |
||
480 | 480 | * @param string $context View or edit context. |
481 | 481 | * @return string |
482 | 482 | */ |
483 | - public function get_excerpt( $context = 'view' ) { |
|
484 | - return $this->get_description( $context ); |
|
483 | + public function get_excerpt($context = 'view') { |
|
484 | + return $this->get_description($context); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | /** |
@@ -491,8 +491,8 @@ discard block |
||
491 | 491 | * @param string $context View or edit context. |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - public function get_summary( $context = 'view' ) { |
|
495 | - return $this->get_description( $context ); |
|
494 | + public function get_summary($context = 'view') { |
|
495 | + return $this->get_description($context); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | /** |
@@ -502,8 +502,8 @@ discard block |
||
502 | 502 | * @param string $context View or edit context. |
503 | 503 | * @return int |
504 | 504 | */ |
505 | - public function get_author( $context = 'view' ) { |
|
506 | - return (int) $this->get_prop( 'author', $context ); |
|
505 | + public function get_author($context = 'view') { |
|
506 | + return (int) $this->get_prop('author', $context); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -513,8 +513,8 @@ discard block |
||
513 | 513 | * @param string $context View or edit context. |
514 | 514 | * @return int |
515 | 515 | */ |
516 | - public function get_user_id( $context = 'view' ) { |
|
517 | - return $this->get_author( $context ); |
|
516 | + public function get_user_id($context = 'view') { |
|
517 | + return $this->get_author($context); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | /** |
@@ -524,8 +524,8 @@ discard block |
||
524 | 524 | * @param string $context View or edit context. |
525 | 525 | * @return int |
526 | 526 | */ |
527 | - public function get_customer_id( $context = 'view' ) { |
|
528 | - return $this->get_author( $context ); |
|
527 | + public function get_customer_id($context = 'view') { |
|
528 | + return $this->get_author($context); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | /** |
@@ -535,8 +535,8 @@ discard block |
||
535 | 535 | * @param string $context View or edit context. |
536 | 536 | * @return string |
537 | 537 | */ |
538 | - public function get_ip( $context = 'view' ) { |
|
539 | - return $this->get_prop( 'user_ip', $context ); |
|
538 | + public function get_ip($context = 'view') { |
|
539 | + return $this->get_prop('user_ip', $context); |
|
540 | 540 | } |
541 | 541 | |
542 | 542 | /** |
@@ -546,8 +546,8 @@ discard block |
||
546 | 546 | * @param string $context View or edit context. |
547 | 547 | * @return int |
548 | 548 | */ |
549 | - public function get_user_ip( $context = 'view' ) { |
|
550 | - return $this->get_ip( $context ); |
|
549 | + public function get_user_ip($context = 'view') { |
|
550 | + return $this->get_ip($context); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
@@ -557,8 +557,8 @@ discard block |
||
557 | 557 | * @param string $context View or edit context. |
558 | 558 | * @return int |
559 | 559 | */ |
560 | - public function get_customer_ip( $context = 'view' ) { |
|
561 | - return $this->get_ip( $context ); |
|
560 | + public function get_customer_ip($context = 'view') { |
|
561 | + return $this->get_ip($context); |
|
562 | 562 | } |
563 | 563 | |
564 | 564 | /** |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | * @param string $context View or edit context. |
569 | 569 | * @return string |
570 | 570 | */ |
571 | - public function get_first_name( $context = 'view' ) { |
|
572 | - return $this->get_prop( 'first_name', $context ); |
|
571 | + public function get_first_name($context = 'view') { |
|
572 | + return $this->get_prop('first_name', $context); |
|
573 | 573 | } |
574 | 574 | |
575 | 575 | /** |
@@ -579,8 +579,8 @@ discard block |
||
579 | 579 | * @param string $context View or edit context. |
580 | 580 | * @return int |
581 | 581 | */ |
582 | - public function get_user_first_name( $context = 'view' ) { |
|
583 | - return $this->get_first_name( $context ); |
|
582 | + public function get_user_first_name($context = 'view') { |
|
583 | + return $this->get_first_name($context); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -590,8 +590,8 @@ discard block |
||
590 | 590 | * @param string $context View or edit context. |
591 | 591 | * @return int |
592 | 592 | */ |
593 | - public function get_customer_first_name( $context = 'view' ) { |
|
594 | - return $this->get_first_name( $context ); |
|
593 | + public function get_customer_first_name($context = 'view') { |
|
594 | + return $this->get_first_name($context); |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | /** |
@@ -601,8 +601,8 @@ discard block |
||
601 | 601 | * @param string $context View or edit context. |
602 | 602 | * @return string |
603 | 603 | */ |
604 | - public function get_last_name( $context = 'view' ) { |
|
605 | - return $this->get_prop( 'last_name', $context ); |
|
604 | + public function get_last_name($context = 'view') { |
|
605 | + return $this->get_prop('last_name', $context); |
|
606 | 606 | } |
607 | 607 | |
608 | 608 | /** |
@@ -612,8 +612,8 @@ discard block |
||
612 | 612 | * @param string $context View or edit context. |
613 | 613 | * @return int |
614 | 614 | */ |
615 | - public function get_user_last_name( $context = 'view' ) { |
|
616 | - return $this->get_last_name( $context ); |
|
615 | + public function get_user_last_name($context = 'view') { |
|
616 | + return $this->get_last_name($context); |
|
617 | 617 | } |
618 | 618 | |
619 | 619 | /** |
@@ -623,8 +623,8 @@ discard block |
||
623 | 623 | * @param string $context View or edit context. |
624 | 624 | * @return int |
625 | 625 | */ |
626 | - public function get_customer_last_name( $context = 'view' ) { |
|
627 | - return $this->get_last_name( $context ); |
|
626 | + public function get_customer_last_name($context = 'view') { |
|
627 | + return $this->get_last_name($context); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | /** |
@@ -634,8 +634,8 @@ discard block |
||
634 | 634 | * @param string $context View or edit context. |
635 | 635 | * @return string |
636 | 636 | */ |
637 | - public function get_full_name( $context = 'view' ) { |
|
638 | - return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) ); |
|
637 | + public function get_full_name($context = 'view') { |
|
638 | + return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context)); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | /** |
@@ -645,8 +645,8 @@ discard block |
||
645 | 645 | * @param string $context View or edit context. |
646 | 646 | * @return int |
647 | 647 | */ |
648 | - public function get_user_full_name( $context = 'view' ) { |
|
649 | - return $this->get_full_name( $context ); |
|
648 | + public function get_user_full_name($context = 'view') { |
|
649 | + return $this->get_full_name($context); |
|
650 | 650 | } |
651 | 651 | |
652 | 652 | /** |
@@ -656,8 +656,8 @@ discard block |
||
656 | 656 | * @param string $context View or edit context. |
657 | 657 | * @return int |
658 | 658 | */ |
659 | - public function get_customer_full_name( $context = 'view' ) { |
|
660 | - return $this->get_full_name( $context ); |
|
659 | + public function get_customer_full_name($context = 'view') { |
|
660 | + return $this->get_full_name($context); |
|
661 | 661 | } |
662 | 662 | |
663 | 663 | /** |
@@ -667,8 +667,8 @@ discard block |
||
667 | 667 | * @param string $context View or edit context. |
668 | 668 | * @return string |
669 | 669 | */ |
670 | - public function get_phone( $context = 'view' ) { |
|
671 | - return $this->get_prop( 'phone', $context ); |
|
670 | + public function get_phone($context = 'view') { |
|
671 | + return $this->get_prop('phone', $context); |
|
672 | 672 | } |
673 | 673 | |
674 | 674 | /** |
@@ -678,8 +678,8 @@ discard block |
||
678 | 678 | * @param string $context View or edit context. |
679 | 679 | * @return int |
680 | 680 | */ |
681 | - public function get_phone_number( $context = 'view' ) { |
|
682 | - return $this->get_phone( $context ); |
|
681 | + public function get_phone_number($context = 'view') { |
|
682 | + return $this->get_phone($context); |
|
683 | 683 | } |
684 | 684 | |
685 | 685 | /** |
@@ -689,8 +689,8 @@ discard block |
||
689 | 689 | * @param string $context View or edit context. |
690 | 690 | * @return int |
691 | 691 | */ |
692 | - public function get_user_phone( $context = 'view' ) { |
|
693 | - return $this->get_phone( $context ); |
|
692 | + public function get_user_phone($context = 'view') { |
|
693 | + return $this->get_phone($context); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | /** |
@@ -700,8 +700,8 @@ discard block |
||
700 | 700 | * @param string $context View or edit context. |
701 | 701 | * @return int |
702 | 702 | */ |
703 | - public function get_customer_phone( $context = 'view' ) { |
|
704 | - return $this->get_phone( $context ); |
|
703 | + public function get_customer_phone($context = 'view') { |
|
704 | + return $this->get_phone($context); |
|
705 | 705 | } |
706 | 706 | |
707 | 707 | /** |
@@ -711,8 +711,8 @@ discard block |
||
711 | 711 | * @param string $context View or edit context. |
712 | 712 | * @return string |
713 | 713 | */ |
714 | - public function get_email( $context = 'view' ) { |
|
715 | - return $this->get_prop( 'email', $context ); |
|
714 | + public function get_email($context = 'view') { |
|
715 | + return $this->get_prop('email', $context); |
|
716 | 716 | } |
717 | 717 | |
718 | 718 | /** |
@@ -722,8 +722,8 @@ discard block |
||
722 | 722 | * @param string $context View or edit context. |
723 | 723 | * @return string |
724 | 724 | */ |
725 | - public function get_email_address( $context = 'view' ) { |
|
726 | - return $this->get_email( $context ); |
|
725 | + public function get_email_address($context = 'view') { |
|
726 | + return $this->get_email($context); |
|
727 | 727 | } |
728 | 728 | |
729 | 729 | /** |
@@ -733,8 +733,8 @@ discard block |
||
733 | 733 | * @param string $context View or edit context. |
734 | 734 | * @return int |
735 | 735 | */ |
736 | - public function get_user_email( $context = 'view' ) { |
|
737 | - return $this->get_email( $context ); |
|
736 | + public function get_user_email($context = 'view') { |
|
737 | + return $this->get_email($context); |
|
738 | 738 | } |
739 | 739 | |
740 | 740 | /** |
@@ -744,8 +744,8 @@ discard block |
||
744 | 744 | * @param string $context View or edit context. |
745 | 745 | * @return int |
746 | 746 | */ |
747 | - public function get_customer_email( $context = 'view' ) { |
|
748 | - return $this->get_email( $context ); |
|
747 | + public function get_customer_email($context = 'view') { |
|
748 | + return $this->get_email($context); |
|
749 | 749 | } |
750 | 750 | |
751 | 751 | /** |
@@ -755,8 +755,8 @@ discard block |
||
755 | 755 | * @param string $context View or edit context. |
756 | 756 | * @return string |
757 | 757 | */ |
758 | - public function get_country( $context = 'view' ) { |
|
759 | - return $this->get_prop( 'country', $context ); |
|
758 | + public function get_country($context = 'view') { |
|
759 | + return $this->get_prop('country', $context); |
|
760 | 760 | } |
761 | 761 | |
762 | 762 | /** |
@@ -766,8 +766,8 @@ discard block |
||
766 | 766 | * @param string $context View or edit context. |
767 | 767 | * @return int |
768 | 768 | */ |
769 | - public function get_user_country( $context = 'view' ) { |
|
770 | - return $this->get_country( $context ); |
|
769 | + public function get_user_country($context = 'view') { |
|
770 | + return $this->get_country($context); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | /** |
@@ -777,8 +777,8 @@ discard block |
||
777 | 777 | * @param string $context View or edit context. |
778 | 778 | * @return int |
779 | 779 | */ |
780 | - public function get_customer_country( $context = 'view' ) { |
|
781 | - return $this->get_country( $context ); |
|
780 | + public function get_customer_country($context = 'view') { |
|
781 | + return $this->get_country($context); |
|
782 | 782 | } |
783 | 783 | |
784 | 784 | /** |
@@ -788,8 +788,8 @@ discard block |
||
788 | 788 | * @param string $context View or edit context. |
789 | 789 | * @return string |
790 | 790 | */ |
791 | - public function get_state( $context = 'view' ) { |
|
792 | - return $this->get_prop( 'state', $context ); |
|
791 | + public function get_state($context = 'view') { |
|
792 | + return $this->get_prop('state', $context); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
@@ -799,8 +799,8 @@ discard block |
||
799 | 799 | * @param string $context View or edit context. |
800 | 800 | * @return int |
801 | 801 | */ |
802 | - public function get_user_state( $context = 'view' ) { |
|
803 | - return $this->get_state( $context ); |
|
802 | + public function get_user_state($context = 'view') { |
|
803 | + return $this->get_state($context); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | /** |
@@ -810,8 +810,8 @@ discard block |
||
810 | 810 | * @param string $context View or edit context. |
811 | 811 | * @return int |
812 | 812 | */ |
813 | - public function get_customer_state( $context = 'view' ) { |
|
814 | - return $this->get_state( $context ); |
|
813 | + public function get_customer_state($context = 'view') { |
|
814 | + return $this->get_state($context); |
|
815 | 815 | } |
816 | 816 | |
817 | 817 | /** |
@@ -821,8 +821,8 @@ discard block |
||
821 | 821 | * @param string $context View or edit context. |
822 | 822 | * @return string |
823 | 823 | */ |
824 | - public function get_city( $context = 'view' ) { |
|
825 | - return $this->get_prop( 'city', $context ); |
|
824 | + public function get_city($context = 'view') { |
|
825 | + return $this->get_prop('city', $context); |
|
826 | 826 | } |
827 | 827 | |
828 | 828 | /** |
@@ -832,8 +832,8 @@ discard block |
||
832 | 832 | * @param string $context View or edit context. |
833 | 833 | * @return string |
834 | 834 | */ |
835 | - public function get_user_city( $context = 'view' ) { |
|
836 | - return $this->get_city( $context ); |
|
835 | + public function get_user_city($context = 'view') { |
|
836 | + return $this->get_city($context); |
|
837 | 837 | } |
838 | 838 | |
839 | 839 | /** |
@@ -843,8 +843,8 @@ discard block |
||
843 | 843 | * @param string $context View or edit context. |
844 | 844 | * @return string |
845 | 845 | */ |
846 | - public function get_customer_city( $context = 'view' ) { |
|
847 | - return $this->get_city( $context ); |
|
846 | + public function get_customer_city($context = 'view') { |
|
847 | + return $this->get_city($context); |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | /** |
@@ -854,8 +854,8 @@ discard block |
||
854 | 854 | * @param string $context View or edit context. |
855 | 855 | * @return string |
856 | 856 | */ |
857 | - public function get_zip( $context = 'view' ) { |
|
858 | - return $this->get_prop( 'zip', $context ); |
|
857 | + public function get_zip($context = 'view') { |
|
858 | + return $this->get_prop('zip', $context); |
|
859 | 859 | } |
860 | 860 | |
861 | 861 | /** |
@@ -865,8 +865,8 @@ discard block |
||
865 | 865 | * @param string $context View or edit context. |
866 | 866 | * @return string |
867 | 867 | */ |
868 | - public function get_user_zip( $context = 'view' ) { |
|
869 | - return $this->get_zip( $context ); |
|
868 | + public function get_user_zip($context = 'view') { |
|
869 | + return $this->get_zip($context); |
|
870 | 870 | } |
871 | 871 | |
872 | 872 | /** |
@@ -876,8 +876,8 @@ discard block |
||
876 | 876 | * @param string $context View or edit context. |
877 | 877 | * @return string |
878 | 878 | */ |
879 | - public function get_customer_zip( $context = 'view' ) { |
|
880 | - return $this->get_zip( $context ); |
|
879 | + public function get_customer_zip($context = 'view') { |
|
880 | + return $this->get_zip($context); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | /** |
@@ -887,8 +887,8 @@ discard block |
||
887 | 887 | * @param string $context View or edit context. |
888 | 888 | * @return string |
889 | 889 | */ |
890 | - public function get_company( $context = 'view' ) { |
|
891 | - return $this->get_prop( 'company', $context ); |
|
890 | + public function get_company($context = 'view') { |
|
891 | + return $this->get_prop('company', $context); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
@@ -898,8 +898,8 @@ discard block |
||
898 | 898 | * @param string $context View or edit context. |
899 | 899 | * @return string |
900 | 900 | */ |
901 | - public function get_user_company( $context = 'view' ) { |
|
902 | - return $this->get_company( $context ); |
|
901 | + public function get_user_company($context = 'view') { |
|
902 | + return $this->get_company($context); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | /** |
@@ -909,8 +909,8 @@ discard block |
||
909 | 909 | * @param string $context View or edit context. |
910 | 910 | * @return string |
911 | 911 | */ |
912 | - public function get_customer_company( $context = 'view' ) { |
|
913 | - return $this->get_company( $context ); |
|
912 | + public function get_customer_company($context = 'view') { |
|
913 | + return $this->get_company($context); |
|
914 | 914 | } |
915 | 915 | |
916 | 916 | /** |
@@ -920,8 +920,8 @@ discard block |
||
920 | 920 | * @param string $context View or edit context. |
921 | 921 | * @return string |
922 | 922 | */ |
923 | - public function get_vat_number( $context = 'view' ) { |
|
924 | - return $this->get_prop( 'vat_number', $context ); |
|
923 | + public function get_vat_number($context = 'view') { |
|
924 | + return $this->get_prop('vat_number', $context); |
|
925 | 925 | } |
926 | 926 | |
927 | 927 | /** |
@@ -931,8 +931,8 @@ discard block |
||
931 | 931 | * @param string $context View or edit context. |
932 | 932 | * @return string |
933 | 933 | */ |
934 | - public function get_user_vat_number( $context = 'view' ) { |
|
935 | - return $this->get_vat_number( $context ); |
|
934 | + public function get_user_vat_number($context = 'view') { |
|
935 | + return $this->get_vat_number($context); |
|
936 | 936 | } |
937 | 937 | |
938 | 938 | /** |
@@ -942,8 +942,8 @@ discard block |
||
942 | 942 | * @param string $context View or edit context. |
943 | 943 | * @return string |
944 | 944 | */ |
945 | - public function get_customer_vat_number( $context = 'view' ) { |
|
946 | - return $this->get_vat_number( $context ); |
|
945 | + public function get_customer_vat_number($context = 'view') { |
|
946 | + return $this->get_vat_number($context); |
|
947 | 947 | } |
948 | 948 | |
949 | 949 | /** |
@@ -953,8 +953,8 @@ discard block |
||
953 | 953 | * @param string $context View or edit context. |
954 | 954 | * @return string |
955 | 955 | */ |
956 | - public function get_vat_rate( $context = 'view' ) { |
|
957 | - return $this->get_prop( 'vat_rate', $context ); |
|
956 | + public function get_vat_rate($context = 'view') { |
|
957 | + return $this->get_prop('vat_rate', $context); |
|
958 | 958 | } |
959 | 959 | |
960 | 960 | /** |
@@ -964,8 +964,8 @@ discard block |
||
964 | 964 | * @param string $context View or edit context. |
965 | 965 | * @return string |
966 | 966 | */ |
967 | - public function get_user_vat_rate( $context = 'view' ) { |
|
968 | - return $this->get_vat_rate( $context ); |
|
967 | + public function get_user_vat_rate($context = 'view') { |
|
968 | + return $this->get_vat_rate($context); |
|
969 | 969 | } |
970 | 970 | |
971 | 971 | /** |
@@ -975,8 +975,8 @@ discard block |
||
975 | 975 | * @param string $context View or edit context. |
976 | 976 | * @return string |
977 | 977 | */ |
978 | - public function get_customer_vat_rate( $context = 'view' ) { |
|
979 | - return $this->get_vat_rate( $context ); |
|
978 | + public function get_customer_vat_rate($context = 'view') { |
|
979 | + return $this->get_vat_rate($context); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | /** |
@@ -986,8 +986,8 @@ discard block |
||
986 | 986 | * @param string $context View or edit context. |
987 | 987 | * @return string |
988 | 988 | */ |
989 | - public function get_address( $context = 'view' ) { |
|
990 | - return $this->get_prop( 'address', $context ); |
|
989 | + public function get_address($context = 'view') { |
|
990 | + return $this->get_prop('address', $context); |
|
991 | 991 | } |
992 | 992 | |
993 | 993 | /** |
@@ -997,8 +997,8 @@ discard block |
||
997 | 997 | * @param string $context View or edit context. |
998 | 998 | * @return string |
999 | 999 | */ |
1000 | - public function get_user_address( $context = 'view' ) { |
|
1001 | - return $this->get_address( $context ); |
|
1000 | + public function get_user_address($context = 'view') { |
|
1001 | + return $this->get_address($context); |
|
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | /** |
@@ -1008,8 +1008,8 @@ discard block |
||
1008 | 1008 | * @param string $context View or edit context. |
1009 | 1009 | * @return string |
1010 | 1010 | */ |
1011 | - public function get_customer_address( $context = 'view' ) { |
|
1012 | - return $this->get_address( $context ); |
|
1011 | + public function get_customer_address($context = 'view') { |
|
1012 | + return $this->get_address($context); |
|
1013 | 1013 | } |
1014 | 1014 | |
1015 | 1015 | /** |
@@ -1019,8 +1019,8 @@ discard block |
||
1019 | 1019 | * @param string $context View or edit context. |
1020 | 1020 | * @return bool |
1021 | 1021 | */ |
1022 | - public function get_address_confirmed( $context = 'view' ) { |
|
1023 | - return (bool) $this->get_prop( 'address_confirmed', $context ); |
|
1022 | + public function get_address_confirmed($context = 'view') { |
|
1023 | + return (bool) $this->get_prop('address_confirmed', $context); |
|
1024 | 1024 | } |
1025 | 1025 | |
1026 | 1026 | /** |
@@ -1030,8 +1030,8 @@ discard block |
||
1030 | 1030 | * @param string $context View or edit context. |
1031 | 1031 | * @return bool |
1032 | 1032 | */ |
1033 | - public function get_user_address_confirmed( $context = 'view' ) { |
|
1034 | - return $this->get_address_confirmed( $context ); |
|
1033 | + public function get_user_address_confirmed($context = 'view') { |
|
1034 | + return $this->get_address_confirmed($context); |
|
1035 | 1035 | } |
1036 | 1036 | |
1037 | 1037 | /** |
@@ -1041,8 +1041,8 @@ discard block |
||
1041 | 1041 | * @param string $context View or edit context. |
1042 | 1042 | * @return bool |
1043 | 1043 | */ |
1044 | - public function get_customer_address_confirmed( $context = 'view' ) { |
|
1045 | - return $this->get_address_confirmed( $context ); |
|
1044 | + public function get_customer_address_confirmed($context = 'view') { |
|
1045 | + return $this->get_address_confirmed($context); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | * @param string $context View or edit context. |
1053 | 1053 | * @return float |
1054 | 1054 | */ |
1055 | - public function get_subtotal( $context = 'view' ) { |
|
1056 | - return (float) $this->get_prop( 'subtotal', $context ); |
|
1055 | + public function get_subtotal($context = 'view') { |
|
1056 | + return (float) $this->get_prop('subtotal', $context); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | /** |
@@ -1063,8 +1063,8 @@ discard block |
||
1063 | 1063 | * @param string $context View or edit context. |
1064 | 1064 | * @return float |
1065 | 1065 | */ |
1066 | - public function get_total_discount( $context = 'view' ) { |
|
1067 | - return (float) $this->get_prop( 'total_discount', $context ); |
|
1066 | + public function get_total_discount($context = 'view') { |
|
1067 | + return (float) $this->get_prop('total_discount', $context); |
|
1068 | 1068 | } |
1069 | 1069 | |
1070 | 1070 | /** |
@@ -1074,8 +1074,8 @@ discard block |
||
1074 | 1074 | * @param string $context View or edit context. |
1075 | 1075 | * @return float |
1076 | 1076 | */ |
1077 | - public function get_total_tax( $context = 'view' ) { |
|
1078 | - return (float) $this->get_prop( 'total_tax', $context ); |
|
1077 | + public function get_total_tax($context = 'view') { |
|
1078 | + return (float) $this->get_prop('total_tax', $context); |
|
1079 | 1079 | } |
1080 | 1080 | |
1081 | 1081 | /** |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @param string $context View or edit context. |
1086 | 1086 | * @return float |
1087 | 1087 | */ |
1088 | - public function get_total_fees( $context = 'view' ) { |
|
1089 | - return (float) $this->get_prop( 'total_fees', $context ); |
|
1088 | + public function get_total_fees($context = 'view') { |
|
1089 | + return (float) $this->get_prop('total_fees', $context); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | /** |
@@ -1096,10 +1096,10 @@ discard block |
||
1096 | 1096 | * @param string $context View or edit context. |
1097 | 1097 | * @return float |
1098 | 1098 | */ |
1099 | - public function get_total( $context = 'view' ) { |
|
1100 | - $total = $this->get_subtotal( $context ) + $this->get_total_fees( $context ) - $this->get_total_discount( $context ) + $this->get_total_tax( $context ); |
|
1101 | - $total = apply_filters( 'getpaid_get_invoice_total_amount', $total, $this ); |
|
1102 | - return (float) wpinv_sanitize_amount( $total ); |
|
1099 | + public function get_total($context = 'view') { |
|
1100 | + $total = $this->get_subtotal($context) + $this->get_total_fees($context) - $this->get_total_discount($context) + $this->get_total_tax($context); |
|
1101 | + $total = apply_filters('getpaid_get_invoice_total_amount', $total, $this); |
|
1102 | + return (float) wpinv_sanitize_amount($total); |
|
1103 | 1103 | } |
1104 | 1104 | |
1105 | 1105 | /** |
@@ -1109,8 +1109,8 @@ discard block |
||
1109 | 1109 | * @param string $context View or edit context. |
1110 | 1110 | * @return array |
1111 | 1111 | */ |
1112 | - public function get_fees( $context = 'view' ) { |
|
1113 | - return wpinv_parse_list( $this->get_prop( 'fees', $context ) ); |
|
1112 | + public function get_fees($context = 'view') { |
|
1113 | + return wpinv_parse_list($this->get_prop('fees', $context)); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | /** |
@@ -1120,8 +1120,8 @@ discard block |
||
1120 | 1120 | * @param string $context View or edit context. |
1121 | 1121 | * @return array |
1122 | 1122 | */ |
1123 | - public function get_discounts( $context = 'view' ) { |
|
1124 | - return wpinv_parse_list( $this->get_prop( 'discounts', $context ) ); |
|
1123 | + public function get_discounts($context = 'view') { |
|
1124 | + return wpinv_parse_list($this->get_prop('discounts', $context)); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | /** |
@@ -1131,8 +1131,8 @@ discard block |
||
1131 | 1131 | * @param string $context View or edit context. |
1132 | 1132 | * @return array |
1133 | 1133 | */ |
1134 | - public function get_taxes( $context = 'view' ) { |
|
1135 | - return wpinv_parse_list( $this->get_prop( 'taxes', $context ) ); |
|
1134 | + public function get_taxes($context = 'view') { |
|
1135 | + return wpinv_parse_list($this->get_prop('taxes', $context)); |
|
1136 | 1136 | } |
1137 | 1137 | |
1138 | 1138 | /** |
@@ -1142,8 +1142,8 @@ discard block |
||
1142 | 1142 | * @param string $context View or edit context. |
1143 | 1143 | * @return array |
1144 | 1144 | */ |
1145 | - public function get_items( $context = 'view' ) { |
|
1146 | - return wpinv_parse_list( $this->get_prop( 'items', $context ) ); |
|
1145 | + public function get_items($context = 'view') { |
|
1146 | + return wpinv_parse_list($this->get_prop('items', $context)); |
|
1147 | 1147 | } |
1148 | 1148 | |
1149 | 1149 | /** |
@@ -1153,8 +1153,8 @@ discard block |
||
1153 | 1153 | * @param string $context View or edit context. |
1154 | 1154 | * @return int |
1155 | 1155 | */ |
1156 | - public function get_payment_form( $context = 'view' ) { |
|
1157 | - return intval( $this->get_prop( 'payment_form', $context ) ); |
|
1156 | + public function get_payment_form($context = 'view') { |
|
1157 | + return intval($this->get_prop('payment_form', $context)); |
|
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | /** |
@@ -1164,8 +1164,8 @@ discard block |
||
1164 | 1164 | * @param string $context View or edit context. |
1165 | 1165 | * @return string |
1166 | 1166 | */ |
1167 | - public function get_submission_id( $context = 'view' ) { |
|
1168 | - return $this->get_prop( 'submission_id', $context ); |
|
1167 | + public function get_submission_id($context = 'view') { |
|
1168 | + return $this->get_prop('submission_id', $context); |
|
1169 | 1169 | } |
1170 | 1170 | |
1171 | 1171 | /** |
@@ -1175,8 +1175,8 @@ discard block |
||
1175 | 1175 | * @param string $context View or edit context. |
1176 | 1176 | * @return string |
1177 | 1177 | */ |
1178 | - public function get_discount_code( $context = 'view' ) { |
|
1179 | - return $this->get_prop( 'discount_code', $context ); |
|
1178 | + public function get_discount_code($context = 'view') { |
|
1179 | + return $this->get_prop('discount_code', $context); |
|
1180 | 1180 | } |
1181 | 1181 | |
1182 | 1182 | /** |
@@ -1186,8 +1186,8 @@ discard block |
||
1186 | 1186 | * @param string $context View or edit context. |
1187 | 1187 | * @return string |
1188 | 1188 | */ |
1189 | - public function get_gateway( $context = 'view' ) { |
|
1190 | - return $this->get_prop( 'gateway', $context ); |
|
1189 | + public function get_gateway($context = 'view') { |
|
1190 | + return $this->get_prop('gateway', $context); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | 1193 | /** |
@@ -1197,8 +1197,8 @@ discard block |
||
1197 | 1197 | * @param string $context View or edit context. |
1198 | 1198 | * @return string |
1199 | 1199 | */ |
1200 | - public function get_transaction_id( $context = 'view' ) { |
|
1201 | - return $this->get_prop( 'transaction_id', $context ); |
|
1200 | + public function get_transaction_id($context = 'view') { |
|
1201 | + return $this->get_prop('transaction_id', $context); |
|
1202 | 1202 | } |
1203 | 1203 | |
1204 | 1204 | /** |
@@ -1208,9 +1208,9 @@ discard block |
||
1208 | 1208 | * @param string $context View or edit context. |
1209 | 1209 | * @return string |
1210 | 1210 | */ |
1211 | - public function get_currency( $context = 'view' ) { |
|
1212 | - $currency = $this->get_prop( 'currency', $context ); |
|
1213 | - return empty( $currency ) ? wpinv_get_currency() : $currency; |
|
1211 | + public function get_currency($context = 'view') { |
|
1212 | + $currency = $this->get_prop('currency', $context); |
|
1213 | + return empty($currency) ? wpinv_get_currency() : $currency; |
|
1214 | 1214 | } |
1215 | 1215 | |
1216 | 1216 | /** |
@@ -1220,16 +1220,16 @@ discard block |
||
1220 | 1220 | * @param string $context View or edit context. |
1221 | 1221 | * @return bool |
1222 | 1222 | */ |
1223 | - public function get_disable_taxes( $context = 'view' ) { |
|
1224 | - return (bool) $this->get_prop( 'disable_taxes', $context ); |
|
1223 | + public function get_disable_taxes($context = 'view') { |
|
1224 | + return (bool) $this->get_prop('disable_taxes', $context); |
|
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | /** |
1228 | 1228 | * Retrieves an invoice key. |
1229 | 1229 | */ |
1230 | - public function get( $key ) { |
|
1231 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
1232 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
1230 | + public function get($key) { |
|
1231 | + if (method_exists($this, 'get_' . $key)) { |
|
1232 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
1233 | 1233 | } else { |
1234 | 1234 | $value = $this->$key; |
1235 | 1235 | } |
@@ -1240,18 +1240,18 @@ discard block |
||
1240 | 1240 | /** |
1241 | 1241 | * Sets an invoice key. |
1242 | 1242 | */ |
1243 | - public function set( $key, $value ) { |
|
1244 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
1243 | + public function set($key, $value) { |
|
1244 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
1245 | 1245 | |
1246 | - if ( $key === 'status' ) { |
|
1246 | + if ($key === 'status') { |
|
1247 | 1247 | $this->old_status = $this->status; |
1248 | 1248 | } |
1249 | 1249 | |
1250 | - if ( ! in_array( $key, $ignore ) ) { |
|
1251 | - $this->pending[ $key ] = $value; |
|
1250 | + if (!in_array($key, $ignore)) { |
|
1251 | + $this->pending[$key] = $value; |
|
1252 | 1252 | } |
1253 | 1253 | |
1254 | - if( '_ID' !== $key ) { |
|
1254 | + if ('_ID' !== $key) { |
|
1255 | 1255 | $this->$key = $value; |
1256 | 1256 | } |
1257 | 1257 | } |
@@ -1259,9 +1259,9 @@ discard block |
||
1259 | 1259 | /** |
1260 | 1260 | * Checks if an invoice key is set. |
1261 | 1261 | */ |
1262 | - public function _isset( $name ) { |
|
1263 | - if ( property_exists( $this, $name) ) { |
|
1264 | - return false === empty( $this->$name ); |
|
1262 | + public function _isset($name) { |
|
1263 | + if (property_exists($this, $name)) { |
|
1264 | + return false === empty($this->$name); |
|
1265 | 1265 | } else { |
1266 | 1266 | return null; |
1267 | 1267 | } |
@@ -1270,67 +1270,67 @@ discard block |
||
1270 | 1270 | /** |
1271 | 1271 | * @param int|WPInv_Invoice|WP_Post $invoice The invoice. |
1272 | 1272 | */ |
1273 | - private function setup_invoice( $invoice ) { |
|
1273 | + private function setup_invoice($invoice) { |
|
1274 | 1274 | global $wpdb; |
1275 | 1275 | $this->pending = array(); |
1276 | 1276 | |
1277 | - if ( empty( $invoice ) ) { |
|
1277 | + if (empty($invoice)) { |
|
1278 | 1278 | return false; |
1279 | 1279 | } |
1280 | 1280 | |
1281 | - if ( is_a( $invoice, 'WPInv_Invoice' ) ) { |
|
1282 | - foreach ( get_object_vars( $invoice ) as $prop => $value ) { |
|
1281 | + if (is_a($invoice, 'WPInv_Invoice')) { |
|
1282 | + foreach (get_object_vars($invoice) as $prop => $value) { |
|
1283 | 1283 | $this->$prop = $value; |
1284 | 1284 | } |
1285 | 1285 | return true; |
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | // Retrieve post object. |
1289 | - $invoice = get_post( $invoice ); |
|
1289 | + $invoice = get_post($invoice); |
|
1290 | 1290 | |
1291 | - if( ! $invoice || is_wp_error( $invoice ) ) { |
|
1291 | + if (!$invoice || is_wp_error($invoice)) { |
|
1292 | 1292 | return false; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | - if( ! ( 'wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type ) ) { |
|
1295 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
1296 | 1296 | return false; |
1297 | 1297 | } |
1298 | 1298 | |
1299 | 1299 | // Retrieve post data. |
1300 | 1300 | $table = $wpdb->prefix . 'getpaid_invoices'; |
1301 | 1301 | $data = $wpdb->get_row( |
1302 | - $wpdb->prepare( "SELECT * FROM $table WHERE post_id=%d", $invoice->ID ) |
|
1302 | + $wpdb->prepare("SELECT * FROM $table WHERE post_id=%d", $invoice->ID) |
|
1303 | 1303 | ); |
1304 | 1304 | |
1305 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice->ID, $data ); |
|
1305 | + do_action('wpinv_pre_setup_invoice', $this, $invoice->ID, $data); |
|
1306 | 1306 | |
1307 | 1307 | // Primary Identifier |
1308 | - $this->ID = absint( $invoice->ID ); |
|
1308 | + $this->ID = absint($invoice->ID); |
|
1309 | 1309 | $this->post_type = $invoice->post_type; |
1310 | 1310 | |
1311 | 1311 | $this->date = $invoice->post_date; |
1312 | 1312 | $this->status = $invoice->post_status; |
1313 | 1313 | |
1314 | - if ( 'future' == $this->status ) { |
|
1314 | + if ('future' == $this->status) { |
|
1315 | 1315 | $this->status = 'publish'; |
1316 | 1316 | } |
1317 | 1317 | |
1318 | 1318 | $this->post_status = $this->status; |
1319 | 1319 | $this->description = $invoice->post_excerpt; |
1320 | 1320 | $this->parent_invoice = $invoice->post_parent; |
1321 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
1322 | - $this->status_nicename = $this->setup_status_nicename( $invoice->post_status ); |
|
1321 | + $this->post_name = $this->setup_post_name($invoice); |
|
1322 | + $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
|
1323 | 1323 | |
1324 | - $this->user_id = ! empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id(); |
|
1325 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
1324 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); |
|
1325 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
1326 | 1326 | $this->currency = wpinv_get_currency(); |
1327 | - $this->setup_invoice_data( $data ); |
|
1327 | + $this->setup_invoice_data($data); |
|
1328 | 1328 | |
1329 | 1329 | // Other Identifiers |
1330 | - $this->title = ! empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
1330 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
1331 | 1331 | |
1332 | 1332 | // Allow extensions to add items to this object via hook |
1333 | - do_action( 'wpinv_setup_invoice', $this, $invoice->ID, $data ); |
|
1333 | + do_action('wpinv_setup_invoice', $this, $invoice->ID, $data); |
|
1334 | 1334 | |
1335 | 1335 | return true; |
1336 | 1336 | } |
@@ -1338,16 +1338,16 @@ discard block |
||
1338 | 1338 | /** |
1339 | 1339 | * @param stdClass $data The invoice data. |
1340 | 1340 | */ |
1341 | - private function setup_invoice_data( $data ) { |
|
1341 | + private function setup_invoice_data($data) { |
|
1342 | 1342 | |
1343 | - if ( empty( $data ) ) { |
|
1344 | - $this->number = $this->setup_invoice_number( $data ); |
|
1343 | + if (empty($data)) { |
|
1344 | + $this->number = $this->setup_invoice_number($data); |
|
1345 | 1345 | return; |
1346 | 1346 | } |
1347 | 1347 | |
1348 | - $data = map_deep( $data, 'maybe_unserialize' ); |
|
1348 | + $data = map_deep($data, 'maybe_unserialize'); |
|
1349 | 1349 | |
1350 | - $this->payment_meta = is_array( $data->custom_meta ) ? $data->custom_meta : array(); |
|
1350 | + $this->payment_meta = is_array($data->custom_meta) ? $data->custom_meta : array(); |
|
1351 | 1351 | $this->due_date = $data->due_date; |
1352 | 1352 | $this->completed_date = $data->completed_date; |
1353 | 1353 | $this->mode = $data->mode; |
@@ -1355,7 +1355,7 @@ discard block |
||
1355 | 1355 | // Items |
1356 | 1356 | $this->fees = $this->setup_fees(); |
1357 | 1357 | $this->cart_details = $this->setup_cart_details(); |
1358 | - $this->items = ! empty( $this->payment_meta['items'] ) ? $this->payment_meta['items'] : array(); |
|
1358 | + $this->items = !empty($this->payment_meta['items']) ? $this->payment_meta['items'] : array(); |
|
1359 | 1359 | |
1360 | 1360 | // Currency Based |
1361 | 1361 | $this->total = $data->total; |
@@ -1363,7 +1363,7 @@ discard block |
||
1363 | 1363 | $this->tax = $data->tax; |
1364 | 1364 | $this->fees_total = $data->fees_total; |
1365 | 1365 | $this->subtotal = $data->subtotal; |
1366 | - $this->currency = empty( $data->currency ) ? wpinv_get_currency() : $data->currency ; |
|
1366 | + $this->currency = empty($data->currency) ? wpinv_get_currency() : $data->currency; |
|
1367 | 1367 | |
1368 | 1368 | // Gateway based |
1369 | 1369 | $this->gateway = $data->gateway; |
@@ -1372,30 +1372,30 @@ discard block |
||
1372 | 1372 | |
1373 | 1373 | // User based |
1374 | 1374 | $this->ip = $data->user_ip; |
1375 | - $this->user_info = ! empty( $this->payment_meta['user_info'] ) ? $this->payment_meta['user_info'] : array(); |
|
1375 | + $this->user_info = !empty($this->payment_meta['user_info']) ? $this->payment_meta['user_info'] : array(); |
|
1376 | 1376 | |
1377 | 1377 | $this->first_name = $data->first_name; |
1378 | 1378 | $this->last_name = $data->last_name; |
1379 | 1379 | $this->company = $data->company; |
1380 | 1380 | $this->vat_number = $data->vat_number; |
1381 | 1381 | $this->vat_rate = $data->vat_rate; |
1382 | - $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
1382 | + $this->adddress_confirmed = (int) $data->adddress_confirmed; |
|
1383 | 1383 | $this->address = $data->address; |
1384 | 1384 | $this->city = $data->city; |
1385 | 1385 | $this->country = $data->country; |
1386 | 1386 | $this->state = $data->state; |
1387 | 1387 | $this->zip = $data->zip; |
1388 | - $this->phone = ! empty( $this->user_info['phone'] ) ? $this->user_info['phone'] : ''; |
|
1388 | + $this->phone = !empty($this->user_info['phone']) ? $this->user_info['phone'] : ''; |
|
1389 | 1389 | |
1390 | - $this->discounts = ! empty( $this->user_info['discount'] ) ? $this->user_info['discount'] : ''; |
|
1390 | + $this->discounts = !empty($this->user_info['discount']) ? $this->user_info['discount'] : ''; |
|
1391 | 1391 | $this->discount = $data->discount; |
1392 | 1392 | $this->discount_code = $data->discount_code; |
1393 | 1393 | |
1394 | 1394 | // Other Identifiers |
1395 | 1395 | $this->key = $data->key; |
1396 | - $this->number = $this->setup_invoice_number( $data ); |
|
1396 | + $this->number = $this->setup_invoice_number($data); |
|
1397 | 1397 | |
1398 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
1398 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
1399 | 1399 | |
1400 | 1400 | |
1401 | 1401 | return true; |
@@ -1405,52 +1405,52 @@ discard block |
||
1405 | 1405 | /** |
1406 | 1406 | * Sets up the status nice name. |
1407 | 1407 | */ |
1408 | - private function setup_status_nicename( $status ) { |
|
1409 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
1408 | + private function setup_status_nicename($status) { |
|
1409 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
1410 | 1410 | |
1411 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
1412 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
1411 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
1412 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
1413 | 1413 | } |
1414 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
1414 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
1415 | 1415 | |
1416 | - return apply_filters( 'setup_status_nicename', $status ); |
|
1416 | + return apply_filters('setup_status_nicename', $status); |
|
1417 | 1417 | } |
1418 | 1418 | |
1419 | 1419 | /** |
1420 | 1420 | * Set's up the invoice number. |
1421 | 1421 | */ |
1422 | - private function setup_invoice_number( $data ) { |
|
1422 | + private function setup_invoice_number($data) { |
|
1423 | 1423 | |
1424 | - if ( ! empty( $data ) && ! empty( $data->number ) ) { |
|
1424 | + if (!empty($data) && !empty($data->number)) { |
|
1425 | 1425 | return $data->number; |
1426 | 1426 | } |
1427 | 1427 | |
1428 | 1428 | $number = $this->ID; |
1429 | 1429 | |
1430 | - if ( $this->status == 'auto-draft' && wpinv_sequential_number_active( $this->post_type ) ) { |
|
1431 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
1430 | + if ($this->status == 'auto-draft' && wpinv_sequential_number_active($this->post_type)) { |
|
1431 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
1432 | 1432 | $number = $next_number; |
1433 | 1433 | } |
1434 | 1434 | |
1435 | - return wpinv_format_invoice_number( $number, $this->post_type ); |
|
1435 | + return wpinv_format_invoice_number($number, $this->post_type); |
|
1436 | 1436 | |
1437 | 1437 | } |
1438 | 1438 | |
1439 | 1439 | /** |
1440 | 1440 | * Invoice's post name. |
1441 | 1441 | */ |
1442 | - private function setup_post_name( $post = NULL ) { |
|
1442 | + private function setup_post_name($post = NULL) { |
|
1443 | 1443 | global $wpdb; |
1444 | 1444 | |
1445 | 1445 | $post_name = ''; |
1446 | 1446 | |
1447 | - if ( !empty( $post ) ) { |
|
1448 | - if( !empty( $post->post_name ) ) { |
|
1447 | + if (!empty($post)) { |
|
1448 | + if (!empty($post->post_name)) { |
|
1449 | 1449 | $post_name = $post->post_name; |
1450 | - } else if ( !empty( $post->ID ) ) { |
|
1451 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
1450 | + } else if (!empty($post->ID)) { |
|
1451 | + $post_name = wpinv_generate_post_name($post->ID); |
|
1452 | 1452 | |
1453 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
1453 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
1454 | 1454 | } |
1455 | 1455 | } |
1456 | 1456 | |
@@ -1463,18 +1463,18 @@ discard block |
||
1463 | 1463 | public function setup_cart_details() { |
1464 | 1464 | global $wpdb; |
1465 | 1465 | |
1466 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
1466 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
1467 | 1467 | $items = $wpdb->get_results( |
1468 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID ) |
|
1468 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $this->ID) |
|
1469 | 1469 | ); |
1470 | 1470 | |
1471 | - if ( empty( $items ) ) { |
|
1471 | + if (empty($items)) { |
|
1472 | 1472 | return array(); |
1473 | 1473 | } |
1474 | 1474 | |
1475 | 1475 | $details = array(); |
1476 | 1476 | |
1477 | - foreach ( $items as $item ) { |
|
1477 | + foreach ($items as $item) { |
|
1478 | 1478 | $item = (array) $item; |
1479 | 1479 | $details[] = array( |
1480 | 1480 | 'name' => $item['item_name'], |
@@ -1493,7 +1493,7 @@ discard block |
||
1493 | 1493 | ); |
1494 | 1494 | } |
1495 | 1495 | |
1496 | - return map_deep( $details, 'maybe_unserialize' ); |
|
1496 | + return map_deep($details, 'maybe_unserialize'); |
|
1497 | 1497 | |
1498 | 1498 | } |
1499 | 1499 | |
@@ -1501,16 +1501,16 @@ discard block |
||
1501 | 1501 | * Convert this to an array. |
1502 | 1502 | */ |
1503 | 1503 | public function array_convert() { |
1504 | - return get_object_vars( $this ); |
|
1504 | + return get_object_vars($this); |
|
1505 | 1505 | } |
1506 | 1506 | |
1507 | 1507 | private function setup_fees() { |
1508 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1508 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1509 | 1509 | return $payment_fees; |
1510 | 1510 | } |
1511 | 1511 | |
1512 | 1512 | private function setup_gateway_title() { |
1513 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1513 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
1514 | 1514 | return $gateway_title; |
1515 | 1515 | } |
1516 | 1516 | |
@@ -1546,16 +1546,16 @@ discard block |
||
1546 | 1546 | 'fees' => $this->fees, |
1547 | 1547 | ); |
1548 | 1548 | |
1549 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
1549 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
1550 | 1550 | |
1551 | 1551 | } |
1552 | 1552 | |
1553 | 1553 | private function insert_invoice() { |
1554 | 1554 | |
1555 | - if ( empty( $this->post_type ) ) { |
|
1556 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
1555 | + if (empty($this->post_type)) { |
|
1556 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
1557 | 1557 | $this->post_type = $post_type; |
1558 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
1558 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
1559 | 1559 | $this->post_type = $post_type; |
1560 | 1560 | } else { |
1561 | 1561 | $this->post_type = 'wpi_invoice'; |
@@ -1563,16 +1563,16 @@ discard block |
||
1563 | 1563 | } |
1564 | 1564 | |
1565 | 1565 | $invoice_number = $this->ID; |
1566 | - if ( $number = $this->number ) { |
|
1566 | + if ($number = $this->number) { |
|
1567 | 1567 | $invoice_number = $number; |
1568 | 1568 | } |
1569 | 1569 | |
1570 | - if ( empty( $this->key ) ) { |
|
1570 | + if (empty($this->key)) { |
|
1571 | 1571 | $this->key = $this->generate_key(); |
1572 | 1572 | $this->pending['key'] = $this->key; |
1573 | 1573 | } |
1574 | 1574 | |
1575 | - if ( empty( $this->ip ) ) { |
|
1575 | + if (empty($this->ip)) { |
|
1576 | 1576 | $this->ip = wpinv_get_ip(); |
1577 | 1577 | $this->pending['ip'] = $this->ip; |
1578 | 1578 | } |
@@ -1610,34 +1610,34 @@ discard block |
||
1610 | 1610 | 'post_author' => $this->user_id, |
1611 | 1611 | 'post_type' => $this->post_type, |
1612 | 1612 | 'post_excerpt' => $this->description, |
1613 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
1614 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
1613 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
1614 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
1615 | 1615 | 'post_parent' => $this->parent_invoice, |
1616 | 1616 | ); |
1617 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
1617 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
1618 | 1618 | |
1619 | 1619 | // Create a blank invoice |
1620 | - if ( !empty( $this->ID ) ) { |
|
1621 | - $args['ID'] = $this->ID; |
|
1622 | - $invoice_id = wp_update_post( $args, true ); |
|
1620 | + if (!empty($this->ID)) { |
|
1621 | + $args['ID'] = $this->ID; |
|
1622 | + $invoice_id = wp_update_post($args, true); |
|
1623 | 1623 | } else { |
1624 | - $invoice_id = wp_insert_post( $args, true ); |
|
1624 | + $invoice_id = wp_insert_post($args, true); |
|
1625 | 1625 | } |
1626 | 1626 | |
1627 | - if ( is_wp_error( $invoice_id ) ) { |
|
1627 | + if (is_wp_error($invoice_id)) { |
|
1628 | 1628 | return false; |
1629 | 1629 | } |
1630 | 1630 | |
1631 | - if ( ! empty( $invoice_id ) ) { |
|
1631 | + if (!empty($invoice_id)) { |
|
1632 | 1632 | $this->ID = $invoice_id; |
1633 | 1633 | $this->_ID = $invoice_id; |
1634 | 1634 | |
1635 | - $this->payment_meta = array_merge( $this->payment_meta, $payment_data ); |
|
1635 | + $this->payment_meta = array_merge($this->payment_meta, $payment_data); |
|
1636 | 1636 | |
1637 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
1638 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
1639 | - foreach( $this->fees as $fee ) { |
|
1640 | - $this->increase_fees( $fee['amount'] ); |
|
1637 | + if (!empty($this->payment_meta['fees'])) { |
|
1638 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
1639 | + foreach ($this->fees as $fee) { |
|
1640 | + $this->increase_fees($fee['amount']); |
|
1641 | 1641 | } |
1642 | 1642 | } |
1643 | 1643 | |
@@ -1653,11 +1653,11 @@ discard block |
||
1653 | 1653 | */ |
1654 | 1654 | public function get_special_fields() { |
1655 | 1655 | |
1656 | - return array ( |
|
1656 | + return array( |
|
1657 | 1657 | 'post_id' => $this->ID, |
1658 | 1658 | 'number' => $this->get_number(), |
1659 | 1659 | 'key' => $this->get_key(), |
1660 | - 'type' => str_replace( 'wpi_', '', $this->post_type ), |
|
1660 | + 'type' => str_replace('wpi_', '', $this->post_type), |
|
1661 | 1661 | 'mode' => $this->mode, |
1662 | 1662 | 'user_ip' => $this->get_ip(), |
1663 | 1663 | 'first_name' => $this->get_first_name(), |
@@ -1697,37 +1697,37 @@ discard block |
||
1697 | 1697 | $this->refresh_payment_data(); |
1698 | 1698 | |
1699 | 1699 | $fields = $this->get_special_fields(); |
1700 | - $fields = array_map( 'maybe_serialize', $fields ); |
|
1700 | + $fields = array_map('maybe_serialize', $fields); |
|
1701 | 1701 | |
1702 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1702 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1703 | 1703 | |
1704 | 1704 | $id = (int) $this->ID; |
1705 | 1705 | |
1706 | - if ( empty( $id ) ) { |
|
1706 | + if (empty($id)) { |
|
1707 | 1707 | return; |
1708 | 1708 | } |
1709 | 1709 | |
1710 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`=$id" ) ) { |
|
1710 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`=$id")) { |
|
1711 | 1711 | |
1712 | - $wpdb->update( $table, $fields, array( 'post_id' => $id ) ); |
|
1712 | + $wpdb->update($table, $fields, array('post_id' => $id)); |
|
1713 | 1713 | |
1714 | 1714 | } else { |
1715 | 1715 | |
1716 | - $wpdb->insert( $table, $fields ); |
|
1716 | + $wpdb->insert($table, $fields); |
|
1717 | 1717 | |
1718 | 1718 | } |
1719 | 1719 | |
1720 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
1721 | - $wpdb->delete( $table, array( 'post_id' => $this->ID ) ); |
|
1720 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
1721 | + $wpdb->delete($table, array('post_id' => $this->ID)); |
|
1722 | 1722 | |
1723 | - foreach ( $this->get_cart_details() as $details ) { |
|
1723 | + foreach ($this->get_cart_details() as $details) { |
|
1724 | 1724 | $fields = array( |
1725 | 1725 | 'post_id' => $this->ID, |
1726 | 1726 | 'item_id' => $details['id'], |
1727 | 1727 | 'item_name' => $details['name'], |
1728 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
1728 | + 'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'], |
|
1729 | 1729 | 'vat_rate' => $details['vat_rate'], |
1730 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
1730 | + 'vat_class' => empty($details['vat_class']) ? '_standard' : $details['vat_class'], |
|
1731 | 1731 | 'tax' => $details['tax'], |
1732 | 1732 | 'item_price' => $details['item_price'], |
1733 | 1733 | 'custom_price' => $details['custom_price'], |
@@ -1739,41 +1739,41 @@ discard block |
||
1739 | 1739 | 'fees' => $details['fees'], |
1740 | 1740 | ); |
1741 | 1741 | |
1742 | - $item_columns = array_keys ( $fields ); |
|
1742 | + $item_columns = array_keys($fields); |
|
1743 | 1743 | |
1744 | - foreach ( $fields as $key => $val ) { |
|
1745 | - if ( is_null( $val ) ) { |
|
1744 | + foreach ($fields as $key => $val) { |
|
1745 | + if (is_null($val)) { |
|
1746 | 1746 | $val = ''; |
1747 | 1747 | } |
1748 | - $val = maybe_serialize( $val ); |
|
1749 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
1748 | + $val = maybe_serialize($val); |
|
1749 | + $fields[$key] = $wpdb->prepare('%s', $val); |
|
1750 | 1750 | } |
1751 | 1751 | |
1752 | - $fields = implode( ', ', $fields ); |
|
1752 | + $fields = implode(', ', $fields); |
|
1753 | 1753 | $item_rows[] = "($fields)"; |
1754 | 1754 | } |
1755 | 1755 | |
1756 | - $item_rows = implode( ', ', $item_rows ); |
|
1757 | - $item_columns = implode( ', ', $item_columns ); |
|
1758 | - $wpdb->query( "INSERT INTO $table ($item_columns) VALUES $item_rows" ); |
|
1756 | + $item_rows = implode(', ', $item_rows); |
|
1757 | + $item_columns = implode(', ', $item_columns); |
|
1758 | + $wpdb->query("INSERT INTO $table ($item_columns) VALUES $item_rows"); |
|
1759 | 1759 | } |
1760 | 1760 | |
1761 | - public function save( $setup = false ) { |
|
1761 | + public function save($setup = false) { |
|
1762 | 1762 | global $wpi_session; |
1763 | 1763 | |
1764 | 1764 | $saved = false; |
1765 | - if ( empty( $this->items ) ) { |
|
1765 | + if (empty($this->items)) { |
|
1766 | 1766 | return $saved; |
1767 | 1767 | } |
1768 | 1768 | |
1769 | - if ( empty( $this->key ) ) { |
|
1769 | + if (empty($this->key)) { |
|
1770 | 1770 | $this->key = $this->generate_key(); |
1771 | 1771 | } |
1772 | 1772 | |
1773 | - if ( empty( $this->ID ) ) { |
|
1773 | + if (empty($this->ID)) { |
|
1774 | 1774 | $invoice_id = $this->insert_invoice(); |
1775 | 1775 | |
1776 | - if ( false === $invoice_id ) { |
|
1776 | + if (false === $invoice_id) { |
|
1777 | 1777 | $saved = false; |
1778 | 1778 | } else { |
1779 | 1779 | $this->ID = $invoice_id; |
@@ -1781,28 +1781,28 @@ discard block |
||
1781 | 1781 | } |
1782 | 1782 | |
1783 | 1783 | // If we have something pending, let's save it |
1784 | - if ( ! empty( $this->pending ) ) { |
|
1784 | + if (!empty($this->pending)) { |
|
1785 | 1785 | $total_increase = 0; |
1786 | 1786 | $total_decrease = 0; |
1787 | 1787 | |
1788 | - foreach ( $this->pending as $key => $value ) { |
|
1788 | + foreach ($this->pending as $key => $value) { |
|
1789 | 1789 | |
1790 | - switch( $key ) { |
|
1790 | + switch ($key) { |
|
1791 | 1791 | case 'items': |
1792 | 1792 | // Update totals for pending items |
1793 | - foreach ( $this->pending[ $key ] as $item ) { |
|
1794 | - switch( $item['action'] ) { |
|
1793 | + foreach ($this->pending[$key] as $item) { |
|
1794 | + switch ($item['action']) { |
|
1795 | 1795 | case 'add': |
1796 | 1796 | $price = $item['price']; |
1797 | 1797 | $taxes = $item['tax']; |
1798 | 1798 | |
1799 | - if ( 'publish' === $this->status ) { |
|
1799 | + if ('publish' === $this->status) { |
|
1800 | 1800 | $total_increase += $price; |
1801 | 1801 | } |
1802 | 1802 | break; |
1803 | 1803 | |
1804 | 1804 | case 'remove': |
1805 | - if ( 'publish' === $this->status ) { |
|
1805 | + if ('publish' === $this->status) { |
|
1806 | 1806 | $total_decrease += $item['price']; |
1807 | 1807 | } |
1808 | 1808 | break; |
@@ -1810,16 +1810,16 @@ discard block |
||
1810 | 1810 | } |
1811 | 1811 | break; |
1812 | 1812 | case 'fees': |
1813 | - if ( 'publish' !== $this->status ) { |
|
1813 | + if ('publish' !== $this->status) { |
|
1814 | 1814 | break; |
1815 | 1815 | } |
1816 | 1816 | |
1817 | - if ( empty( $this->pending[ $key ] ) ) { |
|
1817 | + if (empty($this->pending[$key])) { |
|
1818 | 1818 | break; |
1819 | 1819 | } |
1820 | 1820 | |
1821 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
1822 | - switch( $fee['action'] ) { |
|
1821 | + foreach ($this->pending[$key] as $fee) { |
|
1822 | + switch ($fee['action']) { |
|
1823 | 1823 | case 'add': |
1824 | 1824 | $total_increase += $fee['amount']; |
1825 | 1825 | break; |
@@ -1831,7 +1831,7 @@ discard block |
||
1831 | 1831 | } |
1832 | 1832 | break; |
1833 | 1833 | case 'status': |
1834 | - $this->update_status( $this->status ); |
|
1834 | + $this->update_status($this->status); |
|
1835 | 1835 | break; |
1836 | 1836 | case 'first_name': |
1837 | 1837 | $this->user_info['first_name'] = $this->first_name; |
@@ -1863,12 +1863,12 @@ discard block |
||
1863 | 1863 | case 'vat_number': |
1864 | 1864 | $this->user_info['vat_number'] = $this->vat_number; |
1865 | 1865 | |
1866 | - $vat_info = $wpi_session->get( 'user_vat_data' ); |
|
1867 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
1868 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
1869 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
1870 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
1871 | - $this->adddress_confirmed = (bool)$adddress_confirmed; |
|
1866 | + $vat_info = $wpi_session->get('user_vat_data'); |
|
1867 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
1868 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1869 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
1870 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
1871 | + $this->adddress_confirmed = (bool) $adddress_confirmed; |
|
1872 | 1872 | } |
1873 | 1873 | |
1874 | 1874 | break; |
@@ -1885,34 +1885,34 @@ discard block |
||
1885 | 1885 | 'edit_date' => true, |
1886 | 1886 | ); |
1887 | 1887 | |
1888 | - wp_update_post( $args ); |
|
1888 | + wp_update_post($args); |
|
1889 | 1889 | break; |
1890 | 1890 | case 'due_date': |
1891 | - if ( empty( $this->due_date ) ) { |
|
1891 | + if (empty($this->due_date)) { |
|
1892 | 1892 | $this->due_date = 'none'; |
1893 | 1893 | } |
1894 | 1894 | break; |
1895 | 1895 | case 'discounts': |
1896 | - if ( ! is_array( $this->discounts ) ) { |
|
1897 | - $this->discounts = explode( ',', $this->discounts ); |
|
1896 | + if (!is_array($this->discounts)) { |
|
1897 | + $this->discounts = explode(',', $this->discounts); |
|
1898 | 1898 | } |
1899 | 1899 | |
1900 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
1900 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
1901 | 1901 | break; |
1902 | 1902 | case 'parent_invoice': |
1903 | 1903 | $args = array( |
1904 | 1904 | 'ID' => $this->ID, |
1905 | 1905 | 'post_parent' => $this->parent_invoice, |
1906 | 1906 | ); |
1907 | - wp_update_post( $args ); |
|
1907 | + wp_update_post($args); |
|
1908 | 1908 | break; |
1909 | 1909 | default: |
1910 | - do_action( 'wpinv_save', $this, $key ); |
|
1910 | + do_action('wpinv_save', $this, $key); |
|
1911 | 1911 | break; |
1912 | 1912 | } |
1913 | 1913 | } |
1914 | 1914 | |
1915 | - $this->items = array_values( $this->items ); |
|
1915 | + $this->items = array_values($this->items); |
|
1916 | 1916 | |
1917 | 1917 | $this->pending = array(); |
1918 | 1918 | $saved = true; |
@@ -1925,14 +1925,14 @@ discard block |
||
1925 | 1925 | 'currency' => $this->currency, |
1926 | 1926 | 'user_info' => $this->user_info, |
1927 | 1927 | ); |
1928 | - $this->payment_meta = array_merge( $this->payment_meta, $new_meta ); |
|
1928 | + $this->payment_meta = array_merge($this->payment_meta, $new_meta); |
|
1929 | 1929 | $this->update_items(); |
1930 | 1930 | |
1931 | 1931 | $this->save_special(); |
1932 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
1932 | + do_action('wpinv_invoice_save', $this, $saved); |
|
1933 | 1933 | |
1934 | - if ( true === $saved || $setup ) { |
|
1935 | - $this->setup_invoice( $this->ID ); |
|
1934 | + if (true === $saved || $setup) { |
|
1935 | + $this->setup_invoice($this->ID); |
|
1936 | 1936 | } |
1937 | 1937 | |
1938 | 1938 | $this->refresh_item_ids(); |
@@ -1940,7 +1940,7 @@ discard block |
||
1940 | 1940 | return $saved; |
1941 | 1941 | } |
1942 | 1942 | |
1943 | - public function add_fee( $args, $global = true ) { |
|
1943 | + public function add_fee($args, $global = true) { |
|
1944 | 1944 | $default_args = array( |
1945 | 1945 | 'label' => '', |
1946 | 1946 | 'amount' => 0, |
@@ -1950,75 +1950,75 @@ discard block |
||
1950 | 1950 | 'item_id' => 0, |
1951 | 1951 | ); |
1952 | 1952 | |
1953 | - $fee = wp_parse_args( $args, $default_args ); |
|
1953 | + $fee = wp_parse_args($args, $default_args); |
|
1954 | 1954 | |
1955 | - if ( empty( $fee['label'] ) ) { |
|
1955 | + if (empty($fee['label'])) { |
|
1956 | 1956 | return false; |
1957 | 1957 | } |
1958 | 1958 | |
1959 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
1959 | + $fee['id'] = sanitize_title($fee['label']); |
|
1960 | 1960 | |
1961 | - $this->fees[] = $fee; |
|
1961 | + $this->fees[] = $fee; |
|
1962 | 1962 | |
1963 | 1963 | $added_fee = $fee; |
1964 | 1964 | $added_fee['action'] = 'add'; |
1965 | 1965 | $this->pending['fees'][] = $added_fee; |
1966 | - reset( $this->fees ); |
|
1966 | + reset($this->fees); |
|
1967 | 1967 | |
1968 | - $this->increase_fees( $fee['amount'] ); |
|
1968 | + $this->increase_fees($fee['amount']); |
|
1969 | 1969 | return true; |
1970 | 1970 | } |
1971 | 1971 | |
1972 | - public function remove_fee( $key ) { |
|
1972 | + public function remove_fee($key) { |
|
1973 | 1973 | $removed = false; |
1974 | 1974 | |
1975 | - if ( is_numeric( $key ) ) { |
|
1976 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
1975 | + if (is_numeric($key)) { |
|
1976 | + $removed = $this->remove_fee_by('index', $key); |
|
1977 | 1977 | } |
1978 | 1978 | |
1979 | 1979 | return $removed; |
1980 | 1980 | } |
1981 | 1981 | |
1982 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
1983 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
1982 | + public function remove_fee_by($key, $value, $global = false) { |
|
1983 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
1984 | 1984 | 'index', 'label', 'amount', 'type', |
1985 | - ) ); |
|
1985 | + )); |
|
1986 | 1986 | |
1987 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
1987 | + if (!in_array($key, $allowed_fee_keys)) { |
|
1988 | 1988 | return false; |
1989 | 1989 | } |
1990 | 1990 | |
1991 | 1991 | $removed = false; |
1992 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
1993 | - $removed_fee = $this->fees[ $value ]; |
|
1992 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
1993 | + $removed_fee = $this->fees[$value]; |
|
1994 | 1994 | $removed_fee['action'] = 'remove'; |
1995 | 1995 | $this->pending['fees'][] = $removed_fee; |
1996 | 1996 | |
1997 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1997 | + $this->decrease_fees($removed_fee['amount']); |
|
1998 | 1998 | |
1999 | - unset( $this->fees[ $value ] ); |
|
1999 | + unset($this->fees[$value]); |
|
2000 | 2000 | $removed = true; |
2001 | - } else if ( 'index' !== $key ) { |
|
2002 | - foreach ( $this->fees as $index => $fee ) { |
|
2003 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
2001 | + } else if ('index' !== $key) { |
|
2002 | + foreach ($this->fees as $index => $fee) { |
|
2003 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
2004 | 2004 | $removed_fee = $fee; |
2005 | 2005 | $removed_fee['action'] = 'remove'; |
2006 | 2006 | $this->pending['fees'][] = $removed_fee; |
2007 | 2007 | |
2008 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
2008 | + $this->decrease_fees($removed_fee['amount']); |
|
2009 | 2009 | |
2010 | - unset( $this->fees[ $index ] ); |
|
2010 | + unset($this->fees[$index]); |
|
2011 | 2011 | $removed = true; |
2012 | 2012 | |
2013 | - if ( false === $global ) { |
|
2013 | + if (false === $global) { |
|
2014 | 2014 | break; |
2015 | 2015 | } |
2016 | 2016 | } |
2017 | 2017 | } |
2018 | 2018 | } |
2019 | 2019 | |
2020 | - if ( true === $removed ) { |
|
2021 | - $this->fees = array_values( $this->fees ); |
|
2020 | + if (true === $removed) { |
|
2021 | + $this->fees = array_values($this->fees); |
|
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | return $removed; |
@@ -2026,35 +2026,35 @@ discard block |
||
2026 | 2026 | |
2027 | 2027 | |
2028 | 2028 | |
2029 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
2029 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
2030 | 2030 | // Bail if no note specified |
2031 | - if( !$note ) { |
|
2031 | + if (!$note) { |
|
2032 | 2032 | return false; |
2033 | 2033 | } |
2034 | 2034 | |
2035 | - if ( empty( $this->ID ) ) |
|
2035 | + if (empty($this->ID)) |
|
2036 | 2036 | return false; |
2037 | 2037 | |
2038 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
2039 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
2038 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
2039 | + $user = get_user_by('id', get_current_user_id()); |
|
2040 | 2040 | $comment_author = $user->display_name; |
2041 | 2041 | $comment_author_email = $user->user_email; |
2042 | 2042 | } else { |
2043 | 2043 | $comment_author = 'System'; |
2044 | 2044 | $comment_author_email = 'system@'; |
2045 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
2046 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
2045 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
2046 | + $comment_author_email = sanitize_email($comment_author_email); |
|
2047 | 2047 | } |
2048 | 2048 | |
2049 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
2049 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
2050 | 2050 | |
2051 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
2051 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
2052 | 2052 | 'comment_post_ID' => $this->ID, |
2053 | 2053 | 'comment_content' => $note, |
2054 | 2054 | 'comment_agent' => 'WPInvoicing', |
2055 | 2055 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
2056 | - 'comment_date' => current_time( 'mysql' ), |
|
2057 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
2056 | + 'comment_date' => current_time('mysql'), |
|
2057 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
2058 | 2058 | 'comment_approved' => 1, |
2059 | 2059 | 'comment_parent' => 0, |
2060 | 2060 | 'comment_author' => $comment_author, |
@@ -2062,53 +2062,53 @@ discard block |
||
2062 | 2062 | 'comment_author_url' => '', |
2063 | 2063 | 'comment_author_email' => $comment_author_email, |
2064 | 2064 | 'comment_type' => 'wpinv_note' |
2065 | - ) ) ); |
|
2065 | + ))); |
|
2066 | 2066 | |
2067 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
2067 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
2068 | 2068 | |
2069 | - if ( $customer_type ) { |
|
2070 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
2069 | + if ($customer_type) { |
|
2070 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
2071 | 2071 | |
2072 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
2072 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
2073 | 2073 | } |
2074 | 2074 | |
2075 | 2075 | return $note_id; |
2076 | 2076 | } |
2077 | 2077 | |
2078 | - private function increase_subtotal( $amount = 0.00 ) { |
|
2078 | + private function increase_subtotal($amount = 0.00) { |
|
2079 | 2079 | $amount = (float) $amount; |
2080 | 2080 | $this->subtotal += $amount; |
2081 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
2081 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
2082 | 2082 | |
2083 | 2083 | $this->recalculate_total(); |
2084 | 2084 | } |
2085 | 2085 | |
2086 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
2086 | + private function decrease_subtotal($amount = 0.00) { |
|
2087 | 2087 | $amount = (float) $amount; |
2088 | 2088 | $this->subtotal -= $amount; |
2089 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
2089 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
2090 | 2090 | |
2091 | - if ( $this->subtotal < 0 ) { |
|
2091 | + if ($this->subtotal < 0) { |
|
2092 | 2092 | $this->subtotal = 0; |
2093 | 2093 | } |
2094 | 2094 | |
2095 | 2095 | $this->recalculate_total(); |
2096 | 2096 | } |
2097 | 2097 | |
2098 | - private function increase_fees( $amount = 0.00 ) { |
|
2099 | - $amount = (float)$amount; |
|
2098 | + private function increase_fees($amount = 0.00) { |
|
2099 | + $amount = (float) $amount; |
|
2100 | 2100 | $this->fees_total += $amount; |
2101 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
2101 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
2102 | 2102 | |
2103 | 2103 | $this->recalculate_total(); |
2104 | 2104 | } |
2105 | 2105 | |
2106 | - private function decrease_fees( $amount = 0.00 ) { |
|
2106 | + private function decrease_fees($amount = 0.00) { |
|
2107 | 2107 | $amount = (float) $amount; |
2108 | 2108 | $this->fees_total -= $amount; |
2109 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
2109 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
2110 | 2110 | |
2111 | - if ( $this->fees_total < 0 ) { |
|
2111 | + if ($this->fees_total < 0) { |
|
2112 | 2112 | $this->fees_total = 0; |
2113 | 2113 | } |
2114 | 2114 | |
@@ -2119,54 +2119,54 @@ discard block |
||
2119 | 2119 | global $wpi_nosave; |
2120 | 2120 | |
2121 | 2121 | $this->total = $this->subtotal + $this->tax + $this->fees_total - $this->discount; |
2122 | - $this->total = wpinv_round_amount( $this->total ); |
|
2122 | + $this->total = wpinv_round_amount($this->total); |
|
2123 | 2123 | |
2124 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
2124 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
2125 | 2125 | } |
2126 | 2126 | |
2127 | - public function increase_tax( $amount = 0.00 ) { |
|
2127 | + public function increase_tax($amount = 0.00) { |
|
2128 | 2128 | $amount = (float) $amount; |
2129 | 2129 | $this->tax += $amount; |
2130 | 2130 | |
2131 | 2131 | $this->recalculate_total(); |
2132 | 2132 | } |
2133 | 2133 | |
2134 | - public function decrease_tax( $amount = 0.00 ) { |
|
2134 | + public function decrease_tax($amount = 0.00) { |
|
2135 | 2135 | $amount = (float) $amount; |
2136 | 2136 | $this->tax -= $amount; |
2137 | 2137 | |
2138 | - if ( $this->tax < 0 ) { |
|
2138 | + if ($this->tax < 0) { |
|
2139 | 2139 | $this->tax = 0; |
2140 | 2140 | } |
2141 | 2141 | |
2142 | 2142 | $this->recalculate_total(); |
2143 | 2143 | } |
2144 | 2144 | |
2145 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
2146 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
2145 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
2146 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
2147 | 2147 | |
2148 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
2148 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
2149 | 2149 | return false; // Don't permit status changes that aren't changes |
2150 | 2150 | } |
2151 | 2151 | |
2152 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
2152 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
2153 | 2153 | $updated = false; |
2154 | 2154 | |
2155 | - if ( $do_change ) { |
|
2156 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
2155 | + if ($do_change) { |
|
2156 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
2157 | 2157 | |
2158 | 2158 | $update_post_data = array(); |
2159 | 2159 | $update_post_data['ID'] = $this->ID; |
2160 | 2160 | $update_post_data['post_status'] = $new_status; |
2161 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
2162 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
2161 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
2162 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
2163 | 2163 | |
2164 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
2164 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
2165 | 2165 | |
2166 | - $updated = wp_update_post( $update_post_data ); |
|
2166 | + $updated = wp_update_post($update_post_data); |
|
2167 | 2167 | |
2168 | 2168 | // Process any specific status functions |
2169 | - switch( $new_status ) { |
|
2169 | + switch ($new_status) { |
|
2170 | 2170 | case 'wpi-refunded': |
2171 | 2171 | $this->process_refund(); |
2172 | 2172 | break; |
@@ -2179,9 +2179,9 @@ discard block |
||
2179 | 2179 | } |
2180 | 2180 | |
2181 | 2181 | // Status was changed. |
2182 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
2183 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
2184 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
2182 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
2183 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
2184 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
2185 | 2185 | } |
2186 | 2186 | |
2187 | 2187 | return $updated; |
@@ -2195,68 +2195,68 @@ discard block |
||
2195 | 2195 | $this->save(); |
2196 | 2196 | } |
2197 | 2197 | |
2198 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
2199 | - if ( empty( $meta_key ) ) { |
|
2198 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
2199 | + if (empty($meta_key)) { |
|
2200 | 2200 | return false; |
2201 | 2201 | } |
2202 | 2202 | |
2203 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
2203 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
2204 | 2204 | $current_meta = $this->get_meta(); |
2205 | - $current_meta[ $meta_key ] = $meta_value; |
|
2205 | + $current_meta[$meta_key] = $meta_value; |
|
2206 | 2206 | |
2207 | 2207 | $meta_key = '_wpinv_payment_meta'; |
2208 | 2208 | $meta_value = $current_meta; |
2209 | 2209 | } |
2210 | 2210 | |
2211 | - $key = str_ireplace( '_wpinv_', '', $meta_key ); |
|
2211 | + $key = str_ireplace('_wpinv_', '', $meta_key); |
|
2212 | 2212 | $this->$key = $meta_value; |
2213 | 2213 | |
2214 | - $special = array_keys( $this->get_special_fields() ); |
|
2215 | - if ( in_array( $key, $special ) ) { |
|
2214 | + $special = array_keys($this->get_special_fields()); |
|
2215 | + if (in_array($key, $special)) { |
|
2216 | 2216 | $this->save_special(); |
2217 | 2217 | } else { |
2218 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
2218 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
2219 | 2219 | } |
2220 | 2220 | |
2221 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
2221 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
2222 | 2222 | } |
2223 | 2223 | |
2224 | 2224 | private function process_refund() { |
2225 | 2225 | $process_refund = true; |
2226 | 2226 | |
2227 | 2227 | // If the payment was not in publish, don't decrement stats as they were never incremented |
2228 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
2228 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
2229 | 2229 | $process_refund = false; |
2230 | 2230 | } |
2231 | 2231 | |
2232 | 2232 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
2233 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
2233 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
2234 | 2234 | |
2235 | - if ( false === $process_refund ) { |
|
2235 | + if (false === $process_refund) { |
|
2236 | 2236 | return; |
2237 | 2237 | } |
2238 | 2238 | |
2239 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
2239 | + do_action('wpinv_pre_refund_invoice', $this); |
|
2240 | 2240 | |
2241 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
2242 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
2243 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
2241 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
2242 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
2243 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
2244 | 2244 | |
2245 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
2245 | + do_action('wpinv_post_refund_invoice', $this); |
|
2246 | 2246 | } |
2247 | 2247 | |
2248 | 2248 | private function process_failure() { |
2249 | 2249 | $discounts = $this->discounts; |
2250 | - if ( empty( $discounts ) ) { |
|
2250 | + if (empty($discounts)) { |
|
2251 | 2251 | return; |
2252 | 2252 | } |
2253 | 2253 | |
2254 | - if ( ! is_array( $discounts ) ) { |
|
2255 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
2254 | + if (!is_array($discounts)) { |
|
2255 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
2256 | 2256 | } |
2257 | 2257 | |
2258 | - foreach ( $discounts as $discount ) { |
|
2259 | - wpinv_decrease_discount_usage( $discount ); |
|
2258 | + foreach ($discounts as $discount) { |
|
2259 | + wpinv_decrease_discount_usage($discount); |
|
2260 | 2260 | } |
2261 | 2261 | } |
2262 | 2262 | |
@@ -2264,88 +2264,88 @@ discard block |
||
2264 | 2264 | $process_pending = true; |
2265 | 2265 | |
2266 | 2266 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
2267 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
2267 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
2268 | 2268 | $process_pending = false; |
2269 | 2269 | } |
2270 | 2270 | |
2271 | 2271 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
2272 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
2272 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
2273 | 2273 | |
2274 | - if ( false === $process_pending ) { |
|
2274 | + if (false === $process_pending) { |
|
2275 | 2275 | return; |
2276 | 2276 | } |
2277 | 2277 | |
2278 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
2279 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
2280 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
2278 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
2279 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
2280 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
2281 | 2281 | |
2282 | 2282 | $this->completed_date = ''; |
2283 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
2283 | + $this->update_meta('_wpinv_completed_date', ''); |
|
2284 | 2284 | } |
2285 | 2285 | |
2286 | 2286 | // get data |
2287 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
2288 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
2287 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
2288 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
2289 | 2289 | |
2290 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
2290 | + if ($meta_key === '_wpinv_payment_meta') { |
|
2291 | 2291 | |
2292 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
2292 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
2293 | 2293 | |
2294 | - if ( empty( $meta['key'] ) ) { |
|
2294 | + if (empty($meta['key'])) { |
|
2295 | 2295 | $meta['key'] = $this->key; |
2296 | 2296 | } |
2297 | 2297 | |
2298 | - if ( empty( $meta['date'] ) ) { |
|
2299 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
2298 | + if (empty($meta['date'])) { |
|
2299 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
2300 | 2300 | } |
2301 | 2301 | } |
2302 | 2302 | |
2303 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
2303 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
2304 | 2304 | |
2305 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
2305 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
2306 | 2306 | } |
2307 | 2307 | |
2308 | - public function get_status( $nicename = false ) { |
|
2309 | - if ( !$nicename ) { |
|
2308 | + public function get_status($nicename = false) { |
|
2309 | + if (!$nicename) { |
|
2310 | 2310 | $status = $this->status; |
2311 | 2311 | } else { |
2312 | 2312 | $status = $this->status_nicename; |
2313 | 2313 | } |
2314 | 2314 | |
2315 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
2315 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
2316 | 2316 | } |
2317 | 2317 | |
2318 | 2318 | public function get_cart_details() { |
2319 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
2319 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
2320 | 2320 | } |
2321 | 2321 | |
2322 | - public function get_subtotal( $currency = false ) { |
|
2323 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
2322 | + public function get_subtotal($currency = false) { |
|
2323 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
2324 | 2324 | |
2325 | - if ( $currency ) { |
|
2326 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
2325 | + if ($currency) { |
|
2326 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
2327 | 2327 | } |
2328 | 2328 | |
2329 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
2329 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
2330 | 2330 | } |
2331 | 2331 | |
2332 | - public function get_total( $currency = false ) { |
|
2333 | - if ( $this->is_free_trial() ) { |
|
2334 | - $total = wpinv_round_amount( 0 ); |
|
2332 | + public function get_total($currency = false) { |
|
2333 | + if ($this->is_free_trial()) { |
|
2334 | + $total = wpinv_round_amount(0); |
|
2335 | 2335 | } else { |
2336 | - $total = wpinv_round_amount( $this->total ); |
|
2336 | + $total = wpinv_round_amount($this->total); |
|
2337 | 2337 | } |
2338 | - if ( $currency ) { |
|
2339 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
2338 | + if ($currency) { |
|
2339 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
2340 | 2340 | } |
2341 | 2341 | |
2342 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
2342 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
2343 | 2343 | } |
2344 | 2344 | |
2345 | 2345 | /** |
2346 | 2346 | * Returns recurring payment details. |
2347 | 2347 | */ |
2348 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
2348 | + public function get_recurring_details($field = '', $currency = false) { |
|
2349 | 2349 | $data = array(); |
2350 | 2350 | $data['cart_details'] = $this->cart_details; |
2351 | 2351 | $data['subtotal'] = $this->get_subtotal(); |
@@ -2353,93 +2353,93 @@ discard block |
||
2353 | 2353 | $data['tax'] = $this->get_tax(); |
2354 | 2354 | $data['total'] = $this->get_total(); |
2355 | 2355 | |
2356 | - if ( $this->is_parent() || $this->is_renewal() ) { |
|
2356 | + if ($this->is_parent() || $this->is_renewal()) { |
|
2357 | 2357 | |
2358 | 2358 | // Use the parent to calculate recurring details. |
2359 | - if ( $this->is_renewal() ){ |
|
2359 | + if ($this->is_renewal()) { |
|
2360 | 2360 | $parent = $this->get_parent_payment(); |
2361 | 2361 | } else { |
2362 | 2362 | $parent = $this; |
2363 | 2363 | } |
2364 | 2364 | |
2365 | - if ( empty( $parent ) ) { |
|
2365 | + if (empty($parent)) { |
|
2366 | 2366 | $parent = $this; |
2367 | 2367 | } |
2368 | 2368 | |
2369 | 2369 | // Subtotal. |
2370 | - $data['subtotal'] = wpinv_round_amount( $parent->subtotal ); |
|
2371 | - $data['tax'] = wpinv_round_amount( $parent->tax ); |
|
2372 | - $data['discount'] = wpinv_round_amount( $parent->discount ); |
|
2370 | + $data['subtotal'] = wpinv_round_amount($parent->subtotal); |
|
2371 | + $data['tax'] = wpinv_round_amount($parent->tax); |
|
2372 | + $data['discount'] = wpinv_round_amount($parent->discount); |
|
2373 | 2373 | |
2374 | - if ( $data['discount'] > 0 && $parent->discount_first_payment_only() ) { |
|
2375 | - $data['discount'] = wpinv_round_amount( 0 ); |
|
2374 | + if ($data['discount'] > 0 && $parent->discount_first_payment_only()) { |
|
2375 | + $data['discount'] = wpinv_round_amount(0); |
|
2376 | 2376 | } |
2377 | 2377 | |
2378 | - $data['total'] = wpinv_round_amount( $data['subtotal'] + $data['tax'] - $data['discount'] ); |
|
2378 | + $data['total'] = wpinv_round_amount($data['subtotal'] + $data['tax'] - $data['discount']); |
|
2379 | 2379 | |
2380 | 2380 | } |
2381 | 2381 | |
2382 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
2382 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
2383 | 2383 | |
2384 | - if ( $data['total'] < 0 ) { |
|
2384 | + if ($data['total'] < 0) { |
|
2385 | 2385 | $data['total'] = 0; |
2386 | 2386 | } |
2387 | 2387 | |
2388 | - if ( isset( $data[$field] ) ) { |
|
2389 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
2388 | + if (isset($data[$field])) { |
|
2389 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
2390 | 2390 | } |
2391 | 2391 | |
2392 | 2392 | return $data; |
2393 | 2393 | } |
2394 | 2394 | |
2395 | - public function get_final_tax( $currency = false ) { |
|
2396 | - $final_total = wpinv_round_amount( $this->tax ); |
|
2397 | - if ( $currency ) { |
|
2398 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
2395 | + public function get_final_tax($currency = false) { |
|
2396 | + $final_total = wpinv_round_amount($this->tax); |
|
2397 | + if ($currency) { |
|
2398 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
2399 | 2399 | } |
2400 | 2400 | |
2401 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
2401 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
2402 | 2402 | } |
2403 | 2403 | |
2404 | - public function get_discounts( $array = false ) { |
|
2404 | + public function get_discounts($array = false) { |
|
2405 | 2405 | $discounts = $this->discounts; |
2406 | 2406 | |
2407 | - if ( ! is_array( $discounts ) ) { |
|
2408 | - $discounts = explode( ',', $discounts ); |
|
2407 | + if (!is_array($discounts)) { |
|
2408 | + $discounts = explode(',', $discounts); |
|
2409 | 2409 | } |
2410 | 2410 | |
2411 | - $discounts = array_filter( $discounts ); |
|
2411 | + $discounts = array_filter($discounts); |
|
2412 | 2412 | |
2413 | - if ( ! $array ) { |
|
2414 | - $discounts = implode( ',', $discounts ); |
|
2413 | + if (!$array) { |
|
2414 | + $discounts = implode(',', $discounts); |
|
2415 | 2415 | } |
2416 | 2416 | |
2417 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
2417 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
2418 | 2418 | } |
2419 | 2419 | |
2420 | - public function get_discount( $currency = false, $dash = false ) { |
|
2421 | - if ( !empty( $this->discounts ) ) { |
|
2420 | + public function get_discount($currency = false, $dash = false) { |
|
2421 | + if (!empty($this->discounts)) { |
|
2422 | 2422 | global $ajax_cart_details; |
2423 | 2423 | $ajax_cart_details = $this->get_cart_details(); |
2424 | 2424 | |
2425 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
2425 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
2426 | 2426 | $cart_items = $ajax_cart_details; |
2427 | 2427 | } else { |
2428 | 2428 | $cart_items = $this->items; |
2429 | 2429 | } |
2430 | 2430 | |
2431 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
2431 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
2432 | 2432 | } |
2433 | - $discount = wpinv_round_amount( $this->discount ); |
|
2433 | + $discount = wpinv_round_amount($this->discount); |
|
2434 | 2434 | $dash = $dash && $discount > 0 ? '–' : ''; |
2435 | 2435 | |
2436 | - if ( $currency ) { |
|
2437 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
2436 | + if ($currency) { |
|
2437 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
2438 | 2438 | } |
2439 | 2439 | |
2440 | - $discount = $dash . $discount; |
|
2440 | + $discount = $dash . $discount; |
|
2441 | 2441 | |
2442 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
2442 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
2443 | 2443 | } |
2444 | 2444 | |
2445 | 2445 | public function get_discount_code() { |
@@ -2451,131 +2451,131 @@ discard block |
||
2451 | 2451 | return (int) $this->disable_taxes === 0; |
2452 | 2452 | } |
2453 | 2453 | |
2454 | - public function get_tax( $currency = false ) { |
|
2455 | - $tax = wpinv_round_amount( $this->tax ); |
|
2454 | + public function get_tax($currency = false) { |
|
2455 | + $tax = wpinv_round_amount($this->tax); |
|
2456 | 2456 | |
2457 | - if ( $currency ) { |
|
2458 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
2457 | + if ($currency) { |
|
2458 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
2459 | 2459 | } |
2460 | 2460 | |
2461 | - if ( ! $this->is_taxable() ) { |
|
2462 | - $tax = wpinv_round_amount( 0.00 ); |
|
2461 | + if (!$this->is_taxable()) { |
|
2462 | + $tax = wpinv_round_amount(0.00); |
|
2463 | 2463 | } |
2464 | 2464 | |
2465 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
2465 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
2466 | 2466 | } |
2467 | 2467 | |
2468 | - public function get_fees( $type = 'all' ) { |
|
2469 | - $fees = array(); |
|
2468 | + public function get_fees($type = 'all') { |
|
2469 | + $fees = array(); |
|
2470 | 2470 | |
2471 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
2472 | - foreach ( $this->fees as $fee ) { |
|
2473 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
2471 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
2472 | + foreach ($this->fees as $fee) { |
|
2473 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
2474 | 2474 | continue; |
2475 | 2475 | } |
2476 | 2476 | |
2477 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
2478 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
2479 | - $fees[] = $fee; |
|
2477 | + $fee['label'] = stripslashes($fee['label']); |
|
2478 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
2479 | + $fees[] = $fee; |
|
2480 | 2480 | } |
2481 | 2481 | } |
2482 | 2482 | |
2483 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
2483 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
2484 | 2484 | } |
2485 | 2485 | |
2486 | - public function get_fees_total( $type = 'all' ) { |
|
2486 | + public function get_fees_total($type = 'all') { |
|
2487 | 2487 | $fees_total = (float) 0.00; |
2488 | 2488 | |
2489 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
2490 | - if ( ! empty( $payment_fees ) ) { |
|
2491 | - foreach ( $payment_fees as $fee ) { |
|
2489 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
2490 | + if (!empty($payment_fees)) { |
|
2491 | + foreach ($payment_fees as $fee) { |
|
2492 | 2492 | $fees_total += (float) $fee['amount']; |
2493 | 2493 | } |
2494 | 2494 | } |
2495 | 2495 | |
2496 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
2496 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
2497 | 2497 | |
2498 | 2498 | } |
2499 | 2499 | |
2500 | 2500 | public function get_user_id() { |
2501 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
2501 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
2502 | 2502 | } |
2503 | 2503 | |
2504 | 2504 | public function get_user_full_name() { |
2505 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
2505 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
2506 | 2506 | } |
2507 | 2507 | |
2508 | 2508 | public function get_user_info() { |
2509 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
2509 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
2510 | 2510 | } |
2511 | 2511 | |
2512 | 2512 | public function get_items() { |
2513 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
2513 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
2514 | 2514 | } |
2515 | 2515 | |
2516 | 2516 | public function get_gateway() { |
2517 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
2517 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
2518 | 2518 | } |
2519 | 2519 | |
2520 | 2520 | public function get_gateway_title() { |
2521 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
2521 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
2522 | 2522 | |
2523 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
2523 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
2524 | 2524 | } |
2525 | 2525 | |
2526 | 2526 | public function get_currency() { |
2527 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
2527 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
2528 | 2528 | } |
2529 | 2529 | |
2530 | - public function get_due_date( $display = false ) { |
|
2531 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
2530 | + public function get_due_date($display = false) { |
|
2531 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
2532 | 2532 | |
2533 | - if ( !$display || empty( $due_date ) ) { |
|
2533 | + if (!$display || empty($due_date)) { |
|
2534 | 2534 | return $due_date; |
2535 | 2535 | } |
2536 | 2536 | |
2537 | - return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) ); |
|
2537 | + return date_i18n(get_option('date_format'), strtotime($due_date)); |
|
2538 | 2538 | } |
2539 | 2539 | |
2540 | 2540 | public function get_completed_date() { |
2541 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
2541 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
2542 | 2542 | } |
2543 | 2543 | |
2544 | - public function get_invoice_date( $formatted = true ) { |
|
2544 | + public function get_invoice_date($formatted = true) { |
|
2545 | 2545 | $date_completed = $this->completed_date; |
2546 | 2546 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
2547 | 2547 | |
2548 | - if ( $invoice_date == '' ) { |
|
2548 | + if ($invoice_date == '') { |
|
2549 | 2549 | $date_created = $this->date; |
2550 | 2550 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
2551 | 2551 | } |
2552 | 2552 | |
2553 | - if ( $formatted && $invoice_date ) { |
|
2554 | - $invoice_date = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) ); |
|
2553 | + if ($formatted && $invoice_date) { |
|
2554 | + $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date)); |
|
2555 | 2555 | } |
2556 | 2556 | |
2557 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
2557 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
2558 | 2558 | } |
2559 | 2559 | |
2560 | 2560 | public function get_ip() { |
2561 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
2561 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
2562 | 2562 | } |
2563 | 2563 | |
2564 | 2564 | /** |
2565 | 2565 | * Checks if the invoice has a given status. |
2566 | 2566 | */ |
2567 | - public function has_status( $status ) { |
|
2568 | - $status = wpinv_parse_list( $status ); |
|
2569 | - return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status ); |
|
2567 | + public function has_status($status) { |
|
2568 | + $status = wpinv_parse_list($status); |
|
2569 | + return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status); |
|
2570 | 2570 | } |
2571 | 2571 | |
2572 | - public function add_item( $item_id = 0, $args = array() ) { |
|
2572 | + public function add_item($item_id = 0, $args = array()) { |
|
2573 | 2573 | global $wpi_current_id, $wpi_item_id; |
2574 | 2574 | |
2575 | - $item = new WPInv_Item( $item_id ); |
|
2575 | + $item = new WPInv_Item($item_id); |
|
2576 | 2576 | |
2577 | 2577 | // Bail if this post isn't a item |
2578 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
2578 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
2579 | 2579 | return false; |
2580 | 2580 | } |
2581 | 2581 | |
@@ -2594,8 +2594,8 @@ discard block |
||
2594 | 2594 | 'fees' => array() |
2595 | 2595 | ); |
2596 | 2596 | |
2597 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
2598 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
2597 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
2598 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
2599 | 2599 | |
2600 | 2600 | $wpi_current_id = $this->ID; |
2601 | 2601 | $wpi_item_id = $item->ID; |
@@ -2607,19 +2607,19 @@ discard block |
||
2607 | 2607 | $found_cart_key = false; |
2608 | 2608 | |
2609 | 2609 | if ($has_quantities) { |
2610 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
2610 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
2611 | 2611 | |
2612 | - foreach ( $this->items as $key => $cart_item ) { |
|
2613 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
2612 | + foreach ($this->items as $key => $cart_item) { |
|
2613 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
2614 | 2614 | continue; |
2615 | 2615 | } |
2616 | 2616 | |
2617 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
2617 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
2618 | 2618 | break; |
2619 | 2619 | } |
2620 | 2620 | |
2621 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
2622 | - if ( $item_id != $cart_item['id'] ) { |
|
2621 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
2622 | + if ($item_id != $cart_item['id']) { |
|
2623 | 2623 | continue; |
2624 | 2624 | } |
2625 | 2625 | |
@@ -2631,29 +2631,29 @@ discard block |
||
2631 | 2631 | if ($has_quantities && $found_cart_key !== false) { |
2632 | 2632 | $cart_item = $this->cart_details[$found_cart_key]; |
2633 | 2633 | $item_price = $cart_item['item_price']; |
2634 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
2635 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
2634 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
2635 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
2636 | 2636 | |
2637 | 2637 | $new_quantity = $quantity + $args['quantity']; |
2638 | 2638 | $subtotal = $item_price * $new_quantity; |
2639 | 2639 | |
2640 | 2640 | $args['quantity'] = $new_quantity; |
2641 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
2642 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2641 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
2642 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2643 | 2643 | |
2644 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
2645 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
2644 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
2645 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
2646 | 2646 | // The total increase equals the number removed * the item_price |
2647 | - $total_increased = wpinv_round_amount( $item_price ); |
|
2647 | + $total_increased = wpinv_round_amount($item_price); |
|
2648 | 2648 | |
2649 | - if ( wpinv_prices_include_tax() ) { |
|
2650 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2649 | + if (wpinv_prices_include_tax()) { |
|
2650 | + $subtotal -= wpinv_round_amount($tax); |
|
2651 | 2651 | } |
2652 | 2652 | |
2653 | - $total = $subtotal - $discount + $tax; |
|
2653 | + $total = $subtotal - $discount + $tax; |
|
2654 | 2654 | |
2655 | 2655 | // Do not allow totals to go negative |
2656 | - if( $total < 0 ) { |
|
2656 | + if ($total < 0) { |
|
2657 | 2657 | $total = 0; |
2658 | 2658 | } |
2659 | 2659 | |
@@ -2669,25 +2669,25 @@ discard block |
||
2669 | 2669 | $this->cart_details[$found_cart_key] = $cart_item; |
2670 | 2670 | } else { |
2671 | 2671 | // Set custom price. |
2672 | - if ( $args['custom_price'] !== '' ) { |
|
2672 | + if ($args['custom_price'] !== '') { |
|
2673 | 2673 | $item_price = $args['custom_price']; |
2674 | 2674 | } else { |
2675 | 2675 | // Allow overriding the price |
2676 | - if ( false !== $args['item_price'] ) { |
|
2676 | + if (false !== $args['item_price']) { |
|
2677 | 2677 | $item_price = $args['item_price']; |
2678 | 2678 | } else { |
2679 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
2679 | + $item_price = wpinv_get_item_price($item->ID); |
|
2680 | 2680 | } |
2681 | 2681 | } |
2682 | 2682 | |
2683 | 2683 | // Sanitizing the price here so we don't have a dozen calls later |
2684 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
2685 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
2684 | + $item_price = wpinv_sanitize_amount($item_price); |
|
2685 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
2686 | 2686 | |
2687 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
2688 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
2689 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
2690 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2687 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
2688 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
2689 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
2690 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2691 | 2691 | |
2692 | 2692 | // Setup the items meta item |
2693 | 2693 | $new_item = array( |
@@ -2695,29 +2695,29 @@ discard block |
||
2695 | 2695 | 'quantity' => $args['quantity'], |
2696 | 2696 | ); |
2697 | 2697 | |
2698 | - $this->items[] = $new_item; |
|
2698 | + $this->items[] = $new_item; |
|
2699 | 2699 | |
2700 | - if ( wpinv_prices_include_tax() ) { |
|
2701 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2700 | + if (wpinv_prices_include_tax()) { |
|
2701 | + $subtotal -= wpinv_round_amount($tax); |
|
2702 | 2702 | } |
2703 | 2703 | |
2704 | - $total = $subtotal - $discount + $tax; |
|
2704 | + $total = $subtotal - $discount + $tax; |
|
2705 | 2705 | |
2706 | 2706 | // Do not allow totals to go negative |
2707 | - if( $total < 0 ) { |
|
2707 | + if ($total < 0) { |
|
2708 | 2708 | $total = 0; |
2709 | 2709 | } |
2710 | 2710 | |
2711 | 2711 | $this->cart_details[] = array( |
2712 | 2712 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
2713 | 2713 | 'id' => $item->ID, |
2714 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
2715 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
2714 | + 'item_price' => wpinv_round_amount($item_price), |
|
2715 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
2716 | 2716 | 'quantity' => $args['quantity'], |
2717 | 2717 | 'discount' => $discount, |
2718 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
2719 | - 'tax' => wpinv_round_amount( $tax ), |
|
2720 | - 'price' => wpinv_round_amount( $total ), |
|
2718 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
2719 | + 'tax' => wpinv_round_amount($tax), |
|
2720 | + 'price' => wpinv_round_amount($total), |
|
2721 | 2721 | 'vat_rate' => $tax_rate, |
2722 | 2722 | 'vat_class' => $tax_class, |
2723 | 2723 | 'meta' => $args['meta'], |
@@ -2727,18 +2727,18 @@ discard block |
||
2727 | 2727 | $subtotal = $subtotal - $discount; |
2728 | 2728 | } |
2729 | 2729 | |
2730 | - $added_item = end( $this->cart_details ); |
|
2731 | - $added_item['action'] = 'add'; |
|
2730 | + $added_item = end($this->cart_details); |
|
2731 | + $added_item['action'] = 'add'; |
|
2732 | 2732 | |
2733 | 2733 | $this->pending['items'][] = $added_item; |
2734 | 2734 | |
2735 | - $this->increase_subtotal( $subtotal ); |
|
2736 | - $this->increase_tax( $tax ); |
|
2735 | + $this->increase_subtotal($subtotal); |
|
2736 | + $this->increase_tax($tax); |
|
2737 | 2737 | |
2738 | 2738 | return true; |
2739 | 2739 | } |
2740 | 2740 | |
2741 | - public function remove_item( $item_id, $args = array() ) { |
|
2741 | + public function remove_item($item_id, $args = array()) { |
|
2742 | 2742 | |
2743 | 2743 | // Set some defaults |
2744 | 2744 | $defaults = array( |
@@ -2747,51 +2747,51 @@ discard block |
||
2747 | 2747 | 'custom_price' => '', |
2748 | 2748 | 'cart_index' => false, |
2749 | 2749 | ); |
2750 | - $args = wp_parse_args( $args, $defaults ); |
|
2750 | + $args = wp_parse_args($args, $defaults); |
|
2751 | 2751 | |
2752 | 2752 | // Bail if this post isn't a item |
2753 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
2753 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
2754 | 2754 | return false; |
2755 | 2755 | } |
2756 | 2756 | |
2757 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
2757 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
2758 | 2758 | |
2759 | - foreach ( $this->items as $key => $item ) { |
|
2760 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
2759 | + foreach ($this->items as $key => $item) { |
|
2760 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
2761 | 2761 | continue; |
2762 | 2762 | } |
2763 | 2763 | |
2764 | - if ( false !== $args['cart_index'] ) { |
|
2765 | - $cart_index = absint( $args['cart_index'] ); |
|
2766 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
2764 | + if (false !== $args['cart_index']) { |
|
2765 | + $cart_index = absint($args['cart_index']); |
|
2766 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
2767 | 2767 | |
2768 | - if ( ! empty( $cart_item ) ) { |
|
2768 | + if (!empty($cart_item)) { |
|
2769 | 2769 | // If the cart index item isn't the same item ID, don't remove it |
2770 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
2770 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
2771 | 2771 | continue; |
2772 | 2772 | } |
2773 | 2773 | } |
2774 | 2774 | } |
2775 | 2775 | |
2776 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
2777 | - if ( $item_quantity > $args['quantity'] ) { |
|
2778 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
2776 | + $item_quantity = $this->items[$key]['quantity']; |
|
2777 | + if ($item_quantity > $args['quantity']) { |
|
2778 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
2779 | 2779 | break; |
2780 | 2780 | } else { |
2781 | - unset( $this->items[ $key ] ); |
|
2781 | + unset($this->items[$key]); |
|
2782 | 2782 | break; |
2783 | 2783 | } |
2784 | 2784 | } |
2785 | 2785 | |
2786 | 2786 | $found_cart_key = false; |
2787 | - if ( false === $args['cart_index'] ) { |
|
2788 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
2789 | - if ( $item_id != $item['id'] ) { |
|
2787 | + if (false === $args['cart_index']) { |
|
2788 | + foreach ($this->cart_details as $cart_key => $item) { |
|
2789 | + if ($item_id != $item['id']) { |
|
2790 | 2790 | continue; |
2791 | 2791 | } |
2792 | 2792 | |
2793 | - if ( false !== $args['item_price'] ) { |
|
2794 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
2793 | + if (false !== $args['item_price']) { |
|
2794 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
2795 | 2795 | continue; |
2796 | 2796 | } |
2797 | 2797 | } |
@@ -2800,13 +2800,13 @@ discard block |
||
2800 | 2800 | break; |
2801 | 2801 | } |
2802 | 2802 | } else { |
2803 | - $cart_index = absint( $args['cart_index'] ); |
|
2803 | + $cart_index = absint($args['cart_index']); |
|
2804 | 2804 | |
2805 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
2805 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
2806 | 2806 | return false; // Invalid cart index passed. |
2807 | 2807 | } |
2808 | 2808 | |
2809 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
2809 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
2810 | 2810 | return false; // We still need the proper Item ID to be sure. |
2811 | 2811 | } |
2812 | 2812 | |
@@ -2814,41 +2814,41 @@ discard block |
||
2814 | 2814 | } |
2815 | 2815 | |
2816 | 2816 | $cart_item = $this->cart_details[$found_cart_key]; |
2817 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
2817 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
2818 | 2818 | |
2819 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
2819 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
2820 | 2820 | //return false; // Invoice must contain at least one item. |
2821 | 2821 | } |
2822 | 2822 | |
2823 | - $discounts = $this->get_discounts(); |
|
2823 | + $discounts = $this->get_discounts(); |
|
2824 | 2824 | |
2825 | - if ( $quantity > $args['quantity'] ) { |
|
2825 | + if ($quantity > $args['quantity']) { |
|
2826 | 2826 | $item_price = $cart_item['item_price']; |
2827 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
2827 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
2828 | 2828 | |
2829 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
2829 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
2830 | 2830 | $subtotal = $item_price * $new_quantity; |
2831 | 2831 | |
2832 | 2832 | $args['quantity'] = $new_quantity; |
2833 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
2834 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2833 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
2834 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2835 | 2835 | |
2836 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
2837 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
2838 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
2839 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
2836 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
2837 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
2838 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
2839 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
2840 | 2840 | |
2841 | 2841 | // The total increase equals the number removed * the item_price |
2842 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
2842 | + $total_decrease = wpinv_round_amount($item_price); |
|
2843 | 2843 | |
2844 | - if ( wpinv_prices_include_tax() ) { |
|
2845 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2844 | + if (wpinv_prices_include_tax()) { |
|
2845 | + $subtotal -= wpinv_round_amount($tax); |
|
2846 | 2846 | } |
2847 | 2847 | |
2848 | - $total = $subtotal - $discount + $tax; |
|
2848 | + $total = $subtotal - $discount + $tax; |
|
2849 | 2849 | |
2850 | 2850 | // Do not allow totals to go negative |
2851 | - if( $total < 0 ) { |
|
2851 | + if ($total < 0) { |
|
2852 | 2852 | $total = 0; |
2853 | 2853 | } |
2854 | 2854 | |
@@ -2867,16 +2867,16 @@ discard block |
||
2867 | 2867 | |
2868 | 2868 | $this->cart_details[$found_cart_key] = $cart_item; |
2869 | 2869 | |
2870 | - $remove_item = end( $this->cart_details ); |
|
2870 | + $remove_item = end($this->cart_details); |
|
2871 | 2871 | } else { |
2872 | 2872 | $item_price = $cart_item['item_price']; |
2873 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
2874 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
2873 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
2874 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
2875 | 2875 | |
2876 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
2876 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
2877 | 2877 | $tax_decrease = $tax; |
2878 | 2878 | |
2879 | - unset( $this->cart_details[$found_cart_key] ); |
|
2879 | + unset($this->cart_details[$found_cart_key]); |
|
2880 | 2880 | |
2881 | 2881 | $remove_item = $args; |
2882 | 2882 | $remove_item['id'] = $item_id; |
@@ -2887,8 +2887,8 @@ discard block |
||
2887 | 2887 | $remove_item['action'] = 'remove'; |
2888 | 2888 | $this->pending['items'][] = $remove_item; |
2889 | 2889 | |
2890 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
2891 | - $this->decrease_tax( $tax_decrease ); |
|
2890 | + $this->decrease_subtotal($subtotal_decrease); |
|
2891 | + $this->decrease_tax($tax_decrease); |
|
2892 | 2892 | |
2893 | 2893 | return true; |
2894 | 2894 | } |
@@ -2896,7 +2896,7 @@ discard block |
||
2896 | 2896 | public function update_items($temp = false) { |
2897 | 2897 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
2898 | 2898 | |
2899 | - if ( ! empty( $this->cart_details ) ) { |
|
2899 | + if (!empty($this->cart_details)) { |
|
2900 | 2900 | $wpi_nosave = $temp; |
2901 | 2901 | $cart_subtotal = 0; |
2902 | 2902 | $cart_discount = 0; |
@@ -2906,46 +2906,46 @@ discard block |
||
2906 | 2906 | $_POST['wpinv_country'] = $this->country; |
2907 | 2907 | $_POST['wpinv_state'] = $this->state; |
2908 | 2908 | |
2909 | - foreach ( $this->cart_details as $item ) { |
|
2909 | + foreach ($this->cart_details as $item) { |
|
2910 | 2910 | $item_price = $item['item_price']; |
2911 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
2912 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
2911 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
2912 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
2913 | 2913 | $subtotal = $item_price * $quantity; |
2914 | 2914 | |
2915 | 2915 | $wpi_current_id = $this->ID; |
2916 | 2916 | $wpi_item_id = $item['id']; |
2917 | 2917 | |
2918 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
2918 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
2919 | 2919 | |
2920 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
2921 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
2922 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2920 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
2921 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
2922 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2923 | 2923 | |
2924 | - if ( ! $this->is_taxable() ) { |
|
2924 | + if (!$this->is_taxable()) { |
|
2925 | 2925 | $tax = 0; |
2926 | 2926 | } |
2927 | 2927 | |
2928 | - if ( wpinv_prices_include_tax() ) { |
|
2929 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2928 | + if (wpinv_prices_include_tax()) { |
|
2929 | + $subtotal -= wpinv_round_amount($tax); |
|
2930 | 2930 | } |
2931 | 2931 | |
2932 | - $total = $subtotal - $discount + $tax; |
|
2932 | + $total = $subtotal - $discount + $tax; |
|
2933 | 2933 | |
2934 | 2934 | // Do not allow totals to go negative |
2935 | - if( $total < 0 ) { |
|
2935 | + if ($total < 0) { |
|
2936 | 2936 | $total = 0; |
2937 | 2937 | } |
2938 | 2938 | |
2939 | 2939 | $cart_details[] = array( |
2940 | 2940 | 'id' => $item['id'], |
2941 | 2941 | 'name' => $item['name'], |
2942 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
2943 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
2942 | + 'item_price' => wpinv_round_amount($item_price), |
|
2943 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
2944 | 2944 | 'quantity' => $quantity, |
2945 | 2945 | 'discount' => $discount, |
2946 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
2947 | - 'tax' => wpinv_round_amount( $tax ), |
|
2948 | - 'price' => wpinv_round_amount( $total ), |
|
2946 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
2947 | + 'tax' => wpinv_round_amount($tax), |
|
2948 | + 'price' => wpinv_round_amount($total), |
|
2949 | 2949 | 'vat_rate' => $tax_rate, |
2950 | 2950 | 'vat_class' => $tax_class, |
2951 | 2951 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
@@ -2957,21 +2957,21 @@ discard block |
||
2957 | 2957 | $cart_tax += (float) $tax; |
2958 | 2958 | } |
2959 | 2959 | |
2960 | - if ( $cart_subtotal < 0 ) { |
|
2960 | + if ($cart_subtotal < 0) { |
|
2961 | 2961 | $cart_subtotal = 0; |
2962 | 2962 | } |
2963 | 2963 | |
2964 | - if ( $cart_discount < 0 ) { |
|
2964 | + if ($cart_discount < 0) { |
|
2965 | 2965 | $cart_discount = 0; |
2966 | 2966 | } |
2967 | 2967 | |
2968 | - if ( $cart_tax < 0 ) { |
|
2968 | + if ($cart_tax < 0) { |
|
2969 | 2969 | $cart_tax = 0; |
2970 | 2970 | } |
2971 | 2971 | |
2972 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
2973 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
2974 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
2972 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
2973 | + $this->tax = wpinv_round_amount($cart_tax); |
|
2974 | + $this->discount = wpinv_round_amount($cart_discount); |
|
2975 | 2975 | |
2976 | 2976 | $this->recalculate_total(); |
2977 | 2977 | |
@@ -2986,13 +2986,13 @@ discard block |
||
2986 | 2986 | */ |
2987 | 2987 | public function validate_discount() { |
2988 | 2988 | |
2989 | - $discounts = $this->get_discounts( true ); |
|
2989 | + $discounts = $this->get_discounts(true); |
|
2990 | 2990 | |
2991 | - if ( empty( $discounts ) ) { |
|
2991 | + if (empty($discounts)) { |
|
2992 | 2992 | return false; |
2993 | 2993 | } |
2994 | 2994 | |
2995 | - $discount = wpinv_get_discount_obj( $discounts[0] ); |
|
2995 | + $discount = wpinv_get_discount_obj($discounts[0]); |
|
2996 | 2996 | |
2997 | 2997 | // Ensure it is active. |
2998 | 2998 | return $discount->exists(); |
@@ -3001,62 +3001,62 @@ discard block |
||
3001 | 3001 | |
3002 | 3002 | public function recalculate_totals($temp = false) { |
3003 | 3003 | $this->update_items($temp); |
3004 | - $this->save( true ); |
|
3004 | + $this->save(true); |
|
3005 | 3005 | |
3006 | 3006 | return $this; |
3007 | 3007 | } |
3008 | 3008 | |
3009 | 3009 | public function needs_payment() { |
3010 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
3010 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
3011 | 3011 | |
3012 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
3012 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
3013 | 3013 | $needs_payment = true; |
3014 | 3014 | } else { |
3015 | 3015 | $needs_payment = false; |
3016 | 3016 | } |
3017 | 3017 | |
3018 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
3018 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
3019 | 3019 | } |
3020 | 3020 | |
3021 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
3021 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
3022 | 3022 | $pay_url = wpinv_get_checkout_uri(); |
3023 | 3023 | |
3024 | - if ( is_ssl() ) { |
|
3025 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
3024 | + if (is_ssl()) { |
|
3025 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
3026 | 3026 | } |
3027 | 3027 | |
3028 | 3028 | $key = $this->get_key(); |
3029 | 3029 | |
3030 | - if ( $with_key ) { |
|
3031 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
3030 | + if ($with_key) { |
|
3031 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
3032 | 3032 | } else { |
3033 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
3033 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
3034 | 3034 | } |
3035 | 3035 | |
3036 | - if ( $secret ) { |
|
3037 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
3036 | + if ($secret) { |
|
3037 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
3038 | 3038 | } |
3039 | 3039 | |
3040 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
3040 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
3041 | 3041 | } |
3042 | 3042 | |
3043 | - public function get_view_url( $with_key = false ) { |
|
3044 | - $invoice_url = get_permalink( $this->ID ); |
|
3043 | + public function get_view_url($with_key = false) { |
|
3044 | + $invoice_url = get_permalink($this->ID); |
|
3045 | 3045 | |
3046 | - if ( $with_key ) { |
|
3047 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
3046 | + if ($with_key) { |
|
3047 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
3048 | 3048 | } |
3049 | 3049 | |
3050 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
3050 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
3051 | 3051 | } |
3052 | 3052 | |
3053 | 3053 | /** |
3054 | 3054 | * Generates a unique key for the invoice. |
3055 | 3055 | */ |
3056 | - public function generate_key( $string = '' ) { |
|
3057 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
3056 | + public function generate_key($string = '') { |
|
3057 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
3058 | 3058 | return strtolower( |
3059 | - md5( $this->get_id() . $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) |
|
3059 | + md5($this->get_id() . $string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true)) |
|
3060 | 3060 | ); |
3061 | 3061 | } |
3062 | 3062 | |
@@ -3066,32 +3066,32 @@ discard block |
||
3066 | 3066 | public function generate_number() { |
3067 | 3067 | $number = $this->get_id(); |
3068 | 3068 | |
3069 | - if ( $this->has_status( 'auto-draft' ) && wpinv_sequential_number_active( $this->post_type ) ) { |
|
3070 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
3069 | + if ($this->has_status('auto-draft') && wpinv_sequential_number_active($this->post_type)) { |
|
3070 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
3071 | 3071 | $number = $next_number; |
3072 | 3072 | } |
3073 | 3073 | |
3074 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
3074 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
3075 | 3075 | } |
3076 | 3076 | |
3077 | 3077 | public function is_recurring() { |
3078 | - if ( empty( $this->cart_details ) ) { |
|
3078 | + if (empty($this->cart_details)) { |
|
3079 | 3079 | return false; |
3080 | 3080 | } |
3081 | 3081 | |
3082 | 3082 | $has_subscription = false; |
3083 | - foreach( $this->cart_details as $cart_item ) { |
|
3084 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
3083 | + foreach ($this->cart_details as $cart_item) { |
|
3084 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
3085 | 3085 | $has_subscription = true; |
3086 | 3086 | break; |
3087 | 3087 | } |
3088 | 3088 | } |
3089 | 3089 | |
3090 | - if ( count( $this->cart_details ) > 1 ) { |
|
3090 | + if (count($this->cart_details) > 1) { |
|
3091 | 3091 | $has_subscription = false; |
3092 | 3092 | } |
3093 | 3093 | |
3094 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
3094 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
3095 | 3095 | } |
3096 | 3096 | |
3097 | 3097 | /** |
@@ -3102,13 +3102,13 @@ discard block |
||
3102 | 3102 | public function is_free_trial() { |
3103 | 3103 | $is_free_trial = false; |
3104 | 3104 | |
3105 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
3106 | - if ( ! empty( $item ) && ( $item->has_free_trial() || ( $this->total == 0 && $this->discount_first_payment_only() ) ) ) { |
|
3105 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
3106 | + if (!empty($item) && ($item->has_free_trial() || ($this->total == 0 && $this->discount_first_payment_only()))) { |
|
3107 | 3107 | $is_free_trial = true; |
3108 | 3108 | } |
3109 | 3109 | } |
3110 | 3110 | |
3111 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
3111 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
3112 | 3112 | } |
3113 | 3113 | |
3114 | 3114 | /** |
@@ -3118,12 +3118,12 @@ discard block |
||
3118 | 3118 | |
3119 | 3119 | $parent = $this; |
3120 | 3120 | |
3121 | - if ( $this->is_renewal() ) { |
|
3121 | + if ($this->is_renewal()) { |
|
3122 | 3122 | $parent = $this->get_parent_payment(); |
3123 | 3123 | } |
3124 | 3124 | |
3125 | - if ( $parent && $item = $parent->get_recurring( true ) ) { |
|
3126 | - return ! ( ! empty( $item ) && $item->has_free_trial() ); |
|
3125 | + if ($parent && $item = $parent->get_recurring(true)) { |
|
3126 | + return !(!empty($item) && $item->has_free_trial()); |
|
3127 | 3127 | } |
3128 | 3128 | return false; |
3129 | 3129 | |
@@ -3134,104 +3134,104 @@ discard block |
||
3134 | 3134 | */ |
3135 | 3135 | public function discount_first_payment_only() { |
3136 | 3136 | |
3137 | - if ( empty( $this->discounts ) || ! $this->is_recurring() ) { |
|
3137 | + if (empty($this->discounts) || !$this->is_recurring()) { |
|
3138 | 3138 | return true; |
3139 | 3139 | } |
3140 | 3140 | |
3141 | - $discount = wpinv_get_discount_obj( $this->discounts[0] ); |
|
3141 | + $discount = wpinv_get_discount_obj($this->discounts[0]); |
|
3142 | 3142 | |
3143 | - if ( ! $discount || ! $discount->exists() ) { |
|
3143 | + if (!$discount || !$discount->exists()) { |
|
3144 | 3144 | return true; |
3145 | 3145 | } |
3146 | 3146 | |
3147 | - return ! $discount->get_is_recurring(); |
|
3147 | + return !$discount->get_is_recurring(); |
|
3148 | 3148 | } |
3149 | 3149 | |
3150 | 3150 | public function is_initial_free() { |
3151 | 3151 | $is_initial_free = false; |
3152 | 3152 | |
3153 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
3153 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
3154 | 3154 | $is_initial_free = true; |
3155 | 3155 | } |
3156 | 3156 | |
3157 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
3157 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
3158 | 3158 | } |
3159 | 3159 | |
3160 | - public function get_recurring( $object = false ) { |
|
3160 | + public function get_recurring($object = false) { |
|
3161 | 3161 | $item = NULL; |
3162 | 3162 | |
3163 | - if ( empty( $this->cart_details ) ) { |
|
3163 | + if (empty($this->cart_details)) { |
|
3164 | 3164 | return $item; |
3165 | 3165 | } |
3166 | 3166 | |
3167 | - foreach( $this->cart_details as $cart_item ) { |
|
3168 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
3167 | + foreach ($this->cart_details as $cart_item) { |
|
3168 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
3169 | 3169 | $item = $cart_item['id']; |
3170 | 3170 | break; |
3171 | 3171 | } |
3172 | 3172 | } |
3173 | 3173 | |
3174 | - if ( $object ) { |
|
3175 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
3174 | + if ($object) { |
|
3175 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
3176 | 3176 | |
3177 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
3177 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
3178 | 3178 | } |
3179 | 3179 | |
3180 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
3180 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
3181 | 3181 | } |
3182 | 3182 | |
3183 | 3183 | public function get_subscription_name() { |
3184 | - $item = $this->get_recurring( true ); |
|
3184 | + $item = $this->get_recurring(true); |
|
3185 | 3185 | |
3186 | - if ( empty( $item ) ) { |
|
3186 | + if (empty($item)) { |
|
3187 | 3187 | return NULL; |
3188 | 3188 | } |
3189 | 3189 | |
3190 | - if ( !($name = $item->get_name()) ) { |
|
3190 | + if (!($name = $item->get_name())) { |
|
3191 | 3191 | $name = $item->post_name; |
3192 | 3192 | } |
3193 | 3193 | |
3194 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
3194 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
3195 | 3195 | } |
3196 | 3196 | |
3197 | 3197 | public function get_subscription_id() { |
3198 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
3198 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
3199 | 3199 | |
3200 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
3201 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
3200 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
3201 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
3202 | 3202 | |
3203 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
3203 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
3204 | 3204 | } |
3205 | 3205 | |
3206 | 3206 | return $subscription_id; |
3207 | 3207 | } |
3208 | 3208 | |
3209 | 3209 | public function is_parent() { |
3210 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
3210 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
3211 | 3211 | |
3212 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
3212 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
3213 | 3213 | } |
3214 | 3214 | |
3215 | 3215 | public function is_renewal() { |
3216 | 3216 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
3217 | 3217 | |
3218 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
3218 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
3219 | 3219 | } |
3220 | 3220 | |
3221 | 3221 | public function get_parent_payment() { |
3222 | 3222 | $parent_payment = NULL; |
3223 | 3223 | |
3224 | - if ( $this->is_renewal() ) { |
|
3225 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
3224 | + if ($this->is_renewal()) { |
|
3225 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
3226 | 3226 | } |
3227 | 3227 | |
3228 | 3228 | return $parent_payment; |
3229 | 3229 | } |
3230 | 3230 | |
3231 | 3231 | public function is_paid() { |
3232 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
3232 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
3233 | 3233 | |
3234 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
3234 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
3235 | 3235 | } |
3236 | 3236 | |
3237 | 3237 | /** |
@@ -3244,23 +3244,23 @@ discard block |
||
3244 | 3244 | } |
3245 | 3245 | |
3246 | 3246 | public function is_refunded() { |
3247 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
3247 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
3248 | 3248 | |
3249 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
3249 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
3250 | 3250 | } |
3251 | 3251 | |
3252 | 3252 | public function is_free() { |
3253 | 3253 | $is_free = false; |
3254 | 3254 | |
3255 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
3256 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
3257 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
3255 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
3256 | + if ($this->is_parent() && $this->is_recurring()) { |
|
3257 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
3258 | 3258 | } else { |
3259 | 3259 | $is_free = true; |
3260 | 3260 | } |
3261 | 3261 | } |
3262 | 3262 | |
3263 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
3263 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
3264 | 3264 | } |
3265 | 3265 | |
3266 | 3266 | public function has_vat() { |
@@ -3268,41 +3268,41 @@ discard block |
||
3268 | 3268 | |
3269 | 3269 | $requires_vat = false; |
3270 | 3270 | |
3271 | - if ( $this->country ) { |
|
3271 | + if ($this->country) { |
|
3272 | 3272 | $wpi_country = $this->country; |
3273 | 3273 | |
3274 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
3274 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
3275 | 3275 | } |
3276 | 3276 | |
3277 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
3277 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
3278 | 3278 | } |
3279 | 3279 | |
3280 | 3280 | public function refresh_item_ids() { |
3281 | 3281 | $item_ids = array(); |
3282 | 3282 | |
3283 | - if ( ! empty( $this->cart_details ) ) { |
|
3284 | - foreach ( array_keys( $this->cart_details ) as $item ) { |
|
3285 | - if ( ! empty( $item['id'] ) ) { |
|
3283 | + if (!empty($this->cart_details)) { |
|
3284 | + foreach (array_keys($this->cart_details) as $item) { |
|
3285 | + if (!empty($item['id'])) { |
|
3286 | 3286 | $item_ids[] = $item['id']; |
3287 | 3287 | } |
3288 | 3288 | } |
3289 | 3289 | } |
3290 | 3290 | |
3291 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
3291 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
3292 | 3292 | |
3293 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
3293 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
3294 | 3294 | } |
3295 | 3295 | |
3296 | - public function get_invoice_quote_type( $post_id ) { |
|
3297 | - if ( empty( $post_id ) ) { |
|
3296 | + public function get_invoice_quote_type($post_id) { |
|
3297 | + if (empty($post_id)) { |
|
3298 | 3298 | return ''; |
3299 | 3299 | } |
3300 | 3300 | |
3301 | - $type = get_post_type( $post_id ); |
|
3301 | + $type = get_post_type($post_id); |
|
3302 | 3302 | |
3303 | - if ( 'wpi_invoice' === $type ) { |
|
3303 | + if ('wpi_invoice' === $type) { |
|
3304 | 3304 | $post_type = __('Invoice', 'invoicing'); |
3305 | - } else{ |
|
3305 | + } else { |
|
3306 | 3306 | $post_type = __('Quote', 'invoicing'); |
3307 | 3307 | } |
3308 | 3308 |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,24 +16,24 @@ discard block |
||
16 | 16 | */ |
17 | 17 | function getpaid_get_invoice_post_types() { |
18 | 18 | $post_types = array( |
19 | - 'wpi_quote' => __( 'Quote', 'invoicing' ), |
|
20 | - 'wpi_invoice' => __( 'Invoice', 'invoicing' ), |
|
19 | + 'wpi_quote' => __('Quote', 'invoicing'), |
|
20 | + 'wpi_invoice' => __('Invoice', 'invoicing'), |
|
21 | 21 | ); |
22 | 22 | |
23 | - return apply_filters( 'getpaid_invoice_post_types', $post_types ); |
|
23 | + return apply_filters('getpaid_invoice_post_types', $post_types); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Checks if this is an invocing post type. |
28 | 28 | */ |
29 | -function getpaid_is_invoice_post_type( $post_type ) { |
|
30 | - return array_key_exists( $post_type, getpaid_get_invoice_post_types() ); |
|
29 | +function getpaid_is_invoice_post_type($post_type) { |
|
30 | + return array_key_exists($post_type, getpaid_get_invoice_post_types()); |
|
31 | 31 | } |
32 | 32 | |
33 | 33 | function wpinv_get_invoice_cart_id() { |
34 | 34 | $wpinv_checkout = wpinv_get_checkout_session(); |
35 | 35 | |
36 | - if ( !empty( $wpinv_checkout['invoice_id'] ) ) { |
|
36 | + if (!empty($wpinv_checkout['invoice_id'])) { |
|
37 | 37 | return $wpinv_checkout['invoice_id']; |
38 | 38 | } |
39 | 39 | |
@@ -47,48 +47,48 @@ discard block |
||
47 | 47 | * @param bool $wp_error Whether to return false or WP_Error on failure. |
48 | 48 | * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success. |
49 | 49 | */ |
50 | -function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) { |
|
51 | - if ( empty( $invoice_data ) ) { |
|
50 | +function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) { |
|
51 | + if (empty($invoice_data)) { |
|
52 | 52 | return false; |
53 | 53 | } |
54 | 54 | |
55 | - if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) { |
|
56 | - return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0; |
|
55 | + if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) { |
|
56 | + return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | // If no user id is provided, default to the current user id |
60 | - if ( empty( $invoice_data['user_id'] ) ) { |
|
60 | + if (empty($invoice_data['user_id'])) { |
|
61 | 61 | $invoice_data['user_id'] = get_current_user_id(); |
62 | 62 | } |
63 | 63 | |
64 | - $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0; |
|
64 | + $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0; |
|
65 | 65 | |
66 | - if ( empty( $invoice_data['status'] ) ) { |
|
66 | + if (empty($invoice_data['status'])) { |
|
67 | 67 | $invoice_data['status'] = 'wpi-pending'; |
68 | 68 | } |
69 | 69 | |
70 | - if ( empty( $invoice_data['post_type'] ) ) { |
|
70 | + if (empty($invoice_data['post_type'])) { |
|
71 | 71 | $invoice_data['post_type'] = 'wpi_invoice'; |
72 | 72 | } |
73 | 73 | |
74 | - if ( empty( $invoice_data['ip'] ) ) { |
|
74 | + if (empty($invoice_data['ip'])) { |
|
75 | 75 | $invoice_data['ip'] = wpinv_get_ip(); |
76 | 76 | } |
77 | 77 | |
78 | 78 | // default invoice args, note that status is checked for validity in wpinv_create_invoice() |
79 | 79 | $default_args = array( |
80 | - 'invoice_id' => (int)$invoice_data['invoice_id'], |
|
81 | - 'user_id' => (int)$invoice_data['user_id'], |
|
80 | + 'invoice_id' => (int) $invoice_data['invoice_id'], |
|
81 | + 'user_id' => (int) $invoice_data['user_id'], |
|
82 | 82 | 'status' => $invoice_data['status'], |
83 | 83 | 'post_type' => $invoice_data['post_type'], |
84 | 84 | ); |
85 | 85 | |
86 | - $invoice = wpinv_create_invoice( $default_args, $invoice_data, true ); |
|
87 | - if ( is_wp_error( $invoice ) ) { |
|
86 | + $invoice = wpinv_create_invoice($default_args, $invoice_data, true); |
|
87 | + if (is_wp_error($invoice)) { |
|
88 | 88 | return $wp_error ? $invoice : 0; |
89 | 89 | } |
90 | 90 | |
91 | - if ( empty( $invoice_data['invoice_id'] ) ) { |
|
91 | + if (empty($invoice_data['invoice_id'])) { |
|
92 | 92 | //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) ); |
93 | 93 | } |
94 | 94 | |
@@ -111,24 +111,24 @@ discard block |
||
111 | 111 | 'discount' => array(), |
112 | 112 | ); |
113 | 113 | |
114 | - if ( $user_id = (int)$invoice->get_user_id() ) { |
|
115 | - if ( $user_address = wpinv_get_user_address( $user_id ) ) { |
|
116 | - $default_user_info = wp_parse_args( $user_address, $default_user_info ); |
|
114 | + if ($user_id = (int) $invoice->get_user_id()) { |
|
115 | + if ($user_address = wpinv_get_user_address($user_id)) { |
|
116 | + $default_user_info = wp_parse_args($user_address, $default_user_info); |
|
117 | 117 | } |
118 | 118 | } |
119 | 119 | |
120 | - if ( empty( $invoice_data['user_info'] ) ) { |
|
120 | + if (empty($invoice_data['user_info'])) { |
|
121 | 121 | $invoice_data['user_info'] = array(); |
122 | 122 | } |
123 | 123 | |
124 | - $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info ); |
|
124 | + $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info); |
|
125 | 125 | |
126 | - if ( empty( $user_info['first_name'] ) ) { |
|
126 | + if (empty($user_info['first_name'])) { |
|
127 | 127 | $user_info['first_name'] = $default_user_info['first_name']; |
128 | 128 | $user_info['last_name'] = $default_user_info['last_name']; |
129 | 129 | } |
130 | 130 | |
131 | - if ( empty( $user_info['country'] ) ) { |
|
131 | + if (empty($user_info['country'])) { |
|
132 | 132 | $user_info['country'] = $default_user_info['country']; |
133 | 133 | $user_info['state'] = $default_user_info['state']; |
134 | 134 | $user_info['city'] = $default_user_info['city']; |
@@ -137,13 +137,13 @@ discard block |
||
137 | 137 | $user_info['phone'] = $default_user_info['phone']; |
138 | 138 | } |
139 | 139 | |
140 | - if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) { |
|
141 | - $user_info['discount'] = (array)$user_info['discount']; |
|
140 | + if (!empty($user_info['discount']) && !is_array($user_info['discount'])) { |
|
141 | + $user_info['discount'] = (array) $user_info['discount']; |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Payment details |
145 | 145 | $payment_details = array(); |
146 | - if ( !empty( $invoice_data['payment_details'] ) ) { |
|
146 | + if (!empty($invoice_data['payment_details'])) { |
|
147 | 147 | $default_payment_details = array( |
148 | 148 | 'gateway' => 'manual', |
149 | 149 | 'gateway_title' => '', |
@@ -151,56 +151,56 @@ discard block |
||
151 | 151 | 'transaction_id' => '', |
152 | 152 | ); |
153 | 153 | |
154 | - $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details ); |
|
154 | + $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details); |
|
155 | 155 | |
156 | - if ( empty( $payment_details['gateway'] ) ) { |
|
156 | + if (empty($payment_details['gateway'])) { |
|
157 | 157 | $payment_details['gateway'] = 'manual'; |
158 | 158 | } |
159 | 159 | |
160 | - if ( empty( $payment_details['currency'] ) ) { |
|
160 | + if (empty($payment_details['currency'])) { |
|
161 | 161 | $payment_details['currency'] = wpinv_get_default_country(); |
162 | 162 | } |
163 | 163 | |
164 | - if ( empty( $payment_details['gateway_title'] ) ) { |
|
165 | - $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] ); |
|
164 | + if (empty($payment_details['gateway_title'])) { |
|
165 | + $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']); |
|
166 | 166 | } |
167 | 167 | } |
168 | 168 | |
169 | - $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) ); |
|
170 | - |
|
171 | - if ( !empty( $payment_details ) ) { |
|
172 | - $invoice->set( 'currency', $payment_details['currency'] ); |
|
173 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
174 | - $invoice->set( 'gateway_title', $payment_details['gateway_title'] ); |
|
175 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
176 | - } |
|
177 | - |
|
178 | - $invoice->set( 'user_info', $user_info ); |
|
179 | - $invoice->set( 'first_name', $user_info['first_name'] ); |
|
180 | - $invoice->set( 'last_name', $user_info['last_name'] ); |
|
181 | - $invoice->set( 'address', $user_info['address'] ); |
|
182 | - $invoice->set( 'company', $user_info['company'] ); |
|
183 | - $invoice->set( 'vat_number', $user_info['vat_number'] ); |
|
184 | - $invoice->set( 'phone', $user_info['phone'] ); |
|
185 | - $invoice->set( 'city', $user_info['city'] ); |
|
186 | - $invoice->set( 'country', $user_info['country'] ); |
|
187 | - $invoice->set( 'state', $user_info['state'] ); |
|
188 | - $invoice->set( 'zip', $user_info['zip'] ); |
|
189 | - $invoice->set( 'discounts', $user_info['discount'] ); |
|
190 | - $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) ); |
|
191 | - $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) ); |
|
192 | - $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) ); |
|
193 | - |
|
194 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) { |
|
195 | - foreach ( $invoice_data['cart_details'] as $key => $item ) { |
|
196 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
197 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
198 | - $name = !empty( $item['name'] ) ? $item['name'] : ''; |
|
199 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : ''; |
|
169 | + $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending')); |
|
170 | + |
|
171 | + if (!empty($payment_details)) { |
|
172 | + $invoice->set('currency', $payment_details['currency']); |
|
173 | + $invoice->set('gateway', $payment_details['gateway']); |
|
174 | + $invoice->set('gateway_title', $payment_details['gateway_title']); |
|
175 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
176 | + } |
|
177 | + |
|
178 | + $invoice->set('user_info', $user_info); |
|
179 | + $invoice->set('first_name', $user_info['first_name']); |
|
180 | + $invoice->set('last_name', $user_info['last_name']); |
|
181 | + $invoice->set('address', $user_info['address']); |
|
182 | + $invoice->set('company', $user_info['company']); |
|
183 | + $invoice->set('vat_number', $user_info['vat_number']); |
|
184 | + $invoice->set('phone', $user_info['phone']); |
|
185 | + $invoice->set('city', $user_info['city']); |
|
186 | + $invoice->set('country', $user_info['country']); |
|
187 | + $invoice->set('state', $user_info['state']); |
|
188 | + $invoice->set('zip', $user_info['zip']); |
|
189 | + $invoice->set('discounts', $user_info['discount']); |
|
190 | + $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip())); |
|
191 | + $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live')); |
|
192 | + $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : '')); |
|
193 | + |
|
194 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) { |
|
195 | + foreach ($invoice_data['cart_details'] as $key => $item) { |
|
196 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
197 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
198 | + $name = !empty($item['name']) ? $item['name'] : ''; |
|
199 | + $item_price = isset($item['item_price']) ? $item['item_price'] : ''; |
|
200 | 200 | |
201 | - $post_item = new WPInv_Item( $item_id ); |
|
202 | - if ( !empty( $post_item ) ) { |
|
203 | - $name = !empty( $name ) ? $name : $post_item->get_name(); |
|
201 | + $post_item = new WPInv_Item($item_id); |
|
202 | + if (!empty($post_item)) { |
|
203 | + $name = !empty($name) ? $name : $post_item->get_name(); |
|
204 | 204 | $item_price = $item_price !== '' ? $item_price : $post_item->get_price(); |
205 | 205 | } else { |
206 | 206 | continue; |
@@ -210,266 +210,266 @@ discard block |
||
210 | 210 | 'name' => $name, |
211 | 211 | 'quantity' => $quantity, |
212 | 212 | 'item_price' => $item_price, |
213 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
214 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0.00, |
|
215 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
216 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
217 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
213 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
214 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0.00, |
|
215 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
216 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
217 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
218 | 218 | ); |
219 | 219 | |
220 | - $invoice->add_item( $item_id, $args ); |
|
220 | + $invoice->add_item($item_id, $args); |
|
221 | 221 | } |
222 | 222 | } |
223 | 223 | |
224 | - $invoice->increase_tax( wpinv_get_cart_fee_tax() ); |
|
224 | + $invoice->increase_tax(wpinv_get_cart_fee_tax()); |
|
225 | 225 | |
226 | - if ( isset( $invoice_data['post_date'] ) ) { |
|
227 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
226 | + if (isset($invoice_data['post_date'])) { |
|
227 | + $invoice->set('date', $invoice_data['post_date']); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Invoice due date |
231 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
232 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
231 | + if (isset($invoice_data['due_date'])) { |
|
232 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
233 | 233 | } |
234 | 234 | |
235 | 235 | $invoice->save(); |
236 | 236 | |
237 | 237 | // Add notes |
238 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
239 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
238 | + if (!empty($invoice_data['private_note'])) { |
|
239 | + $invoice->add_note($invoice_data['private_note']); |
|
240 | 240 | } |
241 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
242 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
241 | + if (!empty($invoice_data['user_note'])) { |
|
242 | + $invoice->add_note($invoice_data['user_note'], true); |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( $invoice->is_quote() ) { |
|
245 | + if ($invoice->is_quote()) { |
|
246 | 246 | |
247 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
248 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
247 | + if (isset($invoice_data['valid_until'])) { |
|
248 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
249 | 249 | } |
250 | 250 | return $invoice; |
251 | 251 | |
252 | 252 | } |
253 | 253 | |
254 | - do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data ); |
|
254 | + do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data); |
|
255 | 255 | |
256 | - if ( ! empty( $invoice->ID ) ) { |
|
256 | + if (!empty($invoice->ID)) { |
|
257 | 257 | global $wpi_userID, $wpinv_ip_address_country; |
258 | 258 | |
259 | - if ( isset( $invoice_data['created_via'] ) ) { |
|
260 | - update_post_meta( $invoice->ID, 'wpinv_created_via', $invoice_data['created_via'] ); |
|
259 | + if (isset($invoice_data['created_via'])) { |
|
260 | + update_post_meta($invoice->ID, 'wpinv_created_via', $invoice_data['created_via']); |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | $checkout_session = wpinv_get_checkout_session(); |
264 | 264 | |
265 | 265 | $data_session = array(); |
266 | 266 | $data_session['invoice_id'] = $invoice->ID; |
267 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
267 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
268 | 268 | |
269 | - wpinv_set_checkout_session( $data_session ); |
|
269 | + wpinv_set_checkout_session($data_session); |
|
270 | 270 | |
271 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
271 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
272 | 272 | |
273 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
273 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
274 | 274 | $_POST['state'] = $invoice->state; |
275 | 275 | |
276 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
277 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
276 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
277 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
278 | 278 | |
279 | 279 | $wpinv_ip_address_country = $invoice->country; |
280 | 280 | |
281 | - $invoice = $invoice->recalculate_totals( true ); |
|
281 | + $invoice = $invoice->recalculate_totals(true); |
|
282 | 282 | |
283 | - wpinv_set_checkout_session( $checkout_session ); |
|
283 | + wpinv_set_checkout_session($checkout_session); |
|
284 | 284 | |
285 | 285 | return $invoice; |
286 | 286 | } |
287 | 287 | |
288 | - if ( $wp_error ) { |
|
289 | - if ( is_wp_error( $invoice ) ) { |
|
288 | + if ($wp_error) { |
|
289 | + if (is_wp_error($invoice)) { |
|
290 | 290 | return $invoice; |
291 | 291 | } else { |
292 | - return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) ); |
|
292 | + return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing')); |
|
293 | 293 | } |
294 | 294 | } else { |
295 | 295 | return 0; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | -function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) { |
|
300 | - $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL; |
|
299 | +function wpinv_update_invoice($invoice_data = array(), $wp_error = false) { |
|
300 | + $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL; |
|
301 | 301 | |
302 | - if ( !$invoice_ID ) { |
|
303 | - if ( $wp_error ) { |
|
304 | - return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ); |
|
302 | + if (!$invoice_ID) { |
|
303 | + if ($wp_error) { |
|
304 | + return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')); |
|
305 | 305 | } |
306 | 306 | return 0; |
307 | 307 | } |
308 | 308 | |
309 | - $invoice = wpinv_get_invoice( $invoice_ID ); |
|
309 | + $invoice = wpinv_get_invoice($invoice_ID); |
|
310 | 310 | |
311 | - $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL; |
|
311 | + $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL; |
|
312 | 312 | |
313 | - if ( empty( $invoice->ID ) ) { |
|
314 | - if ( $wp_error ) { |
|
315 | - return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) ); |
|
313 | + if (empty($invoice->ID)) { |
|
314 | + if ($wp_error) { |
|
315 | + return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing')); |
|
316 | 316 | } |
317 | 317 | return 0; |
318 | 318 | } |
319 | 319 | |
320 | - if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote() ) { |
|
321 | - if ( $wp_error ) { |
|
322 | - return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) ); |
|
320 | + if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) { |
|
321 | + if ($wp_error) { |
|
322 | + return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing')); |
|
323 | 323 | } |
324 | 324 | return 0; |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Invoice status |
328 | - if ( !empty( $invoice_data['status'] ) ) { |
|
329 | - $invoice->set( 'status', $invoice_data['status'] ); |
|
328 | + if (!empty($invoice_data['status'])) { |
|
329 | + $invoice->set('status', $invoice_data['status']); |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | // Invoice date |
333 | - if ( !empty( $invoice_data['post_date'] ) ) { |
|
334 | - $invoice->set( 'date', $invoice_data['post_date'] ); |
|
333 | + if (!empty($invoice_data['post_date'])) { |
|
334 | + $invoice->set('date', $invoice_data['post_date']); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | // Invoice due date |
338 | - if ( isset( $invoice_data['due_date'] ) ) { |
|
339 | - $invoice->set( 'due_date', $invoice_data['due_date'] ); |
|
338 | + if (isset($invoice_data['due_date'])) { |
|
339 | + $invoice->set('due_date', $invoice_data['due_date']); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | // Invoice IP address |
343 | - if ( !empty( $invoice_data['ip'] ) ) { |
|
344 | - $invoice->set( 'ip', $invoice_data['ip'] ); |
|
343 | + if (!empty($invoice_data['ip'])) { |
|
344 | + $invoice->set('ip', $invoice_data['ip']); |
|
345 | 345 | } |
346 | 346 | |
347 | 347 | // User info |
348 | - if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) { |
|
349 | - $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info ); |
|
348 | + if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) { |
|
349 | + $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info); |
|
350 | 350 | |
351 | - if ( $discounts = $invoice->get_discounts() ) { |
|
351 | + if ($discounts = $invoice->get_discounts()) { |
|
352 | 352 | $set_discount = $discounts; |
353 | 353 | } else { |
354 | 354 | $set_discount = ''; |
355 | 355 | } |
356 | 356 | |
357 | 357 | // Manage discount |
358 | - if ( !empty( $invoice_data['user_info']['discount'] ) ) { |
|
358 | + if (!empty($invoice_data['user_info']['discount'])) { |
|
359 | 359 | // Remove discount |
360 | - if ( $invoice_data['user_info']['discount'] == 'none' ) { |
|
360 | + if ($invoice_data['user_info']['discount'] == 'none') { |
|
361 | 361 | $set_discount = ''; |
362 | 362 | } else { |
363 | 363 | $set_discount = $invoice_data['user_info']['discount']; |
364 | 364 | } |
365 | 365 | |
366 | - $invoice->set( 'discounts', $set_discount ); |
|
366 | + $invoice->set('discounts', $set_discount); |
|
367 | 367 | } |
368 | 368 | |
369 | 369 | $user_info['discount'] = $set_discount; |
370 | 370 | |
371 | - $invoice->set( 'user_info', $user_info ); |
|
371 | + $invoice->set('user_info', $user_info); |
|
372 | 372 | } |
373 | 373 | |
374 | - if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) { |
|
375 | - $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array(); |
|
374 | + if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) { |
|
375 | + $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array(); |
|
376 | 376 | |
377 | - if ( !empty( $remove_items[0]['id'] ) ) { |
|
378 | - foreach ( $remove_items as $item ) { |
|
379 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
380 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
381 | - if ( empty( $item_id ) ) { |
|
377 | + if (!empty($remove_items[0]['id'])) { |
|
378 | + foreach ($remove_items as $item) { |
|
379 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
380 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
381 | + if (empty($item_id)) { |
|
382 | 382 | continue; |
383 | 383 | } |
384 | 384 | |
385 | - foreach ( $invoice->cart_details as $cart_index => $cart_item ) { |
|
386 | - if ( $item_id == $cart_item['id'] ) { |
|
385 | + foreach ($invoice->cart_details as $cart_index => $cart_item) { |
|
386 | + if ($item_id == $cart_item['id']) { |
|
387 | 387 | $args = array( |
388 | 388 | 'id' => $item_id, |
389 | 389 | 'quantity' => $quantity, |
390 | 390 | 'cart_index' => $cart_index |
391 | 391 | ); |
392 | 392 | |
393 | - $invoice->remove_item( $item_id, $args ); |
|
393 | + $invoice->remove_item($item_id, $args); |
|
394 | 394 | break; |
395 | 395 | } |
396 | 396 | } |
397 | 397 | } |
398 | 398 | } |
399 | 399 | |
400 | - $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array(); |
|
400 | + $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array(); |
|
401 | 401 | |
402 | - if ( !empty( $add_items[0]['id'] ) ) { |
|
403 | - foreach ( $add_items as $item ) { |
|
404 | - $item_id = !empty( $item['id'] ) ? $item['id'] : 0; |
|
405 | - $post_item = new WPInv_Item( $item_id ); |
|
406 | - if ( empty( $post_item ) ) { |
|
402 | + if (!empty($add_items[0]['id'])) { |
|
403 | + foreach ($add_items as $item) { |
|
404 | + $item_id = !empty($item['id']) ? $item['id'] : 0; |
|
405 | + $post_item = new WPInv_Item($item_id); |
|
406 | + if (empty($post_item)) { |
|
407 | 407 | continue; |
408 | 408 | } |
409 | 409 | |
410 | 410 | $valid_item = true; |
411 | - if ( !empty( $recurring_item ) ) { |
|
412 | - if ( $recurring_item->ID != $item_id ) { |
|
411 | + if (!empty($recurring_item)) { |
|
412 | + if ($recurring_item->ID != $item_id) { |
|
413 | 413 | $valid_item = false; |
414 | 414 | } |
415 | - } else if ( wpinv_is_recurring_item( $item_id ) ) { |
|
415 | + } else if (wpinv_is_recurring_item($item_id)) { |
|
416 | 416 | $valid_item = false; |
417 | 417 | } |
418 | 418 | |
419 | - if ( !$valid_item ) { |
|
420 | - if ( $wp_error ) { |
|
421 | - return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) ); |
|
419 | + if (!$valid_item) { |
|
420 | + if ($wp_error) { |
|
421 | + return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing')); |
|
422 | 422 | } |
423 | 423 | return 0; |
424 | 424 | } |
425 | 425 | |
426 | - $quantity = !empty( $item['quantity'] ) ? $item['quantity'] : 1; |
|
427 | - $name = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name(); |
|
428 | - $item_price = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price(); |
|
426 | + $quantity = !empty($item['quantity']) ? $item['quantity'] : 1; |
|
427 | + $name = !empty($item['name']) ? $item['name'] : $post_item->get_name(); |
|
428 | + $item_price = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price(); |
|
429 | 429 | |
430 | 430 | $args = array( |
431 | 431 | 'name' => $name, |
432 | 432 | 'quantity' => $quantity, |
433 | 433 | 'item_price' => $item_price, |
434 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
435 | - 'tax' => !empty( $item['tax'] ) ? $item['tax'] : 0, |
|
436 | - 'discount' => isset( $item['discount'] ) ? $item['discount'] : 0, |
|
437 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
438 | - 'fees' => isset( $item['fees'] ) ? $item['fees'] : array(), |
|
434 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
435 | + 'tax' => !empty($item['tax']) ? $item['tax'] : 0, |
|
436 | + 'discount' => isset($item['discount']) ? $item['discount'] : 0, |
|
437 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
438 | + 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
|
439 | 439 | ); |
440 | 440 | |
441 | - $invoice->add_item( $item_id, $args ); |
|
441 | + $invoice->add_item($item_id, $args); |
|
442 | 442 | } |
443 | 443 | } |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Payment details |
447 | - if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) { |
|
448 | - if ( !empty( $payment_details['gateway'] ) ) { |
|
449 | - $invoice->set( 'gateway', $payment_details['gateway'] ); |
|
447 | + if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) { |
|
448 | + if (!empty($payment_details['gateway'])) { |
|
449 | + $invoice->set('gateway', $payment_details['gateway']); |
|
450 | 450 | } |
451 | 451 | |
452 | - if ( !empty( $payment_details['transaction_id'] ) ) { |
|
453 | - $invoice->set( 'transaction_id', $payment_details['transaction_id'] ); |
|
452 | + if (!empty($payment_details['transaction_id'])) { |
|
453 | + $invoice->set('transaction_id', $payment_details['transaction_id']); |
|
454 | 454 | } |
455 | 455 | } |
456 | 456 | |
457 | - do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data ); |
|
457 | + do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data); |
|
458 | 458 | |
459 | 459 | // Parent invoice |
460 | - if ( !empty( $invoice_data['parent'] ) ) { |
|
461 | - $invoice->set( 'parent_invoice', $invoice_data['parent'] ); |
|
460 | + if (!empty($invoice_data['parent'])) { |
|
461 | + $invoice->set('parent_invoice', $invoice_data['parent']); |
|
462 | 462 | } |
463 | 463 | |
464 | 464 | // Save invoice data. |
465 | 465 | $invoice->save(); |
466 | 466 | |
467 | - if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) { |
|
468 | - if ( $wp_error ) { |
|
469 | - if ( is_wp_error( $invoice ) ) { |
|
467 | + if (empty($invoice->ID) || is_wp_error($invoice)) { |
|
468 | + if ($wp_error) { |
|
469 | + if (is_wp_error($invoice)) { |
|
470 | 470 | return $invoice; |
471 | 471 | } else { |
472 | - return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) ); |
|
472 | + return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing')); |
|
473 | 473 | } |
474 | 474 | } else { |
475 | 475 | return 0; |
@@ -477,19 +477,19 @@ discard block |
||
477 | 477 | } |
478 | 478 | |
479 | 479 | // Add private note |
480 | - if ( !empty( $invoice_data['private_note'] ) ) { |
|
481 | - $invoice->add_note( $invoice_data['private_note'] ); |
|
480 | + if (!empty($invoice_data['private_note'])) { |
|
481 | + $invoice->add_note($invoice_data['private_note']); |
|
482 | 482 | } |
483 | 483 | |
484 | 484 | // Add user note |
485 | - if ( !empty( $invoice_data['user_note'] ) ) { |
|
486 | - $invoice->add_note( $invoice_data['user_note'], true ); |
|
485 | + if (!empty($invoice_data['user_note'])) { |
|
486 | + $invoice->add_note($invoice_data['user_note'], true); |
|
487 | 487 | } |
488 | 488 | |
489 | - if ( $invoice->is_quote() ) { |
|
489 | + if ($invoice->is_quote()) { |
|
490 | 490 | |
491 | - if ( isset( $invoice_data['valid_until'] ) ) { |
|
492 | - update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] ); |
|
491 | + if (isset($invoice_data['valid_until'])) { |
|
492 | + update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']); |
|
493 | 493 | } |
494 | 494 | return $invoice; |
495 | 495 | |
@@ -501,466 +501,466 @@ discard block |
||
501 | 501 | |
502 | 502 | $data_session = array(); |
503 | 503 | $data_session['invoice_id'] = $invoice->ID; |
504 | - $data_session['cart_discounts'] = $invoice->get_discounts( true ); |
|
504 | + $data_session['cart_discounts'] = $invoice->get_discounts(true); |
|
505 | 505 | |
506 | - wpinv_set_checkout_session( $data_session ); |
|
506 | + wpinv_set_checkout_session($data_session); |
|
507 | 507 | |
508 | - $wpi_userID = (int)$invoice->get_user_id(); |
|
508 | + $wpi_userID = (int) $invoice->get_user_id(); |
|
509 | 509 | |
510 | - $_POST['country'] = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country(); |
|
510 | + $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country(); |
|
511 | 511 | $_POST['state'] = $invoice->state; |
512 | 512 | |
513 | - $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) ); |
|
514 | - $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) ); |
|
513 | + $invoice->set('country', sanitize_text_field($_POST['country'])); |
|
514 | + $invoice->set('state', sanitize_text_field($_POST['state'])); |
|
515 | 515 | |
516 | 516 | $wpinv_ip_address_country = $invoice->country; |
517 | 517 | |
518 | - $invoice = $invoice->recalculate_totals( true ); |
|
518 | + $invoice = $invoice->recalculate_totals(true); |
|
519 | 519 | |
520 | - do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data ); |
|
520 | + do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data); |
|
521 | 521 | |
522 | - wpinv_set_checkout_session( $checkout_session ); |
|
522 | + wpinv_set_checkout_session($checkout_session); |
|
523 | 523 | |
524 | 524 | return $invoice; |
525 | 525 | } |
526 | 526 | |
527 | -function wpinv_get_invoice( $invoice_id = 0, $cart = false ) { |
|
528 | - if ( $cart && empty( $invoice_id ) ) { |
|
529 | - $invoice_id = (int)wpinv_get_invoice_cart_id(); |
|
527 | +function wpinv_get_invoice($invoice_id = 0, $cart = false) { |
|
528 | + if ($cart && empty($invoice_id)) { |
|
529 | + $invoice_id = (int) wpinv_get_invoice_cart_id(); |
|
530 | 530 | } |
531 | 531 | |
532 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
532 | + $invoice = new WPInv_Invoice($invoice_id); |
|
533 | 533 | |
534 | - if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) { |
|
534 | + if (!empty($invoice) && !empty($invoice->ID)) { |
|
535 | 535 | return $invoice; |
536 | 536 | } |
537 | 537 | |
538 | 538 | return NULL; |
539 | 539 | } |
540 | 540 | |
541 | -function wpinv_get_invoice_cart( $invoice_id = 0 ) { |
|
542 | - return wpinv_get_invoice( $invoice_id, true ); |
|
541 | +function wpinv_get_invoice_cart($invoice_id = 0) { |
|
542 | + return wpinv_get_invoice($invoice_id, true); |
|
543 | 543 | } |
544 | 544 | |
545 | -function wpinv_get_invoice_description( $invoice_id = 0 ) { |
|
546 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
545 | +function wpinv_get_invoice_description($invoice_id = 0) { |
|
546 | + $invoice = new WPInv_Invoice($invoice_id); |
|
547 | 547 | return $invoice->get_description(); |
548 | 548 | } |
549 | 549 | |
550 | -function wpinv_get_invoice_currency_code( $invoice_id = 0 ) { |
|
551 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
550 | +function wpinv_get_invoice_currency_code($invoice_id = 0) { |
|
551 | + $invoice = new WPInv_Invoice($invoice_id); |
|
552 | 552 | return $invoice->get_currency(); |
553 | 553 | } |
554 | 554 | |
555 | -function wpinv_get_payment_user_email( $invoice_id ) { |
|
556 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
555 | +function wpinv_get_payment_user_email($invoice_id) { |
|
556 | + $invoice = new WPInv_Invoice($invoice_id); |
|
557 | 557 | return $invoice->get_email(); |
558 | 558 | } |
559 | 559 | |
560 | -function wpinv_get_user_id( $invoice_id ) { |
|
561 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
560 | +function wpinv_get_user_id($invoice_id) { |
|
561 | + $invoice = new WPInv_Invoice($invoice_id); |
|
562 | 562 | return $invoice->get_user_id(); |
563 | 563 | } |
564 | 564 | |
565 | -function wpinv_get_invoice_status( $invoice_id, $return_label = false ) { |
|
566 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
565 | +function wpinv_get_invoice_status($invoice_id, $return_label = false) { |
|
566 | + $invoice = new WPInv_Invoice($invoice_id); |
|
567 | 567 | |
568 | - return $invoice->get_status( $return_label ); |
|
568 | + return $invoice->get_status($return_label); |
|
569 | 569 | } |
570 | 570 | |
571 | -function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) { |
|
572 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
571 | +function wpinv_get_payment_gateway($invoice_id, $return_label = false) { |
|
572 | + $invoice = new WPInv_Invoice($invoice_id); |
|
573 | 573 | |
574 | - return $invoice->get_gateway( $return_label ); |
|
574 | + return $invoice->get_gateway($return_label); |
|
575 | 575 | } |
576 | 576 | |
577 | -function wpinv_get_payment_gateway_name( $invoice_id ) { |
|
578 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
577 | +function wpinv_get_payment_gateway_name($invoice_id) { |
|
578 | + $invoice = new WPInv_Invoice($invoice_id); |
|
579 | 579 | |
580 | 580 | return $invoice->get_gateway_title(); |
581 | 581 | } |
582 | 582 | |
583 | -function wpinv_get_payment_transaction_id( $invoice_id ) { |
|
584 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
583 | +function wpinv_get_payment_transaction_id($invoice_id) { |
|
584 | + $invoice = new WPInv_Invoice($invoice_id); |
|
585 | 585 | |
586 | 586 | return $invoice->get_transaction_id(); |
587 | 587 | } |
588 | 588 | |
589 | -function wpinv_get_id_by_transaction_id( $key ) { |
|
589 | +function wpinv_get_id_by_transaction_id($key) { |
|
590 | 590 | global $wpdb; |
591 | 591 | |
592 | - $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) ); |
|
592 | + $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key)); |
|
593 | 593 | |
594 | - if ( $invoice_id != NULL ) |
|
594 | + if ($invoice_id != NULL) |
|
595 | 595 | return $invoice_id; |
596 | 596 | |
597 | 597 | return 0; |
598 | 598 | } |
599 | 599 | |
600 | -function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
601 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
600 | +function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) { |
|
601 | + $invoice = new WPInv_Invoice($invoice_id); |
|
602 | 602 | |
603 | - return $invoice->get_meta( $meta_key, $single ); |
|
603 | + return $invoice->get_meta($meta_key, $single); |
|
604 | 604 | } |
605 | 605 | |
606 | -function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
607 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
606 | +function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') { |
|
607 | + $invoice = new WPInv_Invoice($invoice_id); |
|
608 | 608 | |
609 | - return $invoice->update_meta( $meta_key, $meta_value, $prev_value ); |
|
609 | + return $invoice->update_meta($meta_key, $meta_value, $prev_value); |
|
610 | 610 | } |
611 | 611 | |
612 | -function wpinv_get_items( $invoice_id = 0 ) { |
|
613 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
612 | +function wpinv_get_items($invoice_id = 0) { |
|
613 | + $invoice = wpinv_get_invoice($invoice_id); |
|
614 | 614 | |
615 | 615 | $items = $invoice->get_items(); |
616 | 616 | $invoice_currency = $invoice->get_currency(); |
617 | 617 | |
618 | - if ( !empty( $items ) && is_array( $items ) ) { |
|
619 | - foreach ( $items as $key => $item ) { |
|
618 | + if (!empty($items) && is_array($items)) { |
|
619 | + foreach ($items as $key => $item) { |
|
620 | 620 | $items[$key]['currency'] = $invoice_currency; |
621 | 621 | |
622 | - if ( !isset( $item['subtotal'] ) ) { |
|
622 | + if (!isset($item['subtotal'])) { |
|
623 | 623 | $items[$key]['subtotal'] = $items[$key]['amount'] * 1; |
624 | 624 | } |
625 | 625 | } |
626 | 626 | } |
627 | 627 | |
628 | - return apply_filters( 'wpinv_get_items', $items, $invoice_id ); |
|
628 | + return apply_filters('wpinv_get_items', $items, $invoice_id); |
|
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_get_fees( $invoice_id = 0 ) { |
|
632 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
631 | +function wpinv_get_fees($invoice_id = 0) { |
|
632 | + $invoice = wpinv_get_invoice($invoice_id); |
|
633 | 633 | $fees = $invoice->get_fees(); |
634 | 634 | |
635 | - return apply_filters( 'wpinv_get_fees', $fees, $invoice_id ); |
|
635 | + return apply_filters('wpinv_get_fees', $fees, $invoice_id); |
|
636 | 636 | } |
637 | 637 | |
638 | -function wpinv_get_invoice_ip( $invoice_id ) { |
|
639 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
638 | +function wpinv_get_invoice_ip($invoice_id) { |
|
639 | + $invoice = new WPInv_Invoice($invoice_id); |
|
640 | 640 | return $invoice->get_ip(); |
641 | 641 | } |
642 | 642 | |
643 | -function wpinv_get_invoice_user_info( $invoice_id ) { |
|
644 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
643 | +function wpinv_get_invoice_user_info($invoice_id) { |
|
644 | + $invoice = new WPInv_Invoice($invoice_id); |
|
645 | 645 | return $invoice->get_user_info(); |
646 | 646 | } |
647 | 647 | |
648 | -function wpinv_subtotal( $invoice_id = 0, $currency = false ) { |
|
649 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
648 | +function wpinv_subtotal($invoice_id = 0, $currency = false) { |
|
649 | + $invoice = new WPInv_Invoice($invoice_id); |
|
650 | 650 | |
651 | - return $invoice->get_subtotal( $currency ); |
|
651 | + return $invoice->get_subtotal($currency); |
|
652 | 652 | } |
653 | 653 | |
654 | -function wpinv_tax( $invoice_id = 0, $currency = false ) { |
|
655 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
654 | +function wpinv_tax($invoice_id = 0, $currency = false) { |
|
655 | + $invoice = new WPInv_Invoice($invoice_id); |
|
656 | 656 | |
657 | - return $invoice->get_tax( $currency ); |
|
657 | + return $invoice->get_tax($currency); |
|
658 | 658 | } |
659 | 659 | |
660 | -function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) { |
|
661 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
660 | +function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) { |
|
661 | + $invoice = wpinv_get_invoice($invoice_id); |
|
662 | 662 | |
663 | - return $invoice->get_discount( $currency, $dash ); |
|
663 | + return $invoice->get_discount($currency, $dash); |
|
664 | 664 | } |
665 | 665 | |
666 | -function wpinv_discount_code( $invoice_id = 0 ) { |
|
667 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
666 | +function wpinv_discount_code($invoice_id = 0) { |
|
667 | + $invoice = new WPInv_Invoice($invoice_id); |
|
668 | 668 | |
669 | 669 | return $invoice->get_discount_code(); |
670 | 670 | } |
671 | 671 | |
672 | -function wpinv_payment_total( $invoice_id = 0, $currency = false ) { |
|
673 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
672 | +function wpinv_payment_total($invoice_id = 0, $currency = false) { |
|
673 | + $invoice = new WPInv_Invoice($invoice_id); |
|
674 | 674 | |
675 | - return $invoice->get_total( $currency ); |
|
675 | + return $invoice->get_total($currency); |
|
676 | 676 | } |
677 | 677 | |
678 | -function wpinv_get_date_created( $invoice_id = 0, $format = '' ) { |
|
679 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
678 | +function wpinv_get_date_created($invoice_id = 0, $format = '') { |
|
679 | + $invoice = new WPInv_Invoice($invoice_id); |
|
680 | 680 | |
681 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
681 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
682 | 682 | $date_created = $invoice->get_created_date(); |
683 | - $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : ''; |
|
683 | + $date_created = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : ''; |
|
684 | 684 | |
685 | 685 | return $date_created; |
686 | 686 | } |
687 | 687 | |
688 | -function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) { |
|
689 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
688 | +function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) { |
|
689 | + $invoice = new WPInv_Invoice($invoice_id); |
|
690 | 690 | |
691 | - $format = !empty( $format ) ? $format : get_option( 'date_format' ); |
|
691 | + $format = !empty($format) ? $format : get_option('date_format'); |
|
692 | 692 | $date_completed = $invoice->get_completed_date(); |
693 | - $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : ''; |
|
694 | - if ( $invoice_date == '' && $default ) { |
|
695 | - $invoice_date = wpinv_get_date_created( $invoice_id, $format ); |
|
693 | + $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : ''; |
|
694 | + if ($invoice_date == '' && $default) { |
|
695 | + $invoice_date = wpinv_get_date_created($invoice_id, $format); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | return $invoice_date; |
699 | 699 | } |
700 | 700 | |
701 | -function wpinv_get_invoice_vat_number( $invoice_id = 0 ) { |
|
702 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
701 | +function wpinv_get_invoice_vat_number($invoice_id = 0) { |
|
702 | + $invoice = new WPInv_Invoice($invoice_id); |
|
703 | 703 | |
704 | 704 | return $invoice->vat_number; |
705 | 705 | } |
706 | 706 | |
707 | -function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) { |
|
708 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
707 | +function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) { |
|
708 | + $invoice = new WPInv_Invoice($invoice_id); |
|
709 | 709 | |
710 | - return $invoice->add_note( $note, $user_type, $added_by_user, $system ); |
|
710 | + return $invoice->add_note($note, $user_type, $added_by_user, $system); |
|
711 | 711 | } |
712 | 712 | |
713 | -function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) { |
|
713 | +function wpinv_get_invoice_notes($invoice_id = 0, $type = '') { |
|
714 | 714 | global $invoicing; |
715 | 715 | |
716 | - if ( empty( $invoice_id ) ) { |
|
716 | + if (empty($invoice_id)) { |
|
717 | 717 | return NULL; |
718 | 718 | } |
719 | 719 | |
720 | - $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type ); |
|
720 | + $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type); |
|
721 | 721 | |
722 | - return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type ); |
|
722 | + return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type); |
|
723 | 723 | } |
724 | 724 | |
725 | -function wpinv_get_payment_key( $invoice_id = 0 ) { |
|
726 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
725 | +function wpinv_get_payment_key($invoice_id = 0) { |
|
726 | + $invoice = new WPInv_Invoice($invoice_id); |
|
727 | 727 | return $invoice->get_key(); |
728 | 728 | } |
729 | 729 | |
730 | -function wpinv_get_invoice_number( $invoice_id = 0 ) { |
|
731 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
730 | +function wpinv_get_invoice_number($invoice_id = 0) { |
|
731 | + $invoice = new WPInv_Invoice($invoice_id); |
|
732 | 732 | return $invoice->get_number(); |
733 | 733 | } |
734 | 734 | |
735 | -function wpinv_get_cart_discountable_subtotal( $code_id ) { |
|
735 | +function wpinv_get_cart_discountable_subtotal($code_id) { |
|
736 | 736 | $cart_items = wpinv_get_cart_content_details(); |
737 | 737 | $items = array(); |
738 | 738 | |
739 | - $excluded_items = wpinv_get_discount_excluded_items( $code_id ); |
|
739 | + $excluded_items = wpinv_get_discount_excluded_items($code_id); |
|
740 | 740 | |
741 | - if( $cart_items ) { |
|
741 | + if ($cart_items) { |
|
742 | 742 | |
743 | - foreach( $cart_items as $item ) { |
|
743 | + foreach ($cart_items as $item) { |
|
744 | 744 | |
745 | - if( ! in_array( $item['id'], $excluded_items ) ) { |
|
746 | - $items[] = $item; |
|
745 | + if (!in_array($item['id'], $excluded_items)) { |
|
746 | + $items[] = $item; |
|
747 | 747 | } |
748 | 748 | } |
749 | 749 | } |
750 | 750 | |
751 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
751 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
752 | 752 | |
753 | - return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal ); |
|
753 | + return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal); |
|
754 | 754 | } |
755 | 755 | |
756 | -function wpinv_get_cart_items_subtotal( $items ) { |
|
756 | +function wpinv_get_cart_items_subtotal($items) { |
|
757 | 757 | $subtotal = 0.00; |
758 | 758 | |
759 | - if ( is_array( $items ) && ! empty( $items ) ) { |
|
760 | - $prices = wp_list_pluck( $items, 'subtotal' ); |
|
759 | + if (is_array($items) && !empty($items)) { |
|
760 | + $prices = wp_list_pluck($items, 'subtotal'); |
|
761 | 761 | |
762 | - if( is_array( $prices ) ) { |
|
763 | - $subtotal = array_sum( $prices ); |
|
762 | + if (is_array($prices)) { |
|
763 | + $subtotal = array_sum($prices); |
|
764 | 764 | } else { |
765 | 765 | $subtotal = 0.00; |
766 | 766 | } |
767 | 767 | |
768 | - if( $subtotal < 0 ) { |
|
768 | + if ($subtotal < 0) { |
|
769 | 769 | $subtotal = 0.00; |
770 | 770 | } |
771 | 771 | } |
772 | 772 | |
773 | - return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal ); |
|
773 | + return apply_filters('wpinv_get_cart_items_subtotal', $subtotal); |
|
774 | 774 | } |
775 | 775 | |
776 | -function wpinv_get_cart_subtotal( $items = array() ) { |
|
777 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
778 | - $subtotal = wpinv_get_cart_items_subtotal( $items ); |
|
776 | +function wpinv_get_cart_subtotal($items = array()) { |
|
777 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
778 | + $subtotal = wpinv_get_cart_items_subtotal($items); |
|
779 | 779 | |
780 | - return apply_filters( 'wpinv_get_cart_subtotal', $subtotal ); |
|
780 | + return apply_filters('wpinv_get_cart_subtotal', $subtotal); |
|
781 | 781 | } |
782 | 782 | |
783 | -function wpinv_cart_subtotal( $items = array(), $currency = '' ) { |
|
783 | +function wpinv_cart_subtotal($items = array(), $currency = '') { |
|
784 | 784 | |
785 | - if( empty( $currency ) ) { |
|
785 | + if (empty($currency)) { |
|
786 | 786 | $currency = wpinv_get_currency(); |
787 | 787 | } |
788 | 788 | |
789 | - $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency ); |
|
789 | + $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency); |
|
790 | 790 | |
791 | 791 | return $price; |
792 | 792 | } |
793 | 793 | |
794 | -function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) { |
|
795 | - $subtotal = (float)wpinv_get_cart_subtotal( $items ); |
|
796 | - $discounts = (float)wpinv_get_cart_discounted_amount( $items ); |
|
797 | - $cart_tax = (float)wpinv_get_cart_tax( $items, $invoice ); |
|
798 | - $fees = (float)wpinv_get_cart_fee_total(); |
|
799 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
794 | +function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) { |
|
795 | + $subtotal = (float) wpinv_get_cart_subtotal($items); |
|
796 | + $discounts = (float) wpinv_get_cart_discounted_amount($items); |
|
797 | + $cart_tax = (float) wpinv_get_cart_tax($items, $invoice); |
|
798 | + $fees = (float) wpinv_get_cart_fee_total(); |
|
799 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
800 | 800 | $total = 0; |
801 | 801 | } else { |
802 | - $total = $subtotal - $discounts + $cart_tax + $fees; |
|
802 | + $total = $subtotal - $discounts + $cart_tax + $fees; |
|
803 | 803 | } |
804 | 804 | |
805 | - if ( $total < 0 ) { |
|
805 | + if ($total < 0) { |
|
806 | 806 | $total = 0.00; |
807 | 807 | } |
808 | 808 | |
809 | - $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items ); |
|
809 | + $total = (float) apply_filters('wpinv_get_cart_total', $total, $items); |
|
810 | 810 | |
811 | - return wpinv_sanitize_amount( $total ); |
|
811 | + return wpinv_sanitize_amount($total); |
|
812 | 812 | } |
813 | 813 | |
814 | -function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) { |
|
814 | +function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) { |
|
815 | 815 | global $cart_total; |
816 | - $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() ); |
|
817 | - $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice ); |
|
816 | + $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency()); |
|
817 | + $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice); |
|
818 | 818 | |
819 | 819 | $cart_total = $total; |
820 | 820 | |
821 | - if ( !$echo ) { |
|
821 | + if (!$echo) { |
|
822 | 822 | return $total; |
823 | 823 | } |
824 | 824 | |
825 | 825 | echo $total; |
826 | 826 | } |
827 | 827 | |
828 | -function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) { |
|
828 | +function wpinv_get_cart_tax($items = array(), $invoice = 0) { |
|
829 | 829 | |
830 | - if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) { |
|
830 | + if (!empty($invoice) && !$invoice->is_taxable()) { |
|
831 | 831 | return 0; |
832 | 832 | } |
833 | 833 | |
834 | 834 | $cart_tax = 0; |
835 | - $items = !empty( $items ) ? $items : wpinv_get_cart_content_details(); |
|
835 | + $items = !empty($items) ? $items : wpinv_get_cart_content_details(); |
|
836 | 836 | |
837 | - if ( $items ) { |
|
838 | - $taxes = wp_list_pluck( $items, 'tax' ); |
|
837 | + if ($items) { |
|
838 | + $taxes = wp_list_pluck($items, 'tax'); |
|
839 | 839 | |
840 | - if( is_array( $taxes ) ) { |
|
841 | - $cart_tax = array_sum( $taxes ); |
|
840 | + if (is_array($taxes)) { |
|
841 | + $cart_tax = array_sum($taxes); |
|
842 | 842 | } |
843 | 843 | } |
844 | 844 | |
845 | 845 | $cart_tax += wpinv_get_cart_fee_tax(); |
846 | 846 | |
847 | - return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) ); |
|
847 | + return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax)); |
|
848 | 848 | } |
849 | 849 | |
850 | -function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) { |
|
850 | +function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) { |
|
851 | 851 | |
852 | - if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) { |
|
853 | - echo wpinv_price( wpinv_format_amount( 0 ), $currency ); |
|
852 | + if (!empty($invoice && !$invoice->is_taxable())) { |
|
853 | + echo wpinv_price(wpinv_format_amount(0), $currency); |
|
854 | 854 | return; |
855 | 855 | } |
856 | 856 | |
857 | - $cart_tax = wpinv_get_cart_tax( $items, $invoice ); |
|
858 | - $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency ); |
|
857 | + $cart_tax = wpinv_get_cart_tax($items, $invoice); |
|
858 | + $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency); |
|
859 | 859 | |
860 | - $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items ); |
|
860 | + $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items); |
|
861 | 861 | |
862 | - if ( !$echo ) { |
|
862 | + if (!$echo) { |
|
863 | 863 | return $tax; |
864 | 864 | } |
865 | 865 | |
866 | 866 | echo $tax; |
867 | 867 | } |
868 | 868 | |
869 | -function wpinv_get_cart_discount_code( $items = array() ) { |
|
869 | +function wpinv_get_cart_discount_code($items = array()) { |
|
870 | 870 | $invoice = wpinv_get_invoice_cart(); |
871 | - $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : ''; |
|
871 | + $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : ''; |
|
872 | 872 | |
873 | - return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code ); |
|
873 | + return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code); |
|
874 | 874 | } |
875 | 875 | |
876 | -function wpinv_cart_discount_code( $items = array(), $echo = false ) { |
|
877 | - $cart_discount_code = wpinv_get_cart_discount_code( $items ); |
|
876 | +function wpinv_cart_discount_code($items = array(), $echo = false) { |
|
877 | + $cart_discount_code = wpinv_get_cart_discount_code($items); |
|
878 | 878 | |
879 | - if ( $cart_discount_code != '' ) { |
|
879 | + if ($cart_discount_code != '') { |
|
880 | 880 | $cart_discount_code = ' (' . $cart_discount_code . ')'; |
881 | 881 | } |
882 | 882 | |
883 | - $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items ); |
|
883 | + $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items); |
|
884 | 884 | |
885 | - if ( !$echo ) { |
|
885 | + if (!$echo) { |
|
886 | 886 | return $discount_code; |
887 | 887 | } |
888 | 888 | |
889 | 889 | echo $discount_code; |
890 | 890 | } |
891 | 891 | |
892 | -function wpinv_get_cart_discount( $items = array() ) { |
|
892 | +function wpinv_get_cart_discount($items = array()) { |
|
893 | 893 | $invoice = wpinv_get_invoice_cart(); |
894 | - $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0; |
|
894 | + $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0; |
|
895 | 895 | |
896 | - return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items ); |
|
896 | + return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items); |
|
897 | 897 | } |
898 | 898 | |
899 | -function wpinv_cart_discount( $items = array(), $echo = false ) { |
|
900 | - $cart_discount = wpinv_get_cart_discount( $items ); |
|
901 | - $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) ); |
|
899 | +function wpinv_cart_discount($items = array(), $echo = false) { |
|
900 | + $cart_discount = wpinv_get_cart_discount($items); |
|
901 | + $cart_discount = wpinv_price(wpinv_format_amount($cart_discount)); |
|
902 | 902 | |
903 | - $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items ); |
|
903 | + $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items); |
|
904 | 904 | |
905 | - if ( !$echo ) { |
|
905 | + if (!$echo) { |
|
906 | 906 | return $discount; |
907 | 907 | } |
908 | 908 | |
909 | 909 | echo $discount; |
910 | 910 | } |
911 | 911 | |
912 | -function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) { |
|
913 | - $item = new WPInv_Item( $item_id ); |
|
912 | +function wpinv_get_cart_fees($type = 'all', $item_id = 0) { |
|
913 | + $item = new WPInv_Item($item_id); |
|
914 | 914 | |
915 | - return $item->get_fees( $type, $item_id ); |
|
915 | + return $item->get_fees($type, $item_id); |
|
916 | 916 | } |
917 | 917 | |
918 | 918 | function wpinv_get_cart_fee_total() { |
919 | - $total = 0; |
|
919 | + $total = 0; |
|
920 | 920 | $fees = wpinv_get_cart_fees(); |
921 | 921 | |
922 | - if ( $fees ) { |
|
923 | - foreach ( $fees as $fee_id => $fee ) { |
|
922 | + if ($fees) { |
|
923 | + foreach ($fees as $fee_id => $fee) { |
|
924 | 924 | $total += $fee['amount']; |
925 | 925 | } |
926 | 926 | } |
927 | 927 | |
928 | - return apply_filters( 'wpinv_get_cart_fee_total', $total ); |
|
928 | + return apply_filters('wpinv_get_cart_fee_total', $total); |
|
929 | 929 | } |
930 | 930 | |
931 | 931 | function wpinv_get_cart_fee_tax() { |
932 | 932 | $tax = 0; |
933 | 933 | $fees = wpinv_get_cart_fees(); |
934 | 934 | |
935 | - if ( $fees ) { |
|
936 | - foreach ( $fees as $fee_id => $fee ) { |
|
937 | - if( ! empty( $fee['no_tax'] ) ) { |
|
935 | + if ($fees) { |
|
936 | + foreach ($fees as $fee_id => $fee) { |
|
937 | + if (!empty($fee['no_tax'])) { |
|
938 | 938 | continue; |
939 | 939 | } |
940 | 940 | |
941 | - $tax += wpinv_calculate_tax( $fee['amount'] ); |
|
941 | + $tax += wpinv_calculate_tax($fee['amount']); |
|
942 | 942 | } |
943 | 943 | } |
944 | 944 | |
945 | - return apply_filters( 'wpinv_get_cart_fee_tax', $tax ); |
|
945 | + return apply_filters('wpinv_get_cart_fee_tax', $tax); |
|
946 | 946 | } |
947 | 947 | |
948 | 948 | function wpinv_cart_has_recurring_item() { |
949 | 949 | $cart_items = wpinv_get_cart_contents(); |
950 | 950 | |
951 | - if ( empty( $cart_items ) ) { |
|
951 | + if (empty($cart_items)) { |
|
952 | 952 | return false; |
953 | 953 | } |
954 | 954 | |
955 | 955 | $has_subscription = false; |
956 | - foreach( $cart_items as $cart_item ) { |
|
957 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
956 | + foreach ($cart_items as $cart_item) { |
|
957 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
958 | 958 | $has_subscription = true; |
959 | 959 | break; |
960 | 960 | } |
961 | 961 | } |
962 | 962 | |
963 | - return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items ); |
|
963 | + return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items); |
|
964 | 964 | } |
965 | 965 | |
966 | 966 | function wpinv_cart_has_free_trial() { |
@@ -968,100 +968,100 @@ discard block |
||
968 | 968 | |
969 | 969 | $free_trial = false; |
970 | 970 | |
971 | - if ( !empty( $invoice ) && $invoice->is_free_trial() ) { |
|
971 | + if (!empty($invoice) && $invoice->is_free_trial()) { |
|
972 | 972 | $free_trial = true; |
973 | 973 | } |
974 | 974 | |
975 | - return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice ); |
|
975 | + return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice); |
|
976 | 976 | } |
977 | 977 | |
978 | 978 | function wpinv_get_cart_contents() { |
979 | 979 | $cart_details = wpinv_get_cart_details(); |
980 | 980 | |
981 | - return apply_filters( 'wpinv_get_cart_contents', $cart_details ); |
|
981 | + return apply_filters('wpinv_get_cart_contents', $cart_details); |
|
982 | 982 | } |
983 | 983 | |
984 | 984 | function wpinv_get_cart_content_details() { |
985 | 985 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total; |
986 | 986 | $cart_items = wpinv_get_cart_contents(); |
987 | 987 | |
988 | - if ( empty( $cart_items ) ) { |
|
988 | + if (empty($cart_items)) { |
|
989 | 989 | return false; |
990 | 990 | } |
991 | 991 | $invoice = wpinv_get_invoice_cart(); |
992 | - if ( empty( $invoice ) ) { |
|
992 | + if (empty($invoice)) { |
|
993 | 993 | return false; |
994 | 994 | } |
995 | 995 | |
996 | 996 | $details = array(); |
997 | - $length = count( $cart_items ) - 1; |
|
997 | + $length = count($cart_items) - 1; |
|
998 | 998 | |
999 | - if ( empty( $_POST['country'] ) ) { |
|
999 | + if (empty($_POST['country'])) { |
|
1000 | 1000 | $_POST['country'] = $invoice->country; |
1001 | 1001 | } |
1002 | - if ( !isset( $_POST['state'] ) ) { |
|
1002 | + if (!isset($_POST['state'])) { |
|
1003 | 1003 | $_POST['state'] = $invoice->state; |
1004 | 1004 | } |
1005 | 1005 | |
1006 | - foreach( $cart_items as $key => $item ) { |
|
1007 | - $item_id = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : ''; |
|
1008 | - if ( empty( $item_id ) ) { |
|
1006 | + foreach ($cart_items as $key => $item) { |
|
1007 | + $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : ''; |
|
1008 | + if (empty($item_id)) { |
|
1009 | 1009 | continue; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | 1012 | $wpi_current_id = $invoice->ID; |
1013 | 1013 | $wpi_item_id = $item_id; |
1014 | 1014 | |
1015 | - if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) { |
|
1015 | + if (isset($item['custom_price']) && $item['custom_price'] !== '') { |
|
1016 | 1016 | $item_price = $item['custom_price']; |
1017 | 1017 | } else { |
1018 | - if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) { |
|
1018 | + if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) { |
|
1019 | 1019 | $item_price = $item['item_price']; |
1020 | 1020 | } else { |
1021 | - $item_price = wpinv_get_item_price( $item_id ); |
|
1021 | + $item_price = wpinv_get_item_price($item_id); |
|
1022 | 1022 | } |
1023 | 1023 | } |
1024 | - $discount = wpinv_get_cart_item_discount_amount( $item ); |
|
1025 | - $discount = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item ); |
|
1026 | - $quantity = wpinv_get_cart_item_quantity( $item ); |
|
1027 | - $fees = wpinv_get_cart_fees( 'fee', $item_id ); |
|
1024 | + $discount = wpinv_get_cart_item_discount_amount($item); |
|
1025 | + $discount = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item); |
|
1026 | + $quantity = wpinv_get_cart_item_quantity($item); |
|
1027 | + $fees = wpinv_get_cart_fees('fee', $item_id); |
|
1028 | 1028 | |
1029 | 1029 | $subtotal = $item_price * $quantity; |
1030 | - $tax_rate = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id ); |
|
1031 | - $tax_class = $wpinv_euvat->get_item_class( $item_id ); |
|
1032 | - $tax = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount ); |
|
1030 | + $tax_rate = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id); |
|
1031 | + $tax_class = $wpinv_euvat->get_item_class($item_id); |
|
1032 | + $tax = wpinv_get_cart_item_tax($item_id, $subtotal - $discount); |
|
1033 | 1033 | |
1034 | - if ( ! $invoice->is_taxable() ) { |
|
1034 | + if (!$invoice->is_taxable()) { |
|
1035 | 1035 | $tax = 0; |
1036 | 1036 | } |
1037 | - if ( wpinv_prices_include_tax() ) { |
|
1038 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1037 | + if (wpinv_prices_include_tax()) { |
|
1038 | + $subtotal -= wpinv_round_amount($tax); |
|
1039 | 1039 | } |
1040 | 1040 | |
1041 | - $total = $subtotal - $discount + $tax; |
|
1041 | + $total = $subtotal - $discount + $tax; |
|
1042 | 1042 | |
1043 | 1043 | // Do not allow totals to go negatve |
1044 | - if( $total < 0 ) { |
|
1044 | + if ($total < 0) { |
|
1045 | 1045 | $total = 0; |
1046 | 1046 | } |
1047 | 1047 | |
1048 | - $details[ $key ] = array( |
|
1048 | + $details[$key] = array( |
|
1049 | 1049 | 'id' => $item_id, |
1050 | - 'name' => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ), |
|
1051 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1052 | - 'custom_price' => isset( $item['custom_price'] ) ? $item['custom_price'] : '', |
|
1050 | + 'name' => !empty($item['name']) ? $item['name'] : get_the_title($item_id), |
|
1051 | + 'item_price' => wpinv_round_amount($item_price), |
|
1052 | + 'custom_price' => isset($item['custom_price']) ? $item['custom_price'] : '', |
|
1053 | 1053 | 'quantity' => $quantity, |
1054 | - 'discount' => wpinv_round_amount( $discount ), |
|
1055 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1056 | - 'tax' => wpinv_round_amount( $tax ), |
|
1057 | - 'price' => wpinv_round_amount( $total ), |
|
1054 | + 'discount' => wpinv_round_amount($discount), |
|
1055 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1056 | + 'tax' => wpinv_round_amount($tax), |
|
1057 | + 'price' => wpinv_round_amount($total), |
|
1058 | 1058 | 'vat_rates_class' => $tax_class, |
1059 | 1059 | 'vat_rate' => $tax_rate, |
1060 | - 'meta' => isset( $item['meta'] ) ? $item['meta'] : array(), |
|
1060 | + 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
|
1061 | 1061 | 'fees' => $fees, |
1062 | 1062 | ); |
1063 | 1063 | |
1064 | - if ( $wpinv_is_last_cart_item ) { |
|
1064 | + if ($wpinv_is_last_cart_item) { |
|
1065 | 1065 | $wpinv_is_last_cart_item = false; |
1066 | 1066 | $wpinv_flat_discount_total = 0.00; |
1067 | 1067 | } |
@@ -1070,74 +1070,74 @@ discard block |
||
1070 | 1070 | return $details; |
1071 | 1071 | } |
1072 | 1072 | |
1073 | -function wpinv_get_cart_details( $invoice_id = 0 ) { |
|
1073 | +function wpinv_get_cart_details($invoice_id = 0) { |
|
1074 | 1074 | global $ajax_cart_details; |
1075 | 1075 | |
1076 | - $invoice = wpinv_get_invoice_cart( $invoice_id ); |
|
1076 | + $invoice = wpinv_get_invoice_cart($invoice_id); |
|
1077 | 1077 | $cart_details = $ajax_cart_details; |
1078 | - if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) { |
|
1078 | + if (empty($cart_details) && !empty($invoice->cart_details)) { |
|
1079 | 1079 | $cart_details = $invoice->cart_details; |
1080 | 1080 | } |
1081 | 1081 | |
1082 | - if ( ! empty( $cart_details ) && is_array( $cart_details ) ) { |
|
1083 | - $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country(); |
|
1082 | + if (!empty($cart_details) && is_array($cart_details)) { |
|
1083 | + $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country(); |
|
1084 | 1084 | |
1085 | - foreach ( $cart_details as $key => $cart_item ) { |
|
1086 | - $cart_details[ $key ]['currency'] = $invoice_currency; |
|
1085 | + foreach ($cart_details as $key => $cart_item) { |
|
1086 | + $cart_details[$key]['currency'] = $invoice_currency; |
|
1087 | 1087 | |
1088 | - if ( ! isset( $cart_item['subtotal'] ) ) { |
|
1089 | - $cart_details[ $key ]['subtotal'] = $cart_item['price']; |
|
1088 | + if (!isset($cart_item['subtotal'])) { |
|
1089 | + $cart_details[$key]['subtotal'] = $cart_item['price']; |
|
1090 | 1090 | } |
1091 | 1091 | } |
1092 | 1092 | } |
1093 | 1093 | |
1094 | - return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id ); |
|
1094 | + return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id); |
|
1095 | 1095 | } |
1096 | 1096 | |
1097 | -function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) { |
|
1098 | - if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) { |
|
1097 | +function wpinv_record_status_change($invoice_id, $new_status, $old_status) { |
|
1098 | + if ('wpi_invoice' != get_post_type($invoice_id)) { |
|
1099 | 1099 | return; |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) { |
|
1102 | + if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) { |
|
1103 | 1103 | return; |
1104 | 1104 | } |
1105 | 1105 | |
1106 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
1106 | + $invoice = wpinv_get_invoice($invoice_id); |
|
1107 | 1107 | |
1108 | - if ( wpinv_use_taxes() && $new_status == 'publish' ) { |
|
1108 | + if (wpinv_use_taxes() && $new_status == 'publish') { |
|
1109 | 1109 | |
1110 | - if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->country ) ) { |
|
1111 | - $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true ); |
|
1110 | + if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->country)) { |
|
1111 | + $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true); |
|
1112 | 1112 | } |
1113 | 1113 | } |
1114 | 1114 | |
1115 | - $old_status = wpinv_status_nicename( $old_status ); |
|
1116 | - $new_status = wpinv_status_nicename( $new_status ); |
|
1115 | + $old_status = wpinv_status_nicename($old_status); |
|
1116 | + $new_status = wpinv_status_nicename($new_status); |
|
1117 | 1117 | |
1118 | - $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status ); |
|
1118 | + $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status); |
|
1119 | 1119 | |
1120 | 1120 | // Add note |
1121 | - return $invoice->add_note( $status_change, false, false, true ); |
|
1121 | + return $invoice->add_note($status_change, false, false, true); |
|
1122 | 1122 | } |
1123 | -add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 ); |
|
1123 | +add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3); |
|
1124 | 1124 | |
1125 | -function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) { |
|
1125 | +function wpinv_complete_payment($invoice_id, $new_status, $old_status) { |
|
1126 | 1126 | global $wpi_has_free_trial; |
1127 | 1127 | |
1128 | 1128 | $wpi_has_free_trial = false; |
1129 | 1129 | |
1130 | - if ( $old_status == 'publish' ) { |
|
1130 | + if ($old_status == 'publish') { |
|
1131 | 1131 | return; // Make sure that payments are only paid once |
1132 | 1132 | } |
1133 | 1133 | |
1134 | 1134 | // Make sure the payment completion is only processed when new status is paid |
1135 | - if ( $new_status != 'publish' ) { |
|
1135 | + if ($new_status != 'publish') { |
|
1136 | 1136 | return; |
1137 | 1137 | } |
1138 | 1138 | |
1139 | - $invoice = new WPInv_Invoice( $invoice_id ); |
|
1140 | - if ( empty( $invoice ) ) { |
|
1139 | + $invoice = new WPInv_Invoice($invoice_id); |
|
1140 | + if (empty($invoice)) { |
|
1141 | 1141 | return; |
1142 | 1142 | } |
1143 | 1143 | |
@@ -1145,58 +1145,58 @@ discard block |
||
1145 | 1145 | $completed_date = $invoice->completed_date; |
1146 | 1146 | $cart_details = $invoice->cart_details; |
1147 | 1147 | |
1148 | - do_action( 'wpinv_pre_complete_payment', $invoice_id ); |
|
1148 | + do_action('wpinv_pre_complete_payment', $invoice_id); |
|
1149 | 1149 | |
1150 | - if ( is_array( $cart_details ) ) { |
|
1150 | + if (is_array($cart_details)) { |
|
1151 | 1151 | // Increase purchase count and earnings |
1152 | - foreach ( $cart_details as $cart_index => $item ) { |
|
1152 | + foreach ($cart_details as $cart_index => $item) { |
|
1153 | 1153 | // Ensure these actions only run once, ever |
1154 | - if ( empty( $completed_date ) ) { |
|
1155 | - do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index ); |
|
1154 | + if (empty($completed_date)) { |
|
1155 | + do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index); |
|
1156 | 1156 | } |
1157 | 1157 | } |
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | // Check for discount codes and increment their use counts |
1161 | - if ( $discounts = $invoice->get_discounts( true ) ) { |
|
1162 | - if( ! empty( $discounts ) ) { |
|
1163 | - foreach( $discounts as $code ) { |
|
1164 | - wpinv_increase_discount_usage( $code ); |
|
1161 | + if ($discounts = $invoice->get_discounts(true)) { |
|
1162 | + if (!empty($discounts)) { |
|
1163 | + foreach ($discounts as $code) { |
|
1164 | + wpinv_increase_discount_usage($code); |
|
1165 | 1165 | } |
1166 | 1166 | } |
1167 | 1167 | } |
1168 | 1168 | |
1169 | 1169 | // Ensure this action only runs once ever |
1170 | - if( empty( $completed_date ) ) { |
|
1170 | + if (empty($completed_date)) { |
|
1171 | 1171 | // Save the completed date |
1172 | - $invoice->set( 'completed_date', current_time( 'mysql', 0 ) ); |
|
1172 | + $invoice->set('completed_date', current_time('mysql', 0)); |
|
1173 | 1173 | $invoice->save(); |
1174 | 1174 | |
1175 | - do_action( 'wpinv_complete_payment', $invoice_id ); |
|
1175 | + do_action('wpinv_complete_payment', $invoice_id); |
|
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | // Empty the shopping cart |
1179 | 1179 | wpinv_empty_cart(); |
1180 | 1180 | } |
1181 | -add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 ); |
|
1181 | +add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3); |
|
1182 | 1182 | |
1183 | -function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) { |
|
1184 | - $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id ); |
|
1183 | +function wpinv_update_payment_status($invoice_id, $new_status = 'publish') { |
|
1184 | + $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id); |
|
1185 | 1185 | |
1186 | - if ( empty( $invoice ) ) { |
|
1186 | + if (empty($invoice)) { |
|
1187 | 1187 | return false; |
1188 | 1188 | } |
1189 | 1189 | |
1190 | - return $invoice->update_status( $new_status ); |
|
1190 | + return $invoice->update_status($new_status); |
|
1191 | 1191 | } |
1192 | 1192 | |
1193 | -function wpinv_cart_has_fees( $type = 'all' ) { |
|
1193 | +function wpinv_cart_has_fees($type = 'all') { |
|
1194 | 1194 | return false; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | 1197 | function wpinv_validate_checkout_fields() { |
1198 | 1198 | // Check if there is $_POST |
1199 | - if ( empty( $_POST ) ) { |
|
1199 | + if (empty($_POST)) { |
|
1200 | 1200 | return false; |
1201 | 1201 | } |
1202 | 1202 | |
@@ -1219,28 +1219,28 @@ discard block |
||
1219 | 1219 | |
1220 | 1220 | $invoice = wpinv_get_invoice_cart(); |
1221 | 1221 | $has_subscription = $invoice->is_recurring(); |
1222 | - if ( empty( $invoice ) ) { |
|
1223 | - wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) ); |
|
1222 | + if (empty($invoice)) { |
|
1223 | + wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing')); |
|
1224 | 1224 | return $gateway; |
1225 | 1225 | } |
1226 | 1226 | |
1227 | 1227 | // Check if a gateway value is present |
1228 | - if ( !empty( $_REQUEST['wpi-gateway'] ) ) { |
|
1229 | - $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] ); |
|
1228 | + if (!empty($_REQUEST['wpi-gateway'])) { |
|
1229 | + $gateway = sanitize_text_field($_REQUEST['wpi-gateway']); |
|
1230 | 1230 | |
1231 | - if ( $invoice->is_free() ) { |
|
1231 | + if ($invoice->is_free()) { |
|
1232 | 1232 | $gateway = 'manual'; |
1233 | - } elseif ( !wpinv_is_gateway_active( $gateway ) ) { |
|
1234 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) ); |
|
1235 | - } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) { |
|
1236 | - if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) { |
|
1237 | - wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) ); |
|
1233 | + } elseif (!wpinv_is_gateway_active($gateway)) { |
|
1234 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing')); |
|
1235 | + } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) { |
|
1236 | + if (apply_filters('wpinv_reject_non_recurring_gateway', true)) { |
|
1237 | + wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing')); |
|
1238 | 1238 | } |
1239 | 1239 | } |
1240 | 1240 | } |
1241 | 1241 | |
1242 | - if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) { |
|
1243 | - wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) ); |
|
1242 | + if ($has_subscription && count(wpinv_get_cart_contents()) > 1) { |
|
1243 | + wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing')); |
|
1244 | 1244 | } |
1245 | 1245 | |
1246 | 1246 | return $gateway; |
@@ -1252,41 +1252,41 @@ discard block |
||
1252 | 1252 | // Retrieve the discount stored in cookies |
1253 | 1253 | $discounts = wpinv_get_cart_discounts(); |
1254 | 1254 | |
1255 | - if ( ! is_array( $discounts ) ) { |
|
1255 | + if (!is_array($discounts)) { |
|
1256 | 1256 | return NULL; |
1257 | 1257 | } |
1258 | 1258 | |
1259 | - $discounts = array_filter( $discounts ); |
|
1260 | - $error = false; |
|
1259 | + $discounts = array_filter($discounts); |
|
1260 | + $error = false; |
|
1261 | 1261 | |
1262 | - if ( empty( $discounts ) ) { |
|
1262 | + if (empty($discounts)) { |
|
1263 | 1263 | return NULL; |
1264 | 1264 | } |
1265 | 1265 | |
1266 | 1266 | // If we have discounts, loop through them |
1267 | - foreach ( $discounts as $discount ) { |
|
1267 | + foreach ($discounts as $discount) { |
|
1268 | 1268 | // Check if valid |
1269 | - if ( ! wpinv_is_discount_valid( $discount, (int) $wpi_cart->get_user_id() ) ) { |
|
1269 | + if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) { |
|
1270 | 1270 | // Discount is not valid |
1271 | 1271 | $error = true; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | } |
1275 | 1275 | |
1276 | - if ( $error && ! wpinv_get_errors() ) { |
|
1277 | - wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) ); |
|
1276 | + if ($error && !wpinv_get_errors()) { |
|
1277 | + wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing')); |
|
1278 | 1278 | } |
1279 | 1279 | |
1280 | - return implode( ',', $discounts ); |
|
1280 | + return implode(',', $discounts); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | 1283 | function wpinv_checkout_validate_cc() { |
1284 | 1284 | $card_data = wpinv_checkout_get_cc_info(); |
1285 | 1285 | |
1286 | 1286 | // Validate the card zip |
1287 | - if ( !empty( $card_data['wpinv_zip'] ) ) { |
|
1288 | - if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) { |
|
1289 | - wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) ); |
|
1287 | + if (!empty($card_data['wpinv_zip'])) { |
|
1288 | + if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) { |
|
1289 | + wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing')); |
|
1290 | 1290 | } |
1291 | 1291 | } |
1292 | 1292 | |
@@ -1296,28 +1296,28 @@ discard block |
||
1296 | 1296 | |
1297 | 1297 | function wpinv_checkout_get_cc_info() { |
1298 | 1298 | $cc_info = array(); |
1299 | - $cc_info['card_name'] = isset( $_POST['card_name'] ) ? sanitize_text_field( $_POST['card_name'] ) : ''; |
|
1300 | - $cc_info['card_number'] = isset( $_POST['card_number'] ) ? sanitize_text_field( $_POST['card_number'] ) : ''; |
|
1301 | - $cc_info['card_cvc'] = isset( $_POST['card_cvc'] ) ? sanitize_text_field( $_POST['card_cvc'] ) : ''; |
|
1302 | - $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] ) ? sanitize_text_field( $_POST['card_exp_month'] ) : ''; |
|
1303 | - $cc_info['card_exp_year'] = isset( $_POST['card_exp_year'] ) ? sanitize_text_field( $_POST['card_exp_year'] ) : ''; |
|
1304 | - $cc_info['card_address'] = isset( $_POST['wpinv_address'] ) ? sanitize_text_field( $_POST['wpinv_address'] ) : ''; |
|
1305 | - $cc_info['card_city'] = isset( $_POST['wpinv_city'] ) ? sanitize_text_field( $_POST['wpinv_city'] ) : ''; |
|
1306 | - $cc_info['card_state'] = isset( $_POST['wpinv_state'] ) ? sanitize_text_field( $_POST['wpinv_state'] ) : ''; |
|
1307 | - $cc_info['card_country'] = isset( $_POST['wpinv_country'] ) ? sanitize_text_field( $_POST['wpinv_country'] ) : ''; |
|
1308 | - $cc_info['card_zip'] = isset( $_POST['wpinv_zip'] ) ? sanitize_text_field( $_POST['wpinv_zip'] ) : ''; |
|
1299 | + $cc_info['card_name'] = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : ''; |
|
1300 | + $cc_info['card_number'] = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : ''; |
|
1301 | + $cc_info['card_cvc'] = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : ''; |
|
1302 | + $cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : ''; |
|
1303 | + $cc_info['card_exp_year'] = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : ''; |
|
1304 | + $cc_info['card_address'] = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : ''; |
|
1305 | + $cc_info['card_city'] = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : ''; |
|
1306 | + $cc_info['card_state'] = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : ''; |
|
1307 | + $cc_info['card_country'] = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : ''; |
|
1308 | + $cc_info['card_zip'] = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : ''; |
|
1309 | 1309 | |
1310 | 1310 | // Return cc info |
1311 | 1311 | return $cc_info; |
1312 | 1312 | } |
1313 | 1313 | |
1314 | -function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) { |
|
1314 | +function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') { |
|
1315 | 1315 | $ret = false; |
1316 | 1316 | |
1317 | - if ( empty( $zip ) || empty( $country_code ) ) |
|
1317 | + if (empty($zip) || empty($country_code)) |
|
1318 | 1318 | return $ret; |
1319 | 1319 | |
1320 | - $country_code = strtoupper( $country_code ); |
|
1320 | + $country_code = strtoupper($country_code); |
|
1321 | 1321 | |
1322 | 1322 | $zip_regex = array( |
1323 | 1323 | "AD" => "AD\d{3}", |
@@ -1477,72 +1477,72 @@ discard block |
||
1477 | 1477 | "ZM" => "\d{5}" |
1478 | 1478 | ); |
1479 | 1479 | |
1480 | - if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) |
|
1480 | + if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip)) |
|
1481 | 1481 | $ret = true; |
1482 | 1482 | |
1483 | - return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code ); |
|
1483 | + return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | function wpinv_checkout_validate_agree_to_terms() { |
1487 | 1487 | // Validate agree to terms |
1488 | - if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) { |
|
1488 | + if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) { |
|
1489 | 1489 | // User did not agree |
1490 | - wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) ); |
|
1490 | + wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing'))); |
|
1491 | 1491 | } |
1492 | 1492 | } |
1493 | 1493 | |
1494 | 1494 | function wpinv_checkout_validate_invoice_user() { |
1495 | 1495 | global $wpi_cart, $user_ID; |
1496 | 1496 | |
1497 | - if(empty($wpi_cart)){ |
|
1497 | + if (empty($wpi_cart)) { |
|
1498 | 1498 | $wpi_cart = wpinv_get_invoice_cart(); |
1499 | 1499 | } |
1500 | 1500 | |
1501 | - $invoice_user = (int)$wpi_cart->get_user_id(); |
|
1501 | + $invoice_user = (int) $wpi_cart->get_user_id(); |
|
1502 | 1502 | $valid_user_data = array( |
1503 | 1503 | 'user_id' => $invoice_user |
1504 | 1504 | ); |
1505 | 1505 | |
1506 | 1506 | // If guest checkout allowed |
1507 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1507 | + if (!wpinv_require_login_to_checkout()) { |
|
1508 | 1508 | return $valid_user_data; |
1509 | 1509 | } |
1510 | 1510 | |
1511 | 1511 | // Verify there is a user_ID |
1512 | - if ( $user_ID == $invoice_user ) { |
|
1512 | + if ($user_ID == $invoice_user) { |
|
1513 | 1513 | // Get the logged in user data |
1514 | - $user_data = get_userdata( $user_ID ); |
|
1515 | - $required_fields = wpinv_checkout_required_fields(); |
|
1514 | + $user_data = get_userdata($user_ID); |
|
1515 | + $required_fields = wpinv_checkout_required_fields(); |
|
1516 | 1516 | |
1517 | 1517 | // Loop through required fields and show error messages |
1518 | - if ( !empty( $required_fields ) ) { |
|
1519 | - foreach ( $required_fields as $field_name => $value ) { |
|
1520 | - if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) { |
|
1521 | - wpinv_set_error( $value['error_id'], $value['error_message'] ); |
|
1518 | + if (!empty($required_fields)) { |
|
1519 | + foreach ($required_fields as $field_name => $value) { |
|
1520 | + if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) { |
|
1521 | + wpinv_set_error($value['error_id'], $value['error_message']); |
|
1522 | 1522 | } |
1523 | 1523 | } |
1524 | 1524 | } |
1525 | 1525 | |
1526 | 1526 | // Verify data |
1527 | - if ( $user_data ) { |
|
1527 | + if ($user_data) { |
|
1528 | 1528 | // Collected logged in user data |
1529 | 1529 | $valid_user_data = array( |
1530 | 1530 | 'user_id' => $user_ID, |
1531 | - 'email' => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email, |
|
1532 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name, |
|
1533 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name'] ) ? sanitize_text_field( $_POST['wpinv_last_name'] ) : $user_data->last_name, |
|
1531 | + 'email' => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email, |
|
1532 | + 'first_name' => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name, |
|
1533 | + 'last_name' => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name, |
|
1534 | 1534 | ); |
1535 | 1535 | |
1536 | - if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) { |
|
1537 | - wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) ); |
|
1536 | + if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) { |
|
1537 | + wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing')); |
|
1538 | 1538 | } |
1539 | 1539 | } else { |
1540 | 1540 | // Set invalid user error |
1541 | - wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) ); |
|
1541 | + wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing')); |
|
1542 | 1542 | } |
1543 | 1543 | } else { |
1544 | 1544 | // Set invalid user error |
1545 | - wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) ); |
|
1545 | + wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing')); |
|
1546 | 1546 | } |
1547 | 1547 | |
1548 | 1548 | // Return user data |
@@ -1554,27 +1554,27 @@ discard block |
||
1554 | 1554 | |
1555 | 1555 | $data = array(); |
1556 | 1556 | |
1557 | - if ( is_user_logged_in() ) { |
|
1558 | - if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) { |
|
1559 | - $data['user_id'] = (int)get_current_user_id(); |
|
1557 | + if (is_user_logged_in()) { |
|
1558 | + if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) { |
|
1559 | + $data['user_id'] = (int) get_current_user_id(); |
|
1560 | 1560 | } else { |
1561 | - wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) ); |
|
1561 | + wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing')); |
|
1562 | 1562 | } |
1563 | 1563 | } else { |
1564 | 1564 | // If guest checkout allowed |
1565 | - if ( !wpinv_require_login_to_checkout() ) { |
|
1565 | + if (!wpinv_require_login_to_checkout()) { |
|
1566 | 1566 | $data['user_id'] = 0; |
1567 | 1567 | } else { |
1568 | - wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) ); |
|
1568 | + wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing')); |
|
1569 | 1569 | } |
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | return $data; |
1573 | 1573 | } |
1574 | 1574 | |
1575 | -function wpinv_checkout_form_get_user( $valid_data = array() ) { |
|
1575 | +function wpinv_checkout_form_get_user($valid_data = array()) { |
|
1576 | 1576 | |
1577 | - if ( !empty( $valid_data['current_user']['user_id'] ) ) { |
|
1577 | + if (!empty($valid_data['current_user']['user_id'])) { |
|
1578 | 1578 | $user = $valid_data['current_user']; |
1579 | 1579 | } else { |
1580 | 1580 | // Set the valid invoice user |
@@ -1582,7 +1582,7 @@ discard block |
||
1582 | 1582 | } |
1583 | 1583 | |
1584 | 1584 | // Verify invoice have an user |
1585 | - if ( false === $user || empty( $user ) ) { |
|
1585 | + if (false === $user || empty($user)) { |
|
1586 | 1586 | return false; |
1587 | 1587 | } |
1588 | 1588 | |
@@ -1599,11 +1599,11 @@ discard block |
||
1599 | 1599 | 'zip', |
1600 | 1600 | ); |
1601 | 1601 | |
1602 | - foreach ( $address_fields as $field ) { |
|
1603 | - $user[$field] = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false; |
|
1602 | + foreach ($address_fields as $field) { |
|
1603 | + $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false; |
|
1604 | 1604 | |
1605 | - if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) { |
|
1606 | - update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] ); |
|
1605 | + if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) { |
|
1606 | + update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]); |
|
1607 | 1607 | } |
1608 | 1608 | } |
1609 | 1609 | |
@@ -1611,26 +1611,26 @@ discard block |
||
1611 | 1611 | return $user; |
1612 | 1612 | } |
1613 | 1613 | |
1614 | -function wpinv_set_checkout_session( $invoice_data = array() ) { |
|
1614 | +function wpinv_set_checkout_session($invoice_data = array()) { |
|
1615 | 1615 | global $wpi_session; |
1616 | - return $wpi_session->set( 'wpinv_checkout', $invoice_data ); |
|
1616 | + return $wpi_session->set('wpinv_checkout', $invoice_data); |
|
1617 | 1617 | } |
1618 | 1618 | |
1619 | 1619 | function wpinv_get_checkout_session() { |
1620 | 1620 | global $wpi_session; |
1621 | - return $wpi_session->get( 'wpinv_checkout' ); |
|
1621 | + return $wpi_session->get('wpinv_checkout'); |
|
1622 | 1622 | } |
1623 | 1623 | |
1624 | 1624 | function wpinv_empty_cart() { |
1625 | 1625 | global $wpi_session; |
1626 | 1626 | |
1627 | 1627 | // Remove cart contents |
1628 | - $wpi_session->set( 'wpinv_checkout', NULL ); |
|
1628 | + $wpi_session->set('wpinv_checkout', NULL); |
|
1629 | 1629 | |
1630 | 1630 | // Remove all cart fees |
1631 | - $wpi_session->set( 'wpi_cart_fees', NULL ); |
|
1631 | + $wpi_session->set('wpi_cart_fees', NULL); |
|
1632 | 1632 | |
1633 | - do_action( 'wpinv_empty_cart' ); |
|
1633 | + do_action('wpinv_empty_cart'); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | function wpinv_process_checkout() { |
@@ -1639,7 +1639,7 @@ discard block |
||
1639 | 1639 | wpinv_clear_errors(); |
1640 | 1640 | |
1641 | 1641 | $invoice = wpinv_get_invoice_cart(); |
1642 | - if ( empty( $invoice ) ) { |
|
1642 | + if (empty($invoice)) { |
|
1643 | 1643 | return false; |
1644 | 1644 | } |
1645 | 1645 | |
@@ -1647,42 +1647,42 @@ discard block |
||
1647 | 1647 | |
1648 | 1648 | $wpi_checkout_id = $invoice->ID; |
1649 | 1649 | |
1650 | - do_action( 'wpinv_pre_process_checkout' ); |
|
1650 | + do_action('wpinv_pre_process_checkout'); |
|
1651 | 1651 | |
1652 | - if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty |
|
1652 | + if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty |
|
1653 | 1653 | $valid_data = false; |
1654 | - wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) ); |
|
1654 | + wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing')); |
|
1655 | 1655 | } else { |
1656 | 1656 | // Validate the form $_POST data |
1657 | 1657 | $valid_data = wpinv_validate_checkout_fields(); |
1658 | 1658 | |
1659 | 1659 | // Allow themes and plugins to hook to errors |
1660 | - do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST ); |
|
1660 | + do_action('wpinv_checkout_error_checks', $valid_data, $_POST); |
|
1661 | 1661 | } |
1662 | 1662 | |
1663 | - $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX; |
|
1663 | + $is_ajax = defined('DOING_AJAX') && DOING_AJAX; |
|
1664 | 1664 | |
1665 | 1665 | // Validate the user |
1666 | - $user = wpinv_checkout_form_get_user( $valid_data ); |
|
1666 | + $user = wpinv_checkout_form_get_user($valid_data); |
|
1667 | 1667 | |
1668 | 1668 | // Let extensions validate fields after user is logged in if user has used login/registration form |
1669 | - do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST ); |
|
1669 | + do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST); |
|
1670 | 1670 | |
1671 | - if ( false === $valid_data || wpinv_get_errors() || ! $user ) { |
|
1672 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1673 | - do_action( 'wpinv_ajax_checkout_errors' ); |
|
1671 | + if (false === $valid_data || wpinv_get_errors() || !$user) { |
|
1672 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1673 | + do_action('wpinv_ajax_checkout_errors'); |
|
1674 | 1674 | die(); |
1675 | 1675 | } else { |
1676 | 1676 | return false; |
1677 | 1677 | } |
1678 | 1678 | } |
1679 | 1679 | |
1680 | - if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) { |
|
1680 | + if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) { |
|
1681 | 1681 | // Save address fields. |
1682 | - $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' ); |
|
1683 | - foreach ( $address_fields as $field ) { |
|
1684 | - if ( isset( $user[$field] ) ) { |
|
1685 | - $invoice->set( $field, $user[$field] ); |
|
1682 | + $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company'); |
|
1683 | + foreach ($address_fields as $field) { |
|
1684 | + if (isset($user[$field])) { |
|
1685 | + $invoice->set($field, $user[$field]); |
|
1686 | 1686 | } |
1687 | 1687 | |
1688 | 1688 | $invoice->save(); |
@@ -1690,16 +1690,16 @@ discard block |
||
1690 | 1690 | |
1691 | 1691 | $response['success'] = true; |
1692 | 1692 | $response['data']['subtotal'] = $invoice->get_subtotal(); |
1693 | - $response['data']['subtotalf'] = $invoice->get_subtotal( true ); |
|
1693 | + $response['data']['subtotalf'] = $invoice->get_subtotal(true); |
|
1694 | 1694 | $response['data']['discount'] = $invoice->get_discount(); |
1695 | - $response['data']['discountf'] = $invoice->get_discount( true ); |
|
1695 | + $response['data']['discountf'] = $invoice->get_discount(true); |
|
1696 | 1696 | $response['data']['tax'] = $invoice->get_tax(); |
1697 | - $response['data']['taxf'] = $invoice->get_tax( true ); |
|
1697 | + $response['data']['taxf'] = $invoice->get_tax(true); |
|
1698 | 1698 | $response['data']['total'] = $invoice->get_total(); |
1699 | - $response['data']['totalf'] = $invoice->get_total( true ); |
|
1700 | - $response['data']['free'] = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false; |
|
1699 | + $response['data']['totalf'] = $invoice->get_total(true); |
|
1700 | + $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false; |
|
1701 | 1701 | |
1702 | - wp_send_json( $response ); |
|
1702 | + wp_send_json($response); |
|
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | $user_info = array( |
@@ -1721,42 +1721,42 @@ discard block |
||
1721 | 1721 | |
1722 | 1722 | // Setup invoice information |
1723 | 1723 | $invoice_data = array( |
1724 | - 'invoice_id' => !empty( $invoice ) ? $invoice->ID : 0, |
|
1724 | + 'invoice_id' => !empty($invoice) ? $invoice->ID : 0, |
|
1725 | 1725 | 'items' => $cart_items, |
1726 | 1726 | 'cart_discounts' => $discounts, |
1727 | - 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1728 | - 'subtotal' => wpinv_get_cart_subtotal( $cart_items ), // Amount before taxes and discounts |
|
1729 | - 'discount' => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount |
|
1730 | - 'tax' => wpinv_get_cart_tax( $cart_items, $invoice ), // Taxed amount |
|
1731 | - 'price' => wpinv_get_cart_total( $cart_items, $discounts ), // Amount after taxes |
|
1727 | + 'fees' => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart |
|
1728 | + 'subtotal' => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts |
|
1729 | + 'discount' => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount |
|
1730 | + 'tax' => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount |
|
1731 | + 'price' => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes |
|
1732 | 1732 | 'invoice_key' => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(), |
1733 | 1733 | 'user_email' => $invoice->get_email(), |
1734 | - 'date' => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ), |
|
1735 | - 'user_info' => stripslashes_deep( $user_info ), |
|
1734 | + 'date' => date('Y-m-d H:i:s', current_time('timestamp')), |
|
1735 | + 'user_info' => stripslashes_deep($user_info), |
|
1736 | 1736 | 'post_data' => $_POST, |
1737 | 1737 | 'cart_details' => $cart_items, |
1738 | 1738 | 'gateway' => $valid_data['gateway'], |
1739 | 1739 | 'card_info' => $valid_data['cc_info'] |
1740 | 1740 | ); |
1741 | 1741 | |
1742 | - $vat_info = $wpinv_euvat->current_vat_data(); |
|
1743 | - if ( is_array( $vat_info ) ) { |
|
1742 | + $vat_info = $wpinv_euvat->current_vat_data(); |
|
1743 | + if (is_array($vat_info)) { |
|
1744 | 1744 | $invoice_data['user_info']['vat_number'] = $vat_info['number']; |
1745 | 1745 | $invoice_data['user_info']['vat_rate'] = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']); |
1746 | - $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1746 | + $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
1747 | 1747 | |
1748 | 1748 | // Add the VAT rate to each item in the cart |
1749 | - foreach( $invoice_data['cart_details'] as $key => $item_data) { |
|
1749 | + foreach ($invoice_data['cart_details'] as $key => $item_data) { |
|
1750 | 1750 | $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']); |
1751 | - $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 ); |
|
1751 | + $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4); |
|
1752 | 1752 | } |
1753 | 1753 | } |
1754 | 1754 | |
1755 | 1755 | // Save vat fields. |
1756 | - $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' ); |
|
1757 | - foreach ( $address_fields as $field ) { |
|
1758 | - if ( isset( $invoice_data['user_info'][$field] ) ) { |
|
1759 | - $invoice->set( $field, $invoice_data['user_info'][$field] ); |
|
1756 | + $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed'); |
|
1757 | + foreach ($address_fields as $field) { |
|
1758 | + if (isset($invoice_data['user_info'][$field])) { |
|
1759 | + $invoice->set($field, $invoice_data['user_info'][$field]); |
|
1760 | 1760 | } |
1761 | 1761 | } |
1762 | 1762 | $invoice->save(); |
@@ -1765,54 +1765,54 @@ discard block |
||
1765 | 1765 | $valid_data['user'] = $user; |
1766 | 1766 | |
1767 | 1767 | // Allow themes and plugins to hook before the gateway |
1768 | - do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data ); |
|
1768 | + do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data); |
|
1769 | 1769 | |
1770 | 1770 | // If it is free, abort. |
1771 | - if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 == $invoice->get_recurring_details( 'total' ) ) ) { |
|
1771 | + if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) { |
|
1772 | 1772 | $invoice_data['gateway'] = 'manual'; |
1773 | 1773 | $_POST['wpi-gateway'] = 'manual'; |
1774 | 1774 | } |
1775 | 1775 | |
1776 | 1776 | // Allow the invoice data to be modified before it is sent to the gateway |
1777 | - $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data ); |
|
1777 | + $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data); |
|
1778 | 1778 | |
1779 | - if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) { |
|
1779 | + if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') { |
|
1780 | 1780 | $mode = 'test'; |
1781 | 1781 | } else { |
1782 | - $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live'; |
|
1782 | + $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'; |
|
1783 | 1783 | } |
1784 | 1784 | |
1785 | 1785 | // Setup the data we're storing in the purchase session |
1786 | 1786 | $session_data = $invoice_data; |
1787 | 1787 | // Make sure credit card numbers are never stored in sessions |
1788 | - if ( !empty( $session_data['card_info']['card_number'] ) ) { |
|
1789 | - unset( $session_data['card_info']['card_number'] ); |
|
1788 | + if (!empty($session_data['card_info']['card_number'])) { |
|
1789 | + unset($session_data['card_info']['card_number']); |
|
1790 | 1790 | } |
1791 | 1791 | |
1792 | 1792 | // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data. |
1793 | - wpinv_set_checkout_session( $invoice_data ); |
|
1793 | + wpinv_set_checkout_session($invoice_data); |
|
1794 | 1794 | |
1795 | 1795 | // Set gateway |
1796 | - $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] ); |
|
1797 | - $invoice->update_meta( '_wpinv_mode', $mode ); |
|
1798 | - $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) ); |
|
1796 | + $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']); |
|
1797 | + $invoice->update_meta('_wpinv_mode', $mode); |
|
1798 | + $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp'))); |
|
1799 | 1799 | |
1800 | - do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data ); |
|
1800 | + do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data); |
|
1801 | 1801 | |
1802 | 1802 | // Send info to the gateway for payment processing |
1803 | - wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data ); |
|
1803 | + wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data); |
|
1804 | 1804 | die(); |
1805 | 1805 | } |
1806 | -add_action( 'wpinv_payment', 'wpinv_process_checkout' ); |
|
1806 | +add_action('wpinv_payment', 'wpinv_process_checkout'); |
|
1807 | 1807 | |
1808 | -function wpinv_get_invoices( $args ) { |
|
1809 | - $args = wp_parse_args( $args, array( |
|
1810 | - 'status' => array_keys( wpinv_get_invoice_statuses() ), |
|
1808 | +function wpinv_get_invoices($args) { |
|
1809 | + $args = wp_parse_args($args, array( |
|
1810 | + 'status' => array_keys(wpinv_get_invoice_statuses()), |
|
1811 | 1811 | 'type' => 'wpi_invoice', |
1812 | 1812 | 'parent' => null, |
1813 | 1813 | 'user' => null, |
1814 | 1814 | 'email' => '', |
1815 | - 'limit' => get_option( 'posts_per_page' ), |
|
1815 | + 'limit' => get_option('posts_per_page'), |
|
1816 | 1816 | 'offset' => null, |
1817 | 1817 | 'page' => 1, |
1818 | 1818 | 'exclude' => array(), |
@@ -1820,7 +1820,7 @@ discard block |
||
1820 | 1820 | 'order' => 'DESC', |
1821 | 1821 | 'return' => 'objects', |
1822 | 1822 | 'paginate' => false, |
1823 | - ) ); |
|
1823 | + )); |
|
1824 | 1824 | |
1825 | 1825 | // Handle some BW compatibility arg names where wp_query args differ in naming. |
1826 | 1826 | $map_legacy = array( |
@@ -1833,18 +1833,18 @@ discard block |
||
1833 | 1833 | 'paged' => 'page', |
1834 | 1834 | ); |
1835 | 1835 | |
1836 | - foreach ( $map_legacy as $from => $to ) { |
|
1837 | - if ( isset( $args[ $from ] ) ) { |
|
1838 | - $args[ $to ] = $args[ $from ]; |
|
1836 | + foreach ($map_legacy as $from => $to) { |
|
1837 | + if (isset($args[$from])) { |
|
1838 | + $args[$to] = $args[$from]; |
|
1839 | 1839 | } |
1840 | 1840 | } |
1841 | 1841 | |
1842 | - if ( get_query_var( 'paged' ) ) |
|
1842 | + if (get_query_var('paged')) |
|
1843 | 1843 | $args['page'] = get_query_var('paged'); |
1844 | - else if ( get_query_var( 'page' ) ) |
|
1845 | - $args['page'] = get_query_var( 'page' ); |
|
1846 | - else if ( !empty( $args[ 'page' ] ) ) |
|
1847 | - $args['page'] = $args[ 'page' ]; |
|
1844 | + else if (get_query_var('page')) |
|
1845 | + $args['page'] = get_query_var('page'); |
|
1846 | + else if (!empty($args['page'])) |
|
1847 | + $args['page'] = $args['page']; |
|
1848 | 1848 | else |
1849 | 1849 | $args['page'] = 1; |
1850 | 1850 | |
@@ -1857,48 +1857,48 @@ discard block |
||
1857 | 1857 | 'post_status' => $args['status'], |
1858 | 1858 | 'posts_per_page' => $args['limit'], |
1859 | 1859 | 'meta_query' => array(), |
1860 | - 'date_query' => !empty( $args['date_query'] ) ? $args['date_query'] : array(), |
|
1860 | + 'date_query' => !empty($args['date_query']) ? $args['date_query'] : array(), |
|
1861 | 1861 | 'fields' => 'ids', |
1862 | 1862 | 'orderby' => $args['orderby'], |
1863 | 1863 | 'order' => $args['order'], |
1864 | 1864 | ); |
1865 | 1865 | |
1866 | - if ( !empty( $args['user'] ) ) { |
|
1867 | - $wp_query_args['author'] = absint( $args['user'] ); |
|
1866 | + if (!empty($args['user'])) { |
|
1867 | + $wp_query_args['author'] = absint($args['user']); |
|
1868 | 1868 | } |
1869 | 1869 | |
1870 | - if ( ! is_null( $args['parent'] ) ) { |
|
1871 | - $wp_query_args['post_parent'] = absint( $args['parent'] ); |
|
1870 | + if (!is_null($args['parent'])) { |
|
1871 | + $wp_query_args['post_parent'] = absint($args['parent']); |
|
1872 | 1872 | } |
1873 | 1873 | |
1874 | - if ( ! is_null( $args['offset'] ) ) { |
|
1875 | - $wp_query_args['offset'] = absint( $args['offset'] ); |
|
1874 | + if (!is_null($args['offset'])) { |
|
1875 | + $wp_query_args['offset'] = absint($args['offset']); |
|
1876 | 1876 | } else { |
1877 | - $wp_query_args['paged'] = absint( $args['page'] ); |
|
1877 | + $wp_query_args['paged'] = absint($args['page']); |
|
1878 | 1878 | } |
1879 | 1879 | |
1880 | - if ( ! empty( $args['exclude'] ) ) { |
|
1881 | - $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] ); |
|
1880 | + if (!empty($args['exclude'])) { |
|
1881 | + $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']); |
|
1882 | 1882 | } |
1883 | 1883 | |
1884 | - if ( ! $args['paginate' ] ) { |
|
1884 | + if (!$args['paginate']) { |
|
1885 | 1885 | $wp_query_args['no_found_rows'] = true; |
1886 | 1886 | } |
1887 | 1887 | |
1888 | 1888 | $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args); |
1889 | 1889 | |
1890 | 1890 | // Get results. |
1891 | - $invoices = new WP_Query( $wp_query_args ); |
|
1891 | + $invoices = new WP_Query($wp_query_args); |
|
1892 | 1892 | |
1893 | - if ( 'objects' === $args['return'] ) { |
|
1894 | - $return = array_map( 'wpinv_get_invoice', $invoices->posts ); |
|
1895 | - } elseif ( 'self' === $args['return'] ) { |
|
1893 | + if ('objects' === $args['return']) { |
|
1894 | + $return = array_map('wpinv_get_invoice', $invoices->posts); |
|
1895 | + } elseif ('self' === $args['return']) { |
|
1896 | 1896 | return $invoices; |
1897 | 1897 | } else { |
1898 | 1898 | $return = $invoices->posts; |
1899 | 1899 | } |
1900 | 1900 | |
1901 | - if ( $args['paginate' ] ) { |
|
1901 | + if ($args['paginate']) { |
|
1902 | 1902 | return (object) array( |
1903 | 1903 | 'invoices' => $return, |
1904 | 1904 | 'total' => $invoices->found_posts, |
@@ -1911,22 +1911,22 @@ discard block |
||
1911 | 1911 | |
1912 | 1912 | function wpinv_get_user_invoices_columns() { |
1913 | 1913 | $columns = array( |
1914 | - 'invoice-number' => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ), |
|
1915 | - 'created-date' => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1916 | - 'payment-date' => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ), |
|
1917 | - 'invoice-status' => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ), |
|
1918 | - 'invoice-total' => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ), |
|
1919 | - 'invoice-actions' => array( 'title' => ' ', 'class' => 'text-center' ), |
|
1914 | + 'invoice-number' => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'), |
|
1915 | + 'created-date' => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'), |
|
1916 | + 'payment-date' => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'), |
|
1917 | + 'invoice-status' => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'), |
|
1918 | + 'invoice-total' => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'), |
|
1919 | + 'invoice-actions' => array('title' => ' ', 'class' => 'text-center'), |
|
1920 | 1920 | ); |
1921 | 1921 | |
1922 | - return apply_filters( 'wpinv_user_invoices_columns', $columns ); |
|
1922 | + return apply_filters('wpinv_user_invoices_columns', $columns); |
|
1923 | 1923 | } |
1924 | 1924 | |
1925 | -function wpinv_payment_receipt( $atts, $content = null ) { |
|
1925 | +function wpinv_payment_receipt($atts, $content = null) { |
|
1926 | 1926 | global $wpinv_receipt_args; |
1927 | 1927 | |
1928 | - $wpinv_receipt_args = shortcode_atts( array( |
|
1929 | - 'error' => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ), |
|
1928 | + $wpinv_receipt_args = shortcode_atts(array( |
|
1929 | + 'error' => __('Sorry, trouble retrieving payment receipt.', 'invoicing'), |
|
1930 | 1930 | 'price' => true, |
1931 | 1931 | 'discount' => true, |
1932 | 1932 | 'items' => true, |
@@ -1935,45 +1935,45 @@ discard block |
||
1935 | 1935 | 'invoice_key' => false, |
1936 | 1936 | 'payment_method' => true, |
1937 | 1937 | 'invoice_id' => true |
1938 | - ), $atts, 'wpinv_receipt' ); |
|
1938 | + ), $atts, 'wpinv_receipt'); |
|
1939 | 1939 | |
1940 | 1940 | // Find the invoice. |
1941 | 1941 | $session = wpinv_get_checkout_session(); |
1942 | 1942 | |
1943 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
1944 | - $invoice_id = wpinv_get_invoice_id_by_key( urldecode( $_GET['invoice_key'] ) ); |
|
1945 | - } else if ( isset( $_GET['invoice-id'] ) ) { |
|
1943 | + if (isset($_GET['invoice_key'])) { |
|
1944 | + $invoice_id = wpinv_get_invoice_id_by_key(urldecode($_GET['invoice_key'])); |
|
1945 | + } else if (isset($_GET['invoice-id'])) { |
|
1946 | 1946 | $invoice_id = (int) $_GET['invoice-id']; |
1947 | - } else if ( $session && isset( $session['invoice_key'] ) ) { |
|
1948 | - $invoice_id = wpinv_get_invoice_id_by_key( $session['invoice_key'] ); |
|
1949 | - } else if ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) { |
|
1950 | - $invoice_id = wpinv_get_invoice_id_by_key( $wpinv_receipt_args['invoice_key'] ); |
|
1947 | + } else if ($session && isset($session['invoice_key'])) { |
|
1948 | + $invoice_id = wpinv_get_invoice_id_by_key($session['invoice_key']); |
|
1949 | + } else if (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) { |
|
1950 | + $invoice_id = wpinv_get_invoice_id_by_key($wpinv_receipt_args['invoice_key']); |
|
1951 | 1951 | } |
1952 | 1952 | |
1953 | 1953 | // Did we find the invoice? |
1954 | - if ( empty( $invoice_id ) || ! $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
1955 | - return '<p class="alert alert-error">' . __( 'We could not find your invoice.', 'invoicing' ) . '</p>'; |
|
1954 | + if (empty($invoice_id) || !$invoice = wpinv_get_invoice($invoice_id)) { |
|
1955 | + return '<p class="alert alert-error">' . __('We could not find your invoice.', 'invoicing') . '</p>'; |
|
1956 | 1956 | } |
1957 | 1957 | |
1958 | 1958 | $invoice_key = $invoice->get_key(); |
1959 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
1960 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
1961 | - $user_can_view = $_GET['invoice-id'] == $invoice->ID; |
|
1959 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
1960 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
1961 | + $user_can_view = $_GET['invoice-id'] == $invoice->ID; |
|
1962 | 1962 | } |
1963 | 1963 | |
1964 | 1964 | // Key was provided, but user is logged out. Offer them the ability to login and view the receipt |
1965 | - if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) { |
|
1965 | + if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) { |
|
1966 | 1966 | // login redirect |
1967 | - return '<p class="alert alert-error">' . __( 'You must be logged in to view this receipt', 'invoicing' ) . '</p>'; |
|
1967 | + return '<p class="alert alert-error">' . __('You must be logged in to view this receipt', 'invoicing') . '</p>'; |
|
1968 | 1968 | } |
1969 | 1969 | |
1970 | - if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) { |
|
1970 | + if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) { |
|
1971 | 1971 | return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>'; |
1972 | 1972 | } |
1973 | 1973 | |
1974 | 1974 | ob_start(); |
1975 | 1975 | |
1976 | - wpinv_get_template_part( 'wpinv-invoice-receipt' ); |
|
1976 | + wpinv_get_template_part('wpinv-invoice-receipt'); |
|
1977 | 1977 | |
1978 | 1978 | $display = ob_get_clean(); |
1979 | 1979 | |
@@ -1983,148 +1983,148 @@ discard block |
||
1983 | 1983 | /** |
1984 | 1984 | * Given an invoice key, this function returns the id. |
1985 | 1985 | */ |
1986 | -function wpinv_get_invoice_id_by_key( $key ) { |
|
1986 | +function wpinv_get_invoice_id_by_key($key) { |
|
1987 | 1987 | global $wpdb; |
1988 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1989 | - return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) ); |
|
1988 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
1989 | + return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key)); |
|
1990 | 1990 | } |
1991 | 1991 | |
1992 | -function wpinv_can_view_receipt( $invoice_key = '' ) { |
|
1993 | - $return = current_user_can( 'manage_options' ); |
|
1992 | +function wpinv_can_view_receipt($invoice_key = '') { |
|
1993 | + $return = current_user_can('manage_options'); |
|
1994 | 1994 | |
1995 | - if ( empty( $invoice_key ) ) { |
|
1995 | + if (empty($invoice_key)) { |
|
1996 | 1996 | return false; |
1997 | 1997 | } |
1998 | 1998 | |
1999 | 1999 | global $wpinv_receipt_args; |
2000 | 2000 | |
2001 | - $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
2002 | - if ( isset( $_GET['invoice-id'] ) ) { |
|
2003 | - $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0; |
|
2001 | + $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key); |
|
2002 | + if (isset($_GET['invoice-id'])) { |
|
2003 | + $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0; |
|
2004 | 2004 | } |
2005 | 2005 | |
2006 | - if ( empty( $wpinv_receipt_args['id'] ) ) { |
|
2006 | + if (empty($wpinv_receipt_args['id'])) { |
|
2007 | 2007 | return $return; |
2008 | 2008 | } |
2009 | 2009 | |
2010 | - $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] ); |
|
2011 | - if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) { |
|
2010 | + $invoice = wpinv_get_invoice($wpinv_receipt_args['id']); |
|
2011 | + if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) { |
|
2012 | 2012 | return $return; |
2013 | 2013 | } |
2014 | 2014 | |
2015 | - if ( is_user_logged_in() ) { |
|
2016 | - if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) { |
|
2015 | + if (is_user_logged_in()) { |
|
2016 | + if ((int) $invoice->get_user_id() === (int) get_current_user_id()) { |
|
2017 | 2017 | $return = true; |
2018 | 2018 | } |
2019 | 2019 | } |
2020 | 2020 | |
2021 | 2021 | $session = wpinv_get_checkout_session(); |
2022 | - if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) { |
|
2023 | - $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
2022 | + if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) { |
|
2023 | + $check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key']; |
|
2024 | 2024 | |
2025 | - if ( wpinv_require_login_to_checkout() ) { |
|
2025 | + if (wpinv_require_login_to_checkout()) { |
|
2026 | 2026 | $return = $return && $check_key == $invoice_key; |
2027 | 2027 | } else { |
2028 | 2028 | $return = $check_key == $invoice_key; |
2029 | 2029 | } |
2030 | 2030 | } |
2031 | 2031 | |
2032 | - return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key ); |
|
2032 | + return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key); |
|
2033 | 2033 | } |
2034 | 2034 | |
2035 | 2035 | function wpinv_pay_for_invoice() { |
2036 | 2036 | global $wpinv_euvat; |
2037 | 2037 | |
2038 | - if ( isset( $_GET['invoice_key'] ) ) { |
|
2038 | + if (isset($_GET['invoice_key'])) { |
|
2039 | 2039 | $checkout_uri = wpinv_get_checkout_uri(); |
2040 | - $invoice_key = sanitize_text_field( $_GET['invoice_key'] ); |
|
2040 | + $invoice_key = sanitize_text_field($_GET['invoice_key']); |
|
2041 | 2041 | |
2042 | - if ( empty( $invoice_key ) ) { |
|
2043 | - wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) ); |
|
2044 | - wp_redirect( $checkout_uri ); |
|
2042 | + if (empty($invoice_key)) { |
|
2043 | + wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing')); |
|
2044 | + wp_redirect($checkout_uri); |
|
2045 | 2045 | exit(); |
2046 | 2046 | } |
2047 | 2047 | |
2048 | - do_action( 'wpinv_check_pay_for_invoice', $invoice_key ); |
|
2048 | + do_action('wpinv_check_pay_for_invoice', $invoice_key); |
|
2049 | 2049 | |
2050 | - $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ); |
|
2051 | - $user_can_view = wpinv_can_view_receipt( $invoice_key ); |
|
2052 | - if ( $user_can_view && isset( $_GET['invoice-id'] ) ) { |
|
2053 | - $invoice_id = (int)$_GET['invoice-id']; |
|
2054 | - $user_can_view = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false; |
|
2050 | + $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
|
2051 | + $user_can_view = wpinv_can_view_receipt($invoice_key); |
|
2052 | + if ($user_can_view && isset($_GET['invoice-id'])) { |
|
2053 | + $invoice_id = (int) $_GET['invoice-id']; |
|
2054 | + $user_can_view = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false; |
|
2055 | 2055 | } |
2056 | 2056 | |
2057 | - if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) { |
|
2058 | - if ( $invoice->needs_payment() ) { |
|
2057 | + if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) { |
|
2058 | + if ($invoice->needs_payment()) { |
|
2059 | 2059 | $data = array(); |
2060 | 2060 | $data['invoice_id'] = $invoice_id; |
2061 | - $data['cart_discounts'] = $invoice->get_discounts( true ); |
|
2061 | + $data['cart_discounts'] = $invoice->get_discounts(true); |
|
2062 | 2062 | |
2063 | - wpinv_set_checkout_session( $data ); |
|
2063 | + wpinv_set_checkout_session($data); |
|
2064 | 2064 | |
2065 | - if ( wpinv_get_option( 'vat_ip_country_default' ) ) { |
|
2065 | + if (wpinv_get_option('vat_ip_country_default')) { |
|
2066 | 2066 | $_POST['country'] = $wpinv_euvat->get_country_by_ip(); |
2067 | 2067 | $_POST['state'] = $_POST['country'] == $invoice->country ? $invoice->state : ''; |
2068 | 2068 | |
2069 | - wpinv_recalculate_tax( true ); |
|
2069 | + wpinv_recalculate_tax(true); |
|
2070 | 2070 | } |
2071 | 2071 | |
2072 | 2072 | } else { |
2073 | 2073 | $checkout_uri = $invoice->get_view_url(); |
2074 | 2074 | } |
2075 | 2075 | } else { |
2076 | - wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) ); |
|
2076 | + wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing')); |
|
2077 | 2077 | |
2078 | - $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() ); |
|
2078 | + $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink()); |
|
2079 | 2079 | } |
2080 | 2080 | |
2081 | - if(wp_redirect( $checkout_uri )){ |
|
2081 | + if (wp_redirect($checkout_uri)) { |
|
2082 | 2082 | exit; |
2083 | 2083 | }; |
2084 | 2084 | wpinv_die(); |
2085 | 2085 | } |
2086 | 2086 | } |
2087 | -add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' ); |
|
2087 | +add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice'); |
|
2088 | 2088 | |
2089 | -function wpinv_handle_pay_via_invoice_link( $invoice_key ) { |
|
2090 | - if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) { |
|
2091 | - if ( $invoice = wpinv_get_invoice( $invoice_id ) ) { |
|
2089 | +function wpinv_handle_pay_via_invoice_link($invoice_key) { |
|
2090 | + if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) { |
|
2091 | + if ($invoice = wpinv_get_invoice($invoice_id)) { |
|
2092 | 2092 | $user_id = $invoice->get_user_id(); |
2093 | - $secret = sanitize_text_field( $_GET['_wpipay'] ); |
|
2093 | + $secret = sanitize_text_field($_GET['_wpipay']); |
|
2094 | 2094 | |
2095 | - if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link |
|
2096 | - $redirect_to = remove_query_arg( '_wpipay', get_permalink() ); |
|
2095 | + if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link |
|
2096 | + $redirect_to = remove_query_arg('_wpipay', get_permalink()); |
|
2097 | 2097 | |
2098 | - wpinv_guest_redirect( $redirect_to, $user_id ); |
|
2098 | + wpinv_guest_redirect($redirect_to, $user_id); |
|
2099 | 2099 | exit(); |
2100 | 2100 | } |
2101 | 2101 | } |
2102 | 2102 | } |
2103 | 2103 | } |
2104 | -add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' ); |
|
2104 | +add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link'); |
|
2105 | 2105 | |
2106 | -function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) { |
|
2107 | - $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id; |
|
2106 | +function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') { |
|
2107 | + $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id; |
|
2108 | 2108 | |
2109 | - if ( empty( $invoice_id ) && $invoice_id > 0 ) { |
|
2109 | + if (empty($invoice_id) && $invoice_id > 0) { |
|
2110 | 2110 | return false; |
2111 | 2111 | } |
2112 | 2112 | |
2113 | - if ( empty( $transaction_id ) ) { |
|
2113 | + if (empty($transaction_id)) { |
|
2114 | 2114 | $transaction_id = $invoice_id; |
2115 | 2115 | } |
2116 | 2116 | |
2117 | - $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id ); |
|
2117 | + $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id); |
|
2118 | 2118 | |
2119 | - return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id ); |
|
2119 | + return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id); |
|
2120 | 2120 | } |
2121 | 2121 | |
2122 | -function wpinv_invoice_status_label( $status, $status_display = '' ) { |
|
2123 | - if ( empty( $status_display ) ) { |
|
2124 | - $status_display = wpinv_status_nicename( $status ); |
|
2122 | +function wpinv_invoice_status_label($status, $status_display = '') { |
|
2123 | + if (empty($status_display)) { |
|
2124 | + $status_display = wpinv_status_nicename($status); |
|
2125 | 2125 | } |
2126 | 2126 | |
2127 | - switch ( $status ) { |
|
2127 | + switch ($status) { |
|
2128 | 2128 | case 'publish' : |
2129 | 2129 | case 'wpi-renewal' : |
2130 | 2130 | $class = 'label-success'; |
@@ -2149,201 +2149,201 @@ discard block |
||
2149 | 2149 | |
2150 | 2150 | $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>'; |
2151 | 2151 | |
2152 | - return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display ); |
|
2152 | + return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display); |
|
2153 | 2153 | } |
2154 | 2154 | |
2155 | -function wpinv_format_invoice_number( $number, $type = '' ) { |
|
2156 | - $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type ); |
|
2157 | - if ( null !== $check ) { |
|
2155 | +function wpinv_format_invoice_number($number, $type = '') { |
|
2156 | + $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type); |
|
2157 | + if (null !== $check) { |
|
2158 | 2158 | return $check; |
2159 | 2159 | } |
2160 | 2160 | |
2161 | - if ( !empty( $number ) && !is_numeric( $number ) ) { |
|
2161 | + if (!empty($number) && !is_numeric($number)) { |
|
2162 | 2162 | return $number; |
2163 | 2163 | } |
2164 | 2164 | |
2165 | - $padd = wpinv_get_option( 'invoice_number_padd' ); |
|
2166 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2167 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2165 | + $padd = wpinv_get_option('invoice_number_padd'); |
|
2166 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2167 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2168 | 2168 | |
2169 | - $padd = absint( $padd ); |
|
2170 | - $formatted_number = absint( $number ); |
|
2169 | + $padd = absint($padd); |
|
2170 | + $formatted_number = absint($number); |
|
2171 | 2171 | |
2172 | - if ( $padd > 0 ) { |
|
2173 | - $formatted_number = zeroise( $formatted_number, $padd ); |
|
2172 | + if ($padd > 0) { |
|
2173 | + $formatted_number = zeroise($formatted_number, $padd); |
|
2174 | 2174 | } |
2175 | 2175 | |
2176 | 2176 | $formatted_number = $prefix . $formatted_number . $postfix; |
2177 | 2177 | |
2178 | - return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd ); |
|
2178 | + return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd); |
|
2179 | 2179 | } |
2180 | 2180 | |
2181 | -function wpinv_get_next_invoice_number( $type = '' ) { |
|
2182 | - $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type ); |
|
2183 | - if ( null !== $check ) { |
|
2181 | +function wpinv_get_next_invoice_number($type = '') { |
|
2182 | + $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type); |
|
2183 | + if (null !== $check) { |
|
2184 | 2184 | return $check; |
2185 | 2185 | } |
2186 | 2186 | |
2187 | - if ( !wpinv_sequential_number_active() ) { |
|
2187 | + if (!wpinv_sequential_number_active()) { |
|
2188 | 2188 | return false; |
2189 | 2189 | } |
2190 | 2190 | |
2191 | - $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 ); |
|
2192 | - $start = wpinv_get_option( 'invoice_sequence_start', 1 ); |
|
2193 | - if ( !absint( $start ) > 0 ) { |
|
2191 | + $number = $last_number = get_option('wpinv_last_invoice_number', 0); |
|
2192 | + $start = wpinv_get_option('invoice_sequence_start', 1); |
|
2193 | + if (!absint($start) > 0) { |
|
2194 | 2194 | $start = 1; |
2195 | 2195 | } |
2196 | 2196 | $increment_number = true; |
2197 | 2197 | $save_number = false; |
2198 | 2198 | |
2199 | - if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) { |
|
2200 | - $number = wpinv_clean_invoice_number( $number ); |
|
2199 | + if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) { |
|
2200 | + $number = wpinv_clean_invoice_number($number); |
|
2201 | 2201 | } |
2202 | 2202 | |
2203 | - if ( empty( $number ) ) { |
|
2204 | - if ( !( $last_number === 0 || $last_number === '0' ) ) { |
|
2205 | - $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) ); |
|
2203 | + if (empty($number)) { |
|
2204 | + if (!($last_number === 0 || $last_number === '0')) { |
|
2205 | + $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true)))); |
|
2206 | 2206 | |
2207 | - if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) { |
|
2208 | - if ( is_numeric( $invoice_number ) ) { |
|
2207 | + if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) { |
|
2208 | + if (is_numeric($invoice_number)) { |
|
2209 | 2209 | $number = $invoice_number; |
2210 | 2210 | } else { |
2211 | - $number = wpinv_clean_invoice_number( $invoice_number ); |
|
2211 | + $number = wpinv_clean_invoice_number($invoice_number); |
|
2212 | 2212 | } |
2213 | 2213 | } |
2214 | 2214 | |
2215 | - if ( empty( $number ) ) { |
|
2215 | + if (empty($number)) { |
|
2216 | 2216 | $increment_number = false; |
2217 | 2217 | $number = $start; |
2218 | - $save_number = ( $number - 1 ); |
|
2218 | + $save_number = ($number - 1); |
|
2219 | 2219 | } else { |
2220 | 2220 | $save_number = $number; |
2221 | 2221 | } |
2222 | 2222 | } |
2223 | 2223 | } |
2224 | 2224 | |
2225 | - if ( $start > $number ) { |
|
2225 | + if ($start > $number) { |
|
2226 | 2226 | $increment_number = false; |
2227 | 2227 | $number = $start; |
2228 | - $save_number = ( $number - 1 ); |
|
2228 | + $save_number = ($number - 1); |
|
2229 | 2229 | } |
2230 | 2230 | |
2231 | - if ( $save_number !== false ) { |
|
2232 | - update_option( 'wpinv_last_invoice_number', $save_number ); |
|
2231 | + if ($save_number !== false) { |
|
2232 | + update_option('wpinv_last_invoice_number', $save_number); |
|
2233 | 2233 | } |
2234 | 2234 | |
2235 | - $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number ); |
|
2235 | + $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number); |
|
2236 | 2236 | |
2237 | - if ( $increment_number ) { |
|
2237 | + if ($increment_number) { |
|
2238 | 2238 | $number++; |
2239 | 2239 | } |
2240 | 2240 | |
2241 | - return apply_filters( 'wpinv_get_next_invoice_number', $number ); |
|
2241 | + return apply_filters('wpinv_get_next_invoice_number', $number); |
|
2242 | 2242 | } |
2243 | 2243 | |
2244 | -function wpinv_clean_invoice_number( $number, $type = '' ) { |
|
2245 | - $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type ); |
|
2246 | - if ( null !== $check ) { |
|
2244 | +function wpinv_clean_invoice_number($number, $type = '') { |
|
2245 | + $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type); |
|
2246 | + if (null !== $check) { |
|
2247 | 2247 | return $check; |
2248 | 2248 | } |
2249 | 2249 | |
2250 | - $prefix = wpinv_get_option( 'invoice_number_prefix' ); |
|
2251 | - $postfix = wpinv_get_option( 'invoice_number_postfix' ); |
|
2250 | + $prefix = wpinv_get_option('invoice_number_prefix'); |
|
2251 | + $postfix = wpinv_get_option('invoice_number_postfix'); |
|
2252 | 2252 | |
2253 | - $number = preg_replace( '/' . $prefix . '/', '', $number, 1 ); |
|
2253 | + $number = preg_replace('/' . $prefix . '/', '', $number, 1); |
|
2254 | 2254 | |
2255 | - $length = strlen( $number ); |
|
2256 | - $postfix_pos = strrpos( $number, $postfix ); |
|
2255 | + $length = strlen($number); |
|
2256 | + $postfix_pos = strrpos($number, $postfix); |
|
2257 | 2257 | |
2258 | - if ( false !== $postfix_pos ) { |
|
2259 | - $number = substr_replace( $number, '', $postfix_pos, $length ); |
|
2258 | + if (false !== $postfix_pos) { |
|
2259 | + $number = substr_replace($number, '', $postfix_pos, $length); |
|
2260 | 2260 | } |
2261 | 2261 | |
2262 | - $number = intval( $number ); |
|
2262 | + $number = intval($number); |
|
2263 | 2263 | |
2264 | - return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix ); |
|
2264 | + return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix); |
|
2265 | 2265 | } |
2266 | 2266 | |
2267 | -function wpinv_save_number_post_saved( $post_ID, $post, $update ) { |
|
2267 | +function wpinv_save_number_post_saved($post_ID, $post, $update) { |
|
2268 | 2268 | global $wpdb; |
2269 | 2269 | |
2270 | - if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) { |
|
2271 | - wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type ); |
|
2270 | + if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) { |
|
2271 | + wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type); |
|
2272 | 2272 | } |
2273 | 2273 | |
2274 | - if ( !$update ) { |
|
2275 | - $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) ); |
|
2276 | - clean_post_cache( $post_ID ); |
|
2274 | + if (!$update) { |
|
2275 | + $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID)); |
|
2276 | + clean_post_cache($post_ID); |
|
2277 | 2277 | } |
2278 | 2278 | } |
2279 | -add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 ); |
|
2279 | +add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3); |
|
2280 | 2280 | |
2281 | -function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) { |
|
2282 | - if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) { |
|
2283 | - wpinv_update_invoice_number( $post_ID, true, $post_after->post_type ); |
|
2281 | +function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) { |
|
2282 | + if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) { |
|
2283 | + wpinv_update_invoice_number($post_ID, true, $post_after->post_type); |
|
2284 | 2284 | } |
2285 | 2285 | } |
2286 | -add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 ); |
|
2286 | +add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3); |
|
2287 | 2287 | |
2288 | -function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) { |
|
2288 | +function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') { |
|
2289 | 2289 | global $wpdb; |
2290 | 2290 | |
2291 | - $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type ); |
|
2292 | - if ( null !== $check ) { |
|
2291 | + $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type); |
|
2292 | + if (null !== $check) { |
|
2293 | 2293 | return $check; |
2294 | 2294 | } |
2295 | 2295 | |
2296 | - if ( wpinv_sequential_number_active() ) { |
|
2296 | + if (wpinv_sequential_number_active()) { |
|
2297 | 2297 | $number = wpinv_get_next_invoice_number(); |
2298 | 2298 | |
2299 | - if ( $save_sequential ) { |
|
2300 | - update_option( 'wpinv_last_invoice_number', $number ); |
|
2299 | + if ($save_sequential) { |
|
2300 | + update_option('wpinv_last_invoice_number', $number); |
|
2301 | 2301 | } |
2302 | 2302 | } else { |
2303 | 2303 | $number = $post_ID; |
2304 | 2304 | } |
2305 | 2305 | |
2306 | - $number = wpinv_format_invoice_number( $number ); |
|
2306 | + $number = wpinv_format_invoice_number($number); |
|
2307 | 2307 | |
2308 | - update_post_meta( $post_ID, '_wpinv_number', $number ); |
|
2308 | + update_post_meta($post_ID, '_wpinv_number', $number); |
|
2309 | 2309 | |
2310 | - $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) ); |
|
2310 | + $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID)); |
|
2311 | 2311 | |
2312 | - clean_post_cache( $post_ID ); |
|
2312 | + clean_post_cache($post_ID); |
|
2313 | 2313 | |
2314 | 2314 | return $number; |
2315 | 2315 | } |
2316 | 2316 | |
2317 | -function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) { |
|
2318 | - return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type ); |
|
2317 | +function wpinv_post_name_prefix($post_type = 'wpi_invoice') { |
|
2318 | + return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type); |
|
2319 | 2319 | } |
2320 | 2320 | |
2321 | -function wpinv_generate_post_name( $post_ID ) { |
|
2322 | - $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) ); |
|
2323 | - $post_name = sanitize_title( $prefix . $post_ID ); |
|
2321 | +function wpinv_generate_post_name($post_ID) { |
|
2322 | + $prefix = wpinv_post_name_prefix(get_post_type($post_ID)); |
|
2323 | + $post_name = sanitize_title($prefix . $post_ID); |
|
2324 | 2324 | |
2325 | - return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix ); |
|
2325 | + return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix); |
|
2326 | 2326 | } |
2327 | 2327 | |
2328 | -function wpinv_is_invoice_viewed( $invoice_id ) { |
|
2329 | - if ( empty( $invoice_id ) ) { |
|
2328 | +function wpinv_is_invoice_viewed($invoice_id) { |
|
2329 | + if (empty($invoice_id)) { |
|
2330 | 2330 | return false; |
2331 | 2331 | } |
2332 | 2332 | |
2333 | - $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true ); |
|
2333 | + $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true); |
|
2334 | 2334 | |
2335 | - return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id ); |
|
2335 | + return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id); |
|
2336 | 2336 | } |
2337 | 2337 | |
2338 | 2338 | function wpinv_mark_invoice_viewed() { |
2339 | 2339 | |
2340 | - if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) { |
|
2341 | - $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : ''; |
|
2340 | + if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) { |
|
2341 | + $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : ''; |
|
2342 | 2342 | global $post; |
2343 | 2343 | |
2344 | - if(!empty($invoice_key)){ |
|
2344 | + if (!empty($invoice_key)) { |
|
2345 | 2345 | $invoice_id = wpinv_get_invoice_id_by_key($invoice_key); |
2346 | - } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2346 | + } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) { |
|
2347 | 2347 | $invoice_id = $post->ID; |
2348 | 2348 | } else { |
2349 | 2349 | return; |
@@ -2351,63 +2351,63 @@ discard block |
||
2351 | 2351 | |
2352 | 2352 | $invoice = new WPInv_Invoice($invoice_id); |
2353 | 2353 | |
2354 | - if(!$invoice_id){ |
|
2354 | + if (!$invoice_id) { |
|
2355 | 2355 | return; |
2356 | 2356 | } |
2357 | 2357 | |
2358 | - if ( is_user_logged_in() ) { |
|
2359 | - if ( (int)$invoice->get_user_id() === get_current_user_id() ) { |
|
2360 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2361 | - } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2362 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2358 | + if (is_user_logged_in()) { |
|
2359 | + if ((int) $invoice->get_user_id() === get_current_user_id()) { |
|
2360 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2361 | + } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2362 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2363 | 2363 | } |
2364 | 2364 | } else { |
2365 | - if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) { |
|
2366 | - update_post_meta($invoice_id,'_wpinv_is_viewed', 1); |
|
2365 | + if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) { |
|
2366 | + update_post_meta($invoice_id, '_wpinv_is_viewed', 1); |
|
2367 | 2367 | } |
2368 | 2368 | } |
2369 | 2369 | } |
2370 | 2370 | |
2371 | 2371 | } |
2372 | -add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' ); |
|
2372 | +add_action('template_redirect', 'wpinv_mark_invoice_viewed'); |
|
2373 | 2373 | |
2374 | 2374 | /** |
2375 | 2375 | * @return WPInv_Subscription |
2376 | 2376 | */ |
2377 | -function wpinv_get_subscription( $invoice, $by_parent = false ) { |
|
2378 | - if ( empty( $invoice ) ) { |
|
2377 | +function wpinv_get_subscription($invoice, $by_parent = false) { |
|
2378 | + if (empty($invoice)) { |
|
2379 | 2379 | return false; |
2380 | 2380 | } |
2381 | 2381 | |
2382 | - if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) { |
|
2383 | - $invoice = wpinv_get_invoice( $invoice ); |
|
2382 | + if (!is_object($invoice) && is_scalar($invoice)) { |
|
2383 | + $invoice = wpinv_get_invoice($invoice); |
|
2384 | 2384 | } |
2385 | 2385 | |
2386 | - if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) { |
|
2386 | + if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) { |
|
2387 | 2387 | return false; |
2388 | 2388 | } |
2389 | 2389 | |
2390 | - $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID; |
|
2390 | + $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID; |
|
2391 | 2391 | |
2392 | 2392 | $subs_db = new WPInv_Subscriptions_DB; |
2393 | - $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) ); |
|
2393 | + $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1)); |
|
2394 | 2394 | |
2395 | - if ( ! empty( $subs ) ) { |
|
2396 | - return reset( $subs ); |
|
2395 | + if (!empty($subs)) { |
|
2396 | + return reset($subs); |
|
2397 | 2397 | } |
2398 | 2398 | |
2399 | 2399 | return false; |
2400 | 2400 | } |
2401 | 2401 | |
2402 | -function wpinv_filter_posts_clauses( $clauses, $wp_query ) { |
|
2402 | +function wpinv_filter_posts_clauses($clauses, $wp_query) { |
|
2403 | 2403 | global $wpdb; |
2404 | 2404 | |
2405 | - if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) { |
|
2406 | - if ( !empty( $clauses['join'] ) ) { |
|
2405 | + if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') { |
|
2406 | + if (!empty($clauses['join'])) { |
|
2407 | 2407 | $clauses['join'] .= " "; |
2408 | 2408 | } |
2409 | 2409 | |
2410 | - if ( !empty( $clauses['fields'] ) ) { |
|
2410 | + if (!empty($clauses['fields'])) { |
|
2411 | 2411 | $clauses['fields'] .= ", "; |
2412 | 2412 | } |
2413 | 2413 | |
@@ -2418,4 +2418,4 @@ discard block |
||
2418 | 2418 | |
2419 | 2419 | return $clauses; |
2420 | 2420 | } |
2421 | -add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 ); |
|
2422 | 2421 | \ No newline at end of file |
2422 | +add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2); |
|
2423 | 2423 | \ No newline at end of file |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,215 +15,215 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_max_uses', |
|
35 | - '_wpi_discount_is_recurring', |
|
36 | - '_wpi_discount_min_total', |
|
37 | - '_wpi_discount_max_total', |
|
38 | - ); |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_max_uses', |
|
35 | + '_wpi_discount_is_recurring', |
|
36 | + '_wpi_discount_min_total', |
|
37 | + '_wpi_discount_max_total', |
|
38 | + ); |
|
39 | 39 | |
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpi_discount_code' => 'code', |
|
49 | - '_wpi_discount_amount' => 'amount', |
|
50 | - '_wpi_discount_start' => 'start', |
|
51 | - '_wpi_discount_expiration' => 'expiration', |
|
52 | - '_wpi_discount_type' => 'type', |
|
53 | - '_wpi_discount_uses' => 'uses', |
|
54 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | - '_wpi_discount_items' => 'items', |
|
56 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | - '_wpi_discount_max_uses' => 'max_uses', |
|
58 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | - '_wpi_discount_min_total' => 'min_total', |
|
60 | - '_wpi_discount_max_total' => 'max_total', |
|
61 | - ); |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpi_discount_code' => 'code', |
|
49 | + '_wpi_discount_amount' => 'amount', |
|
50 | + '_wpi_discount_start' => 'start', |
|
51 | + '_wpi_discount_expiration' => 'expiration', |
|
52 | + '_wpi_discount_type' => 'type', |
|
53 | + '_wpi_discount_uses' => 'uses', |
|
54 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | + '_wpi_discount_items' => 'items', |
|
56 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | + '_wpi_discount_max_uses' => 'max_uses', |
|
58 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | + '_wpi_discount_min_total' => 'min_total', |
|
60 | + '_wpi_discount_max_total' => 'max_total', |
|
61 | + ); |
|
62 | 62 | |
63 | - /* |
|
63 | + /* |
|
64 | 64 | |-------------------------------------------------------------------------- |
65 | 65 | | CRUD Methods |
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | */ |
68 | - /** |
|
69 | - * Method to create a new invoice in the database. |
|
70 | - * |
|
71 | - * @param WPInv_Invoice $invoice Invoice object. |
|
72 | - */ |
|
73 | - public function create( &$invoice ) { |
|
74 | - $invoice->set_version( WPINV_VERSION ); |
|
75 | - $invoice->set_date_created( current_time('mysql') ); |
|
68 | + /** |
|
69 | + * Method to create a new invoice in the database. |
|
70 | + * |
|
71 | + * @param WPInv_Invoice $invoice Invoice object. |
|
72 | + */ |
|
73 | + public function create( &$invoice ) { |
|
74 | + $invoice->set_version( WPINV_VERSION ); |
|
75 | + $invoice->set_date_created( current_time('mysql') ); |
|
76 | 76 | |
77 | - // Create a new post. |
|
78 | - $id = wp_insert_post( |
|
79 | - apply_filters( |
|
80 | - 'getpaid_new_invoice_data', |
|
81 | - array( |
|
82 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
83 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
84 | - 'post_status' => $this->get_post_status( $invoice ), |
|
85 | - 'ping_status' => 'closed', |
|
86 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
87 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
88 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
89 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
90 | - ) |
|
91 | - ), |
|
92 | - true |
|
93 | - ); |
|
77 | + // Create a new post. |
|
78 | + $id = wp_insert_post( |
|
79 | + apply_filters( |
|
80 | + 'getpaid_new_invoice_data', |
|
81 | + array( |
|
82 | + 'post_date' => $invoice->get_date_created( 'edit' ), |
|
83 | + 'post_type' => $invoice->get_post_type( 'edit' ), |
|
84 | + 'post_status' => $this->get_post_status( $invoice ), |
|
85 | + 'ping_status' => 'closed', |
|
86 | + 'post_author' => $invoice->get_user_id( 'edit' ), |
|
87 | + 'post_title' => $invoice->get_number( 'edit' ), |
|
88 | + 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
89 | + 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
90 | + ) |
|
91 | + ), |
|
92 | + true |
|
93 | + ); |
|
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $invoice->set_id( $id ); |
|
97 | - $invoice->save_special(); |
|
98 | - $this->update_post_meta( $invoice ); |
|
99 | - $invoice->save_meta_data(); |
|
100 | - $invoice->apply_changes(); |
|
101 | - $this->clear_caches( $invoice ); |
|
102 | - return true; |
|
103 | - } |
|
95 | + if ( $id && ! is_wp_error( $id ) ) { |
|
96 | + $invoice->set_id( $id ); |
|
97 | + $invoice->save_special(); |
|
98 | + $this->update_post_meta( $invoice ); |
|
99 | + $invoice->save_meta_data(); |
|
100 | + $invoice->apply_changes(); |
|
101 | + $this->clear_caches( $invoice ); |
|
102 | + return true; |
|
103 | + } |
|
104 | 104 | |
105 | - if ( is_wp_error( $id ) ) { |
|
106 | - $invoice->last_error = $id->get_error_message(); |
|
107 | - } |
|
105 | + if ( is_wp_error( $id ) ) { |
|
106 | + $invoice->last_error = $id->get_error_message(); |
|
107 | + } |
|
108 | 108 | |
109 | - return false; |
|
110 | - } |
|
109 | + return false; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Method to save special invoice fields in the database. |
|
114 | - * |
|
115 | - * @param WPInv_Invoice $invoice Invoice object. |
|
116 | - */ |
|
117 | - public function save_special( &$invoice ) { |
|
118 | - $invoice->set_version( WPINV_VERSION ); |
|
119 | - $invoice->set_date_created( current_time('mysql') ); |
|
112 | + /** |
|
113 | + * Method to save special invoice fields in the database. |
|
114 | + * |
|
115 | + * @param WPInv_Invoice $invoice Invoice object. |
|
116 | + */ |
|
117 | + public function save_special( &$invoice ) { |
|
118 | + $invoice->set_version( WPINV_VERSION ); |
|
119 | + $invoice->set_date_created( current_time('mysql') ); |
|
120 | 120 | |
121 | 121 | |
122 | - if ( $id && ! is_wp_error( $id ) ) { |
|
123 | - $invoice->set_id( $id ); |
|
124 | - $invoice->save_special(); |
|
125 | - $this->update_post_meta( $invoice ); |
|
126 | - $invoice->save_meta_data(); |
|
127 | - $invoice->apply_changes(); |
|
128 | - $this->clear_caches( $invoice ); |
|
129 | - return true; |
|
130 | - } |
|
122 | + if ( $id && ! is_wp_error( $id ) ) { |
|
123 | + $invoice->set_id( $id ); |
|
124 | + $invoice->save_special(); |
|
125 | + $this->update_post_meta( $invoice ); |
|
126 | + $invoice->save_meta_data(); |
|
127 | + $invoice->apply_changes(); |
|
128 | + $this->clear_caches( $invoice ); |
|
129 | + return true; |
|
130 | + } |
|
131 | 131 | |
132 | - if ( is_wp_error( $id ) ) { |
|
133 | - $invoice->last_error = $id->get_error_message(); |
|
134 | - } |
|
132 | + if ( is_wp_error( $id ) ) { |
|
133 | + $invoice->last_error = $id->get_error_message(); |
|
134 | + } |
|
135 | 135 | |
136 | - return false; |
|
137 | - } |
|
136 | + return false; |
|
137 | + } |
|
138 | 138 | |
139 | - /** |
|
140 | - * Method to read an invoice from the database. |
|
141 | - * |
|
142 | - * @param WPInv_Invoice $invoice Invoice object. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function read( &$invoice ) { |
|
139 | + /** |
|
140 | + * Method to read an invoice from the database. |
|
141 | + * |
|
142 | + * @param WPInv_Invoice $invoice Invoice object. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function read( &$invoice ) { |
|
146 | 146 | |
147 | - $invoice->set_defaults(); |
|
148 | - $invoice_object = get_post( $invoice->get_id() ); |
|
147 | + $invoice->set_defaults(); |
|
148 | + $invoice_object = get_post( $invoice->get_id() ); |
|
149 | 149 | |
150 | - if ( ! $invoice->get_id() || ! $invoice_object || $invoice_object->post_type != 'wpi_invoice' ) { |
|
151 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
152 | - return false; |
|
153 | - } |
|
150 | + if ( ! $invoice->get_id() || ! $invoice_object || $invoice_object->post_type != 'wpi_invoice' ) { |
|
151 | + $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
152 | + return false; |
|
153 | + } |
|
154 | 154 | |
155 | - $invoice->set_props( |
|
156 | - array( |
|
157 | - 'date_created' => 0 < $discount_object->post_date_gmt ? $discount_object->post_date_gmt : null, |
|
158 | - 'date_modified' => 0 < $discount_object->post_modified_gmt ? $discount_object->post_modified_gmt : null, |
|
159 | - 'status' => $discount_object->post_status, |
|
160 | - 'author' => $discount_object->post_author, |
|
161 | - 'description' => $discount_object->post_excerpt, |
|
162 | - ) |
|
163 | - ); |
|
155 | + $invoice->set_props( |
|
156 | + array( |
|
157 | + 'date_created' => 0 < $discount_object->post_date_gmt ? $discount_object->post_date_gmt : null, |
|
158 | + 'date_modified' => 0 < $discount_object->post_modified_gmt ? $discount_object->post_modified_gmt : null, |
|
159 | + 'status' => $discount_object->post_status, |
|
160 | + 'author' => $discount_object->post_author, |
|
161 | + 'description' => $discount_object->post_excerpt, |
|
162 | + ) |
|
163 | + ); |
|
164 | 164 | |
165 | - $this->read_object_data( $discount, $discount_object ); |
|
166 | - $discount->read_meta_data(); |
|
167 | - $discount->set_object_read( true ); |
|
165 | + $this->read_object_data( $discount, $discount_object ); |
|
166 | + $discount->read_meta_data(); |
|
167 | + $discount->set_object_read( true ); |
|
168 | 168 | |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Method to update a discount in the database. |
|
173 | - * |
|
174 | - * @param WPInv_Discount $discount Discount object. |
|
175 | - */ |
|
176 | - public function update( &$discount ) { |
|
177 | - $discount->save_meta_data(); |
|
178 | - $discount->set_version( WPINV_VERSION ); |
|
171 | + /** |
|
172 | + * Method to update a discount in the database. |
|
173 | + * |
|
174 | + * @param WPInv_Discount $discount Discount object. |
|
175 | + */ |
|
176 | + public function update( &$discount ) { |
|
177 | + $discount->save_meta_data(); |
|
178 | + $discount->set_version( WPINV_VERSION ); |
|
179 | 179 | |
180 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
181 | - $discount->set_date_created( current_time('mysql') ); |
|
182 | - } |
|
180 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
181 | + $discount->set_date_created( current_time('mysql') ); |
|
182 | + } |
|
183 | 183 | |
184 | - $changes = $discount->get_changes(); |
|
184 | + $changes = $discount->get_changes(); |
|
185 | 185 | |
186 | - // Only update the post when the post data changes. |
|
187 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
188 | - $post_data = array( |
|
189 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
190 | - 'post_status' => $discount->get_status( 'edit' ), |
|
191 | - 'post_title' => $discount->get_name( 'edit' ), |
|
192 | - 'post_author' => $discount->get_author( 'edit' ), |
|
193 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
194 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
195 | - ); |
|
186 | + // Only update the post when the post data changes. |
|
187 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
188 | + $post_data = array( |
|
189 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
190 | + 'post_status' => $discount->get_status( 'edit' ), |
|
191 | + 'post_title' => $discount->get_name( 'edit' ), |
|
192 | + 'post_author' => $discount->get_author( 'edit' ), |
|
193 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
194 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
195 | + ); |
|
196 | 196 | |
197 | - /** |
|
198 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
199 | - * to update data, since wp_update_post spawns more calls to the |
|
200 | - * save_post action. |
|
201 | - * |
|
202 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
203 | - * or an update purely from CRUD. |
|
204 | - */ |
|
205 | - if ( doing_action( 'save_post' ) ) { |
|
206 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
207 | - clean_post_cache( $discount->get_id() ); |
|
208 | - } else { |
|
209 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
210 | - } |
|
211 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
212 | - } |
|
213 | - $this->update_post_meta( $discount ); |
|
214 | - $discount->apply_changes(); |
|
215 | - $this->clear_caches( $discount ); |
|
216 | - } |
|
197 | + /** |
|
198 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
199 | + * to update data, since wp_update_post spawns more calls to the |
|
200 | + * save_post action. |
|
201 | + * |
|
202 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
203 | + * or an update purely from CRUD. |
|
204 | + */ |
|
205 | + if ( doing_action( 'save_post' ) ) { |
|
206 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
207 | + clean_post_cache( $discount->get_id() ); |
|
208 | + } else { |
|
209 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
210 | + } |
|
211 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
212 | + } |
|
213 | + $this->update_post_meta( $discount ); |
|
214 | + $discount->apply_changes(); |
|
215 | + $this->clear_caches( $discount ); |
|
216 | + } |
|
217 | 217 | |
218 | - /* |
|
218 | + /* |
|
219 | 219 | |-------------------------------------------------------------------------- |
220 | 220 | | Additional Methods |
221 | 221 | |-------------------------------------------------------------------------- |
222 | 222 | */ |
223 | - /** |
|
223 | + /** |
|
224 | 224 | * Returns a list of all special fields. |
225 | - * |
|
226 | - * @param WPInv_Invoice $invoice Invoice object. |
|
225 | + * |
|
226 | + * @param WPInv_Invoice $invoice Invoice object. |
|
227 | 227 | */ |
228 | 228 | public function get_special_fields( $invoice ) { |
229 | 229 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Invoice_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -70,39 +70,39 @@ discard block |
||
70 | 70 | * |
71 | 71 | * @param WPInv_Invoice $invoice Invoice object. |
72 | 72 | */ |
73 | - public function create( &$invoice ) { |
|
74 | - $invoice->set_version( WPINV_VERSION ); |
|
75 | - $invoice->set_date_created( current_time('mysql') ); |
|
73 | + public function create(&$invoice) { |
|
74 | + $invoice->set_version(WPINV_VERSION); |
|
75 | + $invoice->set_date_created(current_time('mysql')); |
|
76 | 76 | |
77 | 77 | // Create a new post. |
78 | 78 | $id = wp_insert_post( |
79 | 79 | apply_filters( |
80 | 80 | 'getpaid_new_invoice_data', |
81 | 81 | array( |
82 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
83 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
84 | - 'post_status' => $this->get_post_status( $invoice ), |
|
82 | + 'post_date' => $invoice->get_date_created('edit'), |
|
83 | + 'post_type' => $invoice->get_post_type('edit'), |
|
84 | + 'post_status' => $this->get_post_status($invoice), |
|
85 | 85 | 'ping_status' => 'closed', |
86 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
87 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
88 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
89 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
86 | + 'post_author' => $invoice->get_user_id('edit'), |
|
87 | + 'post_title' => $invoice->get_number('edit'), |
|
88 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
89 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $invoice->set_id( $id ); |
|
95 | + if ($id && !is_wp_error($id)) { |
|
96 | + $invoice->set_id($id); |
|
97 | 97 | $invoice->save_special(); |
98 | - $this->update_post_meta( $invoice ); |
|
98 | + $this->update_post_meta($invoice); |
|
99 | 99 | $invoice->save_meta_data(); |
100 | 100 | $invoice->apply_changes(); |
101 | - $this->clear_caches( $invoice ); |
|
101 | + $this->clear_caches($invoice); |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_wp_error( $id ) ) { |
|
105 | + if (is_wp_error($id)) { |
|
106 | 106 | $invoice->last_error = $id->get_error_message(); |
107 | 107 | } |
108 | 108 | |
@@ -114,22 +114,22 @@ discard block |
||
114 | 114 | * |
115 | 115 | * @param WPInv_Invoice $invoice Invoice object. |
116 | 116 | */ |
117 | - public function save_special( &$invoice ) { |
|
118 | - $invoice->set_version( WPINV_VERSION ); |
|
119 | - $invoice->set_date_created( current_time('mysql') ); |
|
117 | + public function save_special(&$invoice) { |
|
118 | + $invoice->set_version(WPINV_VERSION); |
|
119 | + $invoice->set_date_created(current_time('mysql')); |
|
120 | 120 | |
121 | 121 | |
122 | - if ( $id && ! is_wp_error( $id ) ) { |
|
123 | - $invoice->set_id( $id ); |
|
122 | + if ($id && !is_wp_error($id)) { |
|
123 | + $invoice->set_id($id); |
|
124 | 124 | $invoice->save_special(); |
125 | - $this->update_post_meta( $invoice ); |
|
125 | + $this->update_post_meta($invoice); |
|
126 | 126 | $invoice->save_meta_data(); |
127 | 127 | $invoice->apply_changes(); |
128 | - $this->clear_caches( $invoice ); |
|
128 | + $this->clear_caches($invoice); |
|
129 | 129 | return true; |
130 | 130 | } |
131 | 131 | |
132 | - if ( is_wp_error( $id ) ) { |
|
132 | + if (is_wp_error($id)) { |
|
133 | 133 | $invoice->last_error = $id->get_error_message(); |
134 | 134 | } |
135 | 135 | |
@@ -142,13 +142,13 @@ discard block |
||
142 | 142 | * @param WPInv_Invoice $invoice Invoice object. |
143 | 143 | * |
144 | 144 | */ |
145 | - public function read( &$invoice ) { |
|
145 | + public function read(&$invoice) { |
|
146 | 146 | |
147 | 147 | $invoice->set_defaults(); |
148 | - $invoice_object = get_post( $invoice->get_id() ); |
|
148 | + $invoice_object = get_post($invoice->get_id()); |
|
149 | 149 | |
150 | - if ( ! $invoice->get_id() || ! $invoice_object || $invoice_object->post_type != 'wpi_invoice' ) { |
|
151 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
150 | + if (!$invoice->get_id() || !$invoice_object || $invoice_object->post_type != 'wpi_invoice') { |
|
151 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | ) |
163 | 163 | ); |
164 | 164 | |
165 | - $this->read_object_data( $discount, $discount_object ); |
|
165 | + $this->read_object_data($discount, $discount_object); |
|
166 | 166 | $discount->read_meta_data(); |
167 | - $discount->set_object_read( true ); |
|
167 | + $discount->set_object_read(true); |
|
168 | 168 | |
169 | 169 | } |
170 | 170 | |
@@ -173,25 +173,25 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param WPInv_Discount $discount Discount object. |
175 | 175 | */ |
176 | - public function update( &$discount ) { |
|
176 | + public function update(&$discount) { |
|
177 | 177 | $discount->save_meta_data(); |
178 | - $discount->set_version( WPINV_VERSION ); |
|
178 | + $discount->set_version(WPINV_VERSION); |
|
179 | 179 | |
180 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
181 | - $discount->set_date_created( current_time('mysql') ); |
|
180 | + if (null === $discount->get_date_created('edit')) { |
|
181 | + $discount->set_date_created(current_time('mysql')); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | $changes = $discount->get_changes(); |
185 | 185 | |
186 | 186 | // Only update the post when the post data changes. |
187 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
187 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) { |
|
188 | 188 | $post_data = array( |
189 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
190 | - 'post_status' => $discount->get_status( 'edit' ), |
|
191 | - 'post_title' => $discount->get_name( 'edit' ), |
|
192 | - 'post_author' => $discount->get_author( 'edit' ), |
|
193 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
194 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
189 | + 'post_date' => $discount->get_date_created('edit'), |
|
190 | + 'post_status' => $discount->get_status('edit'), |
|
191 | + 'post_title' => $discount->get_name('edit'), |
|
192 | + 'post_author' => $discount->get_author('edit'), |
|
193 | + 'post_modified' => $discount->get_date_modified('edit'), |
|
194 | + 'post_excerpt' => $discount->get_description('edit'), |
|
195 | 195 | ); |
196 | 196 | |
197 | 197 | /** |
@@ -202,17 +202,17 @@ discard block |
||
202 | 202 | * This ensures hooks are fired by either WP itself (admin screen save), |
203 | 203 | * or an update purely from CRUD. |
204 | 204 | */ |
205 | - if ( doing_action( 'save_post' ) ) { |
|
206 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
207 | - clean_post_cache( $discount->get_id() ); |
|
205 | + if (doing_action('save_post')) { |
|
206 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id())); |
|
207 | + clean_post_cache($discount->get_id()); |
|
208 | 208 | } else { |
209 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
209 | + wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data)); |
|
210 | 210 | } |
211 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
211 | + $discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
212 | 212 | } |
213 | - $this->update_post_meta( $discount ); |
|
213 | + $this->update_post_meta($discount); |
|
214 | 214 | $discount->apply_changes(); |
215 | - $this->clear_caches( $discount ); |
|
215 | + $this->clear_caches($discount); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | /* |
@@ -225,13 +225,13 @@ discard block |
||
225 | 225 | * |
226 | 226 | * @param WPInv_Invoice $invoice Invoice object. |
227 | 227 | */ |
228 | - public function get_special_fields( $invoice ) { |
|
228 | + public function get_special_fields($invoice) { |
|
229 | 229 | |
230 | - return array ( |
|
230 | + return array( |
|
231 | 231 | 'post_id' => $invoice->get_id(), |
232 | 232 | 'number' => $invoice->get_number(), |
233 | 233 | 'key' => $invoice->get_key(), |
234 | - 'type' => str_replace( 'wpi_', '', $invoice->get_post_type() ), |
|
234 | + 'type' => str_replace('wpi_', '', $invoice->get_post_type()), |
|
235 | 235 | 'mode' => $invoice->get_mode(), |
236 | 236 | 'user_ip' => $invoice->get_user_ip(), |
237 | 237 | 'first_name' => $invoice->get_first_name(), |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | if ( ! defined( 'ABSPATH' ) ) { |
8 | - exit; |
|
8 | + exit; |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -15,180 +15,180 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class GetPaid_Discount_Data_Store extends GetPaid_Data_Store_WP { |
17 | 17 | |
18 | - /** |
|
19 | - * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | - * |
|
21 | - * @since 1.0.19 |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - protected $internal_meta_keys = array( |
|
25 | - '_wpi_discount_code', |
|
26 | - '_wpi_discount_amount', |
|
27 | - '_wpi_discount_start', |
|
28 | - '_wpi_discount_expiration', |
|
29 | - '_wpi_discount_type', |
|
30 | - '_wpi_discount_uses', |
|
31 | - '_wpi_discount_is_single_use', |
|
32 | - '_wpi_discount_items', |
|
33 | - '_wpi_discount_excluded_items', |
|
34 | - '_wpi_discount_max_uses', |
|
35 | - '_wpi_discount_is_recurring', |
|
36 | - '_wpi_discount_min_total', |
|
37 | - '_wpi_discount_max_total', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * A map of meta keys to data props. |
|
42 | - * |
|
43 | - * @since 1.0.19 |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $meta_key_to_props = array( |
|
48 | - '_wpi_discount_code' => 'code', |
|
49 | - '_wpi_discount_amount' => 'amount', |
|
50 | - '_wpi_discount_start' => 'start', |
|
51 | - '_wpi_discount_expiration' => 'expiration', |
|
52 | - '_wpi_discount_type' => 'type', |
|
53 | - '_wpi_discount_uses' => 'uses', |
|
54 | - '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | - '_wpi_discount_items' => 'items', |
|
56 | - '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | - '_wpi_discount_max_uses' => 'max_uses', |
|
58 | - '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | - '_wpi_discount_min_total' => 'min_total', |
|
60 | - '_wpi_discount_max_total' => 'max_total', |
|
61 | - ); |
|
62 | - |
|
63 | - /* |
|
18 | + /** |
|
19 | + * Data stored in meta keys, but not considered "meta" for a discount. |
|
20 | + * |
|
21 | + * @since 1.0.19 |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + protected $internal_meta_keys = array( |
|
25 | + '_wpi_discount_code', |
|
26 | + '_wpi_discount_amount', |
|
27 | + '_wpi_discount_start', |
|
28 | + '_wpi_discount_expiration', |
|
29 | + '_wpi_discount_type', |
|
30 | + '_wpi_discount_uses', |
|
31 | + '_wpi_discount_is_single_use', |
|
32 | + '_wpi_discount_items', |
|
33 | + '_wpi_discount_excluded_items', |
|
34 | + '_wpi_discount_max_uses', |
|
35 | + '_wpi_discount_is_recurring', |
|
36 | + '_wpi_discount_min_total', |
|
37 | + '_wpi_discount_max_total', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * A map of meta keys to data props. |
|
42 | + * |
|
43 | + * @since 1.0.19 |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $meta_key_to_props = array( |
|
48 | + '_wpi_discount_code' => 'code', |
|
49 | + '_wpi_discount_amount' => 'amount', |
|
50 | + '_wpi_discount_start' => 'start', |
|
51 | + '_wpi_discount_expiration' => 'expiration', |
|
52 | + '_wpi_discount_type' => 'type', |
|
53 | + '_wpi_discount_uses' => 'uses', |
|
54 | + '_wpi_discount_is_single_use' => 'is_single_use', |
|
55 | + '_wpi_discount_items' => 'items', |
|
56 | + '_wpi_discount_excluded_items' => 'excluded_items', |
|
57 | + '_wpi_discount_max_uses' => 'max_uses', |
|
58 | + '_wpi_discount_is_recurring' => 'is_recurring', |
|
59 | + '_wpi_discount_min_total' => 'min_total', |
|
60 | + '_wpi_discount_max_total' => 'max_total', |
|
61 | + ); |
|
62 | + |
|
63 | + /* |
|
64 | 64 | |-------------------------------------------------------------------------- |
65 | 65 | | CRUD Methods |
66 | 66 | |-------------------------------------------------------------------------- |
67 | 67 | */ |
68 | 68 | |
69 | - /** |
|
70 | - * Method to create a new discount in the database. |
|
71 | - * |
|
72 | - * @param WPInv_Discount $discount Discount object. |
|
73 | - */ |
|
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
77 | - |
|
78 | - // Create a new post. |
|
79 | - $id = wp_insert_post( |
|
80 | - apply_filters( |
|
81 | - 'getpaid_new_discount_data', |
|
82 | - array( |
|
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | - 'post_type' => 'wpi_discount', |
|
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
86 | - 'ping_status' => 'closed', |
|
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | - ) |
|
91 | - ), |
|
92 | - true |
|
93 | - ); |
|
94 | - |
|
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
98 | - $discount->save_meta_data(); |
|
99 | - $discount->apply_changes(); |
|
100 | - $this->clear_caches( $discount ); |
|
101 | - return true; |
|
102 | - } |
|
103 | - |
|
104 | - if ( is_wp_error( $id ) ) { |
|
105 | - $discount->last_error = $id->get_error_message(); |
|
106 | - } |
|
107 | - |
|
108 | - return false; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Method to read a discount from the database. |
|
113 | - * |
|
114 | - * @param WPInv_Discount $discount Discount object. |
|
115 | - * |
|
116 | - */ |
|
117 | - public function read( &$discount ) { |
|
118 | - |
|
119 | - $discount->set_defaults(); |
|
120 | - $discount_object = get_post( $discount->get_id() ); |
|
121 | - |
|
122 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
123 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
124 | - return false; |
|
125 | - } |
|
126 | - |
|
127 | - $discount->set_props( |
|
128 | - array( |
|
129 | - 'date_created' => 0 < $discount_object->post_date_gmt ? $discount_object->post_date_gmt : null, |
|
130 | - 'date_modified' => 0 < $discount_object->post_modified_gmt ? $discount_object->post_modified_gmt : null, |
|
131 | - 'status' => $discount_object->post_status, |
|
132 | - 'name' => $discount_object->post_title, |
|
133 | - 'author' => $discount_object->post_author, |
|
134 | - 'description' => $discount_object->post_excerpt, |
|
135 | - ) |
|
136 | - ); |
|
137 | - |
|
138 | - $this->read_object_data( $discount, $discount_object ); |
|
139 | - $discount->read_meta_data(); |
|
140 | - $discount->set_object_read( true ); |
|
141 | - |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Method to update a discount in the database. |
|
146 | - * |
|
147 | - * @param WPInv_Discount $discount Discount object. |
|
148 | - */ |
|
149 | - public function update( &$discount ) { |
|
150 | - $discount->save_meta_data(); |
|
151 | - $discount->set_version( WPINV_VERSION ); |
|
152 | - |
|
153 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
154 | - $discount->set_date_created( current_time('mysql') ); |
|
155 | - } |
|
156 | - |
|
157 | - $changes = $discount->get_changes(); |
|
158 | - |
|
159 | - // Only update the post when the post data changes. |
|
160 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
161 | - $post_data = array( |
|
162 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
163 | - 'post_status' => $discount->get_status( 'edit' ), |
|
164 | - 'post_title' => $discount->get_name( 'edit' ), |
|
165 | - 'post_author' => $discount->get_author( 'edit' ), |
|
166 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
167 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
168 | - ); |
|
169 | - |
|
170 | - /** |
|
171 | - * When updating this object, to prevent infinite loops, use $wpdb |
|
172 | - * to update data, since wp_update_post spawns more calls to the |
|
173 | - * save_post action. |
|
174 | - * |
|
175 | - * This ensures hooks are fired by either WP itself (admin screen save), |
|
176 | - * or an update purely from CRUD. |
|
177 | - */ |
|
178 | - if ( doing_action( 'save_post' ) ) { |
|
179 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
180 | - clean_post_cache( $discount->get_id() ); |
|
181 | - } else { |
|
182 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
183 | - } |
|
184 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
185 | - } |
|
186 | - $this->update_post_meta( $discount ); |
|
187 | - $discount->apply_changes(); |
|
188 | - $this->clear_caches( $discount ); |
|
189 | - } |
|
190 | - |
|
191 | - /* |
|
69 | + /** |
|
70 | + * Method to create a new discount in the database. |
|
71 | + * |
|
72 | + * @param WPInv_Discount $discount Discount object. |
|
73 | + */ |
|
74 | + public function create( &$discount ) { |
|
75 | + $discount->set_version( WPINV_VERSION ); |
|
76 | + $discount->set_date_created( current_time('mysql') ); |
|
77 | + |
|
78 | + // Create a new post. |
|
79 | + $id = wp_insert_post( |
|
80 | + apply_filters( |
|
81 | + 'getpaid_new_discount_data', |
|
82 | + array( |
|
83 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
84 | + 'post_type' => 'wpi_discount', |
|
85 | + 'post_status' => $this->get_post_status( $discount ), |
|
86 | + 'ping_status' => 'closed', |
|
87 | + 'post_author' => $discount->get_author( 'edit' ), |
|
88 | + 'post_title' => $discount->get_name( 'edit' ), |
|
89 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
90 | + ) |
|
91 | + ), |
|
92 | + true |
|
93 | + ); |
|
94 | + |
|
95 | + if ( $id && ! is_wp_error( $id ) ) { |
|
96 | + $discount->set_id( $id ); |
|
97 | + $this->update_post_meta( $discount ); |
|
98 | + $discount->save_meta_data(); |
|
99 | + $discount->apply_changes(); |
|
100 | + $this->clear_caches( $discount ); |
|
101 | + return true; |
|
102 | + } |
|
103 | + |
|
104 | + if ( is_wp_error( $id ) ) { |
|
105 | + $discount->last_error = $id->get_error_message(); |
|
106 | + } |
|
107 | + |
|
108 | + return false; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Method to read a discount from the database. |
|
113 | + * |
|
114 | + * @param WPInv_Discount $discount Discount object. |
|
115 | + * |
|
116 | + */ |
|
117 | + public function read( &$discount ) { |
|
118 | + |
|
119 | + $discount->set_defaults(); |
|
120 | + $discount_object = get_post( $discount->get_id() ); |
|
121 | + |
|
122 | + if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
123 | + $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
124 | + return false; |
|
125 | + } |
|
126 | + |
|
127 | + $discount->set_props( |
|
128 | + array( |
|
129 | + 'date_created' => 0 < $discount_object->post_date_gmt ? $discount_object->post_date_gmt : null, |
|
130 | + 'date_modified' => 0 < $discount_object->post_modified_gmt ? $discount_object->post_modified_gmt : null, |
|
131 | + 'status' => $discount_object->post_status, |
|
132 | + 'name' => $discount_object->post_title, |
|
133 | + 'author' => $discount_object->post_author, |
|
134 | + 'description' => $discount_object->post_excerpt, |
|
135 | + ) |
|
136 | + ); |
|
137 | + |
|
138 | + $this->read_object_data( $discount, $discount_object ); |
|
139 | + $discount->read_meta_data(); |
|
140 | + $discount->set_object_read( true ); |
|
141 | + |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Method to update a discount in the database. |
|
146 | + * |
|
147 | + * @param WPInv_Discount $discount Discount object. |
|
148 | + */ |
|
149 | + public function update( &$discount ) { |
|
150 | + $discount->save_meta_data(); |
|
151 | + $discount->set_version( WPINV_VERSION ); |
|
152 | + |
|
153 | + if ( null === $discount->get_date_created( 'edit' ) ) { |
|
154 | + $discount->set_date_created( current_time('mysql') ); |
|
155 | + } |
|
156 | + |
|
157 | + $changes = $discount->get_changes(); |
|
158 | + |
|
159 | + // Only update the post when the post data changes. |
|
160 | + if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
161 | + $post_data = array( |
|
162 | + 'post_date' => $discount->get_date_created( 'edit' ), |
|
163 | + 'post_status' => $discount->get_status( 'edit' ), |
|
164 | + 'post_title' => $discount->get_name( 'edit' ), |
|
165 | + 'post_author' => $discount->get_author( 'edit' ), |
|
166 | + 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
167 | + 'post_excerpt' => $discount->get_description( 'edit' ), |
|
168 | + ); |
|
169 | + |
|
170 | + /** |
|
171 | + * When updating this object, to prevent infinite loops, use $wpdb |
|
172 | + * to update data, since wp_update_post spawns more calls to the |
|
173 | + * save_post action. |
|
174 | + * |
|
175 | + * This ensures hooks are fired by either WP itself (admin screen save), |
|
176 | + * or an update purely from CRUD. |
|
177 | + */ |
|
178 | + if ( doing_action( 'save_post' ) ) { |
|
179 | + $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
180 | + clean_post_cache( $discount->get_id() ); |
|
181 | + } else { |
|
182 | + wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
183 | + } |
|
184 | + $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
185 | + } |
|
186 | + $this->update_post_meta( $discount ); |
|
187 | + $discount->apply_changes(); |
|
188 | + $this->clear_caches( $discount ); |
|
189 | + } |
|
190 | + |
|
191 | + /* |
|
192 | 192 | |-------------------------------------------------------------------------- |
193 | 193 | | Additional Methods |
194 | 194 | |-------------------------------------------------------------------------- |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Discount_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -71,37 +71,37 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Discount $discount Discount object. |
73 | 73 | */ |
74 | - public function create( &$discount ) { |
|
75 | - $discount->set_version( WPINV_VERSION ); |
|
76 | - $discount->set_date_created( current_time('mysql') ); |
|
74 | + public function create(&$discount) { |
|
75 | + $discount->set_version(WPINV_VERSION); |
|
76 | + $discount->set_date_created(current_time('mysql')); |
|
77 | 77 | |
78 | 78 | // Create a new post. |
79 | 79 | $id = wp_insert_post( |
80 | 80 | apply_filters( |
81 | 81 | 'getpaid_new_discount_data', |
82 | 82 | array( |
83 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
83 | + 'post_date' => $discount->get_date_created('edit'), |
|
84 | 84 | 'post_type' => 'wpi_discount', |
85 | - 'post_status' => $this->get_post_status( $discount ), |
|
85 | + 'post_status' => $this->get_post_status($discount), |
|
86 | 86 | 'ping_status' => 'closed', |
87 | - 'post_author' => $discount->get_author( 'edit' ), |
|
88 | - 'post_title' => $discount->get_name( 'edit' ), |
|
89 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
87 | + 'post_author' => $discount->get_author('edit'), |
|
88 | + 'post_title' => $discount->get_name('edit'), |
|
89 | + 'post_excerpt' => $discount->get_description('edit'), |
|
90 | 90 | ) |
91 | 91 | ), |
92 | 92 | true |
93 | 93 | ); |
94 | 94 | |
95 | - if ( $id && ! is_wp_error( $id ) ) { |
|
96 | - $discount->set_id( $id ); |
|
97 | - $this->update_post_meta( $discount ); |
|
95 | + if ($id && !is_wp_error($id)) { |
|
96 | + $discount->set_id($id); |
|
97 | + $this->update_post_meta($discount); |
|
98 | 98 | $discount->save_meta_data(); |
99 | 99 | $discount->apply_changes(); |
100 | - $this->clear_caches( $discount ); |
|
100 | + $this->clear_caches($discount); |
|
101 | 101 | return true; |
102 | 102 | } |
103 | 103 | |
104 | - if ( is_wp_error( $id ) ) { |
|
104 | + if (is_wp_error($id)) { |
|
105 | 105 | $discount->last_error = $id->get_error_message(); |
106 | 106 | } |
107 | 107 | |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | * @param WPInv_Discount $discount Discount object. |
115 | 115 | * |
116 | 116 | */ |
117 | - public function read( &$discount ) { |
|
117 | + public function read(&$discount) { |
|
118 | 118 | |
119 | 119 | $discount->set_defaults(); |
120 | - $discount_object = get_post( $discount->get_id() ); |
|
120 | + $discount_object = get_post($discount->get_id()); |
|
121 | 121 | |
122 | - if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) { |
|
123 | - $discount->last_error = __( 'Invalid discount.', 'invoicing' ); |
|
122 | + if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') { |
|
123 | + $discount->last_error = __('Invalid discount.', 'invoicing'); |
|
124 | 124 | return false; |
125 | 125 | } |
126 | 126 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | ) |
136 | 136 | ); |
137 | 137 | |
138 | - $this->read_object_data( $discount, $discount_object ); |
|
138 | + $this->read_object_data($discount, $discount_object); |
|
139 | 139 | $discount->read_meta_data(); |
140 | - $discount->set_object_read( true ); |
|
140 | + $discount->set_object_read(true); |
|
141 | 141 | |
142 | 142 | } |
143 | 143 | |
@@ -146,25 +146,25 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param WPInv_Discount $discount Discount object. |
148 | 148 | */ |
149 | - public function update( &$discount ) { |
|
149 | + public function update(&$discount) { |
|
150 | 150 | $discount->save_meta_data(); |
151 | - $discount->set_version( WPINV_VERSION ); |
|
151 | + $discount->set_version(WPINV_VERSION); |
|
152 | 152 | |
153 | - if ( null === $discount->get_date_created( 'edit' ) ) { |
|
154 | - $discount->set_date_created( current_time('mysql') ); |
|
153 | + if (null === $discount->get_date_created('edit')) { |
|
154 | + $discount->set_date_created(current_time('mysql')); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | $changes = $discount->get_changes(); |
158 | 158 | |
159 | 159 | // Only update the post when the post data changes. |
160 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) { |
|
160 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) { |
|
161 | 161 | $post_data = array( |
162 | - 'post_date' => $discount->get_date_created( 'edit' ), |
|
163 | - 'post_status' => $discount->get_status( 'edit' ), |
|
164 | - 'post_title' => $discount->get_name( 'edit' ), |
|
165 | - 'post_author' => $discount->get_author( 'edit' ), |
|
166 | - 'post_modified' => $discount->get_date_modified( 'edit' ), |
|
167 | - 'post_excerpt' => $discount->get_description( 'edit' ), |
|
162 | + 'post_date' => $discount->get_date_created('edit'), |
|
163 | + 'post_status' => $discount->get_status('edit'), |
|
164 | + 'post_title' => $discount->get_name('edit'), |
|
165 | + 'post_author' => $discount->get_author('edit'), |
|
166 | + 'post_modified' => $discount->get_date_modified('edit'), |
|
167 | + 'post_excerpt' => $discount->get_description('edit'), |
|
168 | 168 | ); |
169 | 169 | |
170 | 170 | /** |
@@ -175,17 +175,17 @@ discard block |
||
175 | 175 | * This ensures hooks are fired by either WP itself (admin screen save), |
176 | 176 | * or an update purely from CRUD. |
177 | 177 | */ |
178 | - if ( doing_action( 'save_post' ) ) { |
|
179 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) ); |
|
180 | - clean_post_cache( $discount->get_id() ); |
|
178 | + if (doing_action('save_post')) { |
|
179 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id())); |
|
180 | + clean_post_cache($discount->get_id()); |
|
181 | 181 | } else { |
182 | - wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) ); |
|
182 | + wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data)); |
|
183 | 183 | } |
184 | - $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
184 | + $discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
185 | 185 | } |
186 | - $this->update_post_meta( $discount ); |
|
186 | + $this->update_post_meta($discount); |
|
187 | 187 | $discount->apply_changes(); |
188 | - $this->clear_caches( $discount ); |
|
188 | + $this->clear_caches($discount); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /* |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | class WPInv_Plugin { |
15 | 15 | private static $instance; |
16 | 16 | |
17 | 17 | public static function run() { |
18 | - if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) { |
|
18 | + if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) { |
|
19 | 19 | self::$instance = new WPInv_Plugin; |
20 | 20 | self::$instance->includes(); |
21 | 21 | self::$instance->actions(); |
@@ -33,35 +33,35 @@ discard block |
||
33 | 33 | } |
34 | 34 | |
35 | 35 | public function define_constants() { |
36 | - define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) ); |
|
37 | - define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) ); |
|
36 | + define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE)); |
|
37 | + define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE)); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | private function actions() { |
41 | 41 | /* Internationalize the text strings used. */ |
42 | - add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) ); |
|
42 | + add_action('plugins_loaded', array(&$this, 'plugins_loaded')); |
|
43 | 43 | |
44 | 44 | /* Perform actions on admin initialization. */ |
45 | - add_action( 'admin_init', array( &$this, 'admin_init') ); |
|
46 | - add_action( 'init', array( &$this, 'init' ), 3 ); |
|
47 | - add_action( 'init', array( &$this, 'wpinv_actions' ) ); |
|
45 | + add_action('admin_init', array(&$this, 'admin_init')); |
|
46 | + add_action('init', array(&$this, 'init'), 3); |
|
47 | + add_action('init', array(&$this, 'wpinv_actions')); |
|
48 | 48 | |
49 | - if ( class_exists( 'BuddyPress' ) ) { |
|
50 | - add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) ); |
|
49 | + if (class_exists('BuddyPress')) { |
|
50 | + add_action('bp_include', array(&$this, 'bp_invoicing_init')); |
|
51 | 51 | } |
52 | 52 | |
53 | - add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) ); |
|
54 | - add_action( 'wp_footer', array( &$this, 'wp_footer' ) ); |
|
55 | - add_action( 'widgets_init', array( &$this, 'register_widgets' ) ); |
|
56 | - add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) ); |
|
53 | + add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts')); |
|
54 | + add_action('wp_footer', array(&$this, 'wp_footer')); |
|
55 | + add_action('widgets_init', array(&$this, 'register_widgets')); |
|
56 | + add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids')); |
|
57 | 57 | |
58 | - if ( is_admin() ) { |
|
59 | - add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); |
|
60 | - add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) ); |
|
61 | - add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) ); |
|
58 | + if (is_admin()) { |
|
59 | + add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts')); |
|
60 | + add_filter('admin_body_class', array(&$this, 'admin_body_class')); |
|
61 | + add_action('admin_init', array(&$this, 'init_ayecode_connect_helper')); |
|
62 | 62 | |
63 | 63 | } else { |
64 | - add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) ); |
|
64 | + add_filter('pre_get_posts', array(&$this, 'pre_get_posts')); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | /** |
@@ -71,28 +71,28 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference. |
73 | 73 | */ |
74 | - do_action_ref_array( 'wpinv_actions', array( &$this ) ); |
|
74 | + do_action_ref_array('wpinv_actions', array(&$this)); |
|
75 | 75 | |
76 | - add_action( 'admin_init', array( &$this, 'activation_redirect') ); |
|
76 | + add_action('admin_init', array(&$this, 'activation_redirect')); |
|
77 | 77 | } |
78 | 78 | |
79 | 79 | /** |
80 | 80 | * Maybe show the AyeCode Connect Notice. |
81 | 81 | */ |
82 | - public function init_ayecode_connect_helper(){ |
|
82 | + public function init_ayecode_connect_helper() { |
|
83 | 83 | // AyeCode Connect notice |
84 | - if ( is_admin() ){ |
|
84 | + if (is_admin()) { |
|
85 | 85 | // set the strings so they can be translated |
86 | 86 | $strings = array( |
87 | - 'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"), |
|
88 | - 'connect_external' => __( "Please confirm you wish to connect your site?","invoicing" ), |
|
89 | - 'connect' => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ), |
|
90 | - 'connect_button' => __("Connect Site","invoicing"), |
|
91 | - 'connecting_button' => __("Connecting...","invoicing"), |
|
92 | - 'error_localhost' => __( "This service will only work with a live domain, not a localhost.","invoicing" ), |
|
93 | - 'error' => __( "Something went wrong, please refresh and try again.","invoicing" ), |
|
87 | + 'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"), |
|
88 | + 'connect_external' => __("Please confirm you wish to connect your site?", "invoicing"), |
|
89 | + 'connect' => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"), |
|
90 | + 'connect_button' => __("Connect Site", "invoicing"), |
|
91 | + 'connecting_button' => __("Connecting...", "invoicing"), |
|
92 | + 'error_localhost' => __("This service will only work with a live domain, not a localhost.", "invoicing"), |
|
93 | + 'error' => __("Something went wrong, please refresh and try again.", "invoicing"), |
|
94 | 94 | ); |
95 | - new AyeCode_Connect_Helper($strings,array('wpi-addons')); |
|
95 | + new AyeCode_Connect_Helper($strings, array('wpi-addons')); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | /* Internationalize the text strings used. */ |
101 | 101 | $this->load_textdomain(); |
102 | 102 | |
103 | - do_action( 'wpinv_loaded' ); |
|
103 | + do_action('wpinv_loaded'); |
|
104 | 104 | |
105 | 105 | // Fix oxygen page builder conflict |
106 | - if ( function_exists( 'ct_css_output' ) ) { |
|
106 | + if (function_exists('ct_css_output')) { |
|
107 | 107 | wpinv_oxygen_fix_conflict(); |
108 | 108 | } |
109 | 109 | } |
@@ -113,144 +113,144 @@ discard block |
||
113 | 113 | * |
114 | 114 | * @since 1.0 |
115 | 115 | */ |
116 | - public function load_textdomain( $locale = NULL ) { |
|
117 | - if ( empty( $locale ) ) { |
|
118 | - $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale(); |
|
116 | + public function load_textdomain($locale = NULL) { |
|
117 | + if (empty($locale)) { |
|
118 | + $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale(); |
|
119 | 119 | } |
120 | 120 | |
121 | - $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' ); |
|
121 | + $locale = apply_filters('plugin_locale', $locale, 'invoicing'); |
|
122 | 122 | |
123 | - unload_textdomain( 'invoicing' ); |
|
124 | - load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' ); |
|
125 | - load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' ); |
|
123 | + unload_textdomain('invoicing'); |
|
124 | + load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo'); |
|
125 | + load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages'); |
|
126 | 126 | |
127 | 127 | /** |
128 | 128 | * Define language constants. |
129 | 129 | */ |
130 | - require_once( WPINV_PLUGIN_DIR . 'language.php' ); |
|
130 | + require_once(WPINV_PLUGIN_DIR . 'language.php'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | public function includes() { |
134 | 134 | global $wpinv_options; |
135 | 135 | |
136 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' ); |
|
136 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php'); |
|
137 | 137 | $wpinv_options = wpinv_get_settings(); |
138 | 138 | |
139 | 139 | // Load composer packages. |
140 | - require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' ); |
|
140 | + require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php'); |
|
141 | 141 | |
142 | 142 | // load AUI |
143 | - require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' ); |
|
143 | + require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php'); |
|
144 | 144 | |
145 | 145 | // Load the action scheduler. |
146 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' ); |
|
146 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php'); |
|
147 | 147 | |
148 | 148 | // Load functions. |
149 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' ); |
|
150 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' ); |
|
151 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' ); |
|
152 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' ); |
|
153 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' ); |
|
154 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' ); |
|
155 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' ); |
|
156 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' ); |
|
157 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' ); |
|
158 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' ); |
|
159 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' ); |
|
160 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' ); |
|
161 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' ); |
|
149 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php'); |
|
150 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php'); |
|
151 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php'); |
|
152 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php'); |
|
153 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php'); |
|
154 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php'); |
|
155 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php'); |
|
156 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php'); |
|
157 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php'); |
|
158 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php'); |
|
159 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php'); |
|
160 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php'); |
|
161 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php'); |
|
162 | 162 | |
163 | 163 | // Register autoloader. |
164 | 164 | try { |
165 | - spl_autoload_register( array( $this, 'autoload' ), true ); |
|
166 | - } catch ( Exception $e ) { |
|
167 | - wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true ); |
|
168 | - } |
|
169 | - |
|
170 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' ); |
|
171 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' ); |
|
172 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' ); |
|
173 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' ); |
|
174 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' ); |
|
175 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' ); |
|
176 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' ); |
|
177 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' ); |
|
178 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' ); |
|
179 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' ); |
|
180 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' ); |
|
181 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' ); |
|
182 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
|
183 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' ); |
|
184 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' ); |
|
185 | - require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' ); |
|
186 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' ); |
|
187 | - require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' ); |
|
188 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' ); |
|
189 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' ); |
|
190 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' ); |
|
191 | - require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' ); |
|
192 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' ); |
|
193 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' ); |
|
194 | - require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' ); |
|
195 | - require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' ); |
|
196 | - require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' ); |
|
197 | - require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' ); |
|
198 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' ); |
|
199 | - |
|
200 | - if ( !class_exists( 'WPInv_EUVat' ) ) { |
|
201 | - require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' ); |
|
165 | + spl_autoload_register(array($this, 'autoload'), true); |
|
166 | + } catch (Exception $e) { |
|
167 | + wpinv_error_log($e->getMessage(), '', __FILE__, 149, true); |
|
168 | + } |
|
169 | + |
|
170 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php'); |
|
171 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php'); |
|
172 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php'); |
|
173 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php'); |
|
174 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php'); |
|
175 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php'); |
|
176 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php'); |
|
177 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php'); |
|
178 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php'); |
|
179 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php'); |
|
180 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php'); |
|
181 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php'); |
|
182 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php'); |
|
183 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php'); |
|
184 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php'); |
|
185 | + require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php'); |
|
186 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php'); |
|
187 | + require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php'); |
|
188 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php'); |
|
189 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php'); |
|
190 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php'); |
|
191 | + require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php'); |
|
192 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php'); |
|
193 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php'); |
|
194 | + require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php'); |
|
195 | + require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php'); |
|
196 | + require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php'); |
|
197 | + require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php'); |
|
198 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php'); |
|
199 | + |
|
200 | + if (!class_exists('WPInv_EUVat')) { |
|
201 | + require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php'); |
|
202 | 202 | } |
203 | 203 | |
204 | - $gateways = array_keys( wpinv_get_enabled_payment_gateways() ); |
|
205 | - if ( !empty( $gateways ) ) { |
|
206 | - foreach ( $gateways as $gateway ) { |
|
207 | - if ( $gateway == 'manual' ) { |
|
204 | + $gateways = array_keys(wpinv_get_enabled_payment_gateways()); |
|
205 | + if (!empty($gateways)) { |
|
206 | + foreach ($gateways as $gateway) { |
|
207 | + if ($gateway == 'manual') { |
|
208 | 208 | continue; |
209 | 209 | } |
210 | 210 | |
211 | 211 | $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php'; |
212 | 212 | |
213 | - if ( file_exists( $gateway_file ) ) { |
|
214 | - require_once( $gateway_file ); |
|
213 | + if (file_exists($gateway_file)) { |
|
214 | + require_once($gateway_file); |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | } |
218 | - require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' ); |
|
218 | + require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php'); |
|
219 | 219 | |
220 | - if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { |
|
221 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' ); |
|
222 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' ); |
|
223 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' ); |
|
220 | + if (is_admin() || (defined('WP_CLI') && WP_CLI)) { |
|
221 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php'); |
|
222 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php'); |
|
223 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php'); |
|
224 | 224 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' ); |
225 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' ); |
|
226 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' ); |
|
227 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' ); |
|
228 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' ); |
|
229 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' ); |
|
230 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' ); |
|
231 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' ); |
|
232 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' ); |
|
233 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' ); |
|
225 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php'); |
|
226 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php'); |
|
227 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php'); |
|
228 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php'); |
|
229 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php'); |
|
230 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php'); |
|
231 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php'); |
|
232 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php'); |
|
233 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php'); |
|
234 | 234 | //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' ); |
235 | 235 | // load the user class only on the users.php page |
236 | 236 | global $pagenow; |
237 | - if($pagenow=='users.php'){ |
|
237 | + if ($pagenow == 'users.php') { |
|
238 | 238 | new WPInv_Admin_Users(); |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | 242 | // Register cli commands |
243 | - if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
244 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' ); |
|
245 | - WP_CLI::add_command( 'invoicing', 'WPInv_CLI' ); |
|
243 | + if (defined('WP_CLI') && WP_CLI) { |
|
244 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php'); |
|
245 | + WP_CLI::add_command('invoicing', 'WPInv_CLI'); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | // include css inliner |
249 | - if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) { |
|
250 | - include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' ); |
|
249 | + if (!class_exists('Emogrifier') && class_exists('DOMDocument')) { |
|
250 | + include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php'); |
|
251 | 251 | } |
252 | 252 | |
253 | - require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' ); |
|
253 | + require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php'); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | /** |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | * @since 1.0.19 |
262 | 262 | * @return void |
263 | 263 | */ |
264 | - public function autoload( $class_name ) { |
|
264 | + public function autoload($class_name) { |
|
265 | 265 | |
266 | 266 | // Normalize the class name... |
267 | - $class_name = strtolower( $class_name ); |
|
267 | + $class_name = strtolower($class_name); |
|
268 | 268 | |
269 | 269 | // ... and make sure it is our class. |
270 | - if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) { |
|
270 | + if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) { |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // Next, prepare the file name from the class. |
275 | - $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php'; |
|
275 | + $file_name = 'class-' . str_replace('_', '-', $class_name) . '.php'; |
|
276 | 276 | |
277 | 277 | // And an array of possible locations in order of importance. |
278 | 278 | $locations = array( |
@@ -283,11 +283,11 @@ discard block |
||
283 | 283 | ); |
284 | 284 | |
285 | 285 | // Base path of the classes. |
286 | - $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR ); |
|
286 | + $plugin_path = untrailingslashit(WPINV_PLUGIN_DIR); |
|
287 | 287 | |
288 | - foreach ( $locations as $location ) { |
|
288 | + foreach ($locations as $location) { |
|
289 | 289 | |
290 | - if ( file_exists( "$plugin_path/$location/$file_name" ) ) { |
|
290 | + if (file_exists("$plugin_path/$location/$file_name")) { |
|
291 | 291 | include "$plugin_path/$location/$file_name"; |
292 | 292 | break; |
293 | 293 | } |
@@ -301,117 +301,117 @@ discard block |
||
301 | 301 | |
302 | 302 | public function admin_init() { |
303 | 303 | self::$instance->default_payment_form = wpinv_get_default_payment_form(); |
304 | - add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) ); |
|
304 | + add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php')); |
|
305 | 305 | } |
306 | 306 | |
307 | 307 | public function activation_redirect() { |
308 | 308 | // Bail if no activation redirect |
309 | - if ( !get_transient( '_wpinv_activation_redirect' ) ) { |
|
309 | + if (!get_transient('_wpinv_activation_redirect')) { |
|
310 | 310 | return; |
311 | 311 | } |
312 | 312 | |
313 | 313 | // Delete the redirect transient |
314 | - delete_transient( '_wpinv_activation_redirect' ); |
|
314 | + delete_transient('_wpinv_activation_redirect'); |
|
315 | 315 | |
316 | 316 | // Bail if activating from network, or bulk |
317 | - if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) { |
|
317 | + if (is_network_admin() || isset($_GET['activate-multi'])) { |
|
318 | 318 | return; |
319 | 319 | } |
320 | 320 | |
321 | - wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) ); |
|
321 | + wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general')); |
|
322 | 322 | exit; |
323 | 323 | } |
324 | 324 | |
325 | 325 | public function enqueue_scripts() { |
326 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
326 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
327 | 327 | |
328 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' ); |
|
329 | - wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version ); |
|
330 | - wp_enqueue_style( 'wpinv_front_style' ); |
|
328 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css'); |
|
329 | + wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version); |
|
330 | + wp_enqueue_style('wpinv_front_style'); |
|
331 | 331 | |
332 | 332 | // Register scripts |
333 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
334 | - 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' ) ); |
|
333 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
334 | + 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')); |
|
335 | 335 | |
336 | 336 | $localize = array(); |
337 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
338 | - $localize['nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
337 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
338 | + $localize['nonce'] = wp_create_nonce('wpinv-nonce'); |
|
339 | 339 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
340 | 340 | $localize['currency_pos'] = wpinv_currency_position(); |
341 | 341 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
342 | 342 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
343 | 343 | $localize['decimals'] = wpinv_decimals(); |
344 | - $localize['txtComplete'] = __( 'Continue', 'invoicing' ); |
|
344 | + $localize['txtComplete'] = __('Continue', 'invoicing'); |
|
345 | 345 | $localize['UseTaxes'] = wpinv_use_taxes(); |
346 | - $localize['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' ); |
|
347 | - $localize['formNonce'] = wp_create_nonce( 'getpaid_form_nonce' ); |
|
348 | - $localize['connectionError'] = __( 'Could not establish a connection to the server.', 'invoicing' ); |
|
346 | + $localize['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce'); |
|
347 | + $localize['formNonce'] = wp_create_nonce('getpaid_form_nonce'); |
|
348 | + $localize['connectionError'] = __('Could not establish a connection to the server.', 'invoicing'); |
|
349 | 349 | |
350 | - $localize = apply_filters( 'wpinv_front_js_localize', $localize ); |
|
350 | + $localize = apply_filters('wpinv_front_js_localize', $localize); |
|
351 | 351 | |
352 | - wp_enqueue_script( 'jquery-blockui' ); |
|
352 | + wp_enqueue_script('jquery-blockui'); |
|
353 | 353 | $autofill_api = wpinv_get_option('address_autofill_api'); |
354 | 354 | $autofill_active = wpinv_get_option('address_autofill_active'); |
355 | - if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) { |
|
356 | - if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) { |
|
357 | - wp_dequeue_script( 'google-maps-api' ); |
|
355 | + if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) { |
|
356 | + if (wp_script_is('google-maps-api', 'enqueued')) { |
|
357 | + wp_dequeue_script('google-maps-api'); |
|
358 | 358 | } |
359 | - wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false ); |
|
360 | - wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true ); |
|
359 | + wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false); |
|
360 | + wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true); |
|
361 | 361 | } |
362 | 362 | |
363 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
364 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
363 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
364 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
365 | 365 | |
366 | - wp_enqueue_script( 'wpinv-front-script' ); |
|
367 | - wp_localize_script( 'wpinv-front-script', 'WPInv', $localize ); |
|
366 | + wp_enqueue_script('wpinv-front-script'); |
|
367 | + wp_localize_script('wpinv-front-script', 'WPInv', $localize); |
|
368 | 368 | |
369 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' ); |
|
370 | - wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ), $version, true ); |
|
369 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js'); |
|
370 | + wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true); |
|
371 | 371 | } |
372 | 372 | |
373 | - public function admin_enqueue_scripts( $hook ) { |
|
373 | + public function admin_enqueue_scripts($hook) { |
|
374 | 374 | global $post, $pagenow; |
375 | 375 | |
376 | 376 | $post_type = wpinv_admin_post_type(); |
377 | - $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; |
|
378 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : ''; |
|
377 | + $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min'; |
|
378 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : ''; |
|
379 | 379 | |
380 | 380 | $jquery_ui_css = false; |
381 | - if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) { |
|
381 | + if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
|
382 | 382 | $jquery_ui_css = true; |
383 | - } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) { |
|
383 | + } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') { |
|
384 | 384 | $jquery_ui_css = true; |
385 | 385 | } |
386 | - if ( $jquery_ui_css ) { |
|
387 | - wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' ); |
|
388 | - wp_enqueue_style( 'jquery-ui-css' ); |
|
389 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
390 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
386 | + if ($jquery_ui_css) { |
|
387 | + wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16'); |
|
388 | + wp_enqueue_style('jquery-ui-css'); |
|
389 | + wp_deregister_style('yoast-seo-select2'); |
|
390 | + wp_deregister_style('yoast-seo-monorepo'); |
|
391 | 391 | } |
392 | 392 | |
393 | - wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION ); |
|
394 | - wp_enqueue_style( 'wpinv_meta_box_style' ); |
|
393 | + wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION); |
|
394 | + wp_enqueue_style('wpinv_meta_box_style'); |
|
395 | 395 | |
396 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' ); |
|
397 | - wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version ); |
|
398 | - wp_enqueue_style( 'wpinv_admin_style' ); |
|
396 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css'); |
|
397 | + wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version); |
|
398 | + wp_enqueue_style('wpinv_admin_style'); |
|
399 | 399 | |
400 | - $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ); |
|
401 | - if ( $page == 'wpinv-subscriptions' ) { |
|
402 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
403 | - wp_deregister_style( 'yoast-seo-select2' ); |
|
404 | - wp_deregister_style( 'yoast-seo-monorepo' ); |
|
400 | + $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')); |
|
401 | + if ($page == 'wpinv-subscriptions') { |
|
402 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
403 | + wp_deregister_style('yoast-seo-select2'); |
|
404 | + wp_deregister_style('yoast-seo-monorepo'); |
|
405 | 405 | } |
406 | 406 | |
407 | - if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) { |
|
408 | - wp_enqueue_script( 'jquery-ui-datepicker' ); |
|
407 | + if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) { |
|
408 | + wp_enqueue_script('jquery-ui-datepicker'); |
|
409 | 409 | } |
410 | 410 | |
411 | - wp_enqueue_style( 'wp-color-picker' ); |
|
412 | - wp_enqueue_script( 'wp-color-picker' ); |
|
411 | + wp_enqueue_style('wp-color-picker'); |
|
412 | + wp_enqueue_script('wp-color-picker'); |
|
413 | 413 | |
414 | - wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true ); |
|
414 | + wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true); |
|
415 | 415 | |
416 | 416 | if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) { |
417 | 417 | $autofill_api = wpinv_get_option('address_autofill_api'); |
@@ -422,21 +422,21 @@ discard block |
||
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
425 | - wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' ); |
|
426 | - wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION ); |
|
425 | + wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all'); |
|
426 | + wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION); |
|
427 | 427 | |
428 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' ); |
|
429 | - wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ), $version ); |
|
430 | - wp_enqueue_script( 'wpinv-admin-script' ); |
|
428 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js'); |
|
429 | + wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version); |
|
430 | + wp_enqueue_script('wpinv-admin-script'); |
|
431 | 431 | |
432 | 432 | $localize = array(); |
433 | - $localize['ajax_url'] = admin_url( 'admin-ajax.php' ); |
|
434 | - $localize['post_ID'] = isset( $post->ID ) ? $post->ID : ''; |
|
435 | - $localize['wpinv_nonce'] = wp_create_nonce( 'wpinv-nonce' ); |
|
436 | - $localize['add_invoice_note_nonce'] = wp_create_nonce( 'add-invoice-note' ); |
|
437 | - $localize['delete_invoice_note_nonce'] = wp_create_nonce( 'delete-invoice-note' ); |
|
438 | - $localize['invoice_item_nonce'] = wp_create_nonce( 'invoice-item' ); |
|
439 | - $localize['billing_details_nonce'] = wp_create_nonce( 'get-billing-details' ); |
|
433 | + $localize['ajax_url'] = admin_url('admin-ajax.php'); |
|
434 | + $localize['post_ID'] = isset($post->ID) ? $post->ID : ''; |
|
435 | + $localize['wpinv_nonce'] = wp_create_nonce('wpinv-nonce'); |
|
436 | + $localize['add_invoice_note_nonce'] = wp_create_nonce('add-invoice-note'); |
|
437 | + $localize['delete_invoice_note_nonce'] = wp_create_nonce('delete-invoice-note'); |
|
438 | + $localize['invoice_item_nonce'] = wp_create_nonce('invoice-item'); |
|
439 | + $localize['billing_details_nonce'] = wp_create_nonce('get-billing-details'); |
|
440 | 440 | $localize['tax'] = wpinv_tax_amount(); |
441 | 441 | $localize['discount'] = wpinv_discount_amount(); |
442 | 442 | $localize['currency_symbol'] = wpinv_currency_symbol(); |
@@ -444,103 +444,103 @@ discard block |
||
444 | 444 | $localize['thousand_sep'] = wpinv_thousands_separator(); |
445 | 445 | $localize['decimal_sep'] = wpinv_decimal_separator(); |
446 | 446 | $localize['decimals'] = wpinv_decimals(); |
447 | - $localize['save_invoice'] = __( 'Save Invoice', 'invoicing' ); |
|
448 | - $localize['status_publish'] = wpinv_status_nicename( 'publish' ); |
|
449 | - $localize['status_pending'] = wpinv_status_nicename( 'wpi-pending' ); |
|
450 | - $localize['delete_tax_rate'] = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' ); |
|
451 | - $localize['OneItemMin'] = __( 'Invoice must contain at least one item', 'invoicing' ); |
|
452 | - $localize['DeleteInvoiceItem'] = __( 'Are you sure you wish to delete this item?', 'invoicing' ); |
|
453 | - $localize['FillBillingDetails'] = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' ); |
|
454 | - $localize['confirmCalcTotals'] = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' ); |
|
455 | - $localize['AreYouSure'] = __( 'Are you sure?', 'invoicing' ); |
|
456 | - $localize['emptyInvoice'] = __( 'Add at least one item to save invoice!', 'invoicing' ); |
|
457 | - $localize['errDeleteItem'] = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' ); |
|
458 | - $localize['delete_subscription'] = __( 'Are you sure you want to delete this subscription?', 'invoicing' ); |
|
459 | - $localize['action_edit'] = __( 'Edit', 'invoicing' ); |
|
460 | - $localize['action_cancel'] = __( 'Cancel', 'invoicing' ); |
|
461 | - $localize['item_description'] = __( 'Item Description', 'invoicing' ); |
|
462 | - $localize['discount_description'] = __( 'Discount Description', 'invoicing' ); |
|
463 | - $localize['invoice_description'] = __( 'Invoice Description', 'invoicing' ); |
|
464 | - |
|
465 | - $localize = apply_filters( 'wpinv_admin_js_localize', $localize ); |
|
466 | - |
|
467 | - wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize ); |
|
447 | + $localize['save_invoice'] = __('Save Invoice', 'invoicing'); |
|
448 | + $localize['status_publish'] = wpinv_status_nicename('publish'); |
|
449 | + $localize['status_pending'] = wpinv_status_nicename('wpi-pending'); |
|
450 | + $localize['delete_tax_rate'] = __('Are you sure you wish to delete this tax rate?', 'invoicing'); |
|
451 | + $localize['OneItemMin'] = __('Invoice must contain at least one item', 'invoicing'); |
|
452 | + $localize['DeleteInvoiceItem'] = __('Are you sure you wish to delete this item?', 'invoicing'); |
|
453 | + $localize['FillBillingDetails'] = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing'); |
|
454 | + $localize['confirmCalcTotals'] = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing'); |
|
455 | + $localize['AreYouSure'] = __('Are you sure?', 'invoicing'); |
|
456 | + $localize['emptyInvoice'] = __('Add at least one item to save invoice!', 'invoicing'); |
|
457 | + $localize['errDeleteItem'] = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing'); |
|
458 | + $localize['delete_subscription'] = __('Are you sure you want to delete this subscription?', 'invoicing'); |
|
459 | + $localize['action_edit'] = __('Edit', 'invoicing'); |
|
460 | + $localize['action_cancel'] = __('Cancel', 'invoicing'); |
|
461 | + $localize['item_description'] = __('Item Description', 'invoicing'); |
|
462 | + $localize['discount_description'] = __('Discount Description', 'invoicing'); |
|
463 | + $localize['invoice_description'] = __('Invoice Description', 'invoicing'); |
|
464 | + |
|
465 | + $localize = apply_filters('wpinv_admin_js_localize', $localize); |
|
466 | + |
|
467 | + wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize); |
|
468 | 468 | |
469 | 469 | // Load payment form scripts on our admin pages only. |
470 | - if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) { |
|
470 | + if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) { |
|
471 | 471 | |
472 | - wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION ); |
|
473 | - wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION ); |
|
474 | - wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION ); |
|
472 | + wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION); |
|
473 | + wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION); |
|
474 | + wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION); |
|
475 | 475 | |
476 | - $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' ); |
|
477 | - wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ), $version ); |
|
476 | + $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js'); |
|
477 | + wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version); |
|
478 | 478 | |
479 | - wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
479 | + wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array( |
|
480 | 480 | 'elements' => $this->form_elements->get_elements(), |
481 | - 'form_elements' => $this->form_elements->get_form_elements( $post->ID ), |
|
481 | + 'form_elements' => $this->form_elements->get_form_elements($post->ID), |
|
482 | 482 | 'all_items' => $this->form_elements->get_published_items(), |
483 | 483 | 'currency' => wpinv_currency_symbol(), |
484 | 484 | 'position' => wpinv_currency_position(), |
485 | 485 | 'decimals' => (int) wpinv_decimals(), |
486 | 486 | 'thousands_sep' => wpinv_thousands_separator(), |
487 | 487 | 'decimals_sep' => wpinv_decimal_separator(), |
488 | - 'form_items' => $this->form_elements->get_form_items( $post->ID ), |
|
488 | + 'form_items' => $this->form_elements->get_form_items($post->ID), |
|
489 | 489 | 'is_default' => $post->ID == $this->default_payment_form, |
490 | - ) ); |
|
490 | + )); |
|
491 | 491 | |
492 | - wp_enqueue_script( 'wpinv-admin-payment-form-script' ); |
|
492 | + wp_enqueue_script('wpinv-admin-payment-form-script'); |
|
493 | 493 | } |
494 | 494 | |
495 | - if ( $page == 'wpinv-subscriptions' ) { |
|
496 | - wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ), WPINV_VERSION ); |
|
497 | - wp_enqueue_script( 'wpinv-sub-admin-script' ); |
|
495 | + if ($page == 'wpinv-subscriptions') { |
|
496 | + wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION); |
|
497 | + wp_enqueue_script('wpinv-sub-admin-script'); |
|
498 | 498 | } |
499 | 499 | |
500 | - if ( $page == 'wpinv-reports' ) { |
|
501 | - wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' ); |
|
500 | + if ($page == 'wpinv-reports') { |
|
501 | + wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7'); |
|
502 | 502 | } |
503 | 503 | |
504 | 504 | } |
505 | 505 | |
506 | - public function admin_body_class( $classes ) { |
|
506 | + public function admin_body_class($classes) { |
|
507 | 507 | global $pagenow, $post, $current_screen; |
508 | 508 | |
509 | - if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) { |
|
509 | + if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) { |
|
510 | 510 | $classes .= ' wpinv-cpt'; |
511 | 511 | } |
512 | 512 | |
513 | - $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false; |
|
513 | + $page = isset($_GET['page']) ? strtolower($_GET['page']) : false; |
|
514 | 514 | |
515 | - $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false; |
|
516 | - if ( $add_class ) { |
|
517 | - $classes .= ' wpi-' . wpinv_sanitize_key( $page ); |
|
515 | + $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false; |
|
516 | + if ($add_class) { |
|
517 | + $classes .= ' wpi-' . wpinv_sanitize_key($page); |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | $settings_class = array(); |
521 | - if ( $page == 'wpinv-settings' ) { |
|
522 | - if ( !empty( $_REQUEST['tab'] ) ) { |
|
523 | - $settings_class[] = sanitize_text_field( $_REQUEST['tab'] ); |
|
521 | + if ($page == 'wpinv-settings') { |
|
522 | + if (!empty($_REQUEST['tab'])) { |
|
523 | + $settings_class[] = sanitize_text_field($_REQUEST['tab']); |
|
524 | 524 | } |
525 | 525 | |
526 | - if ( !empty( $_REQUEST['section'] ) ) { |
|
527 | - $settings_class[] = sanitize_text_field( $_REQUEST['section'] ); |
|
526 | + if (!empty($_REQUEST['section'])) { |
|
527 | + $settings_class[] = sanitize_text_field($_REQUEST['section']); |
|
528 | 528 | } |
529 | 529 | |
530 | - $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main'; |
|
530 | + $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main'; |
|
531 | 531 | } |
532 | 532 | |
533 | - if ( !empty( $settings_class ) ) { |
|
534 | - $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) ); |
|
533 | + if (!empty($settings_class)) { |
|
534 | + $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-')); |
|
535 | 535 | } |
536 | 536 | |
537 | 537 | $post_type = wpinv_admin_post_type(); |
538 | 538 | |
539 | - if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) { |
|
539 | + if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) { |
|
540 | 540 | return $classes .= ' wpinv'; |
541 | 541 | } |
542 | 542 | |
543 | - if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) { |
|
543 | + if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) { |
|
544 | 544 | $classes .= ' wpi-editable-n'; |
545 | 545 | } |
546 | 546 | |
@@ -552,21 +552,21 @@ discard block |
||
552 | 552 | } |
553 | 553 | |
554 | 554 | public function wpinv_actions() { |
555 | - if ( isset( $_REQUEST['wpi_action'] ) ) { |
|
556 | - do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST ); |
|
555 | + if (isset($_REQUEST['wpi_action'])) { |
|
556 | + do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST); |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
560 | - public function pre_get_posts( $wp_query ) { |
|
561 | - if ( !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() ) { |
|
562 | - $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() ); |
|
560 | + public function pre_get_posts($wp_query) { |
|
561 | + if (!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()) { |
|
562 | + $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses()); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | return $wp_query; |
566 | 566 | } |
567 | 567 | |
568 | 568 | public function bp_invoicing_init() { |
569 | - require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' ); |
|
569 | + require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php'); |
|
570 | 570 | } |
571 | 571 | |
572 | 572 | /** |
@@ -574,13 +574,13 @@ discard block |
||
574 | 574 | * |
575 | 575 | */ |
576 | 576 | public function register_widgets() { |
577 | - register_widget( "WPInv_Checkout_Widget" ); |
|
578 | - register_widget( "WPInv_History_Widget" ); |
|
579 | - register_widget( "WPInv_Receipt_Widget" ); |
|
580 | - register_widget( "WPInv_Subscriptions_Widget" ); |
|
581 | - register_widget( "WPInv_Buy_Item_Widget" ); |
|
582 | - register_widget( "WPInv_Messages_Widget" ); |
|
583 | - register_widget( 'WPInv_GetPaid_Widget' ); |
|
577 | + register_widget("WPInv_Checkout_Widget"); |
|
578 | + register_widget("WPInv_History_Widget"); |
|
579 | + register_widget("WPInv_Receipt_Widget"); |
|
580 | + register_widget("WPInv_Subscriptions_Widget"); |
|
581 | + register_widget("WPInv_Buy_Item_Widget"); |
|
582 | + register_widget("WPInv_Messages_Widget"); |
|
583 | + register_widget('WPInv_GetPaid_Widget'); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -589,10 +589,10 @@ discard block |
||
589 | 589 | * @since 1.0.19 |
590 | 590 | * @param int[] $excluded_posts_ids |
591 | 591 | */ |
592 | - public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){ |
|
592 | + public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) { |
|
593 | 593 | |
594 | 594 | // Ensure that we have an array. |
595 | - if ( ! is_array( $excluded_posts_ids ) ) { |
|
595 | + if (!is_array($excluded_posts_ids)) { |
|
596 | 596 | $excluded_posts_ids = array(); |
597 | 597 | } |
598 | 598 | |
@@ -600,24 +600,24 @@ discard block |
||
600 | 600 | $our_pages = array(); |
601 | 601 | |
602 | 602 | // Checkout page. |
603 | - $our_pages[] = wpinv_get_option( 'checkout_page', false ); |
|
603 | + $our_pages[] = wpinv_get_option('checkout_page', false); |
|
604 | 604 | |
605 | 605 | // Success page. |
606 | - $our_pages[] = wpinv_get_option( 'success_page', false ); |
|
606 | + $our_pages[] = wpinv_get_option('success_page', false); |
|
607 | 607 | |
608 | 608 | // Failure page. |
609 | - $our_pages[] = wpinv_get_option( 'failure_page', false ); |
|
609 | + $our_pages[] = wpinv_get_option('failure_page', false); |
|
610 | 610 | |
611 | 611 | // History page. |
612 | - $our_pages[] = wpinv_get_option( 'invoice_history_page', false ); |
|
612 | + $our_pages[] = wpinv_get_option('invoice_history_page', false); |
|
613 | 613 | |
614 | 614 | // Subscriptions page. |
615 | - $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false ); |
|
615 | + $our_pages[] = wpinv_get_option('invoice_subscription_page', false); |
|
616 | 616 | |
617 | - $our_pages = array_map( 'intval', array_filter( $our_pages ) ); |
|
617 | + $our_pages = array_map('intval', array_filter($our_pages)); |
|
618 | 618 | |
619 | 619 | $excluded_posts_ids = $excluded_posts_ids + $our_pages; |
620 | - return array_unique( $excluded_posts_ids ); |
|
620 | + return array_unique($excluded_posts_ids); |
|
621 | 621 | |
622 | 622 | } |
623 | 623 |