@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * GetPaid REST CRUD controller class. |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @see register_rest_route() |
40 | 40 | */ |
41 | - public function register_namespace_routes( $namespace ) { |
|
41 | + public function register_namespace_routes($namespace) { |
|
42 | 42 | |
43 | 43 | register_rest_route( |
44 | 44 | $namespace, |
@@ -46,22 +46,22 @@ discard block |
||
46 | 46 | array( |
47 | 47 | array( |
48 | 48 | 'methods' => WP_REST_Server::READABLE, |
49 | - 'callback' => array( $this, 'get_items' ), |
|
50 | - 'permission_callback' => array( $this, 'get_items_permissions_check' ), |
|
49 | + 'callback' => array($this, 'get_items'), |
|
50 | + 'permission_callback' => array($this, 'get_items_permissions_check'), |
|
51 | 51 | 'args' => $this->get_collection_params(), |
52 | 52 | ), |
53 | 53 | array( |
54 | 54 | 'methods' => WP_REST_Server::CREATABLE, |
55 | - 'callback' => array( $this, 'create_item' ), |
|
56 | - 'permission_callback' => array( $this, 'create_item_permissions_check' ), |
|
57 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::CREATABLE ), |
|
55 | + 'callback' => array($this, 'create_item'), |
|
56 | + 'permission_callback' => array($this, 'create_item_permissions_check'), |
|
57 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), |
|
58 | 58 | ), |
59 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
59 | + 'schema' => array($this, 'get_public_item_schema'), |
|
60 | 60 | ) |
61 | 61 | ); |
62 | 62 | |
63 | 63 | $get_item_args = array( |
64 | - 'context' => $this->get_context_param( array( 'default' => 'view' ) ), |
|
64 | + 'context' => $this->get_context_param(array('default' => 'view')), |
|
65 | 65 | ); |
66 | 66 | |
67 | 67 | register_rest_route( |
@@ -70,35 +70,35 @@ discard block |
||
70 | 70 | array( |
71 | 71 | 'args' => array( |
72 | 72 | 'id' => array( |
73 | - 'description' => __( 'Unique identifier for the object.', 'invoicing' ), |
|
73 | + 'description' => __('Unique identifier for the object.', 'invoicing'), |
|
74 | 74 | 'type' => 'integer', |
75 | 75 | ), |
76 | 76 | ), |
77 | 77 | array( |
78 | 78 | 'methods' => WP_REST_Server::READABLE, |
79 | - 'callback' => array( $this, 'get_item' ), |
|
80 | - 'permission_callback' => array( $this, 'get_item_permissions_check' ), |
|
79 | + 'callback' => array($this, 'get_item'), |
|
80 | + 'permission_callback' => array($this, 'get_item_permissions_check'), |
|
81 | 81 | 'args' => $get_item_args, |
82 | 82 | ), |
83 | 83 | array( |
84 | 84 | 'methods' => WP_REST_Server::EDITABLE, |
85 | - 'callback' => array( $this, 'update_item' ), |
|
86 | - 'permission_callback' => array( $this, 'update_item_permissions_check' ), |
|
87 | - 'args' => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ), |
|
85 | + 'callback' => array($this, 'update_item'), |
|
86 | + 'permission_callback' => array($this, 'update_item_permissions_check'), |
|
87 | + 'args' => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE), |
|
88 | 88 | ), |
89 | 89 | array( |
90 | 90 | 'methods' => WP_REST_Server::DELETABLE, |
91 | - 'callback' => array( $this, 'delete_item' ), |
|
92 | - 'permission_callback' => array( $this, 'delete_item_permissions_check' ), |
|
91 | + 'callback' => array($this, 'delete_item'), |
|
92 | + 'permission_callback' => array($this, 'delete_item_permissions_check'), |
|
93 | 93 | 'args' => array( |
94 | 94 | 'force' => array( |
95 | 95 | 'type' => 'boolean', |
96 | 96 | 'default' => false, |
97 | - 'description' => __( 'Whether to bypass Trash and force deletion.', 'invoicing' ), |
|
97 | + 'description' => __('Whether to bypass Trash and force deletion.', 'invoicing'), |
|
98 | 98 | ), |
99 | 99 | ), |
100 | 100 | ), |
101 | - 'schema' => array( $this, 'get_public_item_schema' ), |
|
101 | + 'schema' => array($this, 'get_public_item_schema'), |
|
102 | 102 | ) |
103 | 103 | ); |
104 | 104 | |
@@ -110,14 +110,14 @@ discard block |
||
110 | 110 | * @param GetPaid_Data $object Object to save. |
111 | 111 | * @return WP_Error|GetPaid_Data |
112 | 112 | */ |
113 | - protected function save_object( $object ) { |
|
113 | + protected function save_object($object) { |
|
114 | 114 | $object->save(); |
115 | 115 | |
116 | - if ( ! empty( $object->last_error ) ) { |
|
117 | - return new WP_Error( 'rest_cannot_save', $object->last_error, array( 'status' => 400 ) ); |
|
116 | + if (!empty($object->last_error)) { |
|
117 | + return new WP_Error('rest_cannot_save', $object->last_error, array('status' => 400)); |
|
118 | 118 | } |
119 | 119 | |
120 | - return new $this->crud_class( $object->get_id() ); |
|
120 | + return new $this->crud_class($object->get_id()); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -128,21 +128,21 @@ discard block |
||
128 | 128 | * @param int|WP_Post $object_id Supplied ID. |
129 | 129 | * @return GetPaid_Data|WP_Error GetPaid_Data object if ID is valid, WP_Error otherwise. |
130 | 130 | */ |
131 | - protected function get_object( $object_id ) { |
|
131 | + protected function get_object($object_id) { |
|
132 | 132 | |
133 | 133 | // Do we have an object? |
134 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
135 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
134 | + if (empty($this->crud_class) || !class_exists($this->crud_class)) { |
|
135 | + return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing')); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | // Fetch the object. |
139 | - $object = new $this->crud_class( $object_id ); |
|
140 | - if ( ! empty( $object->last_error ) ) { |
|
141 | - return new WP_Error( 'rest_object_invalid_id', $object->last_error, array( 'status' => 404 ) ); |
|
139 | + $object = new $this->crud_class($object_id); |
|
140 | + if (!empty($object->last_error)) { |
|
141 | + return new WP_Error('rest_object_invalid_id', $object->last_error, array('status' => 404)); |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | $this->data_object = $object; |
145 | - return $object->get_id() ? $object : new WP_Error( 'rest_object_invalid_id', __( 'Invalid ID.', 'invoicing' ), array( 'status' => 404 ) ); |
|
145 | + return $object->get_id() ? $object : new WP_Error('rest_object_invalid_id', __('Invalid ID.', 'invoicing'), array('status' => 404)); |
|
146 | 146 | |
147 | 147 | } |
148 | 148 | |
@@ -152,17 +152,17 @@ discard block |
||
152 | 152 | * @param WP_REST_Request $request Full details about the request. |
153 | 153 | * @return WP_Error|WP_REST_Response |
154 | 154 | */ |
155 | - public function get_item( $request ) { |
|
155 | + public function get_item($request) { |
|
156 | 156 | |
157 | 157 | // Fetch the item. |
158 | - $object = $this->get_object( $request['id'] ); |
|
158 | + $object = $this->get_object($request['id']); |
|
159 | 159 | |
160 | - if ( is_wp_error( $object ) ) { |
|
160 | + if (is_wp_error($object)) { |
|
161 | 161 | return $object; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Generate a response. |
165 | - return rest_ensure_response( $this->prepare_item_for_response( $object, $request ) ); |
|
165 | + return rest_ensure_response($this->prepare_item_for_response($object, $request)); |
|
166 | 166 | |
167 | 167 | } |
168 | 168 | |
@@ -172,38 +172,38 @@ discard block |
||
172 | 172 | * @param WP_REST_Request $request Full details about the request. |
173 | 173 | * @return WP_Error|WP_REST_Response |
174 | 174 | */ |
175 | - public function create_item( $request ) { |
|
175 | + public function create_item($request) { |
|
176 | 176 | |
177 | 177 | // Can not create an existing item. |
178 | - if ( ! empty( $request['id'] ) ) { |
|
178 | + if (!empty($request['id'])) { |
|
179 | 179 | /* translators: %s: post type */ |
180 | - return new WP_Error( "getpaid_rest_{$this->rest_base}_exists", __( 'Cannot create existing resource.', 'invoicing' ), array( 'status' => 400 ) ); |
|
180 | + return new WP_Error("getpaid_rest_{$this->rest_base}_exists", __('Cannot create existing resource.', 'invoicing'), array('status' => 400)); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | // Generate a GetPaid_Data object from the request. |
184 | - $object = $this->prepare_item_for_database( $request ); |
|
185 | - if ( is_wp_error( $object ) ) { |
|
184 | + $object = $this->prepare_item_for_database($request); |
|
185 | + if (is_wp_error($object)) { |
|
186 | 186 | return $object; |
187 | 187 | } |
188 | 188 | |
189 | 189 | // Save the object. |
190 | - $object = $this->save_object( $object ); |
|
191 | - if ( is_wp_error( $object ) ) { |
|
190 | + $object = $this->save_object($object); |
|
191 | + if (is_wp_error($object)) { |
|
192 | 192 | return $object; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Save special fields. |
196 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
197 | - if ( is_wp_error( $save_special ) ) { |
|
198 | - $object->delete( true ); |
|
196 | + $save_special = $this->update_additional_fields_for_object($object, $request); |
|
197 | + if (is_wp_error($save_special)) { |
|
198 | + $object->delete(true); |
|
199 | 199 | return $save_special; |
200 | 200 | } |
201 | 201 | |
202 | - $request->set_param( 'context', 'edit' ); |
|
203 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
204 | - $response = rest_ensure_response( $response ); |
|
205 | - $response->set_status( 201 ); |
|
206 | - $response->header( 'Location', rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ) ); |
|
202 | + $request->set_param('context', 'edit'); |
|
203 | + $response = $this->prepare_item_for_response($object, $request); |
|
204 | + $response = rest_ensure_response($response); |
|
205 | + $response->set_status(201); |
|
206 | + $response->header('Location', rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id()))); |
|
207 | 207 | |
208 | 208 | return $response; |
209 | 209 | } |
@@ -214,35 +214,35 @@ discard block |
||
214 | 214 | * @param WP_REST_Request $request Full details about the request. |
215 | 215 | * @return WP_Error|WP_REST_Response |
216 | 216 | */ |
217 | - public function update_item( $request ) { |
|
217 | + public function update_item($request) { |
|
218 | 218 | |
219 | 219 | // Fetch the item. |
220 | - $object = $this->get_object( $request['id'] ); |
|
221 | - if ( is_wp_error( $object ) ) { |
|
220 | + $object = $this->get_object($request['id']); |
|
221 | + if (is_wp_error($object)) { |
|
222 | 222 | return $object; |
223 | 223 | } |
224 | 224 | |
225 | 225 | // Prepare the item for saving. |
226 | - $object = $this->prepare_item_for_database( $request ); |
|
227 | - if ( is_wp_error( $object ) ) { |
|
226 | + $object = $this->prepare_item_for_database($request); |
|
227 | + if (is_wp_error($object)) { |
|
228 | 228 | return $object; |
229 | 229 | } |
230 | 230 | |
231 | 231 | // Save the item. |
232 | - $object = $this->save_object( $object ); |
|
233 | - if ( is_wp_error( $object ) ) { |
|
232 | + $object = $this->save_object($object); |
|
233 | + if (is_wp_error($object)) { |
|
234 | 234 | return $object; |
235 | 235 | } |
236 | 236 | |
237 | 237 | // Save special fields (those added via hooks). |
238 | - $save_special = $this->update_additional_fields_for_object( $object, $request ); |
|
239 | - if ( is_wp_error( $save_special ) ) { |
|
238 | + $save_special = $this->update_additional_fields_for_object($object, $request); |
|
239 | + if (is_wp_error($save_special)) { |
|
240 | 240 | return $save_special; |
241 | 241 | } |
242 | 242 | |
243 | - $request->set_param( 'context', 'edit' ); |
|
244 | - $response = $this->prepare_item_for_response( $object, $request ); |
|
245 | - return rest_ensure_response( $response ); |
|
243 | + $request->set_param('context', 'edit'); |
|
244 | + $response = $this->prepare_item_for_response($object, $request); |
|
245 | + return rest_ensure_response($response); |
|
246 | 246 | } |
247 | 247 | |
248 | 248 | /** |
@@ -251,14 +251,14 @@ discard block |
||
251 | 251 | * @param GetPaid_Data $object GetPaid_Data object. |
252 | 252 | * @return array Links for the given object. |
253 | 253 | */ |
254 | - protected function prepare_links( $object ) { |
|
254 | + protected function prepare_links($object) { |
|
255 | 255 | |
256 | 256 | $links = array( |
257 | 257 | 'self' => array( |
258 | - 'href' => rest_url( sprintf( '/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id() ) ), |
|
258 | + 'href' => rest_url(sprintf('/%s/%s/%d', $this->namespace, $this->rest_base, $object->get_id())), |
|
259 | 259 | ), |
260 | 260 | 'collection' => array( |
261 | - 'href' => rest_url( sprintf( '/%s/%s', $this->namespace, $this->rest_base ) ), |
|
261 | + 'href' => rest_url(sprintf('/%s/%s', $this->namespace, $this->rest_base)), |
|
262 | 262 | ), |
263 | 263 | ); |
264 | 264 | |
@@ -282,8 +282,8 @@ discard block |
||
282 | 282 | * @param array $schema Schema. |
283 | 283 | * @return bool |
284 | 284 | */ |
285 | - public function filter_writable_props( $schema ) { |
|
286 | - return empty( $schema['readonly'] ); |
|
285 | + public function filter_writable_props($schema) { |
|
286 | + return empty($schema['readonly']); |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -293,43 +293,43 @@ discard block |
||
293 | 293 | * @param WP_REST_Request $request Request object. |
294 | 294 | * @return GetPaid_Data|WP_Error Data object or WP_Error. |
295 | 295 | */ |
296 | - protected function prepare_item_for_database( $request ) { |
|
296 | + protected function prepare_item_for_database($request) { |
|
297 | 297 | |
298 | 298 | // Do we have an object? |
299 | - if ( empty( $this->crud_class ) || ! class_exists( $this->crud_class ) ) { |
|
300 | - return new WP_Error( 'no_crud_class', __( 'You need to specify a CRUD class for this controller', 'invoicing' ) ); |
|
299 | + if (empty($this->crud_class) || !class_exists($this->crud_class)) { |
|
300 | + return new WP_Error('no_crud_class', __('You need to specify a CRUD class for this controller', 'invoicing')); |
|
301 | 301 | } |
302 | 302 | |
303 | 303 | // Prepare the object. |
304 | - $id = isset( $request['id'] ) ? absint( $request['id'] ) : 0; |
|
305 | - $object = new $this->crud_class( $id ); |
|
304 | + $id = isset($request['id']) ? absint($request['id']) : 0; |
|
305 | + $object = new $this->crud_class($id); |
|
306 | 306 | |
307 | 307 | // Abort if an error exists. |
308 | - if ( ! empty( $object->last_error ) ) { |
|
309 | - return new WP_Error( 'invalid_item', $object->last_error ); |
|
308 | + if (!empty($object->last_error)) { |
|
309 | + return new WP_Error('invalid_item', $object->last_error); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $schema = $this->get_item_schema(); |
313 | - $data_keys = array_keys( array_filter( $schema['properties'], array( $this, 'filter_writable_props' ) ) ); |
|
313 | + $data_keys = array_keys(array_filter($schema['properties'], array($this, 'filter_writable_props'))); |
|
314 | 314 | |
315 | 315 | // Handle all writable props. |
316 | - foreach ( $data_keys as $key ) { |
|
317 | - $value = $request[ $key ]; |
|
316 | + foreach ($data_keys as $key) { |
|
317 | + $value = $request[$key]; |
|
318 | 318 | |
319 | - if ( ! is_null( $value ) ) { |
|
320 | - switch ( $key ) { |
|
319 | + if (!is_null($value)) { |
|
320 | + switch ($key) { |
|
321 | 321 | |
322 | 322 | case 'meta_data': |
323 | - if ( is_array( $value ) ) { |
|
324 | - foreach ( $value as $meta ) { |
|
325 | - $object->update_meta_data( $meta['key'], $meta['value'], isset( $meta['id'] ) ? $meta['id'] : '' ); |
|
323 | + if (is_array($value)) { |
|
324 | + foreach ($value as $meta) { |
|
325 | + $object->update_meta_data($meta['key'], $meta['value'], isset($meta['id']) ? $meta['id'] : ''); |
|
326 | 326 | } |
327 | 327 | } |
328 | 328 | break; |
329 | 329 | |
330 | 330 | default: |
331 | - if ( is_callable( array( $object, "set_{$key}" ) ) ) { |
|
332 | - $object->{"set_{$key}"}( $value ); |
|
331 | + if (is_callable(array($object, "set_{$key}"))) { |
|
332 | + $object->{"set_{$key}"}($value); |
|
333 | 333 | } |
334 | 334 | break; |
335 | 335 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | |
340 | 340 | // Filters an object before it is inserted via the REST API.. |
341 | - return apply_filters( "getpaid_rest_pre_insert_{$this->rest_base}_object", $object, $request ); |
|
341 | + return apply_filters("getpaid_rest_pre_insert_{$this->rest_base}_object", $object, $request); |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -348,10 +348,10 @@ discard block |
||
348 | 348 | * @param GetPaid_Meta_Data[] $meta_data meta data objects. |
349 | 349 | * @return array |
350 | 350 | */ |
351 | - protected function prepare_object_meta_data( $meta_data ) { |
|
351 | + protected function prepare_object_meta_data($meta_data) { |
|
352 | 352 | $meta = array(); |
353 | 353 | |
354 | - foreach( $meta_data as $object ) { |
|
354 | + foreach ($meta_data as $object) { |
|
355 | 355 | $meta[] = $object->get_data(); |
356 | 356 | } |
357 | 357 | |
@@ -366,14 +366,14 @@ discard block |
||
366 | 366 | * @param array $fields Fields to include. |
367 | 367 | * @return array |
368 | 368 | */ |
369 | - protected function prepare_invoice_items( $invoice ) { |
|
369 | + protected function prepare_invoice_items($invoice) { |
|
370 | 370 | $items = array(); |
371 | 371 | |
372 | - foreach( $invoice->get_items() as $item ) { |
|
372 | + foreach ($invoice->get_items() as $item) { |
|
373 | 373 | |
374 | 374 | $item_data = $item->prepare_data_for_saving(); |
375 | 375 | |
376 | - if ( 'amount' == $invoice->get_template() ) { |
|
376 | + if ('amount' == $invoice->get_template()) { |
|
377 | 377 | $item_data['quantity'] = 1; |
378 | 378 | } |
379 | 379 | |
@@ -392,52 +392,52 @@ discard block |
||
392 | 392 | * @param string $context either view or edit. |
393 | 393 | * @return array |
394 | 394 | */ |
395 | - protected function prepare_object_data( $object, $fields, $context = 'view' ) { |
|
395 | + protected function prepare_object_data($object, $fields, $context = 'view') { |
|
396 | 396 | |
397 | 397 | $data = array(); |
398 | 398 | |
399 | 399 | // Handle all writable props. |
400 | - foreach ( array_keys( $this->get_schema_properties() ) as $key ) { |
|
400 | + foreach (array_keys($this->get_schema_properties()) as $key) { |
|
401 | 401 | |
402 | 402 | // Abort if it is not included. |
403 | - if ( ! empty( $fields ) && ! $this->is_field_included( $key, $fields ) ) { |
|
403 | + if (!empty($fields) && !$this->is_field_included($key, $fields)) { |
|
404 | 404 | continue; |
405 | 405 | } |
406 | 406 | |
407 | 407 | // Or this current object does not support the field. |
408 | - if ( ! $this->object_supports_field( $object, $key ) ) { |
|
408 | + if (!$this->object_supports_field($object, $key)) { |
|
409 | 409 | continue; |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Handle meta data. |
413 | - if ( $key == 'meta_data' ) { |
|
414 | - $data['meta_data'] = $this->prepare_object_meta_data( $object->get_meta_data() ); |
|
413 | + if ($key == 'meta_data') { |
|
414 | + $data['meta_data'] = $this->prepare_object_meta_data($object->get_meta_data()); |
|
415 | 415 | continue; |
416 | 416 | } |
417 | 417 | |
418 | 418 | // Handle items. |
419 | - if ( $key == 'items' && is_a( $object, 'WPInv_Invoice' ) ) { |
|
420 | - $data['items'] = $this->prepare_invoice_items( $object ); |
|
419 | + if ($key == 'items' && is_a($object, 'WPInv_Invoice')) { |
|
420 | + $data['items'] = $this->prepare_invoice_items($object); |
|
421 | 421 | continue; |
422 | 422 | } |
423 | 423 | |
424 | 424 | // Booleans. |
425 | - if ( is_callable( array( $object, $key ) ) ) { |
|
426 | - $data[ $key ] = $object->$key( $context ); |
|
425 | + if (is_callable(array($object, $key))) { |
|
426 | + $data[$key] = $object->$key($context); |
|
427 | 427 | continue; |
428 | 428 | } |
429 | 429 | |
430 | 430 | // Get object value. |
431 | - if ( is_callable( array( $object, "get_{$key}" ) ) ) { |
|
432 | - $value = $object->{"get_{$key}"}( $context ); |
|
431 | + if (is_callable(array($object, "get_{$key}"))) { |
|
432 | + $value = $object->{"get_{$key}"}($context); |
|
433 | 433 | |
434 | 434 | // If the value is an instance of GetPaid_Data... |
435 | - if ( is_a( $value, 'GetPaid_Data' ) ) { |
|
436 | - $value = $value->get_data( $context ); |
|
435 | + if (is_a($value, 'GetPaid_Data')) { |
|
436 | + $value = $value->get_data($context); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | // For objects, retrieves it's properties. |
440 | - $data[ $key ] = is_object( $value ) ? get_object_vars( $value ) : $value ; |
|
440 | + $data[$key] = is_object($value) ? get_object_vars($value) : $value; |
|
441 | 441 | continue; |
442 | 442 | } |
443 | 443 | |
@@ -454,8 +454,8 @@ discard block |
||
454 | 454 | * @param string $field_key The key to check for. |
455 | 455 | * @return bool |
456 | 456 | */ |
457 | - public function object_supports_field( $object, $field_key ) { |
|
458 | - return apply_filters( 'getpaid_rest_object_supports_key', true, $object, $field_key ); |
|
457 | + public function object_supports_field($object, $field_key) { |
|
458 | + return apply_filters('getpaid_rest_object_supports_key', true, $object, $field_key); |
|
459 | 459 | } |
460 | 460 | |
461 | 461 | /** |
@@ -466,27 +466,27 @@ discard block |
||
466 | 466 | * @param WP_REST_Request $request Request object. |
467 | 467 | * @return WP_REST_Response |
468 | 468 | */ |
469 | - public function prepare_item_for_response( $object, $request ) { |
|
470 | - remove_filter( 'rest_post_dispatch', 'rest_filter_response_fields', 10 ); |
|
469 | + public function prepare_item_for_response($object, $request) { |
|
470 | + remove_filter('rest_post_dispatch', 'rest_filter_response_fields', 10); |
|
471 | 471 | |
472 | 472 | $this->data_object = $object; |
473 | 473 | |
474 | 474 | // Fetch the fields to include in this response. |
475 | - $fields = $this->get_fields_for_response( $request ); |
|
475 | + $fields = $this->get_fields_for_response($request); |
|
476 | 476 | |
477 | 477 | // Prepare object data. |
478 | - $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; |
|
479 | - $data = $this->prepare_object_data( $object, $fields, $context ); |
|
480 | - $data = $this->add_additional_fields_to_object( $data, $request ); |
|
481 | - $data = $this->limit_object_to_requested_fields( $data, $fields ); |
|
482 | - $data = $this->filter_response_by_context( $data, $context ); |
|
478 | + $context = !empty($request['context']) ? $request['context'] : 'view'; |
|
479 | + $data = $this->prepare_object_data($object, $fields, $context); |
|
480 | + $data = $this->add_additional_fields_to_object($data, $request); |
|
481 | + $data = $this->limit_object_to_requested_fields($data, $fields); |
|
482 | + $data = $this->filter_response_by_context($data, $context); |
|
483 | 483 | |
484 | 484 | // Prepare the response. |
485 | - $response = rest_ensure_response( $data ); |
|
486 | - $response->add_links( $this->prepare_links( $object, $request ) ); |
|
485 | + $response = rest_ensure_response($data); |
|
486 | + $response->add_links($this->prepare_links($object, $request)); |
|
487 | 487 | |
488 | 488 | // Filter item response. |
489 | - return apply_filters( "getpaid_rest_prepare_{$this->rest_base}_object", $response, $object, $request ); |
|
489 | + return apply_filters("getpaid_rest_prepare_{$this->rest_base}_object", $response, $object, $request); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | } |
@@ -97,9 +97,9 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @param null|string|array $query Optional. The query variables. |
99 | 99 | */ |
100 | - public function __construct( $query = null ) { |
|
101 | - if ( ! is_null( $query ) ) { |
|
102 | - $this->prepare_query( $query ); |
|
100 | + public function __construct($query = null) { |
|
101 | + if (!is_null($query)) { |
|
102 | + $this->prepare_query($query); |
|
103 | 103 | $this->query(); |
104 | 104 | } |
105 | 105 | } |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | * @param string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`. |
113 | 113 | * @return array Complete query variables with undefined ones filled in with defaults. |
114 | 114 | */ |
115 | - public static function fill_query_vars( $args ) { |
|
115 | + public static function fill_query_vars($args) { |
|
116 | 116 | $defaults = array( |
117 | 117 | 'status' => 'all', |
118 | 118 | 'customer_in' => array(), |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | 'fields' => 'all', |
131 | 131 | ); |
132 | 132 | |
133 | - return wp_parse_args( $args, $defaults ); |
|
133 | + return wp_parse_args($args, $defaults); |
|
134 | 134 | } |
135 | 135 | |
136 | 136 | /** |
@@ -182,45 +182,45 @@ discard block |
||
182 | 182 | * Use 'all' for all fields. Default 'all'. |
183 | 183 | * } |
184 | 184 | */ |
185 | - public function prepare_query( $query = array() ) { |
|
185 | + public function prepare_query($query = array()) { |
|
186 | 186 | global $wpdb; |
187 | 187 | |
188 | - if ( empty( $this->query_vars ) || ! empty( $query ) ) { |
|
188 | + if (empty($this->query_vars) || !empty($query)) { |
|
189 | 189 | $this->query_limit = null; |
190 | - $this->query_vars = $this->fill_query_vars( $query ); |
|
190 | + $this->query_vars = $this->fill_query_vars($query); |
|
191 | 191 | } |
192 | 192 | |
193 | - if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) { |
|
194 | - $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] ); |
|
193 | + if (!empty($this->query_vars['fields']) && 'all' !== $this->query_vars['fields']) { |
|
194 | + $this->query_vars['fields'] = wpinv_parse_list($this->query_vars['fields']); |
|
195 | 195 | } |
196 | 196 | |
197 | - do_action( 'getpaid_pre_get_subscriptions', array( &$this ) ); |
|
197 | + do_action('getpaid_pre_get_subscriptions', array(&$this)); |
|
198 | 198 | |
199 | 199 | // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'. |
200 | - $qv =& $this->query_vars; |
|
201 | - $qv = $this->fill_query_vars( $qv ); |
|
200 | + $qv = & $this->query_vars; |
|
201 | + $qv = $this->fill_query_vars($qv); |
|
202 | 202 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
203 | 203 | $this->query_from = "FROM $table"; |
204 | 204 | |
205 | 205 | // Prepare query fields. |
206 | - $this->prepare_query_fields( $qv, $table ); |
|
206 | + $this->prepare_query_fields($qv, $table); |
|
207 | 207 | |
208 | 208 | // Prepare query where. |
209 | - $this->prepare_query_where( $qv, $table ); |
|
209 | + $this->prepare_query_where($qv, $table); |
|
210 | 210 | |
211 | 211 | // Prepare query order. |
212 | - $this->prepare_query_order( $qv, $table ); |
|
212 | + $this->prepare_query_order($qv, $table); |
|
213 | 213 | |
214 | 214 | // limit |
215 | - if ( isset( $qv['number'] ) && $qv['number'] > 0 ) { |
|
216 | - if ( $qv['offset'] ) { |
|
217 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] ); |
|
215 | + if (isset($qv['number']) && $qv['number'] > 0) { |
|
216 | + if ($qv['offset']) { |
|
217 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['offset'], $qv['number']); |
|
218 | 218 | } else { |
219 | - $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] ); |
|
219 | + $this->query_limit = $wpdb->prepare('LIMIT %d, %d', $qv['number'] * ($qv['paged'] - 1), $qv['number']); |
|
220 | 220 | } |
221 | 221 | } |
222 | 222 | |
223 | - do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) ); |
|
223 | + do_action_ref_array('getpaid_after_subscriptions_query', array(&$this)); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -231,22 +231,22 @@ discard block |
||
231 | 231 | * @param array $qv Query vars. |
232 | 232 | * @param string $table Table name. |
233 | 233 | */ |
234 | - protected function prepare_query_fields( &$qv, $table ) { |
|
234 | + protected function prepare_query_fields(&$qv, $table) { |
|
235 | 235 | |
236 | - if ( is_array( $qv['fields'] ) ) { |
|
237 | - $qv['fields'] = array_unique( $qv['fields'] ); |
|
236 | + if (is_array($qv['fields'])) { |
|
237 | + $qv['fields'] = array_unique($qv['fields']); |
|
238 | 238 | |
239 | 239 | $query_fields = array(); |
240 | - foreach ( $qv['fields'] as $field ) { |
|
241 | - $field = sanitize_key( $field ); |
|
240 | + foreach ($qv['fields'] as $field) { |
|
241 | + $field = sanitize_key($field); |
|
242 | 242 | $query_fields[] = "$table.`$field`"; |
243 | 243 | } |
244 | - $this->query_fields = implode( ',', $query_fields ); |
|
244 | + $this->query_fields = implode(',', $query_fields); |
|
245 | 245 | } else { |
246 | 246 | $this->query_fields = "$table.*"; |
247 | 247 | } |
248 | 248 | |
249 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
249 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
250 | 250 | $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields; |
251 | 251 | } |
252 | 252 | |
@@ -260,58 +260,58 @@ discard block |
||
260 | 260 | * @param array $qv Query vars. |
261 | 261 | * @param string $table Table name. |
262 | 262 | */ |
263 | - protected function prepare_query_where( &$qv, $table ) { |
|
263 | + protected function prepare_query_where(&$qv, $table) { |
|
264 | 264 | global $wpdb; |
265 | 265 | $this->query_where = 'WHERE 1=1'; |
266 | 266 | |
267 | 267 | // Status. |
268 | - if ( 'all' !== $qv['status'] ) { |
|
269 | - $statuses = wpinv_clean( wpinv_parse_list( $qv['status'] ) ); |
|
270 | - $prepared_statuses = join( ',', array_fill( 0, count( $statuses ), '%s' ) ); |
|
271 | - $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses ); |
|
268 | + if ('all' !== $qv['status']) { |
|
269 | + $statuses = wpinv_clean(wpinv_parse_list($qv['status'])); |
|
270 | + $prepared_statuses = join(',', array_fill(0, count($statuses), '%s')); |
|
271 | + $this->query_where .= $wpdb->prepare(" AND $table.`status` IN ( $prepared_statuses )", $statuses); |
|
272 | 272 | } |
273 | 273 | |
274 | - if ( ! empty( $qv['customer_in'] ) ) { |
|
275 | - $customer_in = implode( ',', wp_parse_id_list( $qv['customer_in'] ) ); |
|
274 | + if (!empty($qv['customer_in'])) { |
|
275 | + $customer_in = implode(',', wp_parse_id_list($qv['customer_in'])); |
|
276 | 276 | $this->query_where .= " AND $table.`customer_id` IN ($customer_in)"; |
277 | - } elseif ( ! empty( $qv['customer_not_in'] ) ) { |
|
278 | - $customer_not_in = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) ); |
|
277 | + } elseif (!empty($qv['customer_not_in'])) { |
|
278 | + $customer_not_in = implode(',', wp_parse_id_list($qv['customer_not_in'])); |
|
279 | 279 | $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)"; |
280 | 280 | } |
281 | 281 | |
282 | - if ( ! empty( $qv['product_in'] ) ) { |
|
283 | - $product_in = implode( ',', wp_parse_id_list( $qv['product_in'] ) ); |
|
282 | + if (!empty($qv['product_in'])) { |
|
283 | + $product_in = implode(',', wp_parse_id_list($qv['product_in'])); |
|
284 | 284 | $this->query_where .= " AND $table.`product_id` IN ($product_in)"; |
285 | - } elseif ( ! empty( $qv['product_not_in'] ) ) { |
|
286 | - $product_not_in = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) ); |
|
285 | + } elseif (!empty($qv['product_not_in'])) { |
|
286 | + $product_not_in = implode(',', wp_parse_id_list($qv['product_not_in'])); |
|
287 | 287 | $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)"; |
288 | 288 | } |
289 | 289 | |
290 | - if ( ! empty( $qv['invoice_in'] ) ) { |
|
291 | - $invoice_in = implode( ',', wp_parse_id_list( $qv['invoice_in'] ) ); |
|
290 | + if (!empty($qv['invoice_in'])) { |
|
291 | + $invoice_in = implode(',', wp_parse_id_list($qv['invoice_in'])); |
|
292 | 292 | $this->query_where .= " AND $table.`parent_payment_id` IN ($invoice_in)"; |
293 | - } elseif ( ! empty( $qv['invoice_not_in'] ) ) { |
|
294 | - $invoice_not_in = implode( ',', wp_parse_id_list( $qv['invoice_not_in'] ) ); |
|
293 | + } elseif (!empty($qv['invoice_not_in'])) { |
|
294 | + $invoice_not_in = implode(',', wp_parse_id_list($qv['invoice_not_in'])); |
|
295 | 295 | $this->query_where .= " AND $table.`parent_payment_id` NOT IN ($invoice_not_in)"; |
296 | 296 | } |
297 | 297 | |
298 | - if ( ! empty( $qv['include'] ) ) { |
|
299 | - $include = implode( ',', wp_parse_id_list( $qv['include'] ) ); |
|
298 | + if (!empty($qv['include'])) { |
|
299 | + $include = implode(',', wp_parse_id_list($qv['include'])); |
|
300 | 300 | $this->query_where .= " AND $table.`id` IN ($include)"; |
301 | - } elseif ( ! empty( $qv['exclude'] ) ) { |
|
302 | - $exclude = implode( ',', wp_parse_id_list( $qv['exclude'] ) ); |
|
301 | + } elseif (!empty($qv['exclude'])) { |
|
302 | + $exclude = implode(',', wp_parse_id_list($qv['exclude'])); |
|
303 | 303 | $this->query_where .= " AND $table.`id` NOT IN ($exclude)"; |
304 | 304 | } |
305 | 305 | |
306 | 306 | // Date queries are allowed for the subscription creation date. |
307 | - if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) { |
|
308 | - $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" ); |
|
307 | + if (!empty($qv['date_created_query']) && is_array($qv['date_created_query'])) { |
|
308 | + $date_created_query = new WP_Date_Query($qv['date_created_query'], "$table.created"); |
|
309 | 309 | $this->query_where .= $date_created_query->get_sql(); |
310 | 310 | } |
311 | 311 | |
312 | 312 | // Date queries are also allowed for the subscription expiration date. |
313 | - if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) { |
|
314 | - $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" ); |
|
313 | + if (!empty($qv['date_expires_query']) && is_array($qv['date_expires_query'])) { |
|
314 | + $date_expires_query = new WP_Date_Query($qv['date_expires_query'], "$table.expiration"); |
|
315 | 315 | $this->query_where .= $date_expires_query->get_sql(); |
316 | 316 | } |
317 | 317 | |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | * @param array $qv Query vars. |
326 | 326 | * @param string $table Table name. |
327 | 327 | */ |
328 | - protected function prepare_query_order( &$qv, $table ) { |
|
328 | + protected function prepare_query_order(&$qv, $table) { |
|
329 | 329 | |
330 | 330 | // sorting. |
331 | - $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : ''; |
|
332 | - $order = $this->parse_order( $qv['order'] ); |
|
331 | + $qv['order'] = isset($qv['order']) ? strtoupper($qv['order']) : ''; |
|
332 | + $order = $this->parse_order($qv['order']); |
|
333 | 333 | |
334 | 334 | // Default order is by 'id' (latest subscriptions). |
335 | - if ( empty( $qv['orderby'] ) ) { |
|
336 | - $qv['orderby'] = array( 'id' ); |
|
335 | + if (empty($qv['orderby'])) { |
|
336 | + $qv['orderby'] = array('id'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // 'orderby' values may be an array, comma- or space-separated list. |
340 | - $ordersby = array_filter( wpinv_parse_list( $qv['orderby'] ) ); |
|
340 | + $ordersby = array_filter(wpinv_parse_list($qv['orderby'])); |
|
341 | 341 | |
342 | 342 | $orderby_array = array(); |
343 | - foreach ( $ordersby as $_key => $_value ) { |
|
343 | + foreach ($ordersby as $_key => $_value) { |
|
344 | 344 | |
345 | - if ( is_int( $_key ) ) { |
|
345 | + if (is_int($_key)) { |
|
346 | 346 | // Integer key means this is a flat array of 'orderby' fields. |
347 | 347 | $_orderby = $_value; |
348 | 348 | $_order = $order; |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | $_order = $_value; |
353 | 353 | } |
354 | 354 | |
355 | - $parsed = $this->parse_orderby( $_orderby, $table ); |
|
355 | + $parsed = $this->parse_orderby($_orderby, $table); |
|
356 | 356 | |
357 | - if ( $parsed ) { |
|
358 | - $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order ); |
|
357 | + if ($parsed) { |
|
358 | + $orderby_array[] = $parsed . ' ' . $this->parse_order($_order); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | } |
362 | 362 | |
363 | 363 | // If no valid clauses were found, order by id. |
364 | - if ( empty( $orderby_array ) ) { |
|
364 | + if (empty($orderby_array)) { |
|
365 | 365 | $orderby_array[] = "id $order"; |
366 | 366 | } |
367 | 367 | |
368 | - $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array ); |
|
368 | + $this->query_orderby = 'ORDER BY ' . implode(', ', $orderby_array); |
|
369 | 369 | |
370 | 370 | } |
371 | 371 | |
@@ -379,34 +379,34 @@ discard block |
||
379 | 379 | public function query() { |
380 | 380 | global $wpdb; |
381 | 381 | |
382 | - $qv =& $this->query_vars; |
|
382 | + $qv = & $this->query_vars; |
|
383 | 383 | |
384 | 384 | // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the |
385 | 385 | // total_subscriptions property. |
386 | - $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) ); |
|
386 | + $this->results = apply_filters_ref_array('getpaid_subscriptions_pre_query', array(null, &$this)); |
|
387 | 387 | |
388 | - if ( null === $this->results ) { |
|
388 | + if (null === $this->results) { |
|
389 | 389 | $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit"; |
390 | 390 | |
391 | - if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) { |
|
392 | - $this->results = $wpdb->get_results( $this->request ); |
|
391 | + if ((is_array($qv['fields']) && 1 != count($qv['fields'])) || 'all' == $qv['fields']) { |
|
392 | + $this->results = $wpdb->get_results($this->request); |
|
393 | 393 | } else { |
394 | - $this->results = $wpdb->get_col( $this->request ); |
|
394 | + $this->results = $wpdb->get_col($this->request); |
|
395 | 395 | } |
396 | 396 | |
397 | - if ( isset( $qv['count_total'] ) && $qv['count_total'] ) { |
|
398 | - $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this ); |
|
399 | - $this->total_subscriptions = (int) $wpdb->get_var( $found_subscriptions_query ); |
|
397 | + if (isset($qv['count_total']) && $qv['count_total']) { |
|
398 | + $found_subscriptions_query = apply_filters('getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this); |
|
399 | + $this->total_subscriptions = (int) $wpdb->get_var($found_subscriptions_query); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 | |
403 | - if ( 'all' == $qv['fields'] ) { |
|
404 | - foreach ( $this->results as $key => $subscription ) { |
|
405 | - wp_cache_set( $subscription->id, $subscription, 'getpaid_subscriptions' ); |
|
406 | - wp_cache_set( $subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
407 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
408 | - wp_cache_set( $subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
409 | - $this->results[ $key ] = new WPInv_Subscription( $subscription ); |
|
403 | + if ('all' == $qv['fields']) { |
|
404 | + foreach ($this->results as $key => $subscription) { |
|
405 | + wp_cache_set($subscription->id, $subscription, 'getpaid_subscriptions'); |
|
406 | + wp_cache_set($subscription->profile_id, $subscription->id, 'getpaid_subscription_profile_ids_to_subscription_ids'); |
|
407 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
408 | + wp_cache_set($subscription->transaction_id, $subscription->id, 'getpaid_subscription_transaction_ids_to_subscription_ids'); |
|
409 | + $this->results[$key] = new WPInv_Subscription($subscription); |
|
410 | 410 | } |
411 | 411 | } |
412 | 412 | |
@@ -420,9 +420,9 @@ discard block |
||
420 | 420 | * @param string $query_var Query variable key. |
421 | 421 | * @return mixed |
422 | 422 | */ |
423 | - public function get( $query_var ) { |
|
424 | - if ( isset( $this->query_vars[ $query_var ] ) ) { |
|
425 | - return $this->query_vars[ $query_var ]; |
|
423 | + public function get($query_var) { |
|
424 | + if (isset($this->query_vars[$query_var])) { |
|
425 | + return $this->query_vars[$query_var]; |
|
426 | 426 | } |
427 | 427 | |
428 | 428 | return null; |
@@ -436,8 +436,8 @@ discard block |
||
436 | 436 | * @param string $query_var Query variable key. |
437 | 437 | * @param mixed $value Query variable value. |
438 | 438 | */ |
439 | - public function set( $query_var, $value ) { |
|
440 | - $this->query_vars[ $query_var ] = $value; |
|
439 | + public function set($query_var, $value) { |
|
440 | + $this->query_vars[$query_var] = $value; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | /** |
@@ -471,16 +471,16 @@ discard block |
||
471 | 471 | * @param string $table The current table. |
472 | 472 | * @return string Value to use in the ORDER clause, if `$orderby` is valid. |
473 | 473 | */ |
474 | - protected function parse_orderby( $orderby, $table ) { |
|
474 | + protected function parse_orderby($orderby, $table) { |
|
475 | 475 | |
476 | 476 | $_orderby = ''; |
477 | - if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) { |
|
477 | + if (in_array($orderby, array('customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id'))) { |
|
478 | 478 | $_orderby = "$table.`$orderby`"; |
479 | - } elseif ( 'id' === strtolower( $orderby ) ) { |
|
479 | + } elseif ('id' === strtolower($orderby)) { |
|
480 | 480 | $_orderby = "$table.id"; |
481 | - } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) { |
|
482 | - $include = wp_parse_id_list( $this->query_vars['include'] ); |
|
483 | - $include_sql = implode( ',', $include ); |
|
481 | + } elseif ('include' === $orderby && !empty($this->query_vars['include'])) { |
|
482 | + $include = wp_parse_id_list($this->query_vars['include']); |
|
483 | + $include_sql = implode(',', $include); |
|
484 | 484 | $_orderby = "FIELD( $table.id, $include_sql )"; |
485 | 485 | } |
486 | 486 | |
@@ -495,12 +495,12 @@ discard block |
||
495 | 495 | * @param string $order The 'order' query variable. |
496 | 496 | * @return string The sanitized 'order' query variable. |
497 | 497 | */ |
498 | - protected function parse_order( $order ) { |
|
499 | - if ( ! is_string( $order ) || empty( $order ) ) { |
|
498 | + protected function parse_order($order) { |
|
499 | + if (!is_string($order) || empty($order)) { |
|
500 | 500 | return 'DESC'; |
501 | 501 | } |
502 | 502 | |
503 | - if ( 'ASC' === strtoupper( $order ) ) { |
|
503 | + if ('ASC' === strtoupper($order)) { |
|
504 | 504 | return 'ASC'; |
505 | 505 | } else { |
506 | 506 | return 'DESC'; |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords'=> "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | ); |
47 | 47 | |
48 | 48 | |
49 | - parent::__construct( $options ); |
|
49 | + parent::__construct($options); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | public function get_subscriptions() { |
58 | 58 | |
59 | 59 | // Prepare license args. |
60 | - $args = array( |
|
60 | + $args = array( |
|
61 | 61 | 'customer_in' => get_current_user_id(), |
62 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
63 | 63 | ); |
64 | 64 | |
65 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + return new GetPaid_Subscriptions_Query($args); |
|
66 | 66 | |
67 | 67 | } |
68 | 68 | |
@@ -75,14 +75,14 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return mixed|string|bool |
77 | 77 | */ |
78 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
79 | 79 | |
80 | 80 | // Ensure that the user is logged in. |
81 | - if ( ! is_user_logged_in() ) { |
|
81 | + if (!is_user_logged_in()) { |
|
82 | 82 | |
83 | 83 | return aui()->alert( |
84 | 84 | array( |
85 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
86 | 86 | 'type' => 'error', |
87 | 87 | ) |
88 | 88 | ); |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | } |
91 | 91 | |
92 | 92 | // Are we displaying a single subscription? |
93 | - if ( isset( $_GET['subscription'] ) ) { |
|
94 | - return $this->display_single_subscription( trim( $_GET['subscription'] ) ); |
|
93 | + if (isset($_GET['subscription'])) { |
|
94 | + return $this->display_single_subscription(trim($_GET['subscription'])); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Retrieve the user's subscriptions. |
@@ -101,27 +101,27 @@ discard block |
||
101 | 101 | ob_start(); |
102 | 102 | |
103 | 103 | // Backwards compatibility. |
104 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + do_action('wpinv_before_user_subscriptions'); |
|
105 | 105 | |
106 | 106 | // Display errors and notices. |
107 | 107 | wpinv_print_errors(); |
108 | 108 | |
109 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
110 | 110 | |
111 | 111 | // Print the table header. |
112 | 112 | $this->print_table_header(); |
113 | 113 | |
114 | 114 | // Print table body. |
115 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + $this->print_table_body($subscriptions->get_results()); |
|
116 | 116 | |
117 | 117 | // Print table footer. |
118 | 118 | $this->print_table_footer(); |
119 | 119 | |
120 | 120 | // Print the navigation. |
121 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + $this->print_navigation($subscriptions->get_total()); |
|
122 | 122 | |
123 | 123 | // Backwards compatibility. |
124 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + do_action('wpinv_after_user_subscriptions'); |
|
125 | 125 | |
126 | 126 | // Return the output. |
127 | 127 | return ob_get_clean(); |
@@ -136,13 +136,13 @@ discard block |
||
136 | 136 | public function get_subscriptions_table_columns() { |
137 | 137 | |
138 | 138 | $columns = array( |
139 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
140 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
141 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
142 | - 'status' => __( 'Status', 'invoicing' ), |
|
139 | + 'subscription' => __('Subscription', 'invoicing'), |
|
140 | + 'amount' => __('Amount', 'invoicing'), |
|
141 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
142 | + 'status' => __('Status', 'invoicing'), |
|
143 | 143 | ); |
144 | 144 | |
145 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
@@ -157,9 +157,9 @@ discard block |
||
157 | 157 | |
158 | 158 | <thead> |
159 | 159 | <tr> |
160 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
161 | - <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>"> |
|
162 | - <?php echo sanitize_text_field( $label ); ?> |
|
160 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
161 | + <th scope="col" class="getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>"> |
|
162 | + <?php echo sanitize_text_field($label); ?> |
|
163 | 163 | </th> |
164 | 164 | <?php endforeach; ?> |
165 | 165 | </tr> |
@@ -174,12 +174,12 @@ discard block |
||
174 | 174 | * |
175 | 175 | * @param WPInv_Subscription[] $subscriptions |
176 | 176 | */ |
177 | - public function print_table_body( $subscriptions ) { |
|
177 | + public function print_table_body($subscriptions) { |
|
178 | 178 | |
179 | - if ( empty( $subscriptions ) ) { |
|
179 | + if (empty($subscriptions)) { |
|
180 | 180 | $this->print_table_body_no_subscriptions(); |
181 | 181 | } else { |
182 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + $this->print_table_body_subscriptions($subscriptions); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } |
@@ -194,12 +194,12 @@ discard block |
||
194 | 194 | <tbody> |
195 | 195 | |
196 | 196 | <tr> |
197 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
197 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
198 | 198 | |
199 | 199 | <?php |
200 | 200 | echo aui()->alert( |
201 | 201 | array( |
202 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
203 | 203 | 'type' => 'warning', |
204 | 204 | ) |
205 | 205 | ); |
@@ -217,12 +217,12 @@ discard block |
||
217 | 217 | * |
218 | 218 | * @param WPInv_Subscription[] $subscriptions |
219 | 219 | */ |
220 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | + public function print_table_body_subscriptions($subscriptions) { |
|
221 | 221 | |
222 | 222 | ?> |
223 | 223 | <tbody> |
224 | 224 | |
225 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
225 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
226 | 226 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
227 | 227 | <?php |
228 | 228 | wpinv_get_template( |
@@ -248,27 +248,27 @@ discard block |
||
248 | 248 | * @since 1.0.0 |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function add_row_actions( $content, $subscription ) { |
|
251 | + public function add_row_actions($content, $subscription) { |
|
252 | 252 | |
253 | 253 | // Prepare row actions. |
254 | 254 | $actions = array(); |
255 | 255 | |
256 | 256 | // View subscription action. |
257 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ) ); |
|
258 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
257 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page')))); |
|
258 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
259 | 259 | |
260 | 260 | // Filter the actions. |
261 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
261 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
262 | 262 | |
263 | - $sanitized = array(); |
|
264 | - foreach ( $actions as $key => $action ) { |
|
265 | - $key = sanitize_html_class( $key ); |
|
266 | - $action = wp_kses_post( $action ); |
|
263 | + $sanitized = array(); |
|
264 | + foreach ($actions as $key => $action) { |
|
265 | + $key = sanitize_html_class($key); |
|
266 | + $action = wp_kses_post($action); |
|
267 | 267 | $sanitized[] = "<span class='$key'>$action</span>"; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
271 | - $row_actions .= implode( ' | ', $sanitized ); |
|
271 | + $row_actions .= implode(' | ', $sanitized); |
|
272 | 272 | $row_actions .= '</small>'; |
273 | 273 | |
274 | 274 | return $content . $row_actions; |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | |
285 | 285 | <tfoot> |
286 | 286 | <tr> |
287 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
288 | - <th class="getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>"> |
|
289 | - <?php echo sanitize_text_field( $label ); ?> |
|
287 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
288 | + <th class="getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>"> |
|
289 | + <?php echo sanitize_text_field($label); ?> |
|
290 | 290 | </th> |
291 | 291 | <?php endforeach; ?> |
292 | 292 | </tr> |
@@ -302,22 +302,22 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param int $total |
304 | 304 | */ |
305 | - public function print_navigation( $total ) { |
|
305 | + public function print_navigation($total) { |
|
306 | 306 | |
307 | - if ( $total < 1 ) { |
|
307 | + if ($total < 1) { |
|
308 | 308 | |
309 | 309 | // Out-of-bounds, run the query again without LIMIT for total count. |
310 | - $args = array( |
|
310 | + $args = array( |
|
311 | 311 | 'customer_in' => get_current_user_id(), |
312 | 312 | 'fields' => 'id', |
313 | 313 | ); |
314 | 314 | |
315 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
315 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
316 | 316 | $total = $count_query->get_total(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Abort if we do not have pages. |
320 | - if ( 2 > $total ) { |
|
320 | + if (2 > $total) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
@@ -329,9 +329,9 @@ discard block |
||
329 | 329 | |
330 | 330 | echo getpaid_paginate_links( |
331 | 331 | array( |
332 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
332 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
333 | 333 | 'format' => '?paged=%#%', |
334 | - 'total' => (int) ceil( $total / 10 ), |
|
334 | + 'total' => (int) ceil($total / 10), |
|
335 | 335 | ) |
336 | 336 | ); |
337 | 337 | ?> |
@@ -347,29 +347,29 @@ discard block |
||
347 | 347 | * |
348 | 348 | * @return array |
349 | 349 | */ |
350 | - public function get_single_subscription_columns( $subscription ) { |
|
350 | + public function get_single_subscription_columns($subscription) { |
|
351 | 351 | |
352 | 352 | // Prepare subscription detail columns. |
353 | 353 | $fields = apply_filters( |
354 | 354 | 'getpaid_single_subscription_details_fields', |
355 | 355 | array( |
356 | - 'status' => __( 'Status', 'invoicing' ), |
|
357 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
358 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
359 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
360 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
361 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
362 | - 'item' => __( 'Item', 'invoicing' ), |
|
356 | + 'status' => __('Status', 'invoicing'), |
|
357 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
358 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
359 | + 'start_date' => __('Start date', 'invoicing'), |
|
360 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
361 | + 'payments' => __('Payments', 'invoicing'), |
|
362 | + 'item' => __('Item', 'invoicing'), |
|
363 | 363 | ), |
364 | 364 | $subscription |
365 | 365 | ); |
366 | 366 | |
367 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
368 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
367 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
368 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
369 | 369 | } |
370 | 370 | |
371 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
372 | - unset( $fields['initial_amount'] ); |
|
371 | + if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) { |
|
372 | + unset($fields['initial_amount']); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | return $fields; |
@@ -382,16 +382,16 @@ discard block |
||
382 | 382 | * |
383 | 383 | * @return string |
384 | 384 | */ |
385 | - public function display_single_subscription( $subscription ) { |
|
385 | + public function display_single_subscription($subscription) { |
|
386 | 386 | |
387 | 387 | // Fetch the subscription. |
388 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
388 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
389 | 389 | |
390 | - if ( ! $subscription->get_id() ) { |
|
390 | + if (!$subscription->get_id()) { |
|
391 | 391 | |
392 | 392 | return aui()->alert( |
393 | 393 | array( |
394 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
394 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
395 | 395 | 'type' => 'error', |
396 | 396 | ) |
397 | 397 | ); |
@@ -399,11 +399,11 @@ discard block |
||
399 | 399 | } |
400 | 400 | |
401 | 401 | // Ensure that the user owns this subscription key. |
402 | - if ( get_current_user_id() != $subscription->get_customer_id() ) { |
|
402 | + if (get_current_user_id() != $subscription->get_customer_id()) { |
|
403 | 403 | |
404 | 404 | return aui()->alert( |
405 | 405 | array( |
406 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
406 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
407 | 407 | 'type' => 'error', |
408 | 408 | ) |
409 | 409 | ); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -if ( ! defined( 'ABSPATH' ) ) { |
|
8 | +if (!defined('ABSPATH')) { |
|
9 | 9 | exit; // Exit if accessed directly |
10 | 10 | } |
11 | 11 | |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @param WP_Post $post |
21 | 21 | */ |
22 | - public static function output( $post ) { |
|
22 | + public static function output($post) { |
|
23 | 23 | |
24 | 24 | // Fetch the invoice. |
25 | - $invoice = new WPInv_Invoice( $post ); |
|
25 | + $invoice = new WPInv_Invoice($post); |
|
26 | 26 | |
27 | - do_action( 'wpinv_metabox_resend_invoice_before', $invoice ); |
|
27 | + do_action('wpinv_metabox_resend_invoice_before', $invoice); |
|
28 | 28 | |
29 | 29 | $email_url = esc_url( |
30 | 30 | add_query_arg( |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | ); |
51 | 51 | |
52 | 52 | ?> |
53 | - <p class="wpi-meta-row wpi-resend-info"><?php _e( "This will send a copy of the invoice to the customer's email address.", 'invoicing' ); ?></p> |
|
54 | - <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e( 'Resend Invoice', 'invoicing' ); ?></a></p> |
|
55 | - <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p> |
|
53 | + <p class="wpi-meta-row wpi-resend-info"><?php _e("This will send a copy of the invoice to the customer's email address.", 'invoicing'); ?></p> |
|
54 | + <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo $email_url; ?>" class="button button-secondary"><?php _e('Resend Invoice', 'invoicing'); ?></a></p> |
|
55 | + <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo $reminder_url; ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p> |
|
56 | 56 | <?php |
57 | 57 | |
58 | - do_action( 'wpinv_metabox_resend_invoice_after', $invoice ); |
|
58 | + do_action('wpinv_metabox_resend_invoice_after', $invoice); |
|
59 | 59 | |
60 | 60 | } |
61 | 61 |
@@ -7,13 +7,13 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Current page. |
13 | -$current_page = empty( $_GET[ 'page' ] ) ? 1 : absint( $_GET[ 'page' ] ); |
|
13 | +$current_page = empty($_GET['page']) ? 1 : absint($_GET['page']); |
|
14 | 14 | |
15 | 15 | // Fires before displaying user invoices. |
16 | -do_action( 'wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages ); |
|
16 | +do_action('wpinv_before_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages); |
|
17 | 17 | |
18 | 18 | ?> |
19 | 19 | |
@@ -23,9 +23,9 @@ discard block |
||
23 | 23 | <thead> |
24 | 24 | <tr> |
25 | 25 | |
26 | - <?php foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : ?> |
|
27 | - <th class="<?php echo sanitize_html_class( $column_id ); ?> <?php echo ( ! empty( $column_name['class'] ) ? sanitize_html_class( $column_name['class'] ) : '');?> border-bottom-0"> |
|
28 | - <span class="nobr"><?php echo esc_html( $column_name['title'] ); ?></span> |
|
26 | + <?php foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : ?> |
|
27 | + <th class="<?php echo sanitize_html_class($column_id); ?> <?php echo (!empty($column_name['class']) ? sanitize_html_class($column_name['class']) : ''); ?> border-bottom-0"> |
|
28 | + <span class="nobr"><?php echo esc_html($column_name['title']); ?></span> |
|
29 | 29 | </th> |
30 | 30 | <?php endforeach; ?> |
31 | 31 | |
@@ -35,33 +35,33 @@ discard block |
||
35 | 35 | |
36 | 36 | |
37 | 37 | <tbody> |
38 | - <?php foreach ( $invoices->invoices as $invoice ) : ?> |
|
38 | + <?php foreach ($invoices->invoices as $invoice) : ?> |
|
39 | 39 | |
40 | 40 | <tr class="wpinv-item wpinv-item-<?php echo $invoice_status = $invoice->get_status(); ?>"> |
41 | 41 | <?php |
42 | 42 | |
43 | - foreach ( wpinv_get_user_invoices_columns() as $column_id => $column_name ) : |
|
43 | + foreach (wpinv_get_user_invoices_columns() as $column_id => $column_name) : |
|
44 | 44 | |
45 | - $column_id = sanitize_html_class( $column_id ); |
|
46 | - $class = empty( $column_name['class'] ) ? '' : sanitize_html_class( $column_name['class'] ); |
|
45 | + $column_id = sanitize_html_class($column_id); |
|
46 | + $class = empty($column_name['class']) ? '' : sanitize_html_class($column_name['class']); |
|
47 | 47 | |
48 | 48 | echo "<td class='$column_id $class'>"; |
49 | - switch ( $column_id ) { |
|
49 | + switch ($column_id) { |
|
50 | 50 | |
51 | 51 | case 'invoice-number': |
52 | - echo wpinv_invoice_link( $invoice ); |
|
52 | + echo wpinv_invoice_link($invoice); |
|
53 | 53 | break; |
54 | 54 | |
55 | 55 | case 'created-date': |
56 | - echo getpaid_format_date_value( $invoice->get_date_created() ); |
|
56 | + echo getpaid_format_date_value($invoice->get_date_created()); |
|
57 | 57 | break; |
58 | 58 | |
59 | 59 | case 'payment-date': |
60 | 60 | |
61 | - if ( $invoice->needs_payment() ) { |
|
61 | + if ($invoice->needs_payment()) { |
|
62 | 62 | echo "—"; |
63 | 63 | } else { |
64 | - echo getpaid_format_date_value( $invoice->get_date_completed() ); |
|
64 | + echo getpaid_format_date_value($invoice->get_date_completed()); |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | break; |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | break; |
73 | 73 | |
74 | 74 | case 'invoice-total': |
75 | - echo wpinv_price( wpinv_format_amount( $invoice->get_total() ) ); |
|
75 | + echo wpinv_price(wpinv_format_amount($invoice->get_total())); |
|
76 | 76 | |
77 | 77 | break; |
78 | 78 | |
@@ -82,39 +82,39 @@ discard block |
||
82 | 82 | |
83 | 83 | 'pay' => array( |
84 | 84 | 'url' => $invoice->get_checkout_payment_url(), |
85 | - 'name' => __( 'Pay Now', 'invoicing' ), |
|
85 | + 'name' => __('Pay Now', 'invoicing'), |
|
86 | 86 | 'class' => 'btn-success' |
87 | 87 | ), |
88 | 88 | |
89 | 89 | 'print' => array( |
90 | 90 | 'url' => $invoice->get_view_url(), |
91 | - 'name' => __( 'View Invoice', 'invoicing' ), |
|
91 | + 'name' => __('View Invoice', 'invoicing'), |
|
92 | 92 | 'class' => 'btn-secondary', |
93 | 93 | 'attrs' => 'target="_blank"' |
94 | 94 | ) |
95 | 95 | ); |
96 | 96 | |
97 | - if ( ! $invoice->needs_payment() ) { |
|
98 | - unset( $actions['pay'] ); |
|
97 | + if (!$invoice->needs_payment()) { |
|
98 | + unset($actions['pay']); |
|
99 | 99 | } |
100 | 100 | |
101 | - $actions = apply_filters( 'wpinv_user_invoices_actions', $actions, $invoice ); |
|
101 | + $actions = apply_filters('wpinv_user_invoices_actions', $actions, $invoice); |
|
102 | 102 | |
103 | - foreach ( $actions as $key => $action ) { |
|
103 | + foreach ($actions as $key => $action) { |
|
104 | 104 | $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; |
105 | - echo '<a href="' . esc_url( $action['url'] ) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class( $key ) . '" ' . ( !empty($action['attrs']) ? $action['attrs'] : '' ) . '>' . $action['name'] . '</a>'; |
|
105 | + echo '<a href="' . esc_url($action['url']) . '" class="btn btn-sm btn-block ' . $class . ' ' . sanitize_html_class($key) . '" ' . (!empty($action['attrs']) ? $action['attrs'] : '') . '>' . $action['name'] . '</a>'; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | break; |
109 | 109 | |
110 | 110 | default: |
111 | - do_action( "wpinv_user_invoices_column_$column_id", $invoice ); |
|
111 | + do_action("wpinv_user_invoices_column_$column_id", $invoice); |
|
112 | 112 | break; |
113 | 113 | |
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | - do_action( "wpinv_user_invoices_column_after_$column_id", $invoice ); |
|
117 | + do_action("wpinv_user_invoices_column_after_$column_id", $invoice); |
|
118 | 118 | |
119 | 119 | echo '</td>'; |
120 | 120 | |
@@ -127,20 +127,20 @@ discard block |
||
127 | 127 | </tbody> |
128 | 128 | </table> |
129 | 129 | |
130 | - <?php do_action( 'wpinv_before_user_invoices_pagination' ); ?> |
|
130 | + <?php do_action('wpinv_before_user_invoices_pagination'); ?> |
|
131 | 131 | |
132 | - <?php if ( 1 < $invoices->max_num_pages ) : ?> |
|
132 | + <?php if (1 < $invoices->max_num_pages) : ?> |
|
133 | 133 | <div class="invoicing-Pagination"> |
134 | 134 | <?php |
135 | 135 | $big = 999999; |
136 | 136 | |
137 | - echo paginate_links( array( |
|
138 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
137 | + echo paginate_links(array( |
|
138 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
139 | 139 | 'format' => '?paged=%#%', |
140 | 140 | 'total' => $invoices->max_num_pages, |
141 | - ) ); |
|
141 | + )); |
|
142 | 142 | ?> |
143 | 143 | </div> |
144 | 144 | <?php endif; ?> |
145 | 145 | |
146 | -<?php do_action( 'wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages ); ?> |
|
146 | +<?php do_action('wpinv_after_user_invoices', $invoices->invoices, $invoices->total, $invoices->max_num_pages); ?> |
@@ -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 | final class WPInv_Legacy_Invoice { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * Invoice id. |
18 | 18 | */ |
19 | - public $ID = 0; |
|
19 | + public $ID = 0; |
|
20 | 20 | |
21 | 21 | /** |
22 | 22 | * The title of the invoice. Usually the invoice number. |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | /** |
133 | 133 | * The invoice status. |
134 | 134 | */ |
135 | - public $status = 'wpi-pending'; |
|
135 | + public $status = 'wpi-pending'; |
|
136 | 136 | |
137 | 137 | /** |
138 | 138 | * Same as self::$status. |
@@ -259,17 +259,17 @@ discard block |
||
259 | 259 | */ |
260 | 260 | public $parent_invoice = 0; |
261 | 261 | |
262 | - public function __construct( $invoice_id = false ) { |
|
263 | - if( empty( $invoice_id ) ) { |
|
262 | + public function __construct($invoice_id = false) { |
|
263 | + if (empty($invoice_id)) { |
|
264 | 264 | return false; |
265 | 265 | } |
266 | 266 | |
267 | - $this->setup_invoice( $invoice_id ); |
|
267 | + $this->setup_invoice($invoice_id); |
|
268 | 268 | } |
269 | 269 | |
270 | - public function get( $key ) { |
|
271 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
272 | - $value = call_user_func( array( $this, 'get_' . $key ) ); |
|
270 | + public function get($key) { |
|
271 | + if (method_exists($this, 'get_' . $key)) { |
|
272 | + $value = call_user_func(array($this, 'get_' . $key)); |
|
273 | 273 | } else { |
274 | 274 | $value = $this->$key; |
275 | 275 | } |
@@ -277,51 +277,51 @@ discard block |
||
277 | 277 | return $value; |
278 | 278 | } |
279 | 279 | |
280 | - public function set( $key, $value ) { |
|
281 | - $ignore = array( 'items', 'cart_details', 'fees', '_ID' ); |
|
280 | + public function set($key, $value) { |
|
281 | + $ignore = array('items', 'cart_details', 'fees', '_ID'); |
|
282 | 282 | |
283 | - if ( $key === 'status' ) { |
|
283 | + if ($key === 'status') { |
|
284 | 284 | $this->old_status = $this->status; |
285 | 285 | } |
286 | 286 | |
287 | - if ( ! in_array( $key, $ignore ) ) { |
|
288 | - $this->pending[ $key ] = $value; |
|
287 | + if (!in_array($key, $ignore)) { |
|
288 | + $this->pending[$key] = $value; |
|
289 | 289 | } |
290 | 290 | |
291 | - if( '_ID' !== $key ) { |
|
291 | + if ('_ID' !== $key) { |
|
292 | 292 | $this->$key = $value; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - public function _isset( $name ) { |
|
297 | - if ( property_exists( $this, $name) ) { |
|
298 | - return false === empty( $this->$name ); |
|
296 | + public function _isset($name) { |
|
297 | + if (property_exists($this, $name)) { |
|
298 | + return false === empty($this->$name); |
|
299 | 299 | } else { |
300 | 300 | return null; |
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | - private function setup_invoice( $invoice_id ) { |
|
304 | + private function setup_invoice($invoice_id) { |
|
305 | 305 | $this->pending = array(); |
306 | 306 | |
307 | - if ( empty( $invoice_id ) ) { |
|
307 | + if (empty($invoice_id)) { |
|
308 | 308 | return false; |
309 | 309 | } |
310 | 310 | |
311 | - $invoice = get_post( $invoice_id ); |
|
311 | + $invoice = get_post($invoice_id); |
|
312 | 312 | |
313 | - if( !$invoice || is_wp_error( $invoice ) ) { |
|
313 | + if (!$invoice || is_wp_error($invoice)) { |
|
314 | 314 | return false; |
315 | 315 | } |
316 | 316 | |
317 | - if( !('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type) ) { |
|
317 | + if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) { |
|
318 | 318 | return false; |
319 | 319 | } |
320 | 320 | |
321 | - do_action( 'wpinv_pre_setup_invoice', $this, $invoice_id ); |
|
321 | + do_action('wpinv_pre_setup_invoice', $this, $invoice_id); |
|
322 | 322 | |
323 | 323 | // Primary Identifier |
324 | - $this->ID = absint( $invoice_id ); |
|
324 | + $this->ID = absint($invoice_id); |
|
325 | 325 | $this->post_type = $invoice->post_type; |
326 | 326 | |
327 | 327 | // We have a payment, get the generic payment_meta item to reduce calls to it |
@@ -331,14 +331,14 @@ discard block |
||
331 | 331 | $this->completed_date = $this->setup_completed_date(); |
332 | 332 | $this->status = $invoice->post_status; |
333 | 333 | |
334 | - if ( 'future' == $this->status ) { |
|
334 | + if ('future' == $this->status) { |
|
335 | 335 | $this->status = 'publish'; |
336 | 336 | } |
337 | 337 | |
338 | 338 | $this->post_status = $this->status; |
339 | 339 | $this->mode = $this->setup_mode(); |
340 | 340 | $this->parent_invoice = $invoice->post_parent; |
341 | - $this->post_name = $this->setup_post_name( $invoice ); |
|
341 | + $this->post_name = $this->setup_post_name($invoice); |
|
342 | 342 | $this->status_nicename = $this->setup_status_nicename($invoice->post_status); |
343 | 343 | |
344 | 344 | // Items |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | |
362 | 362 | // User based |
363 | 363 | $this->ip = $this->setup_ip(); |
364 | - $this->user_id = !empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();///$this->setup_user_id(); |
|
365 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
364 | + $this->user_id = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id(); ///$this->setup_user_id(); |
|
365 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
366 | 366 | |
367 | 367 | $this->user_info = $this->setup_user_info(); |
368 | 368 | |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | $this->company = $this->user_info['company']; |
372 | 372 | $this->vat_number = $this->user_info['vat_number']; |
373 | 373 | $this->vat_rate = $this->user_info['vat_rate']; |
374 | - $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
374 | + $this->adddress_confirmed = $this->user_info['adddress_confirmed']; |
|
375 | 375 | $this->address = $this->user_info['address']; |
376 | 376 | $this->city = $this->user_info['city']; |
377 | 377 | $this->country = $this->user_info['country']; |
@@ -386,39 +386,39 @@ discard block |
||
386 | 386 | // Other Identifiers |
387 | 387 | $this->key = $this->setup_invoice_key(); |
388 | 388 | $this->number = $this->setup_invoice_number(); |
389 | - $this->title = !empty( $invoice->post_title ) ? $invoice->post_title : $this->number; |
|
389 | + $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number; |
|
390 | 390 | |
391 | - $this->full_name = trim( $this->first_name . ' '. $this->last_name ); |
|
391 | + $this->full_name = trim($this->first_name . ' ' . $this->last_name); |
|
392 | 392 | |
393 | 393 | // Allow extensions to add items to this object via hook |
394 | - do_action( 'wpinv_setup_invoice', $this, $invoice_id ); |
|
394 | + do_action('wpinv_setup_invoice', $this, $invoice_id); |
|
395 | 395 | |
396 | 396 | return true; |
397 | 397 | } |
398 | 398 | |
399 | - private function setup_status_nicename( $status ) { |
|
400 | - $all_invoice_statuses = wpinv_get_invoice_statuses( true, true, $this ); |
|
399 | + private function setup_status_nicename($status) { |
|
400 | + $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this); |
|
401 | 401 | |
402 | - if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) { |
|
403 | - $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
402 | + if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) { |
|
403 | + $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses(); |
|
404 | 404 | } |
405 | - $status = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' ); |
|
405 | + $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing'); |
|
406 | 406 | |
407 | - return apply_filters( 'setup_status_nicename', $status ); |
|
407 | + return apply_filters('setup_status_nicename', $status); |
|
408 | 408 | } |
409 | 409 | |
410 | - private function setup_post_name( $post = NULL ) { |
|
410 | + private function setup_post_name($post = NULL) { |
|
411 | 411 | global $wpdb; |
412 | 412 | |
413 | 413 | $post_name = ''; |
414 | 414 | |
415 | - if ( !empty( $post ) ) { |
|
416 | - if( !empty( $post->post_name ) ) { |
|
415 | + if (!empty($post)) { |
|
416 | + if (!empty($post->post_name)) { |
|
417 | 417 | $post_name = $post->post_name; |
418 | - } else if ( !empty( $post->ID ) ) { |
|
419 | - $post_name = wpinv_generate_post_name( $post->ID ); |
|
418 | + } else if (!empty($post->ID)) { |
|
419 | + $post_name = wpinv_generate_post_name($post->ID); |
|
420 | 420 | |
421 | - $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) ); |
|
421 | + $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID)); |
|
422 | 422 | } |
423 | 423 | } |
424 | 424 | |
@@ -426,12 +426,12 @@ discard block |
||
426 | 426 | } |
427 | 427 | |
428 | 428 | private function setup_due_date() { |
429 | - $due_date = $this->get_meta( '_wpinv_due_date' ); |
|
429 | + $due_date = $this->get_meta('_wpinv_due_date'); |
|
430 | 430 | |
431 | - if ( empty( $due_date ) ) { |
|
432 | - $overdue_time = strtotime( $this->date ) + ( DAY_IN_SECONDS * absint( wpinv_get_option( 'overdue_days' ) ) ); |
|
433 | - $due_date = date_i18n( 'Y-m-d', $overdue_time ); |
|
434 | - } else if ( $due_date == 'none' ) { |
|
431 | + if (empty($due_date)) { |
|
432 | + $overdue_time = strtotime($this->date) + (DAY_IN_SECONDS * absint(wpinv_get_option('overdue_days'))); |
|
433 | + $due_date = date_i18n('Y-m-d', $overdue_time); |
|
434 | + } else if ($due_date == 'none') { |
|
435 | 435 | $due_date = ''; |
436 | 436 | } |
437 | 437 | |
@@ -439,67 +439,67 @@ discard block |
||
439 | 439 | } |
440 | 440 | |
441 | 441 | private function setup_completed_date() { |
442 | - $invoice = get_post( $this->ID ); |
|
442 | + $invoice = get_post($this->ID); |
|
443 | 443 | |
444 | - if ( 'wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status ) { |
|
444 | + if ('wpi-pending' == $invoice->post_status || 'preapproved' == $invoice->post_status) { |
|
445 | 445 | return false; // This invoice was never paid |
446 | 446 | } |
447 | 447 | |
448 | - $date = ( $date = $this->get_meta( '_wpinv_completed_date', true ) ) ? $date : $invoice->modified_date; |
|
448 | + $date = ($date = $this->get_meta('_wpinv_completed_date', true)) ? $date : $invoice->modified_date; |
|
449 | 449 | |
450 | 450 | return $date; |
451 | 451 | } |
452 | 452 | |
453 | 453 | private function setup_cart_details() { |
454 | - $cart_details = isset( $this->payment_meta['cart_details'] ) ? maybe_unserialize( $this->payment_meta['cart_details'] ) : array(); |
|
454 | + $cart_details = isset($this->payment_meta['cart_details']) ? maybe_unserialize($this->payment_meta['cart_details']) : array(); |
|
455 | 455 | return $cart_details; |
456 | 456 | } |
457 | 457 | |
458 | 458 | public function array_convert() { |
459 | - return get_object_vars( $this ); |
|
459 | + return get_object_vars($this); |
|
460 | 460 | } |
461 | 461 | |
462 | 462 | private function setup_items() { |
463 | - $items = isset( $this->payment_meta['items'] ) ? maybe_unserialize( $this->payment_meta['items'] ) : array(); |
|
463 | + $items = isset($this->payment_meta['items']) ? maybe_unserialize($this->payment_meta['items']) : array(); |
|
464 | 464 | return $items; |
465 | 465 | } |
466 | 466 | |
467 | 467 | private function setup_fees() { |
468 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
468 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
469 | 469 | return $payment_fees; |
470 | 470 | } |
471 | 471 | |
472 | 472 | private function setup_currency() { |
473 | - $currency = isset( $this->payment_meta['currency'] ) ? $this->payment_meta['currency'] : apply_filters( 'wpinv_currency_default', wpinv_get_currency(), $this ); |
|
473 | + $currency = isset($this->payment_meta['currency']) ? $this->payment_meta['currency'] : apply_filters('wpinv_currency_default', wpinv_get_currency(), $this); |
|
474 | 474 | return $currency; |
475 | 475 | } |
476 | 476 | |
477 | 477 | private function setup_discount() { |
478 | 478 | //$discount = $this->get_meta( '_wpinv_discount', true ); |
479 | - $discount = (float)$this->subtotal - ( (float)$this->total - (float)$this->tax - (float)$this->fees_total ); |
|
480 | - if ( $discount < 0 ) { |
|
479 | + $discount = (float) $this->subtotal - ((float) $this->total - (float) $this->tax - (float) $this->fees_total); |
|
480 | + if ($discount < 0) { |
|
481 | 481 | $discount = 0; |
482 | 482 | } |
483 | - $discount = wpinv_round_amount( $discount ); |
|
483 | + $discount = wpinv_round_amount($discount); |
|
484 | 484 | |
485 | 485 | return $discount; |
486 | 486 | } |
487 | 487 | |
488 | 488 | private function setup_discount_code() { |
489 | - $discount_code = !empty( $this->discounts ) ? $this->discounts : $this->get_meta( '_wpinv_discount_code', true ); |
|
489 | + $discount_code = !empty($this->discounts) ? $this->discounts : $this->get_meta('_wpinv_discount_code', true); |
|
490 | 490 | return $discount_code; |
491 | 491 | } |
492 | 492 | |
493 | 493 | private function setup_tax() { |
494 | 494 | |
495 | - $tax = $this->get_meta( '_wpinv_tax', true ); |
|
495 | + $tax = $this->get_meta('_wpinv_tax', true); |
|
496 | 496 | |
497 | 497 | // We don't have tax as it's own meta and no meta was passed |
498 | - if ( '' === $tax ) { |
|
499 | - $tax = isset( $this->payment_meta['tax'] ) ? $this->payment_meta['tax'] : 0; |
|
498 | + if ('' === $tax) { |
|
499 | + $tax = isset($this->payment_meta['tax']) ? $this->payment_meta['tax'] : 0; |
|
500 | 500 | } |
501 | 501 | |
502 | - if ( $tax < 0 || ! $this->is_taxable() ) { |
|
502 | + if ($tax < 0 || !$this->is_taxable()) { |
|
503 | 503 | $tax = 0; |
504 | 504 | } |
505 | 505 | |
@@ -510,16 +510,16 @@ discard block |
||
510 | 510 | * If taxes are enabled, allow users to enable/disable taxes per invoice. |
511 | 511 | */ |
512 | 512 | private function setup_is_taxable() { |
513 | - return (int) $this->get_meta( '_wpinv_disable_taxes', true ); |
|
513 | + return (int) $this->get_meta('_wpinv_disable_taxes', true); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | private function setup_subtotal() { |
517 | 517 | $subtotal = 0; |
518 | 518 | $cart_details = $this->cart_details; |
519 | 519 | |
520 | - if ( is_array( $cart_details ) ) { |
|
521 | - foreach ( $cart_details as $item ) { |
|
522 | - if ( isset( $item['subtotal'] ) ) { |
|
520 | + if (is_array($cart_details)) { |
|
521 | + foreach ($cart_details as $item) { |
|
522 | + if (isset($item['subtotal'])) { |
|
523 | 523 | $subtotal += $item['subtotal']; |
524 | 524 | } |
525 | 525 | } |
@@ -533,23 +533,23 @@ discard block |
||
533 | 533 | } |
534 | 534 | |
535 | 535 | private function setup_discounts() { |
536 | - $discounts = ! empty( $this->payment_meta['user_info']['discount'] ) ? $this->payment_meta['user_info']['discount'] : array(); |
|
536 | + $discounts = !empty($this->payment_meta['user_info']['discount']) ? $this->payment_meta['user_info']['discount'] : array(); |
|
537 | 537 | return $discounts; |
538 | 538 | } |
539 | 539 | |
540 | 540 | private function setup_total() { |
541 | - $amount = $this->get_meta( '_wpinv_total', true ); |
|
541 | + $amount = $this->get_meta('_wpinv_total', true); |
|
542 | 542 | |
543 | - if ( empty( $amount ) && '0.00' != $amount ) { |
|
544 | - $meta = $this->get_meta( '_wpinv_payment_meta', true ); |
|
545 | - $meta = maybe_unserialize( $meta ); |
|
543 | + if (empty($amount) && '0.00' != $amount) { |
|
544 | + $meta = $this->get_meta('_wpinv_payment_meta', true); |
|
545 | + $meta = maybe_unserialize($meta); |
|
546 | 546 | |
547 | - if ( isset( $meta['amount'] ) ) { |
|
547 | + if (isset($meta['amount'])) { |
|
548 | 548 | $amount = $meta['amount']; |
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - if($amount < 0){ |
|
552 | + if ($amount < 0) { |
|
553 | 553 | $amount = 0; |
554 | 554 | } |
555 | 555 | |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | } |
558 | 558 | |
559 | 559 | private function setup_mode() { |
560 | - return $this->get_meta( '_wpinv_mode' ); |
|
560 | + return $this->get_meta('_wpinv_mode'); |
|
561 | 561 | } |
562 | 562 | |
563 | 563 | private function setup_gateway() { |
564 | - $gateway = $this->get_meta( '_wpinv_gateway' ); |
|
564 | + $gateway = $this->get_meta('_wpinv_gateway'); |
|
565 | 565 | |
566 | - if ( empty( $gateway ) && 'publish' === $this->status ) { |
|
566 | + if (empty($gateway) && 'publish' === $this->status) { |
|
567 | 567 | $gateway = 'manual'; |
568 | 568 | } |
569 | 569 | |
@@ -571,23 +571,23 @@ discard block |
||
571 | 571 | } |
572 | 572 | |
573 | 573 | private function setup_gateway_title() { |
574 | - $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway ); |
|
574 | + $gateway_title = wpinv_get_gateway_checkout_label($this->gateway); |
|
575 | 575 | return $gateway_title; |
576 | 576 | } |
577 | 577 | |
578 | 578 | private function setup_transaction_id() { |
579 | - $transaction_id = $this->get_meta( '_wpinv_transaction_id' ); |
|
579 | + $transaction_id = $this->get_meta('_wpinv_transaction_id'); |
|
580 | 580 | |
581 | - if ( empty( $transaction_id ) || (int) $transaction_id === (int) $this->ID ) { |
|
581 | + if (empty($transaction_id) || (int) $transaction_id === (int) $this->ID) { |
|
582 | 582 | $gateway = $this->gateway; |
583 | - $transaction_id = apply_filters( 'wpinv_get_invoice_transaction_id-' . $gateway, $this->ID ); |
|
583 | + $transaction_id = apply_filters('wpinv_get_invoice_transaction_id-' . $gateway, $this->ID); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | return $transaction_id; |
587 | 587 | } |
588 | 588 | |
589 | 589 | private function setup_ip() { |
590 | - $ip = $this->get_meta( '_wpinv_user_ip' ); |
|
590 | + $ip = $this->get_meta('_wpinv_user_ip'); |
|
591 | 591 | return $ip; |
592 | 592 | } |
593 | 593 | |
@@ -597,62 +597,62 @@ discard block |
||
597 | 597 | ///} |
598 | 598 | |
599 | 599 | private function setup_first_name() { |
600 | - $first_name = $this->get_meta( '_wpinv_first_name' ); |
|
600 | + $first_name = $this->get_meta('_wpinv_first_name'); |
|
601 | 601 | return $first_name; |
602 | 602 | } |
603 | 603 | |
604 | 604 | private function setup_last_name() { |
605 | - $last_name = $this->get_meta( '_wpinv_last_name' ); |
|
605 | + $last_name = $this->get_meta('_wpinv_last_name'); |
|
606 | 606 | return $last_name; |
607 | 607 | } |
608 | 608 | |
609 | 609 | private function setup_company() { |
610 | - $company = $this->get_meta( '_wpinv_company' ); |
|
610 | + $company = $this->get_meta('_wpinv_company'); |
|
611 | 611 | return $company; |
612 | 612 | } |
613 | 613 | |
614 | 614 | private function setup_vat_number() { |
615 | - $vat_number = $this->get_meta( '_wpinv_vat_number' ); |
|
615 | + $vat_number = $this->get_meta('_wpinv_vat_number'); |
|
616 | 616 | return $vat_number; |
617 | 617 | } |
618 | 618 | |
619 | 619 | private function setup_vat_rate() { |
620 | - $vat_rate = $this->get_meta( '_wpinv_vat_rate' ); |
|
620 | + $vat_rate = $this->get_meta('_wpinv_vat_rate'); |
|
621 | 621 | return $vat_rate; |
622 | 622 | } |
623 | 623 | |
624 | 624 | private function setup_adddress_confirmed() { |
625 | - $adddress_confirmed = $this->get_meta( '_wpinv_adddress_confirmed' ); |
|
625 | + $adddress_confirmed = $this->get_meta('_wpinv_adddress_confirmed'); |
|
626 | 626 | return $adddress_confirmed; |
627 | 627 | } |
628 | 628 | |
629 | 629 | private function setup_phone() { |
630 | - $phone = $this->get_meta( '_wpinv_phone' ); |
|
630 | + $phone = $this->get_meta('_wpinv_phone'); |
|
631 | 631 | return $phone; |
632 | 632 | } |
633 | 633 | |
634 | 634 | private function setup_address() { |
635 | - $address = $this->get_meta( '_wpinv_address', true ); |
|
635 | + $address = $this->get_meta('_wpinv_address', true); |
|
636 | 636 | return $address; |
637 | 637 | } |
638 | 638 | |
639 | 639 | private function setup_city() { |
640 | - $city = $this->get_meta( '_wpinv_city', true ); |
|
640 | + $city = $this->get_meta('_wpinv_city', true); |
|
641 | 641 | return $city; |
642 | 642 | } |
643 | 643 | |
644 | 644 | private function setup_country() { |
645 | - $country = $this->get_meta( '_wpinv_country', true ); |
|
645 | + $country = $this->get_meta('_wpinv_country', true); |
|
646 | 646 | return $country; |
647 | 647 | } |
648 | 648 | |
649 | 649 | private function setup_state() { |
650 | - $state = $this->get_meta( '_wpinv_state', true ); |
|
650 | + $state = $this->get_meta('_wpinv_state', true); |
|
651 | 651 | return $state; |
652 | 652 | } |
653 | 653 | |
654 | 654 | private function setup_zip() { |
655 | - $zip = $this->get_meta( '_wpinv_zip', true ); |
|
655 | + $zip = $this->get_meta('_wpinv_zip', true); |
|
656 | 656 | return $zip; |
657 | 657 | } |
658 | 658 | |
@@ -661,7 +661,7 @@ discard block |
||
661 | 661 | 'user_id' => $this->user_id, |
662 | 662 | 'first_name' => $this->first_name, |
663 | 663 | 'last_name' => $this->last_name, |
664 | - 'email' => get_the_author_meta( 'email', $this->user_id ), |
|
664 | + 'email' => get_the_author_meta('email', $this->user_id), |
|
665 | 665 | 'phone' => $this->phone, |
666 | 666 | 'address' => $this->address, |
667 | 667 | 'city' => $this->city, |
@@ -676,12 +676,12 @@ discard block |
||
676 | 676 | ); |
677 | 677 | |
678 | 678 | $user_info = array(); |
679 | - if ( isset( $this->payment_meta['user_info'] ) ) { |
|
680 | - $user_info = maybe_unserialize( $this->payment_meta['user_info'] ); |
|
679 | + if (isset($this->payment_meta['user_info'])) { |
|
680 | + $user_info = maybe_unserialize($this->payment_meta['user_info']); |
|
681 | 681 | |
682 | - if ( !empty( $user_info ) && isset( $user_info['user_id'] ) && $post = get_post( $this->ID ) ) { |
|
682 | + if (!empty($user_info) && isset($user_info['user_id']) && $post = get_post($this->ID)) { |
|
683 | 683 | $this->user_id = $post->post_author; |
684 | - $this->email = get_the_author_meta( 'email', $this->user_id ); |
|
684 | + $this->email = get_the_author_meta('email', $this->user_id); |
|
685 | 685 | |
686 | 686 | $user_info['user_id'] = $this->user_id; |
687 | 687 | $user_info['email'] = $this->email; |
@@ -690,13 +690,13 @@ discard block |
||
690 | 690 | } |
691 | 691 | } |
692 | 692 | |
693 | - $user_info = wp_parse_args( $user_info, $defaults ); |
|
693 | + $user_info = wp_parse_args($user_info, $defaults); |
|
694 | 694 | |
695 | 695 | // Get the user, but only if it's been created |
696 | - $user = get_userdata( $this->user_id ); |
|
696 | + $user = get_userdata($this->user_id); |
|
697 | 697 | |
698 | - if ( !empty( $user ) && $user->ID > 0 ) { |
|
699 | - if ( empty( $user_info ) ) { |
|
698 | + if (!empty($user) && $user->ID > 0) { |
|
699 | + if (empty($user_info)) { |
|
700 | 700 | $user_info = array( |
701 | 701 | 'user_id' => $user->ID, |
702 | 702 | 'first_name' => $user->first_name, |
@@ -705,23 +705,23 @@ discard block |
||
705 | 705 | 'discount' => '', |
706 | 706 | ); |
707 | 707 | } else { |
708 | - foreach ( $user_info as $key => $value ) { |
|
709 | - if ( ! empty( $value ) ) { |
|
708 | + foreach ($user_info as $key => $value) { |
|
709 | + if (!empty($value)) { |
|
710 | 710 | continue; |
711 | 711 | } |
712 | 712 | |
713 | - switch( $key ) { |
|
713 | + switch ($key) { |
|
714 | 714 | case 'user_id': |
715 | - $user_info[ $key ] = $user->ID; |
|
715 | + $user_info[$key] = $user->ID; |
|
716 | 716 | break; |
717 | 717 | case 'first_name': |
718 | - $user_info[ $key ] = $user->first_name; |
|
718 | + $user_info[$key] = $user->first_name; |
|
719 | 719 | break; |
720 | 720 | case 'last_name': |
721 | - $user_info[ $key ] = $user->last_name; |
|
721 | + $user_info[$key] = $user->last_name; |
|
722 | 722 | break; |
723 | 723 | case 'email': |
724 | - $user_info[ $key ] = $user->user_email; |
|
724 | + $user_info[$key] = $user->user_email; |
|
725 | 725 | break; |
726 | 726 | } |
727 | 727 | } |
@@ -732,25 +732,25 @@ discard block |
||
732 | 732 | } |
733 | 733 | |
734 | 734 | private function setup_invoice_key() { |
735 | - $key = $this->get_meta( '_wpinv_key', true ); |
|
735 | + $key = $this->get_meta('_wpinv_key', true); |
|
736 | 736 | |
737 | 737 | return $key; |
738 | 738 | } |
739 | 739 | |
740 | 740 | private function setup_invoice_number() { |
741 | - $number = $this->get_meta( '_wpinv_number', true ); |
|
741 | + $number = $this->get_meta('_wpinv_number', true); |
|
742 | 742 | |
743 | - if ( !$number ) { |
|
743 | + if (!$number) { |
|
744 | 744 | $number = $this->ID; |
745 | 745 | |
746 | - if ( $this->status == 'auto-draft' ) { |
|
747 | - if ( wpinv_sequential_number_active( $this->post_type ) ) { |
|
748 | - $next_number = wpinv_get_next_invoice_number( $this->post_type ); |
|
746 | + if ($this->status == 'auto-draft') { |
|
747 | + if (wpinv_sequential_number_active($this->post_type)) { |
|
748 | + $next_number = wpinv_get_next_invoice_number($this->post_type); |
|
749 | 749 | $number = $next_number; |
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
753 | - $number = wpinv_format_invoice_number( $number, $this->post_type ); |
|
753 | + $number = wpinv_format_invoice_number($number, $this->post_type); |
|
754 | 754 | } |
755 | 755 | |
756 | 756 | return $number; |
@@ -759,10 +759,10 @@ discard block |
||
759 | 759 | private function insert_invoice() { |
760 | 760 | global $wpdb; |
761 | 761 | |
762 | - if ( empty( $this->post_type ) ) { |
|
763 | - if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) { |
|
762 | + if (empty($this->post_type)) { |
|
763 | + if (!empty($this->ID) && $post_type = get_post_type($this->ID)) { |
|
764 | 764 | $this->post_type = $post_type; |
765 | - } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) { |
|
765 | + } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) { |
|
766 | 766 | $this->post_type = $post_type; |
767 | 767 | } else { |
768 | 768 | $this->post_type = 'wpi_invoice'; |
@@ -770,16 +770,16 @@ discard block |
||
770 | 770 | } |
771 | 771 | |
772 | 772 | $invoice_number = $this->ID; |
773 | - if ( $number = $this->get_meta( '_wpinv_number', true ) ) { |
|
773 | + if ($number = $this->get_meta('_wpinv_number', true)) { |
|
774 | 774 | $invoice_number = $number; |
775 | 775 | } |
776 | 776 | |
777 | - if ( empty( $this->key ) ) { |
|
777 | + if (empty($this->key)) { |
|
778 | 778 | $this->key = self::generate_key(); |
779 | 779 | $this->pending['key'] = $this->key; |
780 | 780 | } |
781 | 781 | |
782 | - if ( empty( $this->ip ) ) { |
|
782 | + if (empty($this->ip)) { |
|
783 | 783 | $this->ip = wpinv_get_ip(); |
784 | 784 | $this->pending['ip'] = $this->ip; |
785 | 785 | } |
@@ -816,60 +816,60 @@ discard block |
||
816 | 816 | 'post_status' => $this->status, |
817 | 817 | 'post_author' => $this->user_id, |
818 | 818 | 'post_type' => $this->post_type, |
819 | - 'post_date' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ), |
|
820 | - 'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ), |
|
819 | + 'post_date' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'), |
|
820 | + 'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1), |
|
821 | 821 | 'post_parent' => $this->parent_invoice, |
822 | 822 | ); |
823 | - $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this ); |
|
823 | + $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this); |
|
824 | 824 | |
825 | 825 | // Create a blank invoice |
826 | - if ( !empty( $this->ID ) ) { |
|
827 | - $args['ID'] = $this->ID; |
|
826 | + if (!empty($this->ID)) { |
|
827 | + $args['ID'] = $this->ID; |
|
828 | 828 | |
829 | - $invoice_id = wp_update_post( $args, true ); |
|
829 | + $invoice_id = wp_update_post($args, true); |
|
830 | 830 | } else { |
831 | - $invoice_id = wp_insert_post( $args, true ); |
|
831 | + $invoice_id = wp_insert_post($args, true); |
|
832 | 832 | } |
833 | 833 | |
834 | - if ( is_wp_error( $invoice_id ) ) { |
|
834 | + if (is_wp_error($invoice_id)) { |
|
835 | 835 | return false; |
836 | 836 | } |
837 | 837 | |
838 | - if ( !empty( $invoice_id ) ) { |
|
838 | + if (!empty($invoice_id)) { |
|
839 | 839 | $this->ID = $invoice_id; |
840 | 840 | $this->_ID = $invoice_id; |
841 | 841 | |
842 | - $this->payment_meta = apply_filters( 'wpinv_payment_meta', $this->payment_meta, $payment_data ); |
|
843 | - if ( ! empty( $this->payment_meta['fees'] ) ) { |
|
844 | - $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] ); |
|
845 | - foreach( $this->fees as $fee ) { |
|
846 | - $this->increase_fees( $fee['amount'] ); |
|
842 | + $this->payment_meta = apply_filters('wpinv_payment_meta', $this->payment_meta, $payment_data); |
|
843 | + if (!empty($this->payment_meta['fees'])) { |
|
844 | + $this->fees = array_merge($this->fees, $this->payment_meta['fees']); |
|
845 | + foreach ($this->fees as $fee) { |
|
846 | + $this->increase_fees($fee['amount']); |
|
847 | 847 | } |
848 | 848 | } |
849 | 849 | |
850 | - $this->update_meta( '_wpinv_payment_meta', $this->payment_meta ); |
|
850 | + $this->update_meta('_wpinv_payment_meta', $this->payment_meta); |
|
851 | 851 | $this->new = true; |
852 | 852 | } |
853 | 853 | |
854 | 854 | return $this->ID; |
855 | 855 | } |
856 | 856 | |
857 | - public function save( $setup = false ) { |
|
857 | + public function save($setup = false) { |
|
858 | 858 | |
859 | 859 | $saved = false; |
860 | - if ( empty( $this->items ) ) { |
|
860 | + if (empty($this->items)) { |
|
861 | 861 | return $saved; // Don't save empty invoice. |
862 | 862 | } |
863 | 863 | |
864 | - if ( empty( $this->key ) ) { |
|
864 | + if (empty($this->key)) { |
|
865 | 865 | $this->key = self::generate_key(); |
866 | 866 | $this->pending['key'] = $this->key; |
867 | 867 | } |
868 | 868 | |
869 | - if ( empty( $this->ID ) ) { |
|
869 | + if (empty($this->ID)) { |
|
870 | 870 | $invoice_id = $this->insert_invoice(); |
871 | 871 | |
872 | - if ( false === $invoice_id ) { |
|
872 | + if (false === $invoice_id) { |
|
873 | 873 | $saved = false; |
874 | 874 | } else { |
875 | 875 | $this->ID = $invoice_id; |
@@ -877,27 +877,27 @@ discard block |
||
877 | 877 | } |
878 | 878 | |
879 | 879 | // If we have something pending, let's save it |
880 | - if ( !empty( $this->pending ) ) { |
|
880 | + if (!empty($this->pending)) { |
|
881 | 881 | $total_increase = 0; |
882 | 882 | $total_decrease = 0; |
883 | 883 | |
884 | - foreach ( $this->pending as $key => $value ) { |
|
885 | - switch( $key ) { |
|
884 | + foreach ($this->pending as $key => $value) { |
|
885 | + switch ($key) { |
|
886 | 886 | case 'items': |
887 | 887 | // Update totals for pending items |
888 | - foreach ( $this->pending[ $key ] as $item ) { |
|
889 | - switch( $item['action'] ) { |
|
888 | + foreach ($this->pending[$key] as $item) { |
|
889 | + switch ($item['action']) { |
|
890 | 890 | case 'add': |
891 | 891 | $price = $item['price']; |
892 | 892 | $taxes = $item['tax']; |
893 | 893 | |
894 | - if ( 'publish' === $this->status ) { |
|
894 | + if ('publish' === $this->status) { |
|
895 | 895 | $total_increase += $price; |
896 | 896 | } |
897 | 897 | break; |
898 | 898 | |
899 | 899 | case 'remove': |
900 | - if ( 'publish' === $this->status ) { |
|
900 | + if ('publish' === $this->status) { |
|
901 | 901 | $total_decrease += $item['price']; |
902 | 902 | } |
903 | 903 | break; |
@@ -905,16 +905,16 @@ discard block |
||
905 | 905 | } |
906 | 906 | break; |
907 | 907 | case 'fees': |
908 | - if ( 'publish' !== $this->status ) { |
|
908 | + if ('publish' !== $this->status) { |
|
909 | 909 | break; |
910 | 910 | } |
911 | 911 | |
912 | - if ( empty( $this->pending[ $key ] ) ) { |
|
912 | + if (empty($this->pending[$key])) { |
|
913 | 913 | break; |
914 | 914 | } |
915 | 915 | |
916 | - foreach ( $this->pending[ $key ] as $fee ) { |
|
917 | - switch( $fee['action'] ) { |
|
916 | + foreach ($this->pending[$key] as $fee) { |
|
917 | + switch ($fee['action']) { |
|
918 | 918 | case 'add': |
919 | 919 | $total_increase += $fee['amount']; |
920 | 920 | break; |
@@ -926,86 +926,86 @@ discard block |
||
926 | 926 | } |
927 | 927 | break; |
928 | 928 | case 'status': |
929 | - $this->update_status( $this->status ); |
|
929 | + $this->update_status($this->status); |
|
930 | 930 | break; |
931 | 931 | case 'gateway': |
932 | - $this->update_meta( '_wpinv_gateway', $this->gateway ); |
|
932 | + $this->update_meta('_wpinv_gateway', $this->gateway); |
|
933 | 933 | break; |
934 | 934 | case 'mode': |
935 | - $this->update_meta( '_wpinv_mode', $this->mode ); |
|
935 | + $this->update_meta('_wpinv_mode', $this->mode); |
|
936 | 936 | break; |
937 | 937 | case 'transaction_id': |
938 | - $this->update_meta( '_wpinv_transaction_id', $this->transaction_id ); |
|
938 | + $this->update_meta('_wpinv_transaction_id', $this->transaction_id); |
|
939 | 939 | break; |
940 | 940 | case 'ip': |
941 | - $this->update_meta( '_wpinv_user_ip', $this->ip ); |
|
941 | + $this->update_meta('_wpinv_user_ip', $this->ip); |
|
942 | 942 | break; |
943 | 943 | ///case 'user_id': |
944 | 944 | ///$this->update_meta( '_wpinv_user_id', $this->user_id ); |
945 | 945 | ///$this->user_info['user_id'] = $this->user_id; |
946 | 946 | ///break; |
947 | 947 | case 'first_name': |
948 | - $this->update_meta( '_wpinv_first_name', $this->first_name ); |
|
948 | + $this->update_meta('_wpinv_first_name', $this->first_name); |
|
949 | 949 | $this->user_info['first_name'] = $this->first_name; |
950 | 950 | break; |
951 | 951 | case 'last_name': |
952 | - $this->update_meta( '_wpinv_last_name', $this->last_name ); |
|
952 | + $this->update_meta('_wpinv_last_name', $this->last_name); |
|
953 | 953 | $this->user_info['last_name'] = $this->last_name; |
954 | 954 | break; |
955 | 955 | case 'phone': |
956 | - $this->update_meta( '_wpinv_phone', $this->phone ); |
|
956 | + $this->update_meta('_wpinv_phone', $this->phone); |
|
957 | 957 | $this->user_info['phone'] = $this->phone; |
958 | 958 | break; |
959 | 959 | case 'address': |
960 | - $this->update_meta( '_wpinv_address', $this->address ); |
|
960 | + $this->update_meta('_wpinv_address', $this->address); |
|
961 | 961 | $this->user_info['address'] = $this->address; |
962 | 962 | break; |
963 | 963 | case 'city': |
964 | - $this->update_meta( '_wpinv_city', $this->city ); |
|
964 | + $this->update_meta('_wpinv_city', $this->city); |
|
965 | 965 | $this->user_info['city'] = $this->city; |
966 | 966 | break; |
967 | 967 | case 'country': |
968 | - $this->update_meta( '_wpinv_country', $this->country ); |
|
968 | + $this->update_meta('_wpinv_country', $this->country); |
|
969 | 969 | $this->user_info['country'] = $this->country; |
970 | 970 | break; |
971 | 971 | case 'state': |
972 | - $this->update_meta( '_wpinv_state', $this->state ); |
|
972 | + $this->update_meta('_wpinv_state', $this->state); |
|
973 | 973 | $this->user_info['state'] = $this->state; |
974 | 974 | break; |
975 | 975 | case 'zip': |
976 | - $this->update_meta( '_wpinv_zip', $this->zip ); |
|
976 | + $this->update_meta('_wpinv_zip', $this->zip); |
|
977 | 977 | $this->user_info['zip'] = $this->zip; |
978 | 978 | break; |
979 | 979 | case 'company': |
980 | - $this->update_meta( '_wpinv_company', $this->company ); |
|
980 | + $this->update_meta('_wpinv_company', $this->company); |
|
981 | 981 | $this->user_info['company'] = $this->company; |
982 | 982 | break; |
983 | 983 | case 'vat_number': |
984 | - $this->update_meta( '_wpinv_vat_number', $this->vat_number ); |
|
984 | + $this->update_meta('_wpinv_vat_number', $this->vat_number); |
|
985 | 985 | $this->user_info['vat_number'] = $this->vat_number; |
986 | 986 | |
987 | - $vat_info = getpaid_session()->get( 'user_vat_data' ); |
|
988 | - if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) { |
|
989 | - $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false; |
|
990 | - $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed ); |
|
991 | - $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed; |
|
987 | + $vat_info = getpaid_session()->get('user_vat_data'); |
|
988 | + if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) { |
|
989 | + $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false; |
|
990 | + $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed); |
|
991 | + $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed; |
|
992 | 992 | } |
993 | 993 | |
994 | 994 | break; |
995 | 995 | case 'vat_rate': |
996 | - $this->update_meta( '_wpinv_vat_rate', $this->vat_rate ); |
|
996 | + $this->update_meta('_wpinv_vat_rate', $this->vat_rate); |
|
997 | 997 | $this->user_info['vat_rate'] = $this->vat_rate; |
998 | 998 | break; |
999 | 999 | case 'adddress_confirmed': |
1000 | - $this->update_meta( '_wpinv_adddress_confirmed', $this->adddress_confirmed ); |
|
1000 | + $this->update_meta('_wpinv_adddress_confirmed', $this->adddress_confirmed); |
|
1001 | 1001 | $this->user_info['adddress_confirmed'] = $this->adddress_confirmed; |
1002 | 1002 | break; |
1003 | 1003 | |
1004 | 1004 | case 'key': |
1005 | - $this->update_meta( '_wpinv_key', $this->key ); |
|
1005 | + $this->update_meta('_wpinv_key', $this->key); |
|
1006 | 1006 | break; |
1007 | 1007 | case 'disable_taxes': |
1008 | - $this->update_meta( '_wpinv_disable_taxes', $this->disable_taxes ); |
|
1008 | + $this->update_meta('_wpinv_disable_taxes', $this->disable_taxes); |
|
1009 | 1009 | break; |
1010 | 1010 | case 'date': |
1011 | 1011 | $args = array( |
@@ -1014,49 +1014,49 @@ discard block |
||
1014 | 1014 | 'edit_date' => true, |
1015 | 1015 | ); |
1016 | 1016 | |
1017 | - wp_update_post( $args ); |
|
1017 | + wp_update_post($args); |
|
1018 | 1018 | break; |
1019 | 1019 | case 'due_date': |
1020 | - if ( empty( $this->due_date ) ) { |
|
1020 | + if (empty($this->due_date)) { |
|
1021 | 1021 | $this->due_date = 'none'; |
1022 | 1022 | } |
1023 | 1023 | |
1024 | - $this->update_meta( '_wpinv_due_date', $this->due_date ); |
|
1024 | + $this->update_meta('_wpinv_due_date', $this->due_date); |
|
1025 | 1025 | break; |
1026 | 1026 | case 'completed_date': |
1027 | - $this->update_meta( '_wpinv_completed_date', $this->completed_date ); |
|
1027 | + $this->update_meta('_wpinv_completed_date', $this->completed_date); |
|
1028 | 1028 | break; |
1029 | 1029 | case 'discounts': |
1030 | - if ( ! is_array( $this->discounts ) ) { |
|
1031 | - $this->discounts = explode( ',', $this->discounts ); |
|
1030 | + if (!is_array($this->discounts)) { |
|
1031 | + $this->discounts = explode(',', $this->discounts); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | - $this->user_info['discount'] = implode( ',', $this->discounts ); |
|
1034 | + $this->user_info['discount'] = implode(',', $this->discounts); |
|
1035 | 1035 | break; |
1036 | 1036 | case 'discount': |
1037 | - $this->update_meta( '_wpinv_discount', wpinv_round_amount( $this->discount ) ); |
|
1037 | + $this->update_meta('_wpinv_discount', wpinv_round_amount($this->discount)); |
|
1038 | 1038 | break; |
1039 | 1039 | case 'discount_code': |
1040 | - $this->update_meta( '_wpinv_discount_code', $this->discount_code ); |
|
1040 | + $this->update_meta('_wpinv_discount_code', $this->discount_code); |
|
1041 | 1041 | break; |
1042 | 1042 | case 'parent_invoice': |
1043 | 1043 | $args = array( |
1044 | 1044 | 'ID' => $this->ID, |
1045 | 1045 | 'post_parent' => $this->parent_invoice, |
1046 | 1046 | ); |
1047 | - wp_update_post( $args ); |
|
1047 | + wp_update_post($args); |
|
1048 | 1048 | break; |
1049 | 1049 | default: |
1050 | - do_action( 'wpinv_save', $this, $key ); |
|
1050 | + do_action('wpinv_save', $this, $key); |
|
1051 | 1051 | break; |
1052 | 1052 | } |
1053 | 1053 | } |
1054 | 1054 | |
1055 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
1056 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
1057 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
1055 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
1056 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
1057 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
1058 | 1058 | |
1059 | - $this->items = array_values( $this->items ); |
|
1059 | + $this->items = array_values($this->items); |
|
1060 | 1060 | |
1061 | 1061 | $new_meta = array( |
1062 | 1062 | 'items' => $this->items, |
@@ -1067,12 +1067,12 @@ discard block |
||
1067 | 1067 | ); |
1068 | 1068 | |
1069 | 1069 | $meta = $this->get_meta(); |
1070 | - $merged_meta = array_merge( $meta, $new_meta ); |
|
1070 | + $merged_meta = array_merge($meta, $new_meta); |
|
1071 | 1071 | |
1072 | 1072 | // Only save the payment meta if it's changed |
1073 | - if ( md5( serialize( $meta ) ) !== md5( serialize( $merged_meta) ) ) { |
|
1074 | - $updated = $this->update_meta( '_wpinv_payment_meta', $merged_meta ); |
|
1075 | - if ( false !== $updated ) { |
|
1073 | + if (md5(serialize($meta)) !== md5(serialize($merged_meta))) { |
|
1074 | + $updated = $this->update_meta('_wpinv_payment_meta', $merged_meta); |
|
1075 | + if (false !== $updated) { |
|
1076 | 1076 | $saved = true; |
1077 | 1077 | } |
1078 | 1078 | } |
@@ -1080,15 +1080,15 @@ discard block |
||
1080 | 1080 | $this->pending = array(); |
1081 | 1081 | $saved = true; |
1082 | 1082 | } else { |
1083 | - $this->update_meta( '_wpinv_subtotal', wpinv_round_amount( $this->subtotal ) ); |
|
1084 | - $this->update_meta( '_wpinv_total', wpinv_round_amount( $this->total ) ); |
|
1085 | - $this->update_meta( '_wpinv_tax', wpinv_round_amount( $this->tax ) ); |
|
1083 | + $this->update_meta('_wpinv_subtotal', wpinv_round_amount($this->subtotal)); |
|
1084 | + $this->update_meta('_wpinv_total', wpinv_round_amount($this->total)); |
|
1085 | + $this->update_meta('_wpinv_tax', wpinv_round_amount($this->tax)); |
|
1086 | 1086 | } |
1087 | 1087 | |
1088 | - do_action( 'wpinv_invoice_save', $this, $saved ); |
|
1088 | + do_action('wpinv_invoice_save', $this, $saved); |
|
1089 | 1089 | |
1090 | - if ( true === $saved || $setup ) { |
|
1091 | - $this->setup_invoice( $this->ID ); |
|
1090 | + if (true === $saved || $setup) { |
|
1091 | + $this->setup_invoice($this->ID); |
|
1092 | 1092 | } |
1093 | 1093 | |
1094 | 1094 | $this->refresh_item_ids(); |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | return $saved; |
1097 | 1097 | } |
1098 | 1098 | |
1099 | - public function add_fee( $args, $global = true ) { |
|
1099 | + public function add_fee($args, $global = true) { |
|
1100 | 1100 | $default_args = array( |
1101 | 1101 | 'label' => '', |
1102 | 1102 | 'amount' => 0, |
@@ -1106,75 +1106,75 @@ discard block |
||
1106 | 1106 | 'item_id' => 0, |
1107 | 1107 | ); |
1108 | 1108 | |
1109 | - $fee = wp_parse_args( $args, $default_args ); |
|
1109 | + $fee = wp_parse_args($args, $default_args); |
|
1110 | 1110 | |
1111 | - if ( empty( $fee['label'] ) ) { |
|
1111 | + if (empty($fee['label'])) { |
|
1112 | 1112 | return false; |
1113 | 1113 | } |
1114 | 1114 | |
1115 | - $fee['id'] = sanitize_title( $fee['label'] ); |
|
1115 | + $fee['id'] = sanitize_title($fee['label']); |
|
1116 | 1116 | |
1117 | - $this->fees[] = $fee; |
|
1117 | + $this->fees[] = $fee; |
|
1118 | 1118 | |
1119 | 1119 | $added_fee = $fee; |
1120 | 1120 | $added_fee['action'] = 'add'; |
1121 | 1121 | $this->pending['fees'][] = $added_fee; |
1122 | - reset( $this->fees ); |
|
1122 | + reset($this->fees); |
|
1123 | 1123 | |
1124 | - $this->increase_fees( $fee['amount'] ); |
|
1124 | + $this->increase_fees($fee['amount']); |
|
1125 | 1125 | return true; |
1126 | 1126 | } |
1127 | 1127 | |
1128 | - public function remove_fee( $key ) { |
|
1128 | + public function remove_fee($key) { |
|
1129 | 1129 | $removed = false; |
1130 | 1130 | |
1131 | - if ( is_numeric( $key ) ) { |
|
1132 | - $removed = $this->remove_fee_by( 'index', $key ); |
|
1131 | + if (is_numeric($key)) { |
|
1132 | + $removed = $this->remove_fee_by('index', $key); |
|
1133 | 1133 | } |
1134 | 1134 | |
1135 | 1135 | return $removed; |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - public function remove_fee_by( $key, $value, $global = false ) { |
|
1139 | - $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array( |
|
1138 | + public function remove_fee_by($key, $value, $global = false) { |
|
1139 | + $allowed_fee_keys = apply_filters('wpinv_fee_keys', array( |
|
1140 | 1140 | 'index', 'label', 'amount', 'type', |
1141 | - ) ); |
|
1141 | + )); |
|
1142 | 1142 | |
1143 | - if ( ! in_array( $key, $allowed_fee_keys ) ) { |
|
1143 | + if (!in_array($key, $allowed_fee_keys)) { |
|
1144 | 1144 | return false; |
1145 | 1145 | } |
1146 | 1146 | |
1147 | 1147 | $removed = false; |
1148 | - if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) { |
|
1149 | - $removed_fee = $this->fees[ $value ]; |
|
1148 | + if ('index' === $key && array_key_exists($value, $this->fees)) { |
|
1149 | + $removed_fee = $this->fees[$value]; |
|
1150 | 1150 | $removed_fee['action'] = 'remove'; |
1151 | 1151 | $this->pending['fees'][] = $removed_fee; |
1152 | 1152 | |
1153 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1153 | + $this->decrease_fees($removed_fee['amount']); |
|
1154 | 1154 | |
1155 | - unset( $this->fees[ $value ] ); |
|
1155 | + unset($this->fees[$value]); |
|
1156 | 1156 | $removed = true; |
1157 | - } else if ( 'index' !== $key ) { |
|
1158 | - foreach ( $this->fees as $index => $fee ) { |
|
1159 | - if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) { |
|
1157 | + } else if ('index' !== $key) { |
|
1158 | + foreach ($this->fees as $index => $fee) { |
|
1159 | + if (isset($fee[$key]) && $fee[$key] == $value) { |
|
1160 | 1160 | $removed_fee = $fee; |
1161 | 1161 | $removed_fee['action'] = 'remove'; |
1162 | 1162 | $this->pending['fees'][] = $removed_fee; |
1163 | 1163 | |
1164 | - $this->decrease_fees( $removed_fee['amount'] ); |
|
1164 | + $this->decrease_fees($removed_fee['amount']); |
|
1165 | 1165 | |
1166 | - unset( $this->fees[ $index ] ); |
|
1166 | + unset($this->fees[$index]); |
|
1167 | 1167 | $removed = true; |
1168 | 1168 | |
1169 | - if ( false === $global ) { |
|
1169 | + if (false === $global) { |
|
1170 | 1170 | break; |
1171 | 1171 | } |
1172 | 1172 | } |
1173 | 1173 | } |
1174 | 1174 | } |
1175 | 1175 | |
1176 | - if ( true === $removed ) { |
|
1177 | - $this->fees = array_values( $this->fees ); |
|
1176 | + if (true === $removed) { |
|
1177 | + $this->fees = array_values($this->fees); |
|
1178 | 1178 | } |
1179 | 1179 | |
1180 | 1180 | return $removed; |
@@ -1182,35 +1182,35 @@ discard block |
||
1182 | 1182 | |
1183 | 1183 | |
1184 | 1184 | |
1185 | - public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) { |
|
1185 | + public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) { |
|
1186 | 1186 | // Bail if no note specified |
1187 | - if( !$note ) { |
|
1187 | + if (!$note) { |
|
1188 | 1188 | return false; |
1189 | 1189 | } |
1190 | 1190 | |
1191 | - if ( empty( $this->ID ) ) |
|
1191 | + if (empty($this->ID)) |
|
1192 | 1192 | return false; |
1193 | 1193 | |
1194 | - if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) { |
|
1195 | - $user = get_user_by( 'id', get_current_user_id() ); |
|
1194 | + if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) { |
|
1195 | + $user = get_user_by('id', get_current_user_id()); |
|
1196 | 1196 | $comment_author = $user->display_name; |
1197 | 1197 | $comment_author_email = $user->user_email; |
1198 | 1198 | } else { |
1199 | 1199 | $comment_author = 'System'; |
1200 | 1200 | $comment_author_email = 'system@'; |
1201 | - $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com'; |
|
1202 | - $comment_author_email = sanitize_email( $comment_author_email ); |
|
1201 | + $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com'; |
|
1202 | + $comment_author_email = sanitize_email($comment_author_email); |
|
1203 | 1203 | } |
1204 | 1204 | |
1205 | - do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type ); |
|
1205 | + do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type); |
|
1206 | 1206 | |
1207 | - $note_id = wp_insert_comment( wp_filter_comment( array( |
|
1207 | + $note_id = wp_insert_comment(wp_filter_comment(array( |
|
1208 | 1208 | 'comment_post_ID' => $this->ID, |
1209 | 1209 | 'comment_content' => $note, |
1210 | 1210 | 'comment_agent' => 'WPInvoicing', |
1211 | 1211 | 'user_id' => is_admin() ? get_current_user_id() : 0, |
1212 | - 'comment_date' => current_time( 'mysql' ), |
|
1213 | - 'comment_date_gmt' => current_time( 'mysql', 1 ), |
|
1212 | + 'comment_date' => current_time('mysql'), |
|
1213 | + 'comment_date_gmt' => current_time('mysql', 1), |
|
1214 | 1214 | 'comment_approved' => 1, |
1215 | 1215 | 'comment_parent' => 0, |
1216 | 1216 | 'comment_author' => $comment_author, |
@@ -1218,53 +1218,53 @@ discard block |
||
1218 | 1218 | 'comment_author_url' => '', |
1219 | 1219 | 'comment_author_email' => $comment_author_email, |
1220 | 1220 | 'comment_type' => 'wpinv_note' |
1221 | - ) ) ); |
|
1221 | + ))); |
|
1222 | 1222 | |
1223 | - do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note ); |
|
1223 | + do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note); |
|
1224 | 1224 | |
1225 | - if ( $customer_type ) { |
|
1226 | - add_comment_meta( $note_id, '_wpi_customer_note', 1 ); |
|
1225 | + if ($customer_type) { |
|
1226 | + add_comment_meta($note_id, '_wpi_customer_note', 1); |
|
1227 | 1227 | |
1228 | - do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) ); |
|
1228 | + do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note)); |
|
1229 | 1229 | } |
1230 | 1230 | |
1231 | 1231 | return $note_id; |
1232 | 1232 | } |
1233 | 1233 | |
1234 | - private function increase_subtotal( $amount = 0.00 ) { |
|
1234 | + private function increase_subtotal($amount = 0.00) { |
|
1235 | 1235 | $amount = (float) $amount; |
1236 | 1236 | $this->subtotal += $amount; |
1237 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1237 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1238 | 1238 | |
1239 | 1239 | $this->recalculate_total(); |
1240 | 1240 | } |
1241 | 1241 | |
1242 | - private function decrease_subtotal( $amount = 0.00 ) { |
|
1242 | + private function decrease_subtotal($amount = 0.00) { |
|
1243 | 1243 | $amount = (float) $amount; |
1244 | 1244 | $this->subtotal -= $amount; |
1245 | - $this->subtotal = wpinv_round_amount( $this->subtotal ); |
|
1245 | + $this->subtotal = wpinv_round_amount($this->subtotal); |
|
1246 | 1246 | |
1247 | - if ( $this->subtotal < 0 ) { |
|
1247 | + if ($this->subtotal < 0) { |
|
1248 | 1248 | $this->subtotal = 0; |
1249 | 1249 | } |
1250 | 1250 | |
1251 | 1251 | $this->recalculate_total(); |
1252 | 1252 | } |
1253 | 1253 | |
1254 | - private function increase_fees( $amount = 0.00 ) { |
|
1255 | - $amount = (float)$amount; |
|
1254 | + private function increase_fees($amount = 0.00) { |
|
1255 | + $amount = (float) $amount; |
|
1256 | 1256 | $this->fees_total += $amount; |
1257 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1257 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1258 | 1258 | |
1259 | 1259 | $this->recalculate_total(); |
1260 | 1260 | } |
1261 | 1261 | |
1262 | - private function decrease_fees( $amount = 0.00 ) { |
|
1262 | + private function decrease_fees($amount = 0.00) { |
|
1263 | 1263 | $amount = (float) $amount; |
1264 | 1264 | $this->fees_total -= $amount; |
1265 | - $this->fees_total = wpinv_round_amount( $this->fees_total ); |
|
1265 | + $this->fees_total = wpinv_round_amount($this->fees_total); |
|
1266 | 1266 | |
1267 | - if ( $this->fees_total < 0 ) { |
|
1267 | + if ($this->fees_total < 0) { |
|
1268 | 1268 | $this->fees_total = 0; |
1269 | 1269 | } |
1270 | 1270 | |
@@ -1275,54 +1275,54 @@ discard block |
||
1275 | 1275 | global $wpi_nosave; |
1276 | 1276 | |
1277 | 1277 | $this->total = $this->subtotal + $this->tax + $this->fees_total; |
1278 | - $this->total = wpinv_round_amount( $this->total ); |
|
1278 | + $this->total = wpinv_round_amount($this->total); |
|
1279 | 1279 | |
1280 | - do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave ); |
|
1280 | + do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave); |
|
1281 | 1281 | } |
1282 | 1282 | |
1283 | - public function increase_tax( $amount = 0.00 ) { |
|
1283 | + public function increase_tax($amount = 0.00) { |
|
1284 | 1284 | $amount = (float) $amount; |
1285 | 1285 | $this->tax += $amount; |
1286 | 1286 | |
1287 | 1287 | $this->recalculate_total(); |
1288 | 1288 | } |
1289 | 1289 | |
1290 | - public function decrease_tax( $amount = 0.00 ) { |
|
1290 | + public function decrease_tax($amount = 0.00) { |
|
1291 | 1291 | $amount = (float) $amount; |
1292 | 1292 | $this->tax -= $amount; |
1293 | 1293 | |
1294 | - if ( $this->tax < 0 ) { |
|
1294 | + if ($this->tax < 0) { |
|
1295 | 1295 | $this->tax = 0; |
1296 | 1296 | } |
1297 | 1297 | |
1298 | 1298 | $this->recalculate_total(); |
1299 | 1299 | } |
1300 | 1300 | |
1301 | - public function update_status( $new_status = false, $note = '', $manual = false ) { |
|
1302 | - $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID ); |
|
1301 | + public function update_status($new_status = false, $note = '', $manual = false) { |
|
1302 | + $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID); |
|
1303 | 1303 | |
1304 | - if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) { |
|
1304 | + if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) { |
|
1305 | 1305 | return false; // Don't permit status changes that aren't changes |
1306 | 1306 | } |
1307 | 1307 | |
1308 | - $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status ); |
|
1308 | + $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status); |
|
1309 | 1309 | $updated = false; |
1310 | 1310 | |
1311 | - if ( $do_change ) { |
|
1312 | - do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status ); |
|
1311 | + if ($do_change) { |
|
1312 | + do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status); |
|
1313 | 1313 | |
1314 | 1314 | $update_post_data = array(); |
1315 | 1315 | $update_post_data['ID'] = $this->ID; |
1316 | 1316 | $update_post_data['post_status'] = $new_status; |
1317 | - $update_post_data['edit_date'] = current_time( 'mysql', 0 ); |
|
1318 | - $update_post_data['edit_date_gmt'] = current_time( 'mysql', 1 ); |
|
1317 | + $update_post_data['edit_date'] = current_time('mysql', 0); |
|
1318 | + $update_post_data['edit_date_gmt'] = current_time('mysql', 1); |
|
1319 | 1319 | |
1320 | - $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID ); |
|
1320 | + $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID); |
|
1321 | 1321 | |
1322 | - $updated = wp_update_post( $update_post_data ); |
|
1322 | + $updated = wp_update_post($update_post_data); |
|
1323 | 1323 | |
1324 | 1324 | // Process any specific status functions |
1325 | - switch( $new_status ) { |
|
1325 | + switch ($new_status) { |
|
1326 | 1326 | case 'wpi-refunded': |
1327 | 1327 | $this->process_refund(); |
1328 | 1328 | break; |
@@ -1335,9 +1335,9 @@ discard block |
||
1335 | 1335 | } |
1336 | 1336 | |
1337 | 1337 | // Status was changed. |
1338 | - do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status ); |
|
1339 | - do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status ); |
|
1340 | - do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status ); |
|
1338 | + do_action('wpinv_status_' . $new_status, $this->ID, $old_status); |
|
1339 | + do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status); |
|
1340 | + do_action('wpinv_update_status', $this->ID, $new_status, $old_status); |
|
1341 | 1341 | } |
1342 | 1342 | |
1343 | 1343 | return $updated; |
@@ -1351,20 +1351,20 @@ discard block |
||
1351 | 1351 | $this->save(); |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) { |
|
1355 | - if ( empty( $meta_key ) ) { |
|
1354 | + public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') { |
|
1355 | + if (empty($meta_key)) { |
|
1356 | 1356 | return false; |
1357 | 1357 | } |
1358 | 1358 | |
1359 | - if ( $meta_key == 'key' || $meta_key == 'date' ) { |
|
1359 | + if ($meta_key == 'key' || $meta_key == 'date') { |
|
1360 | 1360 | $current_meta = $this->get_meta(); |
1361 | - $current_meta[ $meta_key ] = $meta_value; |
|
1361 | + $current_meta[$meta_key] = $meta_value; |
|
1362 | 1362 | |
1363 | 1363 | $meta_key = '_wpinv_payment_meta'; |
1364 | 1364 | $meta_value = $current_meta; |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID ); |
|
1367 | + $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID); |
|
1368 | 1368 | |
1369 | 1369 | // Do not update created date on invoice marked as paid. |
1370 | 1370 | /*if ( $meta_key == '_wpinv_completed_date' && !empty( $meta_value ) ) { |
@@ -1379,45 +1379,45 @@ discard block |
||
1379 | 1379 | wp_update_post( $args ); |
1380 | 1380 | }*/ |
1381 | 1381 | |
1382 | - return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value ); |
|
1382 | + return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value); |
|
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | private function process_refund() { |
1386 | 1386 | $process_refund = true; |
1387 | 1387 | |
1388 | 1388 | // If the payment was not in publish, don't decrement stats as they were never incremented |
1389 | - if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) { |
|
1389 | + if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) { |
|
1390 | 1390 | $process_refund = false; |
1391 | 1391 | } |
1392 | 1392 | |
1393 | 1393 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1394 | - $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this ); |
|
1394 | + $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this); |
|
1395 | 1395 | |
1396 | - if ( false === $process_refund ) { |
|
1396 | + if (false === $process_refund) { |
|
1397 | 1397 | return; |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - do_action( 'wpinv_pre_refund_invoice', $this ); |
|
1400 | + do_action('wpinv_pre_refund_invoice', $this); |
|
1401 | 1401 | |
1402 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this ); |
|
1403 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this ); |
|
1404 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this ); |
|
1402 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this); |
|
1403 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this); |
|
1404 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this); |
|
1405 | 1405 | |
1406 | - do_action( 'wpinv_post_refund_invoice', $this ); |
|
1406 | + do_action('wpinv_post_refund_invoice', $this); |
|
1407 | 1407 | } |
1408 | 1408 | |
1409 | 1409 | private function process_failure() { |
1410 | 1410 | $discounts = $this->discounts; |
1411 | - if ( empty( $discounts ) ) { |
|
1411 | + if (empty($discounts)) { |
|
1412 | 1412 | return; |
1413 | 1413 | } |
1414 | 1414 | |
1415 | - if ( ! is_array( $discounts ) ) { |
|
1416 | - $discounts = array_map( 'trim', explode( ',', $discounts ) ); |
|
1415 | + if (!is_array($discounts)) { |
|
1416 | + $discounts = array_map('trim', explode(',', $discounts)); |
|
1417 | 1417 | } |
1418 | 1418 | |
1419 | - foreach ( $discounts as $discount ) { |
|
1420 | - wpinv_decrease_discount_usage( $discount ); |
|
1419 | + foreach ($discounts as $discount) { |
|
1420 | + wpinv_decrease_discount_usage($discount); |
|
1421 | 1421 | } |
1422 | 1422 | } |
1423 | 1423 | |
@@ -1425,92 +1425,92 @@ discard block |
||
1425 | 1425 | $process_pending = true; |
1426 | 1426 | |
1427 | 1427 | // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented |
1428 | - if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) { |
|
1428 | + if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) { |
|
1429 | 1429 | $process_pending = false; |
1430 | 1430 | } |
1431 | 1431 | |
1432 | 1432 | // Allow extensions to filter for their own payment types, Example: Recurring Payments |
1433 | - $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this ); |
|
1433 | + $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this); |
|
1434 | 1434 | |
1435 | - if ( false === $process_pending ) { |
|
1435 | + if (false === $process_pending) { |
|
1436 | 1436 | return; |
1437 | 1437 | } |
1438 | 1438 | |
1439 | - $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this ); |
|
1440 | - $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this ); |
|
1441 | - $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this ); |
|
1439 | + $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this); |
|
1440 | + $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this); |
|
1441 | + $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this); |
|
1442 | 1442 | |
1443 | 1443 | $this->completed_date = ''; |
1444 | - $this->update_meta( '_wpinv_completed_date', '' ); |
|
1444 | + $this->update_meta('_wpinv_completed_date', ''); |
|
1445 | 1445 | } |
1446 | 1446 | |
1447 | 1447 | // get data |
1448 | - public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) { |
|
1449 | - $meta = get_post_meta( $this->ID, $meta_key, $single ); |
|
1448 | + public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) { |
|
1449 | + $meta = get_post_meta($this->ID, $meta_key, $single); |
|
1450 | 1450 | |
1451 | - if ( $meta_key === '_wpinv_payment_meta' ) { |
|
1451 | + if ($meta_key === '_wpinv_payment_meta') { |
|
1452 | 1452 | |
1453 | - if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is. |
|
1453 | + if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is. |
|
1454 | 1454 | |
1455 | - if ( empty( $meta['key'] ) ) { |
|
1455 | + if (empty($meta['key'])) { |
|
1456 | 1456 | $meta['key'] = $this->setup_invoice_key(); |
1457 | 1457 | } |
1458 | 1458 | |
1459 | - if ( empty( $meta['date'] ) ) { |
|
1460 | - $meta['date'] = get_post_field( 'post_date', $this->ID ); |
|
1459 | + if (empty($meta['date'])) { |
|
1460 | + $meta['date'] = get_post_field('post_date', $this->ID); |
|
1461 | 1461 | } |
1462 | 1462 | } |
1463 | 1463 | |
1464 | - $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID ); |
|
1464 | + $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID); |
|
1465 | 1465 | |
1466 | - return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key ); |
|
1466 | + return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key); |
|
1467 | 1467 | } |
1468 | 1468 | |
1469 | 1469 | public function get_description() { |
1470 | - $post = get_post( $this->ID ); |
|
1470 | + $post = get_post($this->ID); |
|
1471 | 1471 | |
1472 | - $description = !empty( $post ) ? $post->post_content : ''; |
|
1473 | - return apply_filters( 'wpinv_get_description', $description, $this->ID, $this ); |
|
1472 | + $description = !empty($post) ? $post->post_content : ''; |
|
1473 | + return apply_filters('wpinv_get_description', $description, $this->ID, $this); |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | - public function get_status( $nicename = false ) { |
|
1477 | - if ( !$nicename ) { |
|
1476 | + public function get_status($nicename = false) { |
|
1477 | + if (!$nicename) { |
|
1478 | 1478 | $status = $this->status; |
1479 | 1479 | } else { |
1480 | 1480 | $status = $this->status_nicename; |
1481 | 1481 | } |
1482 | 1482 | |
1483 | - return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this ); |
|
1483 | + return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this); |
|
1484 | 1484 | } |
1485 | 1485 | |
1486 | 1486 | public function get_cart_details() { |
1487 | - return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this ); |
|
1487 | + return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this); |
|
1488 | 1488 | } |
1489 | 1489 | |
1490 | - public function get_subtotal( $currency = false ) { |
|
1491 | - $subtotal = wpinv_round_amount( $this->subtotal ); |
|
1490 | + public function get_subtotal($currency = false) { |
|
1491 | + $subtotal = wpinv_round_amount($this->subtotal); |
|
1492 | 1492 | |
1493 | - if ( $currency ) { |
|
1494 | - $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() ); |
|
1493 | + if ($currency) { |
|
1494 | + $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency()); |
|
1495 | 1495 | } |
1496 | 1496 | |
1497 | - return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency ); |
|
1497 | + return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency); |
|
1498 | 1498 | } |
1499 | 1499 | |
1500 | - public function get_total( $currency = false ) { |
|
1501 | - if ( $this->is_free_trial() ) { |
|
1502 | - $total = wpinv_round_amount( 0 ); |
|
1500 | + public function get_total($currency = false) { |
|
1501 | + if ($this->is_free_trial()) { |
|
1502 | + $total = wpinv_round_amount(0); |
|
1503 | 1503 | } else { |
1504 | - $total = wpinv_round_amount( $this->total ); |
|
1504 | + $total = wpinv_round_amount($this->total); |
|
1505 | 1505 | } |
1506 | - if ( $currency ) { |
|
1507 | - $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() ); |
|
1506 | + if ($currency) { |
|
1507 | + $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency()); |
|
1508 | 1508 | } |
1509 | 1509 | |
1510 | - return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency ); |
|
1510 | + return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency); |
|
1511 | 1511 | } |
1512 | 1512 | |
1513 | - public function get_recurring_details( $field = '', $currency = false ) { |
|
1513 | + public function get_recurring_details($field = '', $currency = false) { |
|
1514 | 1514 | $data = array(); |
1515 | 1515 | $data['cart_details'] = $this->cart_details; |
1516 | 1516 | $data['subtotal'] = $this->get_subtotal(); |
@@ -1518,119 +1518,119 @@ discard block |
||
1518 | 1518 | $data['tax'] = $this->get_tax(); |
1519 | 1519 | $data['total'] = $this->get_total(); |
1520 | 1520 | |
1521 | - if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) { |
|
1521 | + if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) { |
|
1522 | 1522 | $is_free_trial = $this->is_free_trial(); |
1523 | - $discounts = $this->get_discounts( true ); |
|
1523 | + $discounts = $this->get_discounts(true); |
|
1524 | 1524 | |
1525 | - if ( $is_free_trial || !empty( $discounts ) ) { |
|
1525 | + if ($is_free_trial || !empty($discounts)) { |
|
1526 | 1526 | $first_use_only = false; |
1527 | 1527 | |
1528 | - if ( !empty( $discounts ) ) { |
|
1529 | - foreach ( $discounts as $key => $code ) { |
|
1530 | - if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) { |
|
1528 | + if (!empty($discounts)) { |
|
1529 | + foreach ($discounts as $key => $code) { |
|
1530 | + if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) { |
|
1531 | 1531 | $first_use_only = true; |
1532 | 1532 | break; |
1533 | 1533 | } |
1534 | 1534 | } |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - if ( !$first_use_only ) { |
|
1538 | - $data['subtotal'] = wpinv_round_amount( $this->subtotal ); |
|
1539 | - $data['discount'] = wpinv_round_amount( $this->discount ); |
|
1540 | - $data['tax'] = wpinv_round_amount( $this->tax ); |
|
1541 | - $data['total'] = wpinv_round_amount( $this->total ); |
|
1537 | + if (!$first_use_only) { |
|
1538 | + $data['subtotal'] = wpinv_round_amount($this->subtotal); |
|
1539 | + $data['discount'] = wpinv_round_amount($this->discount); |
|
1540 | + $data['tax'] = wpinv_round_amount($this->tax); |
|
1541 | + $data['total'] = wpinv_round_amount($this->total); |
|
1542 | 1542 | } else { |
1543 | 1543 | $cart_subtotal = 0; |
1544 | 1544 | $cart_discount = $this->discount; |
1545 | 1545 | $cart_tax = 0; |
1546 | 1546 | |
1547 | - foreach ( $this->cart_details as $key => $item ) { |
|
1548 | - $item_quantity = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
1549 | - $item_subtotal = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1547 | + foreach ($this->cart_details as $key => $item) { |
|
1548 | + $item_quantity = $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
1549 | + $item_subtotal = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity; |
|
1550 | 1550 | $item_discount = 0; |
1551 | - $item_tax = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0; |
|
1551 | + $item_tax = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0; |
|
1552 | 1552 | |
1553 | - if ( wpinv_prices_include_tax() ) { |
|
1554 | - $item_subtotal -= wpinv_round_amount( $item_tax ); |
|
1553 | + if (wpinv_prices_include_tax()) { |
|
1554 | + $item_subtotal -= wpinv_round_amount($item_tax); |
|
1555 | 1555 | } |
1556 | 1556 | |
1557 | 1557 | $item_total = $item_subtotal - $item_discount + $item_tax; |
1558 | 1558 | // Do not allow totals to go negative |
1559 | - if ( $item_total < 0 ) { |
|
1559 | + if ($item_total < 0) { |
|
1560 | 1560 | $item_total = 0; |
1561 | 1561 | } |
1562 | 1562 | |
1563 | - $cart_subtotal += (float)($item_subtotal); |
|
1564 | - $cart_discount += (float)($item_discount); |
|
1565 | - $cart_tax += (float)($item_tax); |
|
1563 | + $cart_subtotal += (float) ($item_subtotal); |
|
1564 | + $cart_discount += (float) ($item_discount); |
|
1565 | + $cart_tax += (float) ($item_tax); |
|
1566 | 1566 | |
1567 | - $data['cart_details'][$key]['discount'] = wpinv_round_amount( $item_discount ); |
|
1568 | - $data['cart_details'][$key]['tax'] = wpinv_round_amount( $item_tax ); |
|
1569 | - $data['cart_details'][$key]['price'] = wpinv_round_amount( $item_total ); |
|
1567 | + $data['cart_details'][$key]['discount'] = wpinv_round_amount($item_discount); |
|
1568 | + $data['cart_details'][$key]['tax'] = wpinv_round_amount($item_tax); |
|
1569 | + $data['cart_details'][$key]['price'] = wpinv_round_amount($item_total); |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | $total = $data['subtotal'] - $data['discount'] + $data['tax']; |
1573 | - if ( $total < 0 ) { |
|
1573 | + if ($total < 0) { |
|
1574 | 1574 | $total = 0; |
1575 | 1575 | } |
1576 | 1576 | |
1577 | - $data['subtotal'] = wpinv_round_amount( $cart_subtotal ); |
|
1578 | - $data['discount'] = wpinv_round_amount( $cart_discount ); |
|
1579 | - $data['tax'] = wpinv_round_amount( $cart_tax ); |
|
1580 | - $data['total'] = wpinv_round_amount( $total ); |
|
1577 | + $data['subtotal'] = wpinv_round_amount($cart_subtotal); |
|
1578 | + $data['discount'] = wpinv_round_amount($cart_discount); |
|
1579 | + $data['tax'] = wpinv_round_amount($cart_tax); |
|
1580 | + $data['total'] = wpinv_round_amount($total); |
|
1581 | 1581 | } |
1582 | 1582 | } |
1583 | 1583 | } |
1584 | 1584 | |
1585 | - $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency ); |
|
1585 | + $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency); |
|
1586 | 1586 | |
1587 | - if ( isset( $data[$field] ) ) { |
|
1588 | - return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] ); |
|
1587 | + if (isset($data[$field])) { |
|
1588 | + return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]); |
|
1589 | 1589 | } |
1590 | 1590 | |
1591 | 1591 | return $data; |
1592 | 1592 | } |
1593 | 1593 | |
1594 | - public function get_final_tax( $currency = false ) { |
|
1595 | - $final_total = wpinv_round_amount( $this->tax ); |
|
1596 | - if ( $currency ) { |
|
1597 | - $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() ); |
|
1594 | + public function get_final_tax($currency = false) { |
|
1595 | + $final_total = wpinv_round_amount($this->tax); |
|
1596 | + if ($currency) { |
|
1597 | + $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency()); |
|
1598 | 1598 | } |
1599 | 1599 | |
1600 | - return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency ); |
|
1600 | + return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency); |
|
1601 | 1601 | } |
1602 | 1602 | |
1603 | - public function get_discounts( $array = false ) { |
|
1603 | + public function get_discounts($array = false) { |
|
1604 | 1604 | $discounts = $this->discounts; |
1605 | - if ( $array && $discounts ) { |
|
1606 | - $discounts = explode( ',', $discounts ); |
|
1605 | + if ($array && $discounts) { |
|
1606 | + $discounts = explode(',', $discounts); |
|
1607 | 1607 | } |
1608 | - return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array ); |
|
1608 | + return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array); |
|
1609 | 1609 | } |
1610 | 1610 | |
1611 | - public function get_discount( $currency = false, $dash = false ) { |
|
1612 | - if ( !empty( $this->discounts ) ) { |
|
1611 | + public function get_discount($currency = false, $dash = false) { |
|
1612 | + if (!empty($this->discounts)) { |
|
1613 | 1613 | global $ajax_cart_details; |
1614 | 1614 | $ajax_cart_details = $this->get_cart_details(); |
1615 | 1615 | |
1616 | - if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) { |
|
1616 | + if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) { |
|
1617 | 1617 | $cart_items = $ajax_cart_details; |
1618 | 1618 | } else { |
1619 | 1619 | $cart_items = $this->items; |
1620 | 1620 | } |
1621 | 1621 | |
1622 | - $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts ); |
|
1622 | + $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts); |
|
1623 | 1623 | } |
1624 | - $discount = wpinv_round_amount( $this->discount ); |
|
1624 | + $discount = wpinv_round_amount($this->discount); |
|
1625 | 1625 | $dash = $dash && $discount > 0 ? '–' : ''; |
1626 | 1626 | |
1627 | - if ( $currency ) { |
|
1628 | - $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() ); |
|
1627 | + if ($currency) { |
|
1628 | + $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency()); |
|
1629 | 1629 | } |
1630 | 1630 | |
1631 | - $discount = $dash . $discount; |
|
1631 | + $discount = $dash . $discount; |
|
1632 | 1632 | |
1633 | - return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash ); |
|
1633 | + return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash); |
|
1634 | 1634 | } |
1635 | 1635 | |
1636 | 1636 | public function get_discount_code() { |
@@ -1642,49 +1642,49 @@ discard block |
||
1642 | 1642 | return (int) $this->disable_taxes === 0; |
1643 | 1643 | } |
1644 | 1644 | |
1645 | - public function get_tax( $currency = false ) { |
|
1646 | - $tax = wpinv_round_amount( $this->tax ); |
|
1645 | + public function get_tax($currency = false) { |
|
1646 | + $tax = wpinv_round_amount($this->tax); |
|
1647 | 1647 | |
1648 | - if ( $currency ) { |
|
1649 | - $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() ); |
|
1648 | + if ($currency) { |
|
1649 | + $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency()); |
|
1650 | 1650 | } |
1651 | 1651 | |
1652 | - if ( ! $this->is_taxable() ) { |
|
1653 | - $tax = wpinv_round_amount( 0.00 ); |
|
1652 | + if (!$this->is_taxable()) { |
|
1653 | + $tax = wpinv_round_amount(0.00); |
|
1654 | 1654 | } |
1655 | 1655 | |
1656 | - return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency ); |
|
1656 | + return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency); |
|
1657 | 1657 | } |
1658 | 1658 | |
1659 | - public function get_fees( $type = 'all' ) { |
|
1660 | - $fees = array(); |
|
1659 | + public function get_fees($type = 'all') { |
|
1660 | + $fees = array(); |
|
1661 | 1661 | |
1662 | - if ( ! empty( $this->fees ) && is_array( $this->fees ) ) { |
|
1663 | - foreach ( $this->fees as $fee ) { |
|
1664 | - if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) { |
|
1662 | + if (!empty($this->fees) && is_array($this->fees)) { |
|
1663 | + foreach ($this->fees as $fee) { |
|
1664 | + if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) { |
|
1665 | 1665 | continue; |
1666 | 1666 | } |
1667 | 1667 | |
1668 | - $fee['label'] = stripslashes( $fee['label'] ); |
|
1669 | - $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() ); |
|
1670 | - $fees[] = $fee; |
|
1668 | + $fee['label'] = stripslashes($fee['label']); |
|
1669 | + $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency()); |
|
1670 | + $fees[] = $fee; |
|
1671 | 1671 | } |
1672 | 1672 | } |
1673 | 1673 | |
1674 | - return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this ); |
|
1674 | + return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | - public function get_fees_total( $type = 'all' ) { |
|
1677 | + public function get_fees_total($type = 'all') { |
|
1678 | 1678 | $fees_total = (float) 0.00; |
1679 | 1679 | |
1680 | - $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array(); |
|
1681 | - if ( ! empty( $payment_fees ) ) { |
|
1682 | - foreach ( $payment_fees as $fee ) { |
|
1680 | + $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array(); |
|
1681 | + if (!empty($payment_fees)) { |
|
1682 | + foreach ($payment_fees as $fee) { |
|
1683 | 1683 | $fees_total += (float) $fee['amount']; |
1684 | 1684 | } |
1685 | 1685 | } |
1686 | 1686 | |
1687 | - return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this ); |
|
1687 | + return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this); |
|
1688 | 1688 | /* |
1689 | 1689 | $fees = $this->get_fees( $type ); |
1690 | 1690 | |
@@ -1704,116 +1704,116 @@ discard block |
||
1704 | 1704 | } |
1705 | 1705 | |
1706 | 1706 | public function get_user_id() { |
1707 | - return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this ); |
|
1707 | + return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this); |
|
1708 | 1708 | } |
1709 | 1709 | |
1710 | 1710 | public function get_first_name() { |
1711 | - return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this ); |
|
1711 | + return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this); |
|
1712 | 1712 | } |
1713 | 1713 | |
1714 | 1714 | public function get_last_name() { |
1715 | - return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this ); |
|
1715 | + return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this); |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | public function get_user_full_name() { |
1719 | - return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this ); |
|
1719 | + return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this); |
|
1720 | 1720 | } |
1721 | 1721 | |
1722 | 1722 | public function get_user_info() { |
1723 | - return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this ); |
|
1723 | + return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this); |
|
1724 | 1724 | } |
1725 | 1725 | |
1726 | 1726 | public function get_email() { |
1727 | - return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this ); |
|
1727 | + return apply_filters('wpinv_user_email', $this->email, $this->ID, $this); |
|
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | public function get_address() { |
1731 | - return apply_filters( 'wpinv_address', $this->address, $this->ID, $this ); |
|
1731 | + return apply_filters('wpinv_address', $this->address, $this->ID, $this); |
|
1732 | 1732 | } |
1733 | 1733 | |
1734 | 1734 | public function get_phone() { |
1735 | - return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this ); |
|
1735 | + return apply_filters('wpinv_phone', $this->phone, $this->ID, $this); |
|
1736 | 1736 | } |
1737 | 1737 | |
1738 | 1738 | public function get_number() { |
1739 | - return apply_filters( 'wpinv_number', $this->number, $this->ID, $this ); |
|
1739 | + return apply_filters('wpinv_number', $this->number, $this->ID, $this); |
|
1740 | 1740 | } |
1741 | 1741 | |
1742 | 1742 | public function get_items() { |
1743 | - return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this ); |
|
1743 | + return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this); |
|
1744 | 1744 | } |
1745 | 1745 | |
1746 | 1746 | public function get_key() { |
1747 | - return apply_filters( 'wpinv_key', $this->key, $this->ID, $this ); |
|
1747 | + return apply_filters('wpinv_key', $this->key, $this->ID, $this); |
|
1748 | 1748 | } |
1749 | 1749 | |
1750 | 1750 | public function get_transaction_id() { |
1751 | - return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this ); |
|
1751 | + return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this); |
|
1752 | 1752 | } |
1753 | 1753 | |
1754 | 1754 | public function get_gateway() { |
1755 | - return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this ); |
|
1755 | + return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | public function get_gateway_title() { |
1759 | - $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway ); |
|
1759 | + $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway); |
|
1760 | 1760 | |
1761 | - return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this ); |
|
1761 | + return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this); |
|
1762 | 1762 | } |
1763 | 1763 | |
1764 | 1764 | public function get_currency() { |
1765 | - return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this ); |
|
1765 | + return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this); |
|
1766 | 1766 | } |
1767 | 1767 | |
1768 | 1768 | public function get_created_date() { |
1769 | - return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this ); |
|
1769 | + return apply_filters('wpinv_created_date', $this->date, $this->ID, $this); |
|
1770 | 1770 | } |
1771 | 1771 | |
1772 | - public function get_due_date( $display = false ) { |
|
1773 | - $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this ); |
|
1772 | + public function get_due_date($display = false) { |
|
1773 | + $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this); |
|
1774 | 1774 | |
1775 | - if ( ! $display ) { |
|
1775 | + if (!$display) { |
|
1776 | 1776 | return $due_date; |
1777 | 1777 | } |
1778 | 1778 | |
1779 | - return getpaid_format_date( $this->due_date ); |
|
1779 | + return getpaid_format_date($this->due_date); |
|
1780 | 1780 | } |
1781 | 1781 | |
1782 | 1782 | public function get_completed_date() { |
1783 | - return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this ); |
|
1783 | + return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this); |
|
1784 | 1784 | } |
1785 | 1785 | |
1786 | - public function get_invoice_date( $formatted = true ) { |
|
1786 | + public function get_invoice_date($formatted = true) { |
|
1787 | 1787 | $date_completed = $this->completed_date; |
1788 | 1788 | $invoice_date = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : ''; |
1789 | 1789 | |
1790 | - if ( $invoice_date == '' ) { |
|
1790 | + if ($invoice_date == '') { |
|
1791 | 1791 | $date_created = $this->date; |
1792 | 1792 | $invoice_date = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : ''; |
1793 | 1793 | } |
1794 | 1794 | |
1795 | - if ( $formatted && $invoice_date ) { |
|
1796 | - $invoice_date = getpaid_format_date( $invoice_date ); |
|
1795 | + if ($formatted && $invoice_date) { |
|
1796 | + $invoice_date = getpaid_format_date($invoice_date); |
|
1797 | 1797 | } |
1798 | 1798 | |
1799 | - return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this ); |
|
1799 | + return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this); |
|
1800 | 1800 | } |
1801 | 1801 | |
1802 | 1802 | public function get_ip() { |
1803 | - return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this ); |
|
1803 | + return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this); |
|
1804 | 1804 | } |
1805 | 1805 | |
1806 | - public function has_status( $status ) { |
|
1807 | - return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status ); |
|
1806 | + public function has_status($status) { |
|
1807 | + return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status); |
|
1808 | 1808 | } |
1809 | 1809 | |
1810 | - public function add_item( $item_id = 0, $args = array() ) { |
|
1810 | + public function add_item($item_id = 0, $args = array()) { |
|
1811 | 1811 | global $wpi_current_id, $wpi_item_id; |
1812 | 1812 | |
1813 | - $item = new WPInv_Item( $item_id ); |
|
1813 | + $item = new WPInv_Item($item_id); |
|
1814 | 1814 | |
1815 | 1815 | // Bail if this post isn't a item |
1816 | - if( !$item || $item->post_type !== 'wpi_item' ) { |
|
1816 | + if (!$item || $item->post_type !== 'wpi_item') { |
|
1817 | 1817 | return false; |
1818 | 1818 | } |
1819 | 1819 | |
@@ -1832,8 +1832,8 @@ discard block |
||
1832 | 1832 | 'fees' => array() |
1833 | 1833 | ); |
1834 | 1834 | |
1835 | - $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults ); |
|
1836 | - $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1; |
|
1835 | + $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults); |
|
1836 | + $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1; |
|
1837 | 1837 | |
1838 | 1838 | $wpi_current_id = $this->ID; |
1839 | 1839 | $wpi_item_id = $item->ID; |
@@ -1845,19 +1845,19 @@ discard block |
||
1845 | 1845 | $found_cart_key = false; |
1846 | 1846 | |
1847 | 1847 | if ($has_quantities) { |
1848 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1848 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1849 | 1849 | |
1850 | - foreach ( $this->items as $key => $cart_item ) { |
|
1851 | - if ( (int)$item_id !== (int)$cart_item['id'] ) { |
|
1850 | + foreach ($this->items as $key => $cart_item) { |
|
1851 | + if ((int) $item_id !== (int) $cart_item['id']) { |
|
1852 | 1852 | continue; |
1853 | 1853 | } |
1854 | 1854 | |
1855 | - $this->items[ $key ]['quantity'] += $args['quantity']; |
|
1855 | + $this->items[$key]['quantity'] += $args['quantity']; |
|
1856 | 1856 | break; |
1857 | 1857 | } |
1858 | 1858 | |
1859 | - foreach ( $this->cart_details as $cart_key => $cart_item ) { |
|
1860 | - if ( $item_id != $cart_item['id'] ) { |
|
1859 | + foreach ($this->cart_details as $cart_key => $cart_item) { |
|
1860 | + if ($item_id != $cart_item['id']) { |
|
1861 | 1861 | continue; |
1862 | 1862 | } |
1863 | 1863 | |
@@ -1869,29 +1869,29 @@ discard block |
||
1869 | 1869 | if ($has_quantities && $found_cart_key !== false) { |
1870 | 1870 | $cart_item = $this->cart_details[$found_cart_key]; |
1871 | 1871 | $item_price = $cart_item['item_price']; |
1872 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
1873 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
1872 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
1873 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
1874 | 1874 | |
1875 | 1875 | $new_quantity = $quantity + $args['quantity']; |
1876 | 1876 | $subtotal = $item_price * $new_quantity; |
1877 | 1877 | |
1878 | 1878 | $args['quantity'] = $new_quantity; |
1879 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1880 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1879 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1880 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1881 | 1881 | |
1882 | - $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0; |
|
1883 | - $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0; |
|
1882 | + $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0; |
|
1883 | + $tax_increased = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0; |
|
1884 | 1884 | // The total increase equals the number removed * the item_price |
1885 | - $total_increased = wpinv_round_amount( $item_price ); |
|
1885 | + $total_increased = wpinv_round_amount($item_price); |
|
1886 | 1886 | |
1887 | - if ( wpinv_prices_include_tax() ) { |
|
1888 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1887 | + if (wpinv_prices_include_tax()) { |
|
1888 | + $subtotal -= wpinv_round_amount($tax); |
|
1889 | 1889 | } |
1890 | 1890 | |
1891 | - $total = $subtotal - $discount + $tax; |
|
1891 | + $total = $subtotal - $discount + $tax; |
|
1892 | 1892 | |
1893 | 1893 | // Do not allow totals to go negative |
1894 | - if( $total < 0 ) { |
|
1894 | + if ($total < 0) { |
|
1895 | 1895 | $total = 0; |
1896 | 1896 | } |
1897 | 1897 | |
@@ -1907,25 +1907,25 @@ discard block |
||
1907 | 1907 | $this->cart_details[$found_cart_key] = $cart_item; |
1908 | 1908 | } else { |
1909 | 1909 | // Set custom price. |
1910 | - if ( $args['custom_price'] !== '' ) { |
|
1910 | + if ($args['custom_price'] !== '') { |
|
1911 | 1911 | $item_price = $args['custom_price']; |
1912 | 1912 | } else { |
1913 | 1913 | // Allow overriding the price |
1914 | - if ( false !== $args['item_price'] ) { |
|
1914 | + if (false !== $args['item_price']) { |
|
1915 | 1915 | $item_price = $args['item_price']; |
1916 | 1916 | } else { |
1917 | - $item_price = wpinv_get_item_price( $item->ID ); |
|
1917 | + $item_price = wpinv_get_item_price($item->ID); |
|
1918 | 1918 | } |
1919 | 1919 | } |
1920 | 1920 | |
1921 | 1921 | // Sanitizing the price here so we don't have a dozen calls later |
1922 | - $item_price = wpinv_sanitize_amount( $item_price ); |
|
1923 | - $subtotal = wpinv_round_amount( $item_price * $args['quantity'] ); |
|
1922 | + $item_price = wpinv_sanitize_amount($item_price); |
|
1923 | + $subtotal = wpinv_round_amount($item_price * $args['quantity']); |
|
1924 | 1924 | |
1925 | - $discount = !empty( $args['discount'] ) ? $args['discount'] : 0; |
|
1926 | - $tax_class = !empty( $args['vat_class'] ) ? $args['vat_class'] : ''; |
|
1927 | - $tax_rate = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0; |
|
1928 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
1925 | + $discount = !empty($args['discount']) ? $args['discount'] : 0; |
|
1926 | + $tax_class = !empty($args['vat_class']) ? $args['vat_class'] : ''; |
|
1927 | + $tax_rate = !empty($args['vat_rate']) ? $args['vat_rate'] : 0; |
|
1928 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
1929 | 1929 | |
1930 | 1930 | // Setup the items meta item |
1931 | 1931 | $new_item = array( |
@@ -1933,29 +1933,29 @@ discard block |
||
1933 | 1933 | 'quantity' => $args['quantity'], |
1934 | 1934 | ); |
1935 | 1935 | |
1936 | - $this->items[] = $new_item; |
|
1936 | + $this->items[] = $new_item; |
|
1937 | 1937 | |
1938 | - if ( wpinv_prices_include_tax() ) { |
|
1939 | - $subtotal -= wpinv_round_amount( $tax ); |
|
1938 | + if (wpinv_prices_include_tax()) { |
|
1939 | + $subtotal -= wpinv_round_amount($tax); |
|
1940 | 1940 | } |
1941 | 1941 | |
1942 | - $total = $subtotal - $discount + $tax; |
|
1942 | + $total = $subtotal - $discount + $tax; |
|
1943 | 1943 | |
1944 | 1944 | // Do not allow totals to go negative |
1945 | - if( $total < 0 ) { |
|
1945 | + if ($total < 0) { |
|
1946 | 1946 | $total = 0; |
1947 | 1947 | } |
1948 | 1948 | |
1949 | 1949 | $this->cart_details[] = array( |
1950 | 1950 | 'name' => !empty($args['name']) ? $args['name'] : $item->get_name(), |
1951 | 1951 | 'id' => $item->ID, |
1952 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
1953 | - 'custom_price' => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ), |
|
1952 | + 'item_price' => wpinv_round_amount($item_price), |
|
1953 | + 'custom_price' => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''), |
|
1954 | 1954 | 'quantity' => $args['quantity'], |
1955 | 1955 | 'discount' => $discount, |
1956 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
1957 | - 'tax' => wpinv_round_amount( $tax ), |
|
1958 | - 'price' => wpinv_round_amount( $total ), |
|
1956 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
1957 | + 'tax' => wpinv_round_amount($tax), |
|
1958 | + 'price' => wpinv_round_amount($total), |
|
1959 | 1959 | 'vat_rate' => $tax_rate, |
1960 | 1960 | 'vat_class' => $tax_class, |
1961 | 1961 | 'meta' => $args['meta'], |
@@ -1965,18 +1965,18 @@ discard block |
||
1965 | 1965 | $subtotal = $subtotal - $discount; |
1966 | 1966 | } |
1967 | 1967 | |
1968 | - $added_item = end( $this->cart_details ); |
|
1969 | - $added_item['action'] = 'add'; |
|
1968 | + $added_item = end($this->cart_details); |
|
1969 | + $added_item['action'] = 'add'; |
|
1970 | 1970 | |
1971 | 1971 | $this->pending['items'][] = $added_item; |
1972 | 1972 | |
1973 | - $this->increase_subtotal( $subtotal ); |
|
1974 | - $this->increase_tax( $tax ); |
|
1973 | + $this->increase_subtotal($subtotal); |
|
1974 | + $this->increase_tax($tax); |
|
1975 | 1975 | |
1976 | 1976 | return true; |
1977 | 1977 | } |
1978 | 1978 | |
1979 | - public function remove_item( $item_id, $args = array() ) { |
|
1979 | + public function remove_item($item_id, $args = array()) { |
|
1980 | 1980 | // Set some defaults |
1981 | 1981 | $defaults = array( |
1982 | 1982 | 'quantity' => 1, |
@@ -1984,51 +1984,51 @@ discard block |
||
1984 | 1984 | 'custom_price' => '', |
1985 | 1985 | 'cart_index' => false, |
1986 | 1986 | ); |
1987 | - $args = wp_parse_args( $args, $defaults ); |
|
1987 | + $args = wp_parse_args($args, $defaults); |
|
1988 | 1988 | |
1989 | 1989 | // Bail if this post isn't a item |
1990 | - if ( get_post_type( $item_id ) !== 'wpi_item' ) { |
|
1990 | + if (get_post_type($item_id) !== 'wpi_item') { |
|
1991 | 1991 | return false; |
1992 | 1992 | } |
1993 | 1993 | |
1994 | - $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details; |
|
1994 | + $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details; |
|
1995 | 1995 | |
1996 | - foreach ( $this->items as $key => $item ) { |
|
1997 | - if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) { |
|
1996 | + foreach ($this->items as $key => $item) { |
|
1997 | + if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) { |
|
1998 | 1998 | continue; |
1999 | 1999 | } |
2000 | 2000 | |
2001 | - if ( false !== $args['cart_index'] ) { |
|
2002 | - $cart_index = absint( $args['cart_index'] ); |
|
2003 | - $cart_item = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false; |
|
2001 | + if (false !== $args['cart_index']) { |
|
2002 | + $cart_index = absint($args['cart_index']); |
|
2003 | + $cart_item = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false; |
|
2004 | 2004 | |
2005 | - if ( ! empty( $cart_item ) ) { |
|
2005 | + if (!empty($cart_item)) { |
|
2006 | 2006 | // If the cart index item isn't the same item ID, don't remove it |
2007 | - if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) { |
|
2007 | + if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) { |
|
2008 | 2008 | continue; |
2009 | 2009 | } |
2010 | 2010 | } |
2011 | 2011 | } |
2012 | 2012 | |
2013 | - $item_quantity = $this->items[ $key ]['quantity']; |
|
2014 | - if ( $item_quantity > $args['quantity'] ) { |
|
2015 | - $this->items[ $key ]['quantity'] -= $args['quantity']; |
|
2013 | + $item_quantity = $this->items[$key]['quantity']; |
|
2014 | + if ($item_quantity > $args['quantity']) { |
|
2015 | + $this->items[$key]['quantity'] -= $args['quantity']; |
|
2016 | 2016 | break; |
2017 | 2017 | } else { |
2018 | - unset( $this->items[ $key ] ); |
|
2018 | + unset($this->items[$key]); |
|
2019 | 2019 | break; |
2020 | 2020 | } |
2021 | 2021 | } |
2022 | 2022 | |
2023 | 2023 | $found_cart_key = false; |
2024 | - if ( false === $args['cart_index'] ) { |
|
2025 | - foreach ( $this->cart_details as $cart_key => $item ) { |
|
2026 | - if ( $item_id != $item['id'] ) { |
|
2024 | + if (false === $args['cart_index']) { |
|
2025 | + foreach ($this->cart_details as $cart_key => $item) { |
|
2026 | + if ($item_id != $item['id']) { |
|
2027 | 2027 | continue; |
2028 | 2028 | } |
2029 | 2029 | |
2030 | - if ( false !== $args['item_price'] ) { |
|
2031 | - if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) { |
|
2030 | + if (false !== $args['item_price']) { |
|
2031 | + if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) { |
|
2032 | 2032 | continue; |
2033 | 2033 | } |
2034 | 2034 | } |
@@ -2037,13 +2037,13 @@ discard block |
||
2037 | 2037 | break; |
2038 | 2038 | } |
2039 | 2039 | } else { |
2040 | - $cart_index = absint( $args['cart_index'] ); |
|
2040 | + $cart_index = absint($args['cart_index']); |
|
2041 | 2041 | |
2042 | - if ( ! array_key_exists( $cart_index, $this->cart_details ) ) { |
|
2042 | + if (!array_key_exists($cart_index, $this->cart_details)) { |
|
2043 | 2043 | return false; // Invalid cart index passed. |
2044 | 2044 | } |
2045 | 2045 | |
2046 | - if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) { |
|
2046 | + if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) { |
|
2047 | 2047 | return false; // We still need the proper Item ID to be sure. |
2048 | 2048 | } |
2049 | 2049 | |
@@ -2051,41 +2051,41 @@ discard block |
||
2051 | 2051 | } |
2052 | 2052 | |
2053 | 2053 | $cart_item = $this->cart_details[$found_cart_key]; |
2054 | - $quantity = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1; |
|
2054 | + $quantity = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1; |
|
2055 | 2055 | |
2056 | - if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) { |
|
2056 | + if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) { |
|
2057 | 2057 | //return false; // Invoice must contain at least one item. |
2058 | 2058 | } |
2059 | 2059 | |
2060 | - $discounts = $this->get_discounts(); |
|
2060 | + $discounts = $this->get_discounts(); |
|
2061 | 2061 | |
2062 | - if ( $quantity > $args['quantity'] ) { |
|
2062 | + if ($quantity > $args['quantity']) { |
|
2063 | 2063 | $item_price = $cart_item['item_price']; |
2064 | - $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0; |
|
2064 | + $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0; |
|
2065 | 2065 | |
2066 | - $new_quantity = max( $quantity - $args['quantity'], 1); |
|
2066 | + $new_quantity = max($quantity - $args['quantity'], 1); |
|
2067 | 2067 | $subtotal = $item_price * $new_quantity; |
2068 | 2068 | |
2069 | 2069 | $args['quantity'] = $new_quantity; |
2070 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
2071 | - $tax = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2070 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
2071 | + $tax = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2072 | 2072 | |
2073 | - $discount_decrease = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0; |
|
2074 | - $discount_decrease = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; |
|
2075 | - $tax_decrease = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0; |
|
2076 | - $tax_decrease = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease; |
|
2073 | + $discount_decrease = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0; |
|
2074 | + $discount_decrease = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; |
|
2075 | + $tax_decrease = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0; |
|
2076 | + $tax_decrease = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease; |
|
2077 | 2077 | |
2078 | 2078 | // The total increase equals the number removed * the item_price |
2079 | - $total_decrease = wpinv_round_amount( $item_price ); |
|
2079 | + $total_decrease = wpinv_round_amount($item_price); |
|
2080 | 2080 | |
2081 | - if ( wpinv_prices_include_tax() ) { |
|
2082 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2081 | + if (wpinv_prices_include_tax()) { |
|
2082 | + $subtotal -= wpinv_round_amount($tax); |
|
2083 | 2083 | } |
2084 | 2084 | |
2085 | - $total = $subtotal - $discount + $tax; |
|
2085 | + $total = $subtotal - $discount + $tax; |
|
2086 | 2086 | |
2087 | 2087 | // Do not allow totals to go negative |
2088 | - if( $total < 0 ) { |
|
2088 | + if ($total < 0) { |
|
2089 | 2089 | $total = 0; |
2090 | 2090 | } |
2091 | 2091 | |
@@ -2104,16 +2104,16 @@ discard block |
||
2104 | 2104 | |
2105 | 2105 | $this->cart_details[$found_cart_key] = $cart_item; |
2106 | 2106 | |
2107 | - $remove_item = end( $this->cart_details ); |
|
2107 | + $remove_item = end($this->cart_details); |
|
2108 | 2108 | } else { |
2109 | 2109 | $item_price = $cart_item['item_price']; |
2110 | - $discount = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0; |
|
2111 | - $tax = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0; |
|
2110 | + $discount = !empty($cart_item['discount']) ? $cart_item['discount'] : 0; |
|
2111 | + $tax = !empty($cart_item['tax']) ? $cart_item['tax'] : 0; |
|
2112 | 2112 | |
2113 | - $subtotal_decrease = ( $item_price * $quantity ) - $discount; |
|
2113 | + $subtotal_decrease = ($item_price * $quantity) - $discount; |
|
2114 | 2114 | $tax_decrease = $tax; |
2115 | 2115 | |
2116 | - unset( $this->cart_details[$found_cart_key] ); |
|
2116 | + unset($this->cart_details[$found_cart_key]); |
|
2117 | 2117 | |
2118 | 2118 | $remove_item = $args; |
2119 | 2119 | $remove_item['id'] = $item_id; |
@@ -2124,8 +2124,8 @@ discard block |
||
2124 | 2124 | $remove_item['action'] = 'remove'; |
2125 | 2125 | $this->pending['items'][] = $remove_item; |
2126 | 2126 | |
2127 | - $this->decrease_subtotal( $subtotal_decrease ); |
|
2128 | - $this->decrease_tax( $tax_decrease ); |
|
2127 | + $this->decrease_subtotal($subtotal_decrease); |
|
2128 | + $this->decrease_tax($tax_decrease); |
|
2129 | 2129 | |
2130 | 2130 | return true; |
2131 | 2131 | } |
@@ -2133,7 +2133,7 @@ discard block |
||
2133 | 2133 | public function update_items($temp = false) { |
2134 | 2134 | global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave; |
2135 | 2135 | |
2136 | - if ( !empty( $this->cart_details ) ) { |
|
2136 | + if (!empty($this->cart_details)) { |
|
2137 | 2137 | $wpi_nosave = $temp; |
2138 | 2138 | $cart_subtotal = 0; |
2139 | 2139 | $cart_discount = 0; |
@@ -2143,65 +2143,65 @@ discard block |
||
2143 | 2143 | $_POST['wpinv_country'] = $this->country; |
2144 | 2144 | $_POST['wpinv_state'] = $this->state; |
2145 | 2145 | |
2146 | - foreach ( $this->cart_details as $key => $item ) { |
|
2146 | + foreach ($this->cart_details as $key => $item) { |
|
2147 | 2147 | $item_price = $item['item_price']; |
2148 | - $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1; |
|
2149 | - $amount = wpinv_round_amount( $item_price * $quantity ); |
|
2148 | + $quantity = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1; |
|
2149 | + $amount = wpinv_round_amount($item_price * $quantity); |
|
2150 | 2150 | $subtotal = $item_price * $quantity; |
2151 | 2151 | |
2152 | 2152 | $wpi_current_id = $this->ID; |
2153 | 2153 | $wpi_item_id = $item['id']; |
2154 | 2154 | |
2155 | - $discount = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() ); |
|
2155 | + $discount = wpinv_get_cart_item_discount_amount($item, $this->get_discounts()); |
|
2156 | 2156 | |
2157 | - $tax_rate = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id ); |
|
2158 | - $tax_class = $wpinv_euvat->get_item_class( $wpi_item_id ); |
|
2159 | - $tax = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0; |
|
2157 | + $tax_rate = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id); |
|
2158 | + $tax_class = $wpinv_euvat->get_item_class($wpi_item_id); |
|
2159 | + $tax = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0; |
|
2160 | 2160 | |
2161 | - if ( ! $this->is_taxable() ) { |
|
2161 | + if (!$this->is_taxable()) { |
|
2162 | 2162 | $tax = 0; |
2163 | 2163 | } |
2164 | 2164 | |
2165 | - if ( wpinv_prices_include_tax() ) { |
|
2166 | - $subtotal -= wpinv_round_amount( $tax ); |
|
2165 | + if (wpinv_prices_include_tax()) { |
|
2166 | + $subtotal -= wpinv_round_amount($tax); |
|
2167 | 2167 | } |
2168 | 2168 | |
2169 | - $total = $subtotal - $discount + $tax; |
|
2169 | + $total = $subtotal - $discount + $tax; |
|
2170 | 2170 | |
2171 | 2171 | // Do not allow totals to go negative |
2172 | - if( $total < 0 ) { |
|
2172 | + if ($total < 0) { |
|
2173 | 2173 | $total = 0; |
2174 | 2174 | } |
2175 | 2175 | |
2176 | 2176 | $cart_details[] = array( |
2177 | 2177 | 'id' => $item['id'], |
2178 | 2178 | 'name' => $item['name'], |
2179 | - 'item_price' => wpinv_round_amount( $item_price ), |
|
2180 | - 'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ), |
|
2179 | + 'item_price' => wpinv_round_amount($item_price), |
|
2180 | + 'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''), |
|
2181 | 2181 | 'quantity' => $quantity, |
2182 | 2182 | 'discount' => $discount, |
2183 | - 'subtotal' => wpinv_round_amount( $subtotal ), |
|
2184 | - 'tax' => wpinv_round_amount( $tax ), |
|
2185 | - 'price' => wpinv_round_amount( $total ), |
|
2183 | + 'subtotal' => wpinv_round_amount($subtotal), |
|
2184 | + 'tax' => wpinv_round_amount($tax), |
|
2185 | + 'price' => wpinv_round_amount($total), |
|
2186 | 2186 | 'vat_rate' => $tax_rate, |
2187 | 2187 | 'vat_class' => $tax_class, |
2188 | 2188 | 'meta' => isset($item['meta']) ? $item['meta'] : array(), |
2189 | 2189 | 'fees' => isset($item['fees']) ? $item['fees'] : array(), |
2190 | 2190 | ); |
2191 | 2191 | |
2192 | - $cart_subtotal += (float)($subtotal - $discount); // TODO |
|
2193 | - $cart_discount += (float)($discount); |
|
2194 | - $cart_tax += (float)($tax); |
|
2192 | + $cart_subtotal += (float) ($subtotal - $discount); // TODO |
|
2193 | + $cart_discount += (float) ($discount); |
|
2194 | + $cart_tax += (float) ($tax); |
|
2195 | 2195 | } |
2196 | - if ( $cart_subtotal < 0 ) { |
|
2196 | + if ($cart_subtotal < 0) { |
|
2197 | 2197 | $cart_subtotal = 0; |
2198 | 2198 | } |
2199 | - if ( $cart_tax < 0 ) { |
|
2199 | + if ($cart_tax < 0) { |
|
2200 | 2200 | $cart_tax = 0; |
2201 | 2201 | } |
2202 | - $this->subtotal = wpinv_round_amount( $cart_subtotal ); |
|
2203 | - $this->tax = wpinv_round_amount( $cart_tax ); |
|
2204 | - $this->discount = wpinv_round_amount( $cart_discount ); |
|
2202 | + $this->subtotal = wpinv_round_amount($cart_subtotal); |
|
2203 | + $this->tax = wpinv_round_amount($cart_tax); |
|
2204 | + $this->discount = wpinv_round_amount($cart_discount); |
|
2205 | 2205 | |
2206 | 2206 | $this->recalculate_total(); |
2207 | 2207 | |
@@ -2213,177 +2213,177 @@ discard block |
||
2213 | 2213 | |
2214 | 2214 | public function recalculate_totals($temp = false) { |
2215 | 2215 | $this->update_items($temp); |
2216 | - $this->save( true ); |
|
2216 | + $this->save(true); |
|
2217 | 2217 | |
2218 | 2218 | return $this; |
2219 | 2219 | } |
2220 | 2220 | |
2221 | 2221 | public function needs_payment() { |
2222 | - $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this ); |
|
2222 | + $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this); |
|
2223 | 2223 | |
2224 | - if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) { |
|
2224 | + if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) { |
|
2225 | 2225 | $needs_payment = true; |
2226 | 2226 | } else { |
2227 | 2227 | $needs_payment = false; |
2228 | 2228 | } |
2229 | 2229 | |
2230 | - return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses ); |
|
2230 | + return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses); |
|
2231 | 2231 | } |
2232 | 2232 | |
2233 | - public function get_checkout_payment_url( $with_key = false, $secret = false ) { |
|
2233 | + public function get_checkout_payment_url($with_key = false, $secret = false) { |
|
2234 | 2234 | $pay_url = wpinv_get_checkout_uri(); |
2235 | 2235 | |
2236 | - if ( is_ssl() ) { |
|
2237 | - $pay_url = str_replace( 'http:', 'https:', $pay_url ); |
|
2236 | + if (is_ssl()) { |
|
2237 | + $pay_url = str_replace('http:', 'https:', $pay_url); |
|
2238 | 2238 | } |
2239 | 2239 | |
2240 | 2240 | $key = $this->get_key(); |
2241 | 2241 | |
2242 | - if ( $with_key ) { |
|
2243 | - $pay_url = add_query_arg( 'invoice_key', $key, $pay_url ); |
|
2242 | + if ($with_key) { |
|
2243 | + $pay_url = add_query_arg('invoice_key', $key, $pay_url); |
|
2244 | 2244 | } else { |
2245 | - $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url ); |
|
2245 | + $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url); |
|
2246 | 2246 | } |
2247 | 2247 | |
2248 | - if ( $secret ) { |
|
2249 | - $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url ); |
|
2248 | + if ($secret) { |
|
2249 | + $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url); |
|
2250 | 2250 | } |
2251 | 2251 | |
2252 | - return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret ); |
|
2252 | + return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret); |
|
2253 | 2253 | } |
2254 | 2254 | |
2255 | - public function get_view_url( $with_key = false ) { |
|
2256 | - $invoice_url = get_permalink( $this->ID ); |
|
2255 | + public function get_view_url($with_key = false) { |
|
2256 | + $invoice_url = get_permalink($this->ID); |
|
2257 | 2257 | |
2258 | - if ( $with_key ) { |
|
2259 | - $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url ); |
|
2258 | + if ($with_key) { |
|
2259 | + $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url); |
|
2260 | 2260 | } |
2261 | 2261 | |
2262 | - return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key ); |
|
2262 | + return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key); |
|
2263 | 2263 | } |
2264 | 2264 | |
2265 | - public function generate_key( $string = '' ) { |
|
2266 | - $auth_key = defined( 'AUTH_KEY' ) ? AUTH_KEY : ''; |
|
2267 | - return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) ); // Unique key |
|
2265 | + public function generate_key($string = '') { |
|
2266 | + $auth_key = defined('AUTH_KEY') ? AUTH_KEY : ''; |
|
2267 | + return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key |
|
2268 | 2268 | } |
2269 | 2269 | |
2270 | 2270 | public function is_recurring() { |
2271 | - if ( empty( $this->cart_details ) ) { |
|
2271 | + if (empty($this->cart_details)) { |
|
2272 | 2272 | return false; |
2273 | 2273 | } |
2274 | 2274 | |
2275 | 2275 | $has_subscription = false; |
2276 | - foreach( $this->cart_details as $cart_item ) { |
|
2277 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2276 | + foreach ($this->cart_details as $cart_item) { |
|
2277 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2278 | 2278 | $has_subscription = true; |
2279 | 2279 | break; |
2280 | 2280 | } |
2281 | 2281 | } |
2282 | 2282 | |
2283 | - if ( count( $this->cart_details ) > 1 ) { |
|
2283 | + if (count($this->cart_details) > 1) { |
|
2284 | 2284 | $has_subscription = false; |
2285 | 2285 | } |
2286 | 2286 | |
2287 | - return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details ); |
|
2287 | + return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details); |
|
2288 | 2288 | } |
2289 | 2289 | |
2290 | 2290 | public function is_free_trial() { |
2291 | 2291 | $is_free_trial = false; |
2292 | 2292 | |
2293 | - if ( $this->is_parent() && $item = $this->get_recurring( true ) ) { |
|
2294 | - if ( !empty( $item ) && $item->has_free_trial() ) { |
|
2293 | + if ($this->is_parent() && $item = $this->get_recurring(true)) { |
|
2294 | + if (!empty($item) && $item->has_free_trial()) { |
|
2295 | 2295 | $is_free_trial = true; |
2296 | 2296 | } |
2297 | 2297 | } |
2298 | 2298 | |
2299 | - return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this ); |
|
2299 | + return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this); |
|
2300 | 2300 | } |
2301 | 2301 | |
2302 | 2302 | public function is_initial_free() { |
2303 | 2303 | $is_initial_free = false; |
2304 | 2304 | |
2305 | - if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) { |
|
2305 | + if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) { |
|
2306 | 2306 | $is_initial_free = true; |
2307 | 2307 | } |
2308 | 2308 | |
2309 | - return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details ); |
|
2309 | + return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | - public function get_recurring( $object = false ) { |
|
2312 | + public function get_recurring($object = false) { |
|
2313 | 2313 | $item = NULL; |
2314 | 2314 | |
2315 | - if ( empty( $this->cart_details ) ) { |
|
2315 | + if (empty($this->cart_details)) { |
|
2316 | 2316 | return $item; |
2317 | 2317 | } |
2318 | 2318 | |
2319 | - foreach( $this->cart_details as $cart_item ) { |
|
2320 | - if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] ) ) { |
|
2319 | + foreach ($this->cart_details as $cart_item) { |
|
2320 | + if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) { |
|
2321 | 2321 | $item = $cart_item['id']; |
2322 | 2322 | break; |
2323 | 2323 | } |
2324 | 2324 | } |
2325 | 2325 | |
2326 | - if ( $object ) { |
|
2327 | - $item = $item ? new WPInv_Item( $item ) : NULL; |
|
2326 | + if ($object) { |
|
2327 | + $item = $item ? new WPInv_Item($item) : NULL; |
|
2328 | 2328 | |
2329 | - apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this ); |
|
2329 | + apply_filters('wpinv_invoice_get_recurring_item', $item, $this); |
|
2330 | 2330 | } |
2331 | 2331 | |
2332 | - return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this ); |
|
2332 | + return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this); |
|
2333 | 2333 | } |
2334 | 2334 | |
2335 | 2335 | public function get_subscription_name() { |
2336 | - $item = $this->get_recurring( true ); |
|
2336 | + $item = $this->get_recurring(true); |
|
2337 | 2337 | |
2338 | - if ( empty( $item ) ) { |
|
2338 | + if (empty($item)) { |
|
2339 | 2339 | return NULL; |
2340 | 2340 | } |
2341 | 2341 | |
2342 | - if ( !($name = $item->get_name()) ) { |
|
2342 | + if (!($name = $item->get_name())) { |
|
2343 | 2343 | $name = $item->post_name; |
2344 | 2344 | } |
2345 | 2345 | |
2346 | - return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this ); |
|
2346 | + return apply_filters('wpinv_invoice_get_subscription_name', $name, $this); |
|
2347 | 2347 | } |
2348 | 2348 | |
2349 | 2349 | public function get_subscription_id() { |
2350 | - $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2350 | + $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true); |
|
2351 | 2351 | |
2352 | - if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) { |
|
2353 | - $parent_invoice = wpinv_get_invoice( $this->parent_invoice ); |
|
2352 | + if (empty($subscription_id) && !empty($this->parent_invoice)) { |
|
2353 | + $parent_invoice = wpinv_get_invoice($this->parent_invoice); |
|
2354 | 2354 | |
2355 | - $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true ); |
|
2355 | + $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true); |
|
2356 | 2356 | } |
2357 | 2357 | |
2358 | 2358 | return $subscription_id; |
2359 | 2359 | } |
2360 | 2360 | |
2361 | 2361 | public function is_parent() { |
2362 | - $is_parent = empty( $this->parent_invoice ) ? true : false; |
|
2362 | + $is_parent = empty($this->parent_invoice) ? true : false; |
|
2363 | 2363 | |
2364 | - return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this ); |
|
2364 | + return apply_filters('wpinv_invoice_is_parent', $is_parent, $this); |
|
2365 | 2365 | } |
2366 | 2366 | |
2367 | 2367 | public function is_renewal() { |
2368 | 2368 | $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false; |
2369 | 2369 | |
2370 | - return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this ); |
|
2370 | + return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this); |
|
2371 | 2371 | } |
2372 | 2372 | |
2373 | 2373 | public function get_parent_payment() { |
2374 | 2374 | $parent_payment = NULL; |
2375 | 2375 | |
2376 | - if ( $this->is_renewal() ) { |
|
2377 | - $parent_payment = wpinv_get_invoice( $this->parent_invoice ); |
|
2376 | + if ($this->is_renewal()) { |
|
2377 | + $parent_payment = wpinv_get_invoice($this->parent_invoice); |
|
2378 | 2378 | } |
2379 | 2379 | |
2380 | 2380 | return $parent_payment; |
2381 | 2381 | } |
2382 | 2382 | |
2383 | 2383 | public function is_paid() { |
2384 | - $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) ); |
|
2384 | + $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal')); |
|
2385 | 2385 | |
2386 | - return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this ); |
|
2386 | + return apply_filters('wpinv_invoice_is_paid', $is_paid, $this); |
|
2387 | 2387 | } |
2388 | 2388 | |
2389 | 2389 | /** |
@@ -2396,23 +2396,23 @@ discard block |
||
2396 | 2396 | } |
2397 | 2397 | |
2398 | 2398 | public function is_refunded() { |
2399 | - $is_refunded = $this->has_status( array( 'wpi-refunded' ) ); |
|
2399 | + $is_refunded = $this->has_status(array('wpi-refunded')); |
|
2400 | 2400 | |
2401 | - return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this ); |
|
2401 | + return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this); |
|
2402 | 2402 | } |
2403 | 2403 | |
2404 | 2404 | public function is_free() { |
2405 | 2405 | $is_free = false; |
2406 | 2406 | |
2407 | - if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) { |
|
2408 | - if ( $this->is_parent() && $this->is_recurring() ) { |
|
2409 | - $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true; |
|
2407 | + if (!((float) wpinv_round_amount($this->get_total()) > 0)) { |
|
2408 | + if ($this->is_parent() && $this->is_recurring()) { |
|
2409 | + $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true; |
|
2410 | 2410 | } else { |
2411 | 2411 | $is_free = true; |
2412 | 2412 | } |
2413 | 2413 | } |
2414 | 2414 | |
2415 | - return apply_filters( 'wpinv_invoice_is_free', $is_free, $this ); |
|
2415 | + return apply_filters('wpinv_invoice_is_free', $is_free, $this); |
|
2416 | 2416 | } |
2417 | 2417 | |
2418 | 2418 | public function has_vat() { |
@@ -2420,41 +2420,41 @@ discard block |
||
2420 | 2420 | |
2421 | 2421 | $requires_vat = false; |
2422 | 2422 | |
2423 | - if ( $this->country ) { |
|
2423 | + if ($this->country) { |
|
2424 | 2424 | $wpi_country = $this->country; |
2425 | 2425 | |
2426 | - $requires_vat = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) ); |
|
2426 | + $requires_vat = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this)); |
|
2427 | 2427 | } |
2428 | 2428 | |
2429 | - return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this ); |
|
2429 | + return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this); |
|
2430 | 2430 | } |
2431 | 2431 | |
2432 | 2432 | public function refresh_item_ids() { |
2433 | 2433 | $item_ids = array(); |
2434 | 2434 | |
2435 | - if ( !empty( $this->cart_details ) ) { |
|
2436 | - foreach ( $this->cart_details as $key => $item ) { |
|
2437 | - if ( !empty( $item['id'] ) ) { |
|
2435 | + if (!empty($this->cart_details)) { |
|
2436 | + foreach ($this->cart_details as $key => $item) { |
|
2437 | + if (!empty($item['id'])) { |
|
2438 | 2438 | $item_ids[] = $item['id']; |
2439 | 2439 | } |
2440 | 2440 | } |
2441 | 2441 | } |
2442 | 2442 | |
2443 | - $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : ''; |
|
2443 | + $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : ''; |
|
2444 | 2444 | |
2445 | - update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids ); |
|
2445 | + update_post_meta($this->ID, '_wpinv_item_ids', $item_ids); |
|
2446 | 2446 | } |
2447 | 2447 | |
2448 | - public function get_invoice_quote_type( $post_id ) { |
|
2449 | - if ( empty( $post_id ) ) { |
|
2448 | + public function get_invoice_quote_type($post_id) { |
|
2449 | + if (empty($post_id)) { |
|
2450 | 2450 | return ''; |
2451 | 2451 | } |
2452 | 2452 | |
2453 | - $type = get_post_type( $post_id ); |
|
2453 | + $type = get_post_type($post_id); |
|
2454 | 2454 | |
2455 | - if ( 'wpi_invoice' === $type ) { |
|
2455 | + if ('wpi_invoice' === $type) { |
|
2456 | 2456 | $post_type = __('Invoice', 'invoicing'); |
2457 | - } else{ |
|
2457 | + } else { |
|
2458 | 2458 | $post_type = __('Quote', 'invoicing'); |
2459 | 2459 | } |
2460 | 2460 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * @since 1.0.0 |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * Retrieves all default settings. |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | function wpinv_get_settings() { |
17 | 17 | $defaults = array(); |
18 | 18 | |
19 | - foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) { |
|
19 | + foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) { |
|
20 | 20 | |
21 | - foreach ( array_values( $tab_settings ) as $section_settings ) { |
|
21 | + foreach (array_values($tab_settings) as $section_settings) { |
|
22 | 22 | |
23 | - foreach ( $section_settings as $key => $setting ) { |
|
24 | - if ( isset( $setting['std'] ) ) { |
|
25 | - $defaults[ $key ] = $setting['std']; |
|
23 | + foreach ($section_settings as $key => $setting) { |
|
24 | + if (isset($setting['std'])) { |
|
25 | + $defaults[$key] = $setting['std']; |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
@@ -43,12 +43,12 @@ discard block |
||
43 | 43 | global $wpinv_options; |
44 | 44 | |
45 | 45 | // Try fetching the saved options. |
46 | - if ( ! is_array( $wpinv_options ) ) { |
|
47 | - $wpinv_options = get_option( 'wpinv_settings' ); |
|
46 | + if (!is_array($wpinv_options)) { |
|
47 | + $wpinv_options = get_option('wpinv_settings'); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // If that fails, don't fetch the default settings to prevent a loop. |
51 | - if ( ! is_array( $wpinv_options ) ) { |
|
51 | + if (!is_array($wpinv_options)) { |
|
52 | 52 | $wpinv_options = array(); |
53 | 53 | } |
54 | 54 | |
@@ -62,13 +62,13 @@ discard block |
||
62 | 62 | * @param mixed $default The default value to use if the setting has not been set. |
63 | 63 | * @return mixed |
64 | 64 | */ |
65 | -function wpinv_get_option( $key = '', $default = false ) { |
|
65 | +function wpinv_get_option($key = '', $default = false) { |
|
66 | 66 | |
67 | 67 | $options = wpinv_get_options(); |
68 | - $value = isset( $options[ $key ] ) ? $options[ $key ] : $default; |
|
69 | - $value = apply_filters( 'wpinv_get_option', $value, $key, $default ); |
|
68 | + $value = isset($options[$key]) ? $options[$key] : $default; |
|
69 | + $value = apply_filters('wpinv_get_option', $value, $key, $default); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default ); |
|
71 | + return apply_filters('wpinv_get_option_' . $key, $value, $key, $default); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -77,11 +77,11 @@ discard block |
||
77 | 77 | * @param array $options the new options. |
78 | 78 | * @return bool |
79 | 79 | */ |
80 | -function wpinv_update_options( $options ) { |
|
80 | +function wpinv_update_options($options) { |
|
81 | 81 | global $wpinv_options; |
82 | 82 | |
83 | 83 | // update the option. |
84 | - if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) { |
|
84 | + if (is_array($options) && update_option('wpinv_settings', $options)) { |
|
85 | 85 | $wpinv_options = $options; |
86 | 86 | return true; |
87 | 87 | } |
@@ -96,24 +96,24 @@ discard block |
||
96 | 96 | * @param mixed $value The setting value. |
97 | 97 | * @return bool |
98 | 98 | */ |
99 | -function wpinv_update_option( $key = '', $value = false ) { |
|
99 | +function wpinv_update_option($key = '', $value = false) { |
|
100 | 100 | |
101 | 101 | // If no key, exit. |
102 | - if ( empty( $key ) ) { |
|
102 | + if (empty($key)) { |
|
103 | 103 | return false; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Maybe delete the option instead. |
107 | - if ( is_null( $value ) ) { |
|
108 | - return wpinv_delete_option( $key ); |
|
107 | + if (is_null($value)) { |
|
108 | + return wpinv_delete_option($key); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | // Prepare the new options. |
112 | 112 | $options = wpinv_get_options(); |
113 | - $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key ); |
|
113 | + $options[$key] = apply_filters('wpinv_update_option', $value, $key); |
|
114 | 114 | |
115 | 115 | // Save the new options. |
116 | - return wpinv_update_options( $options ); |
|
116 | + return wpinv_update_options($options); |
|
117 | 117 | |
118 | 118 | } |
119 | 119 | |
@@ -123,18 +123,18 @@ discard block |
||
123 | 123 | * @param string $key the setting key. |
124 | 124 | * @return bool |
125 | 125 | */ |
126 | -function wpinv_delete_option( $key = '' ) { |
|
126 | +function wpinv_delete_option($key = '') { |
|
127 | 127 | |
128 | 128 | // If no key, exit |
129 | - if ( empty( $key ) ) { |
|
129 | + if (empty($key)) { |
|
130 | 130 | return false; |
131 | 131 | } |
132 | 132 | |
133 | 133 | $options = wpinv_get_options(); |
134 | 134 | |
135 | - if ( isset( $options[ $key ] ) ) { |
|
136 | - unset( $options[ $key ] ); |
|
137 | - return wpinv_update_options( $options ); |
|
135 | + if (isset($options[$key])) { |
|
136 | + unset($options[$key]); |
|
137 | + return wpinv_update_options($options); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | return true; |
@@ -148,14 +148,14 @@ discard block |
||
148 | 148 | function wpinv_register_settings() { |
149 | 149 | |
150 | 150 | // Loop through all tabs. |
151 | - foreach ( wpinv_get_registered_settings() as $tab => $sections ) { |
|
151 | + foreach (wpinv_get_registered_settings() as $tab => $sections) { |
|
152 | 152 | |
153 | 153 | // In each tab, loop through sections. |
154 | - foreach ( $sections as $section => $settings ) { |
|
154 | + foreach ($sections as $section => $settings) { |
|
155 | 155 | |
156 | 156 | // Check for backwards compatibility |
157 | - $section_tabs = wpinv_get_settings_tab_sections( $tab ); |
|
158 | - if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) { |
|
157 | + $section_tabs = wpinv_get_settings_tab_sections($tab); |
|
158 | + if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) { |
|
159 | 159 | $section = 'main'; |
160 | 160 | $settings = $sections; |
161 | 161 | } |
@@ -168,9 +168,9 @@ discard block |
||
168 | 168 | 'wpinv_settings_' . $tab . '_' . $section |
169 | 169 | ); |
170 | 170 | |
171 | - foreach ( $settings as $option ) { |
|
172 | - if ( ! empty( $option['id'] ) ) { |
|
173 | - wpinv_register_settings_option( $tab, $section, $option ); |
|
171 | + foreach ($settings as $option) { |
|
172 | + if (!empty($option['id'])) { |
|
173 | + wpinv_register_settings_option($tab, $section, $option); |
|
174 | 174 | } |
175 | 175 | } |
176 | 176 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Creates our settings in the options table. |
181 | - register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' ); |
|
181 | + register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize'); |
|
182 | 182 | } |
183 | -add_action( 'admin_init', 'wpinv_register_settings' ); |
|
183 | +add_action('admin_init', 'wpinv_register_settings'); |
|
184 | 184 | |
185 | 185 | /** |
186 | 186 | * Register a single settings option. |
@@ -190,46 +190,46 @@ discard block |
||
190 | 190 | * @param string $option |
191 | 191 | * |
192 | 192 | */ |
193 | -function wpinv_register_settings_option( $tab, $section, $option ) { |
|
193 | +function wpinv_register_settings_option($tab, $section, $option) { |
|
194 | 194 | |
195 | - $name = isset( $option['name'] ) ? $option['name'] : ''; |
|
195 | + $name = isset($option['name']) ? $option['name'] : ''; |
|
196 | 196 | $cb = "wpinv_{$option['type']}_callback"; |
197 | 197 | $section = "wpinv_settings_{$tab}_$section"; |
198 | 198 | |
199 | - if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) { |
|
200 | - $tip = esc_attr( $option['desc'] ); |
|
199 | + if (isset($option['desc']) && !empty($option['help-tip'])) { |
|
200 | + $tip = esc_attr($option['desc']); |
|
201 | 201 | $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>"; |
202 | - unset( $option['desc'] ); |
|
202 | + unset($option['desc']); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | // Loop through all tabs. |
206 | 206 | add_settings_field( |
207 | 207 | 'wpinv_settings[' . $option['id'] . ']', |
208 | 208 | $name, |
209 | - function_exists( $cb ) ? $cb : 'wpinv_missing_callback', |
|
209 | + function_exists($cb) ? $cb : 'wpinv_missing_callback', |
|
210 | 210 | $section, |
211 | 211 | $section, |
212 | 212 | array( |
213 | 213 | 'section' => $section, |
214 | - 'id' => isset( $option['id'] ) ? $option['id'] : null, |
|
215 | - 'desc' => isset( $option['desc'] ) ? $option['desc'] : '', |
|
214 | + 'id' => isset($option['id']) ? $option['id'] : null, |
|
215 | + 'desc' => isset($option['desc']) ? $option['desc'] : '', |
|
216 | 216 | 'name' => $name, |
217 | - 'size' => isset( $option['size'] ) ? $option['size'] : null, |
|
218 | - 'options' => isset( $option['options'] ) ? $option['options'] : '', |
|
219 | - 'selected' => isset( $option['selected'] ) ? $option['selected'] : null, |
|
220 | - 'std' => isset( $option['std'] ) ? $option['std'] : '', |
|
221 | - 'min' => isset( $option['min'] ) ? $option['min'] : null, |
|
222 | - 'max' => isset( $option['max'] ) ? $option['max'] : null, |
|
223 | - 'step' => isset( $option['step'] ) ? $option['step'] : null, |
|
224 | - 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, |
|
225 | - 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, |
|
226 | - 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, |
|
227 | - 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, |
|
228 | - 'onchange' => isset( $option['onchange'] ) ? $option['onchange'] : '', |
|
229 | - 'custom' => isset( $option['custom'] ) ? $option['custom'] : '', |
|
230 | - 'class' => isset( $option['class'] ) ? $option['class'] : '', |
|
231 | - 'cols' => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | - 'rows' => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
217 | + 'size' => isset($option['size']) ? $option['size'] : null, |
|
218 | + 'options' => isset($option['options']) ? $option['options'] : '', |
|
219 | + 'selected' => isset($option['selected']) ? $option['selected'] : null, |
|
220 | + 'std' => isset($option['std']) ? $option['std'] : '', |
|
221 | + 'min' => isset($option['min']) ? $option['min'] : null, |
|
222 | + 'max' => isset($option['max']) ? $option['max'] : null, |
|
223 | + 'step' => isset($option['step']) ? $option['step'] : null, |
|
224 | + 'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null, |
|
225 | + 'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true, |
|
226 | + 'readonly' => isset($option['readonly']) ? $option['readonly'] : false, |
|
227 | + 'faux' => isset($option['faux']) ? $option['faux'] : false, |
|
228 | + 'onchange' => isset($option['onchange']) ? $option['onchange'] : '', |
|
229 | + 'custom' => isset($option['custom']) ? $option['custom'] : '', |
|
230 | + 'class' => isset($option['class']) ? $option['class'] : '', |
|
231 | + 'cols' => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50, |
|
232 | + 'rows' => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5, |
|
233 | 233 | ) |
234 | 234 | ); |
235 | 235 | |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return array |
242 | 242 | */ |
243 | 243 | function wpinv_get_registered_settings() { |
244 | - return apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ); |
|
244 | + return apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings')); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -249,134 +249,134 @@ discard block |
||
249 | 249 | * |
250 | 250 | * @return array |
251 | 251 | */ |
252 | -function wpinv_settings_sanitize( $input = array() ) { |
|
252 | +function wpinv_settings_sanitize($input = array()) { |
|
253 | 253 | |
254 | 254 | $wpinv_options = wpinv_get_options(); |
255 | 255 | |
256 | - if ( empty( wp_get_raw_referer() ) ) { |
|
256 | + if (empty(wp_get_raw_referer())) { |
|
257 | 257 | return $input; |
258 | 258 | } |
259 | 259 | |
260 | - wp_parse_str( wp_get_raw_referer(), $referrer ); |
|
260 | + wp_parse_str(wp_get_raw_referer(), $referrer); |
|
261 | 261 | |
262 | 262 | $settings = wpinv_get_registered_settings(); |
263 | - $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; |
|
264 | - $section = isset( $referrer['section'] ) ? $referrer['section'] : 'main'; |
|
263 | + $tab = isset($referrer['tab']) ? $referrer['tab'] : 'general'; |
|
264 | + $section = isset($referrer['section']) ? $referrer['section'] : 'main'; |
|
265 | 265 | |
266 | 266 | $input = $input ? $input : array(); |
267 | - $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input ); |
|
268 | - $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input ); |
|
267 | + $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input); |
|
268 | + $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input); |
|
269 | 269 | |
270 | 270 | // Loop through each setting being saved and pass it through a sanitization filter |
271 | - foreach ( $input as $key => $value ) { |
|
271 | + foreach ($input as $key => $value) { |
|
272 | 272 | |
273 | 273 | // Get the setting type (checkbox, select, etc) |
274 | - $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false; |
|
274 | + $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false; |
|
275 | 275 | |
276 | - if ( $type ) { |
|
276 | + if ($type) { |
|
277 | 277 | // Field type specific filter |
278 | - $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key ); |
|
278 | + $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | // General filter |
282 | - $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key ); |
|
282 | + $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key); |
|
283 | 283 | } |
284 | 284 | |
285 | 285 | // Loop through the whitelist and unset any that are empty for the tab being saved |
286 | - $main_settings = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections |
|
287 | - $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array(); |
|
286 | + $main_settings = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections |
|
287 | + $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array(); |
|
288 | 288 | |
289 | - $found_settings = array_merge( $main_settings, $section_settings ); |
|
289 | + $found_settings = array_merge($main_settings, $section_settings); |
|
290 | 290 | |
291 | - if ( ! empty( $found_settings ) ) { |
|
292 | - foreach ( $found_settings as $key => $value ) { |
|
291 | + if (!empty($found_settings)) { |
|
292 | + foreach ($found_settings as $key => $value) { |
|
293 | 293 | |
294 | 294 | // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work |
295 | - if ( is_numeric( $key ) ) { |
|
295 | + if (is_numeric($key)) { |
|
296 | 296 | $key = $value['id']; |
297 | 297 | } |
298 | 298 | |
299 | - if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) { |
|
300 | - unset( $wpinv_options[ $key ] ); |
|
299 | + if (!isset($input[$key]) && isset($wpinv_options[$key])) { |
|
300 | + unset($wpinv_options[$key]); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | } |
304 | 304 | |
305 | 305 | // Merge our new settings with the existing |
306 | - $output = array_merge( $wpinv_options, $input ); |
|
306 | + $output = array_merge($wpinv_options, $input); |
|
307 | 307 | |
308 | - add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' ); |
|
308 | + add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated'); |
|
309 | 309 | |
310 | 310 | return $output; |
311 | 311 | } |
312 | 312 | |
313 | -function wpinv_settings_sanitize_misc_accounting( $input ) { |
|
313 | +function wpinv_settings_sanitize_misc_accounting($input) { |
|
314 | 314 | |
315 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
315 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
316 | 316 | return $input; |
317 | 317 | } |
318 | 318 | |
319 | - if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) { |
|
319 | + if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) { |
|
320 | 320 | // Shows an admin notice about upgrading previous order numbers |
321 | - getpaid_session()->set( 'upgrade_sequential', '1' ); |
|
321 | + getpaid_session()->set('upgrade_sequential', '1'); |
|
322 | 322 | } |
323 | 323 | |
324 | 324 | return $input; |
325 | 325 | } |
326 | -add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' ); |
|
326 | +add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting'); |
|
327 | 327 | |
328 | -function wpinv_settings_sanitize_tax_rates( $input ) { |
|
329 | - if( ! wpinv_current_user_can_manage_invoicing() ) { |
|
328 | +function wpinv_settings_sanitize_tax_rates($input) { |
|
329 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
330 | 330 | return $input; |
331 | 331 | } |
332 | 332 | |
333 | - $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array(); |
|
333 | + $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array(); |
|
334 | 334 | |
335 | 335 | $tax_rates = array(); |
336 | 336 | |
337 | - if ( !empty( $new_rates ) ) { |
|
338 | - foreach ( $new_rates as $rate ) { |
|
339 | - if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) { |
|
337 | + if (!empty($new_rates)) { |
|
338 | + foreach ($new_rates as $rate) { |
|
339 | + if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) { |
|
340 | 340 | continue; |
341 | 341 | } |
342 | 342 | |
343 | - $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 ); |
|
343 | + $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4); |
|
344 | 344 | |
345 | 345 | $tax_rates[] = $rate; |
346 | 346 | } |
347 | 347 | } |
348 | 348 | |
349 | - update_option( 'wpinv_tax_rates', $tax_rates ); |
|
349 | + update_option('wpinv_tax_rates', $tax_rates); |
|
350 | 350 | |
351 | 351 | return $input; |
352 | 352 | } |
353 | -add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' ); |
|
353 | +add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates'); |
|
354 | 354 | |
355 | -function wpinv_sanitize_text_field( $input ) { |
|
356 | - return trim( $input ); |
|
355 | +function wpinv_sanitize_text_field($input) { |
|
356 | + return trim($input); |
|
357 | 357 | } |
358 | -add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' ); |
|
358 | +add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field'); |
|
359 | 359 | |
360 | 360 | function wpinv_get_settings_tabs() { |
361 | 361 | $tabs = array(); |
362 | - $tabs['general'] = __( 'General', 'invoicing' ); |
|
363 | - $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' ); |
|
364 | - $tabs['taxes'] = __( 'Taxes', 'invoicing' ); |
|
365 | - $tabs['emails'] = __( 'Emails', 'invoicing' ); |
|
366 | - $tabs['privacy'] = __( 'Privacy', 'invoicing' ); |
|
367 | - $tabs['misc'] = __( 'Misc', 'invoicing' ); |
|
368 | - $tabs['tools'] = __( 'Tools', 'invoicing' ); |
|
369 | - |
|
370 | - return apply_filters( 'wpinv_settings_tabs', $tabs ); |
|
362 | + $tabs['general'] = __('General', 'invoicing'); |
|
363 | + $tabs['gateways'] = __('Payment Gateways', 'invoicing'); |
|
364 | + $tabs['taxes'] = __('Taxes', 'invoicing'); |
|
365 | + $tabs['emails'] = __('Emails', 'invoicing'); |
|
366 | + $tabs['privacy'] = __('Privacy', 'invoicing'); |
|
367 | + $tabs['misc'] = __('Misc', 'invoicing'); |
|
368 | + $tabs['tools'] = __('Tools', 'invoicing'); |
|
369 | + |
|
370 | + return apply_filters('wpinv_settings_tabs', $tabs); |
|
371 | 371 | } |
372 | 372 | |
373 | -function wpinv_get_settings_tab_sections( $tab = false ) { |
|
373 | +function wpinv_get_settings_tab_sections($tab = false) { |
|
374 | 374 | $tabs = false; |
375 | 375 | $sections = wpinv_get_registered_settings_sections(); |
376 | 376 | |
377 | - if( $tab && ! empty( $sections[ $tab ] ) ) { |
|
378 | - $tabs = $sections[ $tab ]; |
|
379 | - } else if ( $tab ) { |
|
377 | + if ($tab && !empty($sections[$tab])) { |
|
378 | + $tabs = $sections[$tab]; |
|
379 | + } else if ($tab) { |
|
380 | 380 | $tabs = false; |
381 | 381 | } |
382 | 382 | |
@@ -386,150 +386,150 @@ discard block |
||
386 | 386 | function wpinv_get_registered_settings_sections() { |
387 | 387 | static $sections = false; |
388 | 388 | |
389 | - if ( false !== $sections ) { |
|
389 | + if (false !== $sections) { |
|
390 | 390 | return $sections; |
391 | 391 | } |
392 | 392 | |
393 | 393 | $sections = array( |
394 | - 'general' => apply_filters( 'wpinv_settings_sections_general', array( |
|
395 | - 'main' => __( 'General Settings', 'invoicing' ), |
|
396 | - 'currency_section' => __( 'Currency Settings', 'invoicing' ), |
|
397 | - 'labels' => __( 'Label Texts', 'invoicing' ), |
|
398 | - ) ), |
|
399 | - 'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array( |
|
400 | - 'main' => __( 'Gateway Settings', 'invoicing' ), |
|
401 | - ) ), |
|
402 | - 'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array( |
|
403 | - 'main' => __( 'Tax Settings', 'invoicing' ), |
|
404 | - 'rates' => __( 'Tax Rates', 'invoicing' ), |
|
405 | - ) ), |
|
406 | - 'emails' => apply_filters( 'wpinv_settings_sections_emails', array( |
|
407 | - 'main' => __( 'Email Settings', 'invoicing' ), |
|
408 | - ) ), |
|
409 | - 'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array( |
|
410 | - 'main' => __( 'Privacy policy', 'invoicing' ), |
|
411 | - ) ), |
|
412 | - 'misc' => apply_filters( 'wpinv_settings_sections_misc', array( |
|
413 | - 'main' => __( 'Miscellaneous', 'invoicing' ), |
|
414 | - 'fields' => __( 'Fields Settings', 'invoicing' ), |
|
415 | - 'custom-css' => __( 'Custom CSS', 'invoicing' ), |
|
416 | - ) ), |
|
417 | - 'tools' => apply_filters( 'wpinv_settings_sections_tools', array( |
|
418 | - 'main' => __( 'Diagnostic Tools', 'invoicing' ), |
|
419 | - ) ), |
|
394 | + 'general' => apply_filters('wpinv_settings_sections_general', array( |
|
395 | + 'main' => __('General Settings', 'invoicing'), |
|
396 | + 'currency_section' => __('Currency Settings', 'invoicing'), |
|
397 | + 'labels' => __('Label Texts', 'invoicing'), |
|
398 | + )), |
|
399 | + 'gateways' => apply_filters('wpinv_settings_sections_gateways', array( |
|
400 | + 'main' => __('Gateway Settings', 'invoicing'), |
|
401 | + )), |
|
402 | + 'taxes' => apply_filters('wpinv_settings_sections_taxes', array( |
|
403 | + 'main' => __('Tax Settings', 'invoicing'), |
|
404 | + 'rates' => __('Tax Rates', 'invoicing'), |
|
405 | + )), |
|
406 | + 'emails' => apply_filters('wpinv_settings_sections_emails', array( |
|
407 | + 'main' => __('Email Settings', 'invoicing'), |
|
408 | + )), |
|
409 | + 'privacy' => apply_filters('wpinv_settings_sections_privacy', array( |
|
410 | + 'main' => __('Privacy policy', 'invoicing'), |
|
411 | + )), |
|
412 | + 'misc' => apply_filters('wpinv_settings_sections_misc', array( |
|
413 | + 'main' => __('Miscellaneous', 'invoicing'), |
|
414 | + 'fields' => __('Fields Settings', 'invoicing'), |
|
415 | + 'custom-css' => __('Custom CSS', 'invoicing'), |
|
416 | + )), |
|
417 | + 'tools' => apply_filters('wpinv_settings_sections_tools', array( |
|
418 | + 'main' => __('Diagnostic Tools', 'invoicing'), |
|
419 | + )), |
|
420 | 420 | ); |
421 | 421 | |
422 | - $sections = apply_filters( 'wpinv_settings_sections', $sections ); |
|
422 | + $sections = apply_filters('wpinv_settings_sections', $sections); |
|
423 | 423 | |
424 | 424 | return $sections; |
425 | 425 | } |
426 | 426 | |
427 | -function wpinv_get_pages( $with_slug = false, $default_label = NULL ) { |
|
427 | +function wpinv_get_pages($with_slug = false, $default_label = NULL) { |
|
428 | 428 | $pages_options = array(); |
429 | 429 | |
430 | - if( $default_label !== NULL && $default_label !== false ) { |
|
431 | - $pages_options = array( '' => $default_label ); // Blank option |
|
430 | + if ($default_label !== NULL && $default_label !== false) { |
|
431 | + $pages_options = array('' => $default_label); // Blank option |
|
432 | 432 | } |
433 | 433 | |
434 | 434 | $pages = get_pages(); |
435 | - if ( $pages ) { |
|
436 | - foreach ( $pages as $page ) { |
|
435 | + if ($pages) { |
|
436 | + foreach ($pages as $page) { |
|
437 | 437 | $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title; |
438 | - $pages_options[ $page->ID ] = $title; |
|
438 | + $pages_options[$page->ID] = $title; |
|
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | 442 | return $pages_options; |
443 | 443 | } |
444 | 444 | |
445 | -function wpinv_header_callback( $args ) { |
|
446 | - if ( !empty( $args['desc'] ) ) { |
|
445 | +function wpinv_header_callback($args) { |
|
446 | + if (!empty($args['desc'])) { |
|
447 | 447 | echo $args['desc']; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | -function wpinv_hidden_callback( $args ) { |
|
451 | +function wpinv_hidden_callback($args) { |
|
452 | 452 | global $wpinv_options; |
453 | 453 | |
454 | - if ( isset( $args['set_value'] ) ) { |
|
454 | + if (isset($args['set_value'])) { |
|
455 | 455 | $value = $args['set_value']; |
456 | - } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
457 | - $value = $wpinv_options[ $args['id'] ]; |
|
456 | + } elseif (isset($wpinv_options[$args['id']])) { |
|
457 | + $value = $wpinv_options[$args['id']]; |
|
458 | 458 | } else { |
459 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
459 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
460 | 460 | } |
461 | 461 | |
462 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
462 | + if (isset($args['faux']) && true === $args['faux']) { |
|
463 | 463 | $args['readonly'] = true; |
464 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
464 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
465 | 465 | $name = ''; |
466 | 466 | } else { |
467 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
467 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
468 | 468 | } |
469 | 469 | |
470 | - $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />'; |
|
470 | + $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />'; |
|
471 | 471 | |
472 | 472 | echo $html; |
473 | 473 | } |
474 | 474 | |
475 | -function wpinv_checkbox_callback( $args ) { |
|
475 | +function wpinv_checkbox_callback($args) { |
|
476 | 476 | global $wpinv_options; |
477 | 477 | |
478 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
478 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
479 | 479 | |
480 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
480 | + if (isset($args['faux']) && true === $args['faux']) { |
|
481 | 481 | $name = ''; |
482 | 482 | } else { |
483 | 483 | $name = 'name="wpinv_settings[' . $sanitize_id . ']"'; |
484 | 484 | } |
485 | 485 | |
486 | - $std = isset( $args['std'] ) ? $args['std'] : 0; |
|
487 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
488 | - $checked = checked( empty( $value ), false, false ); |
|
486 | + $std = isset($args['std']) ? $args['std'] : 0; |
|
487 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
488 | + $checked = checked(empty($value), false, false); |
|
489 | 489 | |
490 | 490 | $html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>'; |
491 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
491 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
492 | 492 | |
493 | 493 | echo $html; |
494 | 494 | } |
495 | 495 | |
496 | -function wpinv_multicheck_callback( $args ) { |
|
496 | +function wpinv_multicheck_callback($args) { |
|
497 | 497 | global $wpinv_options; |
498 | 498 | |
499 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
500 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
499 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
500 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
501 | 501 | |
502 | - if ( ! empty( $args['options'] ) ) { |
|
502 | + if (!empty($args['options'])) { |
|
503 | 503 | |
504 | - $std = isset( $args['std'] ) ? $args['std'] : array(); |
|
505 | - $value = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std; |
|
504 | + $std = isset($args['std']) ? $args['std'] : array(); |
|
505 | + $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std; |
|
506 | 506 | |
507 | 507 | echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">'; |
508 | - foreach( $args['options'] as $key => $option ): |
|
509 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
510 | - if ( in_array( $sanitize_key, $value ) ) { |
|
508 | + foreach ($args['options'] as $key => $option): |
|
509 | + $sanitize_key = wpinv_sanitize_key($key); |
|
510 | + if (in_array($sanitize_key, $value)) { |
|
511 | 511 | $enabled = $sanitize_key; |
512 | 512 | } else { |
513 | 513 | $enabled = NULL; |
514 | 514 | } |
515 | - echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/> '; |
|
516 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>'; |
|
515 | + echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/> '; |
|
516 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>'; |
|
517 | 517 | endforeach; |
518 | 518 | echo '</div>'; |
519 | 519 | echo '<p class="description">' . $args['desc'] . '</p>'; |
520 | 520 | } |
521 | 521 | } |
522 | 522 | |
523 | -function wpinv_payment_icons_callback( $args ) { |
|
523 | +function wpinv_payment_icons_callback($args) { |
|
524 | 524 | global $wpinv_options; |
525 | 525 | |
526 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
526 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
527 | 527 | |
528 | - if ( ! empty( $args['options'] ) ) { |
|
529 | - foreach( $args['options'] as $key => $option ) { |
|
530 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
528 | + if (!empty($args['options'])) { |
|
529 | + foreach ($args['options'] as $key => $option) { |
|
530 | + $sanitize_key = wpinv_sanitize_key($key); |
|
531 | 531 | |
532 | - if( isset( $wpinv_options[$args['id']][$key] ) ) { |
|
532 | + if (isset($wpinv_options[$args['id']][$key])) { |
|
533 | 533 | $enabled = $option; |
534 | 534 | } else { |
535 | 535 | $enabled = NULL; |
@@ -537,197 +537,197 @@ discard block |
||
537 | 537 | |
538 | 538 | echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">'; |
539 | 539 | |
540 | - echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/> '; |
|
540 | + echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/> '; |
|
541 | 541 | |
542 | - if ( wpinv_string_is_image_url( $key ) ) { |
|
543 | - echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
542 | + if (wpinv_string_is_image_url($key)) { |
|
543 | + echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
544 | 544 | } else { |
545 | - $card = strtolower( str_replace( ' ', '', $option ) ); |
|
545 | + $card = strtolower(str_replace(' ', '', $option)); |
|
546 | 546 | |
547 | - if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) { |
|
548 | - $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' ); |
|
547 | + if (has_filter('wpinv_accepted_payment_' . $card . '_image')) { |
|
548 | + $image = apply_filters('wpinv_accepted_payment_' . $card . '_image', ''); |
|
549 | 549 | } else { |
550 | - $image = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false ); |
|
550 | + $image = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false); |
|
551 | 551 | $content_dir = WP_CONTENT_DIR; |
552 | 552 | |
553 | - if ( function_exists( 'wp_normalize_path' ) ) { |
|
553 | + if (function_exists('wp_normalize_path')) { |
|
554 | 554 | // Replaces backslashes with forward slashes for Windows systems |
555 | - $image = wp_normalize_path( $image ); |
|
556 | - $content_dir = wp_normalize_path( $content_dir ); |
|
555 | + $image = wp_normalize_path($image); |
|
556 | + $content_dir = wp_normalize_path($content_dir); |
|
557 | 557 | } |
558 | 558 | |
559 | - $image = str_replace( $content_dir, content_url(), $image ); |
|
559 | + $image = str_replace($content_dir, content_url(), $image); |
|
560 | 560 | } |
561 | 561 | |
562 | - echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
562 | + echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>'; |
|
563 | 563 | } |
564 | 564 | echo $option . '</label>'; |
565 | 565 | } |
566 | - echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
566 | + echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>'; |
|
567 | 567 | } |
568 | 568 | } |
569 | 569 | |
570 | -function wpinv_radio_callback( $args ) { |
|
570 | +function wpinv_radio_callback($args) { |
|
571 | 571 | global $wpinv_options; |
572 | 572 | |
573 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
573 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
574 | 574 | |
575 | - foreach ( $args['options'] as $key => $option ) : |
|
576 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
575 | + foreach ($args['options'] as $key => $option) : |
|
576 | + $sanitize_key = wpinv_sanitize_key($key); |
|
577 | 577 | |
578 | 578 | $checked = false; |
579 | 579 | |
580 | - if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key ) |
|
580 | + if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key) |
|
581 | 581 | $checked = true; |
582 | - elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) ) |
|
582 | + elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']])) |
|
583 | 583 | $checked = true; |
584 | 584 | |
585 | 585 | echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/> '; |
586 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>'; |
|
586 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>'; |
|
587 | 587 | endforeach; |
588 | 588 | |
589 | - echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>'; |
|
589 | + echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>'; |
|
590 | 590 | } |
591 | 591 | |
592 | -function wpinv_gateways_callback( $args ) { |
|
592 | +function wpinv_gateways_callback($args) { |
|
593 | 593 | global $wpinv_options; |
594 | 594 | |
595 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
595 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
596 | 596 | |
597 | - foreach ( $args['options'] as $key => $option ) : |
|
598 | - $sanitize_key = wpinv_sanitize_key( $key ); |
|
597 | + foreach ($args['options'] as $key => $option) : |
|
598 | + $sanitize_key = wpinv_sanitize_key($key); |
|
599 | 599 | |
600 | - if ( isset( $wpinv_options['gateways'][ $key ] ) ) |
|
600 | + if (isset($wpinv_options['gateways'][$key])) |
|
601 | 601 | $enabled = '1'; |
602 | 602 | else |
603 | 603 | $enabled = null; |
604 | 604 | |
605 | - echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
606 | - echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>'; |
|
605 | + echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/> '; |
|
606 | + echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>'; |
|
607 | 607 | endforeach; |
608 | 608 | } |
609 | 609 | |
610 | 610 | function wpinv_gateway_select_callback($args) { |
611 | 611 | global $wpinv_options; |
612 | 612 | |
613 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
614 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
613 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
614 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
615 | 615 | |
616 | - echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >'; |
|
616 | + echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >'; |
|
617 | 617 | |
618 | - foreach ( $args['options'] as $key => $option ) : |
|
619 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
620 | - $selected = selected( $key, $args['selected'], false ); |
|
618 | + foreach ($args['options'] as $key => $option) : |
|
619 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
620 | + $selected = selected($key, $args['selected'], false); |
|
621 | 621 | } else { |
622 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : ''; |
|
622 | + $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : ''; |
|
623 | 623 | } |
624 | - echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>'; |
|
624 | + echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>'; |
|
625 | 625 | endforeach; |
626 | 626 | |
627 | 627 | echo '</select>'; |
628 | - echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
628 | + echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
629 | 629 | } |
630 | 630 | |
631 | -function wpinv_text_callback( $args ) { |
|
631 | +function wpinv_text_callback($args) { |
|
632 | 632 | global $wpinv_options; |
633 | 633 | |
634 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
634 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
635 | 635 | |
636 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
637 | - $value = $wpinv_options[ $args['id'] ]; |
|
636 | + if (isset($wpinv_options[$args['id']])) { |
|
637 | + $value = $wpinv_options[$args['id']]; |
|
638 | 638 | } else { |
639 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
639 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
640 | 640 | } |
641 | 641 | |
642 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
642 | + if (isset($args['faux']) && true === $args['faux']) { |
|
643 | 643 | $args['readonly'] = true; |
644 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
644 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
645 | 645 | $name = ''; |
646 | 646 | } else { |
647 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
647 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
648 | 648 | } |
649 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
649 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
650 | 650 | |
651 | 651 | $readonly = $args['readonly'] === true ? ' readonly="readonly"' : ''; |
652 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
653 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>'; |
|
654 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
652 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
653 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>'; |
|
654 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
655 | 655 | |
656 | 656 | echo $html; |
657 | 657 | } |
658 | 658 | |
659 | -function wpinv_number_callback( $args ) { |
|
659 | +function wpinv_number_callback($args) { |
|
660 | 660 | global $wpinv_options; |
661 | 661 | |
662 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
662 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
663 | 663 | |
664 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
665 | - $value = $wpinv_options[ $args['id'] ]; |
|
664 | + if (isset($wpinv_options[$args['id']])) { |
|
665 | + $value = $wpinv_options[$args['id']]; |
|
666 | 666 | } else { |
667 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
667 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
668 | 668 | } |
669 | 669 | |
670 | - if ( isset( $args['faux'] ) && true === $args['faux'] ) { |
|
670 | + if (isset($args['faux']) && true === $args['faux']) { |
|
671 | 671 | $args['readonly'] = true; |
672 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
672 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
673 | 673 | $name = ''; |
674 | 674 | } else { |
675 | - $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"'; |
|
675 | + $name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"'; |
|
676 | 676 | } |
677 | 677 | |
678 | - $max = isset( $args['max'] ) ? $args['max'] : 999999; |
|
679 | - $min = isset( $args['min'] ) ? $args['min'] : 0; |
|
680 | - $step = isset( $args['step'] ) ? $args['step'] : 1; |
|
681 | - $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : ''; |
|
678 | + $max = isset($args['max']) ? $args['max'] : 999999; |
|
679 | + $min = isset($args['min']) ? $args['min'] : 0; |
|
680 | + $step = isset($args['step']) ? $args['step'] : 1; |
|
681 | + $class = !empty($args['class']) ? sanitize_html_class($args['class']) : ''; |
|
682 | 682 | |
683 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
684 | - $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
685 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
683 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
684 | + $html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
685 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
686 | 686 | |
687 | 687 | echo $html; |
688 | 688 | } |
689 | 689 | |
690 | -function wpinv_textarea_callback( $args ) { |
|
690 | +function wpinv_textarea_callback($args) { |
|
691 | 691 | global $wpinv_options; |
692 | 692 | |
693 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
693 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
694 | 694 | |
695 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
696 | - $value = $wpinv_options[ $args['id'] ]; |
|
695 | + if (isset($wpinv_options[$args['id']])) { |
|
696 | + $value = $wpinv_options[$args['id']]; |
|
697 | 697 | } else { |
698 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
698 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
699 | 699 | } |
700 | 700 | |
701 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
702 | - $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text'; |
|
701 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
702 | + $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text'; |
|
703 | 703 | |
704 | - $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
705 | - $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
704 | + $html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
705 | + $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
706 | 706 | |
707 | 707 | echo $html; |
708 | 708 | } |
709 | 709 | |
710 | -function wpinv_password_callback( $args ) { |
|
710 | +function wpinv_password_callback($args) { |
|
711 | 711 | global $wpinv_options; |
712 | 712 | |
713 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
713 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
714 | 714 | |
715 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
716 | - $value = $wpinv_options[ $args['id'] ]; |
|
715 | + if (isset($wpinv_options[$args['id']])) { |
|
716 | + $value = $wpinv_options[$args['id']]; |
|
717 | 717 | } else { |
718 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
718 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
719 | 719 | } |
720 | 720 | |
721 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
722 | - $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>'; |
|
723 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
721 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
722 | + $html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>'; |
|
723 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
724 | 724 | |
725 | 725 | echo $html; |
726 | 726 | } |
727 | 727 | |
728 | 728 | function wpinv_missing_callback($args) { |
729 | 729 | printf( |
730 | - __( 'The callback function used for the %s setting is missing.', 'invoicing' ), |
|
730 | + __('The callback function used for the %s setting is missing.', 'invoicing'), |
|
731 | 731 | '<strong>' . $args['id'] . '</strong>' |
732 | 732 | ); |
733 | 733 | } |
@@ -735,134 +735,134 @@ discard block |
||
735 | 735 | function wpinv_select_callback($args) { |
736 | 736 | global $wpinv_options; |
737 | 737 | |
738 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
738 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
739 | 739 | |
740 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
741 | - $value = $wpinv_options[ $args['id'] ]; |
|
740 | + if (isset($wpinv_options[$args['id']])) { |
|
741 | + $value = $wpinv_options[$args['id']]; |
|
742 | 742 | } else { |
743 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
743 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
744 | 744 | } |
745 | 745 | |
746 | - if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) { |
|
746 | + if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) { |
|
747 | 747 | $value = $args['selected']; |
748 | 748 | } |
749 | 749 | |
750 | - if ( isset( $args['placeholder'] ) ) { |
|
750 | + if (isset($args['placeholder'])) { |
|
751 | 751 | $placeholder = $args['placeholder']; |
752 | 752 | } else { |
753 | 753 | $placeholder = ''; |
754 | 754 | } |
755 | 755 | |
756 | - if( !empty( $args['onchange'] ) ) { |
|
757 | - $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"'; |
|
756 | + if (!empty($args['onchange'])) { |
|
757 | + $onchange = ' onchange="' . esc_attr($args['onchange']) . '"'; |
|
758 | 758 | } else { |
759 | 759 | $onchange = ''; |
760 | 760 | } |
761 | 761 | |
762 | - $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : ''; |
|
762 | + $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : ''; |
|
763 | 763 | |
764 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />'; |
|
764 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />'; |
|
765 | 765 | |
766 | - foreach ( $args['options'] as $option => $name ) { |
|
767 | - $selected = selected( $option, $value, false ); |
|
768 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
766 | + foreach ($args['options'] as $option => $name) { |
|
767 | + $selected = selected($option, $value, false); |
|
768 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
769 | 769 | } |
770 | 770 | |
771 | 771 | $html .= '</select>'; |
772 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
772 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
773 | 773 | |
774 | 774 | echo $html; |
775 | 775 | } |
776 | 776 | |
777 | -function wpinv_color_select_callback( $args ) { |
|
777 | +function wpinv_color_select_callback($args) { |
|
778 | 778 | global $wpinv_options; |
779 | 779 | |
780 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
780 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
781 | 781 | |
782 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
783 | - $value = $wpinv_options[ $args['id'] ]; |
|
782 | + if (isset($wpinv_options[$args['id']])) { |
|
783 | + $value = $wpinv_options[$args['id']]; |
|
784 | 784 | } else { |
785 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
785 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
786 | 786 | } |
787 | 787 | |
788 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>'; |
|
788 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>'; |
|
789 | 789 | |
790 | - foreach ( $args['options'] as $option => $color ) { |
|
791 | - $selected = selected( $option, $value, false ); |
|
792 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>'; |
|
790 | + foreach ($args['options'] as $option => $color) { |
|
791 | + $selected = selected($option, $value, false); |
|
792 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>'; |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | $html .= '</select>'; |
796 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
796 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
797 | 797 | |
798 | 798 | echo $html; |
799 | 799 | } |
800 | 800 | |
801 | -function wpinv_rich_editor_callback( $args ) { |
|
801 | +function wpinv_rich_editor_callback($args) { |
|
802 | 802 | global $wpinv_options, $wp_version; |
803 | 803 | |
804 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
804 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
805 | 805 | |
806 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
807 | - $value = $wpinv_options[ $args['id'] ]; |
|
806 | + if (isset($wpinv_options[$args['id']])) { |
|
807 | + $value = $wpinv_options[$args['id']]; |
|
808 | 808 | |
809 | - if( empty( $args['allow_blank'] ) && empty( $value ) ) { |
|
810 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
809 | + if (empty($args['allow_blank']) && empty($value)) { |
|
810 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
811 | 811 | } |
812 | 812 | } else { |
813 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
813 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
814 | 814 | } |
815 | 815 | |
816 | - $rows = isset( $args['size'] ) ? $args['size'] : 20; |
|
816 | + $rows = isset($args['size']) ? $args['size'] : 20; |
|
817 | 817 | |
818 | 818 | $html = '<div class="getpaid-settings-editor-input">'; |
819 | - if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) { |
|
819 | + if ($wp_version >= 3.3 && function_exists('wp_editor')) { |
|
820 | 820 | ob_start(); |
821 | - wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) ); |
|
821 | + wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false)); |
|
822 | 822 | $html .= ob_get_clean(); |
823 | 823 | } else { |
824 | - $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>'; |
|
824 | + $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>'; |
|
825 | 825 | } |
826 | 826 | |
827 | - $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
827 | + $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
828 | 828 | |
829 | 829 | echo $html; |
830 | 830 | } |
831 | 831 | |
832 | -function wpinv_upload_callback( $args ) { |
|
832 | +function wpinv_upload_callback($args) { |
|
833 | 833 | global $wpinv_options; |
834 | 834 | |
835 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
835 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
836 | 836 | |
837 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
837 | + if (isset($wpinv_options[$args['id']])) { |
|
838 | 838 | $value = $wpinv_options[$args['id']]; |
839 | 839 | } else { |
840 | 840 | $value = isset($args['std']) ? $args['std'] : ''; |
841 | 841 | } |
842 | 842 | |
843 | - $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular'; |
|
844 | - $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>'; |
|
845 | - $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>'; |
|
846 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
843 | + $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular'; |
|
844 | + $html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>'; |
|
845 | + $html .= '<span> <input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>'; |
|
846 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
847 | 847 | |
848 | 848 | echo $html; |
849 | 849 | } |
850 | 850 | |
851 | -function wpinv_color_callback( $args ) { |
|
851 | +function wpinv_color_callback($args) { |
|
852 | 852 | global $wpinv_options; |
853 | 853 | |
854 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
854 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
855 | 855 | |
856 | - if ( isset( $wpinv_options[ $args['id'] ] ) ) { |
|
857 | - $value = $wpinv_options[ $args['id'] ]; |
|
856 | + if (isset($wpinv_options[$args['id']])) { |
|
857 | + $value = $wpinv_options[$args['id']]; |
|
858 | 858 | } else { |
859 | - $value = isset( $args['std'] ) ? $args['std'] : ''; |
|
859 | + $value = isset($args['std']) ? $args['std'] : ''; |
|
860 | 860 | } |
861 | 861 | |
862 | - $default = isset( $args['std'] ) ? $args['std'] : ''; |
|
862 | + $default = isset($args['std']) ? $args['std'] : ''; |
|
863 | 863 | |
864 | - $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />'; |
|
865 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
864 | + $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />'; |
|
865 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
866 | 866 | |
867 | 867 | echo $html; |
868 | 868 | } |
@@ -870,9 +870,9 @@ discard block |
||
870 | 870 | function wpinv_country_states_callback($args) { |
871 | 871 | global $wpinv_options; |
872 | 872 | |
873 | - $sanitize_id = wpinv_sanitize_key( $args['id'] ); |
|
873 | + $sanitize_id = wpinv_sanitize_key($args['id']); |
|
874 | 874 | |
875 | - if ( isset( $args['placeholder'] ) ) { |
|
875 | + if (isset($args['placeholder'])) { |
|
876 | 876 | $placeholder = $args['placeholder']; |
877 | 877 | } else { |
878 | 878 | $placeholder = ''; |
@@ -880,16 +880,16 @@ discard block |
||
880 | 880 | |
881 | 881 | $states = wpinv_get_country_states(); |
882 | 882 | |
883 | - $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | - $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>'; |
|
883 | + $class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"'; |
|
884 | + $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>'; |
|
885 | 885 | |
886 | - foreach ( $states as $option => $name ) { |
|
887 | - $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : ''; |
|
888 | - $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>'; |
|
886 | + foreach ($states as $option => $name) { |
|
887 | + $selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : ''; |
|
888 | + $html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>'; |
|
889 | 889 | } |
890 | 890 | |
891 | 891 | $html .= '</select>'; |
892 | - $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>'; |
|
892 | + $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>'; |
|
893 | 893 | |
894 | 894 | echo $html; |
895 | 895 | } |
@@ -904,96 +904,96 @@ discard block |
||
904 | 904 | <table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts"> |
905 | 905 | <thead> |
906 | 906 | <tr> |
907 | - <th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th> |
|
908 | - <th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th> |
|
909 | - <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th> |
|
910 | - <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> |
|
911 | - <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th> |
|
912 | - <th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th> |
|
907 | + <th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th> |
|
908 | + <th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th> |
|
909 | + <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th> |
|
910 | + <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> |
|
911 | + <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th> |
|
912 | + <th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th> |
|
913 | 913 | </tr> |
914 | 914 | </thead> |
915 | 915 | <tbody> |
916 | - <?php if( !empty( $rates ) ) : ?> |
|
917 | - <?php foreach( $rates as $key => $rate ) : ?> |
|
916 | + <?php if (!empty($rates)) : ?> |
|
917 | + <?php foreach ($rates as $key => $rate) : ?> |
|
918 | 918 | <?php |
919 | - $sanitized_key = wpinv_sanitize_key( $key ); |
|
919 | + $sanitized_key = wpinv_sanitize_key($key); |
|
920 | 920 | ?> |
921 | 921 | <tr> |
922 | 922 | <td class="wpinv_tax_country"> |
923 | 923 | <?php |
924 | - echo wpinv_html_select( array( |
|
925 | - 'options' => wpinv_get_country_list( true ), |
|
924 | + echo wpinv_html_select(array( |
|
925 | + 'options' => wpinv_get_country_list(true), |
|
926 | 926 | 'name' => 'tax_rates[' . $sanitized_key . '][country]', |
927 | 927 | 'id' => 'tax_rates[' . $sanitized_key . '][country]', |
928 | 928 | 'selected' => $rate['country'], |
929 | 929 | 'show_option_all' => false, |
930 | 930 | 'show_option_none' => false, |
931 | 931 | 'class' => 'wpinv-tax-country wpi_select2', |
932 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
933 | - ) ); |
|
932 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
933 | + )); |
|
934 | 934 | ?> |
935 | 935 | </td> |
936 | 936 | <td class="wpinv_tax_state"> |
937 | 937 | <?php |
938 | - $states = wpinv_get_country_states( $rate['country'] ); |
|
939 | - if( !empty( $states ) ) { |
|
940 | - echo wpinv_html_select( array( |
|
941 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
938 | + $states = wpinv_get_country_states($rate['country']); |
|
939 | + if (!empty($states)) { |
|
940 | + echo wpinv_html_select(array( |
|
941 | + 'options' => array_merge(array('' => ''), $states), |
|
942 | 942 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', |
943 | 943 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
944 | 944 | 'selected' => $rate['state'], |
945 | 945 | 'show_option_all' => false, |
946 | 946 | 'show_option_none' => false, |
947 | 947 | 'class' => 'wpi_select2', |
948 | - 'placeholder' => __( 'Choose a state', 'invoicing' ) |
|
949 | - ) ); |
|
948 | + 'placeholder' => __('Choose a state', 'invoicing') |
|
949 | + )); |
|
950 | 950 | } else { |
951 | - echo wpinv_html_text( array( |
|
951 | + echo wpinv_html_text(array( |
|
952 | 952 | 'name' => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'], |
953 | - 'value' => ! empty( $rate['state'] ) ? $rate['state'] : '', |
|
953 | + 'value' => !empty($rate['state']) ? $rate['state'] : '', |
|
954 | 954 | 'id' => 'tax_rates[' . $sanitized_key . '][state]', |
955 | - ) ); |
|
955 | + )); |
|
956 | 956 | } |
957 | 957 | ?> |
958 | 958 | </td> |
959 | 959 | <td class="wpinv_tax_global"> |
960 | - <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/> |
|
961 | - <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
960 | + <input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/> |
|
961 | + <label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
962 | 962 | </td> |
963 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td> |
|
964 | - <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td> |
|
965 | - <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
963 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td> |
|
964 | + <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td> |
|
965 | + <td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
966 | 966 | </tr> |
967 | 967 | <?php endforeach; ?> |
968 | 968 | <?php else : ?> |
969 | 969 | <tr> |
970 | 970 | <td class="wpinv_tax_country"> |
971 | 971 | <?php |
972 | - echo wpinv_html_select( array( |
|
973 | - 'options' => wpinv_get_country_list( true ), |
|
972 | + echo wpinv_html_select(array( |
|
973 | + 'options' => wpinv_get_country_list(true), |
|
974 | 974 | 'name' => 'tax_rates[0][country]', |
975 | 975 | 'show_option_all' => false, |
976 | 976 | 'show_option_none' => false, |
977 | 977 | 'class' => 'wpinv-tax-country wpi_select2', |
978 | - 'placeholder' => __( 'Choose a country', 'invoicing' ) |
|
979 | - ) ); ?> |
|
978 | + 'placeholder' => __('Choose a country', 'invoicing') |
|
979 | + )); ?> |
|
980 | 980 | </td> |
981 | 981 | <td class="wpinv_tax_state"> |
982 | - <?php echo wpinv_html_text( array( |
|
982 | + <?php echo wpinv_html_text(array( |
|
983 | 983 | 'name' => 'tax_rates[0][state]' |
984 | - ) ); ?> |
|
984 | + )); ?> |
|
985 | 985 | </td> |
986 | 986 | <td class="wpinv_tax_global"> |
987 | 987 | <input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/> |
988 | - <label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label> |
|
988 | + <label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label> |
|
989 | 989 | </td> |
990 | - <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td> |
|
990 | + <td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float) wpinv_get_option('tax_rate', 0); ?>"/></td> |
|
991 | 991 | <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td> |
992 | - <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td> |
|
992 | + <td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td> |
|
993 | 993 | </tr> |
994 | 994 | <?php endif; ?> |
995 | 995 | </tbody> |
996 | - <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot> |
|
996 | + <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot> |
|
997 | 997 | </table> |
998 | 998 | <?php |
999 | 999 | echo ob_get_clean(); |
@@ -1004,76 +1004,76 @@ discard block |
||
1004 | 1004 | ob_start(); ?> |
1005 | 1005 | </td><tr> |
1006 | 1006 | <td colspan="2" class="wpinv_tools_tdbox"> |
1007 | - <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1008 | - <?php do_action( 'wpinv_tools_before' ); ?> |
|
1007 | + <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?> |
|
1008 | + <?php do_action('wpinv_tools_before'); ?> |
|
1009 | 1009 | <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts"> |
1010 | 1010 | <thead> |
1011 | 1011 | <tr> |
1012 | - <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th> |
|
1013 | - <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th> |
|
1014 | - <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th> |
|
1012 | + <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th> |
|
1013 | + <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th> |
|
1014 | + <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th> |
|
1015 | 1015 | </tr> |
1016 | 1016 | </thead> |
1017 | - <?php do_action( 'wpinv_tools_row' ); ?> |
|
1017 | + <?php do_action('wpinv_tools_row'); ?> |
|
1018 | 1018 | <tbody> |
1019 | 1019 | </tbody> |
1020 | 1020 | </table> |
1021 | - <?php do_action( 'wpinv_tools_after' ); ?> |
|
1021 | + <?php do_action('wpinv_tools_after'); ?> |
|
1022 | 1022 | <?php |
1023 | 1023 | echo ob_get_clean(); |
1024 | 1024 | } |
1025 | 1025 | |
1026 | -function wpinv_descriptive_text_callback( $args ) { |
|
1027 | - echo wp_kses_post( $args['desc'] ); |
|
1026 | +function wpinv_descriptive_text_callback($args) { |
|
1027 | + echo wp_kses_post($args['desc']); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | -function wpinv_hook_callback( $args ) { |
|
1031 | - do_action( 'wpinv_' . $args['id'], $args ); |
|
1030 | +function wpinv_hook_callback($args) { |
|
1031 | + do_action('wpinv_' . $args['id'], $args); |
|
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | function wpinv_set_settings_cap() { |
1035 | 1035 | return wpinv_get_capability(); |
1036 | 1036 | } |
1037 | -add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' ); |
|
1037 | +add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap'); |
|
1038 | 1038 | |
1039 | -function wpinv_settings_sanitize_input( $value, $key ) { |
|
1040 | - if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) { |
|
1041 | - $value = wpinv_sanitize_amount( $value, 4 ); |
|
1039 | +function wpinv_settings_sanitize_input($value, $key) { |
|
1040 | + if ($key == 'tax_rate' || $key == 'eu_fallback_rate') { |
|
1041 | + $value = wpinv_sanitize_amount($value, 4); |
|
1042 | 1042 | $value = $value >= 100 ? 99 : $value; |
1043 | 1043 | } |
1044 | 1044 | |
1045 | 1045 | return $value; |
1046 | 1046 | } |
1047 | -add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 ); |
|
1047 | +add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2); |
|
1048 | 1048 | |
1049 | -function wpinv_on_update_settings( $old_value, $value, $option ) { |
|
1050 | - $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1051 | - $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : ''; |
|
1049 | +function wpinv_on_update_settings($old_value, $value, $option) { |
|
1050 | + $old = !empty($old_value['remove_data_on_unistall']) ? 1 : ''; |
|
1051 | + $new = !empty($value['remove_data_on_unistall']) ? 1 : ''; |
|
1052 | 1052 | |
1053 | - if ( $old != $new ) { |
|
1054 | - update_option( 'wpinv_remove_data_on_invoice_unistall', $new ); |
|
1053 | + if ($old != $new) { |
|
1054 | + update_option('wpinv_remove_data_on_invoice_unistall', $new); |
|
1055 | 1055 | } |
1056 | 1056 | } |
1057 | -add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 ); |
|
1058 | -add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1059 | -add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1060 | -add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1061 | -add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1062 | -add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1063 | -add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1064 | -add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1065 | -add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1066 | -add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1067 | -add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 ); |
|
1068 | - |
|
1069 | -function wpinv_settings_tab_bottom_emails( $active_tab, $section ) { |
|
1057 | +add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3); |
|
1058 | +add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1059 | +add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1060 | +add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1061 | +add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1062 | +add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1063 | +add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1064 | +add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1065 | +add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1066 | +add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1067 | +add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2); |
|
1068 | + |
|
1069 | +function wpinv_settings_tab_bottom_emails($active_tab, $section) { |
|
1070 | 1070 | ?> |
1071 | 1071 | <div class="wpinv-email-wc-row "> |
1072 | 1072 | <div class="wpinv-email-wc-td"> |
1073 | - <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3> |
|
1073 | + <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3> |
|
1074 | 1074 | <p class="wpinv-email-wc-description"> |
1075 | 1075 | <?php |
1076 | - $description = __( 'The following wildcards can be used in email subjects, heading and content:<br> |
|
1076 | + $description = __('The following wildcards can be used in email subjects, heading and content:<br> |
|
1077 | 1077 | <strong>{site_title} :</strong> Site Title<br> |
1078 | 1078 | <strong>{name} :</strong> Customer\'s full name<br> |
1079 | 1079 | <strong>{first_name} :</strong> Customer\'s first name<br> |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | <strong>{invoice_due_date} :</strong> The date the invoice is due<br> |
1088 | 1088 | <strong>{date} :</strong> Today\'s date.<br> |
1089 | 1089 | <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br> |
1090 | - <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' ); |
|
1090 | + <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing'); |
|
1091 | 1091 | echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section); |
1092 | 1092 | ?> |
1093 | 1093 | </p> |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | -add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' ); |
|
8 | -function wpinv_discount_custom_column( $column ) { |
|
7 | +add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column'); |
|
8 | +function wpinv_discount_custom_column($column) { |
|
9 | 9 | global $post; |
10 | 10 | |
11 | - $discount = new WPInv_Discount( $post ); |
|
11 | + $discount = new WPInv_Discount($post); |
|
12 | 12 | |
13 | - switch ( $column ) { |
|
13 | + switch ($column) { |
|
14 | 14 | case 'code' : |
15 | 15 | echo $discount->get_code(); |
16 | 16 | break; |
@@ -21,38 +21,38 @@ discard block |
||
21 | 21 | echo $discount->get_usage(); |
22 | 22 | break; |
23 | 23 | case 'start_date' : |
24 | - echo getpaid_format_date_value( $discount->get_start_date() ); |
|
24 | + echo getpaid_format_date_value($discount->get_start_date()); |
|
25 | 25 | break; |
26 | 26 | case 'expiry_date' : |
27 | - echo getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ); |
|
27 | + echo getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing')); |
|
28 | 28 | break; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | |
32 | -add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 ); |
|
33 | -function wpinv_post_row_actions( $actions, $post ) { |
|
34 | - $post_type = !empty( $post->post_type ) ? $post->post_type : ''; |
|
32 | +add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2); |
|
33 | +function wpinv_post_row_actions($actions, $post) { |
|
34 | + $post_type = !empty($post->post_type) ? $post->post_type : ''; |
|
35 | 35 | |
36 | - if ( $post_type == 'wpi_invoice' ) { |
|
36 | + if ($post_type == 'wpi_invoice') { |
|
37 | 37 | $actions = array(); |
38 | 38 | } |
39 | 39 | |
40 | - if ( $post_type == 'wpi_discount' ) { |
|
41 | - $actions = wpinv_discount_row_actions( $post, $actions ); |
|
40 | + if ($post_type == 'wpi_discount') { |
|
41 | + $actions = wpinv_discount_row_actions($post, $actions); |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | return $actions; |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_discount_row_actions( $discount, $row_actions ) { |
|
48 | - $row_actions = array(); |
|
49 | - $edit_link = get_edit_post_link( $discount->ID ); |
|
50 | - $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>'; |
|
47 | +function wpinv_discount_row_actions($discount, $row_actions) { |
|
48 | + $row_actions = array(); |
|
49 | + $edit_link = get_edit_post_link($discount->ID); |
|
50 | + $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>'; |
|
51 | 51 | |
52 | - if( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) ) { |
|
53 | - $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>'; |
|
54 | - } elseif( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) ) { |
|
55 | - $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>'; |
|
52 | + if (in_array(strtolower($discount->post_status), array('publish'))) { |
|
53 | + $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>'; |
|
54 | + } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) { |
|
55 | + $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>'; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | $delete_url = esc_url( |
@@ -66,110 +66,110 @@ discard block |
||
66 | 66 | 'wpinv_discount_nonce' |
67 | 67 | ) |
68 | 68 | ); |
69 | - $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>'; |
|
69 | + $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>'; |
|
70 | 70 | |
71 | - $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount ); |
|
71 | + $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount); |
|
72 | 72 | |
73 | 73 | return $row_actions; |
74 | 74 | } |
75 | 75 | |
76 | -add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 ); |
|
77 | -function wpinv_table_primary_column( $default, $screen_id ) { |
|
78 | - if ( 'edit-wpi_invoice' === $screen_id ) { |
|
76 | +add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2); |
|
77 | +function wpinv_table_primary_column($default, $screen_id) { |
|
78 | + if ('edit-wpi_invoice' === $screen_id) { |
|
79 | 79 | return 'name'; |
80 | 80 | } |
81 | 81 | |
82 | 82 | return $default; |
83 | 83 | } |
84 | 84 | |
85 | -function wpinv_discount_bulk_actions( $actions, $display = false ) { |
|
86 | - if ( !$display ) { |
|
85 | +function wpinv_discount_bulk_actions($actions, $display = false) { |
|
86 | + if (!$display) { |
|
87 | 87 | return array(); |
88 | 88 | } |
89 | 89 | |
90 | 90 | $actions = array( |
91 | - 'activate' => __( 'Activate', 'invoicing' ), |
|
92 | - 'deactivate' => __( 'Deactivate', 'invoicing' ), |
|
93 | - 'delete' => __( 'Delete', 'invoicing' ), |
|
91 | + 'activate' => __('Activate', 'invoicing'), |
|
92 | + 'deactivate' => __('Deactivate', 'invoicing'), |
|
93 | + 'delete' => __('Delete', 'invoicing'), |
|
94 | 94 | ); |
95 | 95 | $two = ''; |
96 | 96 | $which = 'top'; |
97 | 97 | echo '</div><div class="alignleft actions bulkactions">'; |
98 | - echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>'; |
|
99 | - echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">"; |
|
100 | - echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>"; |
|
98 | + echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>'; |
|
99 | + echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">"; |
|
100 | + echo '<option value="-1">' . __('Bulk Actions') . "</option>"; |
|
101 | 101 | |
102 | - foreach ( $actions as $name => $title ) { |
|
102 | + foreach ($actions as $name => $title) { |
|
103 | 103 | $class = 'edit' === $name ? ' class="hide-if-no-js"' : ''; |
104 | 104 | |
105 | 105 | echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>"; |
106 | 106 | } |
107 | 107 | echo "</select>"; |
108 | 108 | |
109 | - submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) ); |
|
109 | + submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two")); |
|
110 | 110 | |
111 | 111 | echo '</div><div class="alignleft actions">'; |
112 | 112 | } |
113 | -add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 ); |
|
113 | +add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10); |
|
114 | 114 | |
115 | -function wpinv_disable_months_dropdown( $disable, $post_type ) { |
|
116 | - if ( $post_type == 'wpi_discount' ) { |
|
115 | +function wpinv_disable_months_dropdown($disable, $post_type) { |
|
116 | + if ($post_type == 'wpi_discount') { |
|
117 | 117 | $disable = true; |
118 | 118 | } |
119 | 119 | |
120 | 120 | return $disable; |
121 | 121 | } |
122 | -add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 ); |
|
122 | +add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2); |
|
123 | 123 | |
124 | 124 | function wpinv_restrict_manage_posts() { |
125 | 125 | global $typenow; |
126 | 126 | |
127 | - if( 'wpi_discount' == $typenow ) { |
|
127 | + if ('wpi_discount' == $typenow) { |
|
128 | 128 | wpinv_discount_filters(); |
129 | 129 | } |
130 | 130 | } |
131 | -add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 ); |
|
131 | +add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10); |
|
132 | 132 | |
133 | 133 | function wpinv_discount_filters() { |
134 | - wpinv_discount_bulk_actions( array(), true ); |
|
134 | + wpinv_discount_bulk_actions(array(), true); |
|
135 | 135 | |
136 | 136 | ?> |
137 | 137 | <select name="discount_type" id="dropdown_wpinv_discount_type"> |
138 | - <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option> |
|
138 | + <option value=""><?php _e('Show all types', 'invoicing'); ?></option> |
|
139 | 139 | <?php |
140 | 140 | $types = wpinv_get_discount_types(); |
141 | 141 | |
142 | - foreach ( $types as $name => $type ) { |
|
143 | - echo '<option value="' . esc_attr( $name ) . '"'; |
|
142 | + foreach ($types as $name => $type) { |
|
143 | + echo '<option value="' . esc_attr($name) . '"'; |
|
144 | 144 | |
145 | - if ( isset( $_GET['discount_type'] ) ) |
|
146 | - selected( $name, $_GET['discount_type'] ); |
|
145 | + if (isset($_GET['discount_type'])) |
|
146 | + selected($name, $_GET['discount_type']); |
|
147 | 147 | |
148 | - echo '>' . esc_html__( $type, 'invoicing' ) . '</option>'; |
|
148 | + echo '>' . esc_html__($type, 'invoicing') . '</option>'; |
|
149 | 149 | } |
150 | 150 | ?> |
151 | 151 | </select> |
152 | 152 | <?php |
153 | 153 | } |
154 | 154 | |
155 | -function wpinv_request( $vars ) { |
|
155 | +function wpinv_request($vars) { |
|
156 | 156 | global $typenow, $wp_query, $wp_post_statuses; |
157 | 157 | |
158 | - if ( 'wpi_invoice' === $typenow ) { |
|
159 | - if ( !isset( $vars['post_status'] ) ) { |
|
158 | + if ('wpi_invoice' === $typenow) { |
|
159 | + if (!isset($vars['post_status'])) { |
|
160 | 160 | $post_statuses = wpinv_get_invoice_statuses(); |
161 | 161 | |
162 | - foreach ( $post_statuses as $status => $value ) { |
|
163 | - if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) { |
|
164 | - unset( $post_statuses[ $status ] ); |
|
162 | + foreach ($post_statuses as $status => $value) { |
|
163 | + if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) { |
|
164 | + unset($post_statuses[$status]); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | |
168 | - $vars['post_status'] = array_keys( $post_statuses ); |
|
168 | + $vars['post_status'] = array_keys($post_statuses); |
|
169 | 169 | } |
170 | 170 | |
171 | - if ( isset( $vars['orderby'] ) ) { |
|
172 | - if ( 'amount' == $vars['orderby'] ) { |
|
171 | + if (isset($vars['orderby'])) { |
|
172 | + if ('amount' == $vars['orderby']) { |
|
173 | 173 | $vars = array_merge( |
174 | 174 | $vars, |
175 | 175 | array( |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | 'orderby' => 'meta_value_num' |
178 | 178 | ) |
179 | 179 | ); |
180 | - } else if ( 'customer' == $vars['orderby'] ) { |
|
180 | + } else if ('customer' == $vars['orderby']) { |
|
181 | 181 | $vars = array_merge( |
182 | 182 | $vars, |
183 | 183 | array( |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | 'orderby' => 'meta_value' |
186 | 186 | ) |
187 | 187 | ); |
188 | - } else if ( 'number' == $vars['orderby'] ) { |
|
188 | + } else if ('number' == $vars['orderby']) { |
|
189 | 189 | $vars = array_merge( |
190 | 190 | $vars, |
191 | 191 | array( |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | 'orderby' => 'meta_value' |
194 | 194 | ) |
195 | 195 | ); |
196 | - } else if ( 'payment_date' == $vars['orderby'] ) { |
|
196 | + } else if ('payment_date' == $vars['orderby']) { |
|
197 | 197 | $vars = array_merge( |
198 | 198 | $vars, |
199 | 199 | array( |
@@ -203,73 +203,73 @@ discard block |
||
203 | 203 | ); |
204 | 204 | } |
205 | 205 | } |
206 | - } else if ( 'wpi_discount' == $typenow ) { |
|
207 | - $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array(); |
|
206 | + } else if ('wpi_discount' == $typenow) { |
|
207 | + $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array(); |
|
208 | 208 | // Filter vat rule type |
209 | - if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) { |
|
209 | + if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') { |
|
210 | 210 | $meta_query[] = array( |
211 | 211 | 'key' => '_wpi_discount_type', |
212 | - 'value' => sanitize_text_field( $_GET['discount_type'] ), |
|
212 | + 'value' => sanitize_text_field($_GET['discount_type']), |
|
213 | 213 | 'compare' => '=' |
214 | 214 | ); |
215 | 215 | } |
216 | 216 | |
217 | - if ( !empty( $meta_query ) ) { |
|
217 | + if (!empty($meta_query)) { |
|
218 | 218 | $vars['meta_query'] = $meta_query; |
219 | 219 | } |
220 | 220 | } |
221 | 221 | |
222 | 222 | return $vars; |
223 | 223 | } |
224 | -add_filter( 'request', 'wpinv_request' ); |
|
224 | +add_filter('request', 'wpinv_request'); |
|
225 | 225 | |
226 | -function wpinv_item_type_class( $classes, $class, $post_id ) { |
|
226 | +function wpinv_item_type_class($classes, $class, $post_id) { |
|
227 | 227 | global $pagenow, $typenow; |
228 | 228 | |
229 | - if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) { |
|
230 | - if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) { |
|
231 | - $classes[] = 'wpi-type-' . sanitize_html_class( $type ); |
|
229 | + if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) { |
|
230 | + if ($type = get_post_meta($post_id, '_wpinv_type', true)) { |
|
231 | + $classes[] = 'wpi-type-' . sanitize_html_class($type); |
|
232 | 232 | } |
233 | 233 | |
234 | - if ( !wpinv_item_is_editable( $post_id ) ) { |
|
234 | + if (!wpinv_item_is_editable($post_id)) { |
|
235 | 235 | $classes[] = 'wpi-editable-n'; |
236 | 236 | } |
237 | 237 | } |
238 | 238 | return $classes; |
239 | 239 | } |
240 | -add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 ); |
|
240 | +add_filter('post_class', 'wpinv_item_type_class', 10, 3); |
|
241 | 241 | |
242 | 242 | function wpinv_check_quick_edit() { |
243 | 243 | global $pagenow, $current_screen, $wpinv_item_screen; |
244 | 244 | |
245 | - if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) { |
|
246 | - if ( empty( $wpinv_item_screen ) ) { |
|
247 | - if ( $current_screen->post_type == 'wpi_item' ) { |
|
245 | + if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) { |
|
246 | + if (empty($wpinv_item_screen)) { |
|
247 | + if ($current_screen->post_type == 'wpi_item') { |
|
248 | 248 | $wpinv_item_screen = 'y'; |
249 | 249 | } else { |
250 | 250 | $wpinv_item_screen = 'n'; |
251 | 251 | } |
252 | 252 | } |
253 | 253 | |
254 | - if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) { |
|
255 | - add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
256 | - add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 ); |
|
254 | + if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') { |
|
255 | + add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
256 | + add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2); |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | } |
260 | -add_action( 'admin_head', 'wpinv_check_quick_edit', 10 ); |
|
260 | +add_action('admin_head', 'wpinv_check_quick_edit', 10); |
|
261 | 261 | |
262 | -function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) { |
|
263 | - if ( isset( $actions['inline hide-if-no-js'] ) ) { |
|
264 | - unset( $actions['inline hide-if-no-js'] ); |
|
262 | +function wpinv_item_disable_quick_edit($actions = array(), $row = null) { |
|
263 | + if (isset($actions['inline hide-if-no-js'])) { |
|
264 | + unset($actions['inline hide-if-no-js']); |
|
265 | 265 | } |
266 | 266 | |
267 | - if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) { |
|
268 | - if ( isset( $actions['trash'] ) ) { |
|
269 | - unset( $actions['trash'] ); |
|
267 | + if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) { |
|
268 | + if (isset($actions['trash'])) { |
|
269 | + unset($actions['trash']); |
|
270 | 270 | } |
271 | - if ( isset( $actions['delete'] ) ) { |
|
272 | - unset( $actions['delete'] ); |
|
271 | + if (isset($actions['delete'])) { |
|
272 | + unset($actions['delete']); |
|
273 | 273 | } |
274 | 274 | } |
275 | 275 | |
@@ -286,19 +286,19 @@ discard block |
||
286 | 286 | * @param int $post_parent (default: 0) Parent for the new page |
287 | 287 | * @return int page ID |
288 | 288 | */ |
289 | -function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) { |
|
289 | +function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) { |
|
290 | 290 | global $wpdb; |
291 | 291 | |
292 | - $option_value = wpinv_get_option( $option ); |
|
292 | + $option_value = wpinv_get_option($option); |
|
293 | 293 | |
294 | - if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) { |
|
295 | - if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) { |
|
294 | + if ($option_value > 0 && ($page_object = get_post($option_value))) { |
|
295 | + if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) { |
|
296 | 296 | // Valid page is already in place |
297 | 297 | return $page_object->ID; |
298 | 298 | } |
299 | 299 | } |
300 | 300 | |
301 | - if(!empty($post_parent)){ |
|
301 | + if (!empty($post_parent)) { |
|
302 | 302 | $page = get_page_by_path($post_parent); |
303 | 303 | if ($page) { |
304 | 304 | $post_parent = $page->ID; |
@@ -307,40 +307,40 @@ discard block |
||
307 | 307 | } |
308 | 308 | } |
309 | 309 | |
310 | - if ( strlen( $page_content ) > 0 ) { |
|
310 | + if (strlen($page_content) > 0) { |
|
311 | 311 | // Search for an existing page with the specified page content (typically a shortcode) |
312 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
312 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
313 | 313 | } else { |
314 | 314 | // Search for an existing page with the specified page slug |
315 | - $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) ); |
|
315 | + $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug)); |
|
316 | 316 | } |
317 | 317 | |
318 | - $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content ); |
|
318 | + $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content); |
|
319 | 319 | |
320 | - if ( $valid_page_found ) { |
|
321 | - if ( $option ) { |
|
322 | - wpinv_update_option( $option, $valid_page_found ); |
|
320 | + if ($valid_page_found) { |
|
321 | + if ($option) { |
|
322 | + wpinv_update_option($option, $valid_page_found); |
|
323 | 323 | } |
324 | 324 | return $valid_page_found; |
325 | 325 | } |
326 | 326 | |
327 | 327 | // Search for a matching valid trashed page |
328 | - if ( strlen( $page_content ) > 0 ) { |
|
328 | + if (strlen($page_content) > 0) { |
|
329 | 329 | // Search for an existing page with the specified page content (typically a shortcode) |
330 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) ); |
|
330 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%")); |
|
331 | 331 | } else { |
332 | 332 | // Search for an existing page with the specified page slug |
333 | - $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) ); |
|
333 | + $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug)); |
|
334 | 334 | } |
335 | 335 | |
336 | - if ( $trashed_page_found ) { |
|
336 | + if ($trashed_page_found) { |
|
337 | 337 | $page_id = $trashed_page_found; |
338 | 338 | $page_data = array( |
339 | 339 | 'ID' => $page_id, |
340 | 340 | 'post_status' => 'publish', |
341 | 341 | 'post_parent' => $post_parent, |
342 | 342 | ); |
343 | - wp_update_post( $page_data ); |
|
343 | + wp_update_post($page_data); |
|
344 | 344 | } else { |
345 | 345 | $page_data = array( |
346 | 346 | 'post_status' => 'publish', |
@@ -352,11 +352,11 @@ discard block |
||
352 | 352 | 'post_parent' => $post_parent, |
353 | 353 | 'comment_status' => 'closed', |
354 | 354 | ); |
355 | - $page_id = wp_insert_post( $page_data ); |
|
355 | + $page_id = wp_insert_post($page_data); |
|
356 | 356 | } |
357 | 357 | |
358 | - if ( $option ) { |
|
359 | - wpinv_update_option( $option, (int)$page_id ); |
|
358 | + if ($option) { |
|
359 | + wpinv_update_option($option, (int) $page_id); |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | return $page_id; |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * Metaboxes Admin Class |
@@ -25,93 +25,93 @@ discard block |
||
25 | 25 | public static function init() { |
26 | 26 | |
27 | 27 | // Register metaboxes. |
28 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 ); |
|
28 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2); |
|
29 | 29 | |
30 | 30 | // Remove metaboxes. |
31 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 ); |
|
31 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30); |
|
32 | 32 | |
33 | 33 | // Rename metaboxes. |
34 | - add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 ); |
|
34 | + add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45); |
|
35 | 35 | |
36 | 36 | // Save metaboxes. |
37 | - add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 ); |
|
37 | + add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2); |
|
38 | 38 | } |
39 | 39 | |
40 | 40 | /** |
41 | 41 | * Register core metaboxes. |
42 | 42 | */ |
43 | - public static function add_meta_boxes( $post_type, $post ) { |
|
43 | + public static function add_meta_boxes($post_type, $post) { |
|
44 | 44 | global $wpinv_euvat; |
45 | 45 | |
46 | 46 | // For invoices... |
47 | - if ( $post_type == 'wpi_invoice' ) { |
|
48 | - $invoice = new WPInv_Invoice( $post ); |
|
47 | + if ($post_type == 'wpi_invoice') { |
|
48 | + $invoice = new WPInv_Invoice($post); |
|
49 | 49 | |
50 | 50 | // Resend invoice. |
51 | - if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) { |
|
52 | - add_meta_box( 'wpinv-mb-resend-invoice', __( 'Resend Invoice', 'invoicing' ), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low' ); |
|
51 | + if (!$invoice->is_draft() && !$invoice->is_paid()) { |
|
52 | + add_meta_box('wpinv-mb-resend-invoice', __('Resend Invoice', 'invoicing'), 'GetPaid_Meta_Box_Resend_Invoice::output', 'wpi_invoice', 'side', 'low'); |
|
53 | 53 | } |
54 | 54 | |
55 | 55 | // Subscriptions. |
56 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
57 | - if ( ! empty( $subscription ) ) { |
|
58 | - add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced' ); |
|
59 | - add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced' ); |
|
56 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
57 | + if (!empty($subscription)) { |
|
58 | + add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', 'wpi_invoice', 'advanced'); |
|
59 | + add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', 'wpi_invoice', 'advanced'); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | // Invoice details. |
63 | - add_meta_box( 'wpinv-details', __( 'Invoice Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default' ); |
|
63 | + add_meta_box('wpinv-details', __('Invoice Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Details::output', 'wpi_invoice', 'side', 'default'); |
|
64 | 64 | |
65 | 65 | // Payment details. |
66 | - if ( ! $invoice->is_draft() ) { |
|
67 | - add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default' ); |
|
66 | + if (!$invoice->is_draft()) { |
|
67 | + add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', 'wpi_invoice', 'side', 'default'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Billing details. |
71 | - add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high' ); |
|
71 | + add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', 'wpi_invoice', 'normal', 'high'); |
|
72 | 72 | |
73 | 73 | // Invoice items. |
74 | - add_meta_box( 'wpinv-items', __( 'Invoice Items', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high' ); |
|
74 | + add_meta_box('wpinv-items', __('Invoice Items', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Items::output', 'wpi_invoice', 'normal', 'high'); |
|
75 | 75 | |
76 | 76 | // Invoice notes. |
77 | - add_meta_box( 'wpinv-notes', __( 'Invoice Notes', 'invoicing' ), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low' ); |
|
77 | + add_meta_box('wpinv-notes', __('Invoice Notes', 'invoicing'), 'WPInv_Meta_Box_Notes::output', 'wpi_invoice', 'side', 'low'); |
|
78 | 78 | |
79 | 79 | // Payment form information. |
80 | - if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) { |
|
81 | - add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high' ); |
|
80 | + if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) { |
|
81 | + add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', 'wpi_invoice', 'side', 'high'); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | |
85 | 85 | // For payment forms. |
86 | - if ( $post_type == 'wpi_payment_form' ) { |
|
86 | + if ($post_type == 'wpi_payment_form') { |
|
87 | 87 | |
88 | 88 | // Design payment form. |
89 | - add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' ); |
|
89 | + add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal'); |
|
90 | 90 | |
91 | 91 | // Payment form information. |
92 | - add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' ); |
|
92 | + add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side'); |
|
93 | 93 | |
94 | 94 | } |
95 | 95 | |
96 | 96 | // For invoice items. |
97 | - if ( $post_type == 'wpi_item' ) { |
|
97 | + if ($post_type == 'wpi_item') { |
|
98 | 98 | |
99 | 99 | // Item details. |
100 | - add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' ); |
|
100 | + add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high'); |
|
101 | 101 | |
102 | 102 | // If taxes are enabled, register the tax metabox. |
103 | - if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) { |
|
104 | - add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' ); |
|
103 | + if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) { |
|
104 | + add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high'); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // Item info. |
108 | - add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' ); |
|
108 | + add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core'); |
|
109 | 109 | |
110 | 110 | } |
111 | 111 | |
112 | 112 | // For invoice discounts. |
113 | - if ( $post_type == 'wpi_discount' ) { |
|
114 | - add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' ); |
|
113 | + if ($post_type == 'wpi_discount') { |
|
114 | + add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high'); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * Remove some metaboxes. |
122 | 122 | */ |
123 | 123 | public static function remove_meta_boxes() { |
124 | - remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' ); |
|
124 | + remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal'); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -137,37 +137,37 @@ discard block |
||
137 | 137 | * @param int $post_id Post ID. |
138 | 138 | * @param object $post Post object. |
139 | 139 | */ |
140 | - public static function save_meta_boxes( $post_id, $post ) { |
|
141 | - $post_id = absint( $post_id ); |
|
142 | - $data = wp_unslash( $_POST ); |
|
140 | + public static function save_meta_boxes($post_id, $post) { |
|
141 | + $post_id = absint($post_id); |
|
142 | + $data = wp_unslash($_POST); |
|
143 | 143 | |
144 | 144 | // Do not save for ajax requests. |
145 | - if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) { |
|
145 | + if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) { |
|
146 | 146 | return; |
147 | 147 | } |
148 | 148 | |
149 | 149 | // $post_id and $post are required |
150 | - if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) { |
|
150 | + if (empty($post_id) || empty($post) || self::$saved_meta_boxes) { |
|
151 | 151 | return; |
152 | 152 | } |
153 | 153 | |
154 | 154 | // Dont' save meta boxes for revisions or autosaves. |
155 | - if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) { |
|
155 | + if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) { |
|
156 | 156 | return; |
157 | 157 | } |
158 | 158 | |
159 | 159 | // Check the nonce. |
160 | - if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) { |
|
160 | + if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) { |
|
161 | 161 | return; |
162 | 162 | } |
163 | 163 | |
164 | 164 | // Check the post being saved == the $post_id to prevent triggering this call for other save_post events. |
165 | - if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) { |
|
165 | + if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) { |
|
166 | 166 | return; |
167 | 167 | } |
168 | 168 | |
169 | 169 | // Check user has permission to edit. |
170 | - if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
170 | + if (!current_user_can('edit_post', $post_id)) { |
|
171 | 171 | return; |
172 | 172 | } |
173 | 173 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | |
183 | 183 | // Is this our post type? |
184 | - if ( empty( $post->post_type ) || ! isset( $post_types_map[ $post->post_type ] ) ) { |
|
184 | + if (empty($post->post_type) || !isset($post_types_map[$post->post_type])) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,8 +189,8 @@ discard block |
||
189 | 189 | self::$saved_meta_boxes = true; |
190 | 190 | |
191 | 191 | // Save the post. |
192 | - $class = $post_types_map[ $post->post_type ]; |
|
193 | - $class::save( $post_id, $_POST, $post ); |
|
192 | + $class = $post_types_map[$post->post_type]; |
|
193 | + $class::save($post_id, $_POST, $post); |
|
194 | 194 | |
195 | 195 | } |
196 | 196 |