Passed
Pull Request — master (#412)
by Brian
04:08
created
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
templates/invoice-history.php 1 patch
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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 date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_created() ) );
56
+									echo date_i18n(get_option('date_format'), strtotime($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 "&mdash;";
63 63
 									} else {
64
-										echo date_i18n( get_option( 'date_format' ), strtotime( $invoice->get_date_completed() ) );
64
+										echo date_i18n(get_option('date_format'), strtotime($invoice->get_date_completed()));
65 65
 									}
66 66
 									
67 67
 									break;
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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); ?>
Please login to merge, or discard this patch.