@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Invoice_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -106,61 +106,61 @@ discard block |
||
106 | 106 | * |
107 | 107 | * @param WPInv_Invoice $invoice Invoice object. |
108 | 108 | */ |
109 | - public function create( &$invoice ) { |
|
110 | - $invoice->set_version( WPINV_VERSION ); |
|
111 | - $invoice->set_date_created( current_time('mysql') ); |
|
109 | + public function create(&$invoice) { |
|
110 | + $invoice->set_version(WPINV_VERSION); |
|
111 | + $invoice->set_date_created(current_time('mysql')); |
|
112 | 112 | |
113 | 113 | // Create a new post. |
114 | 114 | $id = wp_insert_post( |
115 | 115 | apply_filters( |
116 | 116 | 'getpaid_new_invoice_data', |
117 | 117 | array( |
118 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
119 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
120 | - 'post_status' => $this->get_post_status( $invoice ), |
|
118 | + 'post_date' => $invoice->get_date_created('edit'), |
|
119 | + 'post_type' => $invoice->get_post_type('edit'), |
|
120 | + 'post_status' => $this->get_post_status($invoice), |
|
121 | 121 | 'ping_status' => 'closed', |
122 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
123 | - 'post_title' => $invoice->get_title( 'edit' ), |
|
124 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
125 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
122 | + 'post_author' => $invoice->get_user_id('edit'), |
|
123 | + 'post_title' => $invoice->get_title('edit'), |
|
124 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
125 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
126 | 126 | ) |
127 | 127 | ), |
128 | 128 | true |
129 | 129 | ); |
130 | 130 | |
131 | - if ( $id && ! is_wp_error( $id ) ) { |
|
131 | + if ($id && !is_wp_error($id)) { |
|
132 | 132 | |
133 | 133 | // Update the new id and regenerate a title. |
134 | - $invoice->set_id( $id ); |
|
134 | + $invoice->set_id($id); |
|
135 | 135 | |
136 | 136 | $invoice->maybe_set_number(); |
137 | 137 | |
138 | 138 | wp_update_post( |
139 | 139 | array( |
140 | 140 | 'ID' => $invoice->get_id(), |
141 | - 'post_title' => $invoice->get_number( 'edit' ), |
|
142 | - 'post_name' => $invoice->get_path( 'edit' ) |
|
141 | + 'post_title' => $invoice->get_number('edit'), |
|
142 | + 'post_name' => $invoice->get_path('edit') |
|
143 | 143 | ) |
144 | 144 | ); |
145 | 145 | |
146 | 146 | // Save special fields and items. |
147 | - $this->save_special_fields( $invoice ); |
|
148 | - $this->save_items( $invoice ); |
|
147 | + $this->save_special_fields($invoice); |
|
148 | + $this->save_items($invoice); |
|
149 | 149 | |
150 | 150 | // Update meta data. |
151 | - $this->update_post_meta( $invoice ); |
|
151 | + $this->update_post_meta($invoice); |
|
152 | 152 | $invoice->save_meta_data(); |
153 | 153 | |
154 | 154 | // Apply changes. |
155 | 155 | $invoice->apply_changes(); |
156 | - $this->clear_caches( $invoice ); |
|
156 | + $this->clear_caches($invoice); |
|
157 | 157 | |
158 | 158 | // Fires after a new invoice is created. |
159 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
159 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice); |
|
160 | 160 | return true; |
161 | 161 | } |
162 | 162 | |
163 | - if ( is_wp_error( $id ) ) { |
|
163 | + if (is_wp_error($id)) { |
|
164 | 164 | $invoice->last_error = $id->get_error_message(); |
165 | 165 | } |
166 | 166 | |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * |
175 | 175 | */ |
176 | - public function read( &$invoice ) { |
|
176 | + public function read(&$invoice) { |
|
177 | 177 | |
178 | 178 | $invoice->set_defaults(); |
179 | - $invoice_object = get_post( $invoice->get_id() ); |
|
179 | + $invoice_object = get_post($invoice->get_id()); |
|
180 | 180 | |
181 | - if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) { |
|
182 | - $invoice->last_error = __( 'Invalid invoice.', 'invoicing' ); |
|
183 | - $invoice->set_id( 0 ); |
|
181 | + if (!$invoice->get_id() || !$invoice_object || !getpaid_is_invoice_post_type($invoice_object->post_type)) { |
|
182 | + $invoice->last_error = __('Invalid invoice.', 'invoicing'); |
|
183 | + $invoice->set_id(0); |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | ) |
199 | 199 | ); |
200 | 200 | |
201 | - $invoice->set_type( $invoice_object->post_type ); |
|
201 | + $invoice->set_type($invoice_object->post_type); |
|
202 | 202 | |
203 | - $this->read_object_data( $invoice, $invoice_object ); |
|
204 | - $this->add_special_fields( $invoice ); |
|
205 | - $this->add_items( $invoice ); |
|
203 | + $this->read_object_data($invoice, $invoice_object); |
|
204 | + $this->add_special_fields($invoice); |
|
205 | + $this->add_items($invoice); |
|
206 | 206 | $invoice->read_meta_data(); |
207 | - $invoice->set_object_read( true ); |
|
208 | - do_action( 'getpaid_read_' . $invoice->get_type(), $invoice ); |
|
207 | + $invoice->set_object_read(true); |
|
208 | + do_action('getpaid_read_' . $invoice->get_type(), $invoice); |
|
209 | 209 | |
210 | 210 | } |
211 | 211 | |
@@ -214,35 +214,35 @@ discard block |
||
214 | 214 | * |
215 | 215 | * @param WPInv_Invoice $invoice Invoice object. |
216 | 216 | */ |
217 | - public function update( &$invoice ) { |
|
217 | + public function update(&$invoice) { |
|
218 | 218 | $invoice->save_meta_data(); |
219 | - $invoice->set_version( WPINV_VERSION ); |
|
219 | + $invoice->set_version(WPINV_VERSION); |
|
220 | 220 | |
221 | - if ( null === $invoice->get_date_created( 'edit' ) ) { |
|
222 | - $invoice->set_date_created( current_time('mysql') ); |
|
221 | + if (null === $invoice->get_date_created('edit')) { |
|
222 | + $invoice->set_date_created(current_time('mysql')); |
|
223 | 223 | } |
224 | 224 | |
225 | 225 | // Ensure both the key and number are set. |
226 | 226 | $invoice->get_path(); |
227 | 227 | |
228 | 228 | // Grab the current status so we can compare. |
229 | - $previous_status = get_post_status( $invoice->get_id() ); |
|
229 | + $previous_status = get_post_status($invoice->get_id()); |
|
230 | 230 | |
231 | 231 | $changes = $invoice->get_changes(); |
232 | 232 | |
233 | 233 | // Only update the post when the post data changes. |
234 | - if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) { |
|
234 | + if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) { |
|
235 | 235 | $post_data = array( |
236 | - 'post_date' => $invoice->get_date_created( 'edit' ), |
|
237 | - 'post_date_gmt' => $invoice->get_date_created_gmt( 'edit' ), |
|
238 | - 'post_status' => $invoice->get_status( 'edit' ), |
|
239 | - 'post_title' => $invoice->get_name( 'edit' ), |
|
240 | - 'post_author' => $invoice->get_user_id( 'edit' ), |
|
241 | - 'post_modified' => $invoice->get_date_modified( 'edit' ), |
|
242 | - 'post_excerpt' => $invoice->get_description( 'edit' ), |
|
243 | - 'post_parent' => $invoice->get_parent_id( 'edit' ), |
|
244 | - 'post_name' => $invoice->get_path( 'edit' ), |
|
245 | - 'post_type' => $invoice->get_post_type( 'edit' ), |
|
236 | + 'post_date' => $invoice->get_date_created('edit'), |
|
237 | + 'post_date_gmt' => $invoice->get_date_created_gmt('edit'), |
|
238 | + 'post_status' => $invoice->get_status('edit'), |
|
239 | + 'post_title' => $invoice->get_name('edit'), |
|
240 | + 'post_author' => $invoice->get_user_id('edit'), |
|
241 | + 'post_modified' => $invoice->get_date_modified('edit'), |
|
242 | + 'post_excerpt' => $invoice->get_description('edit'), |
|
243 | + 'post_parent' => $invoice->get_parent_id('edit'), |
|
244 | + 'post_name' => $invoice->get_path('edit'), |
|
245 | + 'post_type' => $invoice->get_post_type('edit'), |
|
246 | 246 | ); |
247 | 247 | |
248 | 248 | /** |
@@ -253,35 +253,35 @@ discard block |
||
253 | 253 | * This ensures hooks are fired by either WP itself (admin screen save), |
254 | 254 | * or an update purely from CRUD. |
255 | 255 | */ |
256 | - if ( doing_action( 'save_post' ) ) { |
|
257 | - $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) ); |
|
258 | - clean_post_cache( $invoice->get_id() ); |
|
256 | + if (doing_action('save_post')) { |
|
257 | + $GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id())); |
|
258 | + clean_post_cache($invoice->get_id()); |
|
259 | 259 | } else { |
260 | - wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) ); |
|
260 | + wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data)); |
|
261 | 261 | } |
262 | - $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
262 | + $invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook. |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | // Update meta data. |
266 | - $this->update_post_meta( $invoice ); |
|
266 | + $this->update_post_meta($invoice); |
|
267 | 267 | |
268 | 268 | // Save special fields and items. |
269 | - $this->save_special_fields( $invoice ); |
|
270 | - $this->save_items( $invoice ); |
|
269 | + $this->save_special_fields($invoice); |
|
270 | + $this->save_items($invoice); |
|
271 | 271 | |
272 | 272 | // Apply the changes. |
273 | 273 | $invoice->apply_changes(); |
274 | 274 | |
275 | 275 | // Clear caches. |
276 | - $this->clear_caches( $invoice ); |
|
276 | + $this->clear_caches($invoice); |
|
277 | 277 | |
278 | 278 | // Fire a hook depending on the status - this should be considered a creation if it was previously draft status. |
279 | - $new_status = $invoice->get_status( 'edit' ); |
|
279 | + $new_status = $invoice->get_status('edit'); |
|
280 | 280 | |
281 | - if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) { |
|
282 | - do_action( 'getpaid_new_' . $invoice->get_type(), $invoice ); |
|
281 | + if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) { |
|
282 | + do_action('getpaid_new_' . $invoice->get_type(), $invoice); |
|
283 | 283 | } else { |
284 | - do_action( 'getpaid_update_' . $invoice->get_type(), $invoice ); |
|
284 | + do_action('getpaid_update_' . $invoice->get_type(), $invoice); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | } |
@@ -297,45 +297,45 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @param WPInv_Invoice $invoice Invoice object. |
299 | 299 | */ |
300 | - public function add_special_fields( &$invoice ) { |
|
300 | + public function add_special_fields(&$invoice) { |
|
301 | 301 | global $wpdb; |
302 | 302 | |
303 | 303 | // Maybe retrieve from the cache. |
304 | - $data = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
304 | + $data = wp_cache_get($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
305 | 305 | |
306 | 306 | // If not found, retrieve from the db. |
307 | - if ( false === $data ) { |
|
308 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
307 | + if (false === $data) { |
|
308 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
309 | 309 | |
310 | 310 | $data = $wpdb->get_row( |
311 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ), |
|
311 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id()), |
|
312 | 312 | ARRAY_A |
313 | 313 | ); |
314 | 314 | |
315 | 315 | // Update the cache with our data |
316 | - wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' ); |
|
316 | + wp_cache_set($invoice->get_id(), $data, 'getpaid_invoice_special_fields'); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
320 | 320 | // Abort if the data does not exist. |
321 | - if ( empty( $data ) ) { |
|
322 | - $invoice->set_object_read( true ); |
|
323 | - $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) ); |
|
321 | + if (empty($data)) { |
|
322 | + $invoice->set_object_read(true); |
|
323 | + $invoice->set_props(wpinv_get_user_address($invoice->get_user_id())); |
|
324 | 324 | return; |
325 | 325 | } |
326 | 326 | |
327 | 327 | $props = array(); |
328 | 328 | |
329 | - foreach ( $this->database_fields_to_props as $db_field => $prop ) { |
|
329 | + foreach ($this->database_fields_to_props as $db_field => $prop) { |
|
330 | 330 | |
331 | - if ( $db_field == 'post_id' ) { |
|
331 | + if ($db_field == 'post_id') { |
|
332 | 332 | continue; |
333 | 333 | } |
334 | 334 | |
335 | - $props[ $prop ] = $data[ $db_field ]; |
|
335 | + $props[$prop] = $data[$db_field]; |
|
336 | 336 | } |
337 | 337 | |
338 | - $invoice->set_props( $props ); |
|
338 | + $invoice->set_props($props); |
|
339 | 339 | |
340 | 340 | } |
341 | 341 | |
@@ -346,14 +346,14 @@ discard block |
||
346 | 346 | * @param WPInv_Invoice $invoice The Invoice object. |
347 | 347 | * @return array A mapping of field keys => prop names, filtered by ones that should be updated. |
348 | 348 | */ |
349 | - protected function get_special_fields_to_update( $invoice ) { |
|
349 | + protected function get_special_fields_to_update($invoice) { |
|
350 | 350 | $fields_to_update = array(); |
351 | - $changed_props = $invoice->get_changes(); |
|
351 | + $changed_props = $invoice->get_changes(); |
|
352 | 352 | |
353 | 353 | // Props should be updated if they are a part of the $changed array or don't exist yet. |
354 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
355 | - if ( array_key_exists( $prop, $changed_props ) ) { |
|
356 | - $fields_to_update[ $database_field ] = $prop; |
|
354 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
355 | + if (array_key_exists($prop, $changed_props)) { |
|
356 | + $fields_to_update[$database_field] = $prop; |
|
357 | 357 | } |
358 | 358 | } |
359 | 359 | |
@@ -366,25 +366,25 @@ discard block |
||
366 | 366 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
367 | 367 | * @since 1.0.19 |
368 | 368 | */ |
369 | - protected function update_special_fields( &$invoice ) { |
|
369 | + protected function update_special_fields(&$invoice) { |
|
370 | 370 | global $wpdb; |
371 | 371 | |
372 | 372 | $updated_props = array(); |
373 | - $fields_to_update = $this->get_special_fields_to_update( $invoice ); |
|
373 | + $fields_to_update = $this->get_special_fields_to_update($invoice); |
|
374 | 374 | |
375 | - foreach ( $fields_to_update as $database_field => $prop ) { |
|
376 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
377 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
378 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
379 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
375 | + foreach ($fields_to_update as $database_field => $prop) { |
|
376 | + $value = $invoice->{"get_$prop"}('edit'); |
|
377 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
378 | + $value = is_bool($value) ? (int) $value : $value; |
|
379 | + $updated_props[$database_field] = maybe_serialize($value); |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( ! empty( $updated_props ) ) { |
|
382 | + if (!empty($updated_props)) { |
|
383 | 383 | |
384 | 384 | $table = $wpdb->prefix . 'getpaid_invoices'; |
385 | - $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) ); |
|
386 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
387 | - do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props ); |
|
385 | + $wpdb->update($table, $updated_props, array('post_id' => $invoice->get_id())); |
|
386 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
387 | + do_action("getpaid_invoice_update_database_fields", $invoice, $updated_props); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -396,22 +396,22 @@ discard block |
||
396 | 396 | * @param WPInv_Invoice $invoice WPInv_Invoice object. |
397 | 397 | * @since 1.0.19 |
398 | 398 | */ |
399 | - protected function insert_special_fields( &$invoice ) { |
|
399 | + protected function insert_special_fields(&$invoice) { |
|
400 | 400 | global $wpdb; |
401 | 401 | |
402 | - $updated_props = array(); |
|
402 | + $updated_props = array(); |
|
403 | 403 | |
404 | - foreach ( $this->database_fields_to_props as $database_field => $prop ) { |
|
405 | - $value = $invoice->{"get_$prop"}( 'edit' ); |
|
406 | - $value = is_string( $value ) ? wp_slash( $value ) : $value; |
|
407 | - $value = is_bool( $value ) ? ( int ) $value : $value; |
|
408 | - $updated_props[ $database_field ] = maybe_serialize( $value ); |
|
404 | + foreach ($this->database_fields_to_props as $database_field => $prop) { |
|
405 | + $value = $invoice->{"get_$prop"}('edit'); |
|
406 | + $value = is_string($value) ? wp_slash($value) : $value; |
|
407 | + $value = is_bool($value) ? (int) $value : $value; |
|
408 | + $updated_props[$database_field] = maybe_serialize($value); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | $table = $wpdb->prefix . 'getpaid_invoices'; |
412 | - $wpdb->insert( $table, $updated_props ); |
|
413 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' ); |
|
414 | - do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props ); |
|
412 | + $wpdb->insert($table, $updated_props); |
|
413 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_special_fields'); |
|
414 | + do_action("getpaid_invoice_insert_database_fields", $invoice, $updated_props); |
|
415 | 415 | |
416 | 416 | } |
417 | 417 | |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * |
421 | 421 | * @param WPInv_Invoice $invoice Invoice object. |
422 | 422 | */ |
423 | - public function save_special_fields( & $invoice ) { |
|
423 | + public function save_special_fields(& $invoice) { |
|
424 | 424 | global $wpdb; |
425 | 425 | |
426 | 426 | // The invoices table. |
@@ -428,13 +428,13 @@ discard block |
||
428 | 428 | $id = (int) $invoice->get_id(); |
429 | 429 | $invoice->maybe_set_key(); |
430 | 430 | |
431 | - if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) { |
|
431 | + if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) { |
|
432 | 432 | |
433 | - $this->update_special_fields( $invoice ); |
|
433 | + $this->update_special_fields($invoice); |
|
434 | 434 | |
435 | 435 | } else { |
436 | 436 | |
437 | - $this->insert_special_fields( $invoice ); |
|
437 | + $this->insert_special_fields($invoice); |
|
438 | 438 | |
439 | 439 | } |
440 | 440 | |
@@ -445,43 +445,43 @@ discard block |
||
445 | 445 | * |
446 | 446 | * @param WPInv_Invoice $invoice Invoice object. |
447 | 447 | */ |
448 | - public function add_items( &$invoice ) { |
|
448 | + public function add_items(&$invoice) { |
|
449 | 449 | global $wpdb; |
450 | 450 | |
451 | 451 | // Maybe retrieve from the cache. |
452 | - $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
452 | + $items = wp_cache_get($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
453 | 453 | |
454 | 454 | // If not found, retrieve from the db. |
455 | - if ( false === $items ) { |
|
456 | - $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
455 | + if (false === $items) { |
|
456 | + $table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
457 | 457 | |
458 | 458 | $items = $wpdb->get_results( |
459 | - $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() ) |
|
459 | + $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id()) |
|
460 | 460 | ); |
461 | 461 | |
462 | 462 | // Update the cache with our data |
463 | - wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' ); |
|
463 | + wp_cache_set($invoice->get_id(), $items, 'getpaid_invoice_cart_details'); |
|
464 | 464 | |
465 | 465 | } |
466 | 466 | |
467 | 467 | // Abort if no items found. |
468 | - if ( empty( $items ) ) { |
|
468 | + if (empty($items)) { |
|
469 | 469 | return; |
470 | 470 | } |
471 | 471 | |
472 | - foreach ( $items as $item_data ) { |
|
473 | - $item = new GetPaid_Form_Item( $item_data->item_id ); |
|
472 | + foreach ($items as $item_data) { |
|
473 | + $item = new GetPaid_Form_Item($item_data->item_id); |
|
474 | 474 | |
475 | 475 | // Set item data. |
476 | - $item->item_tax = wpinv_sanitize_amount( $item_data->tax ); |
|
477 | - $item->item_discount = wpinv_sanitize_amount( $item_data->discount ); |
|
478 | - $item->set_name( $item_data->item_name ); |
|
479 | - $item->set_description( $item_data->item_description ); |
|
480 | - $item->set_price( $item_data->item_price ); |
|
481 | - $item->set_quantity( $item_data->quantity ); |
|
482 | - $item->set_item_meta( $item_data->meta ); |
|
483 | - |
|
484 | - $invoice->add_item( $item ); |
|
476 | + $item->item_tax = wpinv_sanitize_amount($item_data->tax); |
|
477 | + $item->item_discount = wpinv_sanitize_amount($item_data->discount); |
|
478 | + $item->set_name($item_data->item_name); |
|
479 | + $item->set_description($item_data->item_description); |
|
480 | + $item->set_price($item_data->item_price); |
|
481 | + $item->set_quantity($item_data->quantity); |
|
482 | + $item->set_item_meta($item_data->meta); |
|
483 | + |
|
484 | + $invoice->add_item($item); |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | } |
@@ -491,20 +491,20 @@ discard block |
||
491 | 491 | * |
492 | 492 | * @param WPInv_Invoice $invoice Invoice object. |
493 | 493 | */ |
494 | - public function save_items( $invoice ) { |
|
494 | + public function save_items($invoice) { |
|
495 | 495 | |
496 | 496 | // Delete previously existing items. |
497 | - $this->delete_items( $invoice ); |
|
497 | + $this->delete_items($invoice); |
|
498 | 498 | |
499 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
499 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
500 | 500 | |
501 | - foreach ( $invoice->get_cart_details() as $item_data ) { |
|
502 | - $item_data = array_map( 'maybe_serialize', $item_data ); |
|
503 | - $GLOBALS['wpdb']->insert( $table, $item_data ); |
|
501 | + foreach ($invoice->get_cart_details() as $item_data) { |
|
502 | + $item_data = array_map('maybe_serialize', $item_data); |
|
503 | + $GLOBALS['wpdb']->insert($table, $item_data); |
|
504 | 504 | } |
505 | 505 | |
506 | - wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' ); |
|
507 | - do_action( "getpaid_invoice_save_items", $invoice ); |
|
506 | + wp_cache_delete($invoice->get_id(), 'getpaid_invoice_cart_details'); |
|
507 | + do_action("getpaid_invoice_save_items", $invoice); |
|
508 | 508 | |
509 | 509 | } |
510 | 510 | |
@@ -513,9 +513,9 @@ discard block |
||
513 | 513 | * |
514 | 514 | * @param WPInv_Invoice $invoice Invoice object. |
515 | 515 | */ |
516 | - public function delete_items( $invoice ) { |
|
517 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
516 | + public function delete_items($invoice) { |
|
517 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items'; |
|
518 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -523,9 +523,9 @@ discard block |
||
523 | 523 | * |
524 | 524 | * @param WPInv_Invoice $invoice Invoice object. |
525 | 525 | */ |
526 | - public function delete_special_fields( $invoice ) { |
|
527 | - $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | - return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) ); |
|
526 | + public function delete_special_fields($invoice) { |
|
527 | + $table = $GLOBALS['wpdb']->prefix . 'getpaid_invoices'; |
|
528 | + return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->get_id())); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * |
9 | 9 | */ |
10 | 10 | |
11 | -if ( ! defined( 'ABSPATH' ) ) { |
|
11 | +if (!defined('ABSPATH')) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | * |
118 | 118 | * @param int|object|array $read ID to load from the DB (optional) or already queried data. |
119 | 119 | */ |
120 | - public function __construct( $read = 0 ) { |
|
121 | - $this->data = array_merge( $this->data, $this->extra_data ); |
|
120 | + public function __construct($read = 0) { |
|
121 | + $this->data = array_merge($this->data, $this->extra_data); |
|
122 | 122 | $this->default_data = $this->data; |
123 | 123 | } |
124 | 124 | |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | * @return array |
129 | 129 | */ |
130 | 130 | public function __sleep() { |
131 | - return array( 'id' ); |
|
131 | + return array('id'); |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | /** |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | * If the object no longer exists, remove the ID. |
138 | 138 | */ |
139 | 139 | public function __wakeup() { |
140 | - $this->__construct( absint( $this->id ) ); |
|
140 | + $this->__construct(absint($this->id)); |
|
141 | 141 | |
142 | - if ( ! empty( $this->last_error ) ) { |
|
143 | - $this->set_id( 0 ); |
|
142 | + if (!empty($this->last_error)) { |
|
143 | + $this->set_id(0); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | */ |
153 | 153 | public function __clone() { |
154 | 154 | $this->maybe_read_meta_data(); |
155 | - if ( ! empty( $this->meta_data ) ) { |
|
156 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
157 | - $this->meta_data[ $array_key ] = clone $meta; |
|
158 | - if ( ! empty( $meta->id ) ) { |
|
159 | - $this->meta_data[ $array_key ]->id = null; |
|
155 | + if (!empty($this->meta_data)) { |
|
156 | + foreach ($this->meta_data as $array_key => $meta) { |
|
157 | + $this->meta_data[$array_key] = clone $meta; |
|
158 | + if (!empty($meta->id)) { |
|
159 | + $this->meta_data[$array_key]->id = null; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | * @param string $context View or edit context. |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public function get_status( $context = 'view' ) { |
|
203 | - return $this->get_prop( 'status', $context ); |
|
202 | + public function get_status($context = 'view') { |
|
203 | + return $this->get_prop('status', $context); |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | /** |
@@ -210,10 +210,10 @@ discard block |
||
210 | 210 | * @param bool $force_delete Should the data be deleted permanently. |
211 | 211 | * @return bool result |
212 | 212 | */ |
213 | - public function delete( $force_delete = false ) { |
|
214 | - if ( $this->data_store && $this->get_id() ) { |
|
215 | - $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) ); |
|
216 | - $this->set_id( 0 ); |
|
213 | + public function delete($force_delete = false) { |
|
214 | + if ($this->data_store && $this->get_id()) { |
|
215 | + $this->data_store->delete($this, array('force_delete' => $force_delete)); |
|
216 | + $this->set_id(0); |
|
217 | 217 | return true; |
218 | 218 | } |
219 | 219 | return false; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return int |
227 | 227 | */ |
228 | 228 | public function save() { |
229 | - if ( ! $this->data_store ) { |
|
229 | + if (!$this->data_store) { |
|
230 | 230 | return $this->get_id(); |
231 | 231 | } |
232 | 232 | |
@@ -236,12 +236,12 @@ discard block |
||
236 | 236 | * @param GetPaid_Data $this The object being saved. |
237 | 237 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
238 | 238 | */ |
239 | - do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
239 | + do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
240 | 240 | |
241 | - if ( $this->get_id() ) { |
|
242 | - $this->data_store->update( $this ); |
|
241 | + if ($this->get_id()) { |
|
242 | + $this->data_store->update($this); |
|
243 | 243 | } else { |
244 | - $this->data_store->create( $this ); |
|
244 | + $this->data_store->create($this); |
|
245 | 245 | } |
246 | 246 | |
247 | 247 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | * @param GetPaid_Data $this The object being saved. |
251 | 251 | * @param GetPaid_Data_Store_WP $data_store The data store persisting the data. |
252 | 252 | */ |
253 | - do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store ); |
|
253 | + do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store); |
|
254 | 254 | |
255 | 255 | return $this->get_id(); |
256 | 256 | } |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @return string Data in JSON format. |
263 | 263 | */ |
264 | 264 | public function __toString() { |
265 | - return wp_json_encode( $this->get_data() ); |
|
265 | + return wp_json_encode($this->get_data()); |
|
266 | 266 | } |
267 | 267 | |
268 | 268 | /** |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | * @return array |
273 | 273 | */ |
274 | 274 | public function get_data() { |
275 | - return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) ); |
|
275 | + return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data())); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | /** |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | * @return array |
283 | 283 | */ |
284 | 284 | public function get_data_keys() { |
285 | - return array_keys( $this->data ); |
|
285 | + return array_keys($this->data); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | * @return array |
293 | 293 | */ |
294 | 294 | public function get_extra_data_keys() { |
295 | - return array_keys( $this->extra_data ); |
|
295 | + return array_keys($this->extra_data); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | * @param mixed $meta Meta value to check. |
303 | 303 | * @return bool |
304 | 304 | */ |
305 | - protected function filter_null_meta( $meta ) { |
|
306 | - return ! is_null( $meta->value ); |
|
305 | + protected function filter_null_meta($meta) { |
|
306 | + return !is_null($meta->value); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | /** |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | */ |
315 | 315 | public function get_meta_data() { |
316 | 316 | $this->maybe_read_meta_data(); |
317 | - return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) ); |
|
317 | + return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta'))); |
|
318 | 318 | } |
319 | 319 | |
320 | 320 | /** |
@@ -324,21 +324,21 @@ discard block |
||
324 | 324 | * @param string $key Key to check. |
325 | 325 | * @return bool true if it's an internal key, false otherwise |
326 | 326 | */ |
327 | - protected function is_internal_meta_key( $key ) { |
|
328 | - $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true ); |
|
327 | + protected function is_internal_meta_key($key) { |
|
328 | + $internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true); |
|
329 | 329 | |
330 | - if ( ! $internal_meta_key ) { |
|
330 | + if (!$internal_meta_key) { |
|
331 | 331 | return false; |
332 | 332 | } |
333 | 333 | |
334 | - $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) ); |
|
334 | + $has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key)); |
|
335 | 335 | |
336 | - if ( ! $has_setter_or_getter ) { |
|
336 | + if (!$has_setter_or_getter) { |
|
337 | 337 | return false; |
338 | 338 | } |
339 | 339 | |
340 | 340 | /* translators: %s: $key Key to check */ |
341 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
341 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
342 | 342 | |
343 | 343 | return true; |
344 | 344 | } |
@@ -352,20 +352,20 @@ discard block |
||
352 | 352 | * @access public |
353 | 353 | * |
354 | 354 | */ |
355 | - public function __set( $key, $value ) { |
|
355 | + public function __set($key, $value) { |
|
356 | 356 | |
357 | - if ( 'id' == strtolower( $key ) ) { |
|
358 | - return $this->set_id( $value ); |
|
357 | + if ('id' == strtolower($key)) { |
|
358 | + return $this->set_id($value); |
|
359 | 359 | } |
360 | 360 | |
361 | - if ( method_exists( $this, "set_$key") ) { |
|
361 | + if (method_exists($this, "set_$key")) { |
|
362 | 362 | |
363 | 363 | /* translators: %s: $key Key to set */ |
364 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
364 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
365 | 365 | |
366 | - call_user_func( array( $this, "set_$key" ), $value ); |
|
366 | + call_user_func(array($this, "set_$key"), $value); |
|
367 | 367 | } else { |
368 | - $this->set_prop( $key, $value ); |
|
368 | + $this->set_prop($key, $value); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | } |
@@ -373,25 +373,25 @@ discard block |
||
373 | 373 | /** |
374 | 374 | * Margic method for retrieving a property. |
375 | 375 | */ |
376 | - public function __get( $key ) { |
|
376 | + public function __get($key) { |
|
377 | 377 | |
378 | 378 | // Check if we have a helper method for that. |
379 | - if ( method_exists( $this, 'get_' . $key ) ) { |
|
379 | + if (method_exists($this, 'get_' . $key)) { |
|
380 | 380 | |
381 | - if ( 'post_type' != $key ) { |
|
381 | + if ('post_type' != $key) { |
|
382 | 382 | /* translators: %s: $key Key to set */ |
383 | - getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' ); |
|
383 | + getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19'); |
|
384 | 384 | } |
385 | 385 | |
386 | - return call_user_func( array( $this, 'get_' . $key ) ); |
|
386 | + return call_user_func(array($this, 'get_' . $key)); |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | // Check if the key is in the associated $post object. |
390 | - if ( ! empty( $this->post ) && isset( $this->post->$key ) ) { |
|
390 | + if (!empty($this->post) && isset($this->post->$key)) { |
|
391 | 391 | return $this->post->$key; |
392 | 392 | } |
393 | 393 | |
394 | - return $this->get_prop( $key ); |
|
394 | + return $this->get_prop($key); |
|
395 | 395 | |
396 | 396 | } |
397 | 397 | |
@@ -404,15 +404,15 @@ discard block |
||
404 | 404 | * @param string $context What the value is for. Valid values are view and edit. |
405 | 405 | * @return mixed |
406 | 406 | */ |
407 | - public function get_meta( $key = '', $single = true, $context = 'view' ) { |
|
407 | + public function get_meta($key = '', $single = true, $context = 'view') { |
|
408 | 408 | |
409 | 409 | // Check if this is an internal meta key. |
410 | - $_key = str_replace( '_wpinv', '', $key ); |
|
411 | - $_key = str_replace( 'wpinv', '', $_key ); |
|
412 | - if ( $this->is_internal_meta_key( $_key ) ) { |
|
410 | + $_key = str_replace('_wpinv', '', $key); |
|
411 | + $_key = str_replace('wpinv', '', $_key); |
|
412 | + if ($this->is_internal_meta_key($_key)) { |
|
413 | 413 | $function = 'get_' . $_key; |
414 | 414 | |
415 | - if ( is_callable( array( $this, $function ) ) ) { |
|
415 | + if (is_callable(array($this, $function))) { |
|
416 | 416 | return $this->{$function}(); |
417 | 417 | } |
418 | 418 | } |
@@ -420,20 +420,20 @@ discard block |
||
420 | 420 | // Read the meta data if not yet read. |
421 | 421 | $this->maybe_read_meta_data(); |
422 | 422 | $meta_data = $this->get_meta_data(); |
423 | - $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true ); |
|
423 | + $array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true); |
|
424 | 424 | $value = $single ? '' : array(); |
425 | 425 | |
426 | - if ( ! empty( $array_keys ) ) { |
|
426 | + if (!empty($array_keys)) { |
|
427 | 427 | // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()). |
428 | - if ( $single ) { |
|
429 | - $value = $meta_data[ current( $array_keys ) ]->value; |
|
428 | + if ($single) { |
|
429 | + $value = $meta_data[current($array_keys)]->value; |
|
430 | 430 | } else { |
431 | - $value = array_intersect_key( $meta_data, array_flip( $array_keys ) ); |
|
431 | + $value = array_intersect_key($meta_data, array_flip($array_keys)); |
|
432 | 432 | } |
433 | 433 | } |
434 | 434 | |
435 | - if ( 'view' === $context ) { |
|
436 | - $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this ); |
|
435 | + if ('view' === $context) { |
|
436 | + $value = apply_filters($this->get_hook_prefix() . $key, $value, $this); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | return $value; |
@@ -446,10 +446,10 @@ discard block |
||
446 | 446 | * @param string $key Meta Key. |
447 | 447 | * @return boolean |
448 | 448 | */ |
449 | - public function meta_exists( $key = '' ) { |
|
449 | + public function meta_exists($key = '') { |
|
450 | 450 | $this->maybe_read_meta_data(); |
451 | - $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' ); |
|
452 | - return in_array( $key, $array_keys, true ); |
|
451 | + $array_keys = wp_list_pluck($this->get_meta_data(), 'key'); |
|
452 | + return in_array($key, $array_keys, true); |
|
453 | 453 | } |
454 | 454 | |
455 | 455 | /** |
@@ -458,12 +458,12 @@ discard block |
||
458 | 458 | * @since 1.0.19 |
459 | 459 | * @param array $data Key/Value pairs. |
460 | 460 | */ |
461 | - public function set_meta_data( $data ) { |
|
462 | - if ( ! empty( $data ) && is_array( $data ) ) { |
|
461 | + public function set_meta_data($data) { |
|
462 | + if (!empty($data) && is_array($data)) { |
|
463 | 463 | $this->maybe_read_meta_data(); |
464 | - foreach ( $data as $meta ) { |
|
464 | + foreach ($data as $meta) { |
|
465 | 465 | $meta = (array) $meta; |
466 | - if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) { |
|
466 | + if (isset($meta['key'], $meta['value'], $meta['id'])) { |
|
467 | 467 | $this->meta_data[] = new GetPaid_Meta_Data( |
468 | 468 | array( |
469 | 469 | 'id' => $meta['id'], |
@@ -485,18 +485,18 @@ discard block |
||
485 | 485 | * @param string|array $value Meta value. |
486 | 486 | * @param bool $unique Should this be a unique key?. |
487 | 487 | */ |
488 | - public function add_meta_data( $key, $value, $unique = false ) { |
|
489 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
488 | + public function add_meta_data($key, $value, $unique = false) { |
|
489 | + if ($this->is_internal_meta_key($key)) { |
|
490 | 490 | $function = 'set_' . $key; |
491 | 491 | |
492 | - if ( is_callable( array( $this, $function ) ) ) { |
|
493 | - return $this->{$function}( $value ); |
|
492 | + if (is_callable(array($this, $function))) { |
|
493 | + return $this->{$function}($value); |
|
494 | 494 | } |
495 | 495 | } |
496 | 496 | |
497 | 497 | $this->maybe_read_meta_data(); |
498 | - if ( $unique ) { |
|
499 | - $this->delete_meta_data( $key ); |
|
498 | + if ($unique) { |
|
499 | + $this->delete_meta_data($key); |
|
500 | 500 | } |
501 | 501 | $this->meta_data[] = new GetPaid_Meta_Data( |
502 | 502 | array( |
@@ -515,12 +515,12 @@ discard block |
||
515 | 515 | * @param string|array $value Meta value. |
516 | 516 | * @param int $meta_id Meta ID. |
517 | 517 | */ |
518 | - public function update_meta_data( $key, $value, $meta_id = 0 ) { |
|
519 | - if ( $this->is_internal_meta_key( $key ) ) { |
|
518 | + public function update_meta_data($key, $value, $meta_id = 0) { |
|
519 | + if ($this->is_internal_meta_key($key)) { |
|
520 | 520 | $function = 'set_' . $key; |
521 | 521 | |
522 | - if ( is_callable( array( $this, $function ) ) ) { |
|
523 | - return $this->{$function}( $value ); |
|
522 | + if (is_callable(array($this, $function))) { |
|
523 | + return $this->{$function}($value); |
|
524 | 524 | } |
525 | 525 | } |
526 | 526 | |
@@ -528,33 +528,33 @@ discard block |
||
528 | 528 | |
529 | 529 | $array_key = false; |
530 | 530 | |
531 | - if ( $meta_id ) { |
|
532 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true ); |
|
533 | - $array_key = $array_keys ? current( $array_keys ) : false; |
|
531 | + if ($meta_id) { |
|
532 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true); |
|
533 | + $array_key = $array_keys ? current($array_keys) : false; |
|
534 | 534 | } else { |
535 | 535 | // Find matches by key. |
536 | 536 | $matches = array(); |
537 | - foreach ( $this->meta_data as $meta_data_array_key => $meta ) { |
|
538 | - if ( $meta->key === $key ) { |
|
537 | + foreach ($this->meta_data as $meta_data_array_key => $meta) { |
|
538 | + if ($meta->key === $key) { |
|
539 | 539 | $matches[] = $meta_data_array_key; |
540 | 540 | } |
541 | 541 | } |
542 | 542 | |
543 | - if ( ! empty( $matches ) ) { |
|
543 | + if (!empty($matches)) { |
|
544 | 544 | // Set matches to null so only one key gets the new value. |
545 | - foreach ( $matches as $meta_data_array_key ) { |
|
546 | - $this->meta_data[ $meta_data_array_key ]->value = null; |
|
545 | + foreach ($matches as $meta_data_array_key) { |
|
546 | + $this->meta_data[$meta_data_array_key]->value = null; |
|
547 | 547 | } |
548 | - $array_key = current( $matches ); |
|
548 | + $array_key = current($matches); |
|
549 | 549 | } |
550 | 550 | } |
551 | 551 | |
552 | - if ( false !== $array_key ) { |
|
553 | - $meta = $this->meta_data[ $array_key ]; |
|
552 | + if (false !== $array_key) { |
|
553 | + $meta = $this->meta_data[$array_key]; |
|
554 | 554 | $meta->key = $key; |
555 | 555 | $meta->value = $value; |
556 | 556 | } else { |
557 | - $this->add_meta_data( $key, $value, true ); |
|
557 | + $this->add_meta_data($key, $value, true); |
|
558 | 558 | } |
559 | 559 | } |
560 | 560 | |
@@ -564,13 +564,13 @@ discard block |
||
564 | 564 | * @since 1.0.19 |
565 | 565 | * @param string $key Meta key. |
566 | 566 | */ |
567 | - public function delete_meta_data( $key ) { |
|
567 | + public function delete_meta_data($key) { |
|
568 | 568 | $this->maybe_read_meta_data(); |
569 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true ); |
|
569 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true); |
|
570 | 570 | |
571 | - if ( $array_keys ) { |
|
572 | - foreach ( $array_keys as $array_key ) { |
|
573 | - $this->meta_data[ $array_key ]->value = null; |
|
571 | + if ($array_keys) { |
|
572 | + foreach ($array_keys as $array_key) { |
|
573 | + $this->meta_data[$array_key]->value = null; |
|
574 | 574 | } |
575 | 575 | } |
576 | 576 | } |
@@ -581,13 +581,13 @@ discard block |
||
581 | 581 | * @since 1.0.19 |
582 | 582 | * @param int $mid Meta ID. |
583 | 583 | */ |
584 | - public function delete_meta_data_by_mid( $mid ) { |
|
584 | + public function delete_meta_data_by_mid($mid) { |
|
585 | 585 | $this->maybe_read_meta_data(); |
586 | - $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true ); |
|
586 | + $array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true); |
|
587 | 587 | |
588 | - if ( $array_keys ) { |
|
589 | - foreach ( $array_keys as $array_key ) { |
|
590 | - $this->meta_data[ $array_key ]->value = null; |
|
588 | + if ($array_keys) { |
|
589 | + foreach ($array_keys as $array_key) { |
|
590 | + $this->meta_data[$array_key]->value = null; |
|
591 | 591 | } |
592 | 592 | } |
593 | 593 | } |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | * @since 1.0.19 |
599 | 599 | */ |
600 | 600 | protected function maybe_read_meta_data() { |
601 | - if ( is_null( $this->meta_data ) ) { |
|
601 | + if (is_null($this->meta_data)) { |
|
602 | 602 | $this->read_meta_data(); |
603 | 603 | } |
604 | 604 | } |
@@ -610,42 +610,42 @@ discard block |
||
610 | 610 | * @since 1.0.19 |
611 | 611 | * @param bool $force_read True to force a new DB read (and update cache). |
612 | 612 | */ |
613 | - public function read_meta_data( $force_read = false ) { |
|
613 | + public function read_meta_data($force_read = false) { |
|
614 | 614 | |
615 | 615 | // Reset meta data. |
616 | 616 | $this->meta_data = array(); |
617 | 617 | |
618 | 618 | // Maybe abort early. |
619 | - if ( ! $this->get_id() || ! $this->data_store ) { |
|
619 | + if (!$this->get_id() || !$this->data_store) { |
|
620 | 620 | return; |
621 | 621 | } |
622 | 622 | |
623 | 623 | // Only read from cache if the cache key is set. |
624 | 624 | $cache_key = null; |
625 | - if ( ! $force_read && ! empty( $this->cache_group ) ) { |
|
626 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
627 | - $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group ); |
|
625 | + if (!$force_read && !empty($this->cache_group)) { |
|
626 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
627 | + $raw_meta_data = wp_cache_get($cache_key, $this->cache_group); |
|
628 | 628 | } |
629 | 629 | |
630 | 630 | // Should we force read? |
631 | - if ( empty( $raw_meta_data ) ) { |
|
632 | - $raw_meta_data = $this->data_store->read_meta( $this ); |
|
631 | + if (empty($raw_meta_data)) { |
|
632 | + $raw_meta_data = $this->data_store->read_meta($this); |
|
633 | 633 | |
634 | - if ( ! empty( $cache_key ) ) { |
|
635 | - wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group ); |
|
634 | + if (!empty($cache_key)) { |
|
635 | + wp_cache_set($cache_key, $raw_meta_data, $this->cache_group); |
|
636 | 636 | } |
637 | 637 | |
638 | 638 | } |
639 | 639 | |
640 | 640 | // Set meta data. |
641 | - if ( is_array( $raw_meta_data ) ) { |
|
641 | + if (is_array($raw_meta_data)) { |
|
642 | 642 | |
643 | - foreach ( $raw_meta_data as $meta ) { |
|
643 | + foreach ($raw_meta_data as $meta) { |
|
644 | 644 | $this->meta_data[] = new GetPaid_Meta_Data( |
645 | 645 | array( |
646 | 646 | 'id' => (int) $meta->meta_id, |
647 | 647 | 'key' => $meta->meta_key, |
648 | - 'value' => maybe_unserialize( $meta->meta_value ), |
|
648 | + 'value' => maybe_unserialize($meta->meta_value), |
|
649 | 649 | ) |
650 | 650 | ); |
651 | 651 | } |
@@ -660,28 +660,28 @@ discard block |
||
660 | 660 | * @since 1.0.19 |
661 | 661 | */ |
662 | 662 | public function save_meta_data() { |
663 | - if ( ! $this->data_store || is_null( $this->meta_data ) ) { |
|
663 | + if (!$this->data_store || is_null($this->meta_data)) { |
|
664 | 664 | return; |
665 | 665 | } |
666 | - foreach ( $this->meta_data as $array_key => $meta ) { |
|
667 | - if ( is_null( $meta->value ) ) { |
|
668 | - if ( ! empty( $meta->id ) ) { |
|
669 | - $this->data_store->delete_meta( $this, $meta ); |
|
670 | - unset( $this->meta_data[ $array_key ] ); |
|
666 | + foreach ($this->meta_data as $array_key => $meta) { |
|
667 | + if (is_null($meta->value)) { |
|
668 | + if (!empty($meta->id)) { |
|
669 | + $this->data_store->delete_meta($this, $meta); |
|
670 | + unset($this->meta_data[$array_key]); |
|
671 | 671 | } |
672 | - } elseif ( empty( $meta->id ) ) { |
|
673 | - $meta->id = $this->data_store->add_meta( $this, $meta ); |
|
672 | + } elseif (empty($meta->id)) { |
|
673 | + $meta->id = $this->data_store->add_meta($this, $meta); |
|
674 | 674 | $meta->apply_changes(); |
675 | 675 | } else { |
676 | - if ( $meta->get_changes() ) { |
|
677 | - $this->data_store->update_meta( $this, $meta ); |
|
676 | + if ($meta->get_changes()) { |
|
677 | + $this->data_store->update_meta($this, $meta); |
|
678 | 678 | $meta->apply_changes(); |
679 | 679 | } |
680 | 680 | } |
681 | 681 | } |
682 | - if ( ! empty( $this->cache_group ) ) { |
|
683 | - $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id(); |
|
684 | - wp_cache_delete( $cache_key, $this->cache_group ); |
|
682 | + if (!empty($this->cache_group)) { |
|
683 | + $cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id(); |
|
684 | + wp_cache_delete($cache_key, $this->cache_group); |
|
685 | 685 | } |
686 | 686 | } |
687 | 687 | |
@@ -691,8 +691,8 @@ discard block |
||
691 | 691 | * @since 1.0.19 |
692 | 692 | * @param int $id ID. |
693 | 693 | */ |
694 | - public function set_id( $id ) { |
|
695 | - $this->id = absint( $id ); |
|
694 | + public function set_id($id) { |
|
695 | + $this->id = absint($id); |
|
696 | 696 | } |
697 | 697 | |
698 | 698 | /** |
@@ -702,10 +702,10 @@ discard block |
||
702 | 702 | * @param string $status New status. |
703 | 703 | * @return array details of change. |
704 | 704 | */ |
705 | - public function set_status( $status ) { |
|
705 | + public function set_status($status) { |
|
706 | 706 | $old_status = $this->get_status(); |
707 | 707 | |
708 | - $this->set_prop( 'status', $status ); |
|
708 | + $this->set_prop('status', $status); |
|
709 | 709 | |
710 | 710 | return array( |
711 | 711 | 'from' => $old_status, |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | public function set_defaults() { |
722 | 722 | $this->data = $this->default_data; |
723 | 723 | $this->changes = array(); |
724 | - $this->set_object_read( false ); |
|
724 | + $this->set_object_read(false); |
|
725 | 725 | } |
726 | 726 | |
727 | 727 | /** |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @since 1.0.19 |
731 | 731 | * @param boolean $read Should read?. |
732 | 732 | */ |
733 | - public function set_object_read( $read = true ) { |
|
733 | + public function set_object_read($read = true) { |
|
734 | 734 | $this->object_read = (bool) $read; |
735 | 735 | } |
736 | 736 | |
@@ -755,32 +755,32 @@ discard block |
||
755 | 755 | * |
756 | 756 | * @return bool|WP_Error |
757 | 757 | */ |
758 | - public function set_props( $props, $context = 'set' ) { |
|
758 | + public function set_props($props, $context = 'set') { |
|
759 | 759 | $errors = false; |
760 | 760 | |
761 | - foreach ( $props as $prop => $value ) { |
|
761 | + foreach ($props as $prop => $value) { |
|
762 | 762 | try { |
763 | 763 | /** |
764 | 764 | * Checks if the prop being set is allowed, and the value is not null. |
765 | 765 | */ |
766 | - if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) { |
|
766 | + if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) { |
|
767 | 767 | continue; |
768 | 768 | } |
769 | 769 | $setter = "set_$prop"; |
770 | 770 | |
771 | - if ( is_callable( array( $this, $setter ) ) ) { |
|
772 | - $this->{$setter}( $value ); |
|
771 | + if (is_callable(array($this, $setter))) { |
|
772 | + $this->{$setter}($value); |
|
773 | 773 | } |
774 | - } catch ( Exception $e ) { |
|
775 | - if ( ! $errors ) { |
|
774 | + } catch (Exception $e) { |
|
775 | + if (!$errors) { |
|
776 | 776 | $errors = new WP_Error(); |
777 | 777 | } |
778 | - $errors->add( $e->getCode(), $e->getMessage() ); |
|
778 | + $errors->add($e->getCode(), $e->getMessage()); |
|
779 | 779 | $this->last_error = $e->getMessage(); |
780 | 780 | } |
781 | 781 | } |
782 | 782 | |
783 | - return $errors && count( $errors->get_error_codes() ) ? $errors : true; |
|
783 | + return $errors && count($errors->get_error_codes()) ? $errors : true; |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | /** |
@@ -793,14 +793,14 @@ discard block |
||
793 | 793 | * @param string $prop Name of prop to set. |
794 | 794 | * @param mixed $value Value of the prop. |
795 | 795 | */ |
796 | - protected function set_prop( $prop, $value ) { |
|
797 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
798 | - if ( true === $this->object_read ) { |
|
799 | - if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) { |
|
800 | - $this->changes[ $prop ] = $value; |
|
796 | + protected function set_prop($prop, $value) { |
|
797 | + if (array_key_exists($prop, $this->data)) { |
|
798 | + if (true === $this->object_read) { |
|
799 | + if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) { |
|
800 | + $this->changes[$prop] = $value; |
|
801 | 801 | } |
802 | 802 | } else { |
803 | - $this->data[ $prop ] = $value; |
|
803 | + $this->data[$prop] = $value; |
|
804 | 804 | } |
805 | 805 | } |
806 | 806 | } |
@@ -821,7 +821,7 @@ discard block |
||
821 | 821 | * @since 1.0.19 |
822 | 822 | */ |
823 | 823 | public function apply_changes() { |
824 | - $this->data = array_replace_recursive( $this->data, $this->changes ); |
|
824 | + $this->data = array_replace_recursive($this->data, $this->changes); |
|
825 | 825 | $this->changes = array(); |
826 | 826 | } |
827 | 827 | |
@@ -846,14 +846,14 @@ discard block |
||
846 | 846 | * @param string $context What the value is for. Valid values are view and edit. |
847 | 847 | * @return mixed |
848 | 848 | */ |
849 | - protected function get_prop( $prop, $context = 'view' ) { |
|
849 | + protected function get_prop($prop, $context = 'view') { |
|
850 | 850 | $value = null; |
851 | 851 | |
852 | - if ( array_key_exists( $prop, $this->data ) ) { |
|
853 | - $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ]; |
|
852 | + if (array_key_exists($prop, $this->data)) { |
|
853 | + $value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop]; |
|
854 | 854 | |
855 | - if ( 'view' === $context ) { |
|
856 | - $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this ); |
|
855 | + if ('view' === $context) { |
|
856 | + $value = apply_filters($this->get_hook_prefix() . $prop, $value, $this); |
|
857 | 857 | } |
858 | 858 | } |
859 | 859 | |
@@ -867,13 +867,13 @@ discard block |
||
867 | 867 | * @param string $prop Name of prop to set. |
868 | 868 | * @param string|integer $value Value of the prop. |
869 | 869 | */ |
870 | - protected function set_date_prop( $prop, $value ) { |
|
870 | + protected function set_date_prop($prop, $value) { |
|
871 | 871 | |
872 | - if ( empty( $value ) ) { |
|
873 | - $this->set_prop( $prop, null ); |
|
872 | + if (empty($value)) { |
|
873 | + $this->set_prop($prop, null); |
|
874 | 874 | return; |
875 | 875 | } |
876 | - $this->set_prop( $prop, $value ); |
|
876 | + $this->set_prop($prop, $value); |
|
877 | 877 | |
878 | 878 | } |
879 | 879 | |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | * @param string $code Error code. |
885 | 885 | * @param string $message Error message. |
886 | 886 | */ |
887 | - protected function error( $code, $message ) { |
|
887 | + protected function error($code, $message) { |
|
888 | 888 | $this->last_error = $message; |
889 | 889 | } |
890 | 890 | |
@@ -896,7 +896,7 @@ discard block |
||
896 | 896 | */ |
897 | 897 | public function exists() { |
898 | 898 | $id = $this->get_id(); |
899 | - return ! empty( $id ); |
|
899 | + return !empty($id); |
|
900 | 900 | } |
901 | 901 | |
902 | 902 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * GetPaid_Subscription_Data_Store class file. |
5 | 5 | * |
6 | 6 | */ |
7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
7 | +if (!defined('ABSPATH')) { |
|
8 | 8 | exit; |
9 | 9 | } |
10 | 10 | |
@@ -50,29 +50,29 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param WPInv_Subscription $subscription Subscription object. |
52 | 52 | */ |
53 | - public function create( &$subscription ) { |
|
53 | + public function create(&$subscription) { |
|
54 | 54 | global $wpdb; |
55 | 55 | |
56 | 56 | $values = array(); |
57 | 57 | $formats = array(); |
58 | 58 | |
59 | 59 | $fields = $this->database_fields_to_data_type; |
60 | - unset( $fields['id'] ); |
|
60 | + unset($fields['id']); |
|
61 | 61 | |
62 | - foreach ( $fields as $key => $format ) { |
|
62 | + foreach ($fields as $key => $format) { |
|
63 | 63 | $method = "get_$key"; |
64 | - $values[$key] = $subscription->$method( 'edit' ); |
|
64 | + $values[$key] = $subscription->$method('edit'); |
|
65 | 65 | $formats[] = $format; |
66 | 66 | } |
67 | 67 | |
68 | - $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $values, $formats ); |
|
68 | + $result = $wpdb->insert($wpdb->prefix . 'wpinv_subscriptions', $values, $formats); |
|
69 | 69 | |
70 | - if ( $result ) { |
|
71 | - $subscription->set_id( $wpdb->insert_id ); |
|
70 | + if ($result) { |
|
71 | + $subscription->set_id($wpdb->insert_id); |
|
72 | 72 | $subscription->apply_changes(); |
73 | 73 | $subscription->clear_cache(); |
74 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id() ); |
|
75 | - do_action( 'getpaid_new_subscription', $subscription ); |
|
74 | + update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id', $subscription->get_id()); |
|
75 | + do_action('getpaid_new_subscription', $subscription); |
|
76 | 76 | return true; |
77 | 77 | } |
78 | 78 | |
@@ -85,22 +85,22 @@ discard block |
||
85 | 85 | * @param WPInv_Subscription $subscription Subscription object. |
86 | 86 | * |
87 | 87 | */ |
88 | - public function read( &$subscription ) { |
|
88 | + public function read(&$subscription) { |
|
89 | 89 | global $wpdb; |
90 | 90 | |
91 | 91 | $subscription->set_defaults(); |
92 | 92 | |
93 | - if ( ! $subscription->get_id() ) { |
|
94 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
95 | - $subscription->set_id( 0 ); |
|
93 | + if (!$subscription->get_id()) { |
|
94 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
95 | + $subscription->set_id(0); |
|
96 | 96 | return false; |
97 | 97 | } |
98 | 98 | |
99 | 99 | // Maybe retrieve from the cache. |
100 | - $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' ); |
|
100 | + $raw_subscription = wp_cache_get($subscription->get_id(), 'getpaid_subscriptions'); |
|
101 | 101 | |
102 | 102 | // If not found, retrieve from the db. |
103 | - if ( false === $raw_subscription ) { |
|
103 | + if (false === $raw_subscription) { |
|
104 | 104 | |
105 | 105 | $raw_subscription = $wpdb->get_row( |
106 | 106 | $wpdb->prepare( |
@@ -110,22 +110,22 @@ discard block |
||
110 | 110 | ); |
111 | 111 | |
112 | 112 | // Update the cache with our data |
113 | - wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' ); |
|
113 | + wp_cache_set($subscription->get_id(), $raw_subscription, 'getpaid_subscriptions'); |
|
114 | 114 | |
115 | 115 | } |
116 | 116 | |
117 | - if ( ! $raw_subscription ) { |
|
118 | - $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' ); |
|
117 | + if (!$raw_subscription) { |
|
118 | + $subscription->last_error = __('Invalid subscription ID.', 'invoicing'); |
|
119 | 119 | return false; |
120 | 120 | } |
121 | 121 | |
122 | - foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) { |
|
123 | - $method = "set_$key"; |
|
124 | - $subscription->$method( $raw_subscription->$key ); |
|
122 | + foreach (array_keys($this->database_fields_to_data_type) as $key) { |
|
123 | + $method = "set_$key"; |
|
124 | + $subscription->$method($raw_subscription->$key); |
|
125 | 125 | } |
126 | 126 | |
127 | - $subscription->set_object_read( true ); |
|
128 | - do_action( 'getpaid_read_subscription', $subscription ); |
|
127 | + $subscription->set_object_read(true); |
|
128 | + do_action('getpaid_read_subscription', $subscription); |
|
129 | 129 | |
130 | 130 | } |
131 | 131 | |
@@ -134,22 +134,22 @@ discard block |
||
134 | 134 | * |
135 | 135 | * @param WPInv_Subscription $subscription Subscription object. |
136 | 136 | */ |
137 | - public function update( &$subscription ) { |
|
137 | + public function update(&$subscription) { |
|
138 | 138 | global $wpdb; |
139 | 139 | |
140 | 140 | $changes = $subscription->get_changes(); |
141 | 141 | $values = array(); |
142 | 142 | $format = array(); |
143 | 143 | |
144 | - foreach ( $this->database_fields_to_data_type as $key => $format ) { |
|
145 | - if ( array_key_exists( $key, $changes ) ) { |
|
144 | + foreach ($this->database_fields_to_data_type as $key => $format) { |
|
145 | + if (array_key_exists($key, $changes)) { |
|
146 | 146 | $method = "get_$key"; |
147 | - $values[$key] = $subscription->$method( 'edit' ); |
|
147 | + $values[$key] = $subscription->$method('edit'); |
|
148 | 148 | $formats[] = $format; |
149 | 149 | } |
150 | 150 | } |
151 | 151 | |
152 | - if ( empty( $values ) ) { |
|
152 | + if (empty($values)) { |
|
153 | 153 | return; |
154 | 154 | } |
155 | 155 | |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | // Delete cache. |
170 | 170 | $subscription->clear_cache(); |
171 | 171 | |
172 | - update_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id() ); |
|
172 | + update_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id', $subscription->get_profile_id()); |
|
173 | 173 | |
174 | 174 | // Fire a hook. |
175 | - do_action( 'getpaid_update_subscription', $subscription ); |
|
175 | + do_action('getpaid_update_subscription', $subscription); |
|
176 | 176 | |
177 | 177 | } |
178 | 178 | |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | * |
182 | 182 | * @param WPInv_Subscription $subscription |
183 | 183 | */ |
184 | - public function delete( &$subscription ) { |
|
184 | + public function delete(&$subscription) { |
|
185 | 185 | global $wpdb; |
186 | 186 | |
187 | 187 | $wpdb->query( |
@@ -192,16 +192,16 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | |
195 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id' ); |
|
196 | - delete_post_meta( $subscription->get_parent_invoice_id(), '_wpinv_subscription_id' ); |
|
195 | + delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscr_profile_id'); |
|
196 | + delete_post_meta($subscription->get_parent_invoice_id(), '_wpinv_subscription_id'); |
|
197 | 197 | |
198 | 198 | // Delete cache. |
199 | 199 | $subscription->clear_cache(); |
200 | 200 | |
201 | 201 | // Fire a hook. |
202 | - do_action( 'getpaid_delete_subscription', $subscription ); |
|
202 | + do_action('getpaid_delete_subscription', $subscription); |
|
203 | 203 | |
204 | - $subscription->set_id( 0 ); |
|
204 | + $subscription->set_id(0); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /* |
@@ -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 | } |
@@ -7,52 +7,52 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | -do_action( 'getpaid_before_invoice_line_item', $invoice, $item ); |
|
12 | +do_action('getpaid_before_invoice_line_item', $invoice, $item); |
|
13 | 13 | |
14 | 14 | ?> |
15 | 15 | |
16 | -<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class( $item->get_type() ); ?>'> |
|
16 | +<div class='getpaid-invoice-item item-<?php echo (int) $item->get_id(); ?> item-type-<?php echo sanitize_html_class($item->get_type()); ?>'> |
|
17 | 17 | |
18 | 18 | <div class="form-row"> |
19 | 19 | |
20 | - <?php foreach ( array_keys( $columns ) as $column ): ?> |
|
20 | + <?php foreach (array_keys($columns) as $column): ?> |
|
21 | 21 | |
22 | - <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class( $column ); ?>"> |
|
22 | + <div class="<?php echo 'name' == $column ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-invoice-item-<?php echo sanitize_html_class($column); ?>"> |
|
23 | 23 | |
24 | 24 | <?php |
25 | 25 | |
26 | 26 | // Fires before printing a line item column. |
27 | - do_action( "getpaid_invoice_line_item_before_$column", $item, $invoice ); |
|
27 | + do_action("getpaid_invoice_line_item_before_$column", $item, $invoice); |
|
28 | 28 | |
29 | 29 | // Item name. |
30 | - if ( 'name' == $column ) { |
|
30 | + if ('name' == $column) { |
|
31 | 31 | |
32 | 32 | // Display the name. |
33 | - echo '<div class="mb-1">' . sanitize_text_field( $item->get_name() ) . '</div>'; |
|
33 | + echo '<div class="mb-1">' . sanitize_text_field($item->get_name()) . '</div>'; |
|
34 | 34 | |
35 | 35 | // And an optional description. |
36 | 36 | $description = $item->get_description(); |
37 | 37 | |
38 | - if ( ! empty( $description ) ) { |
|
39 | - $description = wp_kses_post( $description ); |
|
38 | + if (!empty($description)) { |
|
39 | + $description = wp_kses_post($description); |
|
40 | 40 | echo "<small class='form-text text-muted pr-2 m-0'>$description</small>"; |
41 | 41 | } |
42 | 42 | |
43 | - $actions = apply_filters( 'getpaid-invoice-page-line-item-actions', array(), $item, $invoice ); |
|
43 | + $actions = apply_filters('getpaid-invoice-page-line-item-actions', array(), $item, $invoice); |
|
44 | 44 | |
45 | - if ( ! empty( $actions ) ) { |
|
45 | + if (!empty($actions)) { |
|
46 | 46 | |
47 | - $sanitized = array(); |
|
48 | - foreach ( $actions as $key => $action ) { |
|
49 | - $key = sanitize_html_class( $key ); |
|
50 | - $action = wp_kses_post( $action ); |
|
47 | + $sanitized = array(); |
|
48 | + foreach ($actions as $key => $action) { |
|
49 | + $key = sanitize_html_class($key); |
|
50 | + $action = wp_kses_post($action); |
|
51 | 51 | $sanitized[] = "<span class='$key'>$action</span>"; |
52 | 52 | } |
53 | 53 | |
54 | 54 | echo "<small class='form-text getpaid-line-item-actions'>"; |
55 | - echo implode( ' | ', $sanitized ); |
|
55 | + echo implode(' | ', $sanitized); |
|
56 | 56 | echo '</small>'; |
57 | 57 | |
58 | 58 | } |
@@ -60,32 +60,32 @@ discard block |
||
60 | 60 | } |
61 | 61 | |
62 | 62 | // Item price. |
63 | - if ( 'price' == $column ) { |
|
63 | + if ('price' == $column) { |
|
64 | 64 | |
65 | 65 | // Display the item price (or recurring price if this is a renewal invoice) |
66 | - if ( $invoice->is_recurring() && $invoice->is_renewal() ) { |
|
67 | - echo wpinv_price( wpinv_format_amount( $item->get_price() ), $invoice->get_currency() ); |
|
66 | + if ($invoice->is_recurring() && $invoice->is_renewal()) { |
|
67 | + echo wpinv_price(wpinv_format_amount($item->get_price()), $invoice->get_currency()); |
|
68 | 68 | } else { |
69 | - echo wpinv_price( wpinv_format_amount( $item->get_initial_price() ), $invoice->get_currency() ); |
|
69 | + echo wpinv_price(wpinv_format_amount($item->get_initial_price()), $invoice->get_currency()); |
|
70 | 70 | } |
71 | 71 | |
72 | 72 | } |
73 | 73 | |
74 | 74 | // Item quantity. |
75 | - if ( 'quantity' == $column ) { |
|
75 | + if ('quantity' == $column) { |
|
76 | 76 | echo (int) $item->get_qantity(); |
77 | 77 | } |
78 | 78 | |
79 | 79 | // Item sub total. |
80 | - if ( 'subtotal' == $column ) { |
|
81 | - echo wpinv_price( wpinv_format_amount( $item->get_sub_total() ), $invoice->get_currency() ); |
|
80 | + if ('subtotal' == $column) { |
|
81 | + echo wpinv_price(wpinv_format_amount($item->get_sub_total()), $invoice->get_currency()); |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // Fires when printing a line item column. |
85 | - do_action( "getpaid_invoice_line_item_$column", $item, $invoice ); |
|
85 | + do_action("getpaid_invoice_line_item_$column", $item, $invoice); |
|
86 | 86 | |
87 | 87 | // Fires after printing a line item column. |
88 | - do_action( "getpaid_invoice_line_item_after_$column", $item, $invoice ); |
|
88 | + do_action("getpaid_invoice_line_item_after_$column", $item, $invoice); |
|
89 | 89 | |
90 | 90 | ?> |
91 | 91 |
@@ -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); ?> |